Skip to content

Commit 6cb3ebb

Browse files
Merge pull request #16 from dreadnode/ads/eng-1353-attributeerror-in-rigging_examplepy-regarding
fix: Ads/eng 1353 attributeerror in rigging examplepy regarding
2 parents 217d2a5 + 7906311 commit 6cb3ebb

File tree

2 files changed

+153
-84
lines changed

2 files changed

+153
-84
lines changed

.gitignore

Lines changed: 101 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,110 @@
1-
/target
1+
### Rust ###
2+
/target/
3+
**/*.rs.bk
4+
*.pdb
5+
Cargo.lock
6+
# Keep Cargo.lock for binary projects, uncomment this line if it's a library
7+
8+
### IDE and Editors ###
9+
# VSCode
10+
.vscode/*
11+
!.vscode/settings.json
12+
!.vscode/tasks.json
13+
!.vscode/launch.json
14+
!.vscode/extensions.json
15+
*.code-workspace
16+
17+
# JetBrains IDEs (IntelliJ, CLion, etc.)
18+
.idea/
19+
*.iml
20+
*.iws
21+
*.ipr
22+
out/
23+
.idea_modules/
24+
25+
# SublimeText
26+
*.sublime-workspace
27+
*.sublime-project
28+
29+
# Mac
230
.DS_Store
3-
.mypy_cache
4-
__pycache__
31+
.AppleDouble
32+
.LSOverride
33+
._*
34+
35+
# Windows
36+
Thumbs.db
37+
ehthumbs.db
38+
Desktop.ini
39+
40+
### Python ###
41+
# Byte-compiled / optimized / DLL files
42+
__pycache__/
43+
*.py[cod]
44+
*$py.class
45+
46+
# Distribution / packaging
47+
.Python
48+
build/
49+
develop-eggs/
50+
dist/
51+
downloads/
52+
eggs/
53+
.eggs/
54+
lib/
55+
lib64/
56+
parts/
57+
sdist/
58+
var/
59+
wheels/
60+
*.egg-info/
61+
.installed.cfg
62+
*.egg
63+
64+
# Virtual environments
65+
.env
66+
.venv
67+
env/
68+
venv/
69+
ENV/
70+
env.bak/
71+
venv.bak/
72+
.python-version
573

6-
/.venv
74+
# Jupyter Notebook
75+
.ipynb_checkpoints
76+
notebooks/
777

78+
# pytest
79+
.pytest_cache/
80+
.coverage
81+
htmlcov/
882

83+
### Project specific ###
984
# proxy stuff
1085
burp.cer
1186
burp.pem
1287
install_burp.py
1388

14-
# Local working files
15-
hans_test.py
89+
# Logs
90+
logs/
91+
*.log
92+
npm-debug.log*
93+
94+
# Dependencies
95+
node_modules/
96+
97+
# Local config
98+
.env.local
99+
.env.development.local
100+
.env.test.local
101+
.env.production.local
102+
103+
# Build artifacts
104+
/dist
105+
/build
106+
107+
# proxy stuff
108+
burp.cer
109+
burp.pem
110+
install_burp.py

examples/rigging_example.py

Lines changed: 52 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,59 @@
11
import asyncio
2-
import requests
2+
import os
3+
from loguru import logger
34
import rigging as rg
5+
from rigging import logging
46
from rich import print
57

8+
os.environ["LOGFIRE_IGNORE_NO_CONFIG"] = "1"
9+
logging.configure_logging("DEBUG", None, "DEBUG")
610

7-
# we need to wrap the tools in a class that Rigging can understand
8-
class Wrapper(rg.Tool):
9-
# we'll set these in the constructor
10-
name = "_"
11-
description = "_"
12-
13-
def __init__(self, tool: dict):
14-
self.tool = tool
15-
self.name = tool["name"]
16-
self.description = tool["description"]
17-
18-
# declare dynamically the functions by their name
19-
for function in tool["functions"]:
20-
setattr(
21-
Wrapper,
22-
function["name"],
23-
lambda self, *args, **kwargs: self._execute_function(
24-
function["name"], *args, **kwargs
25-
),
11+
12+
async def run():
13+
"""Main function that runs the chat with RoboPages tools"""
14+
15+
try:
16+
logger.info("Fetching tools from RoboPages server")
17+
# Use the built-in robopages integration
18+
tools = rg.integrations.robopages("http://localhost:8000")
19+
20+
logger.info(f"Fetched {len(tools)} tools from RoboPages server")
21+
22+
prompt = """
23+
I need you to find all open ports on the local machine (127.0.0.1).
24+
Please use the available tools to scan the ports and provide a summary of the results.
25+
26+
Be thorough but concise in your analysis. Present the information in a clear format.
27+
28+
After scanning, list all the open ports you found and what services might be running on them.
29+
"""
30+
31+
logger.info("Starting chat with model")
32+
generator = rg.get_generator("gpt-4o")
33+
34+
chat = await generator.chat(prompt).using(*tools, force=True).run()
35+
36+
logger.info("Chat completed. Full conversation:")
37+
for i, message in enumerate(chat.messages):
38+
logger.info(f"Message {i + 1} ({message.role}):")
39+
logger.info(
40+
message.content[:200] + ("..." if len(message.content) > 200 else "")
2641
)
2742

28-
def _execute_function(self, func_name: str, *args, **kwargs):
29-
print(f"executing {self.name}.{func_name}{kwargs} ...")
30-
# execute the call via robopages and return the result to Rigging
31-
return requests.post(
32-
"http://localhost:8000/process",
33-
json=[
34-
{
35-
"type": "function",
36-
"function": {
37-
"name": func_name,
38-
"arguments": kwargs,
39-
},
40-
}
41-
],
42-
).json()[0]["content"]
43-
44-
def get_description(self) -> rg.tool.ToolDescription:
45-
"""Creates a full description of the tool for use in prompting"""
46-
47-
return rg.tool.ToolDescription(
48-
name=self.name,
49-
description=self.description,
50-
functions=[
51-
rg.tool.ToolFunction(
52-
name=function["name"],
53-
description=function["description"],
54-
parameters=[
55-
rg.tool.ToolParameter(
56-
name=param["name"],
57-
type=param["type"],
58-
description=param["description"],
59-
)
60-
for param in function["parameters"]
61-
],
62-
)
63-
for function in self.tool["functions"]
64-
],
65-
)
66-
67-
68-
async def run(model: str):
69-
# get the tools from the Robopages server and wrap each function for Rigging
70-
tools = [
71-
Wrapper(tool)
72-
for tool in requests.get("http://localhost:8000/?flavor=rigging").json()
73-
]
74-
75-
chat = (
76-
await rg.get_generator(model)
77-
.chat("Find open ports on 127.0.0.1")
78-
.using(*tools, force=True)
79-
.run()
80-
)
81-
82-
print(chat.last.content)
83-
84-
85-
asyncio.run(run("gpt-4o"))
43+
print("\n--- RESULT ---\n")
44+
print(chat.last.content)
45+
46+
return chat
47+
48+
except Exception as e:
49+
logger.error(f"Error: {e}")
50+
import traceback
51+
52+
traceback.print_exc()
53+
return None
54+
55+
56+
if __name__ == "__main__":
57+
chat = asyncio.run(run())
58+
if chat:
59+
print(chat.conversation)

0 commit comments

Comments
 (0)