Skip to content

Commit

Permalink
AzureOpenAI related Fixes (#37)
Browse files Browse the repository at this point in the history
fixes few bugs related to AzureOpenAI.
  • Loading branch information
Nisarg1112 authored Mar 11, 2024
1 parent c766519 commit bd87c64
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export OPENAI_API_KEY = "your OpenAI api key"

```bash
export OPENAI_API_TYPE = "azure"
export OPENAI_API_BASE = "https://<your-endpoint>.openai.azure.com/"
export AZURE_OPENAI_ENDPOINT = "https://<your-endpoint>.openai.azure.com/"
export OPENAI_API_KEY = "your Azure OpenAI api key"
export OPENAI_API_VERSION = "2023-05-15"
```
Expand Down
4 changes: 2 additions & 2 deletions 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
from langchain_openai import OpenAIEmbeddings, AzureOpenAIEmbeddings

from codeqai import utils
from codeqai.constants import EmbeddingsModel
Expand All @@ -17,7 +17,7 @@ def __init__(
client=None, model="text-embedding-ada-002"
)
elif model == EmbeddingsModel.AZURE_OPENAI and deployment:
self.embeddings = OpenAIEmbeddings(client=None, deployment=deployment)
self.embeddings = AzureOpenAIEmbeddings(client=None, deployment=deployment)
else:
try:
import sentence_transformers # noqa: F401
Expand Down
8 changes: 4 additions & 4 deletions codeqai/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ def __init__(self, llm_host: LlmHost, chat_model: str, deployment=None):
temperature=0.9, max_tokens=2048, model=chat_model
)
elif llm_host == LlmHost.AZURE_OPENAI and deployment:
openai_ap_base = os.getenv("OPENAI_API_BASE")
if openai_ap_base:
azure_openai_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
if azure_openai_endpoint:
self.chat_model = AzureChatOpenAI(
openai_api_base=openai_ap_base,
azure_endpoint=azure_openai_endpoint,
temperature=0.9,
max_tokens=2048,
deployment_name=deployment,
model=chat_model,
)
else:
raise ValueError(
"Azure OpenAI requires environment variable OPENAI_API_BASE to be set."
"Azure OpenAI requires environment variable AZURE_OPENAI_ENDPOINT to be set."
)
elif llm_host == LlmHost.LLAMACPP:
self.install_llama_cpp()
Expand Down
1 change: 1 addition & 0 deletions codeqai/treesitter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
from codeqai.treesitter.treesitter_rb import TreesitterRuby
from codeqai.treesitter.treesitter_rs import TreesitterRust
from codeqai.treesitter.treesitter_ts import TreesitterTypescript
from codeqai.treesitter.treesitter_hs import TreesitterHaskell

0 comments on commit bd87c64

Please sign in to comment.