-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patharcr.py
More file actions
387 lines (368 loc) · 22.2 KB
/
arcr.py
File metadata and controls
387 lines (368 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
def main():
# Initialize state
state = {
'question_state': {
'current': 'action',
'answers': {
'action': '',
'role': '',
'context': '',
'response': '',
'keywords': [],
'expanded_actions': [],
'expanded_roles': [],
'expanded_contexts': [],
'expanded_responses': []
}
},
'prompt_history': [],
'session_log': []
}
# Suggested options
actions = [
'compose', 'evaluate', 'generate', 'simulate', 'analyze', 'recommend',
'design', 'summarize', 'explain', 'predict', 'translate', 'brainstorm',
'modify', 'study', 'build', 'create', 'transcribe', 'edit', 'enhance',
'debug', 'test', 'research'
]
roles = [
'educator', 'strategist', 'historian', 'ethicist', 'data scientist',
'creative writer', 'engineer', 'consultant', 'researcher', 'marketer',
'policy analyst', 'developer', 'artist', 'journalist', 'entrepreneur',
'therapist', 'futurist', 'cartoonist', 'doctor', 'scientist', 'mechanic',
'accountant', 'designer', 'mathematician'
]
response_types = [
'narrative', 'image', 'report', 'diagram', 'policy brief', 'code',
'list', 'summary', 'plan', 'visualization', 'article', 'email',
'meme', 'story', 'essay', 'resume', 'poem', 'infographic', 'chart',
'website', 'sketch', 'digital art', 'cartoon', 'painting', 'program'
]
visual_responses = ['image', 'cartoon', 'sketch', 'painting', 'chart']
context_examples = {
'educator': ['teaching a high school AI class', 'designing a STEM workshop'],
'strategist': ['planning a corporate expansion', 'devising a marketing campaign'],
'historian': ['analyzing 19th-century trade routes', 'researching ancient civilizations'],
'ethicist': ['evaluating AI bias implications', 'assessing corporate ethics policies'],
'data scientist': ['modeling customer churn', 'analyzing genomic data'],
'creative writer': ['crafting a fantasy novel', 'writing a screenplay'],
'engineer': ['optimizing a renewable energy system', 'designing a smart city infrastructure'],
'consultant': ['advising on digital transformation', 'assessing supply chain efficiency'],
'researcher': ['studying climate change impacts', 'investigating quantum computing'],
'marketer': ['launching a social media campaign', 'analyzing consumer trends'],
'policy analyst': ['drafting environmental regulations', 'evaluating healthcare policies'],
'developer': ['building a web application', 'debugging a machine learning pipeline'],
'artist': ['creating a mural for a community center', 'designing a digital art installation'],
'journalist': ['investigating local government policies', 'writing a feature on tech startups'],
'entrepreneur': ['pitching a sustainable startup idea', 'developing a business model'],
'therapist': ['counseling on stress management', 'designing a mental health workshop'],
'futurist': ['predicting trends in AI development', 'envisioning sustainable cities in 2050'],
'cartoonist': ['creating a comic strip for a magazine', 'designing characters for an animated series'],
'doctor': ['diagnosing a patient with chronic symptoms', 'developing a public health campaign']
}
stop_words = [
'a', 'an', 'and', 'are', 'as', 'at', 'be', 'by', 'for', 'from',
'has', 'he', 'in', 'is', 'it', 'its', 'of', 'on', 'that', 'the',
'to', 'was', 'were', 'will', 'with'
]
common_errors = {'vague': ['detail', 'details', 'detailed']}
def append_output(state, text, is_error=False):
prefix = "[ERROR] " if is_error else "[OUTPUT] "
print(prefix + text)
state['session_log'].append({'type': 'error' if is_error else 'output', 'text': text})
def show_help(state):
help_text = """
WebXOS ARCR: How It Works
The ARCR system guides you to create precise AI prompts in four steps: Action, Role, Context, and Response.
1. **Action**: Choose what the AI should do (e.g., compose, analyze, modify, study).
2. **Role**: Define the AI's perspective (e.g., educator, developer, cartoonist, doctor).
3. **Context**: Provide specific details or scenarios (e.g., "teaching a class"). Be specific to ensure clarity.
4. **Response**: Select the output type (e.g., narrative, code, sketch, digital art).
After building your prompt, you can edit it to refine components or expand it by adding more actions, roles, contexts, or responses. Prompts are displayed in the console for copying. Type 'help' to see this guide, 'clear' to reset, or 'exit' to quit.
"""
append_output(state, help_text)
def update_progress(state):
steps = ['Action', 'Role', 'Context', 'Response']
current_index = ['action', 'role', 'context', 'response'].index(state['question_state']['current']) if state['question_state']['current'] in ['action', 'role', 'context', 'response'] else -1
if current_index >= 0:
return f"Step {current_index + 1}/4: {steps[current_index]}"
elif state['question_state']['current'] == 'edit_prompt':
return "Editing Prompt"
elif state['question_state']['current'] == 'expand_prompt':
return "Expanding Prompt"
elif state['question_state']['current'].startswith('expand_'):
component = state['question_state']['current'].replace('expand_', '')
return f"Expanding {component.capitalize()}"
return ""
def ask_question(state):
progress = update_progress(state)
if progress:
print(f"[PROGRESS] {progress}")
if state['question_state']['current'] == 'action':
append_output(state, f"Specify the action (e.g., compose: write content, analyze: examine data, generate: create new output): {', '.join(actions)}")
elif state['question_state']['current'] == 'role':
append_output(state, f"Define the role (e.g., educator: teaches, developer: codes, artist: creates visuals): {', '.join(roles)}")
elif state['question_state']['current'] == 'context':
role = state['question_state']['answers']['role'].lower()
examples = context_examples.get(role, ['in a specific scenario', 'with clear objectives'])
append_output(state, f"Describe the context in detail (examples: {', '.join(examples)}):")
elif state['question_state']['current'] == 'response':
append_output(state, f"Choose the response type (e.g., narrative: story, image: visual, code: program): {', '.join(response_types)}")
elif state['question_state']['current'] == 'expand_prompt':
append_output(state, "Do you want to expand your prompt? (yes, no)")
elif state['question_state']['current'] == 'expand_select':
append_output(state, "What do you want to expand? (action, role, context, response)")
elif state['question_state']['current'] == 'expand_action':
append_output(state, f"Specify the additional action: {', '.join(actions)}")
elif state['question_state']['current'] == 'expand_role':
append_output(state, f"Define the additional role: {', '.join(roles)}")
elif state['question_state']['current'] == 'expand_context':
role = state['question_state']['answers']['role'].lower()
examples = context_examples.get(role, ['in a specific scenario', 'with clear objectives'])
append_output(state, f"Describe the additional context (examples: {', '.join(examples)}):")
elif state['question_state']['current'] == 'expand_response':
append_output(state, f"Choose the additional response type: {', '.join(response_types)}")
def validate_answer(state, input_str):
normalized_input = input_str.strip().lower()
if not input_str.strip():
append_output(state, "Error: Input cannot be empty.", True)
return False
if state['question_state']['current'] == 'action' and normalized_input not in actions:
append_output(state, f"Error: Select from: {', '.join(actions)}", True)
return False
elif state['question_state']['current'] == 'role' and normalized_input not in roles:
append_output(state, f"Error: Select from: {', '.join(roles)}", True)
return False
elif state['question_state']['current'] == 'context' and len(input_str.strip()) < 10:
append_output(state, "Error: Context must be specific (10+ characters).", True)
return False
elif state['question_state']['current'] == 'response' and normalized_input not in response_types:
append_output(state, f"Error: Select from: {', '.join(response_types)}", True)
return False
elif state['question_state']['current'] == 'expand_prompt' and normalized_input not in ['yes', 'no']:
append_output(state, "Error: Please enter 'yes' or 'no'.", True)
return False
elif state['question_state']['current'] == 'expand_select' and normalized_input not in ['action', 'role', 'context', 'response']:
append_output(state, "Error: Select from: action, role, context, response", True)
return False
elif state['question_state']['current'] == 'expand_action' and normalized_input not in actions:
append_output(state, f"Error: Select from: {', '.join(actions)}", True)
return False
elif state['question_state']['current'] == 'expand_role' and normalized_input not in roles:
append_output(state, f"Error: Select from: {', '.join(roles)}", True)
return False
elif state['question_state']['current'] == 'expand_context' and len(input_str.strip()) < 10:
append_output(state, "Error: Additional context must be specific (10+ characters).", True)
return False
elif state['question_state']['current'] == 'expand_response' and normalized_input not in response_types:
append_output(state, f"Error: Select from: {', '.join(response_types)}", True)
return False
for term in common_errors['vague']:
if term in normalized_input:
append_output(state, "Error: Avoid vague terms (e.g., 'detail').", True)
return False
return True
def autocorrect_input(input_str):
corrected = input_str
corrected = corrected.replace('summary', 'summary', 1).replace('SUMMARY', 'summary', 1)
corrected = corrected.replace('explain', 'explain', 1).replace('EXPLAIN', 'explain', 1)
for term in common_errors['vague']:
corrected = corrected.replace(term, 'specific')
return corrected
def extract_keywords(input_str):
import re
words = re.split(r'[.,!?;:\'"\(\)\s]+', input_str.lower())
keywords = []
for word in words:
if word and word not in stop_words and len(word) > 2 and word not in keywords:
keywords.append(word)
return keywords
def generate_prompt(state):
answers = state['question_state']['answers']
prompt = (
f"The user has a request structured as Action > Role > Context > Response.\n"
f"As a {answers['role']}, perform the following task:\n"
f"- **Action**: {answers['action']}\n"
f"- **Context**: {answers['context']}\n"
f"- **Keywords for DeepSearch**: {', '.join(answers['keywords']) if answers['keywords'] else 'none'} (use these to pretrain on relevant web data before processing)\n"
f"- **Response**: Deliver a {answers['response']}\n"
)
if answers['response'].lower() in visual_responses:
prompt += (
f"\n**Visual Generation Instructions**: User requests visual generation. Use DeepSearch to gather relevant visual data and apply thinking logic to ensure high-quality output.\n"
)
has_expansions = (
len(answers['expanded_actions']) > 0 or
len(answers['expanded_roles']) > 0 or
len(answers['expanded_contexts']) > 0 or
len(answers['expanded_responses']) > 0
)
if has_expansions:
prompt += "\nExpanded Components:\n"
if answers['expanded_actions']:
prompt += f"- **Additional Actions**: {', '.join(answers['expanded_actions'])}\n"
if answers['expanded_roles']:
prompt += f"- **Additional Roles**: {', '.join(answers['expanded_roles'])}\n"
if answers['expanded_contexts']:
prompt += f"- **Additional Contexts**: {', '.join(answers['expanded_contexts'])}\n"
if answers['expanded_responses']:
prompt += f"- **Additional Responses**: {', '.join(answers['expanded_responses'])}\n"
prompt += "Generated by WebXOS ARCR 2025 (Copyright © 2025)."
return prompt
def update_history(state, prompt):
state['prompt_history'].insert(0, {'prompt': prompt})
if len(state['prompt_history']) > 5:
state['prompt_history'].pop()
append_output(state, "Prompt saved.")
state['session_log'].append({'type': 'output', 'text': 'Prompt saved.'})
def clear_console(state):
state['question_state'] = {
'current': 'action',
'answers': {
'action': '',
'role': '',
'context': '',
'response': '',
'keywords': [],
'expanded_actions': [],
'expanded_roles': [],
'expanded_contexts': [],
'expanded_responses': []
}
}
state['prompt_history'] = []
state['session_log'] = []
append_output(state, "Console and state cleared. Ready for a new prompt.")
ask_question(state)
def edit_prompt(state):
state['question_state']['current'] = 'edit_prompt'
while True:
prompt = generate_prompt(state)
append_output(state, f"Generated Prompt:\n\n---\n{prompt}\n---")
append_output(state, "Are you satisfied with this prompt? (yes/no)")
satisfied = input("> ").strip().lower()
if satisfied == 'yes':
update_history(state, prompt)
append_output(state, "Prompt finalized! (Note: Copy to clipboard not supported in this environment; please copy the prompt above.)")
break
elif satisfied == 'no':
append_output(state, "Which part do you want to edit? (action/role/context/response)")
part = input("> ").strip().lower()
if part in ['action', 'role', 'context', 'response']:
if part == 'context':
append_output(state, f"Enter new context (must be specific, 10+ characters):")
new_value = input("> ").strip()
if len(new_value) < 10:
append_output(state, "Error: Context must be at least 10 characters.", True)
continue
state['question_state']['answers']['context'] = new_value
state['question_state']['answers']['keywords'] = extract_keywords(new_value)
else:
valid_options = actions if part == 'action' else roles if part == 'role' else response_types
append_output(state, f"Enter new {part} (options: {', '.join(valid_options)}):")
new_value = input("> ").strip().lower()
if part == 'action' and new_value not in actions:
append_output(state, f"Error: Select from: {', '.join(actions)}", True)
continue
elif part == 'role' and new_value not in roles:
append_output(state, f"Error: Select from: {', '.join(roles)}", True)
continue
elif part == 'response' and new_value not in response_types:
append_output(state, f"Error: Select from: {', '.join(response_types)}", True)
continue
state['question_state']['answers'][part] = new_value
else:
append_output(state, "Invalid part selected.", True)
else:
append_output(state, "Invalid input. Please enter 'yes' or 'no'.", True)
state['question_state']['current'] = 'expand_prompt'
ask_question(state)
def handle_input(state):
print("[INFO] Welcome to WebXOS ARCR! Create precise AI prompts using the ARCR system (Action > Role > Context > Response). Enter each component to build a structured prompt.")
state['session_log'].append({'type': 'output', 'text': "Welcome to WebXOS ARCR! Create precise AI prompts using the ARCR system (Action > Role > Context > Response). Enter each component to build a structured prompt."})
ask_question(state)
while True:
try:
input_str = input("> ").strip()
if input_str.lower() == 'clear':
clear_console(state)
continue
elif input_str.lower() == 'help':
show_help(state)
ask_question(state)
continue
elif input_str.lower() == 'exit':
append_output(state, "Exiting ARCR.")
break
input_str = autocorrect_input(input_str)
if not validate_answer(state, input_str):
continue
append_output(state, f"> {input_str}")
state['session_log'].append({'type': 'input', 'text': input_str})
if state['question_state']['current'] == 'action':
state['question_state']['answers']['action'] = input_str
state['question_state']['current'] = 'role'
ask_question(state)
elif state['question_state']['current'] == 'role':
state['question_state']['answers']['role'] = input_str
state['question_state']['current'] = 'context'
ask_question(state)
elif state['question_state']['current'] == 'context':
state['question_state']['answers']['context'] = input_str
state['question_state']['answers']['keywords'] = extract_keywords(input_str)
state['question_state']['current'] = 'response'
ask_question(state)
elif state['question_state']['current'] == 'response':
state['question_state']['answers']['response'] = input_str
state['question_state']['current'] = 'edit_prompt'
edit_prompt(state)
elif state['question_state']['current'] == 'expand_prompt':
if input_str.lower() == 'yes':
state['question_state']['current'] = 'expand_select'
else:
append_output(state, "Prompt expansion skipped.")
break
ask_question(state)
elif state['question_state']['current'] == 'expand_select':
if input_str.lower() in ['action', 'role', 'context', 'response']:
state['question_state']['current'] = f"expand_{input_str.lower()}"
else:
append_output(state, "Error: Select from: action, role, context, response", True)
continue
ask_question(state)
elif state['question_state']['current'] == 'expand_action':
state['question_state']['answers']['expanded_actions'].append(input_str)
prompt = generate_prompt(state)
append_output(state, f"Updated Prompt:\n\n---\n{prompt}\n---")
update_history(state, prompt)
append_output(state, "Prompt updated! (Note: Copy to clipboard not supported in this environment; please copy the prompt above.)")
state['question_state']['current'] = 'expand_prompt'
ask_question(state)
elif state['question_state']['current'] == 'expand_role':
state['question_state']['answers']['expanded_roles'].append(input_str)
prompt = generate_prompt(state)
append_output(state, f"Updated Prompt:\n\n---\n{prompt}\n---")
update_history(state, prompt)
append_output(state, "Prompt updated! (Note: Copy to clipboard not supported in this environment; please copy the prompt above.)")
state['question_state']['current'] = 'expand_prompt'
ask_question(state)
elif state['question_state']['current'] == 'expand_context':
state['question_state']['answers']['expanded_contexts'].append(input_str)
prompt = generate_prompt(state)
append_output(state, f"Updated Prompt:\n\n---\n{prompt}\n---")
update_history(state, prompt)
append_output(state, "Prompt updated! (Note: Copy to clipboard not supported in this environment; please copy the prompt above.)")
state['question_state']['current'] = 'expand_prompt'
ask_question(state)
elif state['question_state']['current'] == 'expand_response':
state['question_state']['answers']['expanded_responses'].append(input_str)
prompt = generate_prompt(state)
append_output(state, f"Updated Prompt:\n\n---\n{prompt}\n---")
update_history(state, prompt)
append_output(state, "Prompt updated! (Note: Copy to clipboard not supported in this environment; please copy the prompt above.)")
state['question_state']['current'] = 'expand_prompt'
ask_question(state)
except Exception as e:
append_output(state, f"Error processing input: {str(e)}", True)
handle_input(state)
main()