aquin 0.1.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 +2 -0
- package/dist/client.d.ts +16 -0
- package/dist/client.js +60 -0
- package/dist/exceptions.d.ts +19 -0
- package/dist/exceptions.js +46 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +12 -0
- package/package.json +17 -0
package/README.md
ADDED
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface CompletionResponse {
|
|
2
|
+
text: string;
|
|
3
|
+
tokens_in: number;
|
|
4
|
+
tokens_out: number;
|
|
5
|
+
}
|
|
6
|
+
export interface CompletionOptions {
|
|
7
|
+
max_tokens?: number;
|
|
8
|
+
temperature?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class AquinClient {
|
|
11
|
+
private apiKey;
|
|
12
|
+
private baseUrl;
|
|
13
|
+
constructor(apiKey: string, baseUrl?: string);
|
|
14
|
+
complete(prompt: string, options?: CompletionOptions): Promise<CompletionResponse>;
|
|
15
|
+
private handleResponse;
|
|
16
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AquinClient = void 0;
|
|
4
|
+
const exceptions_1 = require("./exceptions");
|
|
5
|
+
const DEFAULT_BASE_URL = "https://www.aquin.app";
|
|
6
|
+
class AquinClient {
|
|
7
|
+
constructor(apiKey, baseUrl = DEFAULT_BASE_URL) {
|
|
8
|
+
if (!apiKey)
|
|
9
|
+
throw new Error("apiKey is required");
|
|
10
|
+
this.apiKey = apiKey;
|
|
11
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
12
|
+
}
|
|
13
|
+
async complete(prompt, options = {}) {
|
|
14
|
+
const { max_tokens = 512, temperature = 0.7 } = options;
|
|
15
|
+
let res;
|
|
16
|
+
try {
|
|
17
|
+
res = await fetch(`${this.baseUrl}/api/v1/model`, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: {
|
|
20
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({ prompt, max_tokens, temperature }),
|
|
24
|
+
redirect: "follow",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
throw new exceptions_1.InferenceError(`Network error: ${err.message}`);
|
|
29
|
+
}
|
|
30
|
+
return this.handleResponse(res);
|
|
31
|
+
}
|
|
32
|
+
async handleResponse(res) {
|
|
33
|
+
if (res.ok) {
|
|
34
|
+
const data = await res.json();
|
|
35
|
+
return {
|
|
36
|
+
text: data.text,
|
|
37
|
+
tokens_in: data.tokens_in,
|
|
38
|
+
tokens_out: data.tokens_out,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
let errorMsg = `HTTP ${res.status}`;
|
|
42
|
+
try {
|
|
43
|
+
const body = await res.json();
|
|
44
|
+
errorMsg = body.error ?? errorMsg;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// empty body
|
|
48
|
+
}
|
|
49
|
+
switch (res.status) {
|
|
50
|
+
case 401: throw new exceptions_1.InvalidKeyError(errorMsg);
|
|
51
|
+
case 402: throw new exceptions_1.InsufficientCreditsError(errorMsg);
|
|
52
|
+
case 404: throw new exceptions_1.ModelNotFoundError(errorMsg);
|
|
53
|
+
case 429: throw new exceptions_1.RateLimitError(errorMsg);
|
|
54
|
+
case 502:
|
|
55
|
+
case 503: throw new exceptions_1.InferenceError(errorMsg, res.status);
|
|
56
|
+
default: throw new exceptions_1.AquinError(errorMsg, res.status);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.AquinClient = AquinClient;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class AquinError extends Error {
|
|
2
|
+
statusCode?: number;
|
|
3
|
+
constructor(message: string, statusCode?: number);
|
|
4
|
+
}
|
|
5
|
+
export declare class InvalidKeyError extends AquinError {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class InsufficientCreditsError extends AquinError {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class RateLimitError extends AquinError {
|
|
12
|
+
constructor(message: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class ModelNotFoundError extends AquinError {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class InferenceError extends AquinError {
|
|
18
|
+
constructor(message: string, statusCode?: number);
|
|
19
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InferenceError = exports.ModelNotFoundError = exports.RateLimitError = exports.InsufficientCreditsError = exports.InvalidKeyError = exports.AquinError = void 0;
|
|
4
|
+
class AquinError extends Error {
|
|
5
|
+
constructor(message, statusCode) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "AquinError";
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.AquinError = AquinError;
|
|
12
|
+
class InvalidKeyError extends AquinError {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message, 401);
|
|
15
|
+
this.name = "InvalidKeyError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.InvalidKeyError = InvalidKeyError;
|
|
19
|
+
class InsufficientCreditsError extends AquinError {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message, 402);
|
|
22
|
+
this.name = "InsufficientCreditsError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.InsufficientCreditsError = InsufficientCreditsError;
|
|
26
|
+
class RateLimitError extends AquinError {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(message, 429);
|
|
29
|
+
this.name = "RateLimitError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.RateLimitError = RateLimitError;
|
|
33
|
+
class ModelNotFoundError extends AquinError {
|
|
34
|
+
constructor(message) {
|
|
35
|
+
super(message, 404);
|
|
36
|
+
this.name = "ModelNotFoundError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.ModelNotFoundError = ModelNotFoundError;
|
|
40
|
+
class InferenceError extends AquinError {
|
|
41
|
+
constructor(message, statusCode) {
|
|
42
|
+
super(message, statusCode);
|
|
43
|
+
this.name = "InferenceError";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.InferenceError = InferenceError;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InferenceError = exports.ModelNotFoundError = exports.RateLimitError = exports.InsufficientCreditsError = exports.InvalidKeyError = exports.AquinError = exports.AquinClient = void 0;
|
|
4
|
+
var client_1 = require("./client");
|
|
5
|
+
Object.defineProperty(exports, "AquinClient", { enumerable: true, get: function () { return client_1.AquinClient; } });
|
|
6
|
+
var exceptions_1 = require("./exceptions");
|
|
7
|
+
Object.defineProperty(exports, "AquinError", { enumerable: true, get: function () { return exceptions_1.AquinError; } });
|
|
8
|
+
Object.defineProperty(exports, "InvalidKeyError", { enumerable: true, get: function () { return exceptions_1.InvalidKeyError; } });
|
|
9
|
+
Object.defineProperty(exports, "InsufficientCreditsError", { enumerable: true, get: function () { return exceptions_1.InsufficientCreditsError; } });
|
|
10
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return exceptions_1.RateLimitError; } });
|
|
11
|
+
Object.defineProperty(exports, "ModelNotFoundError", { enumerable: true, get: function () { return exceptions_1.ModelNotFoundError; } });
|
|
12
|
+
Object.defineProperty(exports, "InferenceError", { enumerable: true, get: function () { return exceptions_1.InferenceError; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aquin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JavaScript/TypeScript SDK for the Aquin model API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"prepublishOnly": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"keywords": ["aquin", "llm", "fine-tuning", "ai"],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^5.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|