-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/langgenius/dify into add_pr…
…ovider
- Loading branch information
Showing
21 changed files
with
209 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
- wikipedia | ||
- nominatim | ||
- yahoo | ||
- alphavantage | ||
- arxiv | ||
- pubmed | ||
- stablediffusion | ||
|
7 changes: 7 additions & 0 deletions
7
api/core/tools/provider/builtin/alphavantage/_assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions
22
api/core/tools/provider/builtin/alphavantage/alphavantage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Any | ||
|
||
from core.tools.errors import ToolProviderCredentialValidationError | ||
from core.tools.provider.builtin.alphavantage.tools.query_stock import QueryStockTool | ||
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController | ||
|
||
|
||
class AlphaVantageProvider(BuiltinToolProviderController): | ||
def _validate_credentials(self, credentials: dict[str, Any]) -> None: | ||
try: | ||
QueryStockTool().fork_tool_runtime( | ||
runtime={ | ||
"credentials": credentials, | ||
} | ||
).invoke( | ||
user_id='', | ||
tool_parameters={ | ||
"code": "AAPL", # Apple Inc. | ||
}, | ||
) | ||
except Exception as e: | ||
raise ToolProviderCredentialValidationError(str(e)) |
31 changes: 31 additions & 0 deletions
31
api/core/tools/provider/builtin/alphavantage/alphavantage.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
identity: | ||
author: zhuhao | ||
name: alphavantage | ||
label: | ||
en_US: AlphaVantage | ||
zh_Hans: AlphaVantage | ||
pt_BR: AlphaVantage | ||
description: | ||
en_US: AlphaVantage is an online platform that provides financial market data and APIs, making it convenient for individual investors and developers to access stock quotes, technical indicators, and stock analysis. | ||
zh_Hans: AlphaVantage是一个在线平台,它提供金融市场数据和API,便于个人投资者和开发者获取股票报价、技术指标和股票分析。 | ||
pt_BR: AlphaVantage is an online platform that provides financial market data and APIs, making it convenient for individual investors and developers to access stock quotes, technical indicators, and stock analysis. | ||
icon: icon.svg | ||
tags: | ||
- finance | ||
credentials_for_provider: | ||
api_key: | ||
type: secret-input | ||
required: true | ||
label: | ||
en_US: AlphaVantage API key | ||
zh_Hans: AlphaVantage API key | ||
pt_BR: AlphaVantage API key | ||
placeholder: | ||
en_US: Please input your AlphaVantage API key | ||
zh_Hans: 请输入你的 AlphaVantage API key | ||
pt_BR: Please input your AlphaVantage API key | ||
help: | ||
en_US: Get your AlphaVantage API key from AlphaVantage | ||
zh_Hans: 从 AlphaVantage 获取您的 AlphaVantage API key | ||
pt_BR: Get your AlphaVantage API key from AlphaVantage | ||
url: https://www.alphavantage.co/support/#api-key |
49 changes: 49 additions & 0 deletions
49
api/core/tools/provider/builtin/alphavantage/tools/query_stock.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from typing import Any, Union | ||
|
||
import requests | ||
|
||
from core.tools.entities.tool_entities import ToolInvokeMessage | ||
from core.tools.tool.builtin_tool import BuiltinTool | ||
|
||
ALPHAVANTAGE_API_URL = "https://www.alphavantage.co/query" | ||
|
||
|
||
class QueryStockTool(BuiltinTool): | ||
|
||
def _invoke(self, | ||
user_id: str, | ||
tool_parameters: dict[str, Any], | ||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]: | ||
|
||
stock_code = tool_parameters.get('code', '') | ||
if not stock_code: | ||
return self.create_text_message('Please tell me your stock code') | ||
|
||
if 'api_key' not in self.runtime.credentials or not self.runtime.credentials.get('api_key'): | ||
return self.create_text_message("Alpha Vantage API key is required.") | ||
|
||
params = { | ||
"function": "TIME_SERIES_DAILY", | ||
"symbol": stock_code, | ||
"outputsize": "compact", | ||
"datatype": "json", | ||
"apikey": self.runtime.credentials['api_key'] | ||
} | ||
response = requests.get(url=ALPHAVANTAGE_API_URL, params=params) | ||
response.raise_for_status() | ||
result = self._handle_response(response.json()) | ||
return self.create_json_message(result) | ||
|
||
def _handle_response(self, response: dict[str, Any]) -> dict[str, Any]: | ||
result = response.get('Time Series (Daily)', {}) | ||
if not result: | ||
return {} | ||
stock_result = {} | ||
for k, v in result.items(): | ||
stock_result[k] = {} | ||
stock_result[k]['open'] = v.get('1. open') | ||
stock_result[k]['high'] = v.get('2. high') | ||
stock_result[k]['low'] = v.get('3. low') | ||
stock_result[k]['close'] = v.get('4. close') | ||
stock_result[k]['volume'] = v.get('5. volume') | ||
return stock_result |
27 changes: 27 additions & 0 deletions
27
api/core/tools/provider/builtin/alphavantage/tools/query_stock.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
identity: | ||
name: query_stock | ||
author: zhuhao | ||
label: | ||
en_US: query_stock | ||
zh_Hans: query_stock | ||
pt_BR: query_stock | ||
description: | ||
human: | ||
en_US: Retrieve information such as daily opening price, daily highest price, daily lowest price, daily closing price, and daily trading volume for a specified stock symbol. | ||
zh_Hans: 获取指定股票代码的每日开盘价、每日最高价、每日最低价、每日收盘价和每日交易量等信息。 | ||
pt_BR: Retrieve information such as daily opening price, daily highest price, daily lowest price, daily closing price, and daily trading volume for a specified stock symbol | ||
llm: Retrieve information such as daily opening price, daily highest price, daily lowest price, daily closing price, and daily trading volume for a specified stock symbol | ||
parameters: | ||
- name: code | ||
type: string | ||
required: true | ||
label: | ||
en_US: stock code | ||
zh_Hans: 股票代码 | ||
pt_BR: stock code | ||
human_description: | ||
en_US: stock code | ||
zh_Hans: 股票代码 | ||
pt_BR: stock code | ||
llm_description: stock code for query from alphavantage | ||
form: llm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.