diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-02 21:59:36 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-02 21:59:36 +0300 |
| commit | 74383d0e31fee5aebec002971ebd2cbddad32ac7 (patch) | |
| tree | 06663e2fa2d515b1ee1e26840417f5d193a71430 /internal/image/openai.go | |
| parent | d94fdaf92d7c66c012e819c73632be16f346b66f (diff) | |
task 009/00i: remove internal translation from image clients; consolidate provider normalization
- task 009: remove translateBulgarianToEnglish from OpenAIClient and
NanoBananaClient. Image clients no longer make internal translation API calls;
callers must supply SearchOptions.Translation (processor and GUI already do).
When translation is absent, opts.Query (the Bulgarian word) is used as
fallback subject so image generation still proceeds. Update tests to pass
translation via SearchOptions rather than relying on the removed fallback.
- task 00i: consolidate duplicate ProviderGemini/ProviderOpenAI constants and
normalizeProvider() functions from internal/translation and internal/phonetic
into a shared config.NormalizeProvider(string) string in
internal/config/provider.go. Both packages now delegate to the shared
function so the normalization rule (lowercase, trim, default "gemini") has
one authoritative home.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/image/openai.go')
| -rw-r--r-- | internal/image/openai.go | 56 |
1 files changed, 10 insertions, 46 deletions
diff --git a/internal/image/openai.go b/internal/image/openai.go index fdd88e4..8623fcd 100644 --- a/internal/image/openai.go +++ b/internal/image/openai.go @@ -89,21 +89,17 @@ func (c *OpenAIClient) Search(ctx context.Context, opts *SearchOptions) ([]Searc } } - // Use provided translation if available, otherwise translate Bulgarian word to English - var translatedWord string - if opts.Translation != "" { - // Use the translation that was already provided (from UI or user input) - translatedWord = opts.Translation - fmt.Printf("Using provided translation: %s -> %s\n", opts.Query, translatedWord) + // Use the caller-provided translation. Translating internally would couple + // the image package to the OpenAI chat API for a concern that belongs in + // the translation package. Callers (processor, GUI) already resolve the + // English translation before calling Search. + translatedWord := opts.Translation + if translatedWord == "" { + // No translation provided — fall back to the original query word so + // image generation still proceeds, albeit potentially with lower quality. + translatedWord = opts.Query } else { - // Translate Bulgarian word to English for better results - var err error - translatedWord, err = c.translateBulgarianToEnglish(ctx, opts.Query) - if err != nil { - // If translation fails, fall back to using the original word - fmt.Printf("Translation failed: %v, using original word\n", err) - translatedWord = opts.Query - } + fmt.Printf("Using provided translation: %s -> %s\n", opts.Query, translatedWord) } // Create prompt - use custom if provided, otherwise generate educational prompt @@ -274,38 +270,6 @@ func (c *OpenAIClient) createEducationalPrompt(ctx context.Context, bulgarianWor return buildEducationalPrompt(selectedStyle, scene, subject) } -// translateBulgarianToEnglish translates a Bulgarian word to English using OpenAI -func (c *OpenAIClient) translateBulgarianToEnglish(ctx context.Context, word string) (string, error) { - // Use OpenAI chat completion to translate - fmt.Printf("OpenAI Translation: Using model 'gpt-4o-mini' to translate '%s'\n", word) - - req := openai.ChatCompletionRequest{ - Model: openai.GPT4oMini, - Messages: []openai.ChatCompletionMessage{ - { - Role: openai.ChatMessageRoleUser, - Content: fmt.Sprintf("Translate the Bulgarian word '%s' to English. Respond with only the English translation, nothing else.", word), - }, - }, - Temperature: 0.3, // Lower temperature for more consistent translations - MaxTokens: 50, - } - - resp, err := c.client.CreateChatCompletion(ctx, req) - if err != nil { - return "", fmt.Errorf("translation failed: %w", err) - } - - if len(resp.Choices) == 0 || resp.Choices[0].Message.Content == "" { - return "", fmt.Errorf("no translation received") - } - - translation := strings.TrimSpace(resp.Choices[0].Message.Content) - fmt.Printf("Translated '%s' to '%s'\n", word, translation) - - return translation, nil -} - // generateSceneDescription generates a contextual scene description for the word func (c *OpenAIClient) generateSceneDescription(ctx context.Context, bulgarianWord, englishTranslation string) (string, error) { // Use OpenAI to generate a scene description |
