datamule 1.0.2__py3-none-any.whl → 1.0.6__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.
- datamule/__init__.py +2 -13
- datamule/document.py +0 -1
- datamule/helper.py +85 -105
- datamule/portfolio.py +105 -29
- datamule/submission.py +0 -38
- {datamule-1.0.2.dist-info → datamule-1.0.6.dist-info}/METADATA +2 -8
- datamule-1.0.6.dist-info/RECORD +10 -0
- datamule/book/__init__.py +0 -0
- datamule/book/book.py +0 -34
- datamule/book/eftsquery.py +0 -127
- datamule/book/xbrl_retriever.py +0 -88
- datamule/data/company_former_names.csv +0 -8148
- datamule/data/company_metadata.csv +0 -10049
- datamule/data/company_tickers.csv +0 -9999
- datamule/data/sec-glossary.csv +0 -728
- datamule/data/xbrl_descriptions.csv +0 -10024
- datamule/downloader/downloader.py +0 -374
- datamule/downloader/premiumdownloader.py +0 -335
- datamule/mapping_dicts/txt_mapping_dicts.py +0 -232
- datamule/mapping_dicts/xml_mapping_dicts.py +0 -19
- datamule/monitor.py +0 -238
- datamule/mulebot/__init__.py +0 -1
- datamule/mulebot/helper.py +0 -35
- datamule/mulebot/mulebot.py +0 -130
- datamule/mulebot/mulebot_server/__init__.py +0 -1
- datamule/mulebot/mulebot_server/server.py +0 -87
- datamule/mulebot/mulebot_server/static/css/minimalist.css +0 -174
- datamule/mulebot/mulebot_server/static/scripts/artifacts.js +0 -68
- datamule/mulebot/mulebot_server/static/scripts/chat.js +0 -92
- datamule/mulebot/mulebot_server/static/scripts/filingArtifacts.js +0 -56
- datamule/mulebot/mulebot_server/static/scripts/listArtifacts.js +0 -15
- datamule/mulebot/mulebot_server/static/scripts/main.js +0 -57
- datamule/mulebot/mulebot_server/static/scripts/prefilledPrompt.js +0 -27
- datamule/mulebot/mulebot_server/static/scripts/suggestions.js +0 -47
- datamule/mulebot/mulebot_server/static/scripts/tableArtifacts.js +0 -129
- datamule/mulebot/mulebot_server/static/scripts/utils.js +0 -28
- datamule/mulebot/mulebot_server/templates/chat-minimalist.html +0 -91
- datamule/mulebot/search.py +0 -52
- datamule/mulebot/tools.py +0 -82
- datamule/packageupdater.py +0 -207
- datamule-1.0.2.dist-info/RECORD +0 -43
- {datamule-1.0.2.dist-info → datamule-1.0.6.dist-info}/WHEEL +0 -0
- {datamule-1.0.2.dist-info → datamule-1.0.6.dist-info}/top_level.txt +0 -0
datamule/monitor.py
DELETED
@@ -1,238 +0,0 @@
|
|
1
|
-
import asyncio
|
2
|
-
import aiohttp
|
3
|
-
from datetime import timedelta, datetime
|
4
|
-
import pytz
|
5
|
-
from collections import deque
|
6
|
-
import time
|
7
|
-
from .helper import headers, identifier_to_cik
|
8
|
-
|
9
|
-
def _get_current_eastern_date():
|
10
|
-
"""Get current date in US Eastern timezone (automatically handles DST) """
|
11
|
-
eastern = pytz.timezone('America/New_York')
|
12
|
-
return datetime.now(eastern)
|
13
|
-
|
14
|
-
class PreciseRateLimiter:
|
15
|
-
def __init__(self, rate, interval=1.0):
|
16
|
-
self.rate = rate # requests per interval
|
17
|
-
self.interval = interval # in seconds
|
18
|
-
self.token_time = self.interval / self.rate # time per token
|
19
|
-
self.last_time = time.time()
|
20
|
-
self.lock = asyncio.Lock()
|
21
|
-
|
22
|
-
async def acquire(self):
|
23
|
-
async with self.lock:
|
24
|
-
now = time.time()
|
25
|
-
wait_time = self.last_time + self.token_time - now
|
26
|
-
if wait_time > 0:
|
27
|
-
await asyncio.sleep(wait_time)
|
28
|
-
self.last_time = time.time()
|
29
|
-
return True
|
30
|
-
|
31
|
-
async def __aenter__(self):
|
32
|
-
await self.acquire()
|
33
|
-
return self
|
34
|
-
|
35
|
-
async def __aexit__(self, exc_type, exc, tb):
|
36
|
-
pass
|
37
|
-
|
38
|
-
class RateMonitor:
|
39
|
-
def __init__(self, window_size=1.0):
|
40
|
-
self.window_size = window_size
|
41
|
-
self.requests = deque()
|
42
|
-
self._lock = asyncio.Lock()
|
43
|
-
|
44
|
-
async def add_request(self, size_bytes):
|
45
|
-
async with self._lock:
|
46
|
-
now = time.time()
|
47
|
-
self.requests.append((now, size_bytes))
|
48
|
-
while self.requests and self.requests[0][0] < now - self.window_size:
|
49
|
-
self.requests.popleft()
|
50
|
-
|
51
|
-
def get_current_rates(self):
|
52
|
-
now = time.time()
|
53
|
-
while self.requests and self.requests[0][0] < now - self.window_size:
|
54
|
-
self.requests.popleft()
|
55
|
-
|
56
|
-
if not self.requests:
|
57
|
-
return 0, 0
|
58
|
-
|
59
|
-
request_count = len(self.requests)
|
60
|
-
byte_count = sum(size for _, size in self.requests)
|
61
|
-
|
62
|
-
requests_per_second = request_count / self.window_size
|
63
|
-
mb_per_second = (byte_count / 1024 / 1024) / self.window_size
|
64
|
-
|
65
|
-
return round(requests_per_second, 1), round(mb_per_second, 2)
|
66
|
-
|
67
|
-
class Monitor:
|
68
|
-
def __init__(self):
|
69
|
-
self.last_total = 0
|
70
|
-
self.last_date = _get_current_eastern_date()
|
71
|
-
self.submissions = []
|
72
|
-
self.max_hits = 10000
|
73
|
-
self.limiter = PreciseRateLimiter(5) # 5 requests per second
|
74
|
-
self.rate_monitor = RateMonitor()
|
75
|
-
self.headers = headers
|
76
|
-
|
77
|
-
async def _fetch_json(self, session, url):
|
78
|
-
"""Fetch JSON with rate limiting and monitoring."""
|
79
|
-
async with self.limiter:
|
80
|
-
try:
|
81
|
-
async with session.get(url) as response:
|
82
|
-
response.raise_for_status()
|
83
|
-
content = await response.read()
|
84
|
-
await self.rate_monitor.add_request(len(content))
|
85
|
-
return await response.json()
|
86
|
-
except Exception as e:
|
87
|
-
print(f"Error fetching {url}: {str(e)}")
|
88
|
-
return None
|
89
|
-
|
90
|
-
async def _poll(self, base_url, session, poll_interval, quiet):
|
91
|
-
"""Poll API until new submissions are found."""
|
92
|
-
while True:
|
93
|
-
current_date = _get_current_eastern_date()
|
94
|
-
date_str = current_date.strftime('%Y-%m-%d')
|
95
|
-
timestamp = int(time.time()) # Add this line
|
96
|
-
|
97
|
-
if self.last_date != current_date.strftime('%Y-%m-%d'):
|
98
|
-
print(f"New date: {date_str}")
|
99
|
-
self.last_total = 0
|
100
|
-
self.submissions = []
|
101
|
-
self.last_date = date_str
|
102
|
-
|
103
|
-
poll_url = f"{base_url}&startdt={date_str}&enddt={date_str}&v={timestamp}" # Modified this line
|
104
|
-
if not quiet:
|
105
|
-
print(f"Polling {poll_url}")
|
106
|
-
|
107
|
-
try:
|
108
|
-
data = await self._fetch_json(session, poll_url)
|
109
|
-
if data:
|
110
|
-
current_total = data['hits']['total']['value']
|
111
|
-
if current_total > self.last_total:
|
112
|
-
print(f"Found {current_total - self.last_total} new submissions")
|
113
|
-
self.last_total = current_total
|
114
|
-
return current_total, data, poll_url
|
115
|
-
self.last_total = current_total
|
116
|
-
except Exception as e:
|
117
|
-
print(f"Error in poll: {str(e)}")
|
118
|
-
|
119
|
-
await asyncio.sleep(poll_interval / 1000)
|
120
|
-
|
121
|
-
async def _retrieve_batch(self, session, poll_url, from_positions, quiet):
|
122
|
-
"""Retrieve a batch of submissions concurrently."""
|
123
|
-
# The poll_url already contains the timestamp from _poll
|
124
|
-
tasks = [
|
125
|
-
self._fetch_json(
|
126
|
-
session,
|
127
|
-
f"{poll_url}&from={pos}"
|
128
|
-
)
|
129
|
-
for pos in from_positions
|
130
|
-
]
|
131
|
-
|
132
|
-
results = await asyncio.gather(*tasks, return_exceptions=True)
|
133
|
-
submissions = []
|
134
|
-
|
135
|
-
for result in results:
|
136
|
-
if isinstance(result, Exception):
|
137
|
-
print(f"Error in batch: {str(result)}")
|
138
|
-
continue
|
139
|
-
if result and 'hits' in result:
|
140
|
-
submissions.extend(result['hits']['hits'])
|
141
|
-
|
142
|
-
return submissions
|
143
|
-
|
144
|
-
async def _retrieve(self, poll_url, initial_data, session, quiet):
|
145
|
-
"""Retrieve all submissions using parallel batch processing."""
|
146
|
-
batch_size = 10 # Number of concurrent requests
|
147
|
-
page_size = 100 # Results per request
|
148
|
-
max_position = min(self.max_hits, self.last_total)
|
149
|
-
submissions = []
|
150
|
-
|
151
|
-
# Process in batches of concurrent requests
|
152
|
-
for batch_start in range(0, max_position, batch_size * page_size):
|
153
|
-
from_positions = [
|
154
|
-
pos for pos in range(
|
155
|
-
batch_start,
|
156
|
-
min(batch_start + batch_size * page_size, max_position),
|
157
|
-
page_size
|
158
|
-
)
|
159
|
-
]
|
160
|
-
|
161
|
-
if not quiet:
|
162
|
-
print(f"Retrieving batch from positions: {from_positions}")
|
163
|
-
|
164
|
-
batch_submissions = await self._retrieve_batch(
|
165
|
-
session, poll_url, from_positions, quiet
|
166
|
-
)
|
167
|
-
|
168
|
-
if not batch_submissions:
|
169
|
-
break
|
170
|
-
|
171
|
-
submissions.extend(batch_submissions)
|
172
|
-
|
173
|
-
# If we got fewer results than expected, we're done
|
174
|
-
if len(batch_submissions) < len(from_positions) * page_size:
|
175
|
-
break
|
176
|
-
|
177
|
-
return submissions
|
178
|
-
|
179
|
-
async def _monitor(self, callback, form=None, cik=None, ticker=None, poll_interval=1000, quiet=True):
|
180
|
-
"""Main monitoring loop with parallel processing."""
|
181
|
-
if poll_interval < 100:
|
182
|
-
raise ValueError("SEC rate limit is 10 requests per second, set poll_interval to 100ms or higher")
|
183
|
-
|
184
|
-
# Handle form parameter
|
185
|
-
if form is None:
|
186
|
-
form = ['-0']
|
187
|
-
elif isinstance(form, str):
|
188
|
-
form = [form]
|
189
|
-
|
190
|
-
# Handle CIK/ticker parameter
|
191
|
-
cik_param = None
|
192
|
-
if ticker is not None:
|
193
|
-
cik_param = identifier_to_cik(ticker)
|
194
|
-
elif cik is not None:
|
195
|
-
cik_param = cik if isinstance(cik, list) else [cik]
|
196
|
-
|
197
|
-
# Construct base URL
|
198
|
-
base_url = 'https://efts.sec.gov/LATEST/search-index?forms=' + ','.join(form)
|
199
|
-
|
200
|
-
# Add CIK parameter if specified
|
201
|
-
if cik_param:
|
202
|
-
cik_list = ','.join(str(c).zfill(10) for c in cik_param)
|
203
|
-
base_url += f"&ciks={cik_list}"
|
204
|
-
|
205
|
-
async with aiohttp.ClientSession(headers=self.headers) as session:
|
206
|
-
while True:
|
207
|
-
try:
|
208
|
-
# Poll until we find new submissions
|
209
|
-
_, data, poll_url = await self._poll(base_url, session, poll_interval, quiet)
|
210
|
-
|
211
|
-
# Retrieve all submissions in parallel
|
212
|
-
submissions = await self._retrieve(poll_url, data, session, quiet)
|
213
|
-
|
214
|
-
# Find new submissions
|
215
|
-
existing_ids = {sub['_id'] for sub in self.submissions}
|
216
|
-
new_submissions = [
|
217
|
-
sub for sub in submissions
|
218
|
-
if sub['_id'] not in existing_ids
|
219
|
-
]
|
220
|
-
|
221
|
-
if new_submissions:
|
222
|
-
self.submissions.extend(new_submissions)
|
223
|
-
if callback:
|
224
|
-
await callback(new_submissions)
|
225
|
-
|
226
|
-
reqs_per_sec, mb_per_sec = self.rate_monitor.get_current_rates()
|
227
|
-
if not quiet:
|
228
|
-
print(f"Current rates: {reqs_per_sec} req/s, {mb_per_sec} MB/s")
|
229
|
-
|
230
|
-
except Exception as e:
|
231
|
-
print(f"Error in monitor: {str(e)}")
|
232
|
-
await asyncio.sleep(poll_interval / 1000)
|
233
|
-
|
234
|
-
await asyncio.sleep(poll_interval / 1000)
|
235
|
-
|
236
|
-
def monitor_submissions(self, callback=None, form=None, cik=None, ticker=None, poll_interval=1000, quiet=True):
|
237
|
-
"""Start the monitoring process."""
|
238
|
-
asyncio.run(self._monitor(callback, form, cik, ticker, poll_interval, quiet))
|
datamule/mulebot/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
from .mulebot import MuleBot
|
datamule/mulebot/helper.py
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
import requests
|
2
|
-
from datamule.global_vars import headers
|
3
|
-
from datamule.helper import identifier_to_cik
|
4
|
-
from datamule import Parser
|
5
|
-
|
6
|
-
parser = Parser()
|
7
|
-
|
8
|
-
def get_company_concept(ticker):
|
9
|
-
|
10
|
-
cik = identifier_to_cik(ticker)[0]
|
11
|
-
url = f'https://data.sec.gov/api/xbrl/companyfacts/CIK{str(cik).zfill(10)}.json'
|
12
|
-
response = requests.get(url,headers=headers)
|
13
|
-
data = response.json()
|
14
|
-
|
15
|
-
table_dict_list = parser.parse_company_concepts(data)
|
16
|
-
|
17
|
-
# drop tables where label is None
|
18
|
-
table_dict_list = [table_dict for table_dict in table_dict_list if table_dict['label'] is not None]
|
19
|
-
|
20
|
-
return table_dict_list
|
21
|
-
|
22
|
-
def select_dict_by_title(data, title):
|
23
|
-
if isinstance(data, dict):
|
24
|
-
if data.get('title') == title:
|
25
|
-
return data
|
26
|
-
for value in data.values():
|
27
|
-
result = select_dict_by_title(value, title)
|
28
|
-
if result:
|
29
|
-
return result
|
30
|
-
elif isinstance(data, list):
|
31
|
-
for item in data:
|
32
|
-
result = select_dict_by_title(item, title)
|
33
|
-
if result:
|
34
|
-
return result
|
35
|
-
return None
|
datamule/mulebot/mulebot.py
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
import openai
|
2
|
-
import json
|
3
|
-
|
4
|
-
from datamule.helper import identifier_to_cik
|
5
|
-
from datamule import Downloader, Parser
|
6
|
-
from .search import search_filing
|
7
|
-
from .tools import tools, return_title_tool
|
8
|
-
from .helper import get_company_concept, select_dict_by_title
|
9
|
-
|
10
|
-
downloader = Downloader()
|
11
|
-
parser = Parser()
|
12
|
-
|
13
|
-
|
14
|
-
class MuleBot:
|
15
|
-
def __init__(self, api_key):
|
16
|
-
self.client = openai.OpenAI(api_key=api_key)
|
17
|
-
self.messages = [
|
18
|
-
{"role": "system", "content": "You are a helpful, but concise, assistant to assist with questions related to the Securities and Exchanges Commission. You are allowed to guess tickers."}
|
19
|
-
]
|
20
|
-
self.total_tokens = 0
|
21
|
-
|
22
|
-
def process_message(self, user_input):
|
23
|
-
|
24
|
-
new_message_chain = self.messages
|
25
|
-
new_message_chain.append({"role": "user", "content": user_input})
|
26
|
-
|
27
|
-
try:
|
28
|
-
response = self.client.chat.completions.create(
|
29
|
-
model="gpt-4o-mini",
|
30
|
-
messages=new_message_chain,
|
31
|
-
tools=tools,
|
32
|
-
tool_choice="auto"
|
33
|
-
)
|
34
|
-
|
35
|
-
self.total_tokens += response.usage.total_tokens
|
36
|
-
assistant_message = response.choices[0].message
|
37
|
-
|
38
|
-
if assistant_message.content is None:
|
39
|
-
assistant_message.content = "I'm processing your request."
|
40
|
-
|
41
|
-
new_message_chain.append({"role": "assistant", "content": assistant_message.content})
|
42
|
-
|
43
|
-
tool_calls = assistant_message.tool_calls
|
44
|
-
if tool_calls is None:
|
45
|
-
return {'key':'text','value':assistant_message.content}
|
46
|
-
else:
|
47
|
-
for tool_call in tool_calls:
|
48
|
-
print(f"Tool call: {tool_call.function.name}")
|
49
|
-
if tool_call.function.name == "identifier_to_cik":
|
50
|
-
function_args = json.loads(tool_call.function.arguments)
|
51
|
-
print(f"Function args: {function_args}")
|
52
|
-
|
53
|
-
cik = identifier_to_cik(function_args["ticker"])
|
54
|
-
return {'key':'text','value':cik}
|
55
|
-
elif tool_call.function.name == "get_company_concept":
|
56
|
-
function_args = json.loads(tool_call.function.arguments)
|
57
|
-
print(f"Function args: {function_args}")
|
58
|
-
table_dict_list = get_company_concept(function_args["ticker"])
|
59
|
-
return {'key':'table','value':table_dict_list}
|
60
|
-
elif tool_call.function.name == "get_filing_urls":
|
61
|
-
function_args = json.loads(tool_call.function.arguments)
|
62
|
-
print(f"Function args: {function_args}")
|
63
|
-
result = downloader.download(**function_args,return_urls=True)
|
64
|
-
return {'key':'list','value':result}
|
65
|
-
elif tool_call.function.name == "find_filing_section_by_title":
|
66
|
-
function_args = json.loads(tool_call.function.arguments)
|
67
|
-
print(f"Function args: {function_args}")
|
68
|
-
# Parse the filing
|
69
|
-
data = parser.parse_filing(function_args["url"])
|
70
|
-
|
71
|
-
# find possible matches
|
72
|
-
section_dicts = search_filing(query = function_args["title"], nested_dict =data, score_cutoff=0.3)
|
73
|
-
|
74
|
-
# feed titles back to assistant
|
75
|
-
titles = [section['title'] for section in section_dicts]
|
76
|
-
new_message_chain.append({"role": "assistant", "content": f"Which of these titles is closest: {','.join(titles)}"})
|
77
|
-
|
78
|
-
title_response = self.client.chat.completions.create(
|
79
|
-
model="gpt-4o-mini",
|
80
|
-
messages=new_message_chain,
|
81
|
-
tools=[return_title_tool],
|
82
|
-
tool_choice="required"
|
83
|
-
)
|
84
|
-
|
85
|
-
title_tool_call = title_response.choices[0].message.tool_calls[0]
|
86
|
-
title = json.loads(title_tool_call.function.arguments)['title']
|
87
|
-
print(f"Selected title: {title}")
|
88
|
-
#print(f"Possible titles: {titles}")
|
89
|
-
|
90
|
-
# select the section
|
91
|
-
#section_dict = select_dict_by_title(data, title)
|
92
|
-
|
93
|
-
# probably want to return full dict, and section label
|
94
|
-
return {'key':'filing','value':{'data':data,'title':title}}
|
95
|
-
|
96
|
-
return {'key':'text','value':'No tool call was made.'}
|
97
|
-
|
98
|
-
except Exception as e:
|
99
|
-
return f"An error occurred: {str(e)}"
|
100
|
-
|
101
|
-
def get_total_tokens(self):
|
102
|
-
return self.total_tokens
|
103
|
-
|
104
|
-
def run(self):
|
105
|
-
"""Basic chatbot loop"""
|
106
|
-
print("MuleBot: Hello! I'm here to assist you with questions related to the Securities and Exchange Commission. Type 'quit', 'exit', or 'bye' to end the conversation.")
|
107
|
-
while True:
|
108
|
-
user_input = input("You: ")
|
109
|
-
if user_input.lower() in ['quit', 'exit', 'bye']:
|
110
|
-
print("MuleBot: Goodbye!")
|
111
|
-
break
|
112
|
-
|
113
|
-
response = self.process_message(user_input)
|
114
|
-
response_type = response['key']
|
115
|
-
|
116
|
-
if response_type == 'text':
|
117
|
-
value = response['value']
|
118
|
-
print(value)
|
119
|
-
elif response_type == 'table':
|
120
|
-
value = response['value']
|
121
|
-
print(value)
|
122
|
-
elif response_type == 'list':
|
123
|
-
value = response['value']
|
124
|
-
print(value)
|
125
|
-
elif response_type == 'filing':
|
126
|
-
value = response['value']
|
127
|
-
print(value)
|
128
|
-
else:
|
129
|
-
value = response['value']
|
130
|
-
print(value)
|
@@ -1 +0,0 @@
|
|
1
|
-
from .server import MuleBotServer
|
@@ -1,87 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
from flask import Flask, request, jsonify, render_template
|
3
|
-
from datamule.mulebot import MuleBot
|
4
|
-
from datamule.filing_viewer import create_interactive_filing, create_valid_id
|
5
|
-
|
6
|
-
class MuleBotServer:
|
7
|
-
def __init__(self, template='chat-minimalist.html'):
|
8
|
-
template_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates'))
|
9
|
-
static_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'static'))
|
10
|
-
self.app = Flask(__name__, template_folder=template_dir, static_folder=static_dir)
|
11
|
-
self.mulebot = None
|
12
|
-
self.template = template
|
13
|
-
self.setup_routes()
|
14
|
-
|
15
|
-
def setup_routes(self):
|
16
|
-
@self.app.route('/')
|
17
|
-
def home():
|
18
|
-
return render_template(self.template)
|
19
|
-
|
20
|
-
@self.app.route('/chat-with-prompt')
|
21
|
-
def chat_with_prompt():
|
22
|
-
prefilled_prompt = request.args.get('prompt', '')
|
23
|
-
return render_template(self.template, prefilled_prompt=prefilled_prompt)
|
24
|
-
|
25
|
-
@self.app.route('/chat', methods=['POST'])
|
26
|
-
def chat():
|
27
|
-
user_input = request.json['message']
|
28
|
-
|
29
|
-
# Process the message using MuleBot's process_message method
|
30
|
-
response = self.mulebot.process_message(user_input)
|
31
|
-
response_type = response['key']
|
32
|
-
|
33
|
-
# Prepare the response based on the type
|
34
|
-
if response_type == 'text':
|
35
|
-
# If response type is text, add it to the chat
|
36
|
-
chat_response = {
|
37
|
-
'type': 'text',
|
38
|
-
'content': response['value']
|
39
|
-
}
|
40
|
-
elif response_type == 'table':
|
41
|
-
# If response type is table, prepare it for the artifact window
|
42
|
-
chat_response = {
|
43
|
-
'type': 'artifact',
|
44
|
-
'content': response['value'],
|
45
|
-
'artifact_type': 'artifact-table'
|
46
|
-
}
|
47
|
-
elif response_type == 'list':
|
48
|
-
chat_response = {
|
49
|
-
'type': 'artifact',
|
50
|
-
'content': response['value'],
|
51
|
-
'artifact_type': 'artifact-list'
|
52
|
-
}
|
53
|
-
elif response_type == 'filing':
|
54
|
-
data = response['value']['data']
|
55
|
-
title = response['value']['title']
|
56
|
-
section_id = create_valid_id(title)
|
57
|
-
|
58
|
-
# create a filing viewer display
|
59
|
-
html = create_interactive_filing(data)
|
60
|
-
|
61
|
-
# we'll need to display the filing viewer in the artifact window, with a json export option
|
62
|
-
chat_response = {
|
63
|
-
'type': 'artifact',
|
64
|
-
'content': html,
|
65
|
-
'data': data,
|
66
|
-
'section_id': section_id,
|
67
|
-
'artifact_type': 'artifact-filing'
|
68
|
-
}
|
69
|
-
else:
|
70
|
-
# Handle other types of responses if needed
|
71
|
-
chat_response = {
|
72
|
-
'type': 'unknown',
|
73
|
-
'content': 'Unsupported response type'
|
74
|
-
}
|
75
|
-
|
76
|
-
return jsonify({
|
77
|
-
'response': chat_response,
|
78
|
-
'total_tokens': self.mulebot.get_total_tokens()
|
79
|
-
})
|
80
|
-
|
81
|
-
def set_api_key(self, api_key):
|
82
|
-
self.mulebot = MuleBot(api_key)
|
83
|
-
|
84
|
-
def run(self, debug=False, host='0.0.0.0', port=5000):
|
85
|
-
if not self.mulebot:
|
86
|
-
raise ValueError("API key not set. Please call set_api_key() before running the server.")
|
87
|
-
self.app.run(debug=debug, host=host, port=port)
|
@@ -1,174 +0,0 @@
|
|
1
|
-
/* Global Styles */
|
2
|
-
body {
|
3
|
-
background-color: #f8f9fa;
|
4
|
-
color: #343a40;
|
5
|
-
}
|
6
|
-
|
7
|
-
/* Cards */
|
8
|
-
.card {
|
9
|
-
border: none;
|
10
|
-
box-shadow: 0 4px 6px rgba(0, 0, 0, .1);
|
11
|
-
}
|
12
|
-
|
13
|
-
/* Buttons */
|
14
|
-
.btn-primary {
|
15
|
-
background-color: #6c757d;
|
16
|
-
border-color: #6c757d;
|
17
|
-
}
|
18
|
-
|
19
|
-
.btn-primary:hover {
|
20
|
-
background-color: #5a6268;
|
21
|
-
border-color: #545b62;
|
22
|
-
}
|
23
|
-
|
24
|
-
.btn-primary:disabled {
|
25
|
-
background-color: #6c757d;
|
26
|
-
border-color: #6c757d;
|
27
|
-
opacity: 0.65;
|
28
|
-
}
|
29
|
-
|
30
|
-
/* Social Buttons */
|
31
|
-
.social-btn {
|
32
|
-
display: inline-flex;
|
33
|
-
align-items: center;
|
34
|
-
justify-content: center;
|
35
|
-
width: auto;
|
36
|
-
height: 36px;
|
37
|
-
border-radius: 6px;
|
38
|
-
margin: 0 5px;
|
39
|
-
padding: 0 12px;
|
40
|
-
background-color: #f8f9fa;
|
41
|
-
border: 1px solid #6c757d;
|
42
|
-
color: #6c757d;
|
43
|
-
font-size: 14px;
|
44
|
-
text-decoration: none;
|
45
|
-
transition: all 0.3s ease;
|
46
|
-
}
|
47
|
-
|
48
|
-
.social-btn:hover {
|
49
|
-
background-color: #6c757d;
|
50
|
-
color: #ffffff;
|
51
|
-
transform: translateY(-2px);
|
52
|
-
}
|
53
|
-
|
54
|
-
.social-btn:hover svg {
|
55
|
-
fill: #ffffff;
|
56
|
-
}
|
57
|
-
|
58
|
-
.social-btn svg {
|
59
|
-
width: 18px;
|
60
|
-
height: 18px;
|
61
|
-
fill: #6c757d;
|
62
|
-
margin-right: 6px;
|
63
|
-
transition: fill 0.3s ease;
|
64
|
-
}
|
65
|
-
|
66
|
-
/* Chat container */
|
67
|
-
#chat-outer-container {
|
68
|
-
position: relative;
|
69
|
-
height: 400px;
|
70
|
-
overflow: hidden;
|
71
|
-
}
|
72
|
-
|
73
|
-
#chat-container {
|
74
|
-
height: 100%;
|
75
|
-
overflow-y: auto;
|
76
|
-
padding-bottom: 40px;
|
77
|
-
/* Make room for the thinking indicator */
|
78
|
-
}
|
79
|
-
|
80
|
-
/* Artifact container */
|
81
|
-
#artifact-container {
|
82
|
-
max-height: 400px;
|
83
|
-
overflow-y: auto;
|
84
|
-
}
|
85
|
-
|
86
|
-
/* Suggestion Box */
|
87
|
-
.suggestion-box {
|
88
|
-
background-color: #f8f9fa;
|
89
|
-
border-radius: 10px;
|
90
|
-
padding: 15px;
|
91
|
-
margin-top: 20px;
|
92
|
-
}
|
93
|
-
|
94
|
-
.suggestion-item {
|
95
|
-
background-color: white;
|
96
|
-
border-radius: 8px;
|
97
|
-
padding: 8px 12px;
|
98
|
-
margin-bottom: 10px;
|
99
|
-
cursor: pointer;
|
100
|
-
transition: background-color 0.3s;
|
101
|
-
}
|
102
|
-
|
103
|
-
.suggestion-item:hover {
|
104
|
-
background-color: #f0f0f0;
|
105
|
-
}
|
106
|
-
|
107
|
-
/* Autocomplete */
|
108
|
-
.select-wrapper {
|
109
|
-
position: relative;
|
110
|
-
}
|
111
|
-
|
112
|
-
.autocomplete-items {
|
113
|
-
position: absolute;
|
114
|
-
border: 1px solid #d4d4d4;
|
115
|
-
border-top: none;
|
116
|
-
z-index: 99;
|
117
|
-
top: 100%;
|
118
|
-
left: 0;
|
119
|
-
right: 0;
|
120
|
-
max-height: 200px;
|
121
|
-
overflow-y: auto;
|
122
|
-
background-color: #fff;
|
123
|
-
}
|
124
|
-
|
125
|
-
.autocomplete-items div {
|
126
|
-
padding: 10px;
|
127
|
-
cursor: pointer;
|
128
|
-
background-color: #fff;
|
129
|
-
border-bottom: 1px solid #d4d4d4;
|
130
|
-
}
|
131
|
-
|
132
|
-
.autocomplete-items div:hover {
|
133
|
-
background-color: #e9e9e9;
|
134
|
-
}
|
135
|
-
|
136
|
-
.autocomplete-active {
|
137
|
-
background-color: DodgerBlue !important;
|
138
|
-
color: #ffffff;
|
139
|
-
}
|
140
|
-
|
141
|
-
/* Thinking Indicator */
|
142
|
-
.thinking-indicator {
|
143
|
-
position: absolute;
|
144
|
-
bottom: 0;
|
145
|
-
left: 0;
|
146
|
-
right: 0;
|
147
|
-
padding: 10px;
|
148
|
-
background-color: #f0f0f0;
|
149
|
-
border-radius: 5px 5px 0 0;
|
150
|
-
display: none;
|
151
|
-
z-index: 1000;
|
152
|
-
box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
|
153
|
-
}
|
154
|
-
|
155
|
-
.dot-animation {
|
156
|
-
display: inline-block;
|
157
|
-
width: 20px;
|
158
|
-
text-align: left;
|
159
|
-
animation: dotAnimation 1.5s infinite;
|
160
|
-
}
|
161
|
-
|
162
|
-
@keyframes dotAnimation {
|
163
|
-
0% {
|
164
|
-
content: '.';
|
165
|
-
}
|
166
|
-
|
167
|
-
33% {
|
168
|
-
content: '..';
|
169
|
-
}
|
170
|
-
|
171
|
-
66% {
|
172
|
-
content: '...';
|
173
|
-
}
|
174
|
-
}
|