(input: ChatCompletionCreateParams)
| 68 | |
| 69 | // Fall back to our own Azure instance for long-running requests |
| 70 | export async function getAzureGpt4Completion(input: ChatCompletionCreateParams) { |
| 71 | const models = ["gpt-4", "gpt-4-turbo", "gpt-4-32k"] as const; |
| 72 | let lastError; |
| 73 | for (const model of models) { |
| 74 | const client = getEndpointForModel(model).client; |
| 75 | |
| 76 | try { |
| 77 | return client.chat.completions.create({ |
| 78 | ...input, |
| 79 | model, |
| 80 | stream: false, |
| 81 | }); |
| 82 | } catch (error) { |
| 83 | if (error instanceof APIError && error.status === 429) { |
| 84 | // store error to throw if all models fail |
| 85 | lastError = error; |
| 86 | continue; |
| 87 | } |
| 88 | console.log("ERROR:", error); |
| 89 | throw error; |
| 90 | } |
| 91 | } |
| 92 | throw lastError; |
| 93 | } |
| 94 | |
| 95 | const azureGpt4Endpoints: readonly { |
| 96 | apiBase: string; |
no test coverage detected