Files
warmbly/internal/pkg/generation/conversation.go
T
Máté Mészáros (Laptop) 4a1c8cddeb AI integration & warmup task
2026-01-24 12:31:22 +01:00

57 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package generation
import (
"context"
"encoding/json"
"fmt"
"github.com/openai/openai-go/v2"
)
var ConversationSchema = GenerateSchema[Conversation]()
func (c *GenerationClient) GenerateConversation(ctx context.Context, theme string) (*Conversation, error) {
systemPrompt := fmt.Sprintf(`
Output valid JSON only.
Positive realistic warmup email thread for theme: %s
- Friendly colleague tone, occasional 😊👍, always ask questions to continue
- Use {{.FirstName}} {{.LastName}} {{.Email}} {{.Company}} {{.Signature}} naturally
- Every body = only text sender writes + {{.Signature}} at end (no headers, no quotes, no "On ...")
- Aim for 1014 messages total across branches
- Include at least 4 branch points with 24 variants each (short/long/different questions)
- Keep replies natural & positive
`, theme)
schemaParam := openai.ResponseFormatJSONSchemaJSONSchemaParam{
Name: "conversation",
Description: openai.String("Realistic branched email warmup thread"),
Schema: ConversationSchema,
Strict: openai.Bool(true),
}
req := openai.ChatCompletionNewParams{
Model: openai.ChatModelGPT4oMini,
Messages: []openai.ChatCompletionMessageParamUnion{
openai.SystemMessage(systemPrompt),
openai.UserMessage("Generate one complete thread now."),
},
ResponseFormat: openai.ChatCompletionNewParamsResponseFormatUnion{
OfJSONSchema: &openai.ResponseFormatJSONSchemaParam{JSONSchema: schemaParam},
},
}
resp, err := c.client.Chat.Completions.New(ctx, req)
if err != nil {
return nil, err
}
var parsed Conversation
if err := json.Unmarshal([]byte(resp.Choices[0].Message.Content), &parsed); err != nil {
return nil, err
}
return &parsed, nil
}