Wasimibnkamal commited on
Commit
e3f19d3
·
verified ·
1 Parent(s): 02be0d4

i have add this file to validate invalid or stupid prompts

Browse files
cua2-core/src/cua2_core/services/agent_utils/prompt_validator.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import Model
2
+
3
+ def validate_prompt(prompt: str, model: Model) -> tuple[bool, str]:
4
+ """
5
+ Validate if a prompt is conceptually possible to solve on a computer.
6
+ Returns a tuple (is_valid: bool, reason: str).
7
+ """
8
+ messages = [
9
+ {
10
+ "role": "system",
11
+ "content": (
12
+ "You are a validation assistant for a computer-use AI. Determine if the user's task is "
13
+ "conceptually solvable using a computer (e.g., navigating web pages, using standard applications). "
14
+ "Tasks like 'order pizza on Amazon', 'download a physical car', or 'make me a coffee' are unsolvable. "
15
+ "If it is solvable, reply with 'VALID'. If it is unsolvable, reply with 'INVALID: <reason>'."
16
+ )
17
+ },
18
+ {"role": "user", "content": prompt}
19
+ ]
20
+
21
+ response = model(messages).content
22
+ if response.startswith("INVALID:"):
23
+ return False, response[8:].strip()
24
+ return True, ""