Skip to content

Commit

Permalink
Support Ollama
Browse files Browse the repository at this point in the history
  • Loading branch information
valentimarco committed Oct 19, 2023
1 parent 86f7700 commit 16eabbe
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
18 changes: 17 additions & 1 deletion core/cat/factory/custom_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests
from langchain.llms.base import LLM
from langchain.llms.openai import OpenAI
from langchain.llms.ollama import Ollama


class LLMDefault(LLM):
Expand Down Expand Up @@ -86,4 +87,19 @@ def __init__(self, **kwargs):

self.url = kwargs['url']
self.openai_api_base = os.path.join(self.url, "v1")


class CustomOllama(Ollama):


def __init__(self, **kwargs):

super().__init__(
base_url=kwargs["base_url"],
model=kwargs["model"],
num_ctx=kwargs["num_ctx"],
repeat_last_n=kwargs["repeat_last_n"],
repeat_penalty=kwargs["repeat_penalty"],
temperature=kwargs["temperature"],
)


23 changes: 21 additions & 2 deletions core/cat/factory/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
from pydantic import BaseModel, ConfigDict

from cat.factory.custom_llm import LLMDefault, LLMCustom, CustomOpenAI
from cat.factory.custom_llm import CustomOllama, LLMDefault, LLMCustom, CustomOpenAI


# Base class to manage LLM configuration.
Expand Down Expand Up @@ -272,6 +272,24 @@ class LLMGooglePalmConfig(LLMSettings):
}
)

class LLMCustomOllama(LLMSettings):
base_url: str
model: str = "llama2"
num_ctx: int = 2048
repeat_last_n: int = 64
repeat_penalty: float = 1.1
temperature: float = 0.8

_pyclass: Type = CustomOllama

model_config = ConfigDict(
json_schema_extra = {
"humanReadableName": "Ollama",
"description": "Configuration for Ollama",
"link": "https://ollama.ai/library"
}
)


SUPPORTED_LANGUAGE_MODELS = [
LLMDefaultConfig,
Expand All @@ -286,7 +304,8 @@ class LLMGooglePalmConfig(LLMSettings):
LLMAzureOpenAIConfig,
LLMAzureChatOpenAIConfig,
LLMAnthropicConfig,
LLMGooglePalmConfig
LLMGooglePalmConfig,
LLMCustomOllama
]

# LLM_SCHEMAS contains metadata to let any client know
Expand Down

0 comments on commit 16eabbe

Please sign in to comment.