webscout 6.2b0__py3-none-any.whl → 6.4__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.
Potentially problematic release.
This version of webscout might be problematic. Click here for more details.
- webscout/AIauto.py +191 -176
- webscout/AIbase.py +112 -239
- webscout/AIutel.py +488 -1130
- webscout/Agents/functioncall.py +248 -198
- webscout/Bing_search.py +250 -153
- webscout/DWEBS.py +454 -178
- webscout/Extra/__init__.py +2 -1
- webscout/Extra/autocoder/__init__.py +9 -0
- webscout/Extra/autocoder/autocoder_utiles.py +121 -0
- webscout/Extra/autocoder/rawdog.py +681 -0
- webscout/Extra/autollama.py +246 -195
- webscout/Extra/gguf.py +441 -226
- webscout/Extra/weather.py +172 -67
- webscout/LLM.py +442 -100
- webscout/Litlogger/__init__.py +681 -0
- webscout/Local/formats.py +4 -2
- webscout/Provider/Amigo.py +19 -10
- webscout/Provider/Andi.py +0 -33
- webscout/Provider/Blackboxai.py +4 -204
- webscout/Provider/DARKAI.py +1 -1
- webscout/Provider/EDITEE.py +1 -1
- webscout/Provider/Llama3.py +1 -1
- webscout/Provider/Marcus.py +137 -0
- webscout/Provider/NinjaChat.py +1 -1
- webscout/Provider/PI.py +221 -207
- webscout/Provider/Perplexity.py +598 -598
- webscout/Provider/RoboCoders.py +206 -0
- webscout/Provider/TTI/AiForce/__init__.py +22 -0
- webscout/Provider/TTI/AiForce/async_aiforce.py +257 -0
- webscout/Provider/TTI/AiForce/sync_aiforce.py +242 -0
- webscout/Provider/TTI/Nexra/__init__.py +22 -0
- webscout/Provider/TTI/Nexra/async_nexra.py +286 -0
- webscout/Provider/TTI/Nexra/sync_nexra.py +258 -0
- webscout/Provider/TTI/PollinationsAI/__init__.py +23 -0
- webscout/Provider/TTI/PollinationsAI/async_pollinations.py +330 -0
- webscout/Provider/TTI/PollinationsAI/sync_pollinations.py +285 -0
- webscout/Provider/TTI/__init__.py +3 -4
- webscout/Provider/TTI/artbit/__init__.py +22 -0
- webscout/Provider/TTI/artbit/async_artbit.py +184 -0
- webscout/Provider/TTI/artbit/sync_artbit.py +176 -0
- webscout/Provider/TTI/blackbox/__init__.py +4 -0
- webscout/Provider/TTI/blackbox/async_blackbox.py +212 -0
- webscout/Provider/TTI/{blackboximage.py → blackbox/sync_blackbox.py} +199 -153
- webscout/Provider/TTI/deepinfra/__init__.py +4 -0
- webscout/Provider/TTI/deepinfra/async_deepinfra.py +227 -0
- webscout/Provider/TTI/deepinfra/sync_deepinfra.py +199 -0
- webscout/Provider/TTI/huggingface/__init__.py +22 -0
- webscout/Provider/TTI/huggingface/async_huggingface.py +199 -0
- webscout/Provider/TTI/huggingface/sync_huggingface.py +195 -0
- webscout/Provider/TTI/imgninza/__init__.py +4 -0
- webscout/Provider/TTI/imgninza/async_ninza.py +214 -0
- webscout/Provider/TTI/{imgninza.py → imgninza/sync_ninza.py} +209 -136
- webscout/Provider/TTI/talkai/__init__.py +4 -0
- webscout/Provider/TTI/talkai/async_talkai.py +229 -0
- webscout/Provider/TTI/talkai/sync_talkai.py +207 -0
- webscout/Provider/__init__.py +146 -132
- webscout/Provider/askmyai.py +158 -0
- webscout/Provider/cerebras.py +227 -206
- webscout/Provider/geminiapi.py +208 -198
- webscout/Provider/llama3mitril.py +180 -0
- webscout/Provider/llmchat.py +203 -0
- webscout/Provider/mhystical.py +176 -0
- webscout/Provider/perplexitylabs.py +265 -0
- webscout/Provider/talkai.py +196 -0
- webscout/Provider/twitterclone.py +251 -244
- webscout/Provider/typegpt.py +359 -0
- webscout/__init__.py +28 -23
- webscout/__main__.py +5 -5
- webscout/cli.py +327 -347
- webscout/conversation.py +227 -0
- webscout/exceptions.py +161 -29
- webscout/litagent/__init__.py +172 -0
- webscout/litprinter/__init__.py +831 -0
- webscout/optimizers.py +270 -0
- webscout/prompt_manager.py +279 -0
- webscout/swiftcli/__init__.py +810 -0
- webscout/transcriber.py +479 -551
- webscout/update_checker.py +125 -0
- webscout/version.py +1 -1
- webscout-6.4.dist-info/LICENSE.md +211 -0
- {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/METADATA +34 -55
- webscout-6.4.dist-info/RECORD +154 -0
- webscout/Provider/TTI/AIuncensored.py +0 -103
- webscout/Provider/TTI/Nexra.py +0 -120
- webscout/Provider/TTI/PollinationsAI.py +0 -138
- webscout/Provider/TTI/WebSimAI.py +0 -142
- webscout/Provider/TTI/aiforce.py +0 -160
- webscout/Provider/TTI/artbit.py +0 -141
- webscout/Provider/TTI/deepinfra.py +0 -148
- webscout/Provider/TTI/huggingface.py +0 -155
- webscout/models.py +0 -23
- webscout-6.2b0.dist-info/LICENSE.md +0 -50
- webscout-6.2b0.dist-info/RECORD +0 -118
- /webscout/{g4f.py → gpt4free.py} +0 -0
- {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/WHEEL +0 -0
- {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/entry_points.txt +0 -0
- {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/top_level.txt +0 -0
webscout/optimizers.py
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"""Prompt optimization utilities."""
|
|
2
|
+
import platform
|
|
3
|
+
import subprocess
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
class Optimizers:
|
|
7
|
+
"""
|
|
8
|
+
>>> Optimizers.code("write a hello world")
|
|
9
|
+
Returns optimized prompt for code generation
|
|
10
|
+
|
|
11
|
+
>>> Optimizers.shell_command("list files")
|
|
12
|
+
Returns optimized prompt for shell commands
|
|
13
|
+
|
|
14
|
+
>>> Optimizers.search("best pizza places")
|
|
15
|
+
Returns optimized prompt for web search
|
|
16
|
+
|
|
17
|
+
>>> Optimizers.math("solve quadratic equation")
|
|
18
|
+
Returns optimized prompt for math problems
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
@staticmethod
|
|
22
|
+
def code(prompt):
|
|
23
|
+
"""Deprecated: Use coder() instead"""
|
|
24
|
+
return Optimizers.coder(prompt)
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def shell_command(prompt):
|
|
28
|
+
"""Deprecated: Use coder() instead"""
|
|
29
|
+
return Optimizers.coder(f"!{prompt}")
|
|
30
|
+
|
|
31
|
+
@staticmethod
|
|
32
|
+
def coder(prompt):
|
|
33
|
+
"""Unified optimizer for both code and shell commands."""
|
|
34
|
+
# Get system info for shell commands
|
|
35
|
+
operating_system = ""
|
|
36
|
+
if platform.system() == "Windows":
|
|
37
|
+
operating_system = "Windows"
|
|
38
|
+
elif platform.system() == "Darwin":
|
|
39
|
+
operating_system = "MacOS"
|
|
40
|
+
elif platform.system() == "Linux":
|
|
41
|
+
try:
|
|
42
|
+
result = subprocess.check_output(["lsb_release", "-si"]).decode().strip()
|
|
43
|
+
operating_system = f"Linux/{result}" if result else "Linux"
|
|
44
|
+
except:
|
|
45
|
+
operating_system = "Linux"
|
|
46
|
+
else:
|
|
47
|
+
operating_system = platform.system()
|
|
48
|
+
|
|
49
|
+
# Get shell info
|
|
50
|
+
shell_name = "/bin/sh"
|
|
51
|
+
if platform.system() == "Windows":
|
|
52
|
+
shell_name = "powershell.exe" if os.getenv("PSModulePath") else "cmd.exe"
|
|
53
|
+
else:
|
|
54
|
+
shell_env = os.getenv("SHELL")
|
|
55
|
+
if shell_env:
|
|
56
|
+
shell_name = shell_env
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
"Your Role: You are a code generation expert. Analyze the request and provide appropriate output.\n"
|
|
60
|
+
"If the request starts with '!' or involves system/shell operations, provide a shell command.\n"
|
|
61
|
+
"Otherwise, provide Python code.\n\n"
|
|
62
|
+
"RULES:\n"
|
|
63
|
+
"1. Provide ONLY code/command output without any description or markdown\n"
|
|
64
|
+
"2. For shell commands:\n"
|
|
65
|
+
f" - Target OS: {operating_system}\n"
|
|
66
|
+
f" - Shell: {shell_name}\n"
|
|
67
|
+
" - Combine multiple steps when possible\n"
|
|
68
|
+
"3. For Python code:\n"
|
|
69
|
+
" - Include necessary imports\n"
|
|
70
|
+
" - Handle errors appropriately\n"
|
|
71
|
+
" - Follow PEP 8 style\n"
|
|
72
|
+
"4. If details are missing, use most logical implementation\n"
|
|
73
|
+
"5. No warnings, descriptions, or explanations\n\n"
|
|
74
|
+
f"Request: {prompt}\n"
|
|
75
|
+
"Output:\n"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
@staticmethod
|
|
79
|
+
def search(prompt):
|
|
80
|
+
"""Optimize prompt for web search queries."""
|
|
81
|
+
return (
|
|
82
|
+
"Your role: Generate a precise and focused web search query.\n"
|
|
83
|
+
"IMPORTANT: Return only the search query without any explanation.\n"
|
|
84
|
+
"Format: Plain text, no markdown.\n"
|
|
85
|
+
"If details are missing, focus on the most relevant aspects.\n\n"
|
|
86
|
+
f"Request: {prompt}\n"
|
|
87
|
+
"Search Query:"
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
def math(prompt):
|
|
92
|
+
"""Optimize prompt for mathematical problem solving."""
|
|
93
|
+
return (
|
|
94
|
+
"Your role: Solve mathematical problems step by step.\n"
|
|
95
|
+
"Format: Plain text, show calculations clearly.\n"
|
|
96
|
+
"Show all steps and intermediate results.\n"
|
|
97
|
+
"Include units where applicable.\n"
|
|
98
|
+
"Provide final answer in a clear format.\n\n"
|
|
99
|
+
f"Problem: {prompt}\n"
|
|
100
|
+
"Solution:"
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
@staticmethod
|
|
104
|
+
def explain(prompt):
|
|
105
|
+
"""Optimize prompt for clear explanations."""
|
|
106
|
+
return (
|
|
107
|
+
"Your role: Explain concepts clearly and concisely.\n"
|
|
108
|
+
"Format: Break down complex ideas into simple terms.\n"
|
|
109
|
+
"Use analogies where helpful.\n"
|
|
110
|
+
"Focus on key points and practical understanding.\n\n"
|
|
111
|
+
f"Topic: {prompt}\n"
|
|
112
|
+
"Explanation:"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
@staticmethod
|
|
116
|
+
def debug(prompt):
|
|
117
|
+
"""Optimize prompt for debugging code."""
|
|
118
|
+
return (
|
|
119
|
+
"Your role: Debug code and identify issues.\n"
|
|
120
|
+
"Steps:\n"
|
|
121
|
+
"1. Identify syntax errors\n"
|
|
122
|
+
"2. Check logic issues\n"
|
|
123
|
+
"3. Look for common pitfalls\n"
|
|
124
|
+
"4. Suggest fixes\n\n"
|
|
125
|
+
f"Code to debug: {prompt}\n"
|
|
126
|
+
"Analysis:"
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
@staticmethod
|
|
130
|
+
def api(prompt):
|
|
131
|
+
"""Optimize prompt for API endpoint design."""
|
|
132
|
+
return (
|
|
133
|
+
"Your role: Design RESTful API endpoints.\n"
|
|
134
|
+
"Include:\n"
|
|
135
|
+
"- HTTP methods\n"
|
|
136
|
+
"- URL structure\n"
|
|
137
|
+
"- Request/Response format\n"
|
|
138
|
+
"- Status codes\n\n"
|
|
139
|
+
f"API requirement: {prompt}\n"
|
|
140
|
+
"Design:"
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
@staticmethod
|
|
144
|
+
def sql(prompt):
|
|
145
|
+
"""Optimize prompt for SQL query generation."""
|
|
146
|
+
return (
|
|
147
|
+
"Your role: Generate optimized SQL queries.\n"
|
|
148
|
+
"Requirements:\n"
|
|
149
|
+
"- Standard SQL syntax\n"
|
|
150
|
+
"- Efficient query structure\n"
|
|
151
|
+
"- Proper joins and indexing\n"
|
|
152
|
+
"- Consider performance\n\n"
|
|
153
|
+
f"Query need: {prompt}\n"
|
|
154
|
+
"SQL:"
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
@staticmethod
|
|
158
|
+
def regex(prompt):
|
|
159
|
+
"""Optimize prompt for regex pattern generation."""
|
|
160
|
+
return (
|
|
161
|
+
"Your role: Generate precise regex patterns.\n"
|
|
162
|
+
"Requirements:\n"
|
|
163
|
+
"- Standard regex syntax\n"
|
|
164
|
+
"- Pattern explanation\n"
|
|
165
|
+
"- Test cases\n"
|
|
166
|
+
"- Consider edge cases\n\n"
|
|
167
|
+
f"Pattern need: {prompt}\n"
|
|
168
|
+
"Regex:"
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
@staticmethod
|
|
172
|
+
def test(prompt):
|
|
173
|
+
"""Optimize prompt for test case generation."""
|
|
174
|
+
return (
|
|
175
|
+
"Your role: Generate comprehensive test cases.\n"
|
|
176
|
+
"Include:\n"
|
|
177
|
+
"- Edge cases\n"
|
|
178
|
+
"- Corner cases\n"
|
|
179
|
+
"- Error scenarios\n"
|
|
180
|
+
"- Happy path\n"
|
|
181
|
+
"Format: Test name and expected result\n\n"
|
|
182
|
+
f"Test requirement: {prompt}\n"
|
|
183
|
+
"Test Cases:"
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
@staticmethod
|
|
187
|
+
def docker(prompt):
|
|
188
|
+
"""Optimize prompt for Dockerfile creation."""
|
|
189
|
+
return (
|
|
190
|
+
"Your role: Create efficient Dockerfile.\n"
|
|
191
|
+
"Consider:\n"
|
|
192
|
+
"- Base image selection\n"
|
|
193
|
+
"- Layer optimization\n"
|
|
194
|
+
"- Security best practices\n"
|
|
195
|
+
"- Multi-stage builds if needed\n\n"
|
|
196
|
+
f"Container requirement: {prompt}\n"
|
|
197
|
+
"Dockerfile:"
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
@staticmethod
|
|
201
|
+
def git(prompt):
|
|
202
|
+
"""Optimize prompt for git commands."""
|
|
203
|
+
return (
|
|
204
|
+
"Your role: Generate git commands.\n"
|
|
205
|
+
"Requirements:\n"
|
|
206
|
+
"- Clear and safe commands\n"
|
|
207
|
+
"- Consider current state\n"
|
|
208
|
+
"- Include safety checks\n"
|
|
209
|
+
"- Best practices\n\n"
|
|
210
|
+
f"Git task: {prompt}\n"
|
|
211
|
+
"Command:"
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
@staticmethod
|
|
215
|
+
def yaml(prompt):
|
|
216
|
+
"""Optimize prompt for YAML configuration."""
|
|
217
|
+
return (
|
|
218
|
+
"Your role: Generate YAML configuration.\n"
|
|
219
|
+
"Requirements:\n"
|
|
220
|
+
"- Valid YAML syntax\n"
|
|
221
|
+
"- Clear structure\n"
|
|
222
|
+
"- Comments for complex parts\n"
|
|
223
|
+
"- Best practices\n\n"
|
|
224
|
+
f"Config need: {prompt}\n"
|
|
225
|
+
"YAML:"
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
@staticmethod
|
|
229
|
+
def cli(prompt):
|
|
230
|
+
"""Optimize prompt for CLI command design."""
|
|
231
|
+
return (
|
|
232
|
+
"Your role: Design CLI commands.\n"
|
|
233
|
+
"Include:\n"
|
|
234
|
+
"- Command structure\n"
|
|
235
|
+
"- Arguments/options\n"
|
|
236
|
+
"- Help messages\n"
|
|
237
|
+
"- Examples\n\n"
|
|
238
|
+
f"CLI requirement: {prompt}\n"
|
|
239
|
+
"Design:"
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
@staticmethod
|
|
243
|
+
def refactor(prompt):
|
|
244
|
+
"""Optimize prompt for code refactoring suggestions."""
|
|
245
|
+
return (
|
|
246
|
+
"Your role: Suggest code improvements.\n"
|
|
247
|
+
"Focus on:\n"
|
|
248
|
+
"- Code quality\n"
|
|
249
|
+
"- Performance\n"
|
|
250
|
+
"- Readability\n"
|
|
251
|
+
"- Best practices\n"
|
|
252
|
+
"- Design patterns\n\n"
|
|
253
|
+
f"Code to refactor: {prompt}\n"
|
|
254
|
+
"Suggestions:"
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
@staticmethod
|
|
258
|
+
def security(prompt):
|
|
259
|
+
"""Optimize prompt for security analysis."""
|
|
260
|
+
return (
|
|
261
|
+
"Your role: Security analysis and fixes.\n"
|
|
262
|
+
"Check for:\n"
|
|
263
|
+
"- Common vulnerabilities\n"
|
|
264
|
+
"- Security best practices\n"
|
|
265
|
+
"- Input validation\n"
|
|
266
|
+
"- Authentication/Authorization\n"
|
|
267
|
+
"- Data protection\n\n"
|
|
268
|
+
f"Code to analyze: {prompt}\n"
|
|
269
|
+
"Analysis:"
|
|
270
|
+
)
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""
|
|
2
|
+
HAI's Awesome Prompts! 🔥
|
|
3
|
+
The most fire prompts collection you'll ever see! 💯
|
|
4
|
+
Created by the legendary HAI squad! 👑
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import json
|
|
9
|
+
import logging
|
|
10
|
+
import requests
|
|
11
|
+
from typing import Optional, Dict, Union, List
|
|
12
|
+
from rich.console import Console
|
|
13
|
+
from rich.table import Table
|
|
14
|
+
from rich.panel import Panel
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
|
|
17
|
+
console = Console()
|
|
18
|
+
|
|
19
|
+
class AwesomePrompts:
|
|
20
|
+
"""The most awesome prompts manager you'll ever see fr fr! 🔥"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
repo_url: str = "https://raw.githubusercontent.com/OE-LUCIFER/prompts/main/prompt.json",
|
|
25
|
+
local_path: Optional[str] = None,
|
|
26
|
+
auto_update: bool = True
|
|
27
|
+
):
|
|
28
|
+
"""Initialize them Awesome Prompts with style! 💫
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
repo_url (str): URL to fetch prompts from
|
|
32
|
+
local_path (str, optional): Where to save them prompts locally
|
|
33
|
+
auto_update (bool): Auto update prompts on init. Defaults to True
|
|
34
|
+
"""
|
|
35
|
+
self.repo_url = repo_url
|
|
36
|
+
self.local_path = local_path or os.path.join(
|
|
37
|
+
os.path.expanduser("~"),
|
|
38
|
+
".webscout",
|
|
39
|
+
"awesome-prompts.json"
|
|
40
|
+
)
|
|
41
|
+
self._cache: Dict[Union[str, int], str] = {}
|
|
42
|
+
self._last_update: Optional[datetime] = None
|
|
43
|
+
|
|
44
|
+
# Create directory if it doesn't exist
|
|
45
|
+
os.makedirs(os.path.dirname(self.local_path), exist_ok=True)
|
|
46
|
+
|
|
47
|
+
# Load those prompts on init if auto_update is True
|
|
48
|
+
if auto_update:
|
|
49
|
+
self.update_prompts_from_online()
|
|
50
|
+
|
|
51
|
+
def _load_prompts(self) -> Dict[Union[str, int], str]:
|
|
52
|
+
"""Load prompts from the local file fr fr! 📂"""
|
|
53
|
+
try:
|
|
54
|
+
if os.path.exists(self.local_path):
|
|
55
|
+
with open(self.local_path, 'r', encoding='utf-8') as f:
|
|
56
|
+
return json.load(f)
|
|
57
|
+
return {}
|
|
58
|
+
except Exception as e:
|
|
59
|
+
console.print(f"[red]❌ Error loading prompts: {str(e)}[/red]")
|
|
60
|
+
return {}
|
|
61
|
+
|
|
62
|
+
def _save_prompts(self, prompts: Dict[Union[str, int], str]) -> None:
|
|
63
|
+
"""Save them prompts with style! 💾"""
|
|
64
|
+
try:
|
|
65
|
+
with open(self.local_path, 'w', encoding='utf-8') as f:
|
|
66
|
+
json.dump(prompts, f, indent=4, ensure_ascii=False)
|
|
67
|
+
self._cache = prompts
|
|
68
|
+
console.print("[green]✨ Prompts saved successfully![/green]")
|
|
69
|
+
except Exception as e:
|
|
70
|
+
console.print(f"[red]❌ Error saving prompts: {str(e)}[/red]")
|
|
71
|
+
|
|
72
|
+
def update_prompts_from_online(self, force: bool = False) -> bool:
|
|
73
|
+
"""Update prompts from the repo! 🚀
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
force (bool): Force update even if recently updated
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
bool: True if update successful
|
|
80
|
+
"""
|
|
81
|
+
try:
|
|
82
|
+
# Check if we need to update
|
|
83
|
+
if not force and self._last_update and \
|
|
84
|
+
(datetime.now() - self._last_update).total_seconds() < 3600:
|
|
85
|
+
console.print("[yellow]⚡ Prompts are already up to date![/yellow]")
|
|
86
|
+
return True
|
|
87
|
+
|
|
88
|
+
console.print("[cyan]🔄 Updating prompts...[/cyan]")
|
|
89
|
+
response = requests.get(self.repo_url, timeout=10)
|
|
90
|
+
response.raise_for_status()
|
|
91
|
+
|
|
92
|
+
# Merge new prompts with existing ones
|
|
93
|
+
new_prompts = response.json()
|
|
94
|
+
existing_prompts = self._load_prompts()
|
|
95
|
+
merged_prompts = {**existing_prompts, **new_prompts}
|
|
96
|
+
|
|
97
|
+
# Create a new dictionary for numeric indices
|
|
98
|
+
indexed_prompts = merged_prompts.copy()
|
|
99
|
+
|
|
100
|
+
# Add indices for numeric access
|
|
101
|
+
for i, (key, value) in enumerate(list(merged_prompts.items())):
|
|
102
|
+
if isinstance(key, str):
|
|
103
|
+
indexed_prompts[i] = value
|
|
104
|
+
|
|
105
|
+
self._save_prompts(indexed_prompts)
|
|
106
|
+
self._last_update = datetime.now()
|
|
107
|
+
|
|
108
|
+
console.print("[green]✨ Prompts updated successfully![/green]")
|
|
109
|
+
return True
|
|
110
|
+
|
|
111
|
+
except Exception as e:
|
|
112
|
+
console.print(f"[red]❌ Error updating prompts: {str(e)}[/red]")
|
|
113
|
+
return False
|
|
114
|
+
|
|
115
|
+
def get_act(
|
|
116
|
+
self,
|
|
117
|
+
key: Union[str, int],
|
|
118
|
+
default: Optional[str] = None,
|
|
119
|
+
case_insensitive: bool = True
|
|
120
|
+
) -> Optional[str]:
|
|
121
|
+
"""Get that perfect prompt! 🎯
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
key: Prompt name or index
|
|
125
|
+
default: Default value if not found
|
|
126
|
+
case_insensitive: Match case exactly?
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
str: The prompt or default value
|
|
130
|
+
"""
|
|
131
|
+
prompts = self._cache or self._load_prompts()
|
|
132
|
+
|
|
133
|
+
# Try direct access first
|
|
134
|
+
if key in prompts:
|
|
135
|
+
return prompts[key]
|
|
136
|
+
|
|
137
|
+
# Try case-insensitive search for string keys
|
|
138
|
+
if isinstance(key, str) and case_insensitive:
|
|
139
|
+
key_lower = key.lower()
|
|
140
|
+
for k, v in prompts.items():
|
|
141
|
+
if isinstance(k, str) and k.lower() == key_lower:
|
|
142
|
+
return v
|
|
143
|
+
|
|
144
|
+
return default
|
|
145
|
+
|
|
146
|
+
def add_prompt(self, name: str, prompt: str) -> bool:
|
|
147
|
+
"""Add a new prompt to the collection! ✨
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
name: Name of the prompt
|
|
151
|
+
prompt: The prompt text
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
bool: Success status
|
|
155
|
+
"""
|
|
156
|
+
if not name or not prompt:
|
|
157
|
+
console.print("[red]❌ Name and prompt cannot be empty![/red]")
|
|
158
|
+
return False
|
|
159
|
+
|
|
160
|
+
prompts = self._cache or self._load_prompts()
|
|
161
|
+
prompts[name] = prompt
|
|
162
|
+
self._save_prompts(prompts)
|
|
163
|
+
return True
|
|
164
|
+
|
|
165
|
+
def delete_prompt(
|
|
166
|
+
self,
|
|
167
|
+
name: Union[str, int],
|
|
168
|
+
case_insensitive: bool = True,
|
|
169
|
+
raise_not_found: bool = False
|
|
170
|
+
) -> bool:
|
|
171
|
+
"""Delete a prompt from the collection! 🗑️
|
|
172
|
+
|
|
173
|
+
Args:
|
|
174
|
+
name: Name or index of prompt to delete
|
|
175
|
+
case_insensitive: Match case exactly?
|
|
176
|
+
raise_not_found: Raise error if prompt not found?
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
bool: Success status
|
|
180
|
+
"""
|
|
181
|
+
prompts = self._cache or self._load_prompts()
|
|
182
|
+
|
|
183
|
+
# Handle direct key match
|
|
184
|
+
if name in prompts:
|
|
185
|
+
del prompts[name]
|
|
186
|
+
self._save_prompts(prompts)
|
|
187
|
+
return True
|
|
188
|
+
|
|
189
|
+
# Handle case-insensitive match
|
|
190
|
+
if isinstance(name, str) and case_insensitive:
|
|
191
|
+
name_lower = name.lower()
|
|
192
|
+
for k in list(prompts.keys()):
|
|
193
|
+
if isinstance(k, str) and k.lower() == name_lower:
|
|
194
|
+
del prompts[k]
|
|
195
|
+
self._save_prompts(prompts)
|
|
196
|
+
return True
|
|
197
|
+
|
|
198
|
+
if raise_not_found:
|
|
199
|
+
raise KeyError(f"Prompt '{name}' not found!")
|
|
200
|
+
console.print(f"[yellow]⚠️ Prompt '{name}' not found![/yellow]")
|
|
201
|
+
return False
|
|
202
|
+
|
|
203
|
+
@property
|
|
204
|
+
def all_acts(self) -> Dict[Union[str, int], str]:
|
|
205
|
+
"""All them awesome prompts mapped with style! 📚
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
dict: All prompts with their indices
|
|
209
|
+
"""
|
|
210
|
+
prompts = self._cache or self._load_prompts()
|
|
211
|
+
if not prompts:
|
|
212
|
+
self.update_prompts_from_online()
|
|
213
|
+
prompts = self._load_prompts()
|
|
214
|
+
|
|
215
|
+
# Create a new dictionary for the result
|
|
216
|
+
result = prompts.copy()
|
|
217
|
+
|
|
218
|
+
# Add numeric indices to the copy
|
|
219
|
+
for i, (key, value) in enumerate(list(prompts.items())):
|
|
220
|
+
if isinstance(key, str):
|
|
221
|
+
result[i] = value
|
|
222
|
+
|
|
223
|
+
return result
|
|
224
|
+
|
|
225
|
+
def show_acts(self, search: Optional[str] = None) -> None:
|
|
226
|
+
"""Show all them awesome prompts with style! 📋
|
|
227
|
+
|
|
228
|
+
Args:
|
|
229
|
+
search: Optional search term to filter prompts
|
|
230
|
+
"""
|
|
231
|
+
prompts = self.all_acts
|
|
232
|
+
|
|
233
|
+
# Create a fire table! 🔥
|
|
234
|
+
table = Table(
|
|
235
|
+
title="🚀 Awesome Prompts Collection",
|
|
236
|
+
show_header=True,
|
|
237
|
+
header_style="bold magenta"
|
|
238
|
+
)
|
|
239
|
+
table.add_column("Index", style="cyan", justify="right")
|
|
240
|
+
table.add_column("Name", style="green")
|
|
241
|
+
table.add_column("Preview", style="yellow")
|
|
242
|
+
|
|
243
|
+
for i, (key, value) in enumerate(prompts.items()):
|
|
244
|
+
if isinstance(key, int):
|
|
245
|
+
continue # Skip numeric keys as they're duplicates
|
|
246
|
+
|
|
247
|
+
# Filter by search term if provided
|
|
248
|
+
if search and search.lower() not in key.lower() and \
|
|
249
|
+
search.lower() not in value.lower():
|
|
250
|
+
continue
|
|
251
|
+
|
|
252
|
+
preview = value[:50] + "..." if len(value) > 50 else value
|
|
253
|
+
table.add_row(str(i), str(key), preview)
|
|
254
|
+
|
|
255
|
+
console.print(table)
|
|
256
|
+
|
|
257
|
+
def get_random_act(self) -> Optional[str]:
|
|
258
|
+
"""Get a random prompt for that surprise factor! 🎲"""
|
|
259
|
+
import random
|
|
260
|
+
prompts = self.all_acts
|
|
261
|
+
string_keys = [k for k in prompts.keys() if isinstance(k, str)]
|
|
262
|
+
if not string_keys:
|
|
263
|
+
return None
|
|
264
|
+
return prompts[random.choice(string_keys)]
|
|
265
|
+
|
|
266
|
+
if __name__ == "__main__":
|
|
267
|
+
# Quick demo of the features! 🚀
|
|
268
|
+
prompts = AwesomePrompts()
|
|
269
|
+
prompts.update_prompts_from_online()
|
|
270
|
+
prompts.show_acts()
|
|
271
|
+
|
|
272
|
+
# Add a test prompt
|
|
273
|
+
prompts.add_prompt("test_prompt", "This is a test prompt! 🔥")
|
|
274
|
+
|
|
275
|
+
# Show the new prompt
|
|
276
|
+
print("\nTest Prompt:", prompts.get_act("test_prompt"))
|
|
277
|
+
|
|
278
|
+
# Clean up
|
|
279
|
+
prompts.delete_prompt("test_prompt")
|