Langchain 学习04 LCEL 01
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
api_key = os.environ['AZURE_OPENAI_API_KEY']
azure_endpoint = os.environ['AZURE_OPENAI_ENDPOINT']
api_version = os.environ['AZURE_OPENAPI_VERSION']
model="gpt-35-turbo"
deployment_name="gpt-35-turbo"
from langchain_openai import AzureChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough
prompt = ChatPromptTemplate.from_template(
"Tell me a short joke about {topic}"
)
output_parser = StrOutputParser()
model = AzureChatOpenAI(
model=model,
deployment_name=deployment_name,
api_key=api_key,
azure_endpoint=azure_endpoint,
api_version=api_version,
)
chain = (
{"topic": RunnablePassthrough()}
| prompt
| model
| output_parser
)
print(chain.invoke("ice cream"))