Fix localstorage error on worker, promptshape
This commit is contained in:
parent
d733b61a66
commit
ebe2d4c0a2
|
|
@ -75,7 +75,7 @@ export class PromptShape extends BaseBoxShapeUtil<IPrompt> {
|
|||
}, {} as Record<string, TLShape>)
|
||||
|
||||
const generateText = async (prompt: string) => {
|
||||
await llm(prompt, (partial: string, done: boolean) => {
|
||||
await llm(prompt, localStorage.getItem("openai_api_key") || "", (partial: string, done: boolean) => {
|
||||
console.log("DONE??", done)
|
||||
this.editor.updateShape<IPrompt>({
|
||||
id: shape.id,
|
||||
|
|
|
|||
|
|
@ -122,7 +122,8 @@ export function CustomContextMenu(props: TLUiContextMenuProps) {
|
|||
llm(
|
||||
`Instruction: ${edge.text}
|
||||
${sourceText ? `Context: ${sourceText}` : ""}`,
|
||||
(partialResponse) => {
|
||||
localStorage.getItem("openai_api_key") || "",
|
||||
(partialResponse: string) => {
|
||||
editor.updateShape({
|
||||
id: edge.to,
|
||||
type: "geo",
|
||||
|
|
|
|||
|
|
@ -409,7 +409,8 @@ export const overrides: TLUiOverrides = {
|
|||
llm(
|
||||
`Instruction: ${edge.text}
|
||||
${sourceText ? `Context: ${sourceText}` : ""}`,
|
||||
(partialResponse) => {
|
||||
localStorage.getItem("openai_api_key") || "",
|
||||
(partialResponse: string) => {
|
||||
editor.updateShape({
|
||||
id: edge.to,
|
||||
type: "geo",
|
||||
|
|
|
|||
|
|
@ -1,14 +1,9 @@
|
|||
import OpenAI from "openai";
|
||||
|
||||
const apiKey = localStorage.getItem("openai_api_key") || ""
|
||||
const openai = new OpenAI({
|
||||
apiKey,
|
||||
dangerouslyAllowBrowser: true,
|
||||
});
|
||||
|
||||
export async function llm(
|
||||
//systemPrompt: string,
|
||||
userPrompt: string,
|
||||
apiKey: string,
|
||||
onToken: (partialResponse: string, done: boolean) => void,
|
||||
) {
|
||||
if (!apiKey) {
|
||||
|
|
@ -17,6 +12,10 @@ export async function llm(
|
|||
//console.log("System Prompt:", systemPrompt);
|
||||
//console.log("User Prompt:", userPrompt);
|
||||
let partial = "";
|
||||
const openai = new OpenAI({
|
||||
apiKey,
|
||||
dangerouslyAllowBrowser: true,
|
||||
});
|
||||
const stream = await openai.chat.completions.create({
|
||||
model: "gpt-4o",
|
||||
messages: [
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import { EmbedShape } from "@/shapes/EmbedShapeUtil"
|
|||
import { MarkdownShape } from "@/shapes/MarkdownShapeUtil"
|
||||
import { MycrozineTemplateShape } from "@/shapes/MycrozineTemplateShapeUtil"
|
||||
import { SlideShape } from "@/shapes/SlideShapeUtil"
|
||||
import { PromptShape } from "@/shapes/PromptShapeUtil"
|
||||
|
||||
// add custom shapes and bindings here if needed:
|
||||
export const customSchema = createTLSchema({
|
||||
|
|
@ -47,6 +48,10 @@ export const customSchema = createTLSchema({
|
|||
props: SlideShape.props,
|
||||
migrations: SlideShape.migrations,
|
||||
},
|
||||
Prompt: {
|
||||
props: PromptShape.props,
|
||||
migrations: PromptShape.migrations,
|
||||
},
|
||||
},
|
||||
bindings: defaultBindingSchemas,
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue