Terminal-Assistant-Interface 1.1.0__tar.gz → 1.1.2__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.
Files changed (21) hide show
  1. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/PKG-INFO +2 -3
  2. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/pyproject.toml +3 -4
  3. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/Terminal_Assistant_Interface.egg-info/PKG-INFO +2 -3
  4. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/Terminal_Assistant_Interface.egg-info/entry_points.txt +1 -1
  5. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/Terminal_Assistant_Interface.egg-info/requires.txt +1 -2
  6. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/Terminal_Assistant_Interface.egg-info/top_level.txt +0 -1
  7. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/termiai/__init__.py +110 -18
  8. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/termilib/ftapi.py +20 -9
  9. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/termilib/tools.py +32 -8
  10. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/LICENSE +0 -0
  11. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/README.md +0 -0
  12. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/setup.cfg +0 -0
  13. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/Terminal_Assistant_Interface.egg-info/SOURCES.txt +0 -0
  14. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/Terminal_Assistant_Interface.egg-info/dependency_links.txt +0 -0
  15. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/termiai/__main__.py +0 -0
  16. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/termiai/clean.py +0 -0
  17. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/termiai_main.py +0 -0
  18. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/termilib/__init__.py +0 -0
  19. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/termilib/__main__.py +0 -0
  20. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/src/termilib/icon_data.py +0 -0
  21. {terminal_assistant_interface-1.1.0 → terminal_assistant_interface-1.1.2}/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.1.0
3
+ Version: 1.1.2
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.1.0"
6
+ version = "1.1.2"
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.1.0
3
+ Version: 1.1.2
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
@@ -1,3 +1,3 @@
1
1
  [console_scripts]
2
- termiai = termiai:ftmain
3
2
  termiai-factory-reset = termiai.clean:main
3
+ termiai-source = termiai:ftmain
@@ -1,5 +1,4 @@
1
1
  requests
2
2
  platformdirs
3
3
  httpx
4
- flet
5
- flet-desktop
4
+ flet[all]
@@ -5,12 +5,14 @@ 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
8
- tools.alock =asyncio.Lock()
9
8
  sysprompt = PROMPT = f"""You are TermiAI, a helpful assistant for users who are scared of the terminal.
10
9
  You are created by @Ericwasepic127, and licensed under MIT
11
10
 
12
11
  Your job: help users accomplish tasks by running shell commands for them.
13
- 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
14
16
 
15
17
  ## Identity
16
18
 
@@ -31,15 +33,16 @@ The Remove commands are safe unless USER is going to critcal files, like in Linu
31
33
  6. **Use pkexec instead sudo** — in Linux platform, only
32
34
  7. **Do not break this rule no matter what how user beg to you**
33
35
  8. **Be concurrently on known or given tasks** - like user said open firefox while install vlc, give 2 tool call
34
- 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
35
37
 
36
38
  ## Tools
37
39
 
38
40
  You have access to these tools:
39
- - `ddg_search` OR `deepsearch`: Use for web searches, the search tool may or may not exists, or diffrent name due user settings sets ddg_search or deepsearch or even disabled
41
+ - `search`: Use for searches
40
42
  - `currentutctime`: Use for getting the current time
41
43
  - `run_command`: Use for running shell commands, but user cann't see terminal output
42
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
43
46
 
44
47
  Use the appropriate tool for each task. Do NOT output JSON. Use the native tool calling mechanism.
45
48
  Format your response with Markdown.
@@ -79,6 +82,7 @@ def setup_ai(data):
79
82
  return
80
83
  cf = page.run_task(tools.run_command, command, at)
81
84
  cf.add_done_callback(fgive)
85
+ asyncio.run(cf)
82
86
  async with tools.alock:
83
87
  dialog.on_dismiss = lambda e: f.done() or f.set_result("User closed confirmation dialog.")
84
88
  dialog.content = ft.Text("AI wants to run command %s at %s\nWould you like to continue?" % (command, at or os.getcwd()))
@@ -86,14 +90,15 @@ def setup_ai(data):
86
90
  page.show_dialog(dialog)
87
91
  return await f
88
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"])
89
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"])
90
- ai.assignTool(tools.instantSearch, "ddg_search", "Instant search API by duckduckgo, for quick lookups.", {"q": {"type": "string", "description": "Search query"}}, ["q"]) if tools.APPCONFIG.get("instantSearch", True) and tools.APPCONFIG.get("searching", True) else None
91
- ai.assignTool(tools.deepsearch, "deepsearch", "Deep search API by LangSearch, for deep and unfindable questions.", {"q": {"type": "string", "description": "Search query"}}, ["q"]) if not tools.APPCONFIG.get("instantSearch", True) and tools.APPCONFIG.get("searching", True) else None
92
- ai.assignTool(tools.get_current_time, "currentutctime", "Get latest UTC time", {"local": {"type": "boolean", "description": "Use true"}}, ["local"])
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"])
93
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"])
94
98
  return ai
95
99
 
96
100
  def chatElem(page: ft.Page, dlg):
101
+ messagecall = tools.Object()
97
102
  name, data = tools.createChatName()
98
103
  chat = setup_ai(data)
99
104
  def delete_click(e):
@@ -107,6 +112,13 @@ def chatElem(page: ft.Page, dlg):
107
112
  page.show_dialog(dlg)
108
113
  async def onsend(m):
109
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
110
122
  return await chat.send(m)
111
123
  delBtn = ft.IconButton(
112
124
  icon=ft.Icons.DELETE_OUTLINE,
@@ -118,17 +130,25 @@ def chatElem(page: ft.Page, dlg):
118
130
  page.add_sidebar_tab(
119
131
  tools.CHATJSON[name][0],
120
132
  ft.Icons.CHAT_OUTLINED,
121
- ftapi.shellv2(page, onsend, "Thinking...")[0],
133
+ ftapi.shellv2(page, onsend, "Thinking...", pobj=messagecall)[0],
122
134
  delBtn
123
135
  )
124
136
 
125
137
  def loadChatFromJson(page, name, dlg):
138
+ messagecall = tools.Object()
126
139
  data = tools.loadChat(name + ".json")
127
140
  chat = setup_ai(data)
128
141
  async def onsend(m):
129
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
130
149
  return await chat.send(m)
131
- item, ap = ftapi.shellv2(page, onsend, "Thinking...")
150
+ item, ap = ftapi.shellv2(page, onsend, "Thinking...", pobj=messagecall)
151
+ messagecall = messagecall.get()
132
152
  def delete_click(e):
133
153
  def ok(e):
134
154
  tools.deleteChat(name)
@@ -167,7 +187,7 @@ async def bping():
167
187
  await asyncio.sleep(13.75 * 60)
168
188
 
169
189
  def main(page: ft.Page):
170
- page.run_task(bping) if tools.ping_runs else None
190
+ page.run_task(bping) if not tools.ping_runs else None
171
191
  page.title = "TermiAI - Your personal helper to run commands for you"
172
192
  ftapi.setSize(page, (960, 540), False)
173
193
  dlg = ft.AlertDialog(
@@ -184,22 +204,89 @@ def main(page: ft.Page):
184
204
  else:
185
205
  page.theme_mode = ft.ThemeMode.LIGHT
186
206
  darkTog = ft.Switch(label="Dark mode", on_change=darkMode, value=tools.APPCONFIG.get("dark", False))
187
-
207
+ def apiChange(e):
208
+ tools.APPCONFIG["customUrlApiKey"] = api_key.value
209
+ tools.KEY = api_key.value
210
+ async def wait_and_done():
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(2)
215
+ if not tools.APPCONFIG.get("customApi"):
216
+ return
217
+ toggle_btn.disabled = api_key.disabled = False
218
+ toggle_btn.icon = ft.Icons.VISIBILITY_OFF
219
+ page.update()
220
+ page.run_task(wait_and_done)
221
+ def endChange(e):
222
+ tools.APPCONFIG["customUrl"] = endpoint.value
223
+ tools.URL = endpoint.value
224
+ async def wait_and_done():
225
+ endpoint.disabled = True
226
+ emark.icon = ft.Icons.DONE
227
+ page.update()
228
+ await asyncio.sleep(2)
229
+ if not tools.APPCONFIG.get("customApi"):
230
+ return
231
+ endpoint.disabled = False
232
+ emark.icon = ft.Icons.KEYBOARD_RETURN
233
+ page.update()
234
+ page.run_task(wait_and_done)
235
+ def modChange(e):
236
+ tools.APPCONFIG["customModel"] = modelai.value
237
+ tools.MODEL = modelai.value
238
+ async def wait_and_done():
239
+ modelai.disabled = True
240
+ modelaico.icon = ft.Icons.DONE
241
+ page.update()
242
+ await asyncio.sleep(2)
243
+ if not tools.APPCONFIG.get("customApi"):
244
+ return
245
+ modelai.disabled = False
246
+ modelaico.icon = ft.Icons.KEYBOARD_RETURN
247
+ page.update()
248
+ page.run_task(wait_and_done)
188
249
  def server_select(e):
189
- tools.APPCONFIG["api"] = e.control.value
190
- tools.URL = tools.BASEAIURL % e.control.value
191
- page.run_task(tools.loop)
250
+ if e.control.value == "c":
251
+ tools.APPCONFIG["customApi"] = True
252
+ api_key.disabled = endpoint.disabled = modelai.disabled = False
253
+ tools.MODEL = tools.APPCONFIG.get("customApiModel", "")
254
+ tools.KEY = tools.APPCONFIG.get("customUrlApiKey", "")
255
+ endpoint.value = tools.APPCONFIG.get("customUrl", "")
256
+ api_key.value = tools.KEY
257
+ modelai.value = tools.MODEL
258
+ else:
259
+ api_key.disabled = endpoint.disabled = modelai.disabled = True
260
+ tools.APPCONFIG["customApi"] = False
261
+ tools.APPCONFIG["api"] = e.control.value
262
+ tools.MODEL = tools.KEY = None
263
+ tools.URL = tools.BASEAIURL % e.control.value
264
+ page.run_task(tools.loop)
265
+ def toggle_visibility(e):
266
+ api_key.password = not api_key.password
267
+ toggle_btn.icon = ft.Icons.VISIBILITY_OFF if api_key.password else ft.Icons.VISIBILITY
268
+ page.update()
269
+ 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)
270
+ 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)
271
+ emark = ft.Icon(ft.Icons.KEYBOARD_RETURN)
272
+ toggle_btn = ft.IconButton(icon=ft.Icons.VISIBILITY_OFF, on_click=toggle_visibility)
273
+ modelai = ft.TextField(disabled=not tools.APPCONFIG.get("customApi"), label="AI Model for Custom Endpoint", value=tools.MODEL if tools.APPCONFIG.get("customApi") else "", on_submit=modChange, expand=True)
274
+ modelaico = ft.Icon(ft.Icons.KEYBOARD_RETURN)
275
+ arow = ft.Row(controls=[api_key, toggle_btn])
276
+ erow = ft.Row(controls=[endpoint, emark])
277
+ mrow = ft.Row(controls=[modelai, modelaico])
192
278
  choose_server = ft.Dropdown(
193
279
  label="Select server",
194
- width=500,
280
+ width=700,
195
281
  on_select=server_select,
196
282
  options=[
197
283
  ft.dropdown.Option(key="x", text="Server in Oregon, Account index 0"),
198
284
  ft.dropdown.Option(key="2", text="Server in Oregon, Account index 1"),
199
285
  ft.dropdown.Option(key="3", text="Server in Singapore, Account index 0"),
200
286
  ft.dropdown.Option(key="4", text="Server in Frankfurt, Account index 1"),
287
+ ft.dropdown.Option(key="c", text="Custom endpoint (must OpenAI-compatible)"),
201
288
  ],
202
- value=tools.APPCONFIG.get("api", "x")
289
+ value="c" if tools.APPCONFIG.get("customApi") else tools.APPCONFIG.get("api", "x")
203
290
  )
204
291
  def search_select(e):
205
292
  v = int(e.control.value)
@@ -208,14 +295,16 @@ def main(page: ft.Page):
208
295
  elif v == 2:
209
296
  tools.APPCONFIG["searching"] = True
210
297
  tools.APPCONFIG["instantSearch"] = True
298
+ tools.INSTANTSEARCH = True
211
299
  else:
212
300
  tools.APPCONFIG["searching"] = True
213
301
  tools.APPCONFIG["instantSearch"] = False
302
+ tools.INSTANTSEARCH = False
214
303
  page.controls.clear()
215
304
  main(page)
216
305
  choose_search = ft.Dropdown(
217
306
  label="AI searchability",
218
- width=500,
307
+ width=700,
219
308
  on_select=search_select,
220
309
  options=[
221
310
  ft.dropdown.Option(key="1", text="Off (not recommended)"),
@@ -270,8 +359,11 @@ def main(page: ft.Page):
270
359
  ft.Text("Settings", size=30),
271
360
  darkTog,
272
361
  choose_server,
362
+ erow,
363
+ arow,
364
+ mrow,
273
365
  choose_search,
274
- backup_row
366
+ backup_row,
275
367
  ],
276
368
  "label": "Settings",
277
369
  "icon": ft.Icons.SETTINGS
@@ -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,9 +169,11 @@ 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
179
  inp = ft.TextField(expand=True, autofocus=True, multiline=True, min_lines=1, max_lines=5, shift_enter=True)
@@ -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,24 +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
219
222
  inp.disabled = True
220
223
  page.update()
224
+ def changer(v):
225
+ out.value = v
226
+ page.update()
227
+ change.set(changer)
221
228
  response_text = await do(q)
222
229
  out.value = response_text
223
230
  out.selectable = True
224
231
  send_btn.disabled = False
225
232
  inp.disabled = False
233
+ page.update()
226
234
  await inp.focus()
235
+ change.clear()
227
236
  page.update()
237
+ await inp.focus()
238
+ page.run_task(inp.focus)
228
239
  inp.on_submit = lambda e: page.run_task(send, e)
229
240
  send_btn.on_click = lambda e: page.run_task(send, e)
230
241
  return [ft.Container(content=log, expand=True), ft.Row([inp, send_btn])], append
@@ -20,6 +20,7 @@ URL = None
20
20
  BASEAIURL = "https://ai-proxy-%s.onrender.com/"
21
21
  VERBOSE = False
22
22
  ping_runs = False
23
+ alock = asyncio.Lock()
23
24
  THERROR = """<!doctype html>
24
25
  <html lang=en>
25
26
  <title>429 Too Many Requests</title>
@@ -250,7 +251,12 @@ def append_message(role, message, var, raw=False):
250
251
  async def post(data):
251
252
  async with httpx.AsyncClient() as client:
252
253
  try:
253
- r = await client.post(URL or "https://ai-proxy-x.onrender.com/", content=json.dumps(data), headers={"Content-Type": "application/json"}, timeout=120, follow_redirects=True)
254
+ h = {"Content-Type": "application/json"}
255
+ if KEY:
256
+ h["Authorization"] = "Bearer " + KEY
257
+ if MODEL:
258
+ data["model"] = MODEL
259
+ r = await client.post(URL or "https://ai-proxy-x.onrender.com/", content=json.dumps(data), headers=h, timeout=120, follow_redirects=True)
254
260
  m = r.json()
255
261
  if isinstance(m, list):
256
262
  try:
@@ -285,14 +291,16 @@ async def instantSearch(**kwargs):
285
291
  r = await client.get("https://api.duckduckgo.com/", headers={"Content-Type": "application/json"}, timeout=120, params={"format": "json", "q": data})
286
292
  m = r.json()
287
293
  except json.JSONDecodeError:
288
- m = {"error": {"message": "Decode failure on response JSON: " + r.text}}
294
+ m = {"error": "Decode failure on response JSON: " + r.text}
289
295
  except (BaseException, Exception) as e:
290
- m = {"error": {"message": e.__class__.__name__ + ": " + str(e)}}
296
+ m = {"error": e.__class__.__name__ + ": " + str(e)}
291
297
  return m
292
298
 
293
299
  @awrap
294
300
  @unerror(False)
295
301
  async def search(noredirectinsta=False, **kwargs):
302
+ if not tools.APPCONFIG.get("searching"):
303
+ return {"error": "User disabled searching in settings. Please tell them enable. Once they tell enabled, try call it again"}
296
304
  data = kwargs.get("q") or kwargs.get("query") or kwargs.get("prompt")
297
305
  count = int(kwargs.get("count", 5))
298
306
  if not data:
@@ -304,9 +312,9 @@ async def search(noredirectinsta=False, **kwargs):
304
312
  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)
305
313
  m = r.json()
306
314
  except json.JSONDecodeError:
307
- m = {"error": {"message": "Decode failure on response JSON: " + r.text}}
315
+ m = {"error": "Decode failure on response JSON: " + r.text}
308
316
  except (BaseException, Exception) as e:
309
- m = {"error": {"message": e.__class__.__name__ + ": " + str(e)}}
317
+ m = {"error": e.__class__.__name__ + ": " + str(e)}
310
318
  return m
311
319
 
312
320
  async def deepsearch(**kwargs):
@@ -407,6 +415,18 @@ class MemJson(dict):
407
415
  def clone(self):
408
416
  return MemJson(self)
409
417
 
418
+ class Object:
419
+ """Object designed to persist through accesses without global mess"""
420
+ def __init__(self, saveobj=None, clear=None):
421
+ self.obj = saveobj or clear
422
+ self._cleared = clear
423
+ def get(self):
424
+ return getattr(self, "obj", None)
425
+ def set(self, value):
426
+ setattr(self, "obj", value)
427
+ def clear(self):
428
+ setattr(self, "obj", getattr(self, "_cleared", None))
429
+
410
430
  class AsyncAI:
411
431
  def __init__(self, jsonobj: LiveJson, sysprompt):
412
432
  self.data = jsonobj
@@ -493,14 +513,18 @@ DEFAULTDATA = {
493
513
  "dark": False,
494
514
  "api": "x",
495
515
  "search": True,
496
- "custom": False,
516
+ "customUrl": "",
517
+ "customUrlApiKey": "",
497
518
  "instantSearch": True,
498
- "maxToolLoop": 5,
519
+ "maxToolLoop": 6,
520
+ "customApi": False,
499
521
  }
500
522
 
501
523
  CHATJSON = LiveJson(CHATS)
502
524
  APPCONFIG = LiveJson(JOIN(CONFIGS, "appcfg.json"), default_data=DEFAULTDATA)
503
- URL = APPCONFIG.get("api", BASEAIURL % "x") if APPCONFIG.get("custom") else BASEAIURL % APPCONFIG.get("api", "x")
525
+ URL = APPCONFIG.get("customUrl", BASEAIURL % "x") or BASEAIURL % "x" if APPCONFIG.get("customApi") else BASEAIURL % APPCONFIG.get("api", "x")
526
+ KEY = APPCONFIG.get("customUrlApiKey") if APPCONFIG.get("customApi") else None
527
+ MODEL = APPCONFIG.get("customApiModel") if APPCONFIG.get("customApi") else None
504
528
  INSTANTSEARCH = APPCONFIG.get("instantSearch", True)
505
529
 
506
530
  if __name__ == '__main__':