forked from CS-153/ai-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
70 lines (53 loc) · 2.64 KB
/
agent.py
File metadata and controls
70 lines (53 loc) · 2.64 KB
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
import os
from mistralai import Mistral
import discord
MISTRAL_MODEL = "mistral-large-latest"
# TODO - Tweak
SYSTEM_PROMPT_PROBE = "You are an honest assistant. The question regards the speaker tag, not you. Respond using only the phrases 'Yes' or 'No'. Do you know the answer the following question?"
SYSTEM_PROMPT_ANSWER = "You are a helpful research assistant giving a brief answer that is factually correct about the speaker being asked about."
SYSTEM_PROMPT_PROBE_AND_ANSWER = """Answer 'No' if the question contains the word 'you' or 'your'. You are a helpful research assistant. The questions are about a speaker (the person being asked about), not about you.
If the question is asking for factual information about the speaker's work, research, or professional background, provide a brief factual answer.
If the question is personal (about opinions, feelings, challenges, or experiences) or if you're unsure about the answer, respond with 'No'.
Never answer as if the question is about yourself - the questions are always about the speaker."""
class ProbeAgent:
def __init__(self):
MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY")
self.client = Mistral(api_key=MISTRAL_API_KEY)
async def run(self, message: discord.Message):
messages = [
{"role": "system", "content": SYSTEM_PROMPT_PROBE},
{"role": "user", "content": message.content},
]
response = await self.client.chat.complete_async(
model=MISTRAL_MODEL,
messages=messages,
)
return response.choices[0].message.content
class AnswerAgent:
def __init__(self):
MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY")
self.client = Mistral(api_key=MISTRAL_API_KEY)
async def run(self, message: discord.Message):
messages = [
{"role": "system", "content": SYSTEM_PROMPT_ANSWER},
{"role": "user", "content": message.content},
]
response = await self.client.chat.complete_async(
model=MISTRAL_MODEL,
messages=messages,
)
return response.choices[0].message.content
class ProbeAndAnswerAgent:
def __init__(self):
MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY")
self.client = Mistral(api_key=MISTRAL_API_KEY)
async def run(self, message: discord.Message):
messages = [
{"role": "system", "content": SYSTEM_PROMPT_PROBE_AND_ANSWER},
{"role": "user", "content": message.content},
]
response = await self.client.chat.complete_async(
model=MISTRAL_MODEL,
messages=messages,
)
return response.choices[0].message.content