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

feat: allow using prompts as tools in chat to swap out the preamble #1075

Open
wants to merge 7 commits into
base: next
Choose a base branch
from

Conversation

pavelgj
Copy link
Collaborator

@pavelgj pavelgj commented Oct 18, 2024

import { gemini15Flash, googleAI } from '@genkit-ai/googleai';
import { genkit } from 'genkit';
import readline from 'node:readline';

const ai = genkit({
  plugins: [googleAI()],
  model: gemini15Flash,
});

const refundAgent = ai.definePrompt(
  {
    name: 'refundAgent',
    config: { temperature: 1 },
    description: 'Refunds Agent can help with refund inquiries',
  },
  '{{role "system"}} Help the user with a refund.'
);

const salesAgent = ai.definePrompt(
  {
    name: 'salesAgent',
    config: { temperature: 1 },
    description: 'Sales Agent can help with sales or product inquiries',
    tools: [refundAgent],
  },
  '{{role "system"}} Be super enthusiastic about selling stuff we offer (bananas mostly)'
);

const triageAgent = ai.definePrompt(
  {
    name: 'triageAgent',
    config: { temperature: 1 },
    description: 'triage Agent',
    tools: [salesAgent, refundAgent],
  },
  '{{role "system"}} greet the person, ask them about what they need and if appropriate transfer to an agents that can better handle the query'
);

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

(async () => {
  const chat = ai.chat({
    prompt: triageAgent,
  });
  while (true) {
    await new Promise((resolve, reject) => {
      rl.question(`Say: `, async (input) => {
        try {
          const { stream } = await chat.sendStream(input);
          for await (const chunk of stream) {
            process.stdout.write(chunk.text);
          }
          resolve(null);
        } catch (e) {
          console.log('e', e);
        }
      });
    });
  }
})();

@@ -38,3 +38,4 @@ last_recording.mp4
/js/core/src/__codegen

!samples/chatbot/server/genkit-ai-vertexai-*.tgz
js/testapps/rag/src/foo.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this scratch/temp work? Or a legit ignore?

const promptMessage: MessageData = {
role: 'user',
content: normalizePart(options.prompt),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed? I don't think its used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants