kwargs is the combined input and model_kwargs
(
self, api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED
)
| 486 | max_time=5, |
| 487 | ) |
| 488 | async def acall( |
| 489 | self, api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED |
| 490 | ): |
| 491 | """ |
| 492 | kwargs is the combined input and model_kwargs |
| 493 | """ |
| 494 | # store the api kwargs in the client |
| 495 | self._api_kwargs = api_kwargs |
| 496 | if self.async_client is None: |
| 497 | self.async_client = self.init_async_client() |
| 498 | if model_type == ModelType.EMBEDDER: |
| 499 | return await self.async_client.embeddings.create(**api_kwargs) |
| 500 | elif model_type == ModelType.LLM: |
| 501 | return await self.async_client.chat.completions.create(**api_kwargs) |
| 502 | elif model_type == ModelType.IMAGE_GENERATION: |
| 503 | # Determine which image API to call based on the presence of image/mask |
| 504 | if "image" in api_kwargs: |
| 505 | if "mask" in api_kwargs: |
| 506 | # Image edit |
| 507 | response = await self.async_client.images.edit(**api_kwargs) |
| 508 | else: |
| 509 | # Image variation |
| 510 | response = await self.async_client.images.create_variation( |
| 511 | **api_kwargs |
| 512 | ) |
| 513 | else: |
| 514 | # Image generation |
| 515 | response = await self.async_client.images.generate(**api_kwargs) |
| 516 | return response.data |
| 517 | else: |
| 518 | raise ValueError(f"model_type {model_type} is not supported") |
| 519 | |
| 520 | @classmethod |
| 521 | def from_dict(cls: type[T], data: Dict[str, Any]) -> T: |
no test coverage detected