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

Env Variables | Must provide one of the 'base_url' or 'azure_endpoint' arguments #286

Open
delicpsyche opened this issue Apr 9, 2024 · 1 comment

Comments

@delicpsyche
Copy link

I am using Azure Open AI Chat deployment , and my .env looks like this

AZURE_OPENAI_DEPLOYMENT_NAME=chat
AZURE_OPENAI_API_KEY="XXXXXXXXXXXX"
AZURE_OPENAI_API_BASE="https://XXXXXXXXX.openai.azure.com/"
AZURE_OPENAI_API_VERSION="2024-03-01-preview"
POSTGRES_PORT=5432
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres

When doing a docker compose , I error out at

opengpts-backend | File "/backend/app/tools.py", line 27, in <module>
opengpts-backend | from app.upload import vstore
opengpts-backend | File "/backend/app/upload.py", line 138, in <module>
opengpts-backend | vstore = _determine_azure_or_openai_embeddings()
opengpts-backend | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
opengpts-backend | File "/backend/app/upload.py", line 66, in _determine_azure_or_openai_embeddings
opengpts-backend | embedding_function=AzureOpenAIEmbeddings(),
opengpts-backend | ^^^^^^^^^^^^^^^^^^^^^^^
opengpts-backend | File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
opengpts-backend | pydantic.error_wrappers.ValidationError: 1 validation error for AzureOpenAIEmbeddings
opengpts-backend | __root__
opengpts-backend | Must provide one of the 'base_url' or 'azure_endpoint' arguments, or the 'AZURE_OPENAI_ENDPOINT' environment variable (type=value_error)

Not sure what I am doing wrong.

@tnakagami
Copy link

@delicpsyche

I am not a developer, but I would like to comment (I am still learning English, so some of the expressions may be difficult to understand).

The AzureOpenAIEmbeddings implemented in langchain_openai is configured to read the following environment variables.

  • AZURE_OPENAI_API_KEY
  • AZURE_OPENAI_ENDPOINT
  • OPENAI_API_VERSION

For this reason, you will need to rewrite your .env as follows.

AZURE_OPENAI_DEPLOYMENT_NAME=chat
AZURE_OPENAI_API_KEY="XXXXXXXXXXXX"
AZURE_OPENAI_ENDPOINT="https://XXXXXXXXX.openai.azure.com/"
OPENAI_API_VERSION="2024-03-01-preview"
POSTGRES_PORT=5432
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres

Or you can specify the following arguments when calling AzureOpenAIEmbedding.

import os
from langchain_openai import AzureOpenAIEmbeddings

# skip ...

vstore = PGVector(
    connection_string=PG_CONNECTION_STRING,
    embedding_function=AzureOpenAIEmbeddings(
        openai_api_key=os.getenv('AZURE_OPENAI_API_KEY'),
        azure_endpoint=os.getenv('AZURE_OPENAI_API_BASE'),
        openai_api_version=os.getenv('AZURE_OPENAI_API_VERSION'),
    ),
    use_jsonb=True,
)

For more information, check the following python script in the container (container name: opengpts-backend).

/usr/local/lib/python3.11/site-packages/langchain_openai/embeddings/azure.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants