-
Notifications
You must be signed in to change notification settings - Fork 6
/
create_episode.py
64 lines (54 loc) · 1.75 KB
/
create_episode.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
import os
from codenav.agents.gpt4.agent import OpenAICodeNavAgent
from codenav.constants import ABS_PATH_OF_CODENAV_DIR, DEFAULT_OPENAI_MODEL
from codenav.environments.code_env import PythonCodeEnv
from codenav.environments.done_env import DoneEnv
from codenav.environments.retrieval_env import EsCodeRetriever, RetrievalEnv
from codenav.interaction.episode import Episode
from codenav.retrieval.elasticsearch.elasticsearch_constants import RESERVED_CHARACTERS
from codenav.retrieval.elasticsearch.index_codebase import DEFAULT_ES_HOST
from codenav.utils.prompt_utils import PromptBuilder
ALLOWED_ACTIONS = ["done", "code", "search"]
CODE_DIR = ABS_PATH_OF_CODENAV_DIR
PARENT_DIR = os.path.dirname(CODE_DIR)
# create prompt
prompt_builder = PromptBuilder(repo_description="codenav/repo_description.txt")
prompt = prompt_builder.build(
dict(
AVAILABLE_ACTIONS=ALLOWED_ACTIONS,
RESERVED_CHARACTERS=RESERVED_CHARACTERS,
RETRIEVALS_PER_KEYWORD=3,
)
)
# create environments
code_env = PythonCodeEnv(
code_dir=CODE_DIR,
sys_paths=[PARENT_DIR],
working_dir=os.path.join(PARENT_DIR, "playground"),
)
retrieval_env = RetrievalEnv(
code_retriever=EsCodeRetriever(
index_name="codenav",
host=DEFAULT_ES_HOST,
),
expansions_per_query=3,
prototypes_per_query=7,
)
done_env = DoneEnv()
# create agent using prompt
agent = OpenAICodeNavAgent(
prompt=prompt,
model=DEFAULT_OPENAI_MODEL,
allowed_action_types=ALLOWED_ACTIONS,
)
# create environments:
episode = Episode(
agent,
action_type_to_env=dict(
code=code_env,
search=retrieval_env,
done=done_env,
),
user_query_str="Find the DoneEnv and instantiate it",
)
episode.step_until_max_steps_or_success(max_steps=5)