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 ) ,
}