diff --git a/assistant/assistant.py b/assistant/assistant.py index 05568648..f86f799a 100644 --- a/assistant/assistant.py +++ b/assistant/assistant.py @@ -23,16 +23,13 @@ class LLM: def __init__(self, chat_model: str): self.chat_model = chat_model - self.client = OpenAI( - # This is the default and can be omitted - api_key=os.environ.get("OPENAI_API_KEY"), - ) + self.llm_client = OpenAI() self.messages = [] self.append_message(ROLE_SYSTEM, os.getenv("ASSISTANT_ROLE")) def chat(self, content: str) -> dict: self.append_message(ROLE_USER, content) - response = self.client.chat.completions.create( + response = self.llm_client.chat.completions.create( model=self.chat_model, messages=self.messages ) logging.info(f"OPENAI RESPONSE: {response.choices[0].message.content}") @@ -41,7 +38,7 @@ def chat(self, content: str) -> dict: return message.content def append_message(self, role, content): - self.messages.append({"role": role, "content": str(content)}) + self.messages.append({MSG_ROLE: role, MSG_CONTENT: str(content)}) llm = LLM(os.getenv("OPENAI_CHAT_MODEL")) diff --git a/readme.md b/readme.md index 2b62be6a..b4404158 100644 --- a/readme.md +++ b/readme.md @@ -39,18 +39,17 @@ retrieval part of the system. | `LIBRARIAN_COLLECTION` | knowledge-base | The name of the ChromaDB collection where the corpus will be stored. | -## Ollama LLM Runtime +## OpenAI LLM Runtime -We use [Ollama](https://ollama.com/) as the model run-time. Ollama makes it easy -to manage multiple models, without having to handle large model files. It also -solves the need for registration on all kinds of sites. Ollama will just pull -the model in and cache it locally. +We use [OpenAI](https://platform.openai.com/) as the model run-time. OpenAI provides robust capabilities for managing multiple models and handling large model files. It simplifies the integration process by managing registrations and pulling models as needed. | `.env` | default | description | |---|---|---| -| `OLLAMA_HOST` | _CHANGEME_ | The IP address or DNS name of the host that runs Ollama. | -| `OLLAMA_PORT` | 11434 | The port number on the host that runs Ollama. | -| `OLLAMA_CHAT_MODEL` | mistral | The LLM model that is used to handle chat messages. | +| `OPENAI_API_KEY` | _CHANGEME_ | The API key for authenticating with OpenAI services. | +| `OPENAI_CHAT_MODEL` | `gpt-3.5` / `gpt-4` | The LLM model that is used to handle chat messages. Read more about [OpenAI models](https://platform.openai.com/docs/models) | + +Note: The __OPENAI_API_KEY__ does not need to be explicitly called in [assistant.py](https://github.com/akvo/rag-doll/blob/master/assistant/assistant.py) because the openai library automatically reads it from the environment variables when `openai.OpenAI()` is instantiated. + ## ChromaDB Vector Database