Skip to content

Commit c0f2a37

Browse files
committed
Update ollamabot.py: translate comments to English
1 parent c8a4145 commit c0f2a37

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

python/ollama.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818
/ollama What is Python?
1919
2020
- To enable or disable automatic responses in channels:
21-
/set plugins.var.python.ollama_bot.highlight_response on # Enable responses in channels
22-
/set plugins.var.python.ollama_bot.highlight_response off # Disable responses in channels
21+
/set plugins.var.python.ollama.highlight_response on # Enable responses in channels
22+
/set plugins.var.python.ollama.highlight_response off # Disable responses in channels
2323
2424
- To enable or disable automatic responses in private messages:
25-
/set plugins.var.python.ollama_bot.pm_response on # Enable PM responses
26-
/set plugins.var.python.ollama_bot.pm_response off # Disable PM responses
25+
/set plugins.var.python.ollama.pm_response on # Enable PM responses
26+
/set plugins.var.python.ollama.pm_response off # Disable PM responses
2727
2828
Dependencies:
2929
- Requires an Ollama server running locally at http://localhost:11434/api/generate
3030
"""
3131

3232
# Script metadata
33-
SCRIPT_NAME = "ollama_bot"
33+
SCRIPT_NAME = "ollama"
3434
SCRIPT_AUTHOR = "teraflops"
35-
SCRIPT_VERSION = "1.9"
35+
SCRIPT_VERSION = "2.1"
3636
SCRIPT_LICENSE = "MIT"
3737
SCRIPT_DESC = "Automatically responds to mentions using Ollama and allows manual queries, including PMs"
3838
OLLAMA_API_URL = "http://localhost:11434/api/generate"
@@ -51,7 +51,7 @@ def setup_config():
5151
def ask_ollama(message):
5252
"""Send a query to Ollama and return the complete response."""
5353
try:
54-
data = {"model": "mistral", "prompt": message, "stream": False}
54+
data = {"model": "gemma", "prompt": message, "stream": False}
5555
headers = {"Content-Type": "application/json"}
5656

5757
response = requests.post(
@@ -70,6 +70,16 @@ def ask_ollama(message):
7070
except requests.exceptions.RequestException as e:
7171
return f"Error connecting to Ollama: {str(e)}"
7272

73+
def command_ollama(data, buffer, args):
74+
"""Command /ollama to manually ask Ollama a question."""
75+
if not args:
76+
weechat.prnt(buffer, "[Ollama] Usage: /ollama <question>")
77+
return weechat.WEECHAT_RC_OK
78+
79+
response = ask_ollama(args)
80+
weechat.prnt(buffer, f"[Ollama] {response}")
81+
return weechat.WEECHAT_RC_OK
82+
7383
def message_callback(data, buffer, date, tags, displayed, highlight, prefix, message):
7484
"""Detect mentions in channels or private messages and respond automatically with Ollama."""
7585

@@ -79,17 +89,17 @@ def message_callback(data, buffer, date, tags, displayed, highlight, prefix, mes
7989
buffer_type = weechat.buffer_get_string(buffer, "localvar_type")
8090
is_private = buffer_type == "private"
8191
username = weechat.info_get("irc_nick", "") # Get the current IRC username
82-
is_mentioned = username.lower() in message.lower()
92+
is_mentioned = f"@{username.lower()}" in message.lower() # Ensure @username is explicitly mentioned
8393

8494
# Ignore private messages if pm_response is off
8595
if is_private and weechat.config_get_plugin("pm_response") == "off":
8696
return weechat.WEECHAT_RC_OK
8797

88-
# Avoid responding to every PM automatically
98+
# Only respond in private messages if it's a direct question
8999
if is_private and not message.strip().endswith("?"):
90100
return weechat.WEECHAT_RC_OK
91101

92-
# Only respond in channels if mentioned
102+
# Only respond in channels if explicitly mentioned or highlighted
93103
if not is_private and not is_mentioned and not int(highlight):
94104
return weechat.WEECHAT_RC_OK
95105

@@ -102,6 +112,7 @@ def message_callback(data, buffer, date, tags, displayed, highlight, prefix, mes
102112

103113
return weechat.WEECHAT_RC_OK
104114

115+
105116
def config_callback(data, option, value):
106117
"""Callback for Weechat configuration changes."""
107118
weechat.prnt("", f"[Ollama] Configuration changed: {option} = {value}")
@@ -110,11 +121,12 @@ def config_callback(data, option, value):
110121
# Register configuration with /set
111122
weechat.config_set_desc_plugin("highlight_response", "Automatically respond to mentions in channels (on/off)")
112123
weechat.config_set_desc_plugin("pm_response", "Automatically respond to private messages (on/off)")
113-
weechat.hook_config("plugins.var.python.ollama_bot.highlight_response", "config_callback", "")
114-
weechat.hook_config("plugins.var.python.ollama_bot.pm_response", "config_callback", "")
124+
weechat.hook_config("plugins.var.python.ollama.highlight_response", "config_callback", "")
125+
weechat.hook_config("plugins.var.python.ollama.pm_response", "config_callback", "")
115126

116127
# Register commands and hooks
117128
weechat.hook_command("ollama", "Ask something to Ollama", "<question>", "Example: /ollama What is Python?", "", "command_ollama", "")
118129
weechat.hook_print("", "notify_highlight", "", 1, "message_callback", "")
119130
weechat.hook_print("", "notify_message", "", 1, "message_callback", "")
120131
weechat.hook_print("", "notify_private", "", 1, "message_callback", "")
132+

0 commit comments

Comments
 (0)