Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
jinchat-server
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
aigc-pioneer
jinchat-server
Commits
5284fb27
提交
5284fb27
authored
5月 14, 2023
作者:
imClumsyPanda
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into dev
上级
c86dd4dd
3ff885d0
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
34 行增加
和
24 行删除
+34
-24
api.py
api.py
+24
-18
local_doc_qa.py
chains/local_doc_qa.py
+5
-1
cli_demo.py
cli_demo.py
+3
-3
image_loader.py
loader/image_loader.py
+1
-1
pdf_loader.py
loader/pdf_loader.py
+1
-1
没有找到文件。
api.py
浏览文件 @
5284fb27
...
@@ -181,7 +181,7 @@ async def delete_docs(
...
@@ -181,7 +181,7 @@ async def delete_docs(
if
os
.
path
.
exists
(
doc_path
):
if
os
.
path
.
exists
(
doc_path
):
os
.
remove
(
doc_path
)
os
.
remove
(
doc_path
)
else
:
else
:
return
{
"code"
:
1
,
"msg"
:
f
"document {doc_name} not found"
}
BaseResponse
(
code
=
1
,
msg
=
f
"document {doc_name} not found"
)
remain_docs
=
await
list_docs
(
knowledge_base_id
)
remain_docs
=
await
list_docs
(
knowledge_base_id
)
if
remain_docs
[
"code"
]
!=
0
or
len
(
remain_docs
[
"data"
])
==
0
:
if
remain_docs
[
"code"
]
!=
0
or
len
(
remain_docs
[
"data"
])
==
0
:
...
@@ -211,24 +211,30 @@ async def local_doc_chat(
...
@@ -211,24 +211,30 @@ async def local_doc_chat(
):
):
vs_path
=
os
.
path
.
join
(
VS_ROOT_PATH
,
knowledge_base_id
)
vs_path
=
os
.
path
.
join
(
VS_ROOT_PATH
,
knowledge_base_id
)
if
not
os
.
path
.
exists
(
vs_path
):
if
not
os
.
path
.
exists
(
vs_path
):
raise
ValueError
(
f
"Knowledge base {knowledge_base_id} not found"
)
# return BaseResponse(code=1, msg=f"Knowledge base {knowledge_base_id} not found")
return
ChatMessage
(
for
resp
,
history
in
local_doc_qa
.
get_knowledge_based_answer
(
question
=
question
,
query
=
question
,
vs_path
=
vs_path
,
chat_history
=
history
,
streaming
=
True
response
=
f
"Knowledge base {knowledge_base_id} not found"
,
):
history
=
history
,
pass
source_documents
=
[],
source_documents
=
[
)
f
"""出处 [{inum + 1}] {os.path.split(doc.metadata['source'])[-1]}:
\n\n
{doc.page_content}
\n\n
"""
else
:
f
"""相关度:{doc.metadata['score']}
\n\n
"""
for
resp
,
history
in
local_doc_qa
.
get_knowledge_based_answer
(
for
inum
,
doc
in
enumerate
(
resp
[
"source_documents"
])
query
=
question
,
vs_path
=
vs_path
,
chat_history
=
history
,
streaming
=
True
]
):
pass
source_documents
=
[
f
"""出处 [{inum + 1}] {os.path.split(doc.metadata['source'])[-1]}:
\n\n
{doc.page_content}
\n\n
"""
f
"""相关度:{doc.metadata['score']}
\n\n
"""
for
inum
,
doc
in
enumerate
(
resp
[
"source_documents"
])
]
return
ChatMessage
(
return
ChatMessage
(
question
=
question
,
question
=
question
,
response
=
resp
[
"result"
],
response
=
resp
[
"result"
],
history
=
history
,
history
=
history
,
source_documents
=
source_documents
,
source_documents
=
source_documents
,
)
)
async
def
chat
(
async
def
chat
(
...
...
chains/local_doc_qa.py
浏览文件 @
5284fb27
...
@@ -39,7 +39,11 @@ def load_file(filepath, sentence_size=SENTENCE_SIZE):
...
@@ -39,7 +39,11 @@ def load_file(filepath, sentence_size=SENTENCE_SIZE):
def
write_check_file
(
filepath
,
docs
):
def
write_check_file
(
filepath
,
docs
):
fout
=
open
(
'load_file.txt'
,
'a'
)
folder_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
filepath
),
"tmp_files"
)
if
not
os
.
path
.
exists
(
folder_path
):
os
.
makedirs
(
folder_path
)
fp
=
os
.
path
.
join
(
folder_path
,
'load_file.txt'
)
fout
=
open
(
fp
,
'a'
)
fout
.
write
(
"filepath=
%
s,len=
%
s"
%
(
filepath
,
len
(
docs
)))
fout
.
write
(
"filepath=
%
s,len=
%
s"
%
(
filepath
,
len
(
docs
)))
fout
.
write
(
'
\n
'
)
fout
.
write
(
'
\n
'
)
for
i
in
docs
:
for
i
in
docs
:
...
...
cli_demo.py
浏览文件 @
5284fb27
...
@@ -31,13 +31,13 @@ if __name__ == "__main__":
...
@@ -31,13 +31,13 @@ if __name__ == "__main__":
chat_history
=
history
,
chat_history
=
history
,
streaming
=
STREAMING
):
streaming
=
STREAMING
):
if
STREAMING
:
if
STREAMING
:
logger
.
info
(
resp
[
"result"
][
last_print_len
:]
)
print
(
resp
[
"result"
][
last_print_len
:],
end
=
""
,
flush
=
True
)
last_print_len
=
len
(
resp
[
"result"
])
last_print_len
=
len
(
resp
[
"result"
])
else
:
else
:
logger
.
info
(
resp
[
"result"
])
print
(
resp
[
"result"
])
if
REPLY_WITH_SOURCE
:
if
REPLY_WITH_SOURCE
:
source_text
=
[
f
"""出处 [{inum + 1}] {os.path.split(doc.metadata['source'])[-1]}:
\n\n
{doc.page_content}
\n\n
"""
source_text
=
[
f
"""出处 [{inum + 1}] {os.path.split(doc.metadata['source'])[-1]}:
\n\n
{doc.page_content}
\n\n
"""
# f"""相关度:{doc.metadata['score']}\n\n"""
# f"""相关度:{doc.metadata['score']}\n\n"""
for
inum
,
doc
in
for
inum
,
doc
in
enumerate
(
resp
[
"source_documents"
])]
enumerate
(
resp
[
"source_documents"
])]
logger
.
info
(
"
\n\n
"
+
"
\n\n
"
.
join
(
source_text
))
print
(
"
\n\n
"
+
"
\n\n
"
.
join
(
source_text
))
loader/image_loader.py
浏览文件 @
5284fb27
...
@@ -30,7 +30,7 @@ class UnstructuredPaddleImageLoader(UnstructuredFileLoader):
...
@@ -30,7 +30,7 @@ class UnstructuredPaddleImageLoader(UnstructuredFileLoader):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
filepath
=
"../content/samples/test.jpg"
filepath
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
)),
"content"
,
"samples"
,
"test.jpg"
)
loader
=
UnstructuredPaddleImageLoader
(
filepath
,
mode
=
"elements"
)
loader
=
UnstructuredPaddleImageLoader
(
filepath
,
mode
=
"elements"
)
docs
=
loader
.
load
()
docs
=
loader
.
load
()
for
doc
in
docs
:
for
doc
in
docs
:
...
...
loader/pdf_loader.py
浏览文件 @
5284fb27
...
@@ -46,7 +46,7 @@ class UnstructuredPaddlePDFLoader(UnstructuredFileLoader):
...
@@ -46,7 +46,7 @@ class UnstructuredPaddlePDFLoader(UnstructuredFileLoader):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
filepath
=
"../content/samples/test.pdf"
filepath
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
)),
"content"
,
"samples"
,
"test.pdf"
)
loader
=
UnstructuredPaddlePDFLoader
(
filepath
,
mode
=
"elements"
)
loader
=
UnstructuredPaddlePDFLoader
(
filepath
,
mode
=
"elements"
)
docs
=
loader
.
load
()
docs
=
loader
.
load
()
for
doc
in
docs
:
for
doc
in
docs
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论