Add type for request too

This commit is contained in:
Niek van der Maas 2023-03-06 19:11:00 +01:00
parent 1ca762bcc0
commit c05fb7379d
2 changed files with 34 additions and 18 deletions

View File

@ -2,7 +2,7 @@
//import { fetchEventSource } from "@microsoft/fetch-event-source";
import { apiKeyStorage, chatsStorage, addMessage, clearMessages } from "./Storage.svelte";
import type { Response, Message } from "./Types.svelte";
import type { Request, Response, Message } from "./Types.svelte";
import { afterUpdate, onMount } from "svelte";
import SvelteMarkdown from "svelte-markdown";
@ -64,14 +64,7 @@
let response: Response;
try {
response = await (
await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${$apiKeyStorage}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
const request: Request = {
model: "gpt-3.5-turbo",
// Submit only the role and content of the messages, provide the previous messages as well for context
messages: messages
@ -87,7 +80,15 @@
//stream: false,
// stop: null
//max_tokens: 4096,
}),
};
response = await (
await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${$apiKeyStorage}`,
"Content-Type": "application/json",
},
body: JSON.stringify(request),
})
).json();
} catch (e) {

View File

@ -17,6 +17,21 @@
total_tokens: number;
};
export type Request = {
model: "gpt-3.5-turbo" | "gpt-3.5-turbo-0301";
messages: Message[];
temperature?: number;
top_p?: number;
n?: number;
stream?: boolean;
stop?: string | null;
max_tokens?: number;
presence_penalty?: number;
frequency_penalty?: number;
logit_bias?: Record<string, any>;
user?: string;
};
type ResponseOK = {
status: "ok";
id: string;