Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
refactor: 统一Hands系统常量到单个源文件 refactor: 更新Hands中文名称和描述 fix: 修复技能市场在连接状态变化时重新加载 fix: 修复身份变更提案的错误处理逻辑 docs: 更新多个功能文档的验证状态和实现位置 docs: 更新Hands系统文档 test: 添加测试文件验证工作区路径
73 lines
1.9 KiB
Rust
73 lines
1.9 KiB
Rust
//! Local LLM driver (Ollama, LM Studio, vLLM, etc.)
|
|
|
|
use async_trait::async_trait;
|
|
use futures::Stream;
|
|
use reqwest::Client;
|
|
use std::pin::Pin;
|
|
use zclaw_types::{Result, ZclawError};
|
|
|
|
use super::{CompletionRequest, CompletionResponse, ContentBlock, LlmDriver, StopReason};
|
|
use crate::stream::StreamChunk;
|
|
|
|
/// Local LLM driver for Ollama, LM Studio, vLLM, etc.
|
|
pub struct LocalDriver {
|
|
client: Client,
|
|
base_url: String,
|
|
}
|
|
|
|
impl LocalDriver {
|
|
pub fn new(base_url: impl Into<String>) -> Self {
|
|
Self {
|
|
client: Client::new(),
|
|
base_url: base_url.into(),
|
|
}
|
|
}
|
|
|
|
pub fn ollama() -> Self {
|
|
Self::new("http://localhost:11434/v1")
|
|
}
|
|
|
|
pub fn lm_studio() -> Self {
|
|
Self::new("http://localhost:1234/v1")
|
|
}
|
|
|
|
pub fn vllm() -> Self {
|
|
Self::new("http://localhost:8000/v1")
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl LlmDriver for LocalDriver {
|
|
fn provider(&self) -> &str {
|
|
"local"
|
|
}
|
|
|
|
fn is_configured(&self) -> bool {
|
|
// Local drivers don't require API keys
|
|
true
|
|
}
|
|
|
|
async fn complete(&self, request: CompletionRequest) -> Result<CompletionResponse> {
|
|
// TODO: Implement actual API call (OpenAI-compatible)
|
|
Ok(CompletionResponse {
|
|
content: vec![ContentBlock::Text {
|
|
text: "Local driver not yet implemented".to_string(),
|
|
}],
|
|
model: request.model,
|
|
input_tokens: 0,
|
|
output_tokens: 0,
|
|
stop_reason: StopReason::EndTurn,
|
|
})
|
|
}
|
|
|
|
fn stream(
|
|
&self,
|
|
_request: CompletionRequest,
|
|
) -> Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send + '_>> {
|
|
// Placeholder - return error stream
|
|
Box::pin(futures::stream::once(async {
|
|
Err(ZclawError::LlmError("Local driver streaming not yet implemented".to_string()))
|
|
}))
|
|
}
|
|
}
|