39 lines
1.7 KiB
Python
39 lines
1.7 KiB
Python
from inference import LlamaMessage, replicate_llama_completion
|
|
|
|
message_format_section = """
|
|
When suggesting code to the user, keep the code as small snippets.
|
|
If the update is meant to be applied to a file, include a line linking the file immediately before the code block like this: "[filename.txt]
|
|
```
|
|
updated segment
|
|
```"
|
|
Omit the file link when the block is not related to a known file
|
|
Code blocks must be under 30 lines. Assistant responses MUST NOT contain horizontal rules.
|
|
When suggesting bash code meant to be directly executed, use the same syntax as above but marking the code block with "[eval]" instead."""
|
|
|
|
async def gral_message(app, system_prompt, message_history: list, file_map: dict):
|
|
messages = [
|
|
LlamaMessage("system", "\n".join([
|
|
system_prompt,
|
|
message_format_section,
|
|
])),
|
|
]
|
|
|
|
file_parts = []
|
|
for filename, content in file_map.items():
|
|
file_parts.append(f"\n---\n[{filename}]\n\n{content}\n")
|
|
|
|
if file_parts:
|
|
file_lines = [
|
|
"This message contains all files relevant to the prompt: each file section in this message starts with a horizontal rule, followed by the file name in square brackets, followed by the file content.",
|
|
"Only this message contains horizontal rules, assistant responses must not include them.",
|
|
"The prompt and conversation start in the next message after this."
|
|
]
|
|
file_lines.extend(file_parts)
|
|
messages.append(
|
|
LlamaMessage("user", "\n".join(file_lines))
|
|
)
|
|
|
|
messages.extend([LlamaMessage(msg['role'], msg['content']) for msg in message_history])
|
|
|
|
response = await replicate_llama_completion(app, messages)
|
|
return response |