Skip to content

Commit

Permalink
Update to OPENAI_API_VERSION
Browse files Browse the repository at this point in the history
Signed-off-by: Brynn Yin <biyi@microsoft.com>
  • Loading branch information
brynn-code committed Mar 5, 2024
1 parent d2e0ec6 commit 343d29e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/how-to-guides/manage-connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Supported types are as follows:
| | base_url | OPENAI_BASE_URL |
| AzureOpenAIConnection | api_key | AZURE_OPENAI_API_KEY |
| | api_base | AZURE_OPENAI_ENDPOINT |
| | api_version | OPENAI_API_VERSION _or_ AZURE_OPENAI_API_VERSION |
| | api_version | OPENAI_API_VERSION |

For example, with `OPENAI_API_KEY` set to environment, an `OpenAIConnection` object can be loaded with `OpenAIConnection.from_env()`.

Expand Down
2 changes: 1 addition & 1 deletion examples/flows/standard/basic/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_client():
from openai import AzureOpenAI as Client
conn.update(
azure_endpoint=os.environ["AZURE_OPENAI_API_BASE"],
api_version=os.environ.get("AZURE_OPENAI_API_VERSION", "2023-07-01-preview"),
api_version=os.environ.get("OPENAI_API_VERSION", "2023-07-01-preview"),
)
return Client(**conn)

Expand Down
4 changes: 2 additions & 2 deletions src/promptflow/promptflow/_sdk/entities/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ def from_env(cls, name="default_env_connection"):
# Env var name reference: https://github.com/openai/openai-python/blob/main/src/openai/lib/azure.py#L160
api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
api_key = os.getenv("AZURE_OPENAI_API_KEY")
# Note: OpenAI supports OPENAI_API_VERSION, but we also enrich AZURE_OPENAI_API_VERSION for consistency.
api_version = os.getenv("OPENAI_API_VERSION") or os.getenv("AZURE_OPENAI_API_VERSION")
# Note: Name OPENAI_API_VERSION from OpenAI.
api_version = os.getenv("OPENAI_API_VERSION")
if api_base is None or api_key is None:
raise RequiredEnvironmentVariablesNotSetError(
env_vars=["AZURE_OPENAI_ENDPOINT", "AZURE_OPENAI_API_KEY"], cls_name=cls.__name__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def test_connection_from_env(self):
{
"AZURE_OPENAI_ENDPOINT": "test_endpoint",
"AZURE_OPENAI_API_KEY": "test_key",
"AZURE_OPENAI_API_VERSION": "2024-01-01-preview",
"OPENAI_API_VERSION": "2024-01-01-preview",
},
):
connection = AzureOpenAIConnection.from_env("test_connection")
Expand Down

0 comments on commit 343d29e

Please sign in to comment.