Find answers from the community

Updated 2 months ago

Classify Structured Llm Without Setup

Plain Text
class classify(BaseModel):
    check_docs: int
    web_search: int
    mentioned_company: str


classify_llm = llm.as_structured_llm(output_cls=classify)
fprompt = CLASSIFICATION.format(
    user_input="How can I contact your firm?")
response = classify_llm.chat([ChatMessage(
    role="user", content=fprompt)])

print(response.raw.check_docs)
print(response.raw.web_search)
print(response.raw.mentioned_company)

Is there a way to do this without setting up a structured llm every time for different objects.
s
L
5 comments
I am actually not using an agent I was just trying to get a structured output from an llm using pydantic.
I found about the structured_predict, so basically I want to use the default llm to return multiple different pydantic objects in different places, for example I want to use the same llm to return an order pydantic object in one place and item object in another
Plain Text
ptemplate = PromptTemplate(CLASSIFICATION)
response2 = llm.structured_predict(
    classify,
    ptemplate,
    user_input="How can I contact your firm?"
)
this is the most optimal way right? @Logan M
Add a reply
Sign up and join the conversation on Discord