Token based authentication

This commit is contained in:
Shivering Ocelot committed 2025-05-28 01:15:46 -05:00
1 parent 9a8e68f021
commit 5bbdfe8747
7 files changed
+121 -77

No files matched your search

+38 -2
View File
@@ -1,4 +1,5 @@
from inference import LlamaMessage, replicate_llama_completion
import re
message_format_section = """
When suggesting code to the user, keep the code as small snippets.
@@ -8,7 +9,9 @@ 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."""
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 = [
@@ -36,4 +39,37 @@ async def gral_message(app, system_prompt, message_history: list, file_map: dict
messages.extend([LlamaMessage(msg['role'], msg['content']) for msg in message_history])
response = await replicate_llama_completion(app, messages)
return response
return response
async def gral_update_file(app, system_prompt, message_history: list, filepath: str, file_content: str):
messages = [
LlamaMessage("system", "\n".join([
system_prompt,
"Respond with the raw contents of the file updated as concluded in the conversation.",
])),
]
# History Message
message_lines = [f"This is the history of the conversation that led to the update of the file {filepath}."]
message_lines.extend([f"{entry['role']}: {entry['content']}" for entry in message_history if entry.get('content')])
messages.append(LlamaMessage("user", "\n".join(message_lines)))
# Main Instruction Message
message_lines = [
f"Write the updated contents of the file: {filepath}, as concluded in the conversation above.",
f"The raw file contents of the file {filepath} are included following the horizontal rule below."
"\n---\n",
file_content,
]
messages.append(LlamaMessage("user", "\n".join(message_lines)))
new_content = await replicate_llama_completion(app, messages)
# Remove backtick fences
md_code_pattern = re.compile(r"^\s*```[\w\s]*\n([\s\S]*)\n```\s*$", re.MULTILINE)
md_match = re.search(md_code_pattern, new_content)
if md_match:
print("agent used backtick fences")
new_content = md_match.group(1)
return new_content