MCPcopy
hub / github.com/zai-org/ChatGLM3 / process_response

Function process_response

openai_api_demo/utils.py:19–42  ·  view source on GitHub ↗
(output: str, use_tool: bool = False)

Source from the content-addressed store, hash-verified

17
18
19def process_response(output: str, use_tool: bool = False) -> Union[str, dict]:
20 content = ""
21 for response in output.split("<|assistant|>"):
22 metadata, content = response.split("\n", maxsplit=1)
23 if not metadata.strip():
24 content = content.strip()
25 content = content.replace("[[训练时间]]", "2023年")
26 else:
27 if use_tool:
28 content = "\n".join(content.split("\n")[1:-1])
29 def tool_call(**kwargs):
30 return kwargs
31
32 parameters = eval(content)
33 content = {
34 "name": metadata.strip(),
35 "arguments": json.dumps(parameters, ensure_ascii=False)
36 }
37 else:
38 content = {
39 "name": metadata.strip(),
40 "content": content
41 }
42 return content
43
44
45@torch.inference_mode()

Callers 2

create_chat_completionFunction · 0.90
predictFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected