Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/agents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions examples/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
27 changes: 24 additions & 3 deletions examples/inference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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,
});

Expand Down
22 changes: 18 additions & 4 deletions examples/inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down