pub struct RandAgent { /* private fields */ }Expand description
推荐使用 RandAgent,不推荐使用 RandAgent。 RandAgent 已不再维护,RandAgent 支持多线程并发访问且更安全。 线程安全的 RandAgent,支持多线程并发访问
Implementations§
Source§impl RandAgent
impl RandAgent
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<AgentState>
pub async fn get_random_valid_agent_state(&self) -> Option<AgentState>
从集合中获取一个随机有效代理 注意: 并不会增加失败计数
Sourcepub async fn get_agents_info(&self) -> Vec<AgentInfo>
pub async fn get_agents_info(&self) -> Vec<AgentInfo>
获取agent info
Sourcepub async fn reset_failures(&self)
pub async fn reset_failures(&self)
重置所有代理的失败计数
Sourcepub async fn get_agent_by_name(
&self,
provider_name: &str,
model_name: &str,
) -> Option<AgentState>
pub async fn get_agent_by_name( &self, provider_name: &str, model_name: &str, ) -> Option<AgentState>
通过名称获取 agent
Sourcepub async fn get_agent_by_id(&self, id: i32) -> Option<AgentState>
pub async fn get_agent_by_id(&self, id: i32) -> Option<AgentState>
通过id获取 agent
Sourcepub async fn try_invoke_with_retry(
&self,
info: Message,
retry_num: Option<usize>,
) -> Result<String, RandAgentError>
pub async fn try_invoke_with_retry( &self, info: Message, retry_num: Option<usize>, ) -> Result<String, RandAgentError>
添加失败重试
pub async fn prompt_with_info( &self, prompt: impl Into<Message> + Send, ) -> Result<(String, AgentInfo), PromptError>
Sourcepub async fn try_invoke_with_info_retry(
&self,
info: Message,
retry_num: Option<usize>,
) -> Result<(String, AgentInfo), RandAgentError>
pub async fn try_invoke_with_info_retry( &self, info: Message, retry_num: Option<usize>, ) -> Result<(String, AgentInfo), RandAgentError>
添加失败重试
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RandAgent
impl !RefUnwindSafe for RandAgent
impl Send for RandAgent
impl Sync for RandAgent
impl Unpin for RandAgent
impl !UnwindSafe for RandAgent
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