-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this was in my git workspace - i don’t remember what this is
- Loading branch information
1 parent
6628c71
commit 7e7f822
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
src/components/CopilotTextareaShowcase/CopilotTextareaShowcase.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |