forked from CS-153/ai-agent
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathagent.py
More file actions
32 lines (26 loc) · 966 Bytes
/
agent.py
File metadata and controls
32 lines (26 loc) · 966 Bytes
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
import os
from mistralai import Mistral
import discord
MISTRAL_MODEL = "mistral-large-latest"
SYSTEM_PROMPT = "You are a helpful assistant."
class MistralAgent:
def __init__(self):
MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY")
self.client = Mistral(api_key=MISTRAL_API_KEY)
# Handle discord and non-discord messages
async def run_command(self, message):
# The simplest form of an agent
# Send the message's content to Mistral's API and return Mistral's response
if isinstance(message, discord.Message):
content = message.content
else:
content = message
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": content},
]
response = await self.client.chat.complete_async(
model=MISTRAL_MODEL,
messages=messages,
)
return response.choices[0].message.content