gigachat #8
@ -1095,3 +1095,11 @@ ORDER BY (q.session != '') ASC, --без сессии первые потом с
|
||||
-- name: GetQuestionsAICount :one
|
||||
SELECT COUNT(*) AS count FROM question WHERE quiz_id = $1 AND (session = $2 OR session = '') AND deleted = FALSE;
|
||||
|
||||
-- name: CreateQuizAudience :one
|
||||
INSERT INTO gigachatAudience (QuizID, Sex, Age) VALUES ($1, $2, $3) RETURNING ID;
|
||||
|
||||
-- name: GetQuizAudience :many
|
||||
SELECT * FROM gigachatAudience WHERE QuizID = $1 AND Deleted = FALSE;
|
||||
|
||||
-- name: DeleteQuizAudience :exec
|
||||
UPDATE gigachatAudience set Deleted = TRUE WHERE QuizID = $1;
|
||||
|
||||
1
dal/schema/000018_init.down.sql
Normal file
1
dal/schema/000018_init.down.sql
Normal file
@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS gigachatAudience;
|
||||
9
dal/schema/000018_init.up.sql
Normal file
9
dal/schema/000018_init.up.sql
Normal file
@ -0,0 +1,9 @@
|
||||
CREATE TABLE IF NOT EXISTS gigachatAudience (
|
||||
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
|
||||
QuizID BIGINT NOT NULL,
|
||||
Sex BOOLEAN NOT NULL,
|
||||
Age VARCHAR(5) NOT NULL,
|
||||
Deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT fk_quiz FOREIGN KEY (QuizID) REFERENCES quiz(ID)
|
||||
);
|
||||
@ -81,6 +81,15 @@ type Field struct {
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
type Gigachataudience struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Quizid int64 `db:"quizid" json:"quizid"`
|
||||
Sex bool `db:"sex" json:"sex"`
|
||||
Age string `db:"age" json:"age"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
type Pipeline struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Amoid int32 `db:"amoid" json:"amoid"`
|
||||
|
||||
@ -716,6 +716,23 @@ func (q *Queries) CreateAmoAccount(ctx context.Context, arg CreateAmoAccountPara
|
||||
return err
|
||||
}
|
||||
|
||||
const createQuizAudience = `-- name: CreateQuizAudience :one
|
||||
INSERT INTO gigachatAudience (QuizID, Sex, Age) VALUES ($1, $2, $3) RETURNING ID
|
||||
`
|
||||
|
||||
type CreateQuizAudienceParams struct {
|
||||
Quizid int64 `db:"quizid" json:"quizid"`
|
||||
Sex bool `db:"sex" json:"sex"`
|
||||
Age string `db:"age" json:"age"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateQuizAudience(ctx context.Context, arg CreateQuizAudienceParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, createQuizAudience, arg.Quizid, arg.Sex, arg.Age)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const createWebHook = `-- name: CreateWebHook :exec
|
||||
INSERT INTO tokens (AccountID, RefreshToken, AccessToken, AuthCode, Expiration, CreatedAt)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
@ -838,6 +855,15 @@ func (q *Queries) DeleteQuestion(ctx context.Context, id int64) (Question, error
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteQuizAudience = `-- name: DeleteQuizAudience :exec
|
||||
UPDATE gigachatAudience set Deleted = TRUE WHERE QuizID = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteQuizAudience(ctx context.Context, quizid int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteQuizAudience, quizid)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteQuizByID = `-- name: DeleteQuizByID :one
|
||||
UPDATE quiz SET deleted=true WHERE quiz.id=$1 AND accountid=$2 RETURNING quiz.id, quiz.qid, quiz.accountid, quiz.deleted, quiz.archived, quiz.fingerprinting, quiz.repeatable, quiz.note_prevented, quiz.mail_notifications, quiz.unique_answers, quiz.super, quiz.group_id, quiz.name, quiz.description, quiz.config, quiz.status, quiz.limit_answers, quiz.due_to, quiz.time_of_passing, quiz.pausable, quiz.version, quiz.version_comment, quiz.parent_ids, quiz.created_at, quiz.updated_at, quiz.questions_count, quiz.answers_count, quiz.average_time_passing, quiz.sessions_count
|
||||
`
|
||||
@ -2177,6 +2203,40 @@ func (q *Queries) GetQuestionsAICount(ctx context.Context, arg GetQuestionsAICou
|
||||
return count, err
|
||||
}
|
||||
|
||||
const getQuizAudience = `-- name: GetQuizAudience :many
|
||||
SELECT id, quizid, sex, age, deleted, createdat FROM gigachatAudience WHERE QuizID = $1 AND Deleted = FALSE
|
||||
`
|
||||
|
||||
func (q *Queries) GetQuizAudience(ctx context.Context, quizid int64) ([]Gigachataudience, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getQuizAudience, quizid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Gigachataudience
|
||||
for rows.Next() {
|
||||
var i Gigachataudience
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Quizid,
|
||||
&i.Sex,
|
||||
&i.Age,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getQuizById = `-- name: GetQuizById :one
|
||||
SELECT id, qid, accountid, deleted, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, super, group_id, name, description, config, status, limit_answers, due_to, time_of_passing, pausable, version, version_comment, parent_ids, created_at, updated_at, questions_count, answers_count, average_time_passing, sessions_count FROM quiz WHERE id=$1 AND accountId=$2
|
||||
`
|
||||
|
||||
49
model/gigachat.go
Normal file
49
model/gigachat.go
Normal file
@ -0,0 +1,49 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type GigaChatMessage struct {
|
||||
Role string `json:"role"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type GigaChatRequest struct {
|
||||
Model string `json:"model"`
|
||||
Stream bool `json:"stream"`
|
||||
UpdateInterval int `json:"update_interval"`
|
||||
Messages []GigaChatMessage `json:"messages"`
|
||||
}
|
||||
|
||||
type GigaChatResponse struct {
|
||||
Choices []struct {
|
||||
Message struct {
|
||||
Role string `json:"role"`
|
||||
Content string `json:"content"`
|
||||
} `json:"message"`
|
||||
} `json:"choices"`
|
||||
}
|
||||
|
||||
const CreatePrompt = `Ты маркетолог и копирайтер. Твоя задача — переформулировать маркетинговый вопрос так, чтобы он лучше подходил определённой целевой аудитории по полу и возрасту.
|
||||
Ответ должен строго состоять из двух строк:
|
||||
|
||||
{
|
||||
"title": "<переформулированный заголовок>",
|
||||
"description": "<переформулированное описание>"
|
||||
}
|
||||
|
||||
Я напишу возраст, пол, заголовок и описание вопроса, а ты вернёшь только отформатированный результат.`
|
||||
|
||||
var ReworkQuestionPrompt string = "%s %s пол.\n%s\n%s"
|
||||
|
||||
var EmptyResponseErrorGigaChat = errors.New("empty response from GigaChat try again")
|
||||
|
||||
type GigaChatAudience struct {
|
||||
ID int64 `json:"id"`
|
||||
QuizID int64 `json:"quiz_id"`
|
||||
Sex bool `json:"sex"` // false - female, true - male
|
||||
Age string `json:"age"`
|
||||
Deleted bool `json:"deleted"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
}
|
||||
@ -6,10 +6,10 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lib/pq"
|
||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||||
"gitea.pena/SQuiz/common/model"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"strings"
|
||||
"sync"
|
||||
@ -651,3 +651,50 @@ func (r *QuizRepository) TemplateCopy(ctx context.Context, accountID, qID string
|
||||
|
||||
return quizID, nil
|
||||
}
|
||||
|
||||
type DepsCreateQuizAudience struct {
|
||||
QuizID int64 `json:"quiz_id"`
|
||||
Sex bool `json:"sex"` // false - female, true - male
|
||||
Age string `json:"age"`
|
||||
}
|
||||
|
||||
func (r *QuizRepository) CreateQuizAudience(ctx context.Context, audience DepsCreateQuizAudience) (int64, error) {
|
||||
result, err := r.queries.CreateQuizAudience(ctx, sqlcgen.CreateQuizAudienceParams{
|
||||
Quizid: audience.QuizID,
|
||||
Sex: audience.Sex,
|
||||
Age: audience.Age,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *QuizRepository) GetQuizAudience(ctx context.Context, quizID int64) ([]model.GigaChatAudience, error) {
|
||||
rows, err := r.queries.GetQuizAudience(ctx, quizID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var audiences []model.GigaChatAudience
|
||||
for _, row := range rows {
|
||||
audiences = append(audiences, model.GigaChatAudience{
|
||||
ID: row.ID,
|
||||
QuizID: row.ID,
|
||||
Sex: row.Sex,
|
||||
Age: row.Age,
|
||||
Deleted: row.Deleted,
|
||||
CreatedAt: row.Createdat.Time.Unix(),
|
||||
})
|
||||
}
|
||||
|
||||
return audiences, nil
|
||||
}
|
||||
|
||||
func (r *QuizRepository) DeleteQuizAudience(ctx context.Context, quizID int64) error {
|
||||
err := r.queries.DeleteQuizAudience(ctx, quizID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -36,6 +36,8 @@ packages:
|
||||
- "./dal/schema/000016_init.down.sql"
|
||||
- "./dal/schema/000017_init.up.sql"
|
||||
- "./dal/schema/000017_init.down.sql"
|
||||
- "./dal/schema/000018_init.up.sql"
|
||||
- "./dal/schema/000018_init.down.sql"
|
||||
engine: "postgresql"
|
||||
emit_json_tags: true
|
||||
emit_db_tags: true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user