Overview
In this example, we will demonstrate how to leverage the enums and typed arrays to segment a complex search prompt into multiple, better structured queries that can be executed separately against specialized APIs or search engines.Why it matters
Extracting a list of tasks from text is a common use case for leveraging language models. This pattern can be applied to various applications, such as virtual assistants like Siri or Alexa, where understanding user intent and breaking down requests into actionable tasks is crucial. In this example, we will demonstrate how to use Instructor to segment search queries, so you can execute them separately against specialized APIs or search engines.Structure of the data
TheSearchQuery is a PHP class that defines the structure of an individual
search query.
It has three fields: title, query, and type. The title field is the title
of the request, the query field is the query to search for relevant content, and
the type field is the type of search. The execute method is used to execute the
search query.
Example
Segmenting the Search Prompt
Thesegment function takes a string data and segments it into multiple search queries.
It uses the StructuredOutput::create() method to extract the data into the target object.
The responseModel parameter specifies Search::class as the model to use for extraction.