This React hook creates a completion instance that predicts structured data based on input context. The result object contains the predicted structured output and state for monitoring the completion.
API
export declare function useStructuredCompletion<
Input,
Schema extends s.SchemaOutput ,
State = unknown,
>(
options: UseStructuredCompletionOptions <
Input,
Schema,
State
>,
): UseStructuredCompletionResult <
s.InferSchemaOutput <Schema>,
State
>;useStructuredCompletion
UseStructuredCompletionResult<s.InferSchemaOutput<Schema>, State>@typeInput@typeSchemas.SchemaOutput@typeState@returnsUseStructuredCompletionResult<s.InferSchemaOutput<Schema>, State>Examples
In this example, the LLM will predict a color palette based on a given theme or mood.
const { output } = useStructuredCompletion({
system: `Predict a color palette based on the given mood or theme. For example,
if the theme is "Calm Ocean", suggest appropriate colors.`,
input: theme,
schema: s.object('Color Palette', {
colors: s.array(
'The colors in the palette',
s.string('Hex color code')
)
})
});