Skip to content

Commit

Permalink
send custom message
Browse files Browse the repository at this point in the history
  • Loading branch information
radiantspace committed May 18, 2024
1 parent 311e4b0 commit 4d91934
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 127 deletions.
24 changes: 24 additions & 0 deletions backend/app/db/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Client struct {
type MongoClient interface {
Disconnect(ctx context.Context) error
GetUser(ctx context.Context) (*models.MongoUser, error)
GetUserIds(ctx context.Context, page int, pageSize int) ([]string, error)
GetUsersCount(ctx context.Context) (int64, error)
GetUsersCountForSubscription(ctx context.Context, subscription string) (int64, error)
MigrateUsersToSubscription(ctx context.Context, from, to string) error
Expand Down Expand Up @@ -189,3 +190,26 @@ func (c *Client) UpdateUserStripeCustomerId(ctx context.Context, stripeCustomerI
_, err := collection.UpdateOne(ctx, filter, update, options)
return err
}

func (c *Client) GetUserIds(ctx context.Context, page int, pageSize int) ([]string, error) {
collection := c.Database(config.CONFIG.MongoDBName).Collection("users")
findOptions := options.Find()
findOptions.SetSkip(int64(page * pageSize))
findOptions.SetLimit(int64(pageSize))
cursor, err := collection.Find(ctx, bson.M{}, findOptions)
if err != nil {
return nil, fmt.Errorf("GetUserIds: failed to find users: %w", err)
}
defer cursor.Close(ctx)

var userIds []string
for cursor.Next(ctx) {
var user models.MongoUser
err := cursor.Decode(&user)
if err != nil {
return nil, fmt.Errorf("GetUserIds: failed to decode user: %w", err)
}
userIds = append(userIds, user.ID)
}
return userIds, nil
}
4 changes: 3 additions & 1 deletion backend/app/lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func AddBotSuffixToGroupCommands(ctx context.Context, message string) string {
client := ctx.Value(models.ClientContext{}).(string)
if client == string(TelegramClientName) && strings.HasPrefix(chatString, "-") {
message = strings.ReplaceAll(message, "/chatgpt", "/chatgpt@"+config.CONFIG.BotName)
message = strings.ReplaceAll(message, "/voicegpt", "/voicegpt@"+config.CONFIG.BotName)
message = strings.ReplaceAll(message, "/clear", "/clear@"+config.CONFIG.BotName)
message = strings.ReplaceAll(message, "/downgrade", "/downgrade@"+config.CONFIG.BotName)
message = strings.ReplaceAll(message, "/grammar", "/grammar@"+config.CONFIG.BotName)
Expand All @@ -132,7 +133,8 @@ func AddBotSuffixToGroupCommands(ctx context.Context, message string) string {
message = strings.ReplaceAll(message, "/terms", "/terms@"+config.CONFIG.BotName)
message = strings.ReplaceAll(message, "/transcribe", "/transcribe@"+config.CONFIG.BotName)
message = strings.ReplaceAll(message, "/upgrade", "/upgrade@"+config.CONFIG.BotName)
message = strings.ReplaceAll(message, "/voicegpt", "/voicegpt@"+config.CONFIG.BotName)
message = strings.ReplaceAll(message, "/translate", "/translate@"+config.CONFIG.BotName)
message = strings.ReplaceAll(message, "/billing", "/billing@"+config.CONFIG.BotName)
}
return message
}
10 changes: 10 additions & 0 deletions backend/app/lib/modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ var summarizeSeed = []models.Message{
},
}

var translateSeed = []models.Message{
{
Role: "system",
Content: "You will translate a text to {{target}} only. You will keep the meaning and style of the original text. If the original text is not in a {{target}}, you will translate it to {{target}}. If the original text is in {{target}}, you will respond - [correct].",
},
}

func GetSeedDataAndPrimer(mode ModeName) ([]models.Message, string) {
var seedData []models.Message
userMessagePrimer := "Text to correct:\n" //default
Expand All @@ -197,6 +204,9 @@ func GetSeedDataAndPrimer(mode ModeName) ([]models.Message, string) {
case Summarize:
seedData = summarizeSeed
userMessagePrimer = ""
case Translate:
seedData = translateSeed
userMessagePrimer = "Text to translate to {{target}}:\n"
default:
seedData = chatGPTSeed
userMessagePrimer = ""
Expand Down
23 changes: 12 additions & 11 deletions backend/app/telegram/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,24 @@ Here are some of the things I can do:
Enjoy and let me know if any /support is needed!`

const (
CancelSubscriptionCommand Command = "/downgrade"
EmiliCommand Command = "/emily"
EmptyCommand Command = ""
StartCommand Command = "/start"
ChatGPTCommand Command = "/chatgpt"
VoiceGPTCommand Command = "/voicegpt"
GrammarCommand Command = "/grammar"
StartCommand Command = "/start"
ClearThreadCommand Command = "/clear"
TeacherCommand Command = "/teacher"
TranscribeCommand Command = "/transcribe"
SummarizeCommand Command = "/summarize"
TranslateCommand Command = "/translate"
StatusCommand Command = "/status"
SupportCommand Command = "/support"
TermsCommand Command = "/terms"
TeacherCommand Command = "/teacher"
UpgradeCommand Command = "/upgrade"
VasilisaCommand Command = "/vasilisa"
TranscribeCommand Command = "/transcribe"
SummarizeCommand Command = "/summarize"
ClearThreadCommand Command = "/clear"
CancelSubscriptionCommand Command = "/downgrade"
BillingCommand Command = "/billing"
VasilisaCommand Command = "/vasilisa"
EmiliCommand Command = "/emily"
EmptyCommand Command = ""

// commands setting for BotFather
Commands string = `
Expand Down Expand Up @@ -634,8 +635,8 @@ func IsCreateImageCommand(prompt string) bool {

log.Debugf("Cleaned prompt: %s", cleanPrompt)

triggerWords := []string{"create", "draw", "picture", "imagine", "image"}
stopWords := []string{"text", "write", "article"}
triggerWords := []string{"create", "draw", "drawing", "picture", "imagine", "image"}
stopWords := []string{"write", "article"}

// Split the prompt into words
words := strings.Fields(cleanPrompt)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/telegram/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

func TestIsCreateImageCommandTrue(t *testing.T) {
prompts := []string{
"Can you create a drawin of a sunset?",
"Can you create an image of a sunset?",
"Draw, please, an image of a cat",
"I'd like a picture! Of a mountain",
Expand All @@ -31,7 +32,6 @@ func TestIsCreateImageCommandTrue(t *testing.T) {

func TestIsCreateImageCommandFalse(t *testing.T) {
prompts := []string{
"Can you create a text?",
"Imagene, please, an article about a cat",
"I'd like a video! Of a mountain",
}
Expand Down
Loading

0 comments on commit 4d91934

Please sign in to comment.