Add better types for `responses`

This commit is contained in:
Niek van der Maas 2023-03-06 19:06:16 +01:00
parent 840851a35b
commit 1ca762bcc0
2 changed files with 27 additions and 5 deletions

View File

@ -91,7 +91,7 @@
})
).json();
} catch (e) {
response = { error: { message: e.message } };
response = { status: "error", error: { message: e.message } };
}
// Hide updating bar
@ -113,7 +113,7 @@
const response = await sendRequest(chat.messages);
if (response.error) {
if (response.status === "error") {
addMessage(chatId, {
role: "system",
content: `Error: ${response.error.message}`,
@ -135,7 +135,7 @@
const response = await sendRequest(chat.messages);
if (response.error) {
if (response.status === "error") {
addMessage(chatId, {
role: "system",
content: `Error: ${response.error.message}`,

View File

@ -17,6 +17,28 @@
total_tokens: number;
};
// TODO: add better type here, for now a generic JSON type
export type Response = Record<string, any>;
type ResponseOK = {
status: "ok";
id: string;
object: string;
created: number;
choices: {
index: number;
message: Message;
finish_reason: string;
}[];
usage: Usage;
};
type ResponseError = {
status: "error";
error: {
message: string;
type?: string;
param?: string | null;
code?: string | null;
};
};
export type Response = ResponseOK | ResponseError;
</script>