با Ragable به راحتی چت ربات های RAG چند چرخشی بسازید! (متن باز)

مدتی است که در حال ساخت رباتهای گفتگوی چندگانه و برنامههای هوش مصنوعی هستم، و کتابخانههای بزرگی برای این منظور وجود دارد، با این حال، گاهی اوقات آنها بیش از حد هستند.
اگر در یادگیری ماشینی تازه کار هستید یا به سادگی می خواهید یک ربات چت چند چرخشی بسازید که بتواند بین عملکردهای مختلف مسیریابی کند تا داده ها را واکشی کند، Ragable برای شما مناسب است!
Ragable چیست
Ragable یک کتابخانه ML است که ساخت رباتهای گفتگوی چند نوبتی مبتنی بر Agent را بسیار آسانتر میکند.
همراه با بسیاری از ملزومات مورد نیاز شما مانند:
- ادغام وکتور فروشگاه: به راحتی تنها با چند خط کد داده ها را از چندین منبع دریافت می کند و جستجوهایی از نوع RAG انجام می دهد.
- روتر عامل: عامل ورودی کاربر را تجزیه و تحلیل می کند و سپس به صورت هوشمند تشخیص می دهد که کدام عملکرد کد شما را باید اجرا کند.
- توابع خالص پایتون: بدون خیال، توابع ساده پایتون که می توانند از داده های کاربر مانند جلسات، اشیاء درخواستی و تقریباً هر چیز دیگری در پایگاه کد شما آگاهی داشته باشند. همچنین 100٪ ایمن است، زیرا Ragable از توابع OpenAI استفاده نمی کند، تنها خروجی عملکرد شما به LLM ارسال می شود.
در اینجا یک مثال کد است:
from ragable.agent import get_openai_agent
from ragable.runnable import Runnable, runnable_from_func
from ragable.adapters.qdrant import QdrantAdapter
from ragable.embedders import StandardEmbedder
@runnable_from_func(
Name="All about php strings",
Instruction="When the human asks about php"
)
def php_strings(params):
response = """
str_replace('x', 'y', $z)
stripos($the_big_blob_of_text, $the_thing_to_search_for)
"""
return response
@runnable_from_func(
Name="All about legendary pokemon",
Instruction="When the human asks about legendary pokemon"
)
def legendary_pokemon(params):
context_data = ""
with open("./testdata/legendary_pokemon.txt", "r") as f:
txt = f.read()
return context_data
if __name__ == "__main__":
# Sets up an OpenAI powered agent.
# Agents can register multiple tasks and will intelligently route the LLM
# - to tasks based on the Runnable "Instruction" prompt.
agent = get_openai_agent()
# Easy integration with the Qdrant vector store (you will need Qdrant running locally)
# Pass in "dsn" and "api_key" for any other setup.
qdrant = QdrantAdapter("ragable_documents")
# The embedder Allows you to feed most common document types into the RAG system.
# Each document is chunked into LLM friendly chunks and vector embedded.
embedder = StandardEmbedder(qdrant)
# Path to your document. Optionally, you can also pass in a "doc_id".
# The doc_id can be an integer or uuid.
# Formats supported: txt, pdf, docx, odt, pptx, odp
embedder.train_from_document("./testdata/bulbasaur.txt")
# You can also embed and index regular strings.
# doc_id is required.
# embedder.train_from_text("some text", 1234)
# A none decorator verson of a Runnable.
bulbasaur_knowledge = Runnable(
Name="Information about bulbasaur",
Instruction="When the human asks about bulbasaur",
Func=qdrant
)
# Tell the agent which Runnable functions it's allowed to execute.
agent.add_tasks([
legendary_pokemon,
php_strings,
bulbasaur_knowledge
])
questions = [
"What is a legendary pokemon?",
"How to perform a string replace in PHP?",
"How to find a string in another string in PHP?",
"Which Pokemon are the evolved forms of bulbasaur?"
]
# Here you can feed the Agent any additional prompts as needed.
# For example, you can store the chat history in Redis or a local session and
# - then add each of the historical messages using this function.
# Supported message types: system, user, ai, assistant
agent.add_message("You are a useful informational bot.", "system")
for q in questions:
response = agent.invoke(q)
print(response)
می توانید نسخه Ragable خود را از اینجا دریافت کنید: https://github.com/plexcorp-pty-ltd/ragable
Ragable هنوز در نسخه بتا است و هنوز به عنوان بسته PIP در دسترس نیست. پس با احتیاط استفاده کنید، نسخه پایدار به زودی منتشر خواهد شد!