H commited on
Commit
22978e1
·
1 Parent(s): 51856f7

Add component AkShare (#2290)

Browse files

### What problem does this PR solve?

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

agent/component/__init__.py CHANGED
@@ -26,6 +26,7 @@ from .yahoofinance import YahooFinance, YahooFinanceParam
26
  from .wencai import WenCai, WenCaiParam
27
  from .jin10 import Jin10, Jin10Param
28
  from .tushare import TuShare, TuShareParam
 
29
 
30
 
31
  def component_class(class_name):
 
26
  from .wencai import WenCai, WenCaiParam
27
  from .jin10 import Jin10, Jin10Param
28
  from .tushare import TuShare, TuShareParam
29
+ from .akshare import AkShare, AkShareParam
30
 
31
 
32
  def component_class(class_name):
agent/component/akshare.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from abc import ABC
17
+ import pandas as pd
18
+ import akshare as ak
19
+ from agent.component.base import ComponentBase, ComponentParamBase
20
+
21
+
22
+ class AkShareParam(ComponentParamBase):
23
+ """
24
+ Define the AkShare component parameters.
25
+ """
26
+
27
+ def __init__(self):
28
+ super().__init__()
29
+ self.top_n = 10
30
+
31
+ def check(self):
32
+ self.check_positive_integer(self.top_n, "Top N")
33
+
34
+
35
+ class AkShare(ComponentBase, ABC):
36
+ component_name = "AkShare"
37
+
38
+ def _run(self, history, **kwargs):
39
+ ans = self.get_input()
40
+ ans = ",".join(ans["content"]) if "content" in ans else ""
41
+ if not ans:
42
+ return AkShare.be_output("")
43
+
44
+ try:
45
+ ak_res = []
46
+ stock_news_em_df = ak.stock_news_em(symbol=ans)
47
+ stock_news_em_df = stock_news_em_df.head(self._param.top_n)
48
+ ak_res = [{"content": '<a href="' + i["新闻链接"] + '">' + i["新闻标题"] + '</a>\n 新闻内容: ' + i[
49
+ "新闻内容"] + " \n发布时间:" + i["发布时间"] + " \n文章来源: " + i["文章来源"]} for index, i in stock_news_em_df.iterrows()]
50
+ except Exception as e:
51
+ return AkShare.be_output("**ERROR**: " + str(e))
52
+
53
+ if not ak_res:
54
+ return AkShare.be_output("")
55
+
56
+ return pd.DataFrame(ak_res)
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
- anthropic===0.34.1
 
2
  arxiv==2.1.3
3
  Aspose.Slides==24.2.0
4
  BCEmbedding==0.1.3
 
1
+ akshare==1.14.72
2
+ anthropic==0.34.1
3
  arxiv==2.1.3
4
  Aspose.Slides==24.2.0
5
  BCEmbedding==0.1.3
requirements_arm.txt CHANGED
@@ -170,3 +170,4 @@ tabulate==0.9.0
170
  vertexai==1.64.0
171
  yfinance==0.2.43
172
  pywencai==0.12.2
 
 
170
  vertexai==1.64.0
171
  yfinance==0.2.43
172
  pywencai==0.12.2
173
+ akshare==1.14.72