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
1e23eda6
Commit
1e23eda6
authored
Nov 24, 2023
by
takatost
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: import error
parent
de93272b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5 additions
and
107 deletions
+5
-107
completion.py
api/controllers/service_api/app/completion.py
+0
-82
orchestrator_rule_parser.py
api/core/orchestrator_rule_parser.py
+0
-5
anthropic_llm.py
api/core/third_party/langchain/llms/anthropic_llm.py
+2
-2
requirements.txt
api/requirements.txt
+3
-18
No files found.
api/controllers/service_api/app/completion.py
View file @
1e23eda6
...
...
@@ -2,11 +2,8 @@ import json
import
logging
from
typing
import
Union
,
Generator
from
datasets
import
Dataset
from
flask
import
stream_with_context
,
Response
from
flask_restful
import
reqparse
from
ragas
import
evaluate
from
ragas.metrics
import
answer_relevancy
,
context_precision
,
faithfulness
from
werkzeug.exceptions
import
NotFound
,
InternalServerError
import
services
...
...
@@ -79,84 +76,6 @@ class CompletionApi(AppApiResource):
raise
InternalServerError
()
class
CompletionEvaluateApi
(
AppApiResource
):
def
post
(
self
,
app_model
,
end_user
):
if
app_model
.
mode
!=
'chat'
:
raise
AppUnavailableError
()
parser
=
reqparse
.
RequestParser
()
parser
.
add_argument
(
'inputs'
,
type
=
dict
,
required
=
True
,
location
=
'json'
)
parser
.
add_argument
(
'queries'
,
type
=
list
,
location
=
'json'
,
default
=
''
)
parser
.
add_argument
(
'files'
,
type
=
list
,
required
=
False
,
location
=
'json'
)
parser
.
add_argument
(
'response_mode'
,
type
=
str
,
choices
=
[
'blocking'
,
'streaming'
],
location
=
'json'
)
parser
.
add_argument
(
'user'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'retriever_from'
,
type
=
str
,
required
=
False
,
default
=
'dev'
,
location
=
'json'
)
args
=
parser
.
parse_args
()
streaming
=
args
[
'response_mode'
]
==
'streaming'
if
end_user
is
None
and
args
[
'user'
]
is
not
None
:
end_user
=
create_or_update_end_user_for_user_id
(
app_model
,
args
[
'user'
])
args
[
'auto_generate_name'
]
=
False
queries
=
args
[
'queries'
]
try
:
questions
=
[]
answers
=
[]
contexts
=
[]
for
query
in
queries
:
args
[
'query'
]
=
query
response
=
CompletionService
.
completion
(
app_model
=
app_model
,
user
=
end_user
,
args
=
args
,
from_source
=
'api'
,
streaming
=
streaming
,
)
questions
.
append
(
query
)
answers
.
append
(
response
[
'answer'
])
context
=
[]
metadata
=
response
[
'metadata'
]
if
'retriever_resources'
in
metadata
and
metadata
[
'retriever_resources'
]:
retriever_resources
=
response
[
'metadata'
][
'retriever_resources'
]
for
retriever_resource
in
retriever_resources
:
context
.
append
(
retriever_resource
[
'content'
])
else
:
context
.
append
(
''
)
contexts
.
append
(
context
)
ds
=
Dataset
.
from_dict
(
{
"question"
:
questions
,
"answer"
:
answers
,
"contexts"
:
contexts
,
}
)
result
=
evaluate
(
ds
,
[
answer_relevancy
,
context_precision
,
faithfulness
])
return
result
except
services
.
errors
.
conversation
.
ConversationNotExistsError
:
raise
NotFound
(
"Conversation Not Exists."
)
except
services
.
errors
.
conversation
.
ConversationCompletedError
:
raise
ConversationCompletedError
()
except
services
.
errors
.
app_model_config
.
AppModelConfigBrokenError
:
logging
.
exception
(
"App model config broken."
)
raise
AppUnavailableError
()
except
ProviderTokenNotInitError
as
ex
:
raise
ProviderNotInitializeError
(
ex
.
description
)
except
QuotaExceededError
:
raise
ProviderQuotaExceededError
()
except
ModelCurrentlyNotSupportError
:
raise
ProviderModelCurrentlyNotSupportError
()
except
(
LLMBadRequestError
,
LLMAPIConnectionError
,
LLMAPIUnavailableError
,
LLMRateLimitError
,
LLMAuthorizationError
)
as
e
:
raise
CompletionRequestError
(
str
(
e
))
except
ValueError
as
e
:
raise
e
except
Exception
as
e
:
logging
.
exception
(
"internal server error."
)
raise
InternalServerError
()
class
CompletionStopApi
(
AppApiResource
):
def
post
(
self
,
app_model
,
end_user
,
task_id
):
if
app_model
.
mode
!=
'completion'
:
...
...
@@ -269,7 +188,6 @@ def compact_response(response: Union[dict | Generator]) -> Response:
api
.
add_resource
(
CompletionApi
,
'/completion-messages'
)
api
.
add_resource
(
CompletionEvaluateApi
,
'/chat-evaluate'
)
api
.
add_resource
(
CompletionStopApi
,
'/completion-messages/<string:task_id>/stop'
)
api
.
add_resource
(
ChatApi
,
'/chat-messages'
)
api
.
add_resource
(
ChatStopApi
,
'/chat-messages/<string:task_id>/stop'
)
api/core/orchestrator_rule_parser.py
View file @
1e23eda6
import
json
import
threading
from
typing
import
Optional
,
List
from
langchain.callbacks.manager
import
Callbacks
...
...
@@ -8,9 +6,6 @@ from langchain.tools import BaseTool, Tool, WikipediaQueryRun
from
langchain.utilities.wikipedia
import
WikipediaAPIWrapper
from
pydantic
import
BaseModel
,
Field
from
core.agent.agent.multi_dataset_router_agent
import
MultiDatasetRouterAgent
from
core.agent.agent.output_parser.structured_chat
import
StructuredChatOutputParser
from
core.agent.agent.structed_multi_dataset_router_agent
import
StructuredMultiDatasetRouterAgent
from
core.agent.agent_executor
import
AgentExecutor
,
PlanningStrategy
,
AgentConfiguration
from
core.callback_handler.agent_loop_gather_callback_handler
import
AgentLoopGatherCallbackHandler
from
core.callback_handler.dataset_tool_callback_handler
import
DatasetToolCallbackHandler
...
...
api/core/third_party/langchain/llms/anthropic_llm.py
View file @
1e23eda6
from
typing
import
Dict
from
langchain.chat_models
import
ChatAnthropic
from
langchain.llms.anthropic
import
_to_secret
from
langchain.llms.anthropic
import
convert_to_secret_str
from
langchain.schema
import
ChatMessage
,
BaseMessage
,
HumanMessage
,
AIMessage
,
SystemMessage
from
langchain.utils
import
get_from_dict_or_env
,
check_package_version
from
pydantic
import
root_validator
...
...
@@ -11,7 +11,7 @@ class AnthropicLLM(ChatAnthropic):
@
root_validator
()
def
validate_environment
(
cls
,
values
:
Dict
)
->
Dict
:
"""Validate that api key and python package exists in environment."""
values
[
"anthropic_api_key"
]
=
_to_secret
(
values
[
"anthropic_api_key"
]
=
convert_to_secret_str
(
get_from_dict_or_env
(
values
,
"anthropic_api_key"
,
"ANTHROPIC_API_KEY"
)
)
# Get custom api url from environment.
...
...
api/requirements.txt
View file @
1e23eda6
...
...
@@ -10,7 +10,7 @@ flask-session2==1.3.1
flask-cors==3.0.10
gunicorn~=21.2.0
gevent~=22.10.2
langchain==0.0.3
11
langchain==0.0.3
40
openai~=0.28.0
psycopg2-binary~=2.9.6
pycryptodome==3.17
...
...
@@ -44,7 +44,7 @@ google-search-results==2.4.2
replicate~=0.9.0
websocket-client~=1.6.1
dashscope~=1.11.0
huggingface_hub~=0.1
6
.4
huggingface_hub~=0.1
9
.4
transformers~=4.31.0
stripe~=5.5.0
pandas==1.5.3
...
...
@@ -55,18 +55,3 @@ werkzeug==2.3.7
pymilvus==2.3.0
qdrant-client==1.6.4
cohere~=4.32
\ No newline at end of file
pydantic~=1.10.12
requests~=2.31.0
regex~=2023.8.8
jieba3k~=0.35.1
numpy~=1.25.2
httpx~=0.24.1
dataclasses~=0.6
click~=8.1.6
blinker~=1.6.2
botocore~=1.31.17
alembic~=1.11.2
tqdm~=4.66.1
pytz~=2022.7.1
datasets~=2.15.0
ragas~=0.0.20
\ No newline at end of file
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