-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_server.py
More file actions
78 lines (64 loc) · 2.55 KB
/
test_server.py
File metadata and controls
78 lines (64 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
from bond import BondAgent
from bond.server import create_bond_server, ServerConfig
from bond.tools import BondToolDeps, github_toolset
# Check for API keys
if "OPENAI_API_KEY" not in os.environ:
print("WARNING: OPENAI_API_KEY not found in environment variables.")
print("The server may fail to generate responses.")
if "GITHUB_TOKEN" not in os.environ:
print("WARNING: GITHUB_TOKEN not found in environment variables.")
print("GitHub tools will not work without a token.")
print("Set it with: export GITHUB_TOKEN=ghp_...")
def list_files(directory: str = ".") -> str:
"""List files in the given directory."""
try:
files = os.listdir(directory)
return "\n".join(files)
except Exception as e:
return f"Error: {e}"
# Create composite deps for GitHub tools
deps = BondToolDeps(github_token=os.environ.get("GITHUB_TOKEN"))
agent = BondAgent(
name="test-assistant",
instructions="""You are a helpful assistant with access to GitHub.
You can:
- Browse any GitHub repository (list files, read files, get repo info)
- Search code in repositories
- View commits and pull requests
- List local files using the list_files tool
When asked about GitHub repositories, use the github tools to fetch real data.
IMPORTANT: If a tool returns a rate limit error, do NOT retry. Just explain to the user that you hit the rate limit and they should try again later.""",
model="openai:gpt-4o-mini",
toolsets=[[list_files], github_toolset],
deps=deps,
max_retries=1, # Reduce retries to prevent rate limit loops
)
# Configure server with explicit CORS origins
# Include multiple Vite ports since it auto-increments when ports are busy
config = ServerConfig(
cors_origins=[
"http://localhost:5173",
"http://localhost:5174",
"http://localhost:5175",
"http://localhost:5176",
"http://localhost:5177",
"http://localhost:5178",
"http://localhost:5179",
"http://127.0.0.1:5173",
"http://127.0.0.1:5174",
"http://127.0.0.1:5175",
"http://127.0.0.1:5176",
"http://127.0.0.1:5177",
"http://127.0.0.1:5178",
"http://127.0.0.1:5179",
"http://localhost:8000",
]
)
app = create_bond_server(agent, config=config)
if __name__ == "__main__":
import uvicorn
print("Starting Bond Test Server on http://0.0.0.0:8000")
print(f"GitHub Token: {'configured' if os.environ.get('GITHUB_TOKEN') else 'NOT SET'}")
print(f"Allowed Origins: {config.cors_origins}")
uvicorn.run(app, host="0.0.0.0", port=8000)