-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrun_server.py
More file actions
93 lines (83 loc) · 3.2 KB
/
run_server.py
File metadata and controls
93 lines (83 loc) · 3.2 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""Run ResearchHarness as a minimal OpenAI-compatible API server."""
from __future__ import annotations
import argparse
import sys
from agent_base.utils import MissingRequiredEnvError, load_default_dotenvs, require_required_env
from api.openai_server import DEFAULT_MAX_CONCURRENT_RUNS, positive_int, serve
def positive_arg(value: str) -> int:
try:
return positive_int(value, "--max-concurrent-runs")
except ValueError as exc:
raise argparse.ArgumentTypeError(str(exc)) from exc
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description="Serve ResearchHarness through /v1/chat/completions.")
parser.add_argument(
"--api-runs-dir",
required=True,
dest="api_runs_dir",
help="Directory where the server creates one isolated subdirectory per request.",
)
parser.add_argument("--host", default="127.0.0.1", help="Host to bind. Defaults to 127.0.0.1.")
parser.add_argument("--port", type=int, default=8686, help="Port to bind. Defaults to 8686.")
parser.add_argument(
"--role-prompt-file",
action="append",
default=[],
dest="role_prompt_files",
help="Optional role prompt file appended to the base ResearchHarness prompt.",
)
parser.add_argument(
"--input-wrapper",
action=argparse.BooleanOptionalAction,
default=False,
help="Enable or disable the input LLM wrapper. Disabled by default.",
)
parser.add_argument(
"--output-wrapper",
action=argparse.BooleanOptionalAction,
default=False,
help="Enable or disable the output LLM wrapper. Disabled by default.",
)
parser.add_argument(
"--max-concurrent-runs",
type=positive_arg,
default=DEFAULT_MAX_CONCURRENT_RUNS,
help=f"Maximum concurrent agent runs handled by this server process. Defaults to {DEFAULT_MAX_CONCURRENT_RUNS}.",
)
parser.add_argument(
"--extra-tool",
action="append",
default=[],
dest="extra_tools",
metavar="NAME",
help="Enable one optional extra tool for every API run. Currently supported: str_replace_editor. May be passed multiple times.",
)
parser.add_argument(
"--tool",
action="append",
default=[],
dest="tool_names",
metavar="NAME",
help="Expose an explicit complete tool set for every API run. May be passed multiple times. Cannot be combined with --extra-tool.",
)
args = parser.parse_args(argv)
load_default_dotenvs()
try:
require_required_env("ResearchHarness API server")
serve(
api_runs_dir=args.api_runs_dir,
host=args.host,
port=args.port,
role_prompt_files=list(args.role_prompt_files),
input_wrapper=args.input_wrapper,
output_wrapper=args.output_wrapper,
max_concurrent_runs=args.max_concurrent_runs,
extra_tools=list(args.extra_tools),
tool_names=list(args.tool_names),
)
except (MissingRequiredEnvError, ValueError) as exc:
print(str(exc), file=sys.stderr)
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())