Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
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
ai-tech
dify
Commits
3b374a46
Commit
3b374a46
authored
Jul 27, 2023
by
jyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mutil thread
parent
e434009d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
4 deletions
+19
-4
dataset_retriever_tool.py
api/core/tool/dataset_retriever_tool.py
+18
-3
8d2d099ceb74_add_qa_model_support.py
api/migrations/versions/8d2d099ceb74_add_qa_model_support.py
+1
-1
No files found.
api/core/tool/dataset_retriever_tool.py
View file @
3b374a46
...
...
@@ -12,7 +12,7 @@ from core.index.keyword_table_index.keyword_table_index import KeywordTableIndex
from
core.index.vector_index.vector_index
import
VectorIndex
from
core.llm.llm_builder
import
LLMBuilder
from
extensions.ext_database
import
db
from
models.dataset
import
Dataset
from
models.dataset
import
Dataset
,
DocumentSegment
class
DatasetRetrieverToolInput
(
BaseModel
):
...
...
@@ -68,6 +68,7 @@ class DatasetRetrieverTool(BaseTool):
)
documents
=
kw_table_index
.
search
(
query
,
search_kwargs
=
{
'k'
:
self
.
k
})
return
str
(
"
\n
"
.
join
([
document
.
page_content
for
document
in
documents
]))
else
:
model_credentials
=
LLMBuilder
.
get_model_credentials
(
tenant_id
=
dataset
.
tenant_id
,
...
...
@@ -98,8 +99,22 @@ class DatasetRetrieverTool(BaseTool):
hit_callback
=
DatasetIndexToolCallbackHandler
(
dataset
.
id
)
hit_callback
.
on_tool_end
(
documents
)
document_context_list
=
[]
index_node_ids
=
[
document
.
metadata
[
'doc_id'
]
for
document
in
documents
]
segments
=
DocumentSegment
.
query
.
filter
(
DocumentSegment
.
completed_at
.
isnot
(
None
),
DocumentSegment
.
status
==
'completed'
,
DocumentSegment
.
enabled
==
True
,
DocumentSegment
.
index_node_id
.
in_
(
index_node_ids
)
)
.
all
()
if
segments
:
for
segment
in
segments
:
if
segment
.
answer
:
document_context_list
.
append
(
segment
.
answer
)
else
:
document_context_list
.
append
(
segment
.
content
)
return
str
(
"
\n
"
.
join
([
document
.
page_content
for
document
in
documents
]
))
return
str
(
"
\n
"
.
join
(
document_context_list
))
async
def
_arun
(
self
,
tool_input
:
str
)
->
str
:
raise
NotImplementedError
()
api/migrations/versions/8d2d099ceb74_add_qa_model_support.py
View file @
3b374a46
...
...
@@ -11,7 +11,7 @@ from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision
=
'8d2d099ceb74'
down_revision
=
'
a5b56fb053ef
'
down_revision
=
'
7ce5a52e4eee
'
branch_labels
=
None
depends_on
=
None
...
...
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