Skip to content

Commit

Permalink
switch --prompts to --raw makes more sense
Browse files Browse the repository at this point in the history
  • Loading branch information
p3nGu1nZz committed Sep 12, 2024
1 parent d0de134 commit 2195728
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion oproof/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self):
self.parser.add_argument(Const.ARG_PROMPT_TEXT, type=str, help=Const.ARG_PROMPT_TEXT_HELP)
self.parser.add_argument(Const.ARG_RESPONSE_TEXT, type=str, help=Const.ARG_RESPONSE_TEXT_HELP)
self.parser.add_argument(Const.ARG_DEBUG, action="store_true", help=Const.ARG_DEBUG_HELP)
self.parser.add_argument(Const.ARG_PROMPTS, action="store_true", help=Const.ARG_PROMPTS_HELP)
self.parser.add_argument(Const.ARG_RAW, action="store_true", help=Const.ARG_RAW_HELP)
self.args = None

def parse(self):
Expand Down
4 changes: 2 additions & 2 deletions oproof/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Const:
ARG_TEXT_HELP = "Input text"
ARG_DEBUG = "--debug"
ARG_DEBUG_HELP = "Enable debug logging"
ARG_PROMPTS = "--prompts"
ARG_PROMPTS_HELP = "Include prompts in the output JSON"
ARG_RAW = "--raw"
ARG_RAW_HELP = "Include raw response in the output JSON"
ARG_DESCRIPTION = "Oproof script"
ARG_PROMPT_TEXT = "prompt"
ARG_PROMPT_TEXT_HELP = "Input prompt"
Expand Down
6 changes: 3 additions & 3 deletions oproof/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def run(parsed_args):
Log.setup(parsed_args.debug)
if parsed_args.debug:
Log.start_main_function()
main._execute(parsed_args.prompt, parsed_args.response, parsed_args.debug, parsed_args.prompts)
main._execute(parsed_args.prompt, parsed_args.response, parsed_args.debug, parsed_args.raw)
except Exception as e:
handle_error(e, parsed_args.debug)

def _execute(self, prompt: str, response: str, debug: bool, include_prompts: bool) -> None:
def _execute(self, prompt: str, response: str, debug: bool, include_raw: bool) -> None:
try:
self.manager.check_version()
validation_result = self.manager.validate_response(prompt, response)
final_result = Serializer.serialize_output(prompt, [validation_result], include_prompts)
final_result = Serializer.serialize_output(prompt, [validation_result], include_raw)
json_output = json.dumps(final_result, indent=2, separators=(',', ': '))
console.print(JSON(json_output))
except ValidationError as e:
Expand Down
2 changes: 1 addition & 1 deletion oproof/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_response_data(self) -> Dict[str, Any]:
"context": self.parsed_response.get("context", "unknown")
}

if self.parsed_response.get("reason") is not None:
if not self.parsed_response.get("is_valid", False) and self.parsed_response.get("reason") is not None:
response_data["reason"] = self.parsed_response.get("reason")

if self.output.get("raw_response") is not None:
Expand Down
10 changes: 5 additions & 5 deletions oproof/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

class Serializer:
@staticmethod
def serialize_output(text: str, responses: List[Dict[str, Any]], include_prompts: bool) -> Dict[str, Any]:
def serialize_output(text: str, responses: List[Dict[str, Any]], include_raw: bool) -> Dict[str, Any]:
result = {
"original_text": text,
"responses": [
Serializer._serialize_response(response, include_prompts)
Serializer._serialize_response(response, include_raw)
for response in responses
]
}
return result

@staticmethod
def _serialize_response(response: Dict[str, Any], include_prompts: bool) -> Dict[str, Any]:
def _serialize_response(response: Dict[str, Any], include_raw: bool) -> Dict[str, Any]:
serialized_response = {
"prompt": response.get("prompt", ""),
"response": response.get("response", ""),
Expand All @@ -22,10 +22,10 @@ def _serialize_response(response: Dict[str, Any], include_prompts: bool) -> Dict
"context": response.get("context", "unknown")
}

if response.get("reason") is not None:
if not response.get("is_valid", False) and response.get("reason") is not None:
serialized_response["reason"] = response.get("reason")

if include_prompts and response.get("raw_response") is not None:
if include_raw and response.get("raw_response") is not None:
serialized_response["raw_response"] = response.get("raw_response")

return serialized_response

0 comments on commit 2195728

Please sign in to comment.