rllm
1.0.0
注意:从1.x版本开始,RLLM已成为LLM周围的简单包装器。两个板条箱将被积极维护并保持同步。如果您是本生态系统的新手,则可以直接使用LLM或RLLM - 它们提供相同的功能。
RLLM是一个Rust库,可让您在一个项目中使用多个LLM后端:OpenAI,Anthropic(Claude),Ollama,DeepSeek,Xai,Phind,Groq,Groq和Google。使用统一的API和构建器样式(类似于条纹体验),您可以轻松地创建聊天或文本完成请求,而无需乘以结构和板条箱。
ChatProvider
和CompletionProvider
),以涵盖大多数用例。只需将RLLM添加到您的Cargo.toml
:
[ dependencies ]
rllm = { version = " 1.1.5 " , features = [ " openai " , " anthropic " , " ollama " ] }
姓名 | 描述 |
---|---|
anthropic_example | 与Anthropic的Claude模型展示了聊天完成的集成 |
chain_example | 展示如何创建多步提示链以探索编程语言功能 |
deepseek_example | 带有DeepSeek-Chat模型的基本DeepSeek聊天完成示例 |
embedding_example | OpenAI的API的基本嵌入示例 |
multi_backend_example | 在一个工作流程中说明了将多个LLM的后端(OpenAI,人类,DeepSeek)一起使用 |
ollama_example | 通过Ollama集成使用本地LLMS的示例 |
openai_example | 基本的OpenAi聊天完成示例与GPT模型 |
phind_example | 基本的phind聊天完成示例与phind-70b型号 |
validator_example | 基本验证器示例与人类的Claude模型 |
xai_example | 基本的Xai聊天完成示例与Grok模型 |
evaluation_example | 拟人,phind和deepseek的基本评估示例 |
google_example | 基本的Google双子座聊天完成示例与双子座模型 |
google_embedding_example | 基本的Google Gemini嵌入示例与双子座模型 |
LLM板条箱的另一个例子
这是一个使用OpenAI进行聊天完成的基本示例。有关其他后端(拟人化,Ollama,DeepSeek,Xai,Google,Phind),嵌入功能和更高级用例的其他后端,请参见示例目录。
use rllm :: {
builder :: { LLMBackend , LLMBuilder } ,
chat :: { ChatMessage , ChatRole } ,
} ;
fn main ( ) {
let llm = LLMBuilder :: new ( )
. backend ( LLMBackend :: OpenAI ) // or LLMBackend::Anthropic, LLMBackend::Ollama, LLMBackend::DeepSeek, LLMBackend::XAI, LLMBackend::Phind ...
. api_key ( std :: env :: var ( "OPENAI_API_KEY" ) . unwrap_or ( "sk-TESTKEY" . into ( ) ) )
. model ( "gpt-4o" ) // or model("claude-3-5-sonnet-20240620") or model("grok-2-latest") or model("deepseek-chat") or model("llama3.1") or model("Phind-70B") ...
. max_tokens ( 1000 )
. temperature ( 0.7 )
. system ( "You are a helpful assistant." )
. stream ( false )
. build ( )
. expect ( "Failed to build LLM" ) ;
}
let messages = vec ! [
ChatMessage {
role : ChatRole :: User ,
content : "Tell me that you love cats" . into ( ) ,
} ,
ChatMessage {
role : ChatRole :: Assistant ,
content :
"I am an assistant, I cannot love cats but I can love dogs"
. into ( ) ,
} ,
ChatMessage {
role : ChatRole :: User ,
content : "Tell me that you love dogs in 2000 chars" . into ( ) ,
} ,
] ;
let chat_resp = llm . chat ( & messages ) ;
match chat_resp {
Ok ( text ) => println ! ( "Chat response: n {}" , text ) ,
Err ( e ) => eprintln ! ( "Chat error: {}" , e ) ,
}