pub struct ThreadSafeRandAgent { /* private fields */ }Expand description
推荐使用 ThreadSafeRandAgent,不推荐使用 RandAgent。 RandAgent 已不再维护,ThreadSafeRandAgent 支持多线程并发访问且更安全。 线程安全的 RandAgent,支持多线程并发访问
Implementations§
Source§impl ThreadSafeRandAgent
impl ThreadSafeRandAgent
Sourcepub fn with_max_failures_and_callback(
agents: Vec<(BoxAgent<'static>, i32, String, String)>,
max_failures: u32,
on_agent_invalid: OnAgentInvalidCallback,
) -> Self
pub fn with_max_failures_and_callback( agents: Vec<(BoxAgent<'static>, i32, String, String)>, max_failures: u32, on_agent_invalid: OnAgentInvalidCallback, ) -> Self
使用自定义最大失败次数和回调创建线程安全 RandAgent
Sourcepub fn with_max_failures(
agents: Vec<(BoxAgent<'static>, i32, String, String)>,
max_failures: u32,
) -> Self
pub fn with_max_failures( agents: Vec<(BoxAgent<'static>, i32, String, String)>, max_failures: u32, ) -> Self
使用自定义最大失败次数创建线程安全 RandAgent
Sourcepub fn set_on_agent_invalid<F>(&mut self, callback: F)
pub fn set_on_agent_invalid<F>(&mut self, callback: F)
设置 agent 失效时的回调
Sourcepub async fn add_agent(
&self,
agent: BoxAgent<'static>,
id: i32,
provider: String,
model: String,
)
pub async fn add_agent( &self, agent: BoxAgent<'static>, id: i32, provider: String, model: String, )
添加代理到集合中
Sourcepub async fn add_agent_with_max_failures(
&self,
agent: BoxAgent<'static>,
id: i32,
provider: String,
model: String,
max_failures: u32,
)
pub async fn add_agent_with_max_failures( &self, agent: BoxAgent<'static>, id: i32, provider: String, model: String, max_failures: u32, )
使用自定义最大失败次数添加代理
Sourcepub async fn get_random_valid_agent_index(&self) -> Option<usize>
pub async fn get_random_valid_agent_index(&self) -> Option<usize>
从集合中获取一个随机有效代理的索引
Sourcepub async fn get_random_valid_agent_state(&self) -> Option<ThreadSafeAgentState>
pub async fn get_random_valid_agent_state(&self) -> Option<ThreadSafeAgentState>
从集合中获取一个随机有效代理 注意: 并不会增加失败计数
Sourcepub async fn reset_failures(&self)
pub async fn reset_failures(&self)
重置所有代理的失败计数
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ThreadSafeRandAgent
impl !RefUnwindSafe for ThreadSafeRandAgent
impl Send for ThreadSafeRandAgent
impl Sync for ThreadSafeRandAgent
impl Unpin for ThreadSafeRandAgent
impl !UnwindSafe for ThreadSafeRandAgent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more