feature: port from python client lib
This commit is contained in:
parent
129c6cd004
commit
fd1a3b50cb
29 changed files with 3141 additions and 2 deletions
69
examples/node/with-tools.js
Normal file
69
examples/node/with-tools.js
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* Example with tool calling for Node.js
|
||||
*/
|
||||
|
||||
import { SecureChatCompletion } from 'nomyo-js';
|
||||
|
||||
async function main() {
|
||||
const client = new SecureChatCompletion({
|
||||
baseUrl: 'https://api.nomyo.ai:12434'
|
||||
});
|
||||
|
||||
try {
|
||||
console.log('Sending chat completion request with tools...');
|
||||
|
||||
const response = await client.create({
|
||||
model: 'Qwen/Qwen3-0.6B',
|
||||
messages: [
|
||||
{ role: 'user', content: "What's the weather like in Paris?" }
|
||||
],
|
||||
tools: [
|
||||
{
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'get_weather',
|
||||
description: 'Get the current weather for a location',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
location: {
|
||||
type: 'string',
|
||||
description: 'The city and country, e.g. Paris, France'
|
||||
},
|
||||
unit: {
|
||||
type: 'string',
|
||||
enum: ['celsius', 'fahrenheit'],
|
||||
description: 'Temperature unit'
|
||||
}
|
||||
},
|
||||
required: ['location']
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
temperature: 0.7
|
||||
});
|
||||
|
||||
console.log('\n📝 Response:');
|
||||
const message = response.choices[0].message;
|
||||
|
||||
if (message.tool_calls) {
|
||||
console.log('🔧 Tool calls requested:');
|
||||
message.tool_calls.forEach((toolCall, index) => {
|
||||
console.log(`\n ${index + 1}. ${toolCall.function.name}`);
|
||||
console.log(` Arguments: ${toolCall.function.arguments}`);
|
||||
});
|
||||
} else {
|
||||
console.log(message.content);
|
||||
}
|
||||
|
||||
console.log('\n📊 Usage:');
|
||||
console.log(`- Total tokens: ${response.usage?.total_tokens}`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error:', error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Loading…
Add table
Add a link
Reference in a new issue