pub struct ConfigurableProtocol<P: Protocol> { /* private fields */ }Expand description
可配置的协议适配器
包装一个基础协议,通过配置来修改其行为(端点路径、认证方式等)。
§示例
use llm_connector::core::{ConfigurableProtocol, ProtocolConfig, EndpointConfig, AuthConfig};
use llm_connector::protocols::OpenAIProtocol;
let config = ProtocolConfig {
name: "custom".to_string(),
endpoints: EndpointConfig {
chat_template: "{base_url}/v1/chat/completions".to_string(),
models_template: Some("{base_url}/v1/models".to_string()),
},
auth: AuthConfig::Bearer,
extra_headers: vec![],
};
let protocol = ConfigurableProtocol::new(
OpenAIProtocol::new("sk-..."),
config
);Implementations§
Source§impl<P: Protocol> ConfigurableProtocol<P>
impl<P: Protocol> ConfigurableProtocol<P>
Sourcepub fn new(inner: P, config: ProtocolConfig) -> Self
pub fn new(inner: P, config: ProtocolConfig) -> Self
Sourcepub fn openai_compatible(inner: P, name: &str) -> Self
pub fn openai_compatible(inner: P, name: &str) -> Self
Trait Implementations§
Source§impl<P: Clone + Protocol> Clone for ConfigurableProtocol<P>
impl<P: Clone + Protocol> Clone for ConfigurableProtocol<P>
Source§fn clone(&self) -> ConfigurableProtocol<P>
fn clone(&self) -> ConfigurableProtocol<P>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<P: Protocol> Protocol for ConfigurableProtocol<P>
impl<P: Protocol> Protocol for ConfigurableProtocol<P>
Source§fn chat_endpoint(&self, base_url: &str) -> String
fn chat_endpoint(&self, base_url: &str) -> String
获取聊天完成的端点URL
Source§fn build_request(
&self,
request: &ChatRequest,
) -> Result<Self::Request, LlmConnectorError>
fn build_request( &self, request: &ChatRequest, ) -> Result<Self::Request, LlmConnectorError>
构建协议特定的请求
Source§fn parse_response(
&self,
response: &str,
) -> Result<ChatResponse, LlmConnectorError>
fn parse_response( &self, response: &str, ) -> Result<ChatResponse, LlmConnectorError>
解析协议特定的响应
Source§fn parse_models(&self, response: &str) -> Result<Vec<String>, LlmConnectorError>
fn parse_models(&self, response: &str) -> Result<Vec<String>, LlmConnectorError>
解析模型列表响应
Auto Trait Implementations§
impl<P> Freeze for ConfigurableProtocol<P>where
P: Freeze,
impl<P> !RefUnwindSafe for ConfigurableProtocol<P>
impl<P> Send for ConfigurableProtocol<P>
impl<P> Sync for ConfigurableProtocol<P>
impl<P> Unpin for ConfigurableProtocol<P>where
P: Unpin,
impl<P> !UnwindSafe for ConfigurableProtocol<P>
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