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
665318da
Unverified
Commit
665318da
authored
Jan 04, 2024
by
Garfield Dai
Committed by
GitHub
Jan 04, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: remove useless code. (#1913)
parent
66cdf577
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
0 additions
and
238 deletions
+0
-238
__init__.py
api/core/external_data_tool/weather_search/__init__.py
+0
-0
schema.json
api/core/external_data_tool/weather_search/schema.json
+0
-35
weather_search.py
api/core/external_data_tool/weather_search/weather_search.py
+0
-45
__init__.py
api/core/moderation/cloud_service/__init__.py
+0
-0
cloud_service.py
api/core/moderation/cloud_service/cloud_service.py
+0
-93
schema.json
api/core/moderation/cloud_service/schema.json
+0
-65
No files found.
api/core/external_data_tool/weather_search/__init__.py
deleted
100644 → 0
View file @
66cdf577
api/core/external_data_tool/weather_search/schema.json
deleted
100644 → 0
View file @
66cdf577
{
"label"
:
{
"en-US"
:
"Weather Search"
,
"zh-Hans"
:
"天气查询"
},
"form_schema"
:
[
{
"type"
:
"select"
,
"label"
:
{
"en-US"
:
"Temperature Unit"
,
"zh-Hans"
:
"温度单位"
},
"variable"
:
"temperature_unit"
,
"required"
:
true
,
"options"
:
[
{
"label"
:
{
"en-US"
:
"Fahrenheit"
,
"zh-Hans"
:
"华氏度"
},
"value"
:
"fahrenheit"
},
{
"label"
:
{
"en-US"
:
"Centigrade"
,
"zh-Hans"
:
"摄氏度"
},
"value"
:
"centigrade"
}
],
"default"
:
"centigrade"
,
"placeholder"
:
"Please select temperature unit"
}
]
}
\ No newline at end of file
api/core/external_data_tool/weather_search/weather_search.py
deleted
100644 → 0
View file @
66cdf577
from
typing
import
Optional
from
core.external_data_tool.base
import
ExternalDataTool
class
WeatherSearch
(
ExternalDataTool
):
"""
The name of custom type must be unique, keep the same with directory and file name.
"""
name
:
str
=
"weather_search"
@
classmethod
def
validate_config
(
cls
,
tenant_id
:
str
,
config
:
dict
)
->
None
:
"""
schema.json validation. It will be called when user save the config.
Example:
.. code-block:: python
config = {
"temperature_unit": "centigrade"
}
:param tenant_id: the id of workspace
:param config: the variables of form config
:return:
"""
if
not
config
.
get
(
'temperature_unit'
):
raise
ValueError
(
'temperature unit is required'
)
def
query
(
self
,
inputs
:
dict
,
query
:
Optional
[
str
]
=
None
)
->
str
:
"""
Query the external data tool.
:param inputs: user inputs
:param query: the query of chat app
:return: the tool query result
"""
city
=
inputs
.
get
(
'city'
)
temperature_unit
=
self
.
config
.
get
(
'temperature_unit'
)
if
temperature_unit
==
'fahrenheit'
:
return
f
'Weather in {city} is 32°F'
else
:
return
f
'Weather in {city} is 0°C'
api/core/moderation/cloud_service/__init__.py
deleted
100644 → 0
View file @
66cdf577
api/core/moderation/cloud_service/cloud_service.py
deleted
100644 → 0
View file @
66cdf577
from
core.moderation.base
import
Moderation
,
ModerationAction
,
ModerationInputsResult
,
ModerationOutputsResult
class
CloudServiceModeration
(
Moderation
):
"""
The name of custom type must be unique, keep the same with directory and file name.
"""
name
:
str
=
"cloud_service"
@
classmethod
def
validate_config
(
cls
,
tenant_id
:
str
,
config
:
dict
)
->
None
:
"""
schema.json validation. It will be called when user save the config.
Example:
.. code-block:: python
config = {
"cloud_provider": "GoogleCloud",
"api_endpoint": "https://api.example.com",
"api_keys": "123456",
"inputs_config": {
"enabled": True,
"preset_response": "Your content violates our usage policy. Please revise and try again."
},
"outputs_config": {
"enabled": True,
"preset_response": "Your content violates our usage policy. Please revise and try again."
}
}
:param tenant_id: the id of workspace
:param config: the variables of form config
:return:
"""
cls
.
_validate_inputs_and_outputs_config
(
config
,
True
)
if
not
config
.
get
(
"cloud_provider"
):
raise
ValueError
(
"cloud_provider is required"
)
if
not
config
.
get
(
"api_endpoint"
):
raise
ValueError
(
"api_endpoint is required"
)
if
not
config
.
get
(
"api_keys"
):
raise
ValueError
(
"api_keys is required"
)
def
moderation_for_inputs
(
self
,
inputs
:
dict
,
query
:
str
=
""
)
->
ModerationInputsResult
:
"""
Moderation for inputs.
:param inputs: user inputs
:param query: the query of chat app, there is empty if is completion app
:return: the moderation result
"""
flagged
=
False
preset_response
=
""
if
self
.
config
[
'inputs_config'
][
'enabled'
]:
preset_response
=
self
.
config
[
'inputs_config'
][
'preset_response'
]
if
query
:
inputs
[
'query__'
]
=
query
flagged
=
self
.
_is_violated
(
inputs
)
# return ModerationInputsResult(flagged=flagged, action=ModerationAction.OVERRIDED, inputs=inputs, query=query)
return
ModerationInputsResult
(
flagged
=
flagged
,
action
=
ModerationAction
.
DIRECT_OUTPUT
,
preset_response
=
preset_response
)
def
moderation_for_outputs
(
self
,
text
:
str
)
->
ModerationOutputsResult
:
"""
Moderation for outputs.
:param text: the text of LLM response
:return: the moderation result
"""
flagged
=
False
preset_response
=
""
if
self
.
config
[
'outputs_config'
][
'enabled'
]:
preset_response
=
self
.
config
[
'outputs_config'
][
'preset_response'
]
flagged
=
self
.
_is_violated
({
'text'
:
text
})
# return ModerationOutputsResult(flagged=flagged, action=ModerationAction.OVERRIDED, text=text)
return
ModerationOutputsResult
(
flagged
=
flagged
,
action
=
ModerationAction
.
DIRECT_OUTPUT
,
preset_response
=
preset_response
)
def
_is_violated
(
self
,
inputs
:
dict
):
"""
The main logic of moderation.
:param inputs:
:return: the moderation result
"""
return
False
api/core/moderation/cloud_service/schema.json
deleted
100644 → 0
View file @
66cdf577
{
"label"
:
{
"en-US"
:
"Cloud Service"
,
"zh-Hans"
:
"云服务"
},
"form_schema"
:
[
{
"type"
:
"select"
,
"label"
:
{
"en-US"
:
"Cloud Provider"
,
"zh-Hans"
:
"云厂商"
},
"variable"
:
"cloud_provider"
,
"required"
:
true
,
"options"
:
[
{
"label"
:
{
"en-US"
:
"AWS"
,
"zh-Hans"
:
"亚马逊"
},
"value"
:
"AWS"
},
{
"label"
:
{
"en-US"
:
"Google Cloud"
,
"zh-Hans"
:
"谷歌云"
},
"value"
:
"GoogleCloud"
},
{
"label"
:
{
"en-US"
:
"Azure Cloud"
,
"zh-Hans"
:
"微软云"
},
"value"
:
"Azure"
}
],
"default"
:
"GoogleCloud"
,
"placeholder"
:
""
},
{
"type"
:
"text-input"
,
"label"
:
{
"en-US"
:
"API Endpoint"
,
"zh-Hans"
:
"API Endpoint"
},
"variable"
:
"api_endpoint"
,
"required"
:
true
,
"max_length"
:
100
,
"default"
:
""
,
"placeholder"
:
"https://api.example.com"
},
{
"type"
:
"paragraph"
,
"label"
:
{
"en-US"
:
"API Key"
,
"zh-Hans"
:
"API Key"
},
"variable"
:
"api_keys"
,
"required"
:
true
,
"default"
:
""
,
"placeholder"
:
"Paste your API key here"
}
]
}
\ 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