lionagi 0.0.312__py3-none-any.whl → 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lionagi/__init__.py +61 -3
- lionagi/core/__init__.py +0 -14
- lionagi/core/_setting/_setting.py +59 -0
- lionagi/core/action/__init__.py +14 -0
- lionagi/core/action/function_calling.py +136 -0
- lionagi/core/action/manual.py +1 -0
- lionagi/core/action/node.py +109 -0
- lionagi/core/action/tool.py +114 -0
- lionagi/core/action/tool_manager.py +356 -0
- lionagi/core/agent/__init__.py +0 -3
- lionagi/core/agent/base_agent.py +45 -36
- lionagi/core/agent/eval/evaluator.py +1 -0
- lionagi/core/agent/eval/vote.py +40 -0
- lionagi/core/agent/learn/learner.py +59 -0
- lionagi/core/agent/plan/unit_template.py +1 -0
- lionagi/core/collections/__init__.py +17 -0
- lionagi/core/collections/_logger.py +319 -0
- lionagi/core/collections/abc/__init__.py +53 -0
- lionagi/core/collections/abc/component.py +615 -0
- lionagi/core/collections/abc/concepts.py +297 -0
- lionagi/core/collections/abc/exceptions.py +150 -0
- lionagi/core/collections/abc/util.py +45 -0
- lionagi/core/collections/exchange.py +161 -0
- lionagi/core/collections/flow.py +426 -0
- lionagi/core/collections/model.py +419 -0
- lionagi/core/collections/pile.py +913 -0
- lionagi/core/collections/progression.py +236 -0
- lionagi/core/collections/util.py +64 -0
- lionagi/core/director/direct.py +314 -0
- lionagi/core/director/director.py +2 -0
- lionagi/core/engine/branch_engine.py +333 -0
- lionagi/core/engine/instruction_map_engine.py +204 -0
- lionagi/core/engine/sandbox_.py +14 -0
- lionagi/core/engine/script_engine.py +99 -0
- lionagi/core/executor/base_executor.py +90 -0
- lionagi/core/executor/graph_executor.py +330 -0
- lionagi/core/executor/neo4j_executor.py +384 -0
- lionagi/core/generic/__init__.py +7 -0
- lionagi/core/generic/edge.py +112 -0
- lionagi/core/generic/edge_condition.py +16 -0
- lionagi/core/generic/graph.py +236 -0
- lionagi/core/generic/hyperedge.py +1 -0
- lionagi/core/generic/node.py +220 -0
- lionagi/core/generic/tree.py +48 -0
- lionagi/core/generic/tree_node.py +79 -0
- lionagi/core/mail/__init__.py +7 -3
- lionagi/core/mail/mail.py +25 -0
- lionagi/core/mail/mail_manager.py +142 -58
- lionagi/core/mail/package.py +45 -0
- lionagi/core/mail/start_mail.py +36 -0
- lionagi/core/message/__init__.py +19 -0
- lionagi/core/message/action_request.py +133 -0
- lionagi/core/message/action_response.py +135 -0
- lionagi/core/message/assistant_response.py +95 -0
- lionagi/core/message/instruction.py +234 -0
- lionagi/core/message/message.py +101 -0
- lionagi/core/message/system.py +86 -0
- lionagi/core/message/util.py +283 -0
- lionagi/core/report/__init__.py +4 -0
- lionagi/core/report/base.py +217 -0
- lionagi/core/report/form.py +231 -0
- lionagi/core/report/report.py +166 -0
- lionagi/core/report/util.py +28 -0
- lionagi/core/rule/__init__.py +0 -0
- lionagi/core/rule/_default.py +16 -0
- lionagi/core/rule/action.py +99 -0
- lionagi/core/rule/base.py +238 -0
- lionagi/core/rule/boolean.py +56 -0
- lionagi/core/rule/choice.py +47 -0
- lionagi/core/rule/mapping.py +96 -0
- lionagi/core/rule/number.py +71 -0
- lionagi/core/rule/rulebook.py +109 -0
- lionagi/core/rule/string.py +52 -0
- lionagi/core/rule/util.py +35 -0
- lionagi/core/session/__init__.py +0 -3
- lionagi/core/session/branch.py +431 -0
- lionagi/core/session/directive_mixin.py +287 -0
- lionagi/core/session/session.py +230 -902
- lionagi/core/structure/__init__.py +1 -0
- lionagi/core/structure/chain.py +1 -0
- lionagi/core/structure/forest.py +1 -0
- lionagi/core/structure/graph.py +1 -0
- lionagi/core/structure/tree.py +1 -0
- lionagi/core/unit/__init__.py +5 -0
- lionagi/core/unit/parallel_unit.py +245 -0
- lionagi/core/unit/template/__init__.py +0 -0
- lionagi/core/unit/template/action.py +81 -0
- lionagi/core/unit/template/base.py +51 -0
- lionagi/core/unit/template/plan.py +84 -0
- lionagi/core/unit/template/predict.py +109 -0
- lionagi/core/unit/template/score.py +124 -0
- lionagi/core/unit/template/select.py +104 -0
- lionagi/core/unit/unit.py +362 -0
- lionagi/core/unit/unit_form.py +305 -0
- lionagi/core/unit/unit_mixin.py +1168 -0
- lionagi/core/unit/util.py +71 -0
- lionagi/core/validator/__init__.py +0 -0
- lionagi/core/validator/validator.py +364 -0
- lionagi/core/work/__init__.py +0 -0
- lionagi/core/work/work.py +76 -0
- lionagi/core/work/work_function.py +101 -0
- lionagi/core/work/work_queue.py +103 -0
- lionagi/core/work/worker.py +258 -0
- lionagi/core/work/worklog.py +120 -0
- lionagi/experimental/__init__.py +0 -0
- lionagi/experimental/compressor/__init__.py +0 -0
- lionagi/experimental/compressor/base.py +46 -0
- lionagi/experimental/compressor/llm_compressor.py +247 -0
- lionagi/experimental/compressor/llm_summarizer.py +61 -0
- lionagi/experimental/compressor/util.py +70 -0
- lionagi/experimental/directive/__init__.py +19 -0
- lionagi/experimental/directive/parser/__init__.py +0 -0
- lionagi/experimental/directive/parser/base_parser.py +282 -0
- lionagi/experimental/directive/template/__init__.py +0 -0
- lionagi/experimental/directive/template/base_template.py +79 -0
- lionagi/experimental/directive/template/schema.py +36 -0
- lionagi/experimental/directive/tokenizer.py +73 -0
- lionagi/experimental/evaluator/__init__.py +0 -0
- lionagi/experimental/evaluator/ast_evaluator.py +131 -0
- lionagi/experimental/evaluator/base_evaluator.py +218 -0
- lionagi/experimental/knowledge/__init__.py +0 -0
- lionagi/experimental/knowledge/base.py +10 -0
- lionagi/experimental/knowledge/graph.py +0 -0
- lionagi/experimental/memory/__init__.py +0 -0
- lionagi/experimental/strategies/__init__.py +0 -0
- lionagi/experimental/strategies/base.py +1 -0
- lionagi/integrations/bridge/autogen_/__init__.py +0 -0
- lionagi/integrations/bridge/autogen_/autogen_.py +124 -0
- lionagi/integrations/bridge/langchain_/documents.py +4 -0
- lionagi/integrations/bridge/llamaindex_/index.py +30 -0
- lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +6 -0
- lionagi/integrations/bridge/llamaindex_/llama_pack.py +227 -0
- lionagi/integrations/bridge/llamaindex_/node_parser.py +6 -9
- lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +1 -0
- lionagi/integrations/bridge/transformers_/__init__.py +0 -0
- lionagi/integrations/bridge/transformers_/install_.py +36 -0
- lionagi/integrations/chunker/__init__.py +0 -0
- lionagi/integrations/chunker/chunk.py +312 -0
- lionagi/integrations/config/oai_configs.py +38 -7
- lionagi/integrations/config/ollama_configs.py +1 -1
- lionagi/integrations/config/openrouter_configs.py +14 -2
- lionagi/integrations/loader/__init__.py +0 -0
- lionagi/integrations/loader/load.py +253 -0
- lionagi/integrations/loader/load_util.py +195 -0
- lionagi/integrations/provider/_mapping.py +46 -0
- lionagi/integrations/provider/litellm.py +2 -1
- lionagi/integrations/provider/mlx_service.py +16 -9
- lionagi/integrations/provider/oai.py +91 -4
- lionagi/integrations/provider/ollama.py +7 -6
- lionagi/integrations/provider/openrouter.py +115 -8
- lionagi/integrations/provider/services.py +2 -2
- lionagi/integrations/provider/transformers.py +18 -22
- lionagi/integrations/storage/__init__.py +3 -0
- lionagi/integrations/storage/neo4j.py +665 -0
- lionagi/integrations/storage/storage_util.py +287 -0
- lionagi/integrations/storage/structure_excel.py +285 -0
- lionagi/integrations/storage/to_csv.py +63 -0
- lionagi/integrations/storage/to_excel.py +83 -0
- lionagi/libs/__init__.py +26 -1
- lionagi/libs/ln_api.py +78 -23
- lionagi/libs/ln_context.py +37 -0
- lionagi/libs/ln_convert.py +21 -9
- lionagi/libs/ln_func_call.py +69 -28
- lionagi/libs/ln_image.py +107 -0
- lionagi/libs/ln_knowledge_graph.py +405 -0
- lionagi/libs/ln_nested.py +26 -11
- lionagi/libs/ln_parse.py +110 -14
- lionagi/libs/ln_queue.py +117 -0
- lionagi/libs/ln_tokenize.py +164 -0
- lionagi/{core/prompt/field_validator.py → libs/ln_validate.py} +79 -14
- lionagi/libs/special_tokens.py +172 -0
- lionagi/libs/sys_util.py +107 -2
- lionagi/lions/__init__.py +0 -0
- lionagi/lions/coder/__init__.py +0 -0
- lionagi/lions/coder/add_feature.py +20 -0
- lionagi/lions/coder/base_prompts.py +22 -0
- lionagi/lions/coder/code_form.py +13 -0
- lionagi/lions/coder/coder.py +168 -0
- lionagi/lions/coder/util.py +96 -0
- lionagi/lions/researcher/__init__.py +0 -0
- lionagi/lions/researcher/data_source/__init__.py +0 -0
- lionagi/lions/researcher/data_source/finhub_.py +191 -0
- lionagi/lions/researcher/data_source/google_.py +199 -0
- lionagi/lions/researcher/data_source/wiki_.py +96 -0
- lionagi/lions/researcher/data_source/yfinance_.py +21 -0
- lionagi/tests/integrations/__init__.py +0 -0
- lionagi/tests/libs/__init__.py +0 -0
- lionagi/tests/libs/test_field_validators.py +353 -0
- lionagi/tests/{test_libs → libs}/test_func_call.py +23 -21
- lionagi/tests/{test_libs → libs}/test_nested.py +36 -21
- lionagi/tests/{test_libs → libs}/test_parse.py +1 -1
- lionagi/tests/libs/test_queue.py +67 -0
- lionagi/tests/test_core/collections/__init__.py +0 -0
- lionagi/tests/test_core/collections/test_component.py +206 -0
- lionagi/tests/test_core/collections/test_exchange.py +138 -0
- lionagi/tests/test_core/collections/test_flow.py +145 -0
- lionagi/tests/test_core/collections/test_pile.py +171 -0
- lionagi/tests/test_core/collections/test_progression.py +129 -0
- lionagi/tests/test_core/generic/__init__.py +0 -0
- lionagi/tests/test_core/generic/test_edge.py +67 -0
- lionagi/tests/test_core/generic/test_graph.py +96 -0
- lionagi/tests/test_core/generic/test_node.py +106 -0
- lionagi/tests/test_core/generic/test_tree_node.py +73 -0
- lionagi/tests/test_core/test_branch.py +115 -292
- lionagi/tests/test_core/test_form.py +46 -0
- lionagi/tests/test_core/test_report.py +105 -0
- lionagi/tests/test_core/test_validator.py +111 -0
- lionagi/version.py +1 -1
- {lionagi-0.0.312.dist-info → lionagi-0.2.1.dist-info}/LICENSE +12 -11
- {lionagi-0.0.312.dist-info → lionagi-0.2.1.dist-info}/METADATA +19 -118
- lionagi-0.2.1.dist-info/RECORD +240 -0
- lionagi/core/branch/__init__.py +0 -4
- lionagi/core/branch/base_branch.py +0 -654
- lionagi/core/branch/branch.py +0 -471
- lionagi/core/branch/branch_flow_mixin.py +0 -96
- lionagi/core/branch/executable_branch.py +0 -347
- lionagi/core/branch/util.py +0 -323
- lionagi/core/direct/__init__.py +0 -6
- lionagi/core/direct/predict.py +0 -161
- lionagi/core/direct/score.py +0 -278
- lionagi/core/direct/select.py +0 -169
- lionagi/core/direct/utils.py +0 -87
- lionagi/core/direct/vote.py +0 -64
- lionagi/core/flow/base/baseflow.py +0 -23
- lionagi/core/flow/monoflow/ReAct.py +0 -238
- lionagi/core/flow/monoflow/__init__.py +0 -9
- lionagi/core/flow/monoflow/chat.py +0 -95
- lionagi/core/flow/monoflow/chat_mixin.py +0 -263
- lionagi/core/flow/monoflow/followup.py +0 -214
- lionagi/core/flow/polyflow/__init__.py +0 -1
- lionagi/core/flow/polyflow/chat.py +0 -248
- lionagi/core/mail/schema.py +0 -56
- lionagi/core/messages/__init__.py +0 -3
- lionagi/core/messages/schema.py +0 -533
- lionagi/core/prompt/prompt_template.py +0 -316
- lionagi/core/schema/__init__.py +0 -22
- lionagi/core/schema/action_node.py +0 -29
- lionagi/core/schema/base_mixin.py +0 -296
- lionagi/core/schema/base_node.py +0 -199
- lionagi/core/schema/condition.py +0 -24
- lionagi/core/schema/data_logger.py +0 -354
- lionagi/core/schema/data_node.py +0 -93
- lionagi/core/schema/prompt_template.py +0 -67
- lionagi/core/schema/structure.py +0 -910
- lionagi/core/tool/__init__.py +0 -3
- lionagi/core/tool/tool_manager.py +0 -280
- lionagi/integrations/bridge/pydantic_/base_model.py +0 -7
- lionagi/tests/test_core/test_base_branch.py +0 -427
- lionagi/tests/test_core/test_chat_flow.py +0 -63
- lionagi/tests/test_core/test_mail_manager.py +0 -75
- lionagi/tests/test_core/test_prompts.py +0 -51
- lionagi/tests/test_core/test_session.py +0 -254
- lionagi/tests/test_core/test_session_base_util.py +0 -312
- lionagi/tests/test_core/test_tool_manager.py +0 -95
- lionagi-0.0.312.dist-info/RECORD +0 -111
- /lionagi/core/{branch/base → _setting}/__init__.py +0 -0
- /lionagi/core/{flow → agent/eval}/__init__.py +0 -0
- /lionagi/core/{flow/base → agent/learn}/__init__.py +0 -0
- /lionagi/core/{prompt → agent/plan}/__init__.py +0 -0
- /lionagi/core/{tool/manual.py → agent/plan/plan.py} +0 -0
- /lionagi/{tests/test_integrations → core/director}/__init__.py +0 -0
- /lionagi/{tests/test_libs → core/engine}/__init__.py +0 -0
- /lionagi/{tests/test_libs/test_async.py → core/executor/__init__.py} +0 -0
- /lionagi/tests/{test_libs → libs}/test_api.py +0 -0
- /lionagi/tests/{test_libs → libs}/test_convert.py +0 -0
- /lionagi/tests/{test_libs → libs}/test_sys_util.py +0 -0
- {lionagi-0.0.312.dist-info → lionagi-0.2.1.dist-info}/WHEEL +0 -0
- {lionagi-0.0.312.dist-info → lionagi-0.2.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,191 @@
|
|
1
|
+
import os
|
2
|
+
from lionagi.libs import convert
|
3
|
+
|
4
|
+
finnhub_key_scheme = "FINNHUB_API_KEY"
|
5
|
+
|
6
|
+
|
7
|
+
class FinnHub:
|
8
|
+
"""
|
9
|
+
A utility class for interacting with the FinnHub API to retrieve financial and market data.
|
10
|
+
|
11
|
+
Attributes:
|
12
|
+
api_key (str): The API key used for authenticating with the FinnHub API.
|
13
|
+
|
14
|
+
Methods:
|
15
|
+
get_client(api_key=None):
|
16
|
+
Returns a FinnHub API client instance for making API calls.
|
17
|
+
|
18
|
+
get_info_df(info_kind="company_news", api_key=None, **kwargs):
|
19
|
+
Retrieves data from the FinnHub API based on the specified 'info_kind' and returns it as a Pandas DataFrame.
|
20
|
+
"""
|
21
|
+
|
22
|
+
api_key = os.getenv(finnhub_key_scheme)
|
23
|
+
|
24
|
+
@classmethod
|
25
|
+
def get_client(cls, api_key=None):
|
26
|
+
"""
|
27
|
+
Creates and returns a FinnHub API client instance.
|
28
|
+
|
29
|
+
Args:
|
30
|
+
api_key (str): The API key used for authenticating with the FinnHub API. If not provided,
|
31
|
+
the class-level API key (if set) will be used.
|
32
|
+
|
33
|
+
Returns:
|
34
|
+
finnhub.Client: A FinnHub API client instance.
|
35
|
+
|
36
|
+
Raises:
|
37
|
+
ImportError: If there is an error while importing the 'finnhub' library.
|
38
|
+
"""
|
39
|
+
try:
|
40
|
+
from lionagi.libs import SysUtil
|
41
|
+
|
42
|
+
SysUtil.check_import("finnhub")
|
43
|
+
|
44
|
+
import finnhub
|
45
|
+
|
46
|
+
return finnhub.Client(api_key=api_key or cls.api_key)
|
47
|
+
except Exception as e:
|
48
|
+
raise ImportError(f"Error occured during importing finnhub: {e}")
|
49
|
+
|
50
|
+
@classmethod
|
51
|
+
def get_info_df(cls, info_kind="company_news", api_key=None, **kwargs):
|
52
|
+
"""
|
53
|
+
Retrieves data from the FinnHub API based on the specified 'info_kind' and returns it as a Pandas DataFrame.
|
54
|
+
|
55
|
+
Args:
|
56
|
+
info_kind (str): The type of information to retrieve from FinnHub. Default is "company_news".
|
57
|
+
api_key (str): The API key used for authenticating with the FinnHub API. If not provided,
|
58
|
+
the class-level API key (if set) will be used.
|
59
|
+
**kwargs: Additional keyword arguments to customize the API query.
|
60
|
+
|
61
|
+
Returns:
|
62
|
+
pandas.DataFrame: A Pandas DataFrame containing the retrieved data.
|
63
|
+
|
64
|
+
Raises:
|
65
|
+
ValueError: If there is an error during the API call or while converting the data to a DataFrame.
|
66
|
+
"""
|
67
|
+
client = cls.get_client(api_key)
|
68
|
+
info_func = cls.get_finnhub_method(client, info_kind)
|
69
|
+
try:
|
70
|
+
results = info_func(**kwargs)
|
71
|
+
try:
|
72
|
+
df = convert.to_df(results)
|
73
|
+
return df
|
74
|
+
except Exception as e:
|
75
|
+
raise ValueError(
|
76
|
+
f"Error occured during converting {info_kind} to DataFrame: {e}"
|
77
|
+
)
|
78
|
+
except Exception as e:
|
79
|
+
raise ValueError(
|
80
|
+
f"Error occured during getting {info_kind} from FinnHub: {e}"
|
81
|
+
)
|
82
|
+
|
83
|
+
@staticmethod
|
84
|
+
def get_finnhub_method(client, info_kind):
|
85
|
+
"""
|
86
|
+
Returns the appropriate FinnHub API method based on the specified 'info_kind'.
|
87
|
+
|
88
|
+
Args:
|
89
|
+
client (finnhub.Client): The FinnHub API client instance.
|
90
|
+
info_kind (str): The type of information to retrieve from FinnHub.
|
91
|
+
|
92
|
+
Returns:
|
93
|
+
Callable or None: The corresponding FinnHub API method, or None if 'info_kind' is not recognized.
|
94
|
+
"""
|
95
|
+
info_func = {
|
96
|
+
"aggregate_indicator": client.aggregate_indicator,
|
97
|
+
"company_basic_financials": client.company_basic_financials,
|
98
|
+
"company_earnings": client.company_earnings,
|
99
|
+
"company_eps_estimates": client.company_eps_estimates,
|
100
|
+
"company_executive": client.company_executive,
|
101
|
+
"company_news": client.company_news,
|
102
|
+
"company_peers": client.company_peers,
|
103
|
+
"company_profile": client.company_profile,
|
104
|
+
"company_profile2": client.company_profile2,
|
105
|
+
"company_revenue_estimates": client.company_revenue_estimates,
|
106
|
+
"country": client.country,
|
107
|
+
"crypto_exchanges": client.crypto_exchanges,
|
108
|
+
"crypto_symbols": client.crypto_symbols,
|
109
|
+
"economic_data": client.economic_data,
|
110
|
+
"filings": client.filings,
|
111
|
+
"financials": client.financials,
|
112
|
+
"financials_reported": client.financials_reported,
|
113
|
+
"forex_exchanges": client.forex_exchanges,
|
114
|
+
"forex_rates": client.forex_rates,
|
115
|
+
"forex_symbols": client.forex_symbols,
|
116
|
+
"fund_ownership": client.fund_ownership,
|
117
|
+
"general_news": client.general_news,
|
118
|
+
"ownership": client.ownership,
|
119
|
+
"ipo_calendar": client.ipo_calendar,
|
120
|
+
"press_releases": client.press_releases,
|
121
|
+
"news_sentiment": client.news_sentiment,
|
122
|
+
"pattern_recognition": client.pattern_recognition,
|
123
|
+
"price_target": client.price_target,
|
124
|
+
"quote": client.quote,
|
125
|
+
"recommendation_trends": client.recommendation_trends,
|
126
|
+
"stock_dividends": client.stock_dividends,
|
127
|
+
"stock_basic_dividends": client.stock_basic_dividends,
|
128
|
+
"stock_symbols": client.stock_symbols,
|
129
|
+
"transcripts": client.transcripts,
|
130
|
+
"transcripts_list": client.transcripts_list,
|
131
|
+
"earnings_calendar": client.earnings_calendar,
|
132
|
+
"covid19": client.covid19,
|
133
|
+
"upgrade_downgrade": client.upgrade_downgrade,
|
134
|
+
"economic_code": client.economic_code,
|
135
|
+
"calendar_economic": client.calendar_economic,
|
136
|
+
"support_resistance": client.support_resistance,
|
137
|
+
"technical_indicator": client.technical_indicator,
|
138
|
+
"stock_splits": client.stock_splits,
|
139
|
+
"forex_candles": client.forex_candles,
|
140
|
+
"crypto_candles": client.crypto_candles,
|
141
|
+
"stock_tick": client.stock_tick,
|
142
|
+
"stock_nbbo": client.stock_nbbo,
|
143
|
+
"indices_const": client.indices_const,
|
144
|
+
"indices_hist_const": client.indices_hist_const,
|
145
|
+
"etfs_profile": client.etfs_profile,
|
146
|
+
"etfs_holdings": client.etfs_holdings,
|
147
|
+
"etfs_sector_exp": client.etfs_sector_exp,
|
148
|
+
"etfs_country_exp": client.etfs_country_exp,
|
149
|
+
"international_filings": client.international_filings,
|
150
|
+
"sec_sentiment_analysis": client.sec_sentiment_analysis,
|
151
|
+
"sec_similarity_index": client.sec_similarity_index,
|
152
|
+
"last_bid_ask": client.last_bid_ask,
|
153
|
+
"fda_calendar": client.fda_calendar,
|
154
|
+
"symbol_lookup": client.symbol_lookup,
|
155
|
+
"stock_insider_transactions": client.stock_insider_transactions,
|
156
|
+
"mutual_fund_profile": client.mutual_fund_profile,
|
157
|
+
"mutual_fund_holdings": client.mutual_fund_holdings,
|
158
|
+
"mutual_fund_sector_exp": client.mutual_fund_sector_exp,
|
159
|
+
"mutual_fund_country_exp": client.mutual_fund_country_exp,
|
160
|
+
"stock_revenue_breakdown": client.stock_revenue_breakdown,
|
161
|
+
"stock_social_sentiment": client.stock_social_sentiment,
|
162
|
+
"stock_investment_theme": client.stock_investment_theme,
|
163
|
+
"stock_supply_chain": client.stock_supply_chain,
|
164
|
+
"company_esg_score": client.company_esg_score,
|
165
|
+
"company_earnings_quality_score": client.company_earnings_quality_score,
|
166
|
+
"crypto_profile": client.crypto_profile,
|
167
|
+
"company_ebitda_estimates": client.company_ebitda_estimates,
|
168
|
+
"company_ebit_estimates": client.company_ebit_estimates,
|
169
|
+
"stock_uspto_patent": client.stock_uspto_patent,
|
170
|
+
"stock_visa_application": client.stock_visa_application,
|
171
|
+
"stock_insider_sentiment": client.stock_insider_sentiment,
|
172
|
+
"bond_profile": client.bond_profile,
|
173
|
+
"bond_price": client.bond_price,
|
174
|
+
"stock_lobbying": client.stock_lobbying,
|
175
|
+
"stock_usa_spending": client.stock_usa_spending,
|
176
|
+
"sector_metric": client.sector_metric,
|
177
|
+
"mutual_fund_eet": client.mutual_fund_eet,
|
178
|
+
"mutual_fund_eet_pai": client.mutual_fund_eet_pai,
|
179
|
+
"isin_change": client.isin_change,
|
180
|
+
"symbol_change": client.symbol_change,
|
181
|
+
"institutional_profile": client.institutional_profile,
|
182
|
+
"institutional_portfolio": client.institutional_portfolio,
|
183
|
+
"institutional_ownership": client.institutional_ownership,
|
184
|
+
"bond_yield_curve": client.bond_yield_curve,
|
185
|
+
"bond_tick": client.bond_tick,
|
186
|
+
"congressional_trading": client.congressional_trading,
|
187
|
+
"price_metrics": client.price_metrics,
|
188
|
+
"market_holiday": client.market_holiday,
|
189
|
+
"market_status": client.market_status,
|
190
|
+
}
|
191
|
+
return info_func.get(info_kind, None)
|
@@ -0,0 +1,199 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
google_key_scheme = "GOOGLE_API_KEY"
|
4
|
+
google_engine_scheme = "GOOGLE_CSE_ID"
|
5
|
+
|
6
|
+
google_api_key = os.getenv(google_key_scheme)
|
7
|
+
google_engine = os.getenv(google_engine_scheme)
|
8
|
+
|
9
|
+
|
10
|
+
class GoogleSearch:
|
11
|
+
"""
|
12
|
+
A utility class for performing Google searches and retrieving search results.
|
13
|
+
|
14
|
+
Attributes:
|
15
|
+
api_key (str): The Google API key used for search (can be set via environment variable).
|
16
|
+
search_engine (str): The Google Custom Search Engine ID (can be set via environment variable).
|
17
|
+
|
18
|
+
Methods:
|
19
|
+
create_agent_engine(api_key=None, search_engine=None, verbose=False):
|
20
|
+
Create an OpenAIAgent for Google search operations.
|
21
|
+
|
22
|
+
url_get_content(url: str):
|
23
|
+
Retrieve and parse the content from a given URL.
|
24
|
+
|
25
|
+
search(title: str = None, url: str = None):
|
26
|
+
Perform a Google search for a given title or URL and retrieve relevant content.
|
27
|
+
"""
|
28
|
+
|
29
|
+
api_key = google_api_key
|
30
|
+
search_engine = google_engine
|
31
|
+
search_url = """
|
32
|
+
https://www.googleapis.com/customsearch/v1?key={key}&cx={engine}&q={query}&start={start}
|
33
|
+
"""
|
34
|
+
|
35
|
+
@classmethod
|
36
|
+
def create_agent(cls, api_key=None, search_engine=None, verbose=False):
|
37
|
+
"""
|
38
|
+
Create an OpenAIAgent for Google search operations.
|
39
|
+
|
40
|
+
Args:
|
41
|
+
api_key (str, optional): The Google API key for search. Defaults to None (uses class attribute).
|
42
|
+
search_engine (str, optional): The Google Custom Search Engine ID. Defaults to None (uses class attribute).
|
43
|
+
verbose (bool, optional): Whether to enable verbose mode for the agent. Defaults to False.
|
44
|
+
|
45
|
+
Returns:
|
46
|
+
OpenAIAgent: An instance of the OpenAIAgent for performing Google searches.
|
47
|
+
|
48
|
+
Raises:
|
49
|
+
ImportError: If there is an issue during the agent creation.
|
50
|
+
"""
|
51
|
+
try:
|
52
|
+
from lionagi.libs import SysUtil
|
53
|
+
|
54
|
+
SysUtil.check_import(package_name="llama_index", pip_name="llama-index")
|
55
|
+
|
56
|
+
SysUtil.check_import(
|
57
|
+
package_name="llama_index",
|
58
|
+
module_name="agent.openai",
|
59
|
+
import_name="OpenAIAgent",
|
60
|
+
pip_name="llama-index-agent-openai",
|
61
|
+
)
|
62
|
+
|
63
|
+
SysUtil.check_import(
|
64
|
+
package_name="llama_index",
|
65
|
+
module_name="tools.google",
|
66
|
+
import_name="GoogleSearchToolSpec",
|
67
|
+
pip_name="llama-index-tools-google",
|
68
|
+
)
|
69
|
+
|
70
|
+
from llama_index.agent import OpenAIAgent
|
71
|
+
from llama_index.tools.tool_spec.load_and_search.base import (
|
72
|
+
LoadAndSearchToolSpec,
|
73
|
+
)
|
74
|
+
from llama_index.tools.google import GoogleSearchToolSpec
|
75
|
+
from llama_index.llms.openai import OpenAI
|
76
|
+
|
77
|
+
llm = OpenAI(model="gpt-4-turbo", temperature=0.1)
|
78
|
+
|
79
|
+
api_key = api_key if api_key else cls.api_key
|
80
|
+
search_engine = search_engine if search_engine else cls.search_engine
|
81
|
+
google_spec = GoogleSearchToolSpec(key=api_key, engine=search_engine)
|
82
|
+
|
83
|
+
# Wrap the google search tool as it returns large payloads
|
84
|
+
tools = LoadAndSearchToolSpec.from_defaults(
|
85
|
+
google_spec.to_tool_list()[0],
|
86
|
+
).to_tool_list()
|
87
|
+
|
88
|
+
# Create the Agent with our tools
|
89
|
+
agent = OpenAIAgent.from_tools(tools, verbose=verbose, llm=llm)
|
90
|
+
return agent
|
91
|
+
|
92
|
+
except Exception as e:
|
93
|
+
raise ImportError(f"Error in importing OpenAIAgent from llama_index: {e}")
|
94
|
+
|
95
|
+
|
96
|
+
# responses_google = []
|
97
|
+
# async def query_google(query: str):
|
98
|
+
# """
|
99
|
+
# Search Google and retrieve a natural language answer to a given query.
|
100
|
+
|
101
|
+
# Args:
|
102
|
+
# query (str): The search query to find an answer for.
|
103
|
+
|
104
|
+
# Returns:
|
105
|
+
# str: A natural language answer obtained from Google search results.
|
106
|
+
|
107
|
+
# Raises:
|
108
|
+
# Exception: If there is an issue with making the request or parsing the response.
|
109
|
+
# """
|
110
|
+
# google_agent = GoogleSearch.create_agent()
|
111
|
+
# response = await google_agent.achat(query)
|
112
|
+
# responses_google.append(response)
|
113
|
+
# return str(response.response)
|
114
|
+
|
115
|
+
|
116
|
+
# @staticmethod
|
117
|
+
# def search(title: str = None, url: str = None):
|
118
|
+
# """
|
119
|
+
# Perform a Google search for a given title or URL and retrieve relevant content.
|
120
|
+
|
121
|
+
# Args:
|
122
|
+
# title (str, optional): The title or query for the Google search. Defaults to None.
|
123
|
+
# url (str, optional): The URL to retrieve content from. Defaults to None.
|
124
|
+
|
125
|
+
# Returns:
|
126
|
+
# str: The retrieved information from the Google search or URL, or an error message if no results are found.
|
127
|
+
|
128
|
+
# Raises:
|
129
|
+
# ValueError: If there is an issue during the search or content retrieval.
|
130
|
+
# """
|
131
|
+
# if not title and not url:
|
132
|
+
# raise 'No search input.'
|
133
|
+
# from ..utils.url_util import get_url_content
|
134
|
+
|
135
|
+
# if url:
|
136
|
+
# return get_url_content(url)
|
137
|
+
# else:
|
138
|
+
# from googlesearch import search
|
139
|
+
# search_result = search(title)
|
140
|
+
|
141
|
+
# for url in search_result:
|
142
|
+
# try:
|
143
|
+
# return get_url_content(url)
|
144
|
+
|
145
|
+
# except:
|
146
|
+
# continue
|
147
|
+
# return 'No matched or valid source'
|
148
|
+
|
149
|
+
|
150
|
+
# get fields of a google search item
|
151
|
+
# @classmethod
|
152
|
+
# def _get_search_item_field(cls, item: Dict[str, Any]) -> Dict[str, str]:
|
153
|
+
# try:
|
154
|
+
# long_description = item["pagemap"]["metatags"][0]["og:description"]
|
155
|
+
# except KeyError:
|
156
|
+
# long_description = "N/A"
|
157
|
+
# url = item.get("link")
|
158
|
+
#
|
159
|
+
# return {
|
160
|
+
# "title": item.get("title"),
|
161
|
+
# "snippet": item.get("snippet"),
|
162
|
+
# "url": item.get("link"),
|
163
|
+
# "long_description": long_description,
|
164
|
+
# "content": get_url_content(url)
|
165
|
+
# }
|
166
|
+
#
|
167
|
+
# @classmethod
|
168
|
+
# def _format_search_url(cls, url, api_key, search_engine, query, start):
|
169
|
+
# url = url or cls.search_url
|
170
|
+
# url = url.format(
|
171
|
+
# key=api_key or cls.api_key,
|
172
|
+
# engine=search_engine or cls.search_engine,
|
173
|
+
# query=query,
|
174
|
+
# start=start
|
175
|
+
# )
|
176
|
+
# return url
|
177
|
+
#
|
178
|
+
# @classmethod
|
179
|
+
# def search(
|
180
|
+
# cls,
|
181
|
+
# query: str =None,
|
182
|
+
# search_url = None,
|
183
|
+
# api_key = None,
|
184
|
+
# search_engine=None,
|
185
|
+
# start: int = 1,
|
186
|
+
# timeout: tuple = (0.5, 0.5),
|
187
|
+
# content=True,
|
188
|
+
# num=5
|
189
|
+
# ):
|
190
|
+
# url = cls._format_search_url(
|
191
|
+
# url = search_url, query=query, api_key=api_key,
|
192
|
+
# search_engine=search_engine, start=start
|
193
|
+
# )
|
194
|
+
# response = get_url_response(url, timeout=timeout)
|
195
|
+
# response_dict = response.json()
|
196
|
+
# items = response_dict.get('items')[:num]
|
197
|
+
# if content:
|
198
|
+
# items = lcall(items, cls._get_search_item_field, dropna=True)
|
199
|
+
# return items
|
@@ -0,0 +1,96 @@
|
|
1
|
+
class WikipediaSearch:
|
2
|
+
"""
|
3
|
+
A utility class for searching and retrieving information from Wikipedia.
|
4
|
+
Methods:
|
5
|
+
query(query: str, lang: str = 'en'):
|
6
|
+
Search for a query on Wikipedia and retrieve relevant information.
|
7
|
+
"""
|
8
|
+
|
9
|
+
# @staticmethod
|
10
|
+
def create_agent(verbose=False):
|
11
|
+
from lionagi.libs import SysUtil
|
12
|
+
|
13
|
+
SysUtil.check_import(package_name="llama_index", pip_name="llama-index")
|
14
|
+
|
15
|
+
SysUtil.check_import(
|
16
|
+
package_name="llama_index",
|
17
|
+
module_name="agent.openai",
|
18
|
+
import_name="OpenAIAgent",
|
19
|
+
pip_name="llama-index-agent-openai",
|
20
|
+
)
|
21
|
+
|
22
|
+
SysUtil.check_import(
|
23
|
+
package_name="llama_index",
|
24
|
+
module_name="tools.wikipedia",
|
25
|
+
import_name="WikipediaToolSpec",
|
26
|
+
pip_name="llama-index-tools-wikipedia",
|
27
|
+
)
|
28
|
+
|
29
|
+
from llama_index.tools.wikipedia import WikipediaToolSpec
|
30
|
+
from llama_index.agent.openai import OpenAIAgent
|
31
|
+
from llama_index.llms.openai import OpenAI
|
32
|
+
|
33
|
+
llm = OpenAI(model="gpt-4-turbo", temperature=0.1)
|
34
|
+
|
35
|
+
tool_spec = WikipediaToolSpec()
|
36
|
+
|
37
|
+
agent = OpenAIAgent.from_tools(
|
38
|
+
tool_spec.to_tool_list(), verbose=verbose, llm=llm
|
39
|
+
)
|
40
|
+
return agent
|
41
|
+
|
42
|
+
|
43
|
+
# responses_wiki = []
|
44
|
+
# async def query_wiki(query: str):
|
45
|
+
# """
|
46
|
+
# Search Wikipedia and retrieve a natural language answer to a given query.
|
47
|
+
|
48
|
+
# Args:
|
49
|
+
# query (str): The search query to find an answer for.
|
50
|
+
|
51
|
+
# Returns:
|
52
|
+
# str: A natural language answer obtained from Google search results.
|
53
|
+
|
54
|
+
# Raises:
|
55
|
+
# Exception: If there is an issue with making the request or parsing the response.
|
56
|
+
# """
|
57
|
+
# wiki_agent = WikipediaSearch.create_agent()
|
58
|
+
# response = await wiki_agent.achat(query)
|
59
|
+
# responses_wiki.append(response)
|
60
|
+
# return str(response.response)
|
61
|
+
|
62
|
+
|
63
|
+
# @staticmethod
|
64
|
+
# def query(query: str, lang: str = 'en'):
|
65
|
+
# """
|
66
|
+
# Search for a query on Wikipedia and retrieve relevant information.
|
67
|
+
|
68
|
+
# Args:
|
69
|
+
# query (str): The query to search for on Wikipedia.
|
70
|
+
# lang (str, optional): The language for the Wikipedia search. Default is 'en' (English).
|
71
|
+
|
72
|
+
# Returns:
|
73
|
+
# str: The retrieved information from Wikipedia or an error message if no results are found.
|
74
|
+
|
75
|
+
# Raises:
|
76
|
+
# WikipediaException: If there is an issue during the Wikipedia search or content retrieval.
|
77
|
+
# """
|
78
|
+
# import lionagi.lions.searcher.wikipedia as wikipedia
|
79
|
+
# from llama_index import Document, VectorStoreIndex
|
80
|
+
|
81
|
+
# wikipedia.set_lang(lang)
|
82
|
+
|
83
|
+
# res = wikipedia.search(query, results=1)
|
84
|
+
# if len(res) == 0:
|
85
|
+
# return "No search results."
|
86
|
+
# try:
|
87
|
+
# wikipedia_page = wikipedia.page(res[0], auto_suggest=False)
|
88
|
+
# except wikipedia.PageError:
|
89
|
+
# return f"Unable to load page {res[0]}."
|
90
|
+
# content = wikipedia_page.content
|
91
|
+
|
92
|
+
# documents = [Document(text=content)]
|
93
|
+
# index = VectorStoreIndex.from_documents(documents)
|
94
|
+
# query_engine = index.as_query_engine()
|
95
|
+
# response = query_engine.query(query)
|
96
|
+
# return response.response
|
@@ -0,0 +1,21 @@
|
|
1
|
+
def get_stock_prices(symbol, **kwargs):
|
2
|
+
"""
|
3
|
+
Fetch historical stock prices for a given symbol using Yahoo Finance.
|
4
|
+
Args:
|
5
|
+
symbol (str): The stock symbol to retrieve data for, e.g., 'AAPL' for Apple Inc.
|
6
|
+
**kwargs: Additional keyword arguments to customize the query, such as 'start', 'end', 'period', etc.
|
7
|
+
Returns:
|
8
|
+
pandas.DataFrame: A DataFrame containing historical stock price data for the specified symbol.
|
9
|
+
Note:
|
10
|
+
- The 'symbol' parameter should be a valid stock symbol recognized by Yahoo Finance.
|
11
|
+
- You can customize the query further by providing keyword arguments, such as 'start' and 'end' to specify a date range.
|
12
|
+
- For a full list of available keyword arguments, refer to the Yahoo Finance API documentation.
|
13
|
+
"""
|
14
|
+
from lionagi.libs import SysUtil
|
15
|
+
|
16
|
+
SysUtil.check_import("yfinance")
|
17
|
+
from yfinance import Ticker
|
18
|
+
|
19
|
+
stock = Ticker(symbol)
|
20
|
+
hist = stock.history(**kwargs)
|
21
|
+
return hist
|
File without changes
|
File without changes
|