query
功能描述
RAG SDK对话功能。
函数原型
def query(text: str, llm_config, *args, **kwargs)
输入参数说明
参数名 |
数据类型 |
可选/必选 |
说明 |
---|---|---|---|
text |
str |
必选 |
原始问题,非空,最大的问题长度为1000*1000。 |
llm_config |
LLMParameterConfig |
可选 |
调用大模型参数,此处默认值temperature为“0.5”,top_p为“0.95”,其余参数说明请参见LLMParameterConfig类。 |
args |
列表 |
可选 |
继承父类方法签名,此处未使用。 |
kwargs |
字典 |
可选 |
继承父类方法签名,此处未使用。 |
返回值说明
数据类型 |
说明 |
---|---|
Union[Dict, Iterator[Dict]] |
返回字典或者迭代器,stream设置成True表示返回迭代器,否则返回字典。其中Dict内容为:
|
调用示例
from mx_rag.chain import ParallelText2TextChain from mx_rag.llm import Text2TextLLM from mx_rag.embedding.local import TextEmbedding from mx_rag.storage.vectorstore import MindFAISS from mx_rag.storage.document_store import SQLiteDocstore from mx_rag.retrievers import Retriever from mx_rag.utils import ClientParam dev = 0 emb = TextEmbedding("/path/to/acge_text_embedding/", dev_id=dev) client_param = ClientParam(ca_file="/path/to/ca.crt") llm = Text2TextLLM(model_name="Meta-Llama-3-8B-Instruct", base_url="https://x.x.x.x:port/v1/chat/completions", client_param=client_param) vector_store = MindFAISS(x_dim=1024, devs=[dev], load_local_index="/path/to/faiss.index", auto_save=True) chunk_store = SQLiteDocstore(db_path="/path/to/sql.db") retriever = Retriever(vector_store=vector_store, document_store=chunk_store, embed_func=emb.embed_documents, k=1, score_threshold=0.6) parallel_chain = ParallelText2TextChain(llm=llm, retriever=retriever) answer = parallel_chain.query(text="123456") print(answer)