Terminal-Assistant-Interface 1.0.12__tar.gz → 1.1.1__tar.gz
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.
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/PKG-INFO +2 -3
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/pyproject.toml +3 -4
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/Terminal_Assistant_Interface.egg-info/PKG-INFO +2 -3
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/Terminal_Assistant_Interface.egg-info/entry_points.txt +1 -1
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/Terminal_Assistant_Interface.egg-info/requires.txt +1 -2
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/Terminal_Assistant_Interface.egg-info/top_level.txt +0 -1
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termiai/__init__.py +148 -20
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/ftapi.py +23 -10
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/tools.py +101 -12
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/LICENSE +0 -0
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/README.md +0 -0
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/setup.cfg +0 -0
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/Terminal_Assistant_Interface.egg-info/SOURCES.txt +0 -0
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/Terminal_Assistant_Interface.egg-info/dependency_links.txt +0 -0
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termiai/__main__.py +0 -0
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termiai/clean.py +0 -0
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termiai_main.py +0 -0
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/__init__.py +0 -0
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/__main__.py +0 -0
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/icon_data.py +0 -0
- {terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/test.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Terminal-Assistant-Interface
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.1
|
|
4
4
|
Summary: Your personal AI assistant to help terminal
|
|
5
5
|
Author-email: Ericwasepic127 <ericwasepic127@outlook.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -14,8 +14,7 @@ License-File: LICENSE
|
|
|
14
14
|
Requires-Dist: requests
|
|
15
15
|
Requires-Dist: platformdirs
|
|
16
16
|
Requires-Dist: httpx
|
|
17
|
-
Requires-Dist: flet
|
|
18
|
-
Requires-Dist: flet-desktop
|
|
17
|
+
Requires-Dist: flet[all]
|
|
19
18
|
Dynamic: license-file
|
|
20
19
|
|
|
21
20
|
### TermiAI
|
|
@@ -3,7 +3,7 @@ requires = ["setuptools >= 77.0.3"]
|
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
[project]
|
|
5
5
|
name = "Terminal-Assistant-Interface"
|
|
6
|
-
version = "1.
|
|
6
|
+
version = "1.1.1"
|
|
7
7
|
authors = [
|
|
8
8
|
{ name="Ericwasepic127", email="ericwasepic127@outlook.com" },
|
|
9
9
|
]
|
|
@@ -20,12 +20,11 @@ dependencies = [
|
|
|
20
20
|
"requests",
|
|
21
21
|
"platformdirs",
|
|
22
22
|
"httpx",
|
|
23
|
-
"flet",
|
|
24
|
-
"flet-desktop",
|
|
23
|
+
"flet[all]",
|
|
25
24
|
]
|
|
26
25
|
|
|
27
26
|
[project.scripts]
|
|
28
|
-
termiai = "termiai:ftmain"
|
|
27
|
+
termiai-source = "termiai:ftmain"
|
|
29
28
|
termiai-factory-reset = "termiai.clean:main"
|
|
30
29
|
|
|
31
30
|
[tool.flet]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Terminal-Assistant-Interface
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.1
|
|
4
4
|
Summary: Your personal AI assistant to help terminal
|
|
5
5
|
Author-email: Ericwasepic127 <ericwasepic127@outlook.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -14,8 +14,7 @@ License-File: LICENSE
|
|
|
14
14
|
Requires-Dist: requests
|
|
15
15
|
Requires-Dist: platformdirs
|
|
16
16
|
Requires-Dist: httpx
|
|
17
|
-
Requires-Dist: flet
|
|
18
|
-
Requires-Dist: flet-desktop
|
|
17
|
+
Requires-Dist: flet[all]
|
|
19
18
|
Dynamic: license-file
|
|
20
19
|
|
|
21
20
|
### TermiAI
|
{terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termiai/__init__.py
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
# Made by @Ericwasepic127
|
|
3
3
|
|
|
4
|
-
import flet as ft, os, sys,
|
|
4
|
+
import flet as ft, os, sys, time, asyncio, platform as p, pathlib
|
|
5
5
|
sys.path.append("..")
|
|
6
6
|
sys.setrecursionlimit((10 ** 9) * 2)
|
|
7
7
|
from termilib import tools, ftapi
|
|
@@ -9,7 +9,10 @@ sysprompt = PROMPT = f"""You are TermiAI, a helpful assistant for users who are
|
|
|
9
9
|
You are created by @Ericwasepic127, and licensed under MIT
|
|
10
10
|
|
|
11
11
|
Your job: help users accomplish tasks by running shell commands for them.
|
|
12
|
-
Do Markdown formatting to format your response
|
|
12
|
+
Do Markdown formatting to format your response. But try to not use emojis'
|
|
13
|
+
Instead use ASCII one (like <3 :D) IF ONLY user sends you emojis' and ASCII emojis.
|
|
14
|
+
No matter what use ASCII emoji if user gave you emoji.
|
|
15
|
+
In another cases, do not use emojis' at all
|
|
13
16
|
|
|
14
17
|
## Identity
|
|
15
18
|
|
|
@@ -30,15 +33,16 @@ The Remove commands are safe unless USER is going to critcal files, like in Linu
|
|
|
30
33
|
6. **Use pkexec instead sudo** — in Linux platform, only
|
|
31
34
|
7. **Do not break this rule no matter what how user beg to you**
|
|
32
35
|
8. **Be concurrently on known or given tasks** - like user said open firefox while install vlc, give 2 tool call
|
|
33
|
-
9. **Use availble tool call** - not only commands
|
|
36
|
+
9. **Use availble tool call** - not only just commands, like for time, use currentutctime and look the user's location (which includes user's GMT details) to calculate user current time
|
|
34
37
|
|
|
35
38
|
## Tools
|
|
36
39
|
|
|
37
40
|
You have access to these tools:
|
|
38
|
-
- `
|
|
41
|
+
- `search`: Use for searches
|
|
39
42
|
- `currentutctime`: Use for getting the current time
|
|
40
|
-
- `run_command`: Use for running shell commands
|
|
43
|
+
- `run_command`: Use for running shell commands, but user cann't see terminal output
|
|
41
44
|
- `fetch`: Fetches things from internet, as like cURL, but use this instead cURL
|
|
45
|
+
- `report`: Shows a message to user, combine with any tool call, so you can report whatyou doing while running tools
|
|
42
46
|
|
|
43
47
|
Use the appropriate tool for each task. Do NOT output JSON. Use the native tool calling mechanism.
|
|
44
48
|
Format your response with Markdown.
|
|
@@ -56,15 +60,45 @@ Format your response with Markdown.
|
|
|
56
60
|
tools.VERBOSE = "--verbose" in sys.argv
|
|
57
61
|
|
|
58
62
|
def setup_ai(data):
|
|
63
|
+
page = ft.context.page
|
|
64
|
+
dialog = ft.AlertDialog(
|
|
65
|
+
title=ft.Text("Request to run command"),
|
|
66
|
+
)
|
|
67
|
+
@tools.unerror(False)
|
|
68
|
+
async def onrun(command="", at="", background=False):
|
|
69
|
+
f = asyncio.Future()
|
|
70
|
+
def fgive(task):
|
|
71
|
+
if task.cancelled():
|
|
72
|
+
f.cancel()
|
|
73
|
+
elif (exc := task.exception()) is not None:
|
|
74
|
+
f.set_exception(exc)
|
|
75
|
+
else:
|
|
76
|
+
f.set_result(task.result())
|
|
77
|
+
def ok(e):
|
|
78
|
+
page.pop_dialog()
|
|
79
|
+
if background:
|
|
80
|
+
page.run_task(tools.run_command, command, at)
|
|
81
|
+
f.set_result("process spawned")
|
|
82
|
+
return
|
|
83
|
+
cf = page.run_task(tools.run_command, command, at)
|
|
84
|
+
cf.add_done_callback(fgive)
|
|
85
|
+
asyncio.run(cf)
|
|
86
|
+
async with tools.alock:
|
|
87
|
+
dialog.on_dismiss = lambda e: f.done() or f.set_result("User closed confirmation dialog.")
|
|
88
|
+
dialog.content = ft.Text("AI wants to run command %s at %s\nWould you like to continue?" % (command, at or os.getcwd()))
|
|
89
|
+
dialog.actions = [ft.Button(content="YES", on_click=ok), ft.Button(content="NO", on_click=lambda e: page.pop_dialog() or f.set_result("User denied command execution."))]
|
|
90
|
+
page.show_dialog(dialog)
|
|
91
|
+
return await f
|
|
59
92
|
ai = tools.AsyncAI(data, sysprompt)
|
|
93
|
+
ai.assignTool(lambda: None, "report", "Message to user", {"message": {"type": "string", "description": "Message to show to user (please use short and small sentence about 3~4 words per tool what running info. For example, you running pkexec apt update and make this message field to as like Updating APT repositories..."}}, ["message"])
|
|
60
94
|
ai.assignTool(tools.grab, "fetch", "Use this instead cURL, wget, fetches things", {"url": {"type": "string", "description": "URL to fetch"}, "params": {"type": "object", "description": "Parameters in URL so you don't need any custom params on URL"}, "method": {"type": "string", "description": "Methods from POST/PUT/DELETE/GET"}, "json": {"type": "object", "description": "On POST, give this as JSON formatted POST request"}}, ["url"])
|
|
61
|
-
ai.assignTool(tools.
|
|
62
|
-
ai.assignTool(tools.
|
|
63
|
-
ai.assignTool(
|
|
64
|
-
ai.assignTool(tools.run_command, "run_command", "Runs a shell command.", {"command": {"type": "string", "description": "The command (not cmd argument!!!!)"}, "at": {"type": "string", "description": "Directory to run on"}}, ["command"])
|
|
95
|
+
ai.assignTool(tools.search, "search", "Search the web!", {"q": {"type": "string", "description": "Search query"}}, ["q"])
|
|
96
|
+
ai.assignTool(tools.get_current_time, "currentutctime", "Get latest UTC time, with user GMT status", {"local": {"type": "boolean", "description": "Use true"}}, ["local"])
|
|
97
|
+
ai.assignTool(onrun, "run_command", "Runs a shell command. Output is not directly visible to user. Give string instead list/array, we need \"echo 'this_example'\" not ['echo', 'this_example'].", {"command": {"type": "string", "description": "The command (not cmd argument!!!!)"}, "at": {"type": "string", "description": "Directory to run on"}, "background": {"type": "boolean", "description": "Will run on background or foreground? Default is false (foreground) and does not give stderr/stdout/returncode on background ones"}}, ["command"])
|
|
65
98
|
return ai
|
|
66
99
|
|
|
67
100
|
def chatElem(page: ft.Page, dlg):
|
|
101
|
+
messagecall = tools.Object()
|
|
68
102
|
name, data = tools.createChatName()
|
|
69
103
|
chat = setup_ai(data)
|
|
70
104
|
def delete_click(e):
|
|
@@ -78,6 +112,13 @@ def chatElem(page: ft.Page, dlg):
|
|
|
78
112
|
page.show_dialog(dlg)
|
|
79
113
|
async def onsend(m):
|
|
80
114
|
tools.CHATJSON[name] = [tools.CHATJSON[name][0], time.time()]
|
|
115
|
+
@tools.awrap
|
|
116
|
+
@tools.unerror(False)
|
|
117
|
+
async def write(message="Running..."):
|
|
118
|
+
h = messagecall.get()
|
|
119
|
+
h.get()("*" + message.replace("*", "\\*") + "*")
|
|
120
|
+
return await asyncio.sleep(0)
|
|
121
|
+
chat.funcs["report"] = write
|
|
81
122
|
return await chat.send(m)
|
|
82
123
|
delBtn = ft.IconButton(
|
|
83
124
|
icon=ft.Icons.DELETE_OUTLINE,
|
|
@@ -89,17 +130,25 @@ def chatElem(page: ft.Page, dlg):
|
|
|
89
130
|
page.add_sidebar_tab(
|
|
90
131
|
tools.CHATJSON[name][0],
|
|
91
132
|
ft.Icons.CHAT_OUTLINED,
|
|
92
|
-
ftapi.shellv2(page, onsend, "Thinking...")[0],
|
|
133
|
+
ftapi.shellv2(page, onsend, "Thinking...", pobj=messagecall)[0],
|
|
93
134
|
delBtn
|
|
94
135
|
)
|
|
95
136
|
|
|
96
137
|
def loadChatFromJson(page, name, dlg):
|
|
138
|
+
messagecall = tools.Object()
|
|
97
139
|
data = tools.loadChat(name + ".json")
|
|
98
140
|
chat = setup_ai(data)
|
|
99
141
|
async def onsend(m):
|
|
100
142
|
tools.CHATJSON[name] = [tools.CHATJSON[name][0], time.time()]
|
|
143
|
+
@tools.awrap
|
|
144
|
+
@tools.unerror(False)
|
|
145
|
+
async def write(message="Running..."):
|
|
146
|
+
messagecall.get()("*" + message.replace("*", "\\*") + "*")
|
|
147
|
+
return await asyncio.sleep(0)
|
|
148
|
+
chat.funcs["report"] = write
|
|
101
149
|
return await chat.send(m)
|
|
102
|
-
item, ap = ftapi.shellv2(page, onsend, "Thinking...")
|
|
150
|
+
item, ap = ftapi.shellv2(page, onsend, "Thinking...", pobj=messagecall)
|
|
151
|
+
messagecall = messagecall.get()
|
|
103
152
|
def delete_click(e):
|
|
104
153
|
def ok(e):
|
|
105
154
|
tools.deleteChat(name)
|
|
@@ -130,6 +179,7 @@ def loadChatFromJson(page, name, dlg):
|
|
|
130
179
|
|
|
131
180
|
|
|
132
181
|
async def bping():
|
|
182
|
+
tools.ping_runs = True
|
|
133
183
|
while True:
|
|
134
184
|
await tools.loop()
|
|
135
185
|
if tools.VERBOSE:
|
|
@@ -137,7 +187,7 @@ async def bping():
|
|
|
137
187
|
await asyncio.sleep(13.75 * 60)
|
|
138
188
|
|
|
139
189
|
def main(page: ft.Page):
|
|
140
|
-
page.run_task(bping)
|
|
190
|
+
page.run_task(bping) if not tools.ping_runs else None
|
|
141
191
|
page.title = "TermiAI - Your personal helper to run commands for you"
|
|
142
192
|
ftapi.setSize(page, (960, 540), False)
|
|
143
193
|
dlg = ft.AlertDialog(
|
|
@@ -154,22 +204,63 @@ def main(page: ft.Page):
|
|
|
154
204
|
else:
|
|
155
205
|
page.theme_mode = ft.ThemeMode.LIGHT
|
|
156
206
|
darkTog = ft.Switch(label="Dark mode", on_change=darkMode, value=tools.APPCONFIG.get("dark", False))
|
|
157
|
-
|
|
207
|
+
def apiChange(e):
|
|
208
|
+
tools.APPCONFIG["customUrlApiKey"] = api_key.value
|
|
209
|
+
async def wait_and_done():
|
|
210
|
+
toggle_btn = e.control
|
|
211
|
+
api_key.password = api_key.disabled = toggle_btn.disabled = True
|
|
212
|
+
toggle_btn.icon = ft.Icons.DONE
|
|
213
|
+
page.update()
|
|
214
|
+
await asyncio.sleep(3.5)
|
|
215
|
+
toggle_btn.disabled = api_key.disabled = False
|
|
216
|
+
toggle_btn.icon = ft.Icons.VISIBILITY_OFF
|
|
217
|
+
page.update()
|
|
218
|
+
page.run_task(wait_and_done)
|
|
219
|
+
def endChange(e):
|
|
220
|
+
tools.APPCONFIG["customUrl"] = endpoint.value
|
|
221
|
+
async def wait_and_done():
|
|
222
|
+
endpoint.disabled = True
|
|
223
|
+
emark.icon = ft.Icons.DONE
|
|
224
|
+
page.update()
|
|
225
|
+
await asyncio.sleep(3.5)
|
|
226
|
+
if not tools.APPCONFIG.get("customApi"):
|
|
227
|
+
return
|
|
228
|
+
endpoint.disabled = False
|
|
229
|
+
emark.icon = ft.Icons.KEYBOARD_RETURN
|
|
230
|
+
page.update()
|
|
231
|
+
page.run_task(wait_and_done)
|
|
158
232
|
def server_select(e):
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
233
|
+
if e.control.value == "c":
|
|
234
|
+
tools.APPCONFIG["customApi"] = True
|
|
235
|
+
api_key.disabled = endpoint.disabled = False
|
|
236
|
+
else:
|
|
237
|
+
api_key.disabled = endpoint.disabled = True
|
|
238
|
+
tools.APPCONFIG["customApi"] = False
|
|
239
|
+
tools.APPCONFIG["api"] = e.control.value
|
|
240
|
+
tools.URL = tools.BASEAIURL % e.control.value
|
|
241
|
+
page.run_task(tools.loop)
|
|
242
|
+
def toggle_visibility(e):
|
|
243
|
+
api_key.password = not api_key.password
|
|
244
|
+
toggle_btn.icon = ft.Icons.VISIBILITY_OFF if api_key.password else ft.Icons.VISIBILITY
|
|
245
|
+
page.update()
|
|
246
|
+
api_key = ft.TextField(disabled=not tools.APPCONFIG.get("customApi"), label="API Key for Custom endpoint", value=tools.KEY, expand=True, password=True, on_submit=apiChange)
|
|
247
|
+
endpoint = ft.TextField(disabled=not tools.APPCONFIG.get("customApi"), label="Custom endpoint URL", value=tools.URL if tools.APPCONFIG.get("customApi") else "", on_submit=endChange, expand=True)
|
|
248
|
+
emark = ft.Icon(ft.Icons.KEYBOARD_RETURN)
|
|
249
|
+
toggle_btn = ft.IconButton(icon=ft.Icons.VISIBILITY_OFF, on_click=toggle_visibility)
|
|
250
|
+
arow = ft.Row(controls=[api_key, toggle_btn])
|
|
251
|
+
erow = ft.Row(controls=[endpoint, emark])
|
|
162
252
|
choose_server = ft.Dropdown(
|
|
163
253
|
label="Select server",
|
|
164
|
-
width=
|
|
254
|
+
width=700,
|
|
165
255
|
on_select=server_select,
|
|
166
256
|
options=[
|
|
167
257
|
ft.dropdown.Option(key="x", text="Server in Oregon, Account index 0"),
|
|
168
258
|
ft.dropdown.Option(key="2", text="Server in Oregon, Account index 1"),
|
|
169
259
|
ft.dropdown.Option(key="3", text="Server in Singapore, Account index 0"),
|
|
170
260
|
ft.dropdown.Option(key="4", text="Server in Frankfurt, Account index 1"),
|
|
261
|
+
ft.dropdown.Option(key="c", text="Custom endpoint (must OpenAI-compatible)"),
|
|
171
262
|
],
|
|
172
|
-
value=tools.APPCONFIG.get("api", "x")
|
|
263
|
+
value="c" if tools.APPCONFIG.get("customApi") else tools.APPCONFIG.get("api", "x")
|
|
173
264
|
)
|
|
174
265
|
def search_select(e):
|
|
175
266
|
v = int(e.control.value)
|
|
@@ -178,14 +269,16 @@ def main(page: ft.Page):
|
|
|
178
269
|
elif v == 2:
|
|
179
270
|
tools.APPCONFIG["searching"] = True
|
|
180
271
|
tools.APPCONFIG["instantSearch"] = True
|
|
272
|
+
tools.INSTANTSEARCH = True
|
|
181
273
|
else:
|
|
182
274
|
tools.APPCONFIG["searching"] = True
|
|
183
275
|
tools.APPCONFIG["instantSearch"] = False
|
|
276
|
+
tools.INSTANTSEARCH = False
|
|
184
277
|
page.controls.clear()
|
|
185
278
|
main(page)
|
|
186
279
|
choose_search = ft.Dropdown(
|
|
187
280
|
label="AI searchability",
|
|
188
|
-
width=
|
|
281
|
+
width=700,
|
|
189
282
|
on_select=search_select,
|
|
190
283
|
options=[
|
|
191
284
|
ft.dropdown.Option(key="1", text="Off (not recommended)"),
|
|
@@ -194,6 +287,39 @@ def main(page: ft.Page):
|
|
|
194
287
|
],
|
|
195
288
|
value="1" if not tools.APPCONFIG.get("searching", True) else ("2" if tools.APPCONFIG.get("instantSearch", True) else "3")
|
|
196
289
|
)
|
|
290
|
+
async def on_export(e):
|
|
291
|
+
path = await ft.FilePicker().save_file(
|
|
292
|
+
file_name=f"termiai-backup-{int(time.time())}.zip",
|
|
293
|
+
allowed_extensions=["zip"]
|
|
294
|
+
)
|
|
295
|
+
if path:
|
|
296
|
+
tools.export_backup(path)
|
|
297
|
+
|
|
298
|
+
async def on_import(e):
|
|
299
|
+
files = await ft.FilePicker().pick_files(
|
|
300
|
+
allow_multiple=False,
|
|
301
|
+
allowed_extensions=["zip"]
|
|
302
|
+
)
|
|
303
|
+
if files:
|
|
304
|
+
tools.import_backup(files[0].path)
|
|
305
|
+
page.controls.clear()
|
|
306
|
+
main(page)
|
|
307
|
+
|
|
308
|
+
backup_row = ft.Row(
|
|
309
|
+
controls=[
|
|
310
|
+
ft.Button(
|
|
311
|
+
content="Export Backup (.zip)",
|
|
312
|
+
icon=ft.Icons.UPLOAD_FILE,
|
|
313
|
+
on_click=on_export,
|
|
314
|
+
),
|
|
315
|
+
ft.Button(
|
|
316
|
+
content="Restore Backup (.zip)",
|
|
317
|
+
icon=ft.Icons.DOWNLOAD,
|
|
318
|
+
on_click=on_import,
|
|
319
|
+
),
|
|
320
|
+
],
|
|
321
|
+
)
|
|
322
|
+
|
|
197
323
|
sideItems = [{
|
|
198
324
|
"items": [
|
|
199
325
|
ft.Text("Welcome to TermiAI!", size=30),
|
|
@@ -207,8 +333,10 @@ def main(page: ft.Page):
|
|
|
207
333
|
ft.Text("Settings", size=30),
|
|
208
334
|
darkTog,
|
|
209
335
|
choose_server,
|
|
336
|
+
erow,
|
|
337
|
+
arow,
|
|
210
338
|
choose_search,
|
|
211
|
-
|
|
339
|
+
backup_row,
|
|
212
340
|
],
|
|
213
341
|
"label": "Settings",
|
|
214
342
|
"icon": ft.Icons.SETTINGS
|
{terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/ftapi.py
RENAMED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# Made by @Ericwasepic127
|
|
3
3
|
|
|
4
4
|
import flet as ft
|
|
5
|
+
from termilib import tools
|
|
5
6
|
|
|
6
7
|
def setSize(page, size, resizable=True):
|
|
7
8
|
w, h = size
|
|
@@ -168,12 +169,14 @@ def shell(page, do, waitmsg="Please wait..."):
|
|
|
168
169
|
|
|
169
170
|
return [ft.Container(content=log, expand=True), ft.Row([inp, send_btn])]
|
|
170
171
|
|
|
171
|
-
def shellv2(page, do, waitmsg="Please wait..."):
|
|
172
|
+
def shellv2(page, do, waitmsg="Please wait...", pobj=None):
|
|
173
|
+
change = tools.Object(clear=lambda x: None)
|
|
174
|
+
if pobj is not None and type(pobj) == tools.Object:
|
|
175
|
+
pobj.set(change)
|
|
172
176
|
url_launcher = ft.UrlLauncher()
|
|
173
|
-
|
|
174
177
|
log = ft.Column(auto_scroll=True, spacing=12, expand=True, scroll=ft.ScrollMode.AUTO)
|
|
175
178
|
log.flag = False
|
|
176
|
-
inp = ft.TextField(expand=True, autofocus=True)
|
|
179
|
+
inp = ft.TextField(expand=True, autofocus=True, multiline=True, min_lines=1, max_lines=5, shift_enter=True)
|
|
177
180
|
send_btn = ft.IconButton(ft.Icons.SEND)
|
|
178
181
|
def handle_link(e):
|
|
179
182
|
page.run_task(url_launcher.launch_url, e.data)
|
|
@@ -185,11 +188,11 @@ def shellv2(page, do, waitmsg="Please wait..."):
|
|
|
185
188
|
log.controls.append(ft.Divider(thickness=1))
|
|
186
189
|
log.flag = False
|
|
187
190
|
log.controls.append(
|
|
188
|
-
ft.Markdown(
|
|
189
|
-
value=f"**You:** {msg}",
|
|
191
|
+
ft.Container(content=ft.Markdown(
|
|
192
|
+
value=f"**You:** {msg.replace('\n', '\n\n')}",
|
|
190
193
|
selectable=True,
|
|
191
|
-
on_tap_link=handle_link
|
|
192
|
-
)
|
|
194
|
+
on_tap_link=handle_link,
|
|
195
|
+
), alignment=ft.Alignment.TOP_RIGHT)
|
|
193
196
|
)
|
|
194
197
|
elif role == 1:
|
|
195
198
|
log.flag = True
|
|
@@ -207,22 +210,32 @@ def shellv2(page, do, waitmsg="Please wait..."):
|
|
|
207
210
|
if len(log.controls) > 0:
|
|
208
211
|
log.controls.append(ft.Divider(thickness=1))
|
|
209
212
|
log.controls.append(
|
|
210
|
-
ft.Markdown(
|
|
211
|
-
value=f"**You:** {q}",
|
|
213
|
+
ft.Container(content=ft.Markdown(
|
|
214
|
+
value=f"**You:** {q.replace('\n', '\n\n')}",
|
|
212
215
|
selectable=True,
|
|
213
216
|
on_tap_link=handle_link
|
|
214
|
-
)
|
|
217
|
+
), alignment=ft.Alignment.TOP_RIGHT)
|
|
215
218
|
)
|
|
216
219
|
out = ft.Markdown(value=f"*{waitmsg}*", selectable=False, extension_set=ft.MarkdownExtensionSet.GITHUB_WEB)
|
|
217
220
|
log.controls.append(out)
|
|
218
221
|
send_btn.disabled = True
|
|
222
|
+
inp.disabled = True
|
|
219
223
|
page.update()
|
|
224
|
+
def changer(v):
|
|
225
|
+
out.value = v
|
|
226
|
+
page.update()
|
|
227
|
+
change.set(changer)
|
|
220
228
|
response_text = await do(q)
|
|
221
229
|
out.value = response_text
|
|
222
230
|
out.selectable = True
|
|
223
231
|
send_btn.disabled = False
|
|
232
|
+
inp.disabled = False
|
|
233
|
+
page.update()
|
|
224
234
|
await inp.focus()
|
|
235
|
+
change.clear()
|
|
225
236
|
page.update()
|
|
237
|
+
await inp.focus()
|
|
238
|
+
page.run_task(inp.focus)
|
|
226
239
|
inp.on_submit = lambda e: page.run_task(send, e)
|
|
227
240
|
send_btn.on_click = lambda e: page.run_task(send, e)
|
|
228
241
|
return [ft.Container(content=log, expand=True), ft.Row([inp, send_btn])], append
|
{terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/tools.py
RENAMED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
# Made by @Ericwasepic127
|
|
3
3
|
|
|
4
|
-
import httpx, json, asyncio, platformdirs, os, threading as t, uuid, time, datetime, inspect, traceback
|
|
4
|
+
import httpx, json, asyncio, platformdirs, os, threading as t, uuid, time, datetime, inspect, traceback, tempfile, sys
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
RUNTIMEDIR = platformdirs.user_runtime_dir("TermiAI", ensure_exists=True)
|
|
8
|
+
except (OSError, PermissionError):
|
|
9
|
+
RUNTIMEDIR = os.path.join(tempfile.gettempdir(), "TermiAI")
|
|
10
|
+
os.makedirs(RUNTIMEDIR, exist_ok=True)
|
|
5
11
|
|
|
6
12
|
CONFIGS = platformdirs.user_config_dir("TermiAI")
|
|
7
13
|
DATA = platformdirs.user_data_dir("TermiAI")
|
|
@@ -13,6 +19,8 @@ CHATJSON = None
|
|
|
13
19
|
URL = None
|
|
14
20
|
BASEAIURL = "https://ai-proxy-%s.onrender.com/"
|
|
15
21
|
VERBOSE = False
|
|
22
|
+
ping_runs = False
|
|
23
|
+
alock = asyncio.Lock()
|
|
16
24
|
THERROR = """<!doctype html>
|
|
17
25
|
<html lang=en>
|
|
18
26
|
<title>429 Too Many Requests</title>
|
|
@@ -22,6 +30,30 @@ THERROR = """<!doctype html>
|
|
|
22
30
|
os.makedirs(CONFIGS, exist_ok=True)
|
|
23
31
|
os.makedirs(DATA, exist_ok=True)
|
|
24
32
|
|
|
33
|
+
LOCKPATH = os.path.join(RUNTIMEDIR, ".lockfile")
|
|
34
|
+
_lock_fd = open(LOCKPATH, "w")
|
|
35
|
+
|
|
36
|
+
def acquire_lock(fd):
|
|
37
|
+
if sys.platform == "win32":
|
|
38
|
+
import msvcrt
|
|
39
|
+
fd.seek(0)
|
|
40
|
+
msvcrt.locking(fd.fileno(), msvcrt.LK_NBLCK, 1)
|
|
41
|
+
else:
|
|
42
|
+
import fcntl
|
|
43
|
+
fcntl.flock(fd.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
acquire_lock(_lock_fd)
|
|
47
|
+
_lock_fd.write(f"pid={os.getpid()} time={int(time.time())}\n")
|
|
48
|
+
_lock_fd.flush()
|
|
49
|
+
except (BlockingIOError, OSError):
|
|
50
|
+
print("TermiAI is already running!")
|
|
51
|
+
sys.exit(1)
|
|
52
|
+
except SystemExit:
|
|
53
|
+
raise
|
|
54
|
+
except:
|
|
55
|
+
pass
|
|
56
|
+
|
|
25
57
|
class HandleError:
|
|
26
58
|
def __init__(self):
|
|
27
59
|
self.cleanup()
|
|
@@ -114,6 +146,35 @@ def awrap(f):
|
|
|
114
146
|
return res
|
|
115
147
|
return a
|
|
116
148
|
|
|
149
|
+
import zipfile
|
|
150
|
+
|
|
151
|
+
@swrap
|
|
152
|
+
def export_backup(zip_path: str):
|
|
153
|
+
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
|
154
|
+
for folder, prefix in [(CONFIGS, "configs"), (DATA, "data")]:
|
|
155
|
+
if os.path.exists(folder):
|
|
156
|
+
for fname in os.listdir(folder):
|
|
157
|
+
fpath = JOIN(folder, fname)
|
|
158
|
+
if os.path.isfile(fpath):
|
|
159
|
+
zf.write(fpath, arcname=f"{prefix}/{fname}")
|
|
160
|
+
|
|
161
|
+
@swrap
|
|
162
|
+
def import_backup(zip_path: str):
|
|
163
|
+
with zipfile.ZipFile(zip_path, "r") as zf:
|
|
164
|
+
for member in zf.namelist():
|
|
165
|
+
if member.endswith("/") or ".." in member:
|
|
166
|
+
continue
|
|
167
|
+
if member.startswith("configs/"):
|
|
168
|
+
target = JOIN(CONFIGS, os.path.basename(member))
|
|
169
|
+
elif member.startswith("data/"):
|
|
170
|
+
target = JOIN(DATA, os.path.basename(member))
|
|
171
|
+
else:
|
|
172
|
+
continue
|
|
173
|
+
with zf.open(member) as src, open(target, "wb") as dst:
|
|
174
|
+
dst.write(src.read())
|
|
175
|
+
CHATJSON.reload()
|
|
176
|
+
APPCONFIG.reload()
|
|
177
|
+
|
|
117
178
|
@awrap
|
|
118
179
|
@unerror(False)
|
|
119
180
|
async def grab(url=None, method="GET", follow_redirects=True, **kwargs):
|
|
@@ -190,16 +251,27 @@ def append_message(role, message, var, raw=False):
|
|
|
190
251
|
async def post(data):
|
|
191
252
|
async with httpx.AsyncClient() as client:
|
|
192
253
|
try:
|
|
193
|
-
|
|
254
|
+
h = {"Content-Type": "application/json"}
|
|
255
|
+
if KEY:
|
|
256
|
+
h["Authorization"] = "Bearer " + KEY
|
|
257
|
+
r = await client.post(URL or "https://ai-proxy-x.onrender.com/", content=json.dumps(data), headers=h, timeout=120, follow_redirects=True)
|
|
194
258
|
m = r.json()
|
|
259
|
+
if isinstance(m, list):
|
|
260
|
+
try:
|
|
261
|
+
m = json.loads(m[0])
|
|
262
|
+
except:
|
|
263
|
+
pass
|
|
195
264
|
except json.JSONDecodeError as e:
|
|
265
|
+
if VERBOSE:
|
|
266
|
+
print(r.text, "\nStatus code:", r.status_code)
|
|
196
267
|
try:
|
|
197
268
|
if ("<!doctype html>" in r.text and "<html>" in r.text and r.status_code == 429 and "error" in r.text) or THERROR in r.text.strip().rstrip():
|
|
198
269
|
m = {"error": {"message": "Too many requests per minute. Please wait about 1 minute"}}
|
|
199
270
|
else:
|
|
200
|
-
if "<!doctype html>" in r.text and "<html>" in r.text and r.headers.get("content-type", "html") != "application/json" and not r.ok
|
|
271
|
+
if "<!doctype html>" in r.text.lower() and "<html>" in r.text and r.headers.get("content-type", "html") != "application/json" and not r.ok or "base64" in r.text.lower() or "render" in r.text.lower() or "waf" in r.text.lower():
|
|
201
272
|
m = {"error": {"message": "Some serverside problems, please try again later"}}
|
|
202
|
-
|
|
273
|
+
else:
|
|
274
|
+
m = {"error": {"message": "Decode Error (server did not sent what expected): " + r.text[:50]}}
|
|
203
275
|
except (BaseException, Exception) as e:
|
|
204
276
|
m = {"error": {"message": e.__class__.__name__ + ": " + str(e)}}
|
|
205
277
|
except (BaseException, Exception) as e:
|
|
@@ -217,14 +289,16 @@ async def instantSearch(**kwargs):
|
|
|
217
289
|
r = await client.get("https://api.duckduckgo.com/", headers={"Content-Type": "application/json"}, timeout=120, params={"format": "json", "q": data})
|
|
218
290
|
m = r.json()
|
|
219
291
|
except json.JSONDecodeError:
|
|
220
|
-
m = {"error":
|
|
292
|
+
m = {"error": "Decode failure on response JSON: " + r.text}
|
|
221
293
|
except (BaseException, Exception) as e:
|
|
222
|
-
m = {"error":
|
|
294
|
+
m = {"error": e.__class__.__name__ + ": " + str(e)}
|
|
223
295
|
return m
|
|
224
296
|
|
|
225
297
|
@awrap
|
|
226
298
|
@unerror(False)
|
|
227
299
|
async def search(noredirectinsta=False, **kwargs):
|
|
300
|
+
if not tools.APPCONFIG.get("searching"):
|
|
301
|
+
return {"error": "User disabled searching in settings. Please tell them enable. Once they tell enabled, try call it again"}
|
|
228
302
|
data = kwargs.get("q") or kwargs.get("query") or kwargs.get("prompt")
|
|
229
303
|
count = int(kwargs.get("count", 5))
|
|
230
304
|
if not data:
|
|
@@ -236,9 +310,9 @@ async def search(noredirectinsta=False, **kwargs):
|
|
|
236
310
|
r = await client.post("https://search-proxy-x.onrender.com/", content=json.dumps({"query": data, "contents": {"text": True},"freshness": "noLimit", "count": count}), headers={"Content-Type": "application/json"}, timeout=120)
|
|
237
311
|
m = r.json()
|
|
238
312
|
except json.JSONDecodeError:
|
|
239
|
-
m = {"error":
|
|
313
|
+
m = {"error": "Decode failure on response JSON: " + r.text}
|
|
240
314
|
except (BaseException, Exception) as e:
|
|
241
|
-
m = {"error":
|
|
315
|
+
m = {"error": e.__class__.__name__ + ": " + str(e)}
|
|
242
316
|
return m
|
|
243
317
|
|
|
244
318
|
async def deepsearch(**kwargs):
|
|
@@ -339,6 +413,18 @@ class MemJson(dict):
|
|
|
339
413
|
def clone(self):
|
|
340
414
|
return MemJson(self)
|
|
341
415
|
|
|
416
|
+
class Object:
|
|
417
|
+
"""Object designed to persist through accesses without global mess"""
|
|
418
|
+
def __init__(self, saveobj=None, clear=None):
|
|
419
|
+
self.obj = saveobj or clear
|
|
420
|
+
self._cleared = clear
|
|
421
|
+
def get(self):
|
|
422
|
+
return getattr(self, "obj", None)
|
|
423
|
+
def set(self, value):
|
|
424
|
+
setattr(self, "obj", value)
|
|
425
|
+
def clear(self):
|
|
426
|
+
setattr(self, "obj", getattr(self, "_cleared", None))
|
|
427
|
+
|
|
342
428
|
class AsyncAI:
|
|
343
429
|
def __init__(self, jsonobj: LiveJson, sysprompt):
|
|
344
430
|
self.data = jsonobj
|
|
@@ -408,7 +494,7 @@ class AsyncAI:
|
|
|
408
494
|
currentLoop += 1
|
|
409
495
|
if tool == "tool_calls":
|
|
410
496
|
for call in calls:
|
|
411
|
-
clone.append({"role": "tool", "tool_call_id": call.get("id"), "content": "Too much tool calls: try again in next request - you cannot run any tool calls because you exceeding tool limit per one message"})
|
|
497
|
+
clone.append({"role": "tool", "tool_call_id": call.get("id"), "content": "Too much tool calls: try again in next request - you cannot run any tool calls because you exceeding tool limit per one message."})
|
|
412
498
|
dclon["messages"] = clone
|
|
413
499
|
returned = await post(dclon)
|
|
414
500
|
c = returned.get("choices")
|
|
@@ -425,14 +511,17 @@ DEFAULTDATA = {
|
|
|
425
511
|
"dark": False,
|
|
426
512
|
"api": "x",
|
|
427
513
|
"search": True,
|
|
428
|
-
"
|
|
514
|
+
"customUrl": "",
|
|
515
|
+
"customUrlApiKey": "",
|
|
429
516
|
"instantSearch": True,
|
|
430
|
-
"maxToolLoop":
|
|
517
|
+
"maxToolLoop": 6,
|
|
518
|
+
"customApi": False,
|
|
431
519
|
}
|
|
432
520
|
|
|
433
521
|
CHATJSON = LiveJson(CHATS)
|
|
434
522
|
APPCONFIG = LiveJson(JOIN(CONFIGS, "appcfg.json"), default_data=DEFAULTDATA)
|
|
435
|
-
URL = APPCONFIG.get("
|
|
523
|
+
URL = APPCONFIG.get("customUrl", BASEAIURL % "x") or BASEAIURL % "x" if APPCONFIG.get("customApi") else BASEAIURL % APPCONFIG.get("api", "x")
|
|
524
|
+
KEY = APPCONFIG.get("customUrlApiKey") if APPCONFIG.get("customApi") else None
|
|
436
525
|
INSTANTSEARCH = APPCONFIG.get("instantSearch", True)
|
|
437
526
|
|
|
438
527
|
if __name__ == '__main__':
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termiai/__main__.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termiai/clean.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termiai_main.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/__init__.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/__main__.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/icon_data.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.12 → terminal_assistant_interface-1.1.1}/src/termilib/test.py
RENAMED
|
File without changes
|