2
2
import requests
3
3
import json
4
4
5
- # Configuración inicial
5
+ # Script metadata
6
6
SCRIPT_NAME = "ollama_bot"
7
7
SCRIPT_AUTHOR = "teraflops"
8
8
SCRIPT_VERSION = "1.5"
9
9
SCRIPT_LICENSE = "MIT"
10
- SCRIPT_DESC = "Responde automáticamente a menciones con Ollama y permite consultas manuales, incluyendo PMs"
10
+ SCRIPT_DESC = "Automatically responds to mentions using Ollama and allows manual queries, including PMs"
11
11
OLLAMA_API_URL = "http://localhost:11434/api/generate"
12
12
13
- # Registrar el script
13
+ # Register the script
14
14
weechat .register (SCRIPT_NAME , SCRIPT_AUTHOR , SCRIPT_VERSION , SCRIPT_LICENSE , SCRIPT_DESC , "" , "" )
15
15
16
- # Configuración del script en Weechat
16
+ # Script configuration in Weechat
17
17
def setup_config ():
18
18
if not weechat .config_is_set_plugin ("highlight_response" ):
19
- weechat .config_set_plugin ("highlight_response" , "on" ) # Responder a menciones y PMs por defecto
19
+ weechat .config_set_plugin ("highlight_response" , "on" ) # Enable auto-responses by default
20
20
setup_config ()
21
21
22
22
def ask_ollama (message ):
23
- """Consulta a Ollama enviando un mensaje y devuelve la respuesta completa ."""
23
+ """Send a query to Ollama and return the complete response ."""
24
24
try :
25
25
data = {"model" : "gemma" , "prompt" : message , "stream" : False }
26
26
response = requests .post (OLLAMA_API_URL , json = data )
27
27
response_json = response .json ()
28
- return response_json .get ("response" , "No se recibió respuesta de Ollama." )
28
+ return response_json .get ("response" , "No response received from Ollama." )
29
29
except Exception as e :
30
- return f"Error al conectar con Ollama: { str (e )} "
30
+ return f"Error connecting to Ollama: { str (e )} "
31
31
32
32
def command_ollama (data , buffer , args ):
33
- """Comando /ollama para preguntar manualmente a Ollama ."""
33
+ """Command /ollama to manually ask Ollama a question ."""
34
34
if not args :
35
- weechat .prnt (buffer , "[Ollama] Uso : /ollama <pregunta >" )
35
+ weechat .prnt (buffer , "[Ollama] Usage : /ollama <question >" )
36
36
return weechat .WEECHAT_RC_OK
37
37
38
38
response = ask_ollama (args )
39
39
weechat .prnt (buffer , f"[Ollama] { response } " )
40
40
return weechat .WEECHAT_RC_OK
41
41
42
42
def message_callback (data , buffer , date , tags , displayed , highlight , prefix , message ):
43
- """Detecta menciones en canales o mensajes privados y responde automáticamente con Ollama."""
43
+ """Detect mentions in channels or private messages and respond automatically with Ollama."""
44
44
if weechat .config_get_plugin ("highlight_response" ) == "off" :
45
- return weechat .WEECHAT_RC_OK # No responde si la opción está deshabilitada
45
+ return weechat .WEECHAT_RC_OK # Do not respond if auto-response is disabled
46
46
47
47
buffer_type = weechat .buffer_get_string (buffer , "localvar_type" )
48
48
is_private = buffer_type == "private"
49
- username = weechat .info_get ("irc_nick" , "" ) # Obtiene tu nombre de usuario en IRC
49
+ username = weechat .info_get ("irc_nick" , "" ) # Get current IRC username
50
50
is_mentioned = username .lower () in message .lower ()
51
51
52
52
if int (highlight ) or is_private or is_mentioned :
@@ -55,17 +55,17 @@ def message_callback(data, buffer, date, tags, displayed, highlight, prefix, mes
55
55
return weechat .WEECHAT_RC_OK
56
56
57
57
def config_callback (data , option , value ):
58
- """Callback para cambios en la configuración de Weechat ."""
59
- weechat .prnt ("" , f"[Ollama] Configuración cambiada : { option } = { value } " )
58
+ """Callback for Weechat configuration changes ."""
59
+ weechat .prnt ("" , f"[Ollama] Configuration changed : { option } = { value } " )
60
60
return weechat .WEECHAT_RC_OK
61
61
62
- # Registrar configuración con /set
63
- weechat .config_set_desc_plugin ("highlight_response" , "Responde automáticamente a menciones y PMs (on/off)" )
62
+ # Register configuration with /set
63
+ weechat .config_set_desc_plugin ("highlight_response" , "Automatically respond to mentions and PMs (on/off)" )
64
64
weechat .hook_config ("plugins.var.python.ollama_bot.highlight_response" , "config_callback" , "" )
65
65
66
- # Registrar comandos y hooks
67
- weechat .hook_command ("ollama" , "Pregunta algo a Ollama" , "<pregunta >" , "Ejemplo : /ollama ¿Qué es Python?" , "" , "command_ollama" , "" )
66
+ # Register commands and hooks
67
+ weechat .hook_command ("ollama" , "Ask something to Ollama" , "<question >" , "Example : /ollama What is Python?" , "" , "command_ollama" , "" )
68
68
weechat .hook_print ("" , "notify_highlight" , "" , 1 , "message_callback" , "" )
69
- weechat .hook_print ("" , "notify_message" , "" , 1 , "message_callback" , "" ) # Captura mensajes normales
69
+ weechat .hook_print ("" , "notify_message" , "" , 1 , "message_callback" , "" ) # Capture normal messages
70
70
weechat .hook_print ("" , "notify_private" , "" , 1 , "message_callback" , "" )
71
71
0 commit comments