azure-utils.ts 950 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * Utility functions for Azure OpenAI tests
  3. */
  4. function parseDeploymentNameMap(value: string | undefined): Map<string, string> {
  5. const map = new Map<string, string>();
  6. if (!value) return map;
  7. for (const entry of value.split(",")) {
  8. const trimmed = entry.trim();
  9. if (!trimmed) continue;
  10. const [modelId, deploymentName] = trimmed.split("=", 2);
  11. if (!modelId || !deploymentName) continue;
  12. map.set(modelId.trim(), deploymentName.trim());
  13. }
  14. return map;
  15. }
  16. export function hasAzureOpenAICredentials(): boolean {
  17. const hasKey = !!process.env.AZURE_OPENAI_API_KEY;
  18. const hasBaseUrl = !!(process.env.AZURE_OPENAI_BASE_URL || process.env.AZURE_OPENAI_RESOURCE_NAME);
  19. return hasKey && hasBaseUrl;
  20. }
  21. export function resolveAzureDeploymentName(modelId: string): string | undefined {
  22. const mapValue = process.env.AZURE_OPENAI_DEPLOYMENT_NAME_MAP;
  23. if (!mapValue) return undefined;
  24. return parseDeploymentNameMap(mapValue).get(modelId);
  25. }