From 634550ea3d963982ca037c7c1482b8433f8e062f Mon Sep 17 00:00:00 2001 From: Niek van der Maas Date: Fri, 3 Mar 2023 19:29:56 +0100 Subject: [PATCH] Add response type --- src/lib/Chat.svelte | 11 +++++------ src/lib/Types.svelte | 3 +++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lib/Chat.svelte b/src/lib/Chat.svelte index 3e69c1c..cbe62d9 100644 --- a/src/lib/Chat.svelte +++ b/src/lib/Chat.svelte @@ -2,7 +2,7 @@ //import { fetchEventSource } from "@microsoft/fetch-event-source"; import { apiKeyStorage, chatsStorage, addMessage, clearMessages } from "./Storage.svelte"; - import type { Message } from "./Types.svelte"; + import type { Response, Message } from "./Types.svelte"; import { marked } from "marked"; import { afterUpdate, onMount } from "svelte"; @@ -62,7 +62,7 @@ }, }); */ - const response = await ( + const response: Response = await ( await fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { @@ -71,12 +71,11 @@ }, body: JSON.stringify({ model: "gpt-3.5-turbo", - // Remove the usage property from all messages + // Submit only the role and content of the messages, provide the previous messages as well for context messages: chat.messages.map((message): Message => { - const { usage, ...rest } = message; - return rest; + const { role, content } = message; + return { role, content }; }), - // Provide the previous messages as well for context // temperature: 1 // top_p: 1 // n: 1 diff --git a/src/lib/Types.svelte b/src/lib/Types.svelte index c5693cb..8fc367f 100644 --- a/src/lib/Types.svelte +++ b/src/lib/Types.svelte @@ -15,4 +15,7 @@ prompt_tokens: number; total_tokens: number; }; + + // TODO: add better type here, for now a generic JSON type + export type Response = Record;