Add better types for `responses`
This commit is contained in:
parent
840851a35b
commit
1ca762bcc0
|
@ -91,7 +91,7 @@
|
||||||
})
|
})
|
||||||
).json();
|
).json();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
response = { error: { message: e.message } };
|
response = { status: "error", error: { message: e.message } };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide updating bar
|
// Hide updating bar
|
||||||
|
@ -113,7 +113,7 @@
|
||||||
|
|
||||||
const response = await sendRequest(chat.messages);
|
const response = await sendRequest(chat.messages);
|
||||||
|
|
||||||
if (response.error) {
|
if (response.status === "error") {
|
||||||
addMessage(chatId, {
|
addMessage(chatId, {
|
||||||
role: "system",
|
role: "system",
|
||||||
content: `Error: ${response.error.message}`,
|
content: `Error: ${response.error.message}`,
|
||||||
|
@ -135,7 +135,7 @@
|
||||||
|
|
||||||
const response = await sendRequest(chat.messages);
|
const response = await sendRequest(chat.messages);
|
||||||
|
|
||||||
if (response.error) {
|
if (response.status === "error") {
|
||||||
addMessage(chatId, {
|
addMessage(chatId, {
|
||||||
role: "system",
|
role: "system",
|
||||||
content: `Error: ${response.error.message}`,
|
content: `Error: ${response.error.message}`,
|
||||||
|
|
|
@ -17,6 +17,28 @@
|
||||||
total_tokens: number;
|
total_tokens: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: add better type here, for now a generic JSON type
|
type ResponseOK = {
|
||||||
export type Response = Record<string, any>;
|
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>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue