wjnwjn59 commited on
Commit
b36a835
·
1 Parent(s): 487fa97

pdate logic

Browse files
Files changed (2) hide show
  1. src/__init__.py +0 -0
  2. src/llm/chat.py +14 -9
src/__init__.py ADDED
File without changes
src/llm/chat.py CHANGED
@@ -31,7 +31,7 @@ class FunctionCallingChat:
31
  ]
32
 
33
  generation_cfg = GenerationConfig(
34
- max_new_tokens=512, temperature=0.2, top_p=0.95, do_sample=True
35
  )
36
 
37
  tokenized = self.tokenizer.apply_chat_template(
@@ -46,11 +46,16 @@ class FunctionCallingChat:
46
  try:
47
  calls = ast.literal_eval(tool_calls_str)
48
  except Exception as e:
49
- raise RuntimeError(f"Cannot parse tool call: {e}\nRaw: {tool_calls_str}")
50
-
51
- results = []
52
- for call in calls:
53
- fn_name = call.func.id
54
- kwargs = {kw.arg: ast.literal_eval(kw.value) for kw in call.keywords}
55
- results.append(TOOLS[fn_name](**kwargs))
56
- return {"raw_tool_call": tool_calls_str, "results": results}
 
 
 
 
 
 
31
  ]
32
 
33
  generation_cfg = GenerationConfig(
34
+ max_new_tokens=128, temperature=0.2, top_p=0.95, do_sample=True
35
  )
36
 
37
  tokenized = self.tokenizer.apply_chat_template(
 
46
  try:
47
  calls = ast.literal_eval(tool_calls_str)
48
  except Exception as e:
49
+ calls = []
50
+ print(f"Error parsing tool calls: {e}", file=sys.stderr)
51
+
52
+ if calls == []:
53
+ return {"raw_tool_call": tool_calls_str, "results": "No function call detected."}
54
+ else:
55
+ results = []
56
+ for call in calls:
57
+ fn_name = call.func.id
58
+ kwargs = {kw.arg: ast.literal_eval(kw.value) for kw in call.keywords}
59
+ results.append(TOOLS[fn_name](**kwargs))
60
+
61
+ return {"raw_tool_call": tool_calls_str, "results": results}