diff --git a/examples/agents.test.ts b/examples/agents.test.ts index addd0e6..b3bc1aa 100644 --- a/examples/agents.test.ts +++ b/examples/agents.test.ts @@ -13,7 +13,7 @@ describe('RAG Integration Tests', () => { it('should create an agent and handle conversation successfully', async () => { // Get available models const models = await client.models.list(); - const llmModel = models.find(model => model.model_type === 'llm'); + const llmModel = models.find(model => model.model_type === 'llm' && !model.identifier.includes('guard') && !model.identifier.includes('405')); expect(llmModel).toBeTruthy(); // Create agent with configuration diff --git a/examples/agents.ts b/examples/agents.ts index d99d92c..3cbce23 100755 --- a/examples/agents.ts +++ b/examples/agents.ts @@ -7,7 +7,11 @@ const client = new LlamaStackClient({ baseURL: 'http://localhost:8321' }); async function main() { const availableModels = (await client.models.list()) - .filter((model: any) => model.model_type === 'llm') + .filter((model: any) => + model.model_type === 'llm' && + !model.identifier.includes('guard') && + !model.identifier.includes('405') + ) .map((model: any) => model.identifier); if (availableModels.length === 0) { @@ -31,12 +35,13 @@ async function main() { }, toolgroups: process.env["TAVILY_SEARCH_API_KEY"] ? ['builtin::websearch'] : [], tool_choice: 'auto', - tool_prompt_format: 'json', + tool_prompt_format: 'python_list', input_shields: [], output_shields: [], enable_session_persistence: false, max_infer_iters: 10, }; + console.log('Agent Configuration:', JSON.stringify(agentConfig, null, 2)); const agentic_system_create_response = await client.agents.create({agent_config: agentConfig}); const agent_id = agentic_system_create_response.agent_id; diff --git a/examples/inference.test.ts b/examples/inference.test.ts index 15a8163..36fe51b 100644 --- a/examples/inference.test.ts +++ b/examples/inference.test.ts @@ -2,9 +2,20 @@ import LlamaStackClient from 'llama-stack-client'; describe('LlamaStack Client Integration Tests', () => { let client: LlamaStackClient; + let availableModels: string[]; - beforeAll(() => { + beforeAll(async () => { client = new LlamaStackClient({ baseURL: 'http://localhost:8321' }); + + // Fetch available models once + const models = await client.models.list(); + availableModels = models + .filter((model: any) => + model.model_type === 'llm' && + !model.identifier.includes('guard') && + !model.identifier.includes('405') + ) + .map((model: any) => model.identifier); }); test('should list available models', async () => { @@ -14,18 +25,28 @@ describe('LlamaStack Client Integration Tests', () => { }); test('should perform non-streaming chat completion', async () => { + // Skip test if no models available + if (availableModels.length === 0) { + console.warn('Skipping test: No available models'); + return; + } const chatCompletion = await client.inference.chatCompletion({ messages: [{ content: 'Hello, how are you?', role: 'user' }], - model_id: 'meta-llama/Llama-3.2-3B-Instruct', + model_id: availableModels[0] as string, }); expect(chatCompletion).toBeDefined(); expect(chatCompletion.completion_message).toBeDefined(); }, 30000); test('should perform streaming chat completion', async () => { + // Skip test if no models available + if (availableModels.length === 0) { + console.warn('Skipping test: No available models'); + return; + } const stream = await client.inference.chatCompletion({ messages: [{ content: 'Hello, how are you?', role: 'user' }], - model_id: 'meta-llama/Llama-3.2-3B-Instruct', + model_id: availableModels[0] as string, stream: true, }); diff --git a/examples/inference.ts b/examples/inference.ts index 6339cba..2fa56b1 100755 --- a/examples/inference.ts +++ b/examples/inference.ts @@ -5,20 +5,34 @@ const client = new LlamaStackClient({ baseURL: 'http://localhost:8321' }); async function main() { // list models - const models = await client.models.list(); - console.log(models); + const availableModels = (await client.models.list()) + .filter((model: any) => + model.model_type === 'llm' && + !model.identifier.includes('guard') && + !model.identifier.includes('405') + ) + .map((model: any) => model.identifier); + + console.log(availableModels); + + if (availableModels.length === 0) { + console.log('No available models. Exiting.'); + return; + } + const selectedModel = availableModels[0]; + console.log(`Using model: ${selectedModel}`); // non-streaming chat-completion const chatCompletion = await client.inference.chatCompletion({ messages: [{ content: 'Hello, how are you?', role: 'user' }], - model_id: 'meta-llama/Llama-3.2-3B-Instruct', + model_id: selectedModel, }); console.log(chatCompletion); // streaming chat-completion const stream = await client.inference.chatCompletion({ messages: [{ content: 'Hello, how are you?', role: 'user' }], - model_id: 'meta-llama/Llama-3.2-3B-Instruct', + model_id: selectedModel, stream: true, }); for await (const chunk of stream) {