Skip to content
Merged
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
10 changes: 5 additions & 5 deletions examples/azure-openai/langchain_azure_universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
javelin_api_key = os.getenv("JAVELIN_API_KEY")
base_url = os.getenv("JAVELIN_BASE_URL")

# The name of your Azure deployment (e.g., "gpt-4")
# The name of your Azure deployment (e.g., "gpt35")
# or whatever you’ve set in Azure. Must also match x-javelin-model if
# Javelin expects that.
model_choice = "gpt-4"
model_choice = "gpt35"

# Javelin route name, as registered in your javelin route dashboard
route_name = "azureopenai_univ"
Expand All @@ -34,14 +34,14 @@
# Provide your actual API version
api_version="2024-08-01-preview",
# The base_url is Javelin’s universal route
base_url=f"{base_url}/v1/azureopenai/deployments/gpt-4/",
base_url=f"{base_url}/v1/openai/deployments/gpt35/",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better maintainability, it's recommended to use the model_choice variable defined on line 21 instead of hardcoding the model name gpt35 in the base_url. This ensures that if the model is changed in one place, it's updated everywhere, preventing potential mismatches between the x-javelin-model header and the deployment name in the URL.

Suggested change
base_url=f"{base_url}/v1/openai/deployments/gpt35/",
base_url=f"{base_url}/v1/openai/deployments/{model_choice}/",

validate_base_url=False,
verbose=True,
default_headers={
"x-javelin-apikey": javelin_api_key,
"x-javelin-route": route_name,
"x-javelin-model": model_choice,
"x-javelin-provider": "https://javelinpreview.openai.azure.com/openai",
"x-javelin-provider": "https://javelinpreview.openai.azure.com",
},
streaming=False, # Non-streaming
)
Expand Down Expand Up @@ -92,7 +92,7 @@ def invoke_streaming(question: str) -> str:
llm_streaming = AzureChatOpenAI(
openai_api_key=azure_openai_api_key,
api_version="2024-08-01-preview",
base_url=f"{base_url}/v1/azureopenai/deployments/gpt-4/",
base_url=f"{base_url}/v1/azureopenai/deployments/gpt35/",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

This base_url has two issues:

  1. Hardcoded Model Name: Similar to the non-streaming function, the model name gpt35 is hardcoded. It should use the model_choice variable to avoid inconsistencies.
  2. Inconsistent URL Path: The path segment azureopenai is used here, while the non-streaming function on line 37 uses openai. This inconsistency is likely a bug and may cause this streaming example to fail. It should probably be openai to match the other function.

Combining these fixes will improve correctness and maintainability.

Suggested change
base_url=f"{base_url}/v1/azureopenai/deployments/gpt35/",
base_url=f"{base_url}/v1/openai/deployments/{model_choice}/",

validate_base_url=False,
verbose=True,
default_headers={
Expand Down
Loading