Struct rig::rag::RagAgentBuilder

source ·
pub struct RagAgentBuilder<M: CompletionModel, C: VectorStoreIndex, T: VectorStoreIndex> { /* private fields */ }
Expand description

Builder for creating a RAG agent

§Example

use rig::{providers::openai, rag_agent::RagAgentBuilder};
use serde_json::json;

let openai_client = openai::Client::from_env();

let model = openai_client.completion_model("gpt-4");

// Configure the agent
let agent = RagAgentBuilder::new(model)
    .preamble("System prompt")
    .static_context("Context document 1")
    .static_context("Context document 2")
    .dynamic_context(2, vector_index)
    .tool(tool1)
    .tool(tool2)
    .temperature(0.8)
    .additional_params(json!({"foo": "bar"}))
    .build();

Implementations§

source§

impl<M: CompletionModel, C: VectorStoreIndex, T: VectorStoreIndex> RagAgentBuilder<M, C, T>

source

pub fn new(model: M) -> Self

source

pub fn preamble(self, preamble: &str) -> Self

Set the system prompt

source

pub fn static_context(self, doc: &str) -> Self

Add a static context document to the RAG agent

source

pub fn static_tool(self, tool: impl Tool + 'static) -> Self

Add a static tool to the RAG agent

source

pub fn dynamic_context(self, sample: usize, dynamic_context: C) -> Self

Add some dynamic context to the RAG agent. On each prompt, sample documents from the dynamic context will be inserted in the request.

source

pub fn dynamic_tools( self, sample: usize, dynamic_tools: T, toolset: ToolSet, ) -> Self

Add some dynamic tools to the RAG agent. On each prompt, sample tools from the dynamic toolset will be inserted in the request.

source

pub fn temperature(self, temperature: f64) -> Self

Set the temperature of the model

source

pub fn build(self) -> RagAgent<M, C, T>

Build the RAG agent

Auto Trait Implementations§

§

impl<M, C, T> Freeze for RagAgentBuilder<M, C, T>
where M: Freeze,

§

impl<M, C, T> !RefUnwindSafe for RagAgentBuilder<M, C, T>

§

impl<M, C, T> Send for RagAgentBuilder<M, C, T>

§

impl<M, C, T> Sync for RagAgentBuilder<M, C, T>

§

impl<M, C, T> Unpin for RagAgentBuilder<M, C, T>
where M: Unpin, C: Unpin, T: Unpin,

§

impl<M, C, T> !UnwindSafe for RagAgentBuilder<M, C, T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more