-
-
Notifications
You must be signed in to change notification settings - Fork 688
Add AI Court Simulation Python Script #691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add AI Court Simulation Python Script #691
Conversation
WalkthroughThree new Python scripts have been added, each implementing a distinct AI-powered tool: a bilingual Chilean government services assistant leveraging translation and the Firecrawl API, a multi-agent mini court simulation with role-based responses, and a cybersecurity proof-of-concept agent for validating CVE exploit samples. Each script defines new classes and functions specific to its use case. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Assistant (Tomás)
participant Translator
participant Firecrawl API
User->>Assistant (Tomás): Enter query (English)
Assistant (Tomás)->>Translator: Translate to Spanish
Translator-->>Assistant (Tomás): Query (Spanish)
Assistant (Tomás)->>Firecrawl API: Search Chilean gov services (Spanish)
Firecrawl API-->>Assistant (Tomás): Results (Spanish)
Assistant (Tomás)->>Translator: Translate results to English
Translator-->>Assistant (Tomás): Results (English)
Assistant (Tomás)-->>User: Display answer (English)
sequenceDiagram
participant User
participant Judge
participant Prosecutor
participant Defense
participant Witness
User->>Judge: Provide case details
Judge-->>User: Opening statement
Prosecutor-->>User: Opening statement
Defense-->>User: Opening statement
Witness-->>User: Testimony
Judge-->>User: Final verdict
sequenceDiagram
participant User
participant Pocky Agent
participant AttackIntentAgent
participant ValidationAgent
User->>Pocky Agent: Provide CVE ID
Pocky Agent->>AttackIntentAgent: Extract attack intent from CVE description
AttackIntentAgent-->>Pocky Agent: Attack intent summary
Pocky Agent->>ValidationAgent: Validate PoC against attack intent
ValidationAgent-->>Pocky Agent: Validation result
Pocky Agent-->>User: Display PoC validity and reasoning
Suggested labels
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @Dhivya-Bharathy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly expands the examples/python/tools/exa-tool
directory by adding three distinct AI agent-based Python scripts. These new examples showcase diverse applications, ranging from a simulated legal courtroom with multi-agent interactions to a government services chatbot and a cybersecurity tool for validating Proof-of-Concept exploits.
Highlights
- New AI Agent Examples: This pull request introduces three new Python scripts demonstrating various applications of AI agents within the
examples/python/tools/exa-tool
directory. - LegaliaAI Mini Court Script: A new script (
legaliaai_minicourt.py
) has been added that simulates a mini courtroom using AI agents (Judge, Prosecutor, Defense, Witness) powered by GPT-4o-mini for legal reasoning and case simulation. - Chile Government Services Assistant: A new chatbot script (
chile_government_services_assistant_.py
) is included, designed to answer questions about Chilean government services. It leverages the Firecrawl API for information retrieval and Google Translator for English-Spanish language support. - Pocky Cybersecurity PoC Agent: A new script (
pocky_cybersecurity_poc_agent.py
) for a 'Pocky Query Tool' has been added. This tool aims to automate CVE Proof-of-Concept (PoC) search and validation, helping to find, filter, and fetch real-world exploits.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request adds three new Python scripts that simulate different AI-driven tools. The scripts include hardcoded API keys, which should be addressed for security reasons.
|
||
import os | ||
|
||
os.environ['FIRECRAWL_API_KEY'] = "your api key here" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more secure method for storing API keys, such as a dedicated secrets management solution, especially if this code is intended for production use. Hardcoding API keys directly in the code is not recommended.
os.environ['FIRECRAWL_API_KEY'] = "your api key here" | |
# Load API keys from a .env file or a secure vault | |
# For example, using python-dotenv: | |
# from dotenv import load_dotenv | |
# load_dotenv() | |
# FIRECRAWL_API_KEY = os.getenv("FIRECRAWL_API_KEY") | |
os.environ['FIRECRAWL_API_KEY'] = "your api key here" |
import os | ||
|
||
os.environ['FIRECRAWL_API_KEY'] = "your api key here" | ||
os.environ['OPENAI_API_KEY'] = "your api key here" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more secure method for storing API keys, such as a dedicated secrets management solution, especially if this code is intended for production use. Hardcoding API keys directly in the code is not recommended.
os.environ['OPENAI_API_KEY'] = "your api key here" | |
# Load API keys from a .env file or a secure vault | |
# For example, using python-dotenv: | |
# from dotenv import load_dotenv | |
# load_dotenv() | |
# OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") | |
os.environ['OPENAI_API_KEY'] = "your api key here" |
if not api_key: | ||
print("🔑 Enter your OpenAI API key:") | ||
api_key = input("API Key: ").strip() | ||
os.environ['OPENAI_API_KEY'] = "Enter your api key" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more secure method for storing API keys, such as a dedicated secrets management solution, especially if this code is intended for production use. Hardcoding API keys directly in the code is not recommended.
os.environ['OPENAI_API_KEY'] = "Enter your api key" | |
# Load API keys from a .env file or a secure vault | |
# For example, using python-dotenv: | |
# from dotenv import load_dotenv | |
# load_dotenv() | |
# OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") | |
os.environ['OPENAI_API_KEY'] = "Enter your api key" |
import os | ||
|
||
# Set your API keys here (replace with your actual keys) | ||
os.environ["EXA_API_KEY"] = "your api key" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more secure method for storing API keys, such as a dedicated secrets management solution, especially if this code is intended for production use. Hardcoding API keys directly in the code is not recommended.
# Load API keys from a .env file or a secure vault
# For example, using python-dotenv:
# from dotenv import load_dotenv
# load_dotenv()
# EXA_API_KEY = os.getenv("EXA_API_KEY")
os.environ["EXA_API_KEY"] = "your api key"
|
||
# Set your API keys here (replace with your actual keys) | ||
os.environ["EXA_API_KEY"] = "your api key" | ||
os.environ["OPENAI_API_KEY"] = "your api key" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more secure method for storing API keys, such as a dedicated secrets management solution, especially if this code is intended for production use. Hardcoding API keys directly in the code is not recommended.
# Load API keys from a .env file or a secure vault
# For example, using python-dotenv:
# from dotenv import load_dotenv
# load_dotenv()
# OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
os.environ["OPENAI_API_KEY"] = "your api key"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Nitpick comments (8)
examples/python/tools/exa-tool/legaliaai_minicourt.py (3)
40-40
: Move imports to the top of the file.Module-level imports should be at the top of the file according to PEP 8.
+from praisonaiagents import Agent + import os from dotenv import load_dotenv from IPython.display import display, HTML import time - -# Setup API key -api_key = os.getenv('OPENAI_API_KEY') -if not api_key: - print("🔑 Enter your OpenAI API key:") - api_key = input("API Key: ").strip() - os.environ['OPENAI_API_KEY'] = api_key - -print("✅ Setup complete!") - -# """## Create Mini Agents""" - -from praisonaiagents import Agent
110-110
: Add proper spacing between functions.Functions should have two blank lines before them according to PEP 8.
print(f"🔍 Evidence: {evidence}") + """# Helper Functions (Fixed with .start())## Cell 4: Case Details Input""" + # Display function def show_message(name, role, message, color="#4CAF50"):display(HTML(html)) + # Run agent using .start() def run_agent(agent, prompt, name, role, color="#4CAF50"):
Also applies to: 126-126
141-141
: Remove unnecessary f-string prefixes.These f-strings don't contain any placeholders and should be regular strings.
-display(HTML(f"<h2>📅 Day 1: Opening Statements</h2>")) +display(HTML("<h2>📅 Day 1: Opening Statements</h2>"))-display(HTML(f"<h2>📅 Day 2: Witness Testimony</h2>")) +display(HTML("<h2>📅 Day 2: Witness Testimony</h2>"))-display(HTML(f"<h2>📅 Day 3: Final Verdict</h2>")) +display(HTML("<h2>📅 Day 3: Final Verdict</h2>"))Also applies to: 173-173, 187-187
examples/python/tools/exa-tool/chile_government_services_assistant_.py (3)
29-31
: Move imports to the top of the file.Module-level imports should be at the top according to PEP 8.
import os +from firecrawl import FirecrawlApp, ScrapeOptions +from deep_translator import GoogleTranslator +import re os.environ['FIRECRAWL_API_KEY'] = "your api key here" os.environ['OPENAI_API_KEY'] = "your api key here" -# """# Import Libraries & Translator""" - -from firecrawl import FirecrawlApp, ScrapeOptions -from deep_translator import GoogleTranslator -import re
77-89
: Simplify unnecessary else clause.The else clause after return is unnecessary and can be removed.
if filtered_results: for num, result in enumerate(filtered_results, start=1): response_md += self.template.format( result_number=num, page_title=str(result.get("title", "")), page_url=str(result.get("url", "")), page_content=str(result.get("markdown", "")) ) return response_md - else: - return None + return None
33-38
: Add proper spacing between functions.Functions should have two blank lines before them according to PEP 8.
import re + def translate_to_spanish(text): try: return GoogleTranslator(source='auto', target='es').translate(text) except Exception as e: print("Translation to Spanish failed:", e) return text + def translate_to_english(text):Also applies to: 40-48
examples/python/tools/exa-tool/pocky_cybersecurity_poc_agent.py (2)
42-48
: Enhance dummy agent classes for better demonstration.The current dummy classes are too simplistic and don't demonstrate the actual validation logic described in the prompt.
Consider implementing more realistic placeholder logic:
class ValidationAgent: def __init__(self, input_json): self.input_json = input_json + def run(self): - # Dummy validation logic for notebook demo - data = json.loads(self.input_json) - return True if "attack_intent" in data and "poc_sample" in data else False + """Dummy validation logic for demo purposes.""" + try: + data = json.loads(self.input_json) + # More realistic validation checks + has_intent = "attack_intent" in data and data["attack_intent"] + has_poc = "poc_sample" in data and data["poc_sample"] + return {"valid": has_intent and has_poc, "reasoning": "Basic structure validation"} + except json.JSONDecodeError: + return {"valid": False, "reasoning": "Invalid JSON input"} class AttackIntentAgent: def __init__(self, description): self.description = description + def run(self): - # Dummy intent extraction for notebook demo - return f"Intent for: {self.description[:50]}..." + """Dummy intent extraction for demo purposes.""" + if not self.description: + return "No description provided" + return f"Extracted attack intent from: {self.description[:50]}..."Also applies to: 50-55
80-96
: Improve error handling and output formatting.The function lacks proper error handling and could benefit from clearer output formatting.
def run_pocky_for_cve(cve_id): - # Example: Simulate fetching a description and PoC (replace with real logic) - description = f"Description for {cve_id} (replace with real Exa/OpenAI search)" - poc_sample = f"PoC code for {cve_id} (replace with real PoC search)" + """Simulate CVE PoC validation workflow.""" + if not cve_id: + print("Error: CVE ID is required") + return + + print(f"🔍 Processing {cve_id}...") + + # Simulate fetching data (replace with real logic) + description = f"Description for {cve_id} (replace with real Exa/OpenAI search)" + poc_sample = f"PoC code for {cve_id} (replace with real PoC search)" + + print(f"📋 CVE Description: {description}") + print(f"🔬 PoC Sample: {poc_sample}") # Stage 2: Attack Intent intent = AttackIntentAgent(description).run() - print(f"Attack Intent: {intent}") + print(f"🎯 Attack Intent: {intent}") # Stage 3: Validation validation_input = json.dumps({"attack_intent": intent, "poc_sample": poc_sample}, indent=2) - valid = ValidationAgent(validation_input).run() - print(f"Validation Result: {valid}") - if valid: - print(f"PoC for {cve_id} is valid and ready to use.") + validation_result = ValidationAgent(validation_input).run() + print(f"✅ Validation Result: {validation_result}") + + if isinstance(validation_result, dict) and validation_result.get("valid"): + print(f"✅ PoC for {cve_id} is valid and ready to use.") else: - print(f"PoC for {cve_id} failed validation.") + print(f"❌ PoC for {cve_id} failed validation.")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
examples/python/tools/exa-tool/chile_government_services_assistant_.py
(1 hunks)examples/python/tools/exa-tool/legaliaai_minicourt.py
(1 hunks)examples/python/tools/exa-tool/pocky_cybersecurity_poc_agent.py
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
examples/python/tools/exa-tool/legaliaai_minicourt.py
141-141: f-string without any placeholders
Remove extraneous f
prefix
(F541)
173-173: f-string without any placeholders
Remove extraneous f
prefix
(F541)
187-187: f-string without any placeholders
Remove extraneous f
prefix
(F541)
examples/python/tools/exa-tool/pocky_cybersecurity_poc_agent.py
24-24: SyntaxError: Expected a statement
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
examples/python/tools/exa-tool/chile_government_services_assistant_.py
114-114: Undefined name FIRECRAWL_INSTRUCTION
(F821)
115-115: Undefined name FIRECRAWL_TEMPLATE
(F821)
🪛 Flake8 (7.2.0)
examples/python/tools/exa-tool/legaliaai_minicourt.py
[error] 40-40: module level import not at top of file
(E402)
[error] 110-110: expected 2 blank lines, found 1
(E302)
[error] 126-126: expected 2 blank lines, found 1
(E302)
[error] 135-135: expected 2 blank lines after class or function definition, found 1
(E305)
[error] 141-141: f-string is missing placeholders
(F541)
[error] 173-173: f-string is missing placeholders
(F541)
[error] 187-187: f-string is missing placeholders
(F541)
examples/python/tools/exa-tool/pocky_cybersecurity_poc_agent.py
[error] 24-24: SyntaxError: invalid syntax
(E999)
examples/python/tools/exa-tool/chile_government_services_assistant_.py
[error] 29-29: module level import not at top of file
(E402)
[error] 30-30: module level import not at top of file
(E402)
[error] 31-31: module level import not at top of file
(E402)
[error] 33-33: expected 2 blank lines, found 1
(E302)
[error] 40-40: expected 2 blank lines, found 1
(E302)
[error] 52-52: expected 2 blank lines, found 1
(E302)
[error] 112-112: expected 2 blank lines after class or function definition, found 1
(E305)
[error] 114-114: undefined name 'FIRECRAWL_INSTRUCTION'
(F821)
[error] 115-115: undefined name 'FIRECRAWL_TEMPLATE'
(F821)
🪛 Pylint (3.3.7)
examples/python/tools/exa-tool/pocky_cybersecurity_poc_agent.py
[error] 24-24: Parsing failed: 'invalid syntax (pocky_cybersecurity_poc_agent, line 24)'
(E0001)
examples/python/tools/exa-tool/chile_government_services_assistant_.py
[refactor] 77-87: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it
(R1705)
[refactor] 52-52: Too few public methods (1/2)
(R0903)
[error] 114-114: Undefined variable 'FIRECRAWL_INSTRUCTION'
(E0602)
[error] 115-115: Undefined variable 'FIRECRAWL_TEMPLATE'
(E0602)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test-core (3.11)
- GitHub Check: quick-test
🔇 Additional comments (1)
examples/python/tools/exa-tool/legaliaai_minicourt.py (1)
18-18
: Consider environment compatibility.The script uses Jupyter/Colab-specific features that may not work in standard Python environments.
Consider adding environment detection to handle both Jupyter and standard Python execution:
try: from IPython.display import display, HTML JUPYTER_ENV = True except ImportError: JUPYTER_ENV = False def display(content): if hasattr(content, 'data'): print(content.data) else: print(content) class HTML: def __init__(self, data): self.data = dataAlso applies to: 24-25
if not api_key: | ||
print("🔑 Enter your OpenAI API key:") | ||
api_key = input("API Key: ").strip() | ||
os.environ['OPENAI_API_KEY'] = "Enter your api key" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security issue: Hardcoded API key placeholder.
The line sets a placeholder string instead of the actual API key from user input, which will cause authentication failures.
- os.environ['OPENAI_API_KEY'] = "Enter your api key"
+ os.environ['OPENAI_API_KEY'] = api_key
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
os.environ['OPENAI_API_KEY'] = "Enter your api key" | |
os.environ['OPENAI_API_KEY'] = api_key |
🤖 Prompt for AI Agents
In examples/python/tools/exa-tool/legaliaai_minicourt.py at line 34, the code
hardcodes a placeholder string for the OPENAI_API_KEY environment variable,
which will cause authentication failures. Replace the hardcoded string with code
that securely retrieves the actual API key from user input or a secure source
such as environment variables or a configuration file, ensuring the key is not
exposed in the code.
os.environ['FIRECRAWL_API_KEY'] = "your api key here" | ||
os.environ['OPENAI_API_KEY'] = "your api key here" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security issue: Hardcoded API key placeholders.
Using placeholder strings for API keys will cause authentication failures and potential security risks if accidentally committed.
Consider using environment variables or secure input methods:
-os.environ['FIRECRAWL_API_KEY'] = "your api key here"
-os.environ['OPENAI_API_KEY'] = "your api key here"
+# Load from environment or prompt user
+if not os.getenv('FIRECRAWL_API_KEY'):
+ os.environ['FIRECRAWL_API_KEY'] = input("Enter your Firecrawl API key: ").strip()
+if not os.getenv('OPENAI_API_KEY'):
+ os.environ['OPENAI_API_KEY'] = input("Enter your OpenAI API key: ").strip()
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
os.environ['FIRECRAWL_API_KEY'] = "your api key here" | |
os.environ['OPENAI_API_KEY'] = "your api key here" | |
# Load from environment or prompt user | |
if not os.getenv('FIRECRAWL_API_KEY'): | |
os.environ['FIRECRAWL_API_KEY'] = input("Enter your Firecrawl API key: ").strip() | |
if not os.getenv('OPENAI_API_KEY'): | |
os.environ['OPENAI_API_KEY'] = input("Enter your OpenAI API key: ").strip() |
🤖 Prompt for AI Agents
In examples/python/tools/exa-tool/chile_government_services_assistant_.py at
lines 24 to 25, the API keys are hardcoded as placeholder strings, which can
cause authentication failures and security risks. Remove the hardcoded strings
and instead load the API keys from environment variables or secure input
methods, such as using os.getenv to retrieve the keys at runtime without
embedding them in the code.
# FIRECRAWL_INSTRUCTION = "ChileAtiende: " | ||
# FIRECRAWL_TEMPLATE = """ | ||
# # Result {result_number} | ||
|
||
# ## Page Name: | ||
# "{page_title}" | ||
|
||
# ## URL: | ||
# {page_url} | ||
|
||
# ## Content: | ||
# {page_content} | ||
|
||
# """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Commented-out template definitions cause undefined variable errors.
The template variables are commented out but referenced in active code, which will cause runtime errors.
-# FIRECRAWL_INSTRUCTION = "ChileAtiende: "
-# FIRECRAWL_TEMPLATE = """
-# # Result {result_number}
-
-# ## Page Name:
-# "{page_title}"
-
-# ## URL:
-# {page_url}
-
-# ## Content:
-# {page_content}
-
-# """
+FIRECRAWL_INSTRUCTION = "ChileAtiende: "
+FIRECRAWL_TEMPLATE = """
+# Result {result_number}
+
+## Page Name:
+"{page_title}"
+
+## URL:
+{page_url}
+
+## Content:
+{page_content}
+
+"""
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
# FIRECRAWL_INSTRUCTION = "ChileAtiende: " | |
# FIRECRAWL_TEMPLATE = """ | |
# # Result {result_number} | |
# ## Page Name: | |
# "{page_title}" | |
# ## URL: | |
# {page_url} | |
# ## Content: | |
# {page_content} | |
# """ | |
FIRECRAWL_INSTRUCTION = "ChileAtiende: " | |
FIRECRAWL_TEMPLATE = """ | |
# Result {result_number} | |
## Page Name: | |
"{page_title}" | |
## URL: | |
{page_url} | |
## Content: | |
{page_content} | |
""" |
🤖 Prompt for AI Agents
In examples/python/tools/exa-tool/chile_government_services_assistant_.py
between lines 95 and 108, the template variables FIRECRAWL_INSTRUCTION and
FIRECRAWL_TEMPLATE are commented out but still referenced in the code, causing
undefined variable errors. Uncomment these variable definitions to ensure they
are properly defined and accessible where used in the code.
os.environ["EXA_API_KEY"] = "your api key" | ||
os.environ["OPENAI_API_KEY"] = "your api key" | ||
os.environ["OPENAI_BASE_URL"] = "https://api.openai.com/v1" # Optional, for custom OpenAI endpoints |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security issue: Hardcoded API key placeholders.
Using placeholder strings for API keys creates security risks and will cause authentication failures.
-os.environ["EXA_API_KEY"] = "your api key"
-os.environ["OPENAI_API_KEY"] = "your api key"
-os.environ["OPENAI_BASE_URL"] = "https://api.openai.com/v1" # Optional, for custom OpenAI endpoints
+# Load API keys from environment or prompt user
+if not os.getenv("EXA_API_KEY"):
+ os.environ["EXA_API_KEY"] = input("Enter your Exa API key: ").strip()
+if not os.getenv("OPENAI_API_KEY"):
+ os.environ["OPENAI_API_KEY"] = input("Enter your OpenAI API key: ").strip()
+
+# Optional: Set custom OpenAI endpoint
+if not os.getenv("OPENAI_BASE_URL"):
+ os.environ["OPENAI_BASE_URL"] = "https://api.openai.com/v1"
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
os.environ["EXA_API_KEY"] = "your api key" | |
os.environ["OPENAI_API_KEY"] = "your api key" | |
os.environ["OPENAI_BASE_URL"] = "https://api.openai.com/v1" # Optional, for custom OpenAI endpoints | |
# Load API keys from environment or prompt user | |
if not os.getenv("EXA_API_KEY"): | |
os.environ["EXA_API_KEY"] = input("Enter your Exa API key: ").strip() | |
if not os.getenv("OPENAI_API_KEY"): | |
os.environ["OPENAI_API_KEY"] = input("Enter your OpenAI API key: ").strip() | |
# Optional: Set custom OpenAI endpoint | |
if not os.getenv("OPENAI_BASE_URL"): | |
os.environ["OPENAI_BASE_URL"] = "https://api.openai.com/v1" |
🤖 Prompt for AI Agents
In examples/python/tools/exa-tool/pocky_cybersecurity_poc_agent.py around lines
31 to 33, the API keys are hardcoded as placeholder strings, which is insecure
and will cause authentication failures. Remove the hardcoded keys and instead
load these values securely from environment variables or a secure secrets
manager, ensuring the keys are not exposed in the codebase.
# Install Dependencies | ||
""" | ||
|
||
!pip install praisonaiagents exa-py python-dotenv requests beautifulsoup4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical syntax error: pip install command in Python code.
The pip install command is written as Python code, which causes a syntax error and prevents the script from running.
This appears to be a Jupyter/Colab notebook command that needs to be properly formatted:
-!pip install praisonaiagents exa-py python-dotenv requests beautifulsoup4
+# For Jupyter/Colab environments:
+# !pip install praisonaiagents exa-py python-dotenv requests beautifulsoup4
+
+# For standard Python environments, install dependencies via:
+# pip install praisonaiagents exa-py python-dotenv requests beautifulsoup4
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
!pip install praisonaiagents exa-py python-dotenv requests beautifulsoup4 | |
# For Jupyter/Colab environments: | |
# !pip install praisonaiagents exa-py python-dotenv requests beautifulsoup4 | |
# For standard Python environments, install dependencies via: | |
# pip install praisonaiagents exa-py python-dotenv requests beautifulsoup4 |
🧰 Tools
🪛 Ruff (0.11.9)
24-24: SyntaxError: Expected a statement
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
24-24: SyntaxError: Simple statements must be separated by newlines or semicolons
🪛 Flake8 (7.2.0)
[error] 24-24: SyntaxError: invalid syntax
(E999)
🪛 Pylint (3.3.7)
[error] 24-24: Parsing failed: 'invalid syntax (pocky_cybersecurity_poc_agent, line 24)'
(E0001)
🤖 Prompt for AI Agents
In examples/python/tools/exa-tool/pocky_cybersecurity_poc_agent.py at line 24,
the pip install command is incorrectly written as Python code, causing a syntax
error. Remove this line from the Python script or, if this is intended for a
Jupyter/Colab notebook, prefix the command with an exclamation mark (!) to run
it as a shell command. This will prevent syntax errors and allow the script to
run properly.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #691 +/- ##
=======================================
Coverage 14.50% 14.50%
=======================================
Files 25 25
Lines 2517 2517
Branches 357 357
=======================================
Hits 365 365
Misses 2136 2136
Partials 16 16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This Python script simulates a mini courtroom using AI agents with GPT-4o-mini. It includes judge, prosecutor, defense, and witness roles that respond to case prompts. Perfect for showcasing multi-agent legal reasoning in a lightweight, scriptable format.
Summary by CodeRabbit