Failed to find a model provider for model [gpt-4o]

i got error, “failed to pipe response. failed to find a model provider for model [gpt-4o]”

here my code,

async function runScript(){
    setRunStarted(true);
    setRunFinished(false);
    
    const response = await fetch ('/api/run-script', {
        method:'POST',
        headers: {
            'Content-Type' : 'application/json',
        },
        body: JSON.stringify({story, pages, path: storiesPath}),

    });

    if (response.ok && response.body) {
        // handle strem for the api
        //..
        console.log("Streaming Started");
        const reader = response.body.getReader();
        const decoder = new TextDecoder();

        handleStream(reader, decoder);

    } else{
        setRunFinished(true);
        setRunStarted(false);
        console.error('failed to stream')
    }
}

    async function handleStream(reader:ReadableStreamDefaultReader<Uint8Array>, decoder:TextDecoder) {
        
        while (true){
            const {done, value} = await reader.read();
            if (done) break;
            const chunk = decoder.decode(value, {stream: true})

            const eventData = chunk
            .split("\n\n")
            .filter((line) => line.startsWith("event: "))
            .map((line) => line.replace(/^event:/, ""))

            eventData.forEach(data => {
                try {

                    const parsedData = JSON.parse(data);
                     

                    if (parsedData.type === "callProgress") {
                        setProgress(
                            parsedData.output[parsedData.output.length - 1].content
                        );
                        setCurrentTols(parsedData.tool?.description || "");
                    }  else if ( parsedData.type === 'callStarted'){
                        setCurrentTols(parsedData.tool?.description || "");
                    } else if ( parsedData.type === 'runFinish'){
                       setRunFinished(true);
                       setRunStarted(false);
                    } else {
                        setEvents((prevEvent) => [...prevEvent, parsedData]);
                    }

                    
                } catch (error) {
                    console.log("error bang", error)
                }
            })
        }
    }

and here the route code

import { NextRequest } from "next/server";
import { RunEventType, RunOpts } from "@gptscript-ai/gptscript";
import g from "@/lib/gptScriptInstance";

const script = "app/api/run-script/story-book.gpt";

export async function POST(request: NextRequest) {
    const {story, pages, path} = await request.json();

    const opts:RunOpts = {
        disableCache: true,
        input: `--story ${story} --pages ${pages} --path ${path}`,
    };
    try{
        const encoder = new TextEncoder();
        const stream = new ReadableStream({
            async start(controller) {
                try {
                    const run = await g.run(script,opts)
                    run.on(RunEventType.Event,(data) => {
                        controller.enqueue(encoder.encode(
                            `event: ${JSON.stringify(data)}\n\n`
                        ));
                    });

                    await run.text();
                    controller.close();

                } catch (error) {
                    controller.error(error);
                    console.error("Error", error);
                }
            },
        });

        return new Response(stream, {
            headers: {
                "Content-Type": "text/event-stream",
                "Cache-Control": "no-cache",
                Connection: "keep-alive",                
            },
        })

    } catch(error) {
        return new Response(JSON.stringify({error:error}), {
            status:500,
        })
    }
    
}

Welcome to the community!

Looks like it might be a gptscript issue - I don’t see any openai related code in what you showed us. If you don’t want to debug their library, maybe reach out to them?

1 Like