Skip to content
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

bug: Upgrade openai library following the langchain upgrade. #574

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from langchain_community.chat_models import AzureChatOpenAI
from langchain_openai import AzureChatOpenAI

from ..base import ModelAdapter
from genai_core.registry import registry
Expand All @@ -24,7 +24,7 @@ def get_llm(self, model_kwargs={}):
params["max_tokens"] = model_kwargs["maxTokens"]

return AzureChatOpenAI(
openai_api_base=os.environ.get(f"AZURE_OPENAI_API_BASE__{self.model_id}"),
azure_endpoint=os.environ.get(f"AZURE_OPENAI_API_BASE__{self.model_id}"),
deployment_name=os.environ.get(
f"AZURE_OPENAI_API_DEPLOYMENT_NAME__{self.model_id}"
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from langchain_community.chat_models import ChatOpenAI
from langchain_openai import ChatOpenAI
from ..base import ModelAdapter
from genai_core.registry import registry

Expand Down
2 changes: 1 addition & 1 deletion lib/shared/file-import-batch-job/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ psycopg2-binary==2.9.7
pgvector==0.2.2
pydantic==2.4.0
urllib3<2
openai==0.28.0
openai==1.47.0
beautifulsoup4==4.12.2
requests==2.32.2
attrs==23.1.0
Expand Down
3 changes: 2 additions & 1 deletion lib/shared/layers/common/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ requests-aws4auth==1.2.3
langchain==0.2.14
langchain-community==0.2.12
langchain-aws==0.1.17
langchain-openai==0.1.25
openai==1.47.0
opensearch-py==2.4.2
psycopg2-binary==2.9.7
pgvector==0.2.2
pydantic==2.4.0
urllib3<2
openai==0.28.1
beautifulsoup4==4.12.2
requests==2.32.0
attrs==23.1.0
Expand Down
4 changes: 2 additions & 2 deletions lib/shared/layers/python-sdk/python/genai_core/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def _generate_embeddings_openai(model: EmbeddingsModel, input: List[str]):
if not openai:
raise CommonError("OpenAI API is not available. Please set OPENAI_API_KEY.")

data = openai.Embedding.create(input=input, model=model.name)["data"]
ret_value = list(map(lambda x: x["embedding"], data))
data = openai.embeddings.create(input=input, model=model.name).data
ret_value = list(map(lambda x: x.embedding, data))

return ret_value

Expand Down
29 changes: 15 additions & 14 deletions lib/shared/layers/python-sdk/python/genai_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,22 @@ def list_openai_models():
if not openai:
return None

models = openai.Model.list()
models = []
for model in openai.models.list():
if model.id.startswith("gpt"):
models.append(
{
"provider": Provider.OPENAI.value,
"name": model.id,
"streaming": True,
"inputModalities": [Modality.TEXT.value],
"outputModalities": [Modality.TEXT.value],
"interface": ModelInterface.LANGCHAIN.value,
"ragSupported": True,
}
)

return [
{
"provider": Provider.OPENAI.value,
"name": model["id"],
"streaming": True,
"inputModalities": [Modality.TEXT.value],
"outputModalities": [Modality.TEXT.value],
"interface": ModelInterface.LANGCHAIN.value,
"ragSupported": True,
}
for model in models.data
if model["id"].startswith("gpt")
]
return models


def list_azure_openai_models():
Expand Down
Loading