Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
LAE
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
文靖昊
LAE
Commits
847e155f
Commit
847e155f
authored
May 07, 2024
by
陈正乐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改存库的question数据
parent
6ce5d9e1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
14 deletions
+14
-14
qa.py
src/server/qa.py
+14
-14
No files found.
src/server/qa.py
View file @
847e155f
...
...
@@ -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
,
(
s
imilarity
,
_
question
))})
self
.
cur_answer
=
self
.
llm
.
run
({
k
:
v
for
k
,
v
in
zip
(
self
.
prompt_kwargs
,
(
s
elf
.
cur_similarity
,
self
.
cur_o
question
))})
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
,
(
s
imilarity
,
_
question
))},
callbacks
=
[
callback
]),
wrap_done
(
self
.
llm
.
arun
({
k
:
v
for
k
,
v
in
zip
(
self
.
prompt_kwargs
,
(
s
elf
.
cur_similarity
,
self
.
cur_o
question
))},
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_
o
question
==
''
and
self
.
cur_answer
==
''
:
pass
else
:
self
.
history
.
append
((
self
.
cur_question
,
self
.
cur_answer
))
self
.
history
.
append
((
self
.
cur_
o
question
,
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_
o
question
,
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
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment