(self, *args: Any, **kwargs: Any)
| 257 | return await loop.run_in_executor(None, functools.partial(self.completion, *args, **kwargs)) |
| 258 | |
| 259 | def streaming(self, *args: Any, **kwargs: Any) -> Iterator[dict[str, Any]]: |
| 260 | response = self.completion(*args, **kwargs) |
| 261 | text = "" |
| 262 | if response.choices: |
| 263 | c = response.choices[0] |
| 264 | msg = c.get("message", {}) if isinstance(c, dict) else getattr(c, "message", {}) |
| 265 | text = ( |
| 266 | msg.get("content") if isinstance(msg, dict) else getattr(msg, "content", "") |
| 267 | ) or "" |
| 268 | usage = { |
| 269 | "completion_tokens": response.usage.completion_tokens if response.usage else 0, |
| 270 | "prompt_tokens": response.usage.prompt_tokens if response.usage else 0, |
| 271 | "total_tokens": response.usage.total_tokens if response.usage else 0, |
| 272 | } |
| 273 | yield { |
| 274 | "text": text, |
| 275 | "is_finished": True, |
| 276 | "finish_reason": "stop", |
| 277 | "index": 0, |
| 278 | "tool_use": None, |
| 279 | "usage": usage, |
| 280 | } |
| 281 | |
| 282 | async def astreaming(self, *args: Any, **kwargs: Any) -> AsyncIterator[dict[str, Any]]: |
| 283 | response = await self.acompletion(*args, **kwargs) |
nothing calls this directly
no test coverage detected