pub struct LanguageModelRequestBuilder<M: LanguageModel, State = ModelStage> { /* private fields */ }Expand description
A type-state builder for constructing LanguageModelRequest instances.
This builder uses phantom types to enforce a specific construction order, ensuring that required fields (like the model) are set before optional ones.
§Type Parameters
M- The language model type.State- The current builder state, determining available methods.
Implementations§
Source§impl<M: LanguageModel> LanguageModelRequestBuilder<M, ModelStage>
Methods available in the ModelStage state.
impl<M: LanguageModel> LanguageModelRequestBuilder<M, ModelStage>
Methods available in the ModelStage state.
Sourcepub fn model(self, model: M) -> LanguageModelRequestBuilder<M, SystemStage>
pub fn model(self, model: M) -> LanguageModelRequestBuilder<M, SystemStage>
Sets the language model for the request.
This is the first required step in building a request.
§Parameters
model- The language model instance to use.
§Returns
The builder in the SystemStage state.
Source§impl<M: LanguageModel> LanguageModelRequestBuilder<M, SystemStage>
Methods available in the SystemStage state.
impl<M: LanguageModel> LanguageModelRequestBuilder<M, SystemStage>
Methods available in the SystemStage state.
Sourcepub fn system(
self,
system: impl Into<String>,
) -> LanguageModelRequestBuilder<M, ConversationStage>
pub fn system( self, system: impl Into<String>, ) -> LanguageModelRequestBuilder<M, ConversationStage>
Sets an optional system prompt for the request.
The system prompt provides context or instructions to the model.
§Parameters
system- The system prompt text.
§Returns
The builder in the ConversationStage state.
Sourcepub fn prompt(
self,
prompt: impl Into<String>,
) -> LanguageModelRequestBuilder<M, OptionsStage>
pub fn prompt( self, prompt: impl Into<String>, ) -> LanguageModelRequestBuilder<M, OptionsStage>
Sets a simple text prompt for the request.
This skips the system prompt and goes directly to options.
§Parameters
prompt- The user prompt text.
§Returns
The builder in the OptionsStage state.
Sourcepub fn messages(
self,
messages: Messages,
) -> LanguageModelRequestBuilder<M, OptionsStage>
pub fn messages( self, messages: Messages, ) -> LanguageModelRequestBuilder<M, OptionsStage>
Sets conversation messages for the request.
This allows for multi-turn conversations with the model.
§Parameters
messages-Messagesinstances representing the conversation.
§Returns
The builder in the OptionsStage state.
Source§impl<M: LanguageModel> LanguageModelRequestBuilder<M, ConversationStage>
Methods available in the ConversationStage state.
impl<M: LanguageModel> LanguageModelRequestBuilder<M, ConversationStage>
Methods available in the ConversationStage state.
Sourcepub fn prompt(
self,
prompt: impl Into<String>,
) -> LanguageModelRequestBuilder<M, OptionsStage>where
M: TextInputSupport,
pub fn prompt(
self,
prompt: impl Into<String>,
) -> LanguageModelRequestBuilder<M, OptionsStage>where
M: TextInputSupport,
Sets a simple text prompt for the request.
This method allows setting a user prompt. The prompt represents the user’s input to the language model.
§Parameters
prompt- The user prompt text.
§Returns
The builder in the OptionsStage state.
Sourcepub fn messages(
self,
messages: Messages,
) -> LanguageModelRequestBuilder<M, OptionsStage>where
M: TextInputSupport,
pub fn messages(
self,
messages: Messages,
) -> LanguageModelRequestBuilder<M, OptionsStage>where
M: TextInputSupport,
Sets conversation messages for the request.
This method allows providing a full conversation history as a vector of messages, enabling multi-turn conversations with the language model.
§Parameters
messages-Messagesinstances representing the conversation.
§Returns
The builder in the OptionsStage state.
Source§impl<M: LanguageModel> LanguageModelRequestBuilder<M, OptionsStage>
Methods available in the OptionsStage state.
impl<M: LanguageModel> LanguageModelRequestBuilder<M, OptionsStage>
Methods available in the OptionsStage state.
Sourcepub fn schema<T: JsonSchema>(self) -> Selfwhere
M: StructuredOutputSupport,
pub fn schema<T: JsonSchema>(self) -> Selfwhere
M: StructuredOutputSupport,
Sets the output schema for structured generation.
This method configures the language model to generate output that conforms
to the provided JSON schema. The schema is derived from the given type T.
§Type Parameters
T- A type that implementsJsonSchema, used to generate the output schema.
§Returns
The builder with the schema configured.
Sourcepub fn temperature(self, temperature: impl Into<u32>) -> Self
pub fn temperature(self, temperature: impl Into<u32>) -> Self
Sourcepub fn stop_sequences(self, stop_sequences: impl Into<Vec<String>>) -> Self
pub fn stop_sequences(self, stop_sequences: impl Into<Vec<String>>) -> Self
Sourcepub fn max_retries(self, max_retries: impl Into<u32>) -> Self
pub fn max_retries(self, max_retries: impl Into<u32>) -> Self
Sourcepub fn frequency_penalty(self, frequency_penalty: impl Into<f32>) -> Self
pub fn frequency_penalty(self, frequency_penalty: impl Into<f32>) -> Self
Sourcepub fn with_tool(self, tool: Tool) -> Selfwhere
M: ToolCallSupport,
pub fn with_tool(self, tool: Tool) -> Selfwhere
M: ToolCallSupport,
Sourcepub fn on_step_start<F>(self, hook: F) -> Self
pub fn on_step_start<F>(self, hook: F) -> Self
Sourcepub fn on_step_finish<F>(self, hook: F) -> Self
pub fn on_step_finish<F>(self, hook: F) -> Self
Sourcepub fn reasoning_effort(
self,
reasoning_effort: impl Into<ReasoningEffort>,
) -> Selfwhere
M: ReasoningSupport,
pub fn reasoning_effort(
self,
reasoning_effort: impl Into<ReasoningEffort>,
) -> Selfwhere
M: ReasoningSupport,
Sourcepub fn build(self) -> LanguageModelRequest<M>
pub fn build(self) -> LanguageModelRequest<M>
Builds the LanguageModelRequest.
This method consumes the builder and returns the configured request.
§Returns
The constructed LanguageModelRequest.
Methods from Deref<Target = LanguageModelOptions>§
Sourcepub fn step(&self, index: usize) -> Option<Step>
pub fn step(&self, index: usize) -> Option<Step>
Returns the step with the given index, if it exists.
Sourcepub fn content(&self) -> Option<&LanguageModelResponseContentType>
pub fn content(&self) -> Option<&LanguageModelResponseContentType>
Returns the content of the last assistant message, excluding reasoning.
Sourcepub fn tool_results(&self) -> Option<Vec<ToolResultInfo>>
pub fn tool_results(&self) -> Option<Vec<ToolResultInfo>>
Extracts all tool results from the conversation.
Sourcepub fn tool_calls(&self) -> Option<Vec<ToolCallInfo>>
pub fn tool_calls(&self) -> Option<Vec<ToolCallInfo>>
Extracts all tool calls from the conversation.
Sourcepub fn stop_reason(&self) -> Option<StopReason>
pub fn stop_reason(&self) -> Option<StopReason>
Returns the reason why generation stopped.