Skip to content

Commit 7906311

Browse files
fix: update rigging example to use native robopages tool
1 parent ce67ef1 commit 7906311

File tree

2 files changed

+111
-156
lines changed

2 files changed

+111
-156
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: 10 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,23 @@
11
import asyncio
22
import os
33
from loguru import logger
4-
import requests
54
import rigging as rg
65
from rigging import logging
76
from rich import print
8-
from typing import Annotated
97

108
os.environ["LOGFIRE_IGNORE_NO_CONFIG"] = "1"
119
logging.configure_logging("DEBUG", None, "DEBUG")
1210

1311

14-
class RoboPagesTool(rg.Tool):
15-
"""Base class for RoboPages tools that are dynamically wrapped from the server"""
16-
17-
name = "robopages_tool"
18-
description = "A tool from the RoboPages server"
19-
20-
def __init__(self, tool_data):
21-
self.data = tool_data
22-
self.name = tool_data["name"]
23-
self.description = tool_data["description"]
24-
25-
for function in tool_data["functions"]:
26-
func_name = function["name"]
27-
params = function.get("parameters", [])
28-
29-
def make_func(f_name, f_params):
30-
param_list = []
31-
annotations = {"return": str}
32-
33-
for p in f_params:
34-
param_name = p["name"]
35-
param_desc = p.get("description", "")
36-
annotations[param_name] = Annotated[str, param_desc]
37-
param_list.append(param_name)
38-
39-
def dynamic_func(self, **kwargs):
40-
"""Dynamically created function"""
41-
filtered_kwargs = {
42-
k: v for k, v in kwargs.items() if k in param_list
43-
}
44-
return self._call_function(f_name, filtered_kwargs)
45-
46-
dynamic_func.__name__ = f_name
47-
dynamic_func.__annotations__ = annotations
48-
dynamic_func.__doc__ = function.get("description", "")
49-
50-
return dynamic_func
51-
52-
setattr(
53-
self,
54-
func_name,
55-
make_func(func_name, params).__get__(self, self.__class__),
56-
)
57-
58-
def _call_function(self, func_name: str, args: dict) -> str:
59-
"""Call the function on the RoboPages server"""
60-
print(f"Calling {self.name}.{func_name}({args})")
61-
62-
try:
63-
response = requests.post(
64-
"http://localhost:8000/process",
65-
json=[
66-
{
67-
"type": "function",
68-
"function": {
69-
"name": func_name,
70-
"arguments": args,
71-
},
72-
}
73-
],
74-
)
75-
76-
return response.json()[0]["content"]
77-
except Exception as e:
78-
print(f"Error calling function: {e}")
79-
return f"Error: {str(e)}"
80-
81-
82-
def create_tool_class(tool_data):
83-
"""Create a new Tool class dynamically for a specific tool from RoboPages"""
84-
tool_name = tool_data["name"]
85-
tool_desc = tool_data["description"]
86-
87-
class_name = f"{tool_name.replace(' ', '')}Tool"
88-
89-
new_class = type(
90-
class_name,
91-
(rg.Tool,),
92-
{
93-
"name": tool_name,
94-
"description": tool_desc,
95-
},
96-
)
97-
98-
for function in tool_data["functions"]:
99-
func_name = function["name"]
100-
params = function.get("parameters", [])
101-
102-
param_list = []
103-
annotations = {"return": str}
104-
105-
for p in params:
106-
param_name = p["name"]
107-
param_desc = p.get("description", "")
108-
annotations[param_name] = Annotated[str, param_desc]
109-
param_list.append(param_name)
110-
111-
def make_function(fn_name, fn_params):
112-
def dynamic_func(self, **kwargs):
113-
"""Dynamically created function"""
114-
filtered_kwargs = {k: v for k, v in kwargs.items() if k in fn_params}
115-
116-
# Call the RoboPages server
117-
try:
118-
response = requests.post(
119-
"http://localhost:8000/process",
120-
json=[
121-
{
122-
"type": "function",
123-
"function": {
124-
"name": fn_name,
125-
"arguments": filtered_kwargs,
126-
},
127-
}
128-
],
129-
)
130-
return response.json()[0]["content"]
131-
except Exception as e:
132-
print(f"Error calling function: {e}")
133-
return f"Error: {str(e)}"
134-
135-
dynamic_func.__name__ = fn_name
136-
dynamic_func.__annotations__ = annotations
137-
dynamic_func.__doc__ = function.get("description", "")
138-
139-
return dynamic_func
140-
141-
setattr(new_class, func_name, make_function(func_name, param_list))
142-
143-
return new_class
144-
145-
14612
async def run():
14713
"""Main function that runs the chat with RoboPages tools"""
14814

14915
try:
150-
# Fetch tools from the RoboPages server
151-
response = requests.get("http://localhost:8000/?flavor=rigging")
152-
tools_data = response.json()
153-
154-
logger.info(f"Fetched {len(tools_data)} tools from RoboPages server")
155-
for tool in tools_data:
156-
logger.info(f"Tool: {tool['name']} - {tool['description']}")
157-
for func in tool.get("functions", []):
158-
logger.info(f" Function: {func['name']}")
16+
logger.info("Fetching tools from RoboPages server")
17+
# Use the built-in robopages integration
18+
tools = rg.integrations.robopages("http://localhost:8000")
15919

160-
tools = []
161-
for tool_data in tools_data:
162-
tool_class = create_tool_class(tool_data)
163-
tools.append(tool_class())
164-
165-
logger.info(f"Created {len(tools)} tool instances")
20+
logger.info(f"Fetched {len(tools)} tools from RoboPages server")
16621

16722
prompt = """
16823
I need you to find all open ports on the local machine (127.0.0.1).
@@ -188,12 +43,17 @@ async def run():
18843
print("\n--- RESULT ---\n")
18944
print(chat.last.content)
19045

46+
return chat
47+
19148
except Exception as e:
19249
logger.error(f"Error: {e}")
19350
import traceback
19451

19552
traceback.print_exc()
53+
return None
19654

19755

19856
if __name__ == "__main__":
199-
asyncio.run(run())
57+
chat = asyncio.run(run())
58+
if chat:
59+
print(chat.conversation)

0 commit comments

Comments
 (0)