Skip to content

Commit

Permalink
[#36] Update readme, ommit api key, restore msg_role and msg_content
Browse files Browse the repository at this point in the history
  • Loading branch information
dedenbangkit committed Jul 15, 2024
1 parent e8ca512 commit 12dfa34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
9 changes: 3 additions & 6 deletions assistant/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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"))
Expand Down
15 changes: 7 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 12dfa34

Please sign in to comment.