All files / src/providers/openai utils.ts

100% Statements 4/4
100% Branches 2/2
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                                      53x 2x 2x   51x    
/**
 * Builds a URL by appending an endpoint to a base URL.
 * Handles query parameters correctly by inserting the endpoint before the query string.
 *
 * @param baseUrl - The base URL (may include query parameters)
 * @param endpoint - The endpoint path to append (e.g., '/chat/completions')
 * @returns The complete URL
 *
 * @example
 * // Standard URL
 * buildUrl('https://api.openai.com/v1', '/chat/completions')
 * // => 'https://api.openai.com/v1/chat/completions'
 *
 * @example
 * // URL with query params (Azure)
 * buildUrl('https://resource.azure.com/openai/deployments/gpt-4?api-version=2024-08-01', '/chat/completions')
 * // => 'https://resource.azure.com/openai/deployments/gpt-4/chat/completions?api-version=2024-08-01'
 */
export function buildUrl(baseUrl: string, endpoint: string): string {
  if (baseUrl.includes("?")) {
    const [basePath, queryString] = baseUrl.split("?");
    return `${basePath}${endpoint}?${queryString}`;
  }
  return `${baseUrl}${endpoint}`;
}