@nomyx/assistant
Version:
A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)
100 lines (99 loc) • 3.61 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const PromptAction_1 = require("../prompts/PromptAction");
// Mock AI provider and logger
const mockAIProvider = {
chat: async () => ({ content: 'Mock response', toolCalls: [] }),
streamChat: async function* () { yield { content: 'Mock stream response', toolCalls: [] }; },
getCapabilities: () => ({
maxTokens: 1000,
supportsFunctionCalling: true,
supportsStreaming: true,
supportedModels: ['mock-model'],
maxSimultaneousCalls: 1,
supportsSemanticCaching: false
}),
use: () => { },
registerPlugin: () => { },
convertToolSchema: () => ({}),
convertToolCall: () => ({ name: 'mockTool', arguments: {} })
};
const mockLogger = {
debug: console.log,
info: console.log,
warn: console.warn,
error: console.error
};
// Create a sample PromptAction with routing
const sampleSchema = {
input: {
type: 'object',
properties: {
temperature: { type: 'number', description: 'The current temperature' }
},
required: ['temperature']
},
output: {
type: 'object',
properties: {
recommendation: { type: 'string', description: 'A weather-based recommendation' }
}
}
};
const rootPrompt = new PromptAction_1.PromptAction({
name: 'rootPrompt',
schema: sampleSchema,
systemContent: 'You are a helpful assistant.',
userContent: 'Please provide a response.',
routing: [
{
condition: 'params.temperature > 30',
prompt: new PromptAction_1.PromptAction({
name: 'hotWeatherPrompt',
schema: sampleSchema,
systemContent: 'You are a weather expert.',
userContent: 'It\'s hot outside. What should we do?'
})
},
{
condition: 'params.temperature <= 30 && params.temperature > 10',
prompt: new PromptAction_1.PromptAction({
name: 'mildWeatherPrompt',
schema: sampleSchema,
systemContent: 'You are a weather expert.',
userContent: 'The weather is mild. Any activity suggestions?'
})
},
{
condition: 'params.temperature <= 10',
prompt: new PromptAction_1.PromptAction({
name: 'coldWeatherPrompt',
schema: sampleSchema,
systemContent: 'You are a weather expert.',
userContent: 'It\'s cold outside. How should we prepare?'
})
}
]
});
// Test function
function runRoutingTest() {
const context = {
aiProvider: mockAIProvider,
logger: mockLogger,
state: {},
user: { id: 'test-user', name: 'Test User' },
session: { id: 'test-session', timestamp: new Date().toISOString() },
functionSchemas: [],
executeAction: async () => ({})
};
console.log('Test 1: Hot weather');
console.log((0, PromptAction_1.testPromptRouting)(rootPrompt, { temperature: 35 }, context));
console.log('\nTest 2: Mild weather');
console.log((0, PromptAction_1.testPromptRouting)(rootPrompt, { temperature: 20 }, context));
console.log('\nTest 3: Cold weather');
console.log((0, PromptAction_1.testPromptRouting)(rootPrompt, { temperature: 5 }, context));
console.log('\nTest 4: Edge case (exactly 30 degrees)');
console.log((0, PromptAction_1.testPromptRouting)(rootPrompt, { temperature: 30 }, context));
}
// Run the test
runRoutingTest();