-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.py
More file actions
60 lines (44 loc) · 1.8 KB
/
Copy pathengine.py
File metadata and controls
60 lines (44 loc) · 1.8 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
"""Create vectorless Engine instances from settings."""
from __future__ import annotations
from typing import TYPE_CHECKING
from vectorless_code.settings import UserSettings, load_user_settings
if TYPE_CHECKING:
from vectorless import Engine
def create_engine(user_settings: UserSettings | None = None) -> Engine:
"""Create a vectorless Engine from settings.
Pins a fixed workspace directory so incremental recompile reuse persists
regardless of the current working directory or daemon restarts. Document IDs
are project-namespaced (see ``compile.py``), so a single global workspace is
safe to share across projects.
Raises ``RuntimeError`` if required settings are missing.
"""
import os
from vectorless import Engine as _Engine, EngineConfig
settings = user_settings or load_user_settings()
if not settings.api_key:
raise RuntimeError(
"VECTORLESS_API_KEY is not set. "
"Run `vcc init` or set the VECTORLESS_API_KEY environment variable."
)
if not settings.model:
raise RuntimeError(
"VECTORLESS_MODEL is not set. "
"Run `vcc init` or set the VECTORLESS_MODEL environment variable."
)
if not settings.endpoint:
raise RuntimeError(
"VECTORLESS_ENDPOINT is not set. "
"Run `vcc init` or set the VECTORLESS_ENDPOINT environment variable."
)
workspace = os.environ.get("VECTORLESS_CODE_WORKSPACE") or os.path.join(
os.path.expanduser("~"), ".vectorless_code", "workspace"
)
config = EngineConfig(
llm={
"model": settings.model,
"api_key": settings.api_key,
"endpoint": settings.endpoint,
},
storage={"workspace_dir": workspace},
)
return _Engine(config=config)