10. Runtime Arguments Binding
Runtime Arguments Binding
%pip install -qU langchain langchain-openaifrom langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
# Write the following equation using algebraic symbols, then solve it.
"Write out the following equation using algebraic symbols then solve it. "
"Use the format\n\nEQUATION:...\nSOLUTION:...\n\n",
),
(
"human",
"{equation_statement}", # Receives the equation sentence entered by the user as a variable.
),
]
)
# Initialize the ChatOpenAI model and set the temperature to 0.
model = ChatOpenAI(model="gpt-4", temperature=0)
# It takes an equation sentence as input and passes it to the prompt, and parses the results generated by the model into a string.
runnable = (
{"equation_statement": RunnablePassthrough()} | prompt | model | StrOutputParser()
)
# Enter an example equation sentence and print the result.
print(runnable.invoke("x raised to the third plus seven equals 12"))OpenAI Functions feature connection
Connect OpenAI tools
Last updated