You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Program.cs
  3. using Aspire.Hosting.Python;
  4. using Microsoft.Extensions.Hosting;
  5. const string pythonHelloAgentPath = "../core_xlang_hello_python_agent";
  6. const string pythonHelloAgentPy = "hello_python_agent.py";
  7. const string pythonVEnv = "../../../../python/.venv";
  8. //Environment.SetEnvironmentVariable("XLANG_TEST_NO_DOTNET", "true");
  9. //Environment.SetEnvironmentVariable("XLANG_TEST_NO_PYTHON", "true");
  10. var builder = DistributedApplication.CreateBuilder(args);
  11. var backend = builder.AddProject<Projects.Microsoft_AutoGen_AgentHost>("AgentHost").WithExternalHttpEndpoints();
  12. IResourceBuilder<ProjectResource>? dotnet = null;
  13. #pragma warning disable ASPIREHOSTINGPYTHON001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
  14. IResourceBuilder<PythonAppResource>? python = null;
  15. if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("XLANG_TEST_NO_DOTNET")))
  16. {
  17. dotnet = builder.AddProject<Projects.HelloAgentTests>("HelloAgentTestsDotNET")
  18. .WithReference(backend)
  19. .WithEnvironment("AGENT_HOST", backend.GetEndpoint("https"))
  20. .WithEnvironment("STAY_ALIVE_ON_GOODBYE", "true")
  21. .WaitFor(backend);
  22. }
  23. if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("XLANG_TEST_NO_PYTHON")))
  24. {
  25. // xlang is over http for now - in prod use TLS between containers
  26. python = builder.AddPythonApp("HelloAgentTestsPython", pythonHelloAgentPath, pythonHelloAgentPy, pythonVEnv)
  27. .WithReference(backend)
  28. .WithEnvironment("AGENT_HOST", backend.GetEndpoint("http"))
  29. .WithEnvironment("STAY_ALIVE_ON_GOODBYE", "true")
  30. .WithEnvironment("GRPC_DNS_RESOLVER", "native")
  31. .WithOtlpExporter()
  32. .WaitFor(backend);
  33. if (dotnet != null) { python.WaitFor(dotnet); }
  34. }
  35. #pragma warning restore ASPIREHOSTINGPYTHON001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
  36. using var app = builder.Build();
  37. await app.StartAsync();
  38. var url = backend.GetEndpoint("http").Url;
  39. Console.WriteLine("Backend URL: " + url);
  40. if (dotnet != null) { Console.WriteLine("Dotnet Resource Projects.HelloAgentTests invoked as HelloAgentTestsDotNET"); }
  41. if (python != null) { Console.WriteLine("Python Resource hello_python_agent.py invoked as HelloAgentTestsPython"); }
  42. await app.WaitForShutdownAsync();