Args: config: configuration for openai-gpt model
(self, config: OpenAIGPTConfig = OpenAIGPTConfig())
| 419 | async_client: AsyncOpenAI | AsyncGroq | AsyncCerebras | None |
| 420 | |
| 421 | def __init__(self, config: OpenAIGPTConfig = OpenAIGPTConfig()): |
| 422 | """ |
| 423 | Args: |
| 424 | config: configuration for openai-gpt model |
| 425 | """ |
| 426 | # copy the config to avoid modifying the original; deep to decouple |
| 427 | # nested models while preserving their concrete subclasses |
| 428 | config = config.model_copy(deep=True) |
| 429 | super().__init__(config) |
| 430 | self.config: OpenAIGPTConfig = config |
| 431 | # save original model name such as `provider/model` before |
| 432 | # we strip out the `provider` - we retain the original in |
| 433 | # case some params are specific to a provider. |
| 434 | self.chat_model_orig = self.config.chat_model_orig or self.config.chat_model |
| 435 | |
| 436 | # Run the first time the model is used |
| 437 | self.run_on_first_use = cache(self.config.run_on_first_use) |
| 438 | |
| 439 | # global override of chat_model, |
| 440 | # to allow quick testing with other models |
| 441 | if settings.chat_model != "": |
| 442 | self.config.chat_model = settings.chat_model |
| 443 | self.chat_model_orig = settings.chat_model |
| 444 | self.config.completion_model = settings.chat_model |
| 445 | |
| 446 | if len(parts := self.config.chat_model.split("//")) > 1: |
| 447 | # there is a formatter specified, e.g. |
| 448 | # "litellm/ollama/mistral//hf" or |
| 449 | # "local/localhost:8000/v1//mistral-instruct-v0.2" |
| 450 | formatter = parts[1] |
| 451 | self.config.chat_model = parts[0] |
| 452 | if formatter == "hf": |
| 453 | # e.g. "litellm/ollama/mistral//hf" -> "litellm/ollama/mistral" |
| 454 | formatter = find_hf_formatter(self.config.chat_model) |
| 455 | if formatter != "": |
| 456 | # e.g. "mistral" |
| 457 | self.config.formatter = formatter |
| 458 | logging.warning( |
| 459 | f""" |
| 460 | Using completions (not chat) endpoint with HuggingFace |
| 461 | chat_template for {formatter} for |
| 462 | model {self.config.chat_model} |
| 463 | """ |
| 464 | ) |
| 465 | else: |
| 466 | # e.g. "local/localhost:8000/v1//mistral-instruct-v0.2" |
| 467 | self.config.formatter = formatter |
| 468 | |
| 469 | if self.config.formatter is not None: |
| 470 | self.config.hf_formatter = HFFormatter( |
| 471 | HFPromptFormatterConfig(model_name=self.config.formatter) |
| 472 | ) |
| 473 | |
| 474 | self.supports_json_schema: bool = self.config.supports_json_schema or False |
| 475 | self.supports_strict_tools: bool = self.config.supports_strict_tools or False |
| 476 | |
| 477 | OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", DUMMY_API_KEY) |
| 478 | self.api_key = config.api_key |
no test coverage detected