简单对话
(self, message: str, **kwargs)
| 22 | self.conversation_history = [] |
| 23 | |
| 24 | def simple_chat(self, message: str, **kwargs) -> Dict[str, Any]: |
| 25 | """简单对话""" |
| 26 | data = { |
| 27 | "model": self.model_name, |
| 28 | "messages": [{"role": "user", "content": message}], |
| 29 | "temperature": kwargs.get("temperature", 0.7), |
| 30 | "max_tokens": kwargs.get("max_tokens", 1000), |
| 31 | **kwargs, |
| 32 | } |
| 33 | |
| 34 | response = requests.post(f"{self.base_url}/v1/chat/completions", headers=self.headers, json=data) |
| 35 | |
| 36 | if response.status_code == 200: |
| 37 | return response.json() |
| 38 | else: |
| 39 | raise Exception(f"API调用失败: {response.status_code} - {response.text}") |
| 40 | |
| 41 | def stream_chat(self, message: str, **kwargs): |
| 42 | data = { |