rise-ai / agent /jsonencoder.py
markpeace's picture
basic chat is working again
224ff63
raw
history blame
1.36 kB
from langchain_openai import ChatOpenAI
from agent.datastructures import parser
model = ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0)
#from langchain_core.utils.function_calling import convert_pydantic_to_openai_function
#from agent.datastructures import ResponseSchema
#converted_tools = [convert_pydantic_to_openai_function(ResponseSchema)]
#model.bind_functions(convert_pydantic_to_openai_function(ResponseSchema))
from langchain.prompts import ChatPromptTemplate,PromptTemplate, MessagesPlaceholder,SystemMessagePromptTemplate
prompt = PromptTemplate(
template="""
{format_instructions}
Only provide a single JSON blob, beginning with '{{' and ending with '}}'
/n {input} /n
""",
input_variables=["input"],
partial_variables={"format_instructions": parser.get_format_instructions()},
)
prompt = ChatPromptTemplate.from_messages(
[
("system", "The thread_id of this conversation is {thread_id}."),
("system", "You will be given the chat so far, you should render the final answer as a JSON object"),
SystemMessagePromptTemplate.from_template("{format_instructions}").format(format_instructions=parser.get_format_instructions()),
MessagesPlaceholder(variable_name="conversation"),
]
)
json_parse_chain = prompt | model | parser