RandAgent

Struct RandAgent 

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

推荐使用 RandAgent,不推荐使用 RandAgent。 RandAgent 已不再维护,RandAgent 支持多线程并发访问且更安全。 线程安全的 RandAgent,支持多线程并发访问

Implementations§

Source§

impl RandAgent

Source

pub fn new(agents: Vec<(AgentVariant, i32, String, String)>) -> Self

创建新的线程安全 RandAgent

Source

pub fn with_max_failures_and_callback( agents: Vec<(AgentVariant, i32, String, String)>, max_failures: u32, on_agent_invalid: OnAgentInvalidCallback, ) -> Self

使用自定义最大失败次数和回调创建线程安全 RandAgent

Source

pub fn with_max_failures( agents: Vec<(AgentVariant, i32, String, String)>, max_failures: u32, ) -> Self

使用自定义最大失败次数创建线程安全 RandAgent

Source

pub fn set_on_agent_invalid<F>(&mut self, callback: F)
where F: Fn(i32) + Send + Sync + 'static,

设置 agent 失效时的回调

Source

pub async fn add_agent( &self, agent: AgentVariant, id: i32, provider: String, model: String, )

添加代理到集合中

Source

pub async fn add_agent_with_max_failures( &self, agent: AgentVariant, id: i32, provider: String, model: String, max_failures: u32, )

使用自定义最大失败次数添加代理

Source

pub async fn len(&self) -> usize

获取有效代理数量

Source

pub async fn get_random_valid_agent_index(&self) -> Option<usize>

从集合中获取一个随机有效代理的索引

Source

pub async fn get_random_valid_agent_state(&self) -> Option<AgentState>

从集合中获取一个随机有效代理 注意: 并不会增加失败计数

Source

pub async fn total_len(&self) -> usize

获取总代理数量(包括无效的)

Source

pub async fn is_empty(&self) -> bool

检查是否有有效代理

Source

pub async fn get_agents_info(&self) -> Vec<AgentInfo>

获取agent info

Source

pub async fn failure_stats(&self) -> Vec<(usize, u32, u32)>

获取失败统计

Source

pub async fn reset_failures(&self)

重置所有代理的失败计数

Source

pub async fn get_agent_by_name( &self, provider_name: &str, model_name: &str, ) -> Option<AgentState>

通过名称获取 agent

Source

pub async fn get_agent_by_id(&self, id: i32) -> Option<AgentState>

通过id获取 agent

Source

pub async fn try_invoke_with_retry( &self, info: Message, retry_num: Option<usize>, ) -> Result<String, RandAgentError>

添加失败重试

Source

pub async fn prompt_with_info( &self, prompt: impl Into<Message> + Send, ) -> Result<(String, AgentInfo), PromptError>

Source

pub async fn try_invoke_with_info_retry( &self, info: Message, retry_num: Option<usize>, ) -> Result<(String, AgentInfo), RandAgentError>

添加失败重试

Trait Implementations§

Source§

impl Clone for RandAgent

Source§

fn clone(&self) -> RandAgent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Prompt for RandAgent

Source§

async fn prompt( &self, prompt: impl Into<Message> + Send, ) -> Result<String, PromptError>

Send a simple prompt to the underlying completion model. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
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
Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,