Last active
April 11, 2024 08:05
-
-
Save izikeros/523a5cf492cc6908733d1fbb2a820d98 to your computer and use it in GitHub Desktop.
[Langchain OpenAI biolerplate] The small example that can be a test if RAGAS and openai are configured properly and both works #langchain #openai
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Smoke test for the Azure OpenAI model from langchain_openai. | |
Check if the API is working as expected and all the required environment variables are set. | |
Requires the following environment variables (you can use it as .env_template): | |
AZURE_OPENAI_API_KEY= | |
AZURE_OPENAI_API_VERSION= | |
AZURE_OPENAI_ENDPOINT= | |
COMPLETION_DEPLOYMENT_NAME= | |
""" | |
import os | |
from dotenv import load_dotenv | |
from langchain_core.messages import HumanMessage | |
from langchain_openai import AzureChatOpenAI | |
load_dotenv() | |
model = AzureChatOpenAI( | |
api_version=os.getenv("AZURE_OPENAI_API_VERSION"), | |
azure_deployment=os.getenv("COMPLETION_DEPLOYMENT_NAME"), | |
) | |
message = HumanMessage( | |
content="Translate this sentence from English to French. I love programming." | |
) | |
print(model([message])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment