18
18
/ollama What is Python?
19
19
20
20
- 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
23
23
24
24
- 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
27
27
28
28
Dependencies:
29
29
- Requires an Ollama server running locally at http://localhost:11434/api/generate
30
30
"""
31
31
32
32
# Script metadata
33
- SCRIPT_NAME = "ollama_bot "
33
+ SCRIPT_NAME = "ollama "
34
34
SCRIPT_AUTHOR = "teraflops"
35
- SCRIPT_VERSION = "1.9 "
35
+ SCRIPT_VERSION = "2.1 "
36
36
SCRIPT_LICENSE = "MIT"
37
37
SCRIPT_DESC = "Automatically responds to mentions using Ollama and allows manual queries, including PMs"
38
38
OLLAMA_API_URL = "http://localhost:11434/api/generate"
@@ -51,7 +51,7 @@ def setup_config():
51
51
def ask_ollama (message ):
52
52
"""Send a query to Ollama and return the complete response."""
53
53
try :
54
- data = {"model" : "mistral " , "prompt" : message , "stream" : False }
54
+ data = {"model" : "gemma " , "prompt" : message , "stream" : False }
55
55
headers = {"Content-Type" : "application/json" }
56
56
57
57
response = requests .post (
@@ -70,6 +70,16 @@ def ask_ollama(message):
70
70
except requests .exceptions .RequestException as e :
71
71
return f"Error connecting to Ollama: { str (e )} "
72
72
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
+
73
83
def message_callback (data , buffer , date , tags , displayed , highlight , prefix , message ):
74
84
"""Detect mentions in channels or private messages and respond automatically with Ollama."""
75
85
@@ -79,17 +89,17 @@ def message_callback(data, buffer, date, tags, displayed, highlight, prefix, mes
79
89
buffer_type = weechat .buffer_get_string (buffer , "localvar_type" )
80
90
is_private = buffer_type == "private"
81
91
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
83
93
84
94
# Ignore private messages if pm_response is off
85
95
if is_private and weechat .config_get_plugin ("pm_response" ) == "off" :
86
96
return weechat .WEECHAT_RC_OK
87
97
88
- # Avoid responding to every PM automatically
98
+ # Only respond in private messages if it's a direct question
89
99
if is_private and not message .strip ().endswith ("?" ):
90
100
return weechat .WEECHAT_RC_OK
91
101
92
- # Only respond in channels if mentioned
102
+ # Only respond in channels if explicitly mentioned or highlighted
93
103
if not is_private and not is_mentioned and not int (highlight ):
94
104
return weechat .WEECHAT_RC_OK
95
105
@@ -102,6 +112,7 @@ def message_callback(data, buffer, date, tags, displayed, highlight, prefix, mes
102
112
103
113
return weechat .WEECHAT_RC_OK
104
114
115
+
105
116
def config_callback (data , option , value ):
106
117
"""Callback for Weechat configuration changes."""
107
118
weechat .prnt ("" , f"[Ollama] Configuration changed: { option } = { value } " )
@@ -110,11 +121,12 @@ def config_callback(data, option, value):
110
121
# Register configuration with /set
111
122
weechat .config_set_desc_plugin ("highlight_response" , "Automatically respond to mentions in channels (on/off)" )
112
123
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" , "" )
115
126
116
127
# Register commands and hooks
117
128
weechat .hook_command ("ollama" , "Ask something to Ollama" , "<question>" , "Example: /ollama What is Python?" , "" , "command_ollama" , "" )
118
129
weechat .hook_print ("" , "notify_highlight" , "" , 1 , "message_callback" , "" )
119
130
weechat .hook_print ("" , "notify_message" , "" , 1 , "message_callback" , "" )
120
131
weechat .hook_print ("" , "notify_private" , "" , 1 , "message_callback" , "" )
132
+
0 commit comments