Skip to content

Commit

Permalink
Allow setting OpenAI model in settings (zylon-ai#1386)
Browse files Browse the repository at this point in the history
feat(settings): Allow setting openai model to be used. Default to GPT 3.5
  • Loading branch information
aly-shehata authored and simonbermudez committed Feb 24, 2024
1 parent 8c9fd31 commit 14980c4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions fern/docs/pages/manual/llms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ llm:

openai:
api_key: <your_openai_api_key> # You could skip this configuration and use the OPENAI_API_KEY env var instead
model: <openai_model_to_use> # Optional model to use. Default is "gpt-3.5-turbo"
# Note: Open AI Models are listed here [here](https://platform.openai.com/docs/models)
```

And run PrivateGPT loading that profile you just created:
Expand Down
6 changes: 4 additions & 2 deletions private_gpt/components/llm/llm_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def __init__(self, settings: Settings) -> None:
case "openai":
from llama_index.llms import OpenAI

openai_settings = settings.openai.api_key
self.llm = OpenAI(api_key=openai_settings)
openai_settings = settings.openai
self.llm = OpenAI(
api_key=openai_settings.api_key, model=openai_settings.model
)
case "mock":
self.llm = MockLLM()
4 changes: 4 additions & 0 deletions private_gpt/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class SagemakerSettings(BaseModel):

class OpenAISettings(BaseModel):
api_key: str
model: str = Field(
"gpt-3.5-turbo",
description=("OpenAI Model to use. Example: 'gpt-4'."),
)


class UISettings(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ sagemaker:

openai:
api_key: ${OPENAI_API_KEY:}
model: gpt-3.5-turbo

0 comments on commit 14980c4

Please sign in to comment.