Add response type
This commit is contained in:
parent
b0a638bfb5
commit
634550ea3d
|
@ -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 { Message } from "./Types.svelte";
|
import type { Response, Message } from "./Types.svelte";
|
||||||
|
|
||||||
import { marked } from "marked";
|
import { marked } from "marked";
|
||||||
import { afterUpdate, onMount } from "svelte";
|
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", {
|
await fetch("https://api.openai.com/v1/chat/completions", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -71,12 +71,11 @@
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: "gpt-3.5-turbo",
|
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 => {
|
messages: chat.messages.map((message): Message => {
|
||||||
const { usage, ...rest } = message;
|
const { role, content } = message;
|
||||||
return rest;
|
return { role, content };
|
||||||
}),
|
}),
|
||||||
// Provide the previous messages as well for context
|
|
||||||
// temperature: 1
|
// temperature: 1
|
||||||
// top_p: 1
|
// top_p: 1
|
||||||
// n: 1
|
// n: 1
|
||||||
|
|
|
@ -15,4 +15,7 @@
|
||||||
prompt_tokens: number;
|
prompt_tokens: number;
|
||||||
total_tokens: number;
|
total_tokens: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: add better type here, for now a generic JSON type
|
||||||
|
export type Response = Record<string, any>;
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue