zero-loop / agent.py
ZEROLABS1's picture
Upload agent.py with huggingface_hub
db50de9 verified
Raw History Blame Contribute Delete
908 Bytes
import sys
from llama_cpp import Llama # pip install llama-cpp-python
from tools import parse_call, run_tool
llm = Llama(model_path=sys.argv[1], n_ctx=2048, verbose=False)
msgs = []
while True:
q = input("you> ").strip()
if not q: break
msgs.append({"role": "user", "content": q})
for _ in range(3):
out = llm.create_chat_completion(messages=msgs, max_tokens=700, temperature=0.6, top_p=0.95)["choices"][0]["message"]["content"]
if "<think>" not in out: out = "<think>\n" + out # the chat template already opened the think block
msgs.append({"role": "assistant", "content": out})
call = parse_call(out)
if not call: break
try: res = run_tool(call["name"], call["arguments"])
except Exception as e: res = "error: " + str(e)
msgs.append({"role": "tool", "content": res})
print(out.split("</think>")[-1].strip())