@layer-ai/core 0.1.12 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/routes/complete.d.ts.map +1 -1
- package/dist/routes/complete.js +24 -4
- package/dist/routes/v2/complete.d.ts +4 -0
- package/dist/routes/v2/complete.d.ts.map +1 -0
- package/dist/routes/v2/complete.js +214 -0
- package/dist/routes/v2/tests/test-complete-anthropic.d.ts +2 -0
- package/dist/routes/v2/tests/test-complete-anthropic.d.ts.map +1 -0
- package/dist/routes/v2/tests/test-complete-anthropic.js +132 -0
- package/dist/routes/v2/tests/test-complete-openai.d.ts +2 -0
- package/dist/routes/v2/tests/test-complete-openai.d.ts.map +1 -0
- package/dist/routes/v2/tests/test-complete-openai.js +178 -0
- package/dist/routes/v2/tests/test-complete-routing.d.ts +2 -0
- package/dist/routes/v2/tests/test-complete-routing.d.ts.map +1 -0
- package/dist/routes/v2/tests/test-complete-routing.js +192 -0
- package/dist/services/providers/anthropic-adapter.d.ts +12 -0
- package/dist/services/providers/anthropic-adapter.d.ts.map +1 -0
- package/dist/services/providers/anthropic-adapter.js +203 -0
- package/dist/services/providers/base-adapter.d.ts +1 -1
- package/dist/services/providers/base-adapter.d.ts.map +1 -1
- package/dist/services/providers/base-adapter.js +1 -1
- package/dist/services/providers/openai-adapter.d.ts +2 -2
- package/dist/services/providers/openai-adapter.d.ts.map +1 -1
- package/dist/services/providers/openai-adapter.js +15 -3
- package/dist/services/providers/tests/test-anthropic-adapter.d.ts +2 -0
- package/dist/services/providers/tests/test-anthropic-adapter.d.ts.map +1 -0
- package/dist/services/providers/tests/test-anthropic-adapter.js +104 -0
- package/dist/services/providers/tests/test-openai-adapter.d.ts +2 -0
- package/dist/services/providers/tests/test-openai-adapter.d.ts.map +1 -0
- package/dist/services/providers/tests/test-openai-adapter.js +118 -0
- package/package.json +9 -9
- package/LICENSE +0 -21
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { OpenAIAdapter } from '../openai-adapter.js';
|
|
2
|
+
const adapter = new OpenAIAdapter();
|
|
3
|
+
async function testChatCompletion() {
|
|
4
|
+
console.log('Testing chat completion...');
|
|
5
|
+
const request = {
|
|
6
|
+
gate: 'test-gate',
|
|
7
|
+
model: 'gpt-4o-mini',
|
|
8
|
+
type: 'chat',
|
|
9
|
+
data: {
|
|
10
|
+
messages: [
|
|
11
|
+
{ role: 'user', content: 'Say "Hello World" and nothing else.' }
|
|
12
|
+
],
|
|
13
|
+
temperature: 0.7,
|
|
14
|
+
maxTokens: 10,
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const response = await adapter.call(request);
|
|
18
|
+
console.log('Response:', response.content);
|
|
19
|
+
console.log('Tokens:', response.usage);
|
|
20
|
+
console.log('Cost:', response.cost);
|
|
21
|
+
console.log('Latency:', response.latencyMs + 'ms');
|
|
22
|
+
console.log('Finish reason:', response.finishReason);
|
|
23
|
+
console.log('✅ Chat completion test passed\n');
|
|
24
|
+
}
|
|
25
|
+
async function testChatWithVision() {
|
|
26
|
+
console.log('Testing chat with vision...');
|
|
27
|
+
const request = {
|
|
28
|
+
gate: 'test-gate',
|
|
29
|
+
model: 'gpt-4o-mini',
|
|
30
|
+
type: 'chat',
|
|
31
|
+
data: {
|
|
32
|
+
messages: [
|
|
33
|
+
{
|
|
34
|
+
role: 'user',
|
|
35
|
+
content: 'What color is the sky in this image?',
|
|
36
|
+
images: [{
|
|
37
|
+
url: 'https://images.unsplash.com/photo-1765202659641-9ad9facfe5cf?q=80&w=1364&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
|
|
38
|
+
detail: 'high'
|
|
39
|
+
}]
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
maxTokens: 50,
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const response = await adapter.call(request);
|
|
46
|
+
console.log('Response:', response.content);
|
|
47
|
+
console.log('Finish reason:', response.finishReason);
|
|
48
|
+
console.log('✅ Vision test passed\n');
|
|
49
|
+
}
|
|
50
|
+
async function testImageGeneration() {
|
|
51
|
+
console.log('Testing image generation...');
|
|
52
|
+
const request = {
|
|
53
|
+
gate: 'test-gate',
|
|
54
|
+
model: 'dall-e-3',
|
|
55
|
+
type: 'image',
|
|
56
|
+
data: {
|
|
57
|
+
prompt: 'A cute cat playing with a ball of yarn',
|
|
58
|
+
size: '1024x1024',
|
|
59
|
+
quality: 'standard',
|
|
60
|
+
count: 1,
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const response = await adapter.call(request);
|
|
64
|
+
console.log('Generated images:', response.images?.length);
|
|
65
|
+
console.log('Image URL:', response.images?.[0]?.url);
|
|
66
|
+
console.log('Revised prompt:', response.images?.[0]?.revisedPrompt);
|
|
67
|
+
console.log('✅ Image generation test passed\n');
|
|
68
|
+
}
|
|
69
|
+
async function testEmbeddings() {
|
|
70
|
+
console.log('Testing embeddings...');
|
|
71
|
+
const request = {
|
|
72
|
+
gate: 'test-gate',
|
|
73
|
+
model: 'text-embedding-3-small',
|
|
74
|
+
type: 'embeddings',
|
|
75
|
+
data: {
|
|
76
|
+
input: 'Hello world',
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const response = await adapter.call(request);
|
|
80
|
+
console.log('Embeddings dimensions:', response.embeddings?.[0]?.length);
|
|
81
|
+
console.log('Tokens:', response.usage);
|
|
82
|
+
console.log('Cost:', response.cost);
|
|
83
|
+
console.log('✅ Embeddings test passed\n');
|
|
84
|
+
}
|
|
85
|
+
async function testTextToSpeech() {
|
|
86
|
+
console.log('Testing text-to-speech...');
|
|
87
|
+
const request = {
|
|
88
|
+
gate: 'test-gate',
|
|
89
|
+
model: 'tts-1',
|
|
90
|
+
type: 'tts',
|
|
91
|
+
data: {
|
|
92
|
+
input: 'Hello, this is a test.',
|
|
93
|
+
voice: 'alloy',
|
|
94
|
+
speed: 1.0,
|
|
95
|
+
responseFormat: 'mp3',
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const response = await adapter.call(request);
|
|
99
|
+
console.log('Audio format:', response.audio?.format);
|
|
100
|
+
console.log('Audio base64 length:', response.audio?.base64?.length);
|
|
101
|
+
console.log('✅ Text-to-speech test passed\n');
|
|
102
|
+
}
|
|
103
|
+
async function runTests() {
|
|
104
|
+
try {
|
|
105
|
+
await testChatCompletion();
|
|
106
|
+
console.log('Testing vision...');
|
|
107
|
+
await testChatWithVision();
|
|
108
|
+
await testImageGeneration();
|
|
109
|
+
await testEmbeddings();
|
|
110
|
+
await testTextToSpeech();
|
|
111
|
+
console.log('✅ All tests passed!');
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error('❌ Test failed:', error);
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
runTests();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layer-ai/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Core API routes and services for Layer AI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"clean": "rm -rf dist"
|
|
21
|
+
},
|
|
17
22
|
"author": "Micah Nettey",
|
|
18
23
|
"license": "MIT",
|
|
19
24
|
"repository": {
|
|
@@ -28,14 +33,14 @@
|
|
|
28
33
|
"dependencies": {
|
|
29
34
|
"@anthropic-ai/sdk": "^0.39.0",
|
|
30
35
|
"@google/genai": "^1.30.0",
|
|
36
|
+
"@layer-ai/sdk": "workspace:^",
|
|
31
37
|
"bcryptjs": "^2.4.3",
|
|
32
38
|
"express": "^4.18.2",
|
|
33
39
|
"ioredis": "^5.3.2",
|
|
34
40
|
"jsonwebtoken": "^9.0.2",
|
|
35
41
|
"nanoid": "^5.0.4",
|
|
36
42
|
"openai": "^4.24.0",
|
|
37
|
-
"pg": "^8.11.3"
|
|
38
|
-
"@layer-ai/sdk": "^0.1.4"
|
|
43
|
+
"pg": "^8.11.3"
|
|
39
44
|
},
|
|
40
45
|
"devDependencies": {
|
|
41
46
|
"@types/express": "^4.17.21",
|
|
@@ -44,10 +49,5 @@
|
|
|
44
49
|
"@types/node": "^20.10.4",
|
|
45
50
|
"@types/pg": "^8.10.9",
|
|
46
51
|
"typescript": "^5.3.3"
|
|
47
|
-
},
|
|
48
|
-
"scripts": {
|
|
49
|
-
"build": "tsc",
|
|
50
|
-
"dev": "tsc --watch",
|
|
51
|
-
"clean": "rm -rf dist"
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Layer AI
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|