@loopers/client 0.4.7 → 1.0.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/README.md +15 -0
- package/dist/client.d.ts +20 -0
- package/dist/client.js +27 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -1
- package/package.json +1 -1
- package/src/client.ts +26 -1
- package/src/index.ts +9 -1
- package/test/client.test.ts +30 -0
package/README.md
CHANGED
|
@@ -74,6 +74,21 @@ const response = await client.messages.create({
|
|
|
74
74
|
console.log(`Request Cost: $${(response as any).loopers_cost} USD`);
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
### Other Providers (Groq, Mistral, DeepSeek, Together)
|
|
78
|
+
|
|
79
|
+
Because these providers are OpenAI-compatible, they share the exact same interface as `LoopersOpenAI`. Simply substitute the class name:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { LoopersGroq } from '@loopers/client';
|
|
83
|
+
|
|
84
|
+
// Example using Groq
|
|
85
|
+
const client = new LoopersGroq({
|
|
86
|
+
loopersUrl: 'http://localhost:8080',
|
|
87
|
+
loopersKey: 'lp-xxx',
|
|
88
|
+
providerKey: 'gsk_xxx'
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
77
92
|
## License
|
|
78
93
|
|
|
79
94
|
MIT
|
package/dist/client.d.ts
CHANGED
|
@@ -13,6 +13,26 @@ export declare class LoopersOpenAI extends OpenAI {
|
|
|
13
13
|
[key: string]: any;
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
+
export declare class LoopersGroq extends LoopersOpenAI {
|
|
17
|
+
constructor(options: LoopersClientOptions & {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export declare class LoopersMistral extends LoopersOpenAI {
|
|
22
|
+
constructor(options: LoopersClientOptions & {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export declare class LoopersDeepSeek extends LoopersOpenAI {
|
|
27
|
+
constructor(options: LoopersClientOptions & {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export declare class LoopersTogether extends LoopersOpenAI {
|
|
32
|
+
constructor(options: LoopersClientOptions & {
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
16
36
|
export declare class LoopersAnthropic extends Anthropic {
|
|
17
37
|
constructor(options: LoopersClientOptions & {
|
|
18
38
|
[key: string]: any;
|
package/dist/client.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.LoopersAnthropic = exports.LoopersOpenAI = void 0;
|
|
6
|
+
exports.LoopersAnthropic = exports.LoopersTogether = exports.LoopersDeepSeek = exports.LoopersMistral = exports.LoopersGroq = exports.LoopersOpenAI = void 0;
|
|
7
7
|
const openai_1 = __importDefault(require("openai"));
|
|
8
8
|
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
9
9
|
function createLoopersFetch(loopersKey, providerKey, sessionId, sessionBudget, maxSteps, customFetch) {
|
|
@@ -78,18 +78,42 @@ function createLoopersFetch(loopersKey, providerKey, sessionId, sessionBudget, m
|
|
|
78
78
|
}
|
|
79
79
|
class LoopersOpenAI extends openai_1.default {
|
|
80
80
|
constructor(options) {
|
|
81
|
-
const { loopersUrl, loopersKey, providerKey, sessionId, sessionBudget, maxSteps, ...openaiOptions } = options;
|
|
81
|
+
const { loopersUrl, loopersKey, providerKey, sessionId, sessionBudget, maxSteps, _providerPath, ...openaiOptions } = options;
|
|
82
82
|
const baseFetch = openaiOptions.fetch;
|
|
83
83
|
const loopersFetch = createLoopersFetch(loopersKey, providerKey, sessionId, sessionBudget, maxSteps, baseFetch);
|
|
84
84
|
super({
|
|
85
85
|
...openaiOptions,
|
|
86
|
-
baseURL: `${loopersUrl.replace(/\/$/, '')}
|
|
86
|
+
baseURL: `${loopersUrl.replace(/\/$/, '')}/${_providerPath || 'openai/v1'}`,
|
|
87
87
|
apiKey: loopersKey,
|
|
88
88
|
fetch: loopersFetch,
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
exports.LoopersOpenAI = LoopersOpenAI;
|
|
93
|
+
class LoopersGroq extends LoopersOpenAI {
|
|
94
|
+
constructor(options) {
|
|
95
|
+
super({ ...options, _providerPath: 'groq/v1' });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.LoopersGroq = LoopersGroq;
|
|
99
|
+
class LoopersMistral extends LoopersOpenAI {
|
|
100
|
+
constructor(options) {
|
|
101
|
+
super({ ...options, _providerPath: 'mistral/v1' });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.LoopersMistral = LoopersMistral;
|
|
105
|
+
class LoopersDeepSeek extends LoopersOpenAI {
|
|
106
|
+
constructor(options) {
|
|
107
|
+
super({ ...options, _providerPath: 'deepseek/v1' });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.LoopersDeepSeek = LoopersDeepSeek;
|
|
111
|
+
class LoopersTogether extends LoopersOpenAI {
|
|
112
|
+
constructor(options) {
|
|
113
|
+
super({ ...options, _providerPath: 'together/v1' });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.LoopersTogether = LoopersTogether;
|
|
93
117
|
class LoopersAnthropic extends sdk_1.default {
|
|
94
118
|
constructor(options) {
|
|
95
119
|
const { loopersUrl, loopersKey, providerKey, sessionId, sessionBudget, maxSteps, ...anthropicOptions } = options;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { LoopersOpenAI, LoopersAnthropic, LoopersClientOptions } from './client';
|
|
1
|
+
export { LoopersOpenAI, LoopersAnthropic, LoopersGroq, LoopersMistral, LoopersDeepSeek, LoopersTogether, LoopersClientOptions, } from './client';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LoopersAnthropic = exports.LoopersOpenAI = void 0;
|
|
3
|
+
exports.LoopersTogether = exports.LoopersDeepSeek = exports.LoopersMistral = exports.LoopersGroq = exports.LoopersAnthropic = exports.LoopersOpenAI = void 0;
|
|
4
4
|
var client_1 = require("./client");
|
|
5
5
|
Object.defineProperty(exports, "LoopersOpenAI", { enumerable: true, get: function () { return client_1.LoopersOpenAI; } });
|
|
6
6
|
Object.defineProperty(exports, "LoopersAnthropic", { enumerable: true, get: function () { return client_1.LoopersAnthropic; } });
|
|
7
|
+
Object.defineProperty(exports, "LoopersGroq", { enumerable: true, get: function () { return client_1.LoopersGroq; } });
|
|
8
|
+
Object.defineProperty(exports, "LoopersMistral", { enumerable: true, get: function () { return client_1.LoopersMistral; } });
|
|
9
|
+
Object.defineProperty(exports, "LoopersDeepSeek", { enumerable: true, get: function () { return client_1.LoopersDeepSeek; } });
|
|
10
|
+
Object.defineProperty(exports, "LoopersTogether", { enumerable: true, get: function () { return client_1.LoopersTogether; } });
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -108,6 +108,7 @@ export class LoopersOpenAI extends OpenAI {
|
|
|
108
108
|
sessionId,
|
|
109
109
|
sessionBudget,
|
|
110
110
|
maxSteps,
|
|
111
|
+
_providerPath,
|
|
111
112
|
...openaiOptions
|
|
112
113
|
} = options;
|
|
113
114
|
|
|
@@ -123,13 +124,37 @@ export class LoopersOpenAI extends OpenAI {
|
|
|
123
124
|
|
|
124
125
|
super({
|
|
125
126
|
...openaiOptions,
|
|
126
|
-
baseURL: `${loopersUrl.replace(/\/$/, '')}
|
|
127
|
+
baseURL: `${loopersUrl.replace(/\/$/, '')}/${_providerPath || 'openai/v1'}`,
|
|
127
128
|
apiKey: loopersKey,
|
|
128
129
|
fetch: loopersFetch,
|
|
129
130
|
});
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
export class LoopersGroq extends LoopersOpenAI {
|
|
135
|
+
constructor(options: LoopersClientOptions & { [key: string]: any }) {
|
|
136
|
+
super({ ...options, _providerPath: 'groq/v1' });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export class LoopersMistral extends LoopersOpenAI {
|
|
141
|
+
constructor(options: LoopersClientOptions & { [key: string]: any }) {
|
|
142
|
+
super({ ...options, _providerPath: 'mistral/v1' });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export class LoopersDeepSeek extends LoopersOpenAI {
|
|
147
|
+
constructor(options: LoopersClientOptions & { [key: string]: any }) {
|
|
148
|
+
super({ ...options, _providerPath: 'deepseek/v1' });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export class LoopersTogether extends LoopersOpenAI {
|
|
153
|
+
constructor(options: LoopersClientOptions & { [key: string]: any }) {
|
|
154
|
+
super({ ...options, _providerPath: 'together/v1' });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
133
158
|
export class LoopersAnthropic extends Anthropic {
|
|
134
159
|
constructor(
|
|
135
160
|
options: LoopersClientOptions & {
|
package/src/index.ts
CHANGED
package/test/client.test.ts
CHANGED
|
@@ -99,3 +99,33 @@ describe('LoopersAnthropic', () => {
|
|
|
99
99
|
expect(headers.get('X-Loopers-Provider-Key')).toBe('sk-ant');
|
|
100
100
|
});
|
|
101
101
|
});
|
|
102
|
+
|
|
103
|
+
import { LoopersGroq } from '../src/client';
|
|
104
|
+
|
|
105
|
+
describe('LoopersGroq', () => {
|
|
106
|
+
it('should override baseURL to groq/v1', async () => {
|
|
107
|
+
const mockFetch = vi.fn().mockResolvedValue({
|
|
108
|
+
json: async () => ({ id: 'chatcmpl-123' }),
|
|
109
|
+
text: async () => JSON.stringify({ id: 'chatcmpl-123' }),
|
|
110
|
+
headers: new Headers(),
|
|
111
|
+
ok: true,
|
|
112
|
+
status: 200,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const client = new LoopersGroq({
|
|
116
|
+
loopersUrl: 'http://localhost:8080',
|
|
117
|
+
loopersKey: 'lp-123',
|
|
118
|
+
providerKey: 'gsk_123',
|
|
119
|
+
fetch: mockFetch as any,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
await client.chat.completions.create({
|
|
123
|
+
model: 'llama-3',
|
|
124
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
128
|
+
const [url, init] = mockFetch.mock.calls[0];
|
|
129
|
+
expect(url.toString()).toBe('http://localhost:8080/groq/v1/chat/completions');
|
|
130
|
+
});
|
|
131
|
+
});
|