Skip to content

Fix: Correct environment variable handling for limited Azure OpenAI GPT and embedding access by properly differentiating endpoints. #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions nano_graphrag/_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import aioboto3
from openai import AsyncOpenAI, AsyncAzureOpenAI, APIConnectionError, RateLimitError
from azure.core.exceptions import HttpResponseError
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add azure dep in requirement.txt

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait there is no Azure in requirement? shiii,sorry for that


from tenacity import (
retry,
Expand All @@ -19,6 +20,7 @@
global_openai_async_client = None
global_azure_openai_async_client = None
global_amazon_bedrock_async_client = None
global_azure_openai_emb_async_client = None


def get_openai_async_client_instance():
Expand All @@ -34,6 +36,12 @@ def get_azure_openai_async_client_instance():
global_azure_openai_async_client = AsyncAzureOpenAI()
return global_azure_openai_async_client

def get_azure_openai_emb_async_client_instance():
global global_azure_openai_emb_async_client
if global_azure_openai_emb_async_client is None:
global_azure_openai_emb_async_client = AsyncAzureOpenAI(azure_endpoint=os.environ["AZURE_ENDPOINT_EMB"])
return global_azure_openai_emb_async_client


def get_amazon_bedrock_async_client_instance():
global global_amazon_bedrock_async_client
Expand Down Expand Up @@ -287,8 +295,11 @@ async def azure_gpt_4o_mini_complete(
retry=retry_if_exception_type((RateLimitError, APIConnectionError)),
)
async def azure_openai_embedding(texts: list[str]) -> np.ndarray:
azure_openai_client = get_azure_openai_async_client_instance()

azure_openai_client = get_azure_openai_emb_async_client_instance()

response = await azure_openai_client.embeddings.create(
model="text-embedding-3-small", input=texts, encoding_format="float"
model="text-embedding-3-small", input=texts, encoding_format="float"
)

return np.array([dp.embedding for dp in response.data])
Loading