404 resource not found error

Keshri, Anjali (Cognizant) 0 Reputation points
2024-04-18T05:21:59.5566667+00:00

This is my code

import os; from langchain_openai import AzureOpenAI from dotenv import load_dotenv from langchain_core.prompts import PromptTemplate load_dotenv()

client = AzureOpenAI( api_key = os.getenv("AZURE_OPENAI_API_KEY"), api_version = "2024-02-15-preview", azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT") ) prompt = PromptTemplate( input_variables=["api_url"], template="""Act as a technical writer. Write detailed documentation for the API that exists at {api_url}. Only detail the request, do not describe the response. Do not include any parameters not in the sample endpoint.""" )

url = "https://api.open-meteo.com/v1/forecast?latitude=48.1351&longitude=11.5820&hourly=temperature_2m&temperature_unit=fahrenheit&current_weather=true"

chain = prompt | client

response = chain.invoke({"api_url": url}) print(response)

This is my error
openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,172 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Aki Nishikawa 485 Reputation points Microsoft Employee
    2024-04-23T11:52:49.53+00:00

    Hello Keshri, Anjali (Cognizant),

    No deployment name of model is specified when instantiating client with AzureOpenAI. Did you omit the deployment name from your code intentionally, or forget adding the deployment name?

    client = AzureOpenAI(
        api_key = os.getenv("AZURE_OPENAI_API_KEY"),
        api_version = "2024-02-15-preview",
        azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
        deployment_name="<deployment name>"
    )
    

    When the deployment name was added, your code worked on my environment.