ZEROLABS1 commited on
Commit
db50de9
·
verified ·
1 Parent(s): e7c1a47

Upload agent.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. agent.py +19 -0
agent.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from llama_cpp import Llama # pip install llama-cpp-python
3
+ from tools import parse_call, run_tool
4
+ llm = Llama(model_path=sys.argv[1], n_ctx=2048, verbose=False)
5
+ msgs = []
6
+ while True:
7
+ q = input("you> ").strip()
8
+ if not q: break
9
+ msgs.append({"role": "user", "content": q})
10
+ for _ in range(3):
11
+ out = llm.create_chat_completion(messages=msgs, max_tokens=700, temperature=0.6, top_p=0.95)["choices"][0]["message"]["content"]
12
+ if "<think>" not in out: out = "<think>\n" + out # the chat template already opened the think block
13
+ msgs.append({"role": "assistant", "content": out})
14
+ call = parse_call(out)
15
+ if not call: break
16
+ try: res = run_tool(call["name"], call["arguments"])
17
+ except Exception as e: res = "error: " + str(e)
18
+ msgs.append({"role": "tool", "content": res})
19
+ print(out.split("</think>")[-1].strip())