Skip to content

Commit

Permalink
feat: add Anthropic Claude 3 Opus chat model (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
fynnfluegge authored Mar 29, 2024
1 parent 6eae54f commit f3ceae8
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Built with [langchain](https://github.com/langchain-ai/langchain), [treesitter](
- ⚙️  Synchronize vector store and latest code changes with ease
- 💻  100% local embeddings and llms
- sentence-transformers, instructor-embeddings, llama.cpp, Ollama
- 🌐  OpenAI and Azure OpenAI support
- 🌐  OpenAI, Azure OpenAI and Anthropic
- 🌳  Treesitter integration

> [!NOTE]
Expand Down Expand Up @@ -143,6 +143,12 @@ export OPENAI_API_KEY = "your Azure OpenAI api key"
export OPENAI_API_VERSION = "2023-05-15"
```

### Anthropic

```bash
export ANTHROPIC_API_KEY="your Anthropic api key"
```

> [!NOTE]
> To change the environment variables later, update the `~/.config/codeqai/.env` manually.
Expand Down
4 changes: 4 additions & 0 deletions codeqai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def run():
"OPENAI_API_VERSION",
]
)

if config["llm-host"] == LlmHost.ANTHROPIC.value:
required_keys.append("ANTHROPIC_API_KEY")

env_path = get_config_path().replace("config.yaml", ".env")
env_loader(env_path, required_keys)

Expand Down
15 changes: 15 additions & 0 deletions codeqai/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def create_config():
choices=[
LlmHost.OPENAI.value,
LlmHost.AZURE_OPENAI.value,
LlmHost.ANTHROPIC.value,
],
default=LlmHost.OPENAI.value,
),
Expand Down Expand Up @@ -180,6 +181,20 @@ def create_config():
),
]

elif config["llm-host"] == "Anthropic":
questions = [
inquirer.List(
"chat-model",
message="Which Anthropic chat model do you want to use?",
choices=[
"claude-3-opus-20240229",
"claude-3-sonnet-20240229",
"claude-3-haiku-20240307",
],
default="claude-3-opus-20240229",
),
]

# Check if "chat-model" is already present in the case of Azure_OpenAI
if "chat-model" not in config:
answersChatmodel = inquirer.prompt(questions)
Expand Down
1 change: 1 addition & 0 deletions codeqai/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ class LlmHost(Enum):
OLLAMA = "Ollama"
OPENAI = "OpenAI"
AZURE_OPENAI = "Azure-OpenAI"
ANTHROPIC = "Anhtropic"
2 changes: 1 addition & 1 deletion codeqai/embeddings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inquirer
from langchain_community.embeddings import HuggingFaceEmbeddings
from langchain_openai import OpenAIEmbeddings, AzureOpenAIEmbeddings
from langchain_openai import AzureOpenAIEmbeddings, OpenAIEmbeddings

from codeqai import utils
from codeqai.constants import EmbeddingsModel
Expand Down
6 changes: 5 additions & 1 deletion codeqai/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import inquirer
from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain_community.chat_models import AzureChatOpenAI
from langchain_community.chat_models import AzureChatOpenAI, ChatAnthropic
from langchain_community.llms import LlamaCpp, Ollama
from langchain_openai import ChatOpenAI

Expand Down Expand Up @@ -33,6 +33,10 @@ def __init__(self, llm_host: LlmHost, chat_model: str, deployment=None):
raise ValueError(
"Azure OpenAI requires environment variable AZURE_OPENAI_ENDPOINT to be set."
)
elif llm_host == LlmHost.ANTHROPIC:
self.chat_model = ChatAnthropic(
temperature=0.9, max_tokens=2048, model_name=chat_model
)
elif llm_host == LlmHost.LLAMACPP:
self.install_llama_cpp()
self.chat_model = LlamaCpp(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "codeqai"
version = "0.0.16"
version = "0.0.17"
description = ""
authors = ["fynnfluegge <fynnfluegge@gmx.de>"]
readme = "README.md"
Expand Down

0 comments on commit f3ceae8

Please sign in to comment.