ddas commited on
Commit
e965542
Β·
unverified Β·
1 Parent(s): 40187f3

new trace dataset

Browse files
Files changed (2) hide show
  1. agent.py +28 -2
  2. app.py +2 -2
agent.py CHANGED
@@ -766,9 +766,27 @@ def create_tool_result_message(tool_results, provider):
766
  }
767
 
768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769
  def push_trace_to_explorer(trace_messages, annotations=None, user_info="", evaluation_results=None, model_name=""):
770
  """
771
  Push the complete conversation trace to Invariant Labs Explorer using Push API
 
 
 
 
772
  """
773
  try:
774
  if not INVARIANT_SDK_AVAILABLE:
@@ -783,6 +801,14 @@ def push_trace_to_explorer(trace_messages, annotations=None, user_info="", evalu
783
  # Initialize Invariant client
784
  client = InvariantClient(api_key=invariant_api_key)
785
 
 
 
 
 
 
 
 
 
786
  # Prepare metadata
787
  metadata = {"pushed_at": datetime.now().isoformat()}
788
  if user_info and user_info.strip():
@@ -806,12 +832,12 @@ def push_trace_to_explorer(trace_messages, annotations=None, user_info="", evalu
806
  response = client.create_request_and_push_trace(
807
  messages=[trace_messages], # List of traces, each trace is a list of messages
808
  annotations=[annotations] if annotations else None,
809
- dataset="instruction-challenge",
810
  metadata=[metadata]
811
  )
812
 
813
  print(f"πŸ“Š Trace successfully pushed to Invariant Labs Explorer")
814
- print(f" Dataset: instruction-challenge")
815
  print(f" Messages: {len(trace_messages)}")
816
  print(f" Trace ID: {response.id[0] if response.id else 'unknown'}")
817
  if model_name and model_name.strip():
 
766
  }
767
 
768
 
769
+ def is_running_on_spaces():
770
+ """
771
+ Detect if the code is running on Hugging Face Spaces.
772
+
773
+ Returns:
774
+ bool: True if running on Spaces, False if running locally
775
+
776
+ Note:
777
+ Set IS_SPACE=True as an environment variable in your HF Space configuration.
778
+ This variable won't exist in local environments.
779
+ """
780
+ return os.getenv("IS_SPACE", "").lower() == "true"
781
+
782
+
783
  def push_trace_to_explorer(trace_messages, annotations=None, user_info="", evaluation_results=None, model_name=""):
784
  """
785
  Push the complete conversation trace to Invariant Labs Explorer using Push API
786
+
787
+ Note:
788
+ For HF Spaces deployment, set IS_SPACE=True in your Space's environment variables
789
+ to automatically use the public dataset URL.
790
  """
791
  try:
792
  if not INVARIANT_SDK_AVAILABLE:
 
801
  # Initialize Invariant client
802
  client = InvariantClient(api_key=invariant_api_key)
803
 
804
+ # Determine dataset based on environment
805
+ if is_running_on_spaces():
806
+ dataset_name = "public-instruction-challenge"
807
+ environment = "Hugging Face Spaces"
808
+ else:
809
+ dataset_name = "instruction-challenge"
810
+ environment = "Local Development"
811
+
812
  # Prepare metadata
813
  metadata = {"pushed_at": datetime.now().isoformat()}
814
  if user_info and user_info.strip():
 
832
  response = client.create_request_and_push_trace(
833
  messages=[trace_messages], # List of traces, each trace is a list of messages
834
  annotations=[annotations] if annotations else None,
835
+ dataset=dataset_name,
836
  metadata=[metadata]
837
  )
838
 
839
  print(f"πŸ“Š Trace successfully pushed to Invariant Labs Explorer")
840
+ print(f" Dataset: {dataset_name}")
841
  print(f" Messages: {len(trace_messages)}")
842
  print(f" Trace ID: {response.id[0] if response.id else 'unknown'}")
843
  if model_name and model_name.strip():
app.py CHANGED
@@ -689,7 +689,7 @@ Now the practical bits:
689
  -Light bites vs. full meal
690
 
691
  Can't wait to see you there!
692
- β€” Emmaa""")
693
  ]
694
 
695
  # Working inbox (gets modified during attacks, can be reset)
@@ -1518,7 +1518,7 @@ You achieve Attacker Goal 2 and user goal is also achieved and no information ab
1518
  # Optional user identification field
1519
  user_info = gr.Textbox(
1520
  label="",
1521
- placeholder="If you want us to know your email address/name in the exploit trace that we collect, feel free to enter it here (optional)",
1522
  max_length=200,
1523
  show_label=False,
1524
  elem_id="user-info-field",
 
689
  -Light bites vs. full meal
690
 
691
  Can't wait to see you there!
692
+ β€” Emma""")
693
  ]
694
 
695
  # Working inbox (gets modified during attacks, can be reset)
 
1518
  # Optional user identification field
1519
  user_info = gr.Textbox(
1520
  label="",
1521
+ placeholder="We are running this challenge as part of a research project. If you want us to know your name/email in the exploit trace that we collect, feel free to enter it here (optional)",
1522
  max_length=200,
1523
  show_label=False,
1524
  elem_id="user-info-field",