(output: str, use_tool: bool = False)
| 17 | |
| 18 | |
| 19 | def 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() |
no outgoing calls
no test coverage detected