()
| 20 | |
| 21 | |
| 22 | async def main(): |
| 23 | msg = input_with_fallback( |
| 24 | "Hi! Enter a message, and we'll translate it to Spanish.\n\n", |
| 25 | "Good morning!", |
| 26 | ) |
| 27 | |
| 28 | # Ensure the entire workflow is a single trace |
| 29 | with trace("Parallel translation"): |
| 30 | res_1, res_2, res_3 = await asyncio.gather( |
| 31 | Runner.run( |
| 32 | spanish_agent, |
| 33 | msg, |
| 34 | ), |
| 35 | Runner.run( |
| 36 | spanish_agent, |
| 37 | msg, |
| 38 | ), |
| 39 | Runner.run( |
| 40 | spanish_agent, |
| 41 | msg, |
| 42 | ), |
| 43 | ) |
| 44 | |
| 45 | outputs = [ |
| 46 | ItemHelpers.text_message_outputs(res_1.new_items), |
| 47 | ItemHelpers.text_message_outputs(res_2.new_items), |
| 48 | ItemHelpers.text_message_outputs(res_3.new_items), |
| 49 | ] |
| 50 | |
| 51 | translations = "\n\n".join(outputs) |
| 52 | print(f"\n\nTranslations:\n\n{translations}") |
| 53 | |
| 54 | best_translation = await Runner.run( |
| 55 | translation_picker, |
| 56 | f"Input: {msg}\n\nTranslations:\n{translations}", |
| 57 | ) |
| 58 | |
| 59 | print("\n\n-----") |
| 60 | |
| 61 | print(f"Best translation: {best_translation.final_output}") |
| 62 | |
| 63 | |
| 64 | if __name__ == "__main__": |
no test coverage detected