ai
ai copied to clipboard
Error: Failed to convert the response to stream. Received status code: 429. Sveltekit
//src/routes/api/completion/+server.ts
import { OPENAI_API_KEY } from "$env/static/private";
import { Configuration, OpenAIApi } from "openai-edge";
import { OpenAIStream, StreamingTextResponse } from "ai";
import type { RequestHandler } from "./$types";
const config = new Configuration({
apiKey: OPENAI_API_KEY,
});
const openai = new OpenAIApi(config);
export const POST = (async ({ request }) => {
const { prompt } = await request.json();
const response = await openai.createCompletion({
model: "text-davinci-003",
max_tokens: 16,
stream: true,
prompt: prompt,
});
const stream = OpenAIStream(response);
return new StreamingTextResponse(stream);
}) satisfies RequestHandler;
//src/routes/+page.svelte
<script>
import { useCompletion } from "ai/svelte";
const { input, handleSubmit, completion } = useCompletion({
api: "/api/completion",
});
</script>
<main>
<form on:submit={handleSubmit}>
<input
type="text"
bind:value={$input}
placeholder="Describe your business..."
/>
<button type="submit">Generate Slogan</button>
</form>
<p>{$completion}</p>
</main>
Possibly related to #144
Possibly related to #144
omg I put the billing info and it works now lmao that is such a cashgrab move by "OPEN"ai xdxd insane
@AdrianFerrer1 Totally agree, I suspect this will be the source of many issues for those using the OpenAI integration.
Improved error handling was implemented in #163