This commit is contained in:
2026-02-01 18:24:19 +03:00
parent e60555df02
commit 21c46ff2c1
2 changed files with 11 additions and 5 deletions

View File

@@ -3,9 +3,9 @@ services:
build: . build: .
environment: environment:
BOT_TOKEN: "" BOT_TOKEN: ""
CHAT_ID: "" CHAT_ID: -1003268915330
CHANNEL_ID: -1003290014225 CHANNEL_ID: -1003290014225
OPENAI_BASE_URL: http://localhost:8080/v1 OPENAI_BASE_URL: http://llama-server:8080/v1
SYSTEM_PROMPT_PATH: /etc/sysprompt.txt SYSTEM_PROMPT_PATH: /etc/sysprompt.txt
MAX_CONCURRENT_REQUESTS: 2 MAX_CONCURRENT_REQUESTS: 2
volumes: volumes:

12
main.go
View File

@@ -21,12 +21,17 @@ import (
type OpenAIPrompter struct { type OpenAIPrompter struct {
cli openai.Client cli openai.Client
cfg *Config cfg *Config
log *slog.Logger
} }
func (p *OpenAIPrompter) Prompt(ctx context.Context, req PromptRequest) (*HighlyTrustedResponse, error) { func (p *OpenAIPrompter) Prompt(ctx context.Context, req PromptRequest) (*HighlyTrustedResponse, error) {
p.log.Info("new prompt request",
"req", req)
instructions := p.cfg.SystemPrompt instructions := p.cfg.SystemPrompt
if req.OriginalPostContent != nil { if req.OriginalPostContent != nil {
instructions += fmt.Sprintf("\nThis is the channel post that user is mentioning: %s", *req.OriginalPostContent) instructions += fmt.Sprintf("\nThis is the channel post that user is mentioning: %s", *req.OriginalPostContent)
p.log.Info("composed instructions with post", "instructions", instructions)
} }
resp, err := p.cli.Responses.New(ctx, responses.ResponseNewParams{ resp, err := p.cli.Responses.New(ctx, responses.ResponseNewParams{
@@ -47,12 +52,13 @@ func (p *OpenAIPrompter) Prompt(ctx context.Context, req PromptRequest) (*Highly
}, nil }, nil
} }
func NewOpenAIProoooompter(cfg *Config) *OpenAIPrompter { func NewOpenAIProoooompter(cfg *Config, log *slog.Logger) *OpenAIPrompter {
return &OpenAIPrompter{ return &OpenAIPrompter{
cli: openai.NewClient( cli: openai.NewClient(
option.WithBaseURL(cfg.OpenAIBaseURL), option.WithBaseURL(cfg.OpenAIBaseURL),
), ),
cfg: cfg, cfg: cfg,
log: log,
} }
} }
@@ -104,7 +110,7 @@ func (a *App) handleMessage(ctx context.Context, msg *tgbotapi.Message) error {
) )
var ogPostContent *string var ogPostContent *string
if msg.ReplyToMessage.From.ID == a.config.ChannelID { if msg.ReplyToMessage != nil && msg.ReplyToMessage.SenderChat.ID == a.config.ChannelID {
a.log.Info("message was a reply to channel post") a.log.Info("message was a reply to channel post")
ogPostContent = &msg.ReplyToMessage.Text ogPostContent = &msg.ReplyToMessage.Text
} }
@@ -250,7 +256,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
prompter := NewOpenAIProoooompter(&cfg) prompter := NewOpenAIProoooompter(&cfg, log)
app, err := NewApp(&cfg, prompter) app, err := NewApp(&cfg, prompter)
if err != nil { if err != nil {