Skip to content

Commit

Permalink
[GPT] improve custom base_url docs
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Jan 11, 2025
1 parent 533f361 commit 297f4ff
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions Services/Services_bases/gpt_service/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def get_fields_description(self):
if self._env_secret_key is None:
return {
services_constants.CONIG_OPENAI_SECRET_KEY: "Your openai API secret key",
services_constants.CONIG_LLM_CUSTOM_BASE_URL: "Custom LLM base url to use. Leave empty to use openai.com",
services_constants.CONIG_LLM_CUSTOM_BASE_URL: (
"Custom LLM base url to use. Leave empty to use openai.com. For Ollama models, "
"add /v1 to the url (such as: http://localhost:11434/v1)"
),
}
return {}

Expand Down Expand Up @@ -365,20 +368,28 @@ async def prepare(self) -> None:
if self.use_stored_signals_only():
self.logger.info(f"Skipping GPT - OpenAI models fetch as self.use_stored_signals_only() is True")
return
if self._get_base_url():
self.logger.info(f"Using custom LLM url: {self._get_base_url()}")
fetched_models = await self._get_client().models.list()
self.models = [d.id for d in fetched_models.data]
if self.model not in self.models:
self.logger.warning(
f"Warning: the default '{self.model}' model is not in available LLM models from the "
f"selected LLM provider. "
f"Available models are: {self.models}. Please select an available model when configuring your "
f"evaluators."
)
if self._get_base_url():
self.logger.info(
f"Custom LLM available models are: {self.models}. "
f"Please select one of those in your evaluator configuration."
)
else:
self.logger.warning(
f"Warning: the default '{self.model}' model is not in available LLM models from the "
f"selected LLM provider. "
f"Available models are: {self.models}. Please select an available model when configuring your "
f"evaluators."
)
except openai.AuthenticationError as err:
self.logger.error(f"Invalid OpenAI api key: {err}")
self.creation_error_message = err
except Exception as err:
self.logger.error(f"Unexpected error when checking api key: {err}")
self.logger.exception(err, True, f"Unexpected error when initializing GPT service: {err}")

def _is_healthy(self):
return self.use_stored_signals_only() or (self._get_api_key() and self.models)
Expand Down

0 comments on commit 297f4ff

Please sign in to comment.