Skip to content

How can I use instructor with multiple functions - in a more agentic system where the LLM chooses the function to call? #296

Answered by jxnl
zby asked this question in Q&A
Discussion options

You must be logged in to vote
# Union of Search, Lookup, and Finish
class TakeAction(BaseModel):
    action: Union[Search, Lookup, Finish]

    def process(self):
        """Process the action."""
        return self.action.process()


# Enables `response_model`
client = instructor.patch(OpenAI())

action = client.chat.completions.create(
    model="gpt-3.5-turbo",
    response_model=TakeAction,
    messages=[
        {"role": "user", "content": "I need to find information about Python"},
    ],
)

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
7 replies
@zby
Comment options

@zby
Comment options

@jxnl
Comment options

@jxnl
Comment options

Answer selected by zby
@zby
Comment options

@jxnl
Comment options

@zby
Comment options

Comment options

You must be logged in to vote
2 replies
@jxnl
Comment options

@zby
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants