Skip to content

Commit

Permalink
Add support for Ollama LLM
Browse files Browse the repository at this point in the history
Allow using Ollama as the LLM

Signed-off-by: Ygal Blum <[email protected]>
  • Loading branch information
ygalblum committed Feb 2, 2024
1 parent 869233f commit e657437
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions private_gpt/components/llm/llm_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ def __init__(self, settings: Settings) -> None:
)
case "mock":
self.llm = MockLLM()
case "ollama":
from llama_index.llms import Ollama

ollama_settings = settings.ollama
self.llm = Ollama(
model=ollama_settings.model, base_url=ollama_settings.api_base
)
14 changes: 13 additions & 1 deletion private_gpt/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class DataSettings(BaseModel):


class LLMSettings(BaseModel):
mode: Literal["local", "openai", "openailike", "sagemaker", "mock"]
mode: Literal["local", "openai", "openailike", "sagemaker", "mock", "ollama"]
max_new_tokens: int = Field(
256,
description="The maximum number of token that the LLM is authorized to generate in one completion.",
Expand Down Expand Up @@ -168,6 +168,17 @@ class OpenAISettings(BaseModel):
)


class OllamaSettings(BaseModel):
api_base: str = Field(
"http://localhost:11434",
description="Base URL of Ollama API. Example: 'https://localhost:11434'.",
)
model: str = Field(
None,
description="Model to use. Example: 'llama2-uncensored'.",
)


class UISettings(BaseModel):
enabled: bool
path: str
Expand Down Expand Up @@ -243,6 +254,7 @@ class Settings(BaseModel):
local: LocalSettings
sagemaker: SagemakerSettings
openai: OpenAISettings
ollama: OllamaSettings
vectorstore: VectorstoreSettings
qdrant: QdrantSettings | None = None

Expand Down
3 changes: 3 additions & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ sagemaker:
openai:
api_key: ${OPENAI_API_KEY:}
model: gpt-3.5-turbo

ollama:
model: llama2-uncensored

0 comments on commit e657437

Please sign in to comment.