Module rig::completion
source · Expand description
This module contains the implementation of the completion functionality for the LLM (Large Language Model) chat interface. It provides traits, structs, and enums for generating completion requests, handling completion responses, and defining completion models.
The main traits defined in this module are:
Prompt
: Defines a high-level LLM chat interface for prompting and receiving responses.Completion
: Defines a low-level LLM completion interface for generating completion requests.CompletionModel
: Defines a completion model that can be used to generate completion responses.
The module also provides various structs and enums for representing generic completion requests, responses, and errors.
Example Usage:
use rig::providers::openai::{Client, self};
use rig::completion::*;
// Initialize the OpenAI client and a completion model
let openai = Client::new("your-openai-api-key");
let model = openai.model(openai::GPT_4).build();
// Create the completion request
let builder = model.completion_request("Who are you?");
.preamble(
"You are Marvin, an extremely smart but depressed robot who is nonetheless helpful towards humanity.".to_string())
.build();
// Send the completion request and get the completion response
let response = model.completion(request)
.await
.expect("Failed to get completion response");
// Handle the completion response
match completion_response.choice {
ModelChoice::Message(message) => {
// Handle the completion response as a message
println!("Received message: {}", message);
}
ModelChoice::ToolCall(tool_name, tool_params) => {
// Handle the completion response as a tool call
println!("Received tool call: {} {:?}", tool_name, tool_params);
}
}
For more information on how to use the completion functionality, refer to the documentation of the individual traits, structs, and enums defined in this module.
Structs§
- Struct representing a general completion request that can be sent to a completion model provider.
- Builder struct for constructing a completion request.
- General completion response struct that contains the high-level completion choice and the raw response.
Enums§
- Enum representing the high-level completion choice returned by the completion model provider.
Traits§
- Trait defining a high-level LLM chat interface (i.e.: prompt and chat hiroty in, response out).
- Trait defininig a low-level LLM completion interface
- Trait defining a completion model that can be used to generate completion responses. This trait is meant to be implemented by the user to define a custom completion model, either from a third party provider (e.g.: OpenAI) or locally.
- Trait defining a high-level LLM on-shot prompt interface (i.e.: prompt in, response out).