forked from Sunbird-AIAssistant/sakhi-api-service
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathollama.py
34 lines (26 loc) · 983 Bytes
/
ollama.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
from typing import Any
from langchain.chat_models import ChatOllama
from llm.base import BaseChatClient
class OllamaChatClient(BaseChatClient):
"""
This class provides a ollama chat interface.
"""
ollama_api_endpoint: str
def __init__(self) -> None:
self.ollama_api_endpoint = os.getenv(
"OLLAMA_API_ENDPOINT", "http://localhost:11434")
def get_client(self, model=os.getenv("LLM_MODEL"), **kwargs: Any) -> ChatOllama:
"""
This method creates and returns a ChatOllama instance.
Args:
model (str, optional): The LLM model to use. Defaults to the value of the environment variable "LLM_MODEL".
**kwargs: Additional arguments to be passed to the ChatOllama constructor.
Returns:
An instance of the ChatOllama class.
"""
return ChatOllama(
base_url=self.ollama_api_endpoint,
model=model,
**kwargs
)