Introduce Expert Agent. Prompt agents from UI.
This commit is contained in:
1 parent
a7cc529e38
commit
7853b71587
6 files changed
+194
-28
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import re
|
||||
import json
|
||||
import inspect
|
||||
from string import Template
|
||||
|
||||
from inference import LlamaMessage, replicate_llama_completion, Models
|
||||
from agent import Agent, AgentField
|
||||
|
||||
CLASS_DESCRIPTION = """
|
||||
Expert AI in any field, powered by Llama 3 70b.
|
||||
Will get guidelines, documents, and other advanced features in the future.
|
||||
""".strip()
|
||||
|
||||
class ExpertAgent(Agent):
|
||||
identifier = "expert"
|
||||
description = CLASS_DESCRIPTION
|
||||
schema_fields = [
|
||||
AgentField('system_prompt', 'string', default="You are an expert AI assistant."),
|
||||
]
|
||||
|
||||
def __init__(self, app, data):
|
||||
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]
|
||||
|
||||
system = self.config['system_prompt']
|
||||
if instruction != None and input != None:
|
||||
system += "\n" + instruction
|
||||
|
||||
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)
|
||||
return response
|
||||
|
||||
async def received_message(self, message):
|
||||
raise Exception("TODO: expert chat support")
|
||||
|
||||
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,
|
||||
content=response,
|
||||
thread_id=message.thread_id,
|
||||
)
|
||||
Reference in new issue
Block a user