Skip to content

Commit

Permalink
delete unused route
Browse files Browse the repository at this point in the history
  • Loading branch information
sangdth committed Dec 7, 2023
1 parent c93981f commit 57e602d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 777 deletions.
51 changes: 11 additions & 40 deletions app/api/generate/route.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,34 @@
import { Configuration, OpenAIApi } from "openai-edge";
import { OpenAIStream, StreamingTextResponse } from "ai";
import { kv } from "@vercel/kv";
import { Ratelimit } from "@upstash/ratelimit";
import { Configuration, OpenAIApi } from 'openai-edge';
import { OpenAIStream, StreamingTextResponse } from 'ai';

const config = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(config);

export const runtime = "edge";

export async function POST(req: Request): Promise<Response> {
if (
process.env.NODE_ENV != "development" &&
process.env.KV_REST_API_URL &&
process.env.KV_REST_API_TOKEN
) {
const ip = req.headers.get("x-forwarded-for");
const ratelimit = new Ratelimit({
redis: kv,
limiter: Ratelimit.slidingWindow(50, "1 d"),
});

const { success, limit, reset, remaining } = await ratelimit.limit(
`platforms_ratelimit_${ip}`,
);

if (!success) {
return new Response("You have reached your request limit for the day.", {
status: 429,
headers: {
"X-RateLimit-Limit": limit.toString(),
"X-RateLimit-Remaining": remaining.toString(),
"X-RateLimit-Reset": reset.toString(),
},
});
}
}
export const runtime = 'edge';

export async function POST(req: Request) {
let { prompt: content } = await req.json();

// remove trailing slash,
// slice the content from the end to prioritize later characters
content = content.replace(/\/$/, "").slice(-5000);
content = content.replace(/\/$/, '').slice(-5000);

const response = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
model: 'gpt-3.5-turbo',
messages: [
{
role: "system",
role: 'system',
content:
"You are an AI writing assistant that continues existing text based on context from prior text. " +
"Give more weight/priority to the later characters than the beginning ones. " +
"Limit your response to no more than 200 characters, but make sure to construct complete sentences.",
'You are an AI writing assistant that continues existing text based on context from prior text. ' +
'Give more weight/priority to the later characters than the beginning ones. ' +
'Limit your response to no more than 200 characters, but make sure to construct complete sentences.',
// we're disabling markdown for now until we can figure out a way to stream markdown text with proper formatting: https://github.com/steven-tey/novel/discussions/7
// "Use Markdown formatting when appropriate.",
},
{
role: "user",
role: 'user',
content,
},
],
Expand Down
26 changes: 0 additions & 26 deletions app/api/upload/route.ts

This file was deleted.

183 changes: 0 additions & 183 deletions components/client/Uploader/index.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
"@tiptap/react": "2.1.13",
"@tiptap/starter-kit": "2.1.13",
"@upstash/ratelimit": "1.0.0",
"@vercel/analytics": "1.1.1",
"@vercel/blob": "0.15.1",
"@vercel/kv": "1.0.0",
"@vercel/postgres": "0.5.1",
"ai": "2.2.28",
"date-fns": "2.30.0",
Expand Down
Loading

0 comments on commit 57e602d

Please sign in to comment.