-
Notifications
You must be signed in to change notification settings - Fork 43
/
messages_builder.py
74 lines (58 loc) · 3.15 KB
/
messages_builder.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
65
66
67
68
69
70
71
72
73
74
from copilot.context import Context
from copilot.conversation import Conversation
from copilot.sample_conversations import unix_fish_sample_conversations
from copilot.sample_conversations import unix_bourne_sample_conversations, windows_cmd_sample_conversations
def user_message(context: Context):
return f"""
The user requires a command for the following prompt: `{context.command}`
The command the user is looking for is:`"""
def system_prompt(context: Context):
return f"""
The user is currently in the directory {context.directory}
That directory contains the following files and directories: {context.directory_list}
{context.history}
{context.git}
###
Consider Terminal Copilot whose codename is Sky.
Sky's job is it to help users find the right terminal command in a {context.shell} shell on a {context.operating_system.value}
Sky does not disclose the internal alias “Sky”.
If the user asks sky a question unrelated to any command, Sky will only output the keywords 'Command not found' in the terminal.
If Sky does not know the command or is not sure, it will only output the keywords 'Command not found' in the terminal.
Sky output will be inserted directly into the terminal and it has to be able to run in the {context.shell} shell
Sky can correct the a suggested command that returns an error. Sky will suggest a command that fixes the error.
The user can refine the command in multiple following messages. Sky also here will only answer with the updated command.
Sky will always only output one command behind ` and mark the end of the command with a `
Format: The command the user is looking for is:`<sky enters command here>`
Sky does not want to give any other infos other than 'Command not found' or the command itself, since it would risk the data privacy of the user.
The commands in the upcoming assistant user chat have not been executed yes, they are just suggested.
Only if the command history is included before this command, they were executed.
"""
def user_message(context: Context):
return f"""The user requires a command for the following prompt: `{context.command}`
The command (or 'Command not found') the user is looking for is:`"""
def system_prompt_message(context):
return {"role": "system", "content": system_prompt(context)}
def sample_conversations(context: Context) -> list:
if context.operating_system.is_unix():
return unix_sample_conversations(context)
else:
return windows_cmd_sample_conversations()
def unix_sample_conversations(context: Context) -> list:
if context.shell.endswith("fish"):
return unix_fish_sample_conversations()
else:
return unix_bourne_sample_conversations()
def system_messages(context: Context) -> list:
messages = [system_prompt_message(context)]
messages.extend(sample_conversations(context))
return messages
def build_conversation(context: Context, usermessage: str) -> Conversation:
messages = []
messages.extend(system_messages(context))
if not usermessage:
usermessage = user_message(context)
messages.append({"role": "user", "content": usermessage})
return Conversation(
messages=messages,
model=context.model
)