Closed AnjaliKeshri closed 1 month ago
In command line: pip install langchain-openai
Instead of using from openai import AzureOpenAI
use from langchain_openai import AzureOpenAI
This is my modified 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."""
)
chain = prompt | client
response = chain.invoke({"api_url": url}) print(response)
but now i am getting this error
File "C:\Users\2282635\OneDrive - Cognizant\Desktop\Chatbot\Langchain\test-azure.py", line 25, in
check you azure_openai_endpoint or azure_openai_key
Checked other resources
Example Code
import os; from langchain.llms.openai import OpenAI from openai import AzureOpenAI from dotenv import load_dotenv from langchain.chains.api.base import LLMChain from langchain.chains.api.base import APIChain from langchain.chains.api import open_meteo_docs 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.""" )
chain = LLMChain( llm=client, verbose=True, prompt=prompt ) url = "https://pitchfork.com/api/v2/search/?genre=experimental&genre=global&genre=jazz&genre=metal&genre=pop&genre=rap&genre=rock&types=reviews&sort=publishdate%20desc%2Cposition%20asc&size=5&start=0&rating_from=0.0"
response = chain.run(url) print(response)
Error Message and Stack Trace (if applicable)
File "pydantic\main.py", line 341, in pydantic.main.BaseModel.init pydantic.error_wrappers.ValidationError: 2 validation errors for LLMChain llm instance of Runnable expected (type=type_error.arbitrary_type; expected_arbitrary_type=Runnable) llm instance of Runnable expected (type=type_error.arbitrary_type; expected_arbitrary_type=Runnable)
Description
I am trying to call an external api. Here i am using langchain version==0.1.0 pydantic==1.10.8 and openai==1.7.0 I am using azureopenai instead openai.. and whenever i want to use the LLMChain , i got this 2 validation error. I am confused that whether this is because of any version issue or the implementation of the code.
System Info
Python 3.10.11 langchain version==0.1.0 pydantic==1.10.8 openai==1.7.0 openapi-schema-pydantic==1.2.4