Skip to content

Commit 03ffab5

Browse files
committed
Plugins: Update the Gemini system prompt
Also making sure we're injecting the current time and date.
1 parent 263b63c commit 03ffab5

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

plugins/shrimpai/shrimpai.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@
3232
import logging
3333
import sys
3434
import json
35+
import datetime
3536
import plugin
3637

3738
from utils import gemini
3839

39-
DEFAULT_PROMPT = """You are an IRC bot. Users will post questions that you answer."""
40+
DEFAULT_PROMPT = (
41+
"You are an IRC bot. Users will post questions that you answer. Keep your responses brief and "
42+
"as precise as possible. If you are not sure about an answer, make that clear but don't be "
43+
"overly vague. The user can ask questions in any language and, unless otherwise "
44+
"instructed, you will respond in the same langage as the user."
45+
)
4046
DEFAULT_MODEL = "gemini-2.5-flash"
4147

4248

@@ -53,7 +59,7 @@ def started(self, settings):
5359
self.system_message = {"role": "system", "content": prompt}
5460
self.model = s["model"] if "model" in s else DEFAULT_MODEL
5561
self.max_tokens = int(s["max_tokens"]) if "max_tokens" in s else 512
56-
self.temperature = int(s["temperature"]) if "temperature" in s else 0.2
62+
self.temperature = float(s["temperature"]) if "temperature" in s else 0.2
5763
self.history = []
5864
self.max_history = int(s["max_history"]) if "max_history" in s else 5
5965
# Max number of seconds of inactivity before cleaning out the message history
@@ -95,7 +101,13 @@ def add_to_history(self, message):
95101
def respond_to_message(self, query, server, channel):
96102
message = {"role": "user", "content": query}
97103
self.add_to_history(message)
98-
messages = [self.system_message] + self.history
104+
105+
current_time = datetime.datetime.now().astimezone().strftime("%A, %B %d, %Y %H:%M:%S %Z")
106+
prompt = self.system_message["content"]
107+
full_prompt = f"{prompt}\n\nCurrent date and time: {current_time}"
108+
system_message = {"role": "system", "content": full_prompt}
109+
110+
messages = [system_message] + self.history
99111
result = gemini.get_response(
100112
self.key, messages, self.model, self.max_tokens, self.temperature
101113
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__author__ = "reggna"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import unittest
2+
from unittest.mock import MagicMock, patch
3+
import json
4+
import datetime
5+
from plugins.shrimpgemini.shrimpgemini import shrimpgemini
6+
7+
8+
class TestShrimpGemini(unittest.TestCase):
9+
def setUp(self):
10+
self.plugin = shrimpgemini()
11+
# Mock settings for started()
12+
self.settings = json.dumps(
13+
{"key": "test-key", "trigger": "gemini:", "channel": "#test", "temperature": "0.5"}
14+
)
15+
self.plugin.started(self.settings)
16+
17+
def test_started_temperature_is_float(self):
18+
self.assertEqual(self.plugin.temperature, 0.5)
19+
self.assertIsInstance(self.plugin.temperature, float)
20+
21+
@patch("utils.gemini.get_response")
22+
def test_respond_to_message_includes_date_time(self, mock_get_response):
23+
mock_get_response.return_value = "Test response"
24+
self.plugin.safe_privmsg = MagicMock()
25+
26+
# Test query
27+
query = "What time is it?"
28+
server = "test-server"
29+
channel = "#test"
30+
31+
# Call the method
32+
self.plugin.respond_to_message(query, server, channel)
33+
34+
# Check call arguments
35+
# messages should be the second argument
36+
args, kwargs = mock_get_response.call_args
37+
messages = args[1]
38+
39+
# The system message should be the first in the list
40+
system_msg = messages[0]
41+
self.assertEqual(system_msg["role"], "system")
42+
43+
# Check if "Current date and time" is in the system message content
44+
self.assertIn("Current date and time:", system_msg["content"])
45+
46+
# Verify the date format
47+
now_str = datetime.datetime.now().astimezone().strftime("%A, %B %d, %Y")
48+
self.assertIn(now_str, system_msg["content"])
49+
50+
# Verify timezone is present (e.g., UTC, CET, etc.)
51+
tz_str = datetime.datetime.now().astimezone().strftime("%Z")
52+
self.assertIn(tz_str, system_msg["content"])
53+
54+
55+
if __name__ == "__main__":
56+
unittest.main()

0 commit comments

Comments
 (0)