文本补全
(self, prompt: str, **kwargs)
| 68 | raise Exception(f"API调用失败: {response.status_code} - {response.text}") |
| 69 | |
| 70 | def completions(self, prompt: str, **kwargs) -> Dict[str, Any]: |
| 71 | """文本补全""" |
| 72 | data = { |
| 73 | "model": self.model_name, |
| 74 | "prompt": prompt, |
| 75 | "temperature": kwargs.get("temperature", 0.7), |
| 76 | "max_tokens": kwargs.get("max_tokens", 100), |
| 77 | **kwargs, |
| 78 | } |
| 79 | |
| 80 | response = requests.post(f"{self.base_url}/v1/completions", headers=self.headers, json=data) |
| 81 | |
| 82 | if response.status_code == 200: |
| 83 | return response.json() |
| 84 | else: |
| 85 | raise Exception(f"API调用失败: {response.status_code} - {response.text}") |
| 86 | |
| 87 | def stream_completions(self, prompt: str, **kwargs): |
| 88 | """流式文本补全""" |