pub struct OpenAIAgent {
pub api_key: String,
pub model: String,
/* private fields */
}Expand description
Agente para comunicação com a API OpenAI.
Este agente implementa a trait AIAgent e se conecta aos endpoints da
OpenAI para enviar prompts e obter respostas de modelos como GPT-3.5 e GPT-4.
Fields§
§api_key: StringChave de API do OpenAI
model: StringNome do modelo a ser usado (ex: “gpt-3.5-turbo”, “gpt-4”)
Implementations§
Source§impl OpenAIAgent
impl OpenAIAgent
Sourcepub fn new(
api_key: String,
model: String,
http_client: Box<dyn HttpClient>,
) -> Self
pub fn new( api_key: String, model: String, http_client: Box<dyn HttpClient>, ) -> Self
Cria uma nova instância do agente OpenAI.
§Argumentos
api_key- Chave de API da OpenAImodel- Nome do modelo a ser usadohttp_client- Cliente HTTP para fazer as requisições
§Exemplo
use mcprs::agent_openai::OpenAIAgent;
use mcprs::testing::ReqwestClient;
let agent = OpenAIAgent::new(
"sua-chave-api".to_string(),
"gpt-3.5-turbo".to_string(),
Box::new(ReqwestClient::new())
);Trait Implementations§
Source§impl AIAgent for OpenAIAgent
impl AIAgent for OpenAIAgent
Source§fn process_request<'life0, 'async_trait>(
&'life0 self,
message: MCPMessage,
) -> Pin<Box<dyn Future<Output = Result<MCPMessage, MCPError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn process_request<'life0, 'async_trait>(
&'life0 self,
message: MCPMessage,
) -> Pin<Box<dyn Future<Output = Result<MCPMessage, MCPError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Processa uma requisição enviando-a para a API OpenAI.
§Parâmetros esperados no payload
user_prompt- O prompt do usuário (obrigatório)
§Formato da resposta
A resposta terá o comando “openai_response” e o payload conterá:
answer- O texto da resposta gerada pelo modelo
§Erros
- Retorna
MCPError::InternalAgentErrorse:- O campo
user_promptestiver ausente - Houver falha na comunicação com a API
- A resposta da API não puder ser processada
- O campo
Auto Trait Implementations§
impl Freeze for OpenAIAgent
impl !RefUnwindSafe for OpenAIAgent
impl Send for OpenAIAgent
impl Sync for OpenAIAgent
impl Unpin for OpenAIAgent
impl UnsafeUnpin for OpenAIAgent
impl !UnwindSafe for OpenAIAgent
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more