Create and cache a client for the given model config.
(self, config: ModelConfig)
| 674 | await self._create_client(config) |
| 675 | |
| 676 | async def _create_client(self, config: ModelConfig) -> None: |
| 677 | """Create and cache a client for the given model config.""" |
| 678 | if config.provider == "openrouter": |
| 679 | # OpenRouter models (only chat/completions supported for now) |
| 680 | if config.model_type == "chat/completions": |
| 681 | client = ChatOpenRouter( |
| 682 | model=config.model_id, |
| 683 | api_key=config.api_key, |
| 684 | base_url=config.api_base, |
| 685 | reasoning=config.reasoning if config.reasoning else None, |
| 686 | plugins=config.plugins if config.plugins else None, |
| 687 | temperature=config.temperature or self.default_temperature, |
| 688 | max_completion_tokens=config.max_completion_tokens or self.max_tokens, |
| 689 | http_referer=os.getenv("OPENROUTER_HTTP_REFERER"), |
| 690 | x_title=os.getenv("OPENROUTER_X_TITLE"), |
| 691 | ) |
| 692 | logger.info(f"| Created ChatOpenRouter client for {config.model_name}") |
| 693 | else: |
| 694 | raise ValueError(f"Unsupported model type {config.model_type} for OpenRouter provider") |
| 695 | elif config.provider == "anthropic": |
| 696 | # Anthropic models (only chat/completions supported for now) |
| 697 | if config.model_type == "chat/completions": |
| 698 | client = ChatAnthropic( |
| 699 | model=config.model_id, |
| 700 | api_key=config.api_key, |
| 701 | base_url=config.api_base, |
| 702 | reasoning=config.reasoning if config.reasoning else None, |
| 703 | temperature=config.temperature or self.default_temperature, |
| 704 | max_tokens=config.max_completion_tokens or self.max_tokens, |
| 705 | ) |
| 706 | logger.info(f"| Created ChatAnthropic client for {config.model_name}") |
| 707 | else: |
| 708 | raise ValueError(f"Unsupported model type {config.model_type} for Anthropic provider") |
| 709 | elif config.provider == "google": |
| 710 | # Google Gemini models (only chat/completions supported for now) |
| 711 | if config.model_type == "chat/completions": |
| 712 | client = ChatGoogle( |
| 713 | model=config.model_id, |
| 714 | api_key=config.api_key, |
| 715 | reasoning=config.reasoning if config.reasoning else None, |
| 716 | temperature=config.temperature or self.default_temperature, |
| 717 | max_output_tokens=config.max_completion_tokens or self.max_tokens, |
| 718 | ) |
| 719 | logger.info(f"| Created ChatGoogle client for {config.model_name}") |
| 720 | else: |
| 721 | raise ValueError(f"Unsupported model type {config.model_type} for Google provider") |
| 722 | elif config.model_type == "responses": |
| 723 | # Create ResponseOpenAI client |
| 724 | client = ResponseOpenAI( |
| 725 | model=config.model_id, |
| 726 | api_key=config.api_key, |
| 727 | base_url=config.api_base, |
| 728 | reasoning=config.reasoning if config.reasoning else None, |
| 729 | max_output_tokens=config.max_output_tokens or self.max_tokens, |
| 730 | ) |
| 731 | logger.info(f"| Created ResponseOpenAI client for {config.model_name}") |
| 732 | elif config.model_type == "transcriptions": |
| 733 | # Create TranscribeOpenAI client |
no test coverage detected