Extracting request context creation to separate file.
This commit is contained in:
parent
d890faf461
commit
ca005a9370
33
bot/bot.go
33
bot/bot.go
|
@ -257,39 +257,6 @@ func (b *Bot) statsHandler(bot *telego.Bot, update telego.Update) {
|
|||
}
|
||||
}
|
||||
|
||||
func (b *Bot) createLlmRequestContext(update telego.Update) llm.RequestContext {
|
||||
message := update.Message
|
||||
|
||||
rc := llm.RequestContext{}
|
||||
|
||||
if message == nil {
|
||||
slog.Debug("request context creation problem: no message provided. returning empty context.", "request-context", rc)
|
||||
|
||||
return rc
|
||||
}
|
||||
|
||||
user := message.From
|
||||
if user != nil {
|
||||
rc.User = llm.UserContext{
|
||||
Username: user.Username,
|
||||
FirstName: user.FirstName,
|
||||
LastName: user.LastName,
|
||||
IsPremium: user.IsPremium,
|
||||
}
|
||||
}
|
||||
|
||||
chat := message.Chat
|
||||
rc.Chat = llm.ChatContext{
|
||||
Title: chat.Title,
|
||||
Description: chat.Description,
|
||||
Type: chat.Type,
|
||||
}
|
||||
|
||||
slog.Debug("request context created", "request-context", rc)
|
||||
|
||||
return rc
|
||||
}
|
||||
|
||||
func (b *Bot) escapeMarkdownV1Symbols(input string) string {
|
||||
return b.markdownV1Replacer.Replace(input)
|
||||
}
|
||||
|
|
58
bot/request_context.go
Normal file
58
bot/request_context.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
package bot
|
||||
|
||||
import (
|
||||
"github.com/mymmrac/telego"
|
||||
"log/slog"
|
||||
"telegram-ollama-reply-bot/llm"
|
||||
)
|
||||
|
||||
func (b *Bot) createLlmRequestContext(update telego.Update) llm.RequestContext {
|
||||
message := update.Message
|
||||
iq := update.InlineQuery
|
||||
|
||||
rc := llm.RequestContext{
|
||||
Empty: true,
|
||||
Inline: false,
|
||||
}
|
||||
|
||||
switch {
|
||||
case message == nil && iq == nil:
|
||||
slog.Debug("request context creation problem: no message provided. returning empty context.", "request-context", rc)
|
||||
|
||||
return rc
|
||||
case iq != nil:
|
||||
rc.Inline = true
|
||||
}
|
||||
|
||||
rc.Empty = false
|
||||
|
||||
var user *telego.User
|
||||
|
||||
if rc.Inline {
|
||||
user = &iq.From
|
||||
} else {
|
||||
user = message.From
|
||||
}
|
||||
|
||||
if user != nil {
|
||||
rc.User = llm.UserContext{
|
||||
Username: user.Username,
|
||||
FirstName: user.FirstName,
|
||||
LastName: user.LastName,
|
||||
IsPremium: user.IsPremium,
|
||||
}
|
||||
}
|
||||
|
||||
if !rc.Inline {
|
||||
chat := message.Chat
|
||||
rc.Chat = llm.ChatContext{
|
||||
Title: chat.Title,
|
||||
Description: chat.Description,
|
||||
Type: chat.Type,
|
||||
}
|
||||
}
|
||||
|
||||
slog.Debug("request context created", "request-context", rc)
|
||||
|
||||
return rc
|
||||
}
|
Loading…
Reference in a new issue