Invoke a model asynchronously. Args: model: Model name messages: List of Message objects (for transcription models, should contain ContentPartAudio) tools: Optional list of Tool instances response_format: Optional response for
(
self,
model: str,
messages: List[Message],
tools: Optional[List["Tool"]] = None,
response_format: Optional[Union[BaseModel, Dict]] = None,
stream: bool = False,
plugins: Optional[List[Dict[str, Any]]] = None,
**kwargs: Any,
)
| 769 | logger.info(f"Registered model: {config.model_name}") |
| 770 | |
| 771 | async def __call__( |
| 772 | self, |
| 773 | model: str, |
| 774 | messages: List[Message], |
| 775 | tools: Optional[List["Tool"]] = None, |
| 776 | response_format: Optional[Union[BaseModel, Dict]] = None, |
| 777 | stream: bool = False, |
| 778 | plugins: Optional[List[Dict[str, Any]]] = None, |
| 779 | **kwargs: Any, |
| 780 | ) -> LLMResponse: |
| 781 | """ |
| 782 | Invoke a model asynchronously. |
| 783 | |
| 784 | Args: |
| 785 | model: Model name |
| 786 | messages: List of Message objects (for transcription models, should contain ContentPartAudio) |
| 787 | tools: Optional list of Tool instances |
| 788 | response_format: Optional response format (Pydantic model or dict) |
| 789 | stream: Whether to stream the response |
| 790 | **kwargs: Additional parameters |
| 791 | |
| 792 | Returns: |
| 793 | LLMResponse with formatted message |
| 794 | """ |
| 795 | # Validate that tools and response_format are not both provided |
| 796 | if tools and response_format: |
| 797 | raise ValueError("tools and response_format cannot be used together") |
| 798 | |
| 799 | current_model = model |
| 800 | try: |
| 801 | # Get client for the model |
| 802 | client = self.model_clients.get(current_model) |
| 803 | if not client: |
| 804 | raise ValueError(f"Model {current_model} not found. Available models: {list(self.models.keys())}") |
| 805 | |
| 806 | # Check model type and call appropriate method |
| 807 | model_config = self.models.get(current_model) |
| 808 | |
| 809 | if model_config and model_config.model_type == "transcriptions": |
| 810 | # Transcription models use messages parameter (extracts audio from messages) |
| 811 | if messages is None: |
| 812 | raise ValueError("messages parameter is required for transcription models") |
| 813 | result = await client( |
| 814 | messages=messages, |
| 815 | **kwargs, |
| 816 | ) |
| 817 | elif model_config and model_config.model_type == "embeddings": |
| 818 | # Embedding models use messages parameter (extracts text from messages) |
| 819 | # Filter out unsupported parameters (tools, response_format, stream) |
| 820 | embedding_kwargs = {k: v for k, v in kwargs.items() if k not in ['tools', 'response_format', 'stream']} |
| 821 | if messages is None: |
| 822 | raise ValueError("messages parameter is required for embedding models") |
| 823 | result = await client( |
| 824 | messages=messages, |
| 825 | **embedding_kwargs, |
| 826 | ) |
| 827 | else: |
| 828 | # Chat/response models use messages parameter |