gptscript-ai / gptscript

Build AI assistants that interact with your systems
https://gptscript.ai
Apache License 2.0
2.99k stars 261 forks source link

I am not able to change the default model for the gptscript from gpt-4o , I want to use another version gpt-3.5-turbo #583

Closed kamalbuilds closed 1 month ago

kamalbuilds commented 3 months ago

image

kamalbuilds commented 3 months ago

@vincent99 @darkthread @lucj @kaihendry @thedadams

thedadams commented 3 months ago

Hi @kamalbuilds. Your screenshot doesn't give much indication as to the problem you're having. Can you explain a little bit about what is happening and how it is different than you expect?

kamalbuilds commented 3 months ago

Hi @thedadams Actually I am trying to run the gptscript using the below code with openai keys and though I am trying to pass gpt-3.5-turbo version as the default model . It is trying to access the gpt-4o paid model as the default one.

"@gptscript-ai/gptscript": "^0.8.3",

Running

const run = await g.run(script, opts);

leads me to the errror , Below are the files and the output of console for reference

import { GPTScript } from "@gptscript-ai/gptscript";

const g = new GPTScript({
  APIKey: process.env.OPENAI_API_KEY,
  DefaultModel: "gpt-3.5-turbo"
});

export default g;

route.ts

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) {
  // to get the body we do
  const { story, pages, path } = await request.json();

  const opts: RunOpts = {
    disableCache: true,
    input: `--story ${story} --pages ${pages} --${path}`,
  };

  try {
    const encoder = new TextEncoder();
    const stream = new ReadableStream({
      async start(controller) {
        try {
          g.listModels().then((models) => {
            console.log("Models:", models);
          });
          console.log("Running gptscript with options:", opts);

          const run = await g.run(script, opts);
          console.log("GPTScript run initiated:", run);

          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) {
    console.error("Error in POST handler:", error);
    return new Response(JSON.stringify({ error: error }), {
      status: 500,
    });
  }
}
thedadams commented 3 months ago

Oh, you're using the Node SDK. Thanks for providing more information.

The issue you're seeing should be fixed in v0.8.5. Can you try upgrading?

kamalbuilds commented 3 months ago

@thedadams , still I get the same error. image

thedadams commented 3 months ago

That looks like a different error. Do you have your OPENAI_API_KEY set?

kamalbuilds commented 3 months ago

yes , I have it set

That looks like a different error. Do you have your OPENAI_API_KEY set?

thedadams commented 3 months ago

OK. I think I understand what the issue is, but let me ask a few more questions.

You opened the issue stating that you can't use gpt-3.5-turbo. Did you ever see any error that explicitly said that? Or have you always seen the last error you posted in the screenshot? Have you been running this application only on Windows?

Can you post the contents of 'C:\Users\geniu\Desktop\base\ForgestoryOnchain\node_modules\@gptscript-ai\gptscript\bin, please?

thedadams commented 3 months ago

This should be fixed in v0.9.0. Let us know if this is not the case for you.