Skip to content

Commit 5f5ea88

Browse files
fixes #33
1 parent df44f20 commit 5f5ea88

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

README.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22

33
Milla is an IRC bot that:
44

5-
- sends things over to an LLM when you ask it questions and prints the answer with optional syntax-highlighting.<br/>
6-
Currently supported providers:
7-
8-
* Ollama
9-
* Openai
10-
* Gemini
11-
5+
- sends things over to an LLM when you ask it questions and prints the answer with optional syntax-highlighting.Currently supported providers: Ollama, Openai, Gemini <br/>
126
- Milla can run more than one instance of itself
137
- Each instance can connect to a different ircd, and will get the full set of configs, e.g. different proxies, different postgres instance, ...
148
- You can define custom commands in the form of SQL queries to the database with the SQL query result being passed to the bot along with the given prompt and an optional limit so you don't go bankrupt(unless you are running ollama locally like the smart cookie that you are).<br/>
@@ -247,13 +241,20 @@ Custom commands let you define a command that does a SQL query to the database a
247241

248242
```toml
249243
[ircd.devinet_terra.customCommands.digest]
250-
sql = "select log from liberanet_milla_us_market_news;"
251-
limit = 10
252-
prompt = "give me digest of the provided news"
244+
sql = "select log from liberanet_milla_us_market_news order by log desc;"
245+
limit = 300
246+
context = ["you are a sentiment-analysis bot"]
247+
prompt= "i have provided to you news headlines in the form of previous conversations between you and me using the user role. please provide the digest of the news for me."
253248
[ircd.devinet_terra.customCommands.summarize]
254-
sql= "select log from liberanet_milla_us_market_news;"
249+
sql= "select log from liberanet_milla_us_market_news order by log desc;"
255250
limit= 300
256-
prompt= "given all the data, summarize the news for me"
251+
context = ["you are a sentiment-analysis bot"]
252+
prompt= "i have provided to you news headlines in the form of previous conversations between you and me using the user role. please summarize the provided news for me. provide some details."
253+
[ircd.devinet_terra.customCommands.canada]
254+
sql= "select log from liberanet_milla_us_market_news order by log desc;"
255+
limit= 300
256+
context = ["you are a canadian news anchor", "you only care about news that is relevant to canada"]
257+
prompt= "i have provided to you news headlines in the form of previous conversations between you and me using the user role. please summarize the provided news for me. provide some details."
257258
```
258259

259260
In the above example digest and summarize will be the names of the commands: `milla: /cmd summarize`.<br/>

main.go

+38-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ func getTableFromChanName(channel, ircdName string) string {
113113
return tableName
114114
}
115115

116+
func stripColorCodes(input string) string {
117+
re := regexp.MustCompile(`\x1b\[[0-9;]*m`)
118+
input = re.ReplaceAllString(input, "")
119+
re = regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?`)
120+
input = re.ReplaceAllString(input, "")
121+
122+
return input
123+
}
124+
116125
func sanitizeLog(log string) string {
117126
sanitizeLog := strings.ReplaceAll(log, "'", " ")
118127

@@ -328,6 +337,18 @@ func handleCustomCommand(
328337
})
329338
}
330339

340+
for _, customContext := range customCommand.Context {
341+
gptMemory = append(gptMemory, openai.ChatCompletionMessage{
342+
Role: openai.ChatMessageRoleUser,
343+
Content: customContext,
344+
})
345+
}
346+
347+
var bigPrompt string
348+
for _, log := range logs {
349+
bigPrompt += log.Log + "\n"
350+
}
351+
331352
result := ChatGPTRequestProcessor(appConfig, client, event, &gptMemory, customCommand.Prompt)
332353
if result != "" {
333354
sendToIRC(client, event, result, appConfig.ChromaFormatter)
@@ -344,6 +365,15 @@ func handleCustomCommand(
344365
})
345366
}
346367

368+
for _, customContext := range customCommand.Context {
369+
geminiMemory = append(geminiMemory, &genai.Content{
370+
Parts: []genai.Part{
371+
genai.Text(customContext),
372+
},
373+
Role: "user",
374+
})
375+
}
376+
347377
result := GeminiRequestProcessor(appConfig, client, event, &geminiMemory, customCommand.Prompt)
348378
if result != "" {
349379
sendToIRC(client, event, result, appConfig.ChromaFormatter)
@@ -358,6 +388,13 @@ func handleCustomCommand(
358388
})
359389
}
360390

391+
for _, customContext := range customCommand.Context {
392+
ollamaMemory = append(ollamaMemory, MemoryElement{
393+
Role: "user",
394+
Content: customContext,
395+
})
396+
}
397+
361398
result := OllamaRequestProcessor(appConfig, client, event, &ollamaMemory, customCommand.Prompt)
362399
if result != "" {
363400
sendToIRC(client, event, result, appConfig.ChromaFormatter)
@@ -996,7 +1033,7 @@ func scrapeChannel(irc *girc.Client, poolChan chan *pgxpool.Pool, appConfig Toml
9961033
"insert into %s (channel,log,nick) values ('%s','%s','%s')",
9971034
tableName,
9981035
sanitizeLog(event.Params[0]),
999-
event.Last(),
1036+
stripColorCodes(event.Last()),
10001037
event.Source.Name,
10011038
)
10021039

plugins/rss.lua

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env lua5.1
2-
31
local milla = require("milla")
42
local yaml = require("yaml")
53
local http = require("http")

types.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ type LogModel struct {
1717
}
1818

1919
type CustomCommand struct {
20-
SQL string `toml:"sql"`
21-
Limit int `toml:"limit"`
22-
Prompt string `toml:"prompt"`
20+
SQL string `toml:"sql"`
21+
Limit int `toml:"limit"`
22+
Context []string `toml:"context"`
23+
Prompt string `toml:"prompt"`
2324
}
2425

2526
type LuaLstates struct {

0 commit comments

Comments
 (0)