feature: port from python client lib

This commit is contained in:
Alpha Nerd 2026-01-17 12:02:08 +01:00
parent 129c6cd004
commit fd1a3b50cb
29 changed files with 3141 additions and 2 deletions

47
examples/node/basic.js Normal file
View file

@ -0,0 +1,47 @@
/**
* Basic usage example for Node.js
*/
import { SecureChatCompletion } from 'nomyo-js';
async function main() {
// Initialize client
const client = new SecureChatCompletion({
baseUrl: 'https://api.nomyo.ai:12434',
// For local development, use:
// baseUrl: 'http://localhost:12434',
// allowHttp: true
});
try {
// Simple chat completion
console.log('Sending chat completion request...');
const response = await client.create({
model: 'Qwen/Qwen3-0.6B',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello! How are you today?' }
],
temperature: 0.7
});
console.log('\n📝 Response:');
console.log(response.choices[0].message.content);
console.log('\n📊 Usage:');
console.log(`- Prompt tokens: ${response.usage?.prompt_tokens}`);
console.log(`- Completion tokens: ${response.usage?.completion_tokens}`);
console.log(`- Total tokens: ${response.usage?.total_tokens}`);
console.log('\n🔐 Security info:');
console.log(`- Encrypted: ${response._metadata?.is_encrypted}`);
console.log(`- Algorithm: ${response._metadata?.encryption_algorithm}`);
} catch (error) {
console.error('❌ Error:', error.message);
throw error;
}
}
main();

View 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();