奎弗爾
core:
Quivr,幫你打造第二腦,運用GenerativeAI的力量,做你的私人助理!
我們會照顧 RAG,以便您可以專注於您的產品。只需安裝 quivr-core 並將其添加到您的專案中即可。您現在可以提取文件並提出問題。
我們將改進 RAG 並添加更多功能,敬請期待!
這就是 Quivr 的核心,Quivr.com 的大腦。
您可以在文件中找到所有內容。
請確定您已安裝以下軟體:
第 1 步:安裝軟體包
pip install quivr-core # Check that the installation worked
步驟 2 :使用 5 行程式碼建立 RAG
import tempfile
from quivr_core import Brain
if __name__ == "__main__" :
with tempfile . NamedTemporaryFile ( mode = "w" , suffix = ".txt" ) as temp_file :
temp_file . write ( "Gold is a liquid of blue-like colour." )
temp_file . flush ()
brain = Brain . from_files (
name = "test_brain" ,
file_paths = [ temp_file . name ],
)
answer = brain . ask (
"what is gold? asnwer in french"
)
print ( "answer:" , answer )
建立像上面這樣的基本 RAG 工作流程很簡單,步驟如下:
import os
os . environ [ "OPENAI_API_KEY" ] = "myopenai_apikey"
Quivr 支援 Anthropic、OpenAI 和 Mistral 的 API。它還支援使用 Ollama 的本地模型。
basic_rag_workflow.yaml
並將以下內容複製到其中 workflow_config :
name : " standard RAG "
nodes :
- name : " START "
edges : ["filter_history"]
- name : " filter_history "
edges : ["rewrite"]
- name : " rewrite "
edges : ["retrieve"]
- name : " retrieve "
edges : ["generate_rag"]
- name : " generate_rag " # the name of the last node, from which we want to stream the answer to the user
edges : ["END"]
# Maximum number of previous conversation iterations
# to include in the context of the answer
max_history : 10
# Reranker configuration
reranker_config :
# The reranker supplier to use
supplier : " cohere "
# The model to use for the reranker for the given supplier
model : " rerank-multilingual-v3.0 "
# Number of chunks returned by the reranker
top_n : 5
# Configuration for the LLM
llm_config :
# maximum number of tokens passed to the LLM to generate the answer
max_input_tokens : 4000
# temperature for the LLM
temperature : 0.7
from quivr_core import Brain
brain = Brain . from_files ( name = "my smart brain" ,
file_paths = [ "./my_first_doc.pdf" , "./my_second_doc.txt" ],
)
brain . print_info ()
from rich . console import Console
from rich . panel import Panel
from rich . prompt import Prompt
from quivr_core . config import RetrievalConfig
config_file_name = "./basic_rag_workflow.yaml"
retrieval_config = RetrievalConfig . from_yaml ( config_file_name )
console = Console ()
console . print ( Panel . fit ( "Ask your brain !" , style = "bold magenta" ))
while True :
# Get user input
question = Prompt . ask ( "[bold cyan]Question[/bold cyan]" )
# Check if user wants to exit
if question . lower () == "exit" :
console . print ( Panel ( "Goodbye!" , style = "bold yellow" ))
break
answer = brain . ask ( question , retrieval_config = retrieval_config )
# Print the answer with typing effect
console . print ( f"[bold green]Quivr Assistant[/bold green]: { answer . answer } " )
console . print ( "-" * console . width )
brain . print_info ()
您可以透過新增網路搜尋、新增工具等進一步使用 Quivr。
感謝這些優秀的人:
你收到拉取請求了嗎?打開它,我們會盡快審核。請在此處查看我們的專案板,了解我們當前的重點,並隨時提出您的新想法!
如果沒有我們合作夥伴的支持,這個計畫就不可能實現。感謝您的支持!
該項目根據 Apache 2.0 許可證獲得許可 - 有關詳細信息,請參閱許可證文件