-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
initialize.py
125 lines (109 loc) · 4.76 KB
/
initialize.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import asyncio
import models
from agent import AgentConfig, ModelConfig
from python.helpers import dotenv, files, rfc_exchange, runtime, settings, docker, log
def initialize():
current_settings = settings.get_settings()
# chat model from user settings
chat_llm = ModelConfig(
provider=models.ModelProvider[current_settings["chat_model_provider"]],
name=current_settings["chat_model_name"],
ctx_length=current_settings["chat_model_ctx_length"],
limit_requests=current_settings["chat_model_rl_requests"],
limit_input=current_settings["chat_model_rl_input"],
limit_output=current_settings["chat_model_rl_output"],
kwargs={
"temperature": current_settings["chat_model_temperature"],
**current_settings["chat_model_kwargs"],
},
)
# utility model from user settings
utility_llm = ModelConfig(
provider=models.ModelProvider[current_settings["util_model_provider"]],
name=current_settings["util_model_name"],
ctx_length=current_settings["util_model_ctx_length"],
limit_requests=current_settings["util_model_rl_requests"],
limit_input=current_settings["util_model_rl_input"],
limit_output=current_settings["util_model_rl_output"],
kwargs={
"temperature": current_settings["util_model_temperature"],
**current_settings["util_model_kwargs"],
},
)
# embedding model from user settings
embedding_llm = ModelConfig(
provider=models.ModelProvider[current_settings["embed_model_provider"]],
name=current_settings["embed_model_name"],
ctx_length=0,
limit_requests=current_settings["embed_model_rl_requests"],
limit_input=0,
limit_output=0,
kwargs={
**current_settings["embed_model_kwargs"],
},
)
# agent configuration
config = AgentConfig(
chat_model=chat_llm,
utility_model=utility_llm,
embeddings_model=embedding_llm,
prompts_subdir=current_settings["agent_prompts_subdir"],
memory_subdir=current_settings["agent_memory_subdir"],
knowledge_subdirs=["default", current_settings["agent_knowledge_subdir"]],
code_exec_docker_enabled=False,
# code_exec_docker_name = "A0-dev",
# code_exec_docker_image = "frdel/agent-zero-run:development",
# code_exec_docker_ports = { "22/tcp": 55022, "80/tcp": 55080 }
# code_exec_docker_volumes = {
# files.get_base_dir(): {"bind": "/a0", "mode": "rw"},
# files.get_abs_path("work_dir"): {"bind": "/root", "mode": "rw"},
# },
# code_exec_ssh_enabled = True,
# code_exec_ssh_addr = "localhost",
# code_exec_ssh_port = 55022,
# code_exec_ssh_user = "root",
# code_exec_ssh_pass = "",
# additional = {},
)
# update SSH and docker settings
set_runtime_config(config, current_settings)
# update config with runtime args
args_override(config)
# return config object
return config
def args_override(config):
# update config with runtime args
for key, value in runtime.args.items():
if hasattr(config, key):
# conversion based on type of config[key]
if isinstance(getattr(config, key), bool):
value = value.lower().strip() == "true"
elif isinstance(getattr(config, key), int):
value = int(value)
elif isinstance(getattr(config, key), float):
value = float(value)
elif isinstance(getattr(config, key), str):
value = str(value)
else:
raise Exception(
f"Unsupported argument type of '{key}': {type(getattr(config, key))}"
)
setattr(config, key, value)
def set_runtime_config(config: AgentConfig, set: settings.Settings):
ssh_conf = settings.get_runtime_config(set)
for key, value in ssh_conf.items():
if hasattr(config, key):
setattr(config, key, value)
# if config.code_exec_docker_enabled:
# config.code_exec_docker_ports["22/tcp"] = ssh_conf["code_exec_ssh_port"]
# config.code_exec_docker_ports["80/tcp"] = ssh_conf["code_exec_http_port"]
# config.code_exec_docker_name = f"{config.code_exec_docker_name}-{ssh_conf['code_exec_ssh_port']}-{ssh_conf['code_exec_http_port']}"
# dman = docker.DockerContainerManager(
# logger=log.Log(),
# name=config.code_exec_docker_name,
# image=config.code_exec_docker_image,
# ports=config.code_exec_docker_ports,
# volumes=config.code_exec_docker_volumes,
# )
# dman.start_container()
# config.code_exec_ssh_pass = asyncio.run(rfc_exchange.get_root_password())