Skip to main content

ConfigBuilder

Struct ConfigBuilder 

Source
pub struct ConfigBuilder { /* private fields */ }
Expand description

Builder for creating Config instances.

Implementations§

Source§

impl ConfigBuilder

Source

pub fn new() -> Self

Create a new ConfigBuilder.

Examples found in repository?
examples/client_example_json.rs (line 40)
35fn main() {
36    let provider = "AnthropicProvider";
37    let model = "claude-3-haiku-20240307";
38
39    // Create agent with JSON server configuration
40    let config = ConfigBuilder::new()
41        .with_provider(provider)
42        .with_model(model)
43        .with_server_config(SERVER_CONFIG)
44        .build();
45
46    let agent = match GopherAgent::create(config) {
47        Ok(agent) => agent,
48        Err(e) => {
49            eprintln!("Error: {}", e);
50            std::process::exit(1);
51        }
52    };
53
54    println!("GopherAgent created!");
55
56    // Get question from command line args or use default
57    let args: Vec<String> = env::args().collect();
58    let question = if args.len() > 1 {
59        args[1..].join(" ")
60    } else {
61        "What is the weather like in New York?".to_string()
62    };
63
64    println!("Question: {}", question);
65
66    // Run the query
67    match agent.run(&question) {
68        Ok(answer) => {
69            println!("Answer:");
70            println!("{}", answer);
71        }
72        Err(e) => {
73            eprintln!("Error: {}", e);
74            std::process::exit(1);
75        }
76    }
77}
Source

pub fn with_provider<S: Into<String>>(self, provider: S) -> Self

Set the provider name.

Examples found in repository?
examples/client_example_json.rs (line 41)
35fn main() {
36    let provider = "AnthropicProvider";
37    let model = "claude-3-haiku-20240307";
38
39    // Create agent with JSON server configuration
40    let config = ConfigBuilder::new()
41        .with_provider(provider)
42        .with_model(model)
43        .with_server_config(SERVER_CONFIG)
44        .build();
45
46    let agent = match GopherAgent::create(config) {
47        Ok(agent) => agent,
48        Err(e) => {
49            eprintln!("Error: {}", e);
50            std::process::exit(1);
51        }
52    };
53
54    println!("GopherAgent created!");
55
56    // Get question from command line args or use default
57    let args: Vec<String> = env::args().collect();
58    let question = if args.len() > 1 {
59        args[1..].join(" ")
60    } else {
61        "What is the weather like in New York?".to_string()
62    };
63
64    println!("Question: {}", question);
65
66    // Run the query
67    match agent.run(&question) {
68        Ok(answer) => {
69            println!("Answer:");
70            println!("{}", answer);
71        }
72        Err(e) => {
73            eprintln!("Error: {}", e);
74            std::process::exit(1);
75        }
76    }
77}
Source

pub fn with_model<S: Into<String>>(self, model: S) -> Self

Set the model name.

Examples found in repository?
examples/client_example_json.rs (line 42)
35fn main() {
36    let provider = "AnthropicProvider";
37    let model = "claude-3-haiku-20240307";
38
39    // Create agent with JSON server configuration
40    let config = ConfigBuilder::new()
41        .with_provider(provider)
42        .with_model(model)
43        .with_server_config(SERVER_CONFIG)
44        .build();
45
46    let agent = match GopherAgent::create(config) {
47        Ok(agent) => agent,
48        Err(e) => {
49            eprintln!("Error: {}", e);
50            std::process::exit(1);
51        }
52    };
53
54    println!("GopherAgent created!");
55
56    // Get question from command line args or use default
57    let args: Vec<String> = env::args().collect();
58    let question = if args.len() > 1 {
59        args[1..].join(" ")
60    } else {
61        "What is the weather like in New York?".to_string()
62    };
63
64    println!("Question: {}", question);
65
66    // Run the query
67    match agent.run(&question) {
68        Ok(answer) => {
69            println!("Answer:");
70            println!("{}", answer);
71        }
72        Err(e) => {
73            eprintln!("Error: {}", e);
74            std::process::exit(1);
75        }
76    }
77}
Source

pub fn with_api_key<S: Into<String>>(self, api_key: S) -> Self

Set the API key.

Source

pub fn with_server_config<S: Into<String>>(self, server_config: S) -> Self

Set the server config JSON.

Examples found in repository?
examples/client_example_json.rs (line 43)
35fn main() {
36    let provider = "AnthropicProvider";
37    let model = "claude-3-haiku-20240307";
38
39    // Create agent with JSON server configuration
40    let config = ConfigBuilder::new()
41        .with_provider(provider)
42        .with_model(model)
43        .with_server_config(SERVER_CONFIG)
44        .build();
45
46    let agent = match GopherAgent::create(config) {
47        Ok(agent) => agent,
48        Err(e) => {
49            eprintln!("Error: {}", e);
50            std::process::exit(1);
51        }
52    };
53
54    println!("GopherAgent created!");
55
56    // Get question from command line args or use default
57    let args: Vec<String> = env::args().collect();
58    let question = if args.len() > 1 {
59        args[1..].join(" ")
60    } else {
61        "What is the weather like in New York?".to_string()
62    };
63
64    println!("Question: {}", question);
65
66    // Run the query
67    match agent.run(&question) {
68        Ok(answer) => {
69            println!("Answer:");
70            println!("{}", answer);
71        }
72        Err(e) => {
73            eprintln!("Error: {}", e);
74            std::process::exit(1);
75        }
76    }
77}
Source

pub fn build(self) -> Config

Build the Config.

Examples found in repository?
examples/client_example_json.rs (line 44)
35fn main() {
36    let provider = "AnthropicProvider";
37    let model = "claude-3-haiku-20240307";
38
39    // Create agent with JSON server configuration
40    let config = ConfigBuilder::new()
41        .with_provider(provider)
42        .with_model(model)
43        .with_server_config(SERVER_CONFIG)
44        .build();
45
46    let agent = match GopherAgent::create(config) {
47        Ok(agent) => agent,
48        Err(e) => {
49            eprintln!("Error: {}", e);
50            std::process::exit(1);
51        }
52    };
53
54    println!("GopherAgent created!");
55
56    // Get question from command line args or use default
57    let args: Vec<String> = env::args().collect();
58    let question = if args.len() > 1 {
59        args[1..].join(" ")
60    } else {
61        "What is the weather like in New York?".to_string()
62    };
63
64    println!("Question: {}", question);
65
66    // Run the query
67    match agent.run(&question) {
68        Ok(answer) => {
69            println!("Answer:");
70            println!("{}", answer);
71        }
72        Err(e) => {
73            eprintln!("Error: {}", e);
74            std::process::exit(1);
75        }
76    }
77}

Trait Implementations§

Source§

impl Debug for ConfigBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConfigBuilder

Source§

fn default() -> ConfigBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, 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.