Add type for request too
This commit is contained in:
parent
1ca762bcc0
commit
c05fb7379d
|
@ -2,7 +2,7 @@
|
||||||
//import { fetchEventSource } from "@microsoft/fetch-event-source";
|
//import { fetchEventSource } from "@microsoft/fetch-event-source";
|
||||||
|
|
||||||
import { apiKeyStorage, chatsStorage, addMessage, clearMessages } from "./Storage.svelte";
|
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 { afterUpdate, onMount } from "svelte";
|
||||||
import SvelteMarkdown from "svelte-markdown";
|
import SvelteMarkdown from "svelte-markdown";
|
||||||
|
@ -64,14 +64,7 @@
|
||||||
|
|
||||||
let response: Response;
|
let response: Response;
|
||||||
try {
|
try {
|
||||||
response = await (
|
const request: Request = {
|
||||||
await fetch("https://api.openai.com/v1/chat/completions", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${$apiKeyStorage}`,
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
model: "gpt-3.5-turbo",
|
model: "gpt-3.5-turbo",
|
||||||
// Submit only the role and content of the messages, provide the previous messages as well for context
|
// Submit only the role and content of the messages, provide the previous messages as well for context
|
||||||
messages: messages
|
messages: messages
|
||||||
|
@ -87,7 +80,15 @@
|
||||||
//stream: false,
|
//stream: false,
|
||||||
// stop: null
|
// stop: null
|
||||||
//max_tokens: 4096,
|
//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();
|
).json();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -17,6 +17,21 @@
|
||||||
total_tokens: number;
|
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 = {
|
type ResponseOK = {
|
||||||
status: "ok";
|
status: "ok";
|
||||||
id: string;
|
id: string;
|
||||||
|
|
Loading…
Reference in New Issue