empty chat completion for custom non things

This commit is contained in:
Dallin Romney 2025-05-15 18:57:43 -07:00
parent 1a47f96259
commit 88d2bf2fa0
3 changed files with 31 additions and 0 deletions

View file

@ -12,6 +12,7 @@ import {
import { ChatCompletionCreateParams } from "openai/src/resources/index.js";
import { AnthropicConfig } from "../types.js";
import { chatChunk, chatChunkFromDelta, customFetch } from "../util.js";
import { EMPTY_CHAT_COMPLETION } from "../util/emptyChatCompletion.js";
import {
BaseLlmApi,
CreateRerankResponse,
@ -157,6 +158,10 @@ export class AnthropicApi implements BaseLlmApi {
},
);
if (response.status === 499) {
return EMPTY_CHAT_COMPLETION;
}
const completion = (await response.json()) as any;
return {
id: completion.id,

View file

@ -15,6 +15,7 @@ import {
} from "openai/resources/index";
import { CohereConfig } from "../types.js";
import { chatCompletion, customFetch, embedding } from "../util.js";
import { EMPTY_CHAT_COMPLETION } from "../util/emptyChatCompletion.js";
import {
BaseLlmApi,
CreateRerankResponse,
@ -77,6 +78,10 @@ export class CohereApi implements BaseLlmApi {
},
);
if (resp.status === 499) {
return EMPTY_CHAT_COMPLETION;
}
const data = (await resp.json()) as any;
const { input_tokens, output_tokens } = data.meta.tokens;
return chatCompletion({

View file

@ -0,0 +1,21 @@
import { ChatCompletion } from "openai/resources/index";
export const EMPTY_CHAT_COMPLETION: ChatCompletion = {
choices: [
{
finish_reason: "stop",
index: 0,
logprobs: null,
message: {
content: null,
role: "assistant",
refusal: null,
},
},
],
usage: undefined,
created: Date.now(),
id: "",
model: "UNSPECIFIED",
object: "chat.completion",
};