enable chat for expert, custom inference parameters

This commit is contained in:
Shivering Ocelot committed 2025-07-17 21:10:28 -05:00
1 parent 7853b71587
commit 69e8614a98
2 files changed
+49 -22

No files matched your search

+41 -15
View File
@@ -22,29 +22,55 @@ class ExpertAgent(Agent):
Agent.__init__(self, app, data)
async def prompt(self, instruction, input=None, **kwargs):
# if instruction and input are passed, instruction extends the system prompt
# otherwise, use the one passed as the user prompt, with the regular system prompt
# TODO: if 'history' in kwargs: interpret it as user-agent turns assuming list[str]
# Instruction extends system if there's input or messages
# Otherwise instruction is the user prompt
# Input is always added as a user message at the end, if present
# Use 'messages' as starting point when passed
messages = []
if 'messages' in kwargs:
messages = [LlamaMessage(msg['role'], msg['content']) for msg in kwargs['messages']]
# Construct the default messages
system = self.config['system_prompt']
if instruction != None and input != None:
prompt = input
if input == None and not messages:
prompt = instruction
elif instruction:
system += "\n" + instruction
# Add default messages to list
messages.insert(0, LlamaMessage("system", system))
if prompt:
messages.append(LlamaMessage("user", prompt))
prompt = input if input != None else instruction
messages = [
LlamaMessage("system", system),
LlamaMessage("user", prompt)
]
response = await replicate_llama_completion(self.app, messages, model=Models.llama_70b)
response = await replicate_llama_completion(self.app, messages, model=Models.llama_70b, max_tokens=2048)
return response
async def received_message(self, message):
raise Exception("TODO: expert chat support")
chat_view = self.app.get_chat_view(message.chat_id)
thread = chat_view.get_thread(message.thread_id)
def msg_role(message):
sender = message.sender
is_digit = isinstance(sender, (int, str)) and str(sender).isdigit()
if is_digit and str(sender) == str(self.id):
return 'assistant'
elif sender == 'user':
return 'user'
else:
raise Exception("Unsupported sender: " + sender)
messages = [{'role': msg_role(msg), 'content': msg.content} for msg in thread.messages]
response = await self.prompt(
instruction=None,
input=None,
messages=messages
)
messages = []
response = await replicate_llama_completion(self.app, messages, model=Models.llama_70b)
self.app.send_chat_message(
chat_id=message.chat_id,
sender=self.id,