Skip to content

Commit

Permalink
this was in my git workspace - i don’t remember what this is
Browse files Browse the repository at this point in the history
  • Loading branch information
ataibarkai committed Jan 8, 2024
1 parent 6628c71 commit 7e7f822
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { OpenAIStream, StreamingTextResponse } from "ai";
import OpenAI from "openai";

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

export const runtime = "edge";

export async function POST(req: Request) {
const { messages, copilotkit_manually_passed_function_descriptions } =
await req.json();

const response = await openai.chat.completions.create({
model: "gpt-4",
stream: true,
messages,
functions: copilotkit_manually_passed_function_descriptions,
});

const stream = OpenAIStream(response, {
experimental_onFunctionCall: async (
{ name, arguments: args },
createFunctionCallMessages
) => {
return undefined; // returning undefined to avoid sending any messages to the client when a function is called. Temporary, bc currently vercel ai sdk does not support returning both text and function calls -- although the API does support it.
},
});

return new StreamingTextResponse(stream);
}
22 changes: 22 additions & 0 deletions src/api/copilotkit_chatlike/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { OpenAIStream, StreamingTextResponse } from "ai";
import OpenAI from "openai";
import { CompletionCreateParamsStreaming } from "openai/resources/chat/completions";

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

export const runtime = "edge";

export async function POST(req: Request): Promise<Response> {
const forwardedProps = await req.json();

const response = await openai.chat.completions.create({
model: "gpt-4",
...forwardedProps,
stream: true,
} as CompletionCreateParamsStreaming);

const stream = OpenAIStream(response);
return new StreamingTextResponse(stream);
}
24 changes: 24 additions & 0 deletions src/components/CopilotTextareaShowcase/CopilotTextareaShowcase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";
import {
CopilotTextarea,
HTMLCopilotTextAreaElement,
} from "@copilotkit/react-textarea";

const CopilotTextareaShowcase: React.FC = () => {
const handleChange = (
event: React.ChangeEvent<HTMLCopilotTextAreaElement>
): void => {
console.log(event.target.value);
};

return (
<CopilotTextarea
value=""
onChange={handleChange}
autosuggestionsConfig={{
textareaPurpose: "comment",
}}
/>
);
};
export default CopilotTextareaShowcase;

0 comments on commit 7e7f822

Please sign in to comment.