增加 多线程
This commit is contained in:
parent
c3429e78f7
commit
88d2bc501c
@ -0,0 +1,20 @@
|
||||
from threading import Thread
|
||||
|
||||
import worker
|
||||
import server
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Start the worker thread
|
||||
worker_thread = Thread(target=worker.sync_documents, args=())
|
||||
worker_thread.start()
|
||||
|
||||
# Start the server thread
|
||||
server_thread = Thread(target=server.serve, args=())
|
||||
server_thread.start()
|
||||
|
||||
# Wait for the threads to finish
|
||||
worker_thread.join()
|
||||
server_thread.join()
|
||||
|
||||
|
||||
|
@ -52,10 +52,10 @@ class AIServer(document_query_pb2_grpc.DocumentQuery):
|
||||
|
||||
print(real_document)
|
||||
|
||||
print("正在调用 LLM...")
|
||||
print("正在调用 LLM: " + question + "...")
|
||||
chain = load_qa_with_sources_chain(OpenAI(temperature=0), chain_type="map_reduce",
|
||||
return_intermediate_steps=True,
|
||||
verbose=True)
|
||||
return_intermediate_steps=False,
|
||||
verbose=False)
|
||||
output = chain({"input_documents": real_document, "question": question}, return_only_outputs=False)
|
||||
print("回复:" + output["output_text"])
|
||||
|
||||
@ -77,4 +77,3 @@ def serve():
|
||||
server.wait_for_termination()
|
||||
|
||||
|
||||
serve()
|
||||
|
@ -1,13 +1,19 @@
|
||||
import time
|
||||
|
||||
import documents_pb2_grpc
|
||||
import documents_pb2
|
||||
import init
|
||||
import doc_client
|
||||
import sys
|
||||
import signal
|
||||
|
||||
print("获取需要更新的数据...")
|
||||
documents_response = doc_client.stub.GetNoVectorDocuments(documents_pb2.GetNoVectorDocumentsRequest()).documents
|
||||
|
||||
# # get all documents with no vector
|
||||
for document in documents_response:
|
||||
def sync_documents():
|
||||
while True:
|
||||
documents_response = doc_client.stub.GetNoVectorDocuments(documents_pb2.GetNoVectorDocumentsRequest()).documents
|
||||
|
||||
# # get all documents with no vector
|
||||
for document in documents_response:
|
||||
docContent = document.title + "\n" + document.content
|
||||
|
||||
print("正在更新向量...")
|
||||
@ -25,3 +31,5 @@ for document in documents_response:
|
||||
|
||||
print(update_vector_id_response)
|
||||
print("更新向量完成")
|
||||
|
||||
time.sleep(1 * 60)
|
||||
|
Loading…
Reference in New Issue
Block a user