import { readdirSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { FileSystemContext, RLMAgent } from '@astack-tech/components';
import type { LLMProvider } from '@astack-tech/components';
import { ModelProvider } from '@astack-tech/integrations';
const apiKey = process.env['DEEPSEEK_API_KEY'];
if (apiKey === undefined || apiKey === '') {
throw new Error('Set DEEPSEEK_API_KEY to run this example.');
}
const model = new ModelProvider.Deepseek({ apiKey });
const llm: LLMProvider = {
generate: prompt => model.generateCompletion(prompt),
};
const sourceDir = fileURLToPath(new URL('../../packages/core/src', import.meta.url));
const files = readdirSync(sourceDir, { recursive: true, encoding: 'utf8' }).filter(file =>
file.endsWith('.ts')
);
const context = new FileSystemContext(sourceDir, files);
const agent = new RLMAgent({ rootLLM: llm, subLLM: llm });
const result = await agent.run({
context,
query: 'How does Pipeline decide which output to return when no endpoint is given?',
});
console.log(result.answer);