Skip to main content

GopherAgent

Struct GopherAgent 

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

A gopher-orch agent for running AI queries.

Implementations§

Source§

impl GopherAgent

Source

pub fn create(config: Config) -> Result<Self>

Create a new GopherAgent with the given configuration.

Examples found in repository?
examples/client_example_json.rs (line 46)
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 create_with_api_key( provider: &str, model: &str, api_key: &str, ) -> Result<Self>

Create a new GopherAgent with an API key.

Source

pub fn create_with_server_config( provider: &str, model: &str, server_config: &str, ) -> Result<Self>

Create a new GopherAgent with a server config.

Source

pub fn run(&self, query: &str) -> Result<String>

Run a query against the agent with the default timeout (60 seconds).

Examples found in repository?
examples/client_example_json.rs (line 67)
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 run_with_timeout(&self, query: &str, timeout_ms: u64) -> Result<String>

Run a query against the agent with a custom timeout.

Source

pub fn run_detailed(&self, query: &str) -> AgentResult

Run a query and return detailed result information.

Source

pub fn run_detailed_with_timeout( &self, query: &str, timeout_ms: u64, ) -> AgentResult

Run a query with custom timeout and return detailed result.

Source

pub fn is_disposed(&self) -> bool

Check if the agent has been disposed.

Trait Implementations§

Source§

impl Drop for GopherAgent

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for GopherAgent

Source§

impl Sync for GopherAgent

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.