Skip to content

Commit

Permalink
Better UX for interactive model
Browse files Browse the repository at this point in the history
  • Loading branch information
klntsky committed Nov 12, 2024
1 parent ab591c7 commit dfbf8e1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions python/src/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ async def eval_ast(ast, runtime):
retries = 0
prompt = IF_PROMPT + condition
while prompt_result != "true" and prompt_result != "false":
prompt_result = await runtime.invoke(prompt)
prompt_result = prompt_result.strip()
retries += 1
if retries >= MAX_RETRIES:
raise ValueError(
"Failed to answer :if prompt: "
+ prompt
+ "\nOutput: "
+ prompt_result
)
prompt_result = await runtime.invoke(prompt)
prompt_result = prompt_result.strip()
retries += 1
if prompt_result == "true":
async for chunk in eval_ast(ast["then"], runtime):
yield chunk
Expand Down
9 changes: 8 additions & 1 deletion python/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ def parse_arguments():
"INPUT_FILES", nargs="*", help="A list of metaprompt files."
)

parser.add_argument(
"--model",
type=str,
help="LLM id to use",
default="interactive" # TODO: use dynamic model selection
)

parser.add_argument(
"--set",
action=ParseSetAction,
Expand All @@ -55,7 +62,7 @@ async def main():
content = file.read()
metaprompt = parse_metaprompt(content)
env = Env(env=config.parameters)
config.model = "gpt-3.5-turbo"
config.model = args.model or "interactive"
runtime = Runtime(config, env)
runtime.cwd = os.path.dirname(file_path)
async for chunk in eval_ast(metaprompt, runtime):
Expand Down
2 changes: 1 addition & 1 deletion python/src/providers/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ async def ainvoke(self, prompt: str) -> AsyncGenerator[str, None]:
Yields:
str: Chunks of the response as they're received.
"""
output = input("[interactive]: " + prompt)
output = input("[Q]: " + prompt + "\n[A]: ")
yield output

0 comments on commit dfbf8e1

Please sign in to comment.