Skip to content

Commit

Permalink
exclude continuation prompt/examples when not in continuation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
granawkins committed Jan 31, 2024
1 parent 1062ca2 commit a653de8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion rawdog/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def banner():
parser.add_argument('--dry-run', action='store_true', help='Print the script before executing and prompt for confirmation.')
parser.add_argument('--continuation', action='store_true', help='Allow Rawdog to execute consecutive scripts.')
args = parser.parse_args()
llm_client = LLMClient() # Will prompt for API key if not found
llm_client = LLMClient(continuation=args.continuation) # Will prompt for API key if not found
if len(args.prompt) > 0:
rawdog(" ".join(args.prompt))
else:
Expand Down
15 changes: 11 additions & 4 deletions rawdog/llm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
set_llm_api_key,
set_llm_model
)
from rawdog.prompts import script_prompt, script_examples
from rawdog.prompts import (
continuation_prompt,
continuation_examples,
script_prompt,
script_examples
)


class LLMClient:

def __init__(self):
def __init__(self, continuation: bool = False):
self.log_path = rawdog_dir / "logs.jsonl"
self.base_url = get_llm_base_url() or 'https://api.openai.com/v1'
set_base_url(self.base_url)
Expand All @@ -31,9 +36,11 @@ def __init__(self):
print(f"API Key ({self.api_key}) not found. ")
self.api_key = input("Enter API Key (e.g. OpenAI): ").strip()
set_llm_api_key(self.api_key)
_prompt = continuation_prompt if continuation else script_prompt
_examples = continuation_examples if continuation else script_examples
self.conversation = [
{"role": "system", "content": script_prompt},
{"role": "system", "content": script_examples},
{"role": "system", "content": _prompt},
{"role": "system", "content": _examples},
]

def get_response(
Expand Down
52 changes: 32 additions & 20 deletions rawdog/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,6 @@
iii. Communicate back to the user by printing to the console in that SCRIPT
3. The compiler checks your SCRIPT using ast.parse() then runs it using exec()
You'll get to see the output of a script before your next interaction. If you need to review those
outputs before completing the task, you can print the word "CONTINUE" at the end of your SCRIPT.
This can be useful for summarizing documents or technical readouts, reading instructions before
deciding what to do, or other tasks that require multi-step reasoning.
A typical 'CONTINUE' interaction looks like this:
1. The user gives you a natural language PROMPT.
2. You:
i. Determine what needs to be done
ii. Determine that you need to see the output of some subprocess call to complete the task
iii. Write a short Python SCRIPT to print that and then print the word "CONTINUE"
3. The compiler
i. Checks and runs your SCRIPT
ii. Captures the output and appends it to the conversation as "LAST SCRIPT OUTPUT:"
iii. Finds the word "CONTINUE" and sends control back to you
4. You again:
i. Look at the original PROMPT + the "LAST SCRIPT OUTPUT:" to determine what needs to be done
ii. Write a short Python SCRIPT to do it
iii. Communicate back to the user by printing to the console in that SCRIPT
5. The compiler...
Please follow these conventions carefully:
- Decline any tasks that seem dangerous, irreversible, or that you don't understand.
- Always review the full conversation prior to answering and maintain continuity.
Expand Down Expand Up @@ -88,6 +68,38 @@ def get_name(f):
print("Error:", e)
```
-------------------------------------------------------------------------------
"""

# CONTINUATIONS

_continuation_prompt = """
You'll get to see the output of a script before your next interaction. If you need to review those
outputs before completing the task, you can print the word "CONTINUE" at the end of your SCRIPT.
This can be useful for summarizing documents or technical readouts, reading instructions before
deciding what to do, or other tasks that require multi-step reasoning.
A typical 'CONTINUE' interaction looks like this:
1. The user gives you a natural language PROMPT.
2. You:
i. Determine what needs to be done
ii. Determine that you need to see the output of some subprocess call to complete the task
iii. Write a short Python SCRIPT to print that and then print the word "CONTINUE"
3. The compiler
i. Checks and runs your SCRIPT
ii. Captures the output and appends it to the conversation as "LAST SCRIPT OUTPUT:"
iii. Finds the word "CONTINUE" and sends control back to you
4. You again:
i. Look at the original PROMPT + the "LAST SCRIPT OUTPUT:" to determine what needs to be done
ii. Write a short Python SCRIPT to do it
iii. Communicate back to the user by printing to the console in that SCRIPT
5. The compiler...
"""

# Insert right after the basic interaction pattern
continuation_prompt = script_prompt.replace(
"Please follow these conventions carefully:",
_continuation_prompt + "\nPlease follow these conventions carefully:")

continuation_examples = script_examples + """
PROMPT: Summarize my essay, "Essay 2021-09-01.txt"
SCRIPT:
Expand Down

0 comments on commit a653de8

Please sign in to comment.