You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we pass a pydantic.BaseModel as output type to the prompt without passing the schema itself to the system prompt, we are getting parsing errors - the desired structure is not preserved in raw LLM output even though using models that support that feature described here: https://platform.openai.com/docs/guides/structured-outputs .
How can we reproduce it?
importasynciofrompydanticimportBaseModelfromragbits.core.promptimportPromptfromragbits.core.llms.litellmimportLiteLLMclassQueryWithContext(BaseModel):
""" Input format for the QueryWithContext. """query: strcontext: list[str]
classOutputSchema(BaseModel):
last: strprevious: strclassRAGPrompt(Prompt[QueryWithContext, OutputSchema]):
""" A simple prompt for RAG system. """system_prompt=f""" You are a helpful assistant. Answer the QUESTION that will be provided using CONTEXT. If in the given CONTEXT there is not enough information refuse to answer. """user_prompt=""" QUESTION: {{ query }} CONTEXT: {% for item in context %} {{ item }} {% endfor %} """asyncdefmain():
llm=LiteLLM(model_name="gpt-4o-2024-08-06")
query="Write down names of last two world cup winners"context= ["Today is November 2017", "Germany won 2014 world cup", "Spain won 2010 world cup"]
prompt=RAGPrompt(QueryWithContext(query=query, context=context))
response=awaitllm.generate(prompt)
print(response)
asyncio.run(main())
Relevant log output
No response
The text was updated successfully, but these errors were encountered:
What happened?
When we pass a
pydantic.BaseModel
as output type to the prompt without passing the schema itself to the system prompt, we are getting parsing errors - the desired structure is not preserved in raw LLM output even though using models that support that feature described here: https://platform.openai.com/docs/guides/structured-outputs .How can we reproduce it?
Relevant log output
No response
The text was updated successfully, but these errors were encountered: