reorganize openai clients: rename python/openai-client to python/openai, add javascript/openai/nodejs and elixir/openai
This commit is contained in:
parent
0cf61ea676
commit
bdf7875f31
9 changed files with 552 additions and 0 deletions
13
languages/javascript/openai/nodejs/Dockerfile
Normal file
13
languages/javascript/openai/nodejs/Dockerfile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Use official Node.js image (checked 2025-10-15: node:23-alpine is latest stable)
|
||||
FROM node:23-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files and install dependencies
|
||||
COPY package.json ./
|
||||
RUN npm install
|
||||
|
||||
# Copy application code
|
||||
COPY uncloseai.js ./
|
||||
|
||||
CMD ["node", "uncloseai.js"]
|
||||
27
languages/javascript/openai/nodejs/package.json
Normal file
27
languages/javascript/openai/nodejs/package.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "uncloseai-nodejs-openai",
|
||||
"version": "1.0.0",
|
||||
"description": "Node.js client using official OpenAI SDK for uncloseai endpoints",
|
||||
"type": "module",
|
||||
"main": "uncloseai.js",
|
||||
"scripts": {
|
||||
"start": "node uncloseai.js"
|
||||
},
|
||||
"keywords": [
|
||||
"ai",
|
||||
"openai",
|
||||
"uncloseai",
|
||||
"llm",
|
||||
"chat",
|
||||
"tts",
|
||||
"streaming"
|
||||
],
|
||||
"author": "UncloseAI",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"openai": "^4.77.0"
|
||||
}
|
||||
}
|
||||
65
languages/javascript/openai/nodejs/uncloseai.js
Normal file
65
languages/javascript/openai/nodejs/uncloseai.js
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import OpenAI from 'openai';
|
||||
import fs from 'fs';
|
||||
|
||||
console.log('=== UncloseAI Node.js Client (Official OpenAI SDK) ===\n');
|
||||
|
||||
// Non-streaming chat with Hermes
|
||||
console.log('=== Non-Streaming Chat (Hermes) ===');
|
||||
const hermesClient = new OpenAI({
|
||||
apiKey: 'dummy-key',
|
||||
baseURL: 'https://hermes.ai.unturf.com/v1'
|
||||
});
|
||||
|
||||
const hermesResponse = await hermesClient.chat.completions.create({
|
||||
model: 'adamo1139/Hermes-3-Llama-3.1-8B-FP8-Dynamic',
|
||||
messages: [
|
||||
{ role: 'user', content: 'Give a Python Fizzbuzz solution in one line of code?' }
|
||||
],
|
||||
temperature: 0.5,
|
||||
max_tokens: 150
|
||||
});
|
||||
|
||||
console.log(`Response: ${hermesResponse.choices[0].message.content}\n`);
|
||||
|
||||
// Streaming chat with Qwen
|
||||
console.log('=== Streaming Chat (Qwen) ===');
|
||||
const qwenClient = new OpenAI({
|
||||
apiKey: 'dummy-key',
|
||||
baseURL: 'https://qwen.ai.unturf.com/v1'
|
||||
});
|
||||
|
||||
const qwenStream = await qwenClient.chat.completions.create({
|
||||
model: 'hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:Q4_K_M',
|
||||
messages: [
|
||||
{ role: 'user', content: 'Give a Python Fizzbuzz solution in one line of code?' }
|
||||
],
|
||||
temperature: 0.5,
|
||||
max_tokens: 150,
|
||||
stream: true
|
||||
});
|
||||
|
||||
process.stdout.write('Response: ');
|
||||
for await (const chunk of qwenStream) {
|
||||
process.stdout.write(chunk.choices[0]?.delta?.content || '');
|
||||
}
|
||||
console.log('\n');
|
||||
|
||||
// TTS example
|
||||
console.log('=== TTS Speech Generation ===');
|
||||
const ttsClient = new OpenAI({
|
||||
apiKey: 'YOLO',
|
||||
baseURL: 'https://speech.ai.unturf.com/v1'
|
||||
});
|
||||
|
||||
const mp3 = await ttsClient.audio.speech.create({
|
||||
model: 'tts-1',
|
||||
voice: 'alloy',
|
||||
input: 'I think so therefore, Today is a wonderful day to grow something people love!',
|
||||
speed: 0.9
|
||||
});
|
||||
|
||||
const buffer = Buffer.from(await mp3.arrayBuffer());
|
||||
fs.writeFileSync('speech.mp3', buffer);
|
||||
console.log(`[OK] Speech file created: speech.mp3 (${buffer.length} bytes)\n`);
|
||||
|
||||
console.log('=== Examples Complete ===');
|
||||
Loading…
Add table
Add a link
Reference in a new issue