RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Add component Jin10 (#2271)
Hfd3e55cfcfe9
diff --git a/agent/component/__init__.py b/agent/component/__init__.pyindex 87bf80d049..619663f3ca 100644--- a/agent/component/__init__.py+++ b/agent/component/__init__.py@@ -24,6 +24,7 @@ from .qweather import QWeather, QWeatherParamfrom .exesql import ExeSQL, ExeSQLParamfrom .yahoofinance import YahooFinance, YahooFinanceParamfrom .wencai import WenCai, WenCaiParam+from .jin10 import Jin10, Jin10Paramdef component_class(class_name):diff --git a/agent/component/jin10.py b/agent/component/jin10.pynew file mode 100644index 0000000000..b133f8d140--- /dev/null+++ b/agent/component/jin10.py@@ -0,0 +1,130 @@+#+# Copyright 2024 The InfiniFlow Authors. All Rights Reserved.+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#+import json+from abc import ABC+import pandas as pd+import requests+from agent.component.base import ComponentBase, ComponentParamBase+++class Jin10Param(ComponentParamBase):+ """+ Define the Jin10 component parameters.+ """++ def __init__(self):+ super().__init__()+ self.type = "flash"+ self.secret_key = "xxx"+ self.flash_type = '1'+ self.calendar_type = 'cj'+ self.calendar_datatype = 'data'+ self.symbols_type = 'GOODS'+ self.symbols_datatype = 'symbols'+ self.contain = ""+ self.filter = ""++ def check(self):+ self.check_valid_value(self.type, "Type", ['flash', 'calendar', 'symbols', 'news'])+ self.check_valid_value(self.flash_type, "Flash Type", ['1', '2', '3', '4', '5'])+ self.check_valid_value(self.calendar_type, "Calendar Type", ['cj', 'qh', 'hk', 'us'])+ self.check_valid_value(self.calendar_datatype, "Calendar DataType", ['data', 'event', 'holiday'])+ self.check_valid_value(self.symbols_type, "Symbols Type", ['GOODS', 'FOREX', 'FUTURE', 'CRYPTO'])+ self.check_valid_value(self.symbols_datatype, 'Symbols DataType', ['symbols', 'quotes'])+++class Jin10(ComponentBase, ABC):+ component_name = "Jin10"++ def _run(self, history, **kwargs):+ ans = self.get_input()+ ans = " - ".join(ans["content"]) if "content" in ans else ""+ if not ans:+ return Jin10.be_output("")++ jin10_res = []+ headers = {'secret-key': self._param.secret_key}+ try:+ if self._param.type == "flash":+ params = {+ 'category': self._param.flash_type,+ 'contain': self._param.contain,+ 'filter': self._param.filter+ }+ response = requests.get(+ url='https://open-data-api.jin10.com/data-api/flash?category=' + self._param.flash_type,+ headers=headers, data=json.dumps(params))+ response = response.json()+ for i in response['data']:+ jin10_res.append({"content": i['data']['content']})+ if self._param.type == "calendar":+ params = {+ 'category': self._param.calendar_type+ }+ response = requests.get(+ url='https://open-data-api.jin10.com/data-api/calendar/' + self._param.calendar_datatype + '?category=' + self._param.calendar_type,+ headers=headers, data=json.dumps(params))++ response = response.json()+ jin10_res.append({"content": pd.DataFrame(response['data']).to_markdown()})+ if self._param.type == "symbols":+ params = {+ 'type': self._param.symbols_type+ }+ if self._param.symbols_datatype == "quotes":+ params['codes'] = 'BTCUSD'+ response = requests.get(+ url='https://open-data-api.jin10.com/data-api/' + self._param.symbols_datatype + '?type=' + self._param.symbols_type,+ headers=headers, data=json.dumps(params))+ response = response.json()+ if self._param.symbols_datatype == "symbols":+ for i in response['data']:+ i['Commodity Code'] = i['c']+ i['Stock Exchange'] = i['e']+ i['Commodity Name'] = i['n']+ i['Commodity Type'] = i['t']+ del i['c'], i['e'], i['n'], i['t']+ if self._param.symbols_datatype == "quotes":+ for i in response['data']:+ i['Selling Price'] = i['a']+ i['buying price'] = i['b']+ i['commodity code'] = i['c']+ i['Stock Exchange'] = i['e']+ i['Highest Price'] = i['h']+ i['Yesterday’s Closing Price'] = i['hc']+ i['Lowest Price'] = i['l']+ i['Opening Price'] = i['o']+ i['Latest Price'] = i['p']+ i['Market Quote Time'] = i['t']+ del i['a'], i['b'], i['c'], i['e'], i['h'], i['hc'], i['l'], i['o'], i['p'], i['t']+ jin10_res.append({"content": pd.DataFrame(response['data']).to_markdown()})+ if self._param.type == "news":+ params = {+ 'contain': self._param.contain,+ 'filter': self._param.filter+ }+ response = requests.get(+ url='https://open-data-api.jin10.com/data-api/news',+ headers=headers, data=json.dumps(params))+ response = response.json()+ jin10_res.append({"content": pd.DataFrame(response['data']).to_markdown()})+ except Exception as e:+ return Jin10.be_output("**ERROR**: " + str(e))++ if not jin10_res:+ return Jin10.be_output("")++ return pd.DataFrame(jin10_res)