-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathserver.py
56 lines (47 loc) · 1.44 KB
/
server.py
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
"""
Example server for the ReDel web interface.
Environment Variables:
- OPENAI_API_KEY
- ANTHROPIC_API_KEY (optional)
Configuration:
- root engine: gpt-4o
- delegate engine: gpt-4o
- tools:
- Browsing (always included in delegates)
- long engine: claude-3-opus (for summarizing long webpages, if ANTHROPIC_API_KEY is set)
"""
import logging
import os
from kani.engines.anthropic import AnthropicEngine
from kani.engines.openai import OpenAIEngine
from kani.ext.ratelimits import RatelimitedEngine
from redel import AUTOGENERATE_TITLE, ReDel
from redel.delegation import DelegateOne
from redel.server import VizServer
from redel.tools.browsing import Browsing
# Define the engines
engine = OpenAIEngine(model="gpt-4o", temperature=0.8, top_p=0.95)
if "ANTHROPIC_API_KEY" in os.environ:
long_engine = RatelimitedEngine(
AnthropicEngine(model="claude-3-5-sonnet-20240620", temperature=0.7, max_tokens=4096), max_concurrency=1
)
else:
long_engine = None
# Define the configuration for each interactive session
ai = ReDel(
root_engine=engine,
delegate_engine=engine,
delegation_scheme=DelegateOne,
title=AUTOGENERATE_TITLE,
tool_configs={
Browsing: {
"always_include": True,
"kwargs": {"long_engine": long_engine},
},
},
)
# configure and start the server
server = VizServer(ai)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
server.serve()