Skip to content

improve prompt translation support for Conversation related types#1441

Merged
jmartin-tech merged 2 commits intoNVIDIA:mainfrom
jmartin-tech:fix/msg-conv-prompt-translation
Oct 28, 2025
Merged

improve prompt translation support for Conversation related types#1441
jmartin-tech merged 2 commits intoNVIDIA:mainfrom
jmartin-tech:fix/msg-conv-prompt-translation

Conversation

@jmartin-tech
Copy link
Collaborator

Identified by @aishwaryap, when processing prompts of type Message or Conversation strict type awareness is required.

  • wrap single string in list
  • extract first result

Verification

List the steps needed to make sure this thing works

  • added test validate type check for impacted probes

* wrap single string in list
* extract first result

Signed-off-by: Jeffrey Martin <[email protected]>
@aishwaryap
Copy link
Collaborator

Can we sneak in another related bug fix here? Lines 402-418 also currently assume self.prompts is a List[str].

The correct code snippet needed here is:

for seq, prompt in enumerate(prompts):
            notes = None
            if self.langprovider.target_lang != self.lang:
                if isinstance(prompt, str):
                    notes = {
                        "pre_translation_prompt": garak.attempt.Conversation(
                            [
                                garak.attempt.Turn("user", garak.attempt.Message(prompt, lang=self.lang))
                            ]
                        )
                    }
                elif isinstance(prompt, garak.attempt.Message):
                    notes = {
                        "pre_translation_prompt": garak.attempt.Conversation(
                            [
                                garak.attempt.Turn("user", garak.attempt.Message(prompt.text, lang=self.lang))
                            ]
                        )
                    }
                elif isinstance(prompt, garak.attempt.Conversation):
                    notes = {
                        "pre_translation_prompt": prompt
                    }
                    for turn in prompt.turns:
                        turn.content.lang = self.lang
 
            attempts_todo.append(self._mint_attempt(prompt, seq, notes, lang))

Copy link
Collaborator

@leondz leondz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@leondz
Copy link
Collaborator

leondz commented Oct 28, 2025

oh, nice catch @aishwaryap !

* ensure use of a copy of the source prompt
* set language on all supported types where needed

Signed-off-by: Jeffrey Martin <[email protected]>
@jmartin-tech jmartin-tech changed the title get_text receives and returns a list improve prompt translation support for Conversation related types Oct 28, 2025
@jmartin-tech jmartin-tech merged commit 9db44ce into NVIDIA:main Oct 28, 2025
15 checks passed
@jmartin-tech jmartin-tech deleted the fix/msg-conv-prompt-translation branch October 28, 2025 20:40
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants