-
Notifications
You must be signed in to change notification settings - Fork 5
/
create_prompt.py
31 lines (26 loc) · 1.16 KB
/
create_prompt.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
from codenav.agents.gpt4.agent import DEFAULT_OPENAI_MODEL, OpenAICodeNavAgent
from codenav.retrieval.elasticsearch.elasticsearch_constants import RESERVED_CHARACTERS
from codenav.utils.prompt_utils import PromptBuilder
# Prompt builder puts together a prompt template from text files
# The template may contain placeholders for values
prompt_builder = PromptBuilder(repo_description="codenav/repo_description.txt")
prompt_template, placeholder_to_paths = prompt_builder.build_template()
# see placeholders and the file paths they appear in
print("Placeholders in template:\n", placeholder_to_paths)
# provide values for these placeholders
ALLOWED_ACTIONS = ["done", "code", "search"]
placeholder_values = dict(
AVAILABLE_ACTIONS=ALLOWED_ACTIONS,
RESERVED_CHARACTERS=RESERVED_CHARACTERS,
RETRIEVALS_PER_KEYWORD=3,
)
print("Provided values:\n", placeholder_values)
# build prompt using values
# the following is equivalent to prompt_template.format(**placeholder_values)
prompt = prompt_builder.build(placeholder_values)
# create agent using prompt
agent = OpenAICodeNavAgent(
prompt=prompt,
model=DEFAULT_OPENAI_MODEL,
allowed_action_types=ALLOWED_ACTIONS,
)