Commit 847e155f by 陈正乐

修改存库的question数据

parent 6ce5d9e1
......@@ -53,6 +53,8 @@ class QA:
self.llm = LLMChain(llm=self.base_llm, prompt=self.prompt, llm_kwargs=self.llm_kwargs)
self.cur_answer = ""
self.cur_question = ""
self.cur_similarity = ""
self.cur_oquestion = ""
# 为所给问题返回similarity文本
def get_similarity(self, _aquestion):
......@@ -60,18 +62,20 @@ class QA:
# 一次性直接给出所有的答案
async def chat(self, _question):
similarity = self.get_similarity(_aquestion=_question)
self.cur_question = self.prompt.format(**{k: v for k, v in zip(self.prompt_kwargs, (similarity, _question))})
self.cur_oquestion = _question
self.cur_similarity = self.get_similarity(_aquestion=self.cur_oquestion)
self.cur_question = self.prompt.format(**{k: v for k, v in zip(self.prompt_kwargs, (self.cur_similarity, self.cur_oquestion))})
self.cur_answer = ""
if not _question:
return ""
self.cur_answer = self.llm.run({k: v for k, v in zip(self.prompt_kwargs, (similarity, _question))})
self.cur_answer = self.llm.run({k: v for k, v in zip(self.prompt_kwargs, (self.cur_similarity, self.cur_oquestion))})
return self.cur_answer
# 异步输出,逐渐输出答案
async def async_chat(self, _question):
similarity = self.get_similarity(_aquestion=_question)
self.cur_question = self.prompt.format(**{k: v for k, v in zip(self.prompt_kwargs, (similarity, _question))})
self.cur_oquestion = _question
self.cur_similarity = self.get_similarity(_aquestion=self.cur_oquestion)
self.cur_question = self.prompt.format(**{k: v for k, v in zip(self.prompt_kwargs, (self.cur_similarity, self.cur_oquestion))})
callback = AsyncIteratorCallbackHandler()
async def wrap_done(fn: Awaitable, event: asyncio.Event):
......@@ -85,28 +89,24 @@ class QA:
event.set()
task = asyncio.create_task(
wrap_done(self.llm.arun({k: v for k, v in zip(self.prompt_kwargs, (similarity, _question))}, callbacks=[callback]),
wrap_done(self.llm.arun({k: v for k, v in zip(self.prompt_kwargs, (self.cur_similarity, self.cur_oquestion))}, callbacks=[callback]),
callback.done))
self.cur_answer = ""
async for token in callback.aiter():
self.cur_answer = self.cur_answer + token
yield f"{self.cur_answer}"
print(datetime.now())
await task
print('----------------', self.cur_question)
print('================', self.cur_answer)
print(datetime.now())
def get_history(self):
return self.history
def update_history(self):
if self.cur_question == '' and self.cur_answer == '':
if self.cur_oquestion == '' and self.cur_answer == '':
pass
else:
self.history.append((self.cur_question, self.cur_answer))
self.history.append((self.cur_oquestion, self.cur_answer))
self.crud.update_last(chat_id=self.chat_id)
self.crud.insert_turn_qa(chat_id=self.chat_id, question=self.cur_question, answer=self.cur_answer,
self.crud.insert_turn_qa(chat_id=self.chat_id, question=self.cur_oquestion, answer=self.cur_answer,
turn_number=len(self.history), is_last=1)
......@@ -118,7 +118,7 @@ if __name__ == "__main__":
chat_completion=ChatCompletion(ak="pT7sV1smp4AeDl0LjyZuHBV9", sk="b3N0ibo1IKTLZlSs7weZc8jdR0oHjyMu"))
vecstore_faiss = VectorStore_FAISS(
embedding_model_name=EMBEEDING_MODEL_PATH,
store_path=FAISS_STORE_PATH,
store_path='../../faiss',
index_name=INDEX_NAME,
info={"port": VEC_DB_PORT, "host": VEC_DB_HOST, "dbname": VEC_DB_DBNAME, "username": VEC_DB_USER,
"password": VEC_DB_PASSWORD},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment