import asyncio, pathlib, textwrap, os SRC = pathlib.Path(__file__).with_name("app_adk.py") def build_wrapped_source(src_text: str) -> str: # Indent the user's script under an async function so top-level 'await' works indented = textwrap.indent(src_text, " ") return ( "import asyncio\n" "async def __entry__():\n" f"{indented}\n" "asyncio.run(__entry__())\n" ) def main(): code_text = SRC.read_text(encoding="utf-8") wrapped = build_wrapped_source(code_text) # Prepare a __main__-like global namespace g = { "__name__": "__main__", "__file__": str(SRC), "__package__": None, "__spec__": None, "__doc__": None, "__cached__": None, } # *** Inject MODEL_GPT to point LiteLLM at Azure without touching your script *** deployment = os.getenv("AZURE_OPENAI_DEPLOYMENT", "gpt-4o-mini") g["MODEL_GPT"] = f"azure/{deployment}" # Execute the wrapped script exec(compile(wrapped, str(SRC), "exec"), g, g) if __name__ == "__main__": main()