Feat/assistant app (#2086)
Co-authored-by: chenhe <guchenhe@gmail.com> Co-authored-by: Pascal M <11357019+perzeuss@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="23" viewBox="0 0 22 23" fill="none">
|
||||
<path d="M21.4992 14.615L17.0326 15.5683L17.4865 20.0065L13.3037 18.2132L10.9994 22.0669L8.69549 18.2132L4.51225 20.0065L4.96656 15.5678L0.5 14.615L3.542 11.2832L0.5 7.9519L4.96656 6.99854L4.51225 2.55981L8.69549 4.35369L10.9994 0.5L13.3037 4.35369L17.4865 2.56031L17.0326 7.00401L21.4992 7.9519L18.4572 11.2832L21.4992 14.615Z" fill="#F16850"/>
|
||||
<path d="M10.9993 7.23111L8.69495 4.35315L4.51221 2.56026L7.00396 5.84084L10.9993 7.23111Z" fill="#FD694F"/>
|
||||
<path d="M4.96656 6.99847L0.5 7.95183L3.542 11.2831L7.11734 9.9838L4.96656 6.99847Z" fill="#FF3413"/>
|
||||
<path d="M7.00346 5.84037L4.51221 2.55978L4.96602 6.99851L7.11729 9.98384L7.00346 5.84037Z" fill="#DC1D23"/>
|
||||
<path d="M13.3031 4.35369L10.9987 0.5L8.69434 4.35369L10.9987 7.23116L13.3031 4.35369Z" fill="#FF9281"/>
|
||||
<path d="M18.4577 11.2831L21.4997 7.95183L17.0331 6.99847L14.8818 9.9838L18.4577 11.2831Z" fill="#FF8B79"/>
|
||||
<path d="M14.8823 9.98384L17.0331 6.99851L17.4929 2.55978L14.9957 5.84037L14.8818 9.98384H14.8823Z" fill="#FD694F"/>
|
||||
<path d="M14.9954 5.84034L17.4926 2.55975L13.3044 4.35364L11 7.23111L14.9954 5.84034Z" fill="#EF5240"/>
|
||||
<path d="M17.47 13.2694L21.4997 14.6149L18.4577 11.2831L14.8818 9.98383L17.47 13.2694Z" fill="#FF482C"/>
|
||||
<path d="M7.11783 9.98383L3.542 11.2831L0.5 14.6149L4.52965 13.2699L7.11783 9.98383Z" fill="#EC2101"/>
|
||||
<path d="M11 17.8612V22.0664L13.3044 18.2132L13.4008 14.439L11 17.8612Z" fill="#D21C22"/>
|
||||
<path d="M17.4703 13.2693L13.4009 14.4389L17.0334 15.5682L21.4999 14.6149L17.4703 13.2693Z" fill="#C90901"/>
|
||||
<path d="M13.3042 18.2132L17.4874 20.0065L17.0331 15.5683L13.4011 14.439L13.3042 18.2132Z" fill="#EC2101"/>
|
||||
<path d="M4.52965 13.2693L0.5 14.6154L4.96656 15.5632L8.59906 14.4394L4.52965 13.2703V13.2693Z" fill="#B6171E"/>
|
||||
<path d="M8.59912 14.439L8.69555 18.2132L10.9999 22.0669V17.8612L8.59912 14.439Z" fill="#B4151B"/>
|
||||
<path d="M4.96602 15.5623L4.51221 20.006L8.69495 18.2131L8.59852 14.439L4.96602 15.5623Z" fill="#D21C22"/>
|
||||
<path d="M14.882 9.98384L14.9954 5.84036L11 7.23113V11.2608L14.882 9.98384Z" fill="#E63320"/>
|
||||
<path d="M11.0003 7.23113L7.00391 5.84036L7.11773 9.98384L10.9998 11.2608L11.0003 7.23113Z" fill="#FF4527"/>
|
||||
<path d="M8.59912 14.439L10.9999 17.8613L13.4007 14.439L10.9999 11.2608L8.59912 14.439Z" fill="#FF9281"/>
|
||||
<path d="M11 11.2608L13.4008 14.439L17.4702 13.2699L14.882 9.98386L11 11.2608Z" fill="#FD684D"/>
|
||||
<path d="M7.1165 9.9839L4.52832 13.2694L8.59773 14.439L10.9985 11.2608L7.1165 9.9839Z" fill="#FD745C"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
@@ -0,0 +1,77 @@
|
||||
from core.tools.tool.builtin_tool import BuiltinTool
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage
|
||||
from core.tools.errors import ToolProviderCredentialValidationError, ToolInvokeError
|
||||
|
||||
from typing import Any, Dict, List, Union
|
||||
|
||||
from httpx import get
|
||||
|
||||
class WolframAlphaTool(BuiltinTool):
|
||||
_base_url = 'https://api.wolframalpha.com/v2/query'
|
||||
|
||||
def _invoke(self,
|
||||
user_id: str,
|
||||
tool_paramters: Dict[str, Any],
|
||||
) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
query = tool_paramters.get('query', '')
|
||||
if not query:
|
||||
return self.create_text_message('Please input query')
|
||||
appid = self.runtime.credentials.get('appid', '')
|
||||
if not appid:
|
||||
raise ToolProviderCredentialValidationError('Please input appid')
|
||||
|
||||
params = {
|
||||
'appid': appid,
|
||||
'input': query,
|
||||
'includepodid': 'Result',
|
||||
'format': 'plaintext',
|
||||
'output': 'json'
|
||||
}
|
||||
|
||||
finished = False
|
||||
result = None
|
||||
# try 3 times at most
|
||||
counter = 0
|
||||
|
||||
while not finished and counter < 3:
|
||||
counter += 1
|
||||
try:
|
||||
response = get(self._base_url, params=params, timeout=20)
|
||||
response.raise_for_status()
|
||||
response_data = response.json()
|
||||
except Exception as e:
|
||||
raise ToolInvokeError(str(e))
|
||||
|
||||
if 'success' not in response_data['queryresult'] or response_data['queryresult']['success'] != True:
|
||||
query_result = response_data.get('queryresult', {})
|
||||
if 'error' in query_result and query_result['error']:
|
||||
if 'msg' in query_result['error']:
|
||||
if query_result['error']['msg'] == 'Invalid appid':
|
||||
raise ToolProviderCredentialValidationError('Invalid appid')
|
||||
raise ToolInvokeError('Failed to invoke tool')
|
||||
|
||||
if 'didyoumeans' in response_data['queryresult']:
|
||||
# get the most likely interpretation
|
||||
query = ''
|
||||
max_score = 0
|
||||
for didyoumean in response_data['queryresult']['didyoumeans']:
|
||||
if float(didyoumean['score']) > max_score:
|
||||
query = didyoumean['val']
|
||||
max_score = float(didyoumean['score'])
|
||||
|
||||
params['input'] = query
|
||||
else:
|
||||
finished = True
|
||||
if 'souces' in response_data['queryresult']:
|
||||
return self.create_link_message(response_data['queryresult']['sources']['url'])
|
||||
elif 'pods' in response_data['queryresult']:
|
||||
result = response_data['queryresult']['pods'][0]['subpods'][0]['plaintext']
|
||||
|
||||
if not finished or not result:
|
||||
return self.create_text_message('No result found')
|
||||
|
||||
return self.create_text_message(result)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
identity:
|
||||
name: wolframalpha
|
||||
author: Dify
|
||||
label:
|
||||
en_US: WolframAlpha
|
||||
zh_Hans: WolframAlpha
|
||||
description:
|
||||
human:
|
||||
en_US: WolframAlpha is a powerful computational knowledge engine.
|
||||
zh_Hans: WolframAlpha 是一个强大的计算知识引擎。
|
||||
llm: WolframAlpha is a powerful computational knowledge engine. one single query can get the answer of a question.
|
||||
parameters:
|
||||
- name: query
|
||||
type: string
|
||||
required: true
|
||||
label:
|
||||
en_US: Query string
|
||||
zh_Hans: 计算语句
|
||||
human_description:
|
||||
en_US: used for calculating
|
||||
zh_Hans: 用于计算最终结果
|
||||
llm_description: a single query for calculating
|
||||
form: llm
|
||||
24
api/core/tools/provider/builtin/wolframalpha/wolframalpha.py
Normal file
24
api/core/tools/provider/builtin/wolframalpha/wolframalpha.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolProviderType
|
||||
from core.tools.tool.tool import Tool
|
||||
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
|
||||
from core.tools.errors import ToolProviderCredentialValidationError
|
||||
|
||||
from core.tools.provider.builtin.wolframalpha.tools.wolframalpha import WolframAlphaTool
|
||||
|
||||
from typing import Any, Dict, List
|
||||
|
||||
class GoogleProvider(BuiltinToolProviderController):
|
||||
def _validate_credentials(self, credentials: Dict[str, Any]) -> None:
|
||||
try:
|
||||
WolframAlphaTool().fork_tool_runtime(
|
||||
meta={
|
||||
"credentials": credentials,
|
||||
}
|
||||
).invoke(
|
||||
user_id='',
|
||||
tool_paramters={
|
||||
"query": "1+2+....+111",
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
raise ToolProviderCredentialValidationError(str(e))
|
||||
@@ -0,0 +1,24 @@
|
||||
identity:
|
||||
author: Dify
|
||||
name: wolframalpha
|
||||
label:
|
||||
en_US: WolframAlpha
|
||||
zh_Hans: WolframAlpha
|
||||
description:
|
||||
en_US: WolframAlpha is a powerful computational knowledge engine.
|
||||
zh_Hans: WolframAlpha 是一个强大的计算知识引擎。
|
||||
icon: icon.svg
|
||||
credentails_for_provider:
|
||||
appid:
|
||||
type: secret-input
|
||||
required: true
|
||||
label:
|
||||
en_US: WolframAlpha AppID
|
||||
zh_Hans: WolframAlpha AppID
|
||||
placeholder:
|
||||
en_US: Please input your WolframAlpha AppID
|
||||
zh_Hans: 请输入你的 WolframAlpha AppID
|
||||
help:
|
||||
en_US: Get your WolframAlpha AppID from WolframAlpha, please use "full results" api access.
|
||||
zh_Hans: 从 WolframAlpha 获取您的 WolframAlpha AppID,请使用 "full results" API。
|
||||
url: https://products.wolframalpha.com/api
|
||||
Reference in New Issue
Block a user