Function calling
(self, message: str, tools: List[Dict], tool_choice: str = "auto", **kwargs)
| 115 | raise Exception(f"API调用失败: {response.status_code} - {response.text}") |
| 116 | |
| 117 | def function_call(self, message: str, tools: List[Dict], tool_choice: str = "auto", **kwargs) -> Dict[str, Any]: |
| 118 | """Function calling""" |
| 119 | data = { |
| 120 | "model": self.model_name, |
| 121 | "messages": [{"role": "user", "content": message}], |
| 122 | "tools": tools, |
| 123 | "tool_choice": tool_choice, |
| 124 | "temperature": kwargs.get("temperature", 0.7), |
| 125 | "max_tokens": kwargs.get("max_tokens", 1000), |
| 126 | **kwargs, |
| 127 | } |
| 128 | |
| 129 | response = requests.post(f"{self.base_url}/v1/chat/completions", headers=self.headers, json=data) |
| 130 | |
| 131 | if response.status_code == 200: |
| 132 | return response.json() |
| 133 | else: |
| 134 | raise Exception(f"API调用失败: {response.status_code} - {response.text}") |
| 135 | |
| 136 | def stream_function_call(self, message: str, tools: List[Dict], tool_choice: str = "auto", **kwargs): |
| 137 | """stream Function calling""" |
no test coverage detected