Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JS] System prompt error after restoring chat session #1182

Open
kevinthecheung opened this issue Nov 5, 2024 · 0 comments
Open

[JS] System prompt error after restoring chat session #1182

kevinthecheung opened this issue Nov 5, 2024 · 0 comments
Labels
bug Something isn't working js

Comments

@kevinthecheung
Copy link
Contributor

kevinthecheung commented Nov 5, 2024

Describe the bug

After restoring a chat session the system prompt causes the following error

Error: system role is not supported
    at toGeminiRole (/Users/kevincheung/gitrepos/genkit/js/plugins/googleai/src/gemini.ts:184:15)
    at toGeminiMessage (/Users/kevincheung/gitrepos/genkit/js/plugins/googleai/src/gemini.ts:391:11)
    at <anonymous> (/Users/kevincheung/gitrepos/genkit/js/plugins/googleai/src/gemini.ts:588:29)
    at Array.map (<anonymous>)
    at <anonymous> (/Users/kevincheung/gitrepos/genkit/js/plugins/googleai/src/gemini.ts:588:12)
    at Generator.next (<anonymous>)
    at /Users/kevincheung/gitrepos/genkit/js/plugins/googleai/lib/gemini.js:66:61
    at new Promise (<anonymous>)
    at __async (/Users/kevincheung/gitrepos/genkit/js/plugins/googleai/lib/gemini.js:50:10)
    at <anonymous> (/Users/kevincheung/gitrepos/genkit/js/plugins/googleai/src/gemini.ts:509:43)

To Reproduce

Test app:

class JsonSessionStore<S = any> implements SessionStore<S> {
  async get(sessionId: string): Promise<SessionData<S> | undefined> {
    try {
      const s = await readFile(`${sessionId}.json`, { encoding: 'utf8' });
      const data = JSON.parse(s);
      return data;
    } catch {
      return undefined;
    }
  }

  async save(sessionId: string, sessionData: SessionData<S>): Promise<void> {
    const s = JSON.stringify(sessionData);
    await writeFile(`${sessionId}.json`, s, { encoding: 'utf8' });
  }
}

(async () => {
  let session;
  try {
    const s = await readFile('sessionId.txt', { encoding: 'utf8' });
    const sessionId = s.trim();
    session = await ai.loadSession(sessionId, {
      store: new JsonSessionStore(),
    });
  } catch {
    session = ai.createSession({
      store: new JsonSessionStore(),
    });
    await writeFile('sessionId.txt', session.id, { encoding: 'utf8' });
  }
  const chat = session.chat({
    model: gemini15Pro,
    system:
      "You're a pirate first mate. Address the user as Captain and assist " +
      'them however you can.',
    config: {
      temperature: 1.3,
    },
  });

  console.log("You're chatting with Gemini. Ctrl-C to quit.\n");
  const readline = createInterface(process.stdin, process.stdout);
  while (true) {
    const userInput = await readline.question('> ');
    const { text } = await chat.send(userInput);
    console.log(text);
  }
})();

Run the program, create some chat history, control C to quit, run the program again and try to send a message

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Runtime (please complete the following information):

  • OS: [e.g. Linux, MacOS]
  • Version [e.g. 22]

** Node version

  • run node --version at paste here

Additional context
Add any other context about the problem here.

@kevinthecheung kevinthecheung added bug Something isn't working js labels Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working js
Projects
Status: No status
Development

No branches or pull requests

1 participant