Hi @Peter,
Thank you for reaching out to Microsoft Q&A forum!
I tried to repro the issue with the given code below and able to run the program:
import os
from langchain_openai import AzureChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage
# Set your Azure OpenAI credentials in environment variables
os.environ["AZURE_OPENAI_API_KEY"] = "<KEY>"
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://<ENDPOINT>.openai.azure.com/" # Ensure this is correct
os.environ["AZURE_OPENAI_DEPLOYMENT"] = "gpt-4o-mini" # Use your actual deployment name
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-05-15" # Check if this version is supported
# Initialize the AzureChatOpenAI model
model = AzureChatOpenAI(
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
azure_deployment=os.environ["AZURE_OPENAI_DEPLOYMENT"],
openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"]
)
# Create system and human messages
messages = [
SystemMessage(content="Translate the following from English into Italian"),
HumanMessage(content="hi!")
]
response = model.invoke(messages)
# Print the translation
print("Translation:", response)
Output:
Hope this helps. Do let us know if you any further queries.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful.