@bodhiapp/ts-client 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 +62 -0
- package/dist/client.d.ts +23 -0
- package/dist/client.js +47 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/package.json +21 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @bodhiapp/ts-client
|
|
2
|
+
|
|
3
|
+
TypeScript client for the Bodhi API, providing type-safe access to the API endpoints.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @bodhiapp/ts-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { BodhiClient } from "@bodhiapp/ts-client";
|
|
15
|
+
|
|
16
|
+
// Initialize the client
|
|
17
|
+
const client = new BodhiClient({
|
|
18
|
+
baseUrl: "https://api.yourdomain.com",
|
|
19
|
+
apiKey: "your-api-key",
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Create a chat completion
|
|
23
|
+
async function chatWithBodhi() {
|
|
24
|
+
const response = await client.createChatCompletion({
|
|
25
|
+
model: "gpt-3.5-turbo",
|
|
26
|
+
messages: [
|
|
27
|
+
{ role: "system", content: "You are a helpful assistant." },
|
|
28
|
+
{ role: "user", content: "Hello, who are you?" },
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(response.choices[0].message.content);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// List available models
|
|
36
|
+
async function listAvailableModels() {
|
|
37
|
+
const models = await client.listModels();
|
|
38
|
+
console.log(models.data);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Development
|
|
43
|
+
|
|
44
|
+
This package is generated from the Bodhi API OpenAPI specification.
|
|
45
|
+
|
|
46
|
+
To regenerate the client:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm run generate
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
To build the package:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm run build
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
To run tests:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm test
|
|
62
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { operations } from './types/api';
|
|
2
|
+
export interface ClientOptions {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export declare class BodhiClient {
|
|
8
|
+
private baseUrl;
|
|
9
|
+
private headers;
|
|
10
|
+
constructor(options: ClientOptions);
|
|
11
|
+
/**
|
|
12
|
+
* Make a request to the Bodhi API
|
|
13
|
+
*/
|
|
14
|
+
request<T>(method: string, path: string, body?: unknown, additionalHeaders?: Record<string, string>): Promise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Create a chat completion
|
|
17
|
+
*/
|
|
18
|
+
createChatCompletion(params: operations['createChatCompletion']['requestBody']['content']['application/json']): Promise<operations['createChatCompletion']['responses']['200']['content']['application/json']>;
|
|
19
|
+
/**
|
|
20
|
+
* List available models
|
|
21
|
+
*/
|
|
22
|
+
listModels(): Promise<operations['listModels']['responses']['200']['content']['application/json']>;
|
|
23
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BodhiClient = void 0;
|
|
4
|
+
class BodhiClient {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.baseUrl = options.baseUrl.endsWith('/') ? options.baseUrl.slice(0, -1) : options.baseUrl;
|
|
7
|
+
this.headers = {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
...options.headers,
|
|
10
|
+
};
|
|
11
|
+
if (options.apiKey) {
|
|
12
|
+
this.headers['Authorization'] = `Bearer ${options.apiKey}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Make a request to the Bodhi API
|
|
17
|
+
*/
|
|
18
|
+
async request(method, path, body, additionalHeaders) {
|
|
19
|
+
const url = `${this.baseUrl}${path.startsWith('/') ? path : `/${path}`}`;
|
|
20
|
+
const response = await fetch(url, {
|
|
21
|
+
method,
|
|
22
|
+
headers: {
|
|
23
|
+
...this.headers,
|
|
24
|
+
...additionalHeaders,
|
|
25
|
+
},
|
|
26
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
27
|
+
});
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
const errorText = await response.text();
|
|
30
|
+
throw new Error(`Request failed with status ${response.status}: ${errorText}`);
|
|
31
|
+
}
|
|
32
|
+
return response.json();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a chat completion
|
|
36
|
+
*/
|
|
37
|
+
async createChatCompletion(params) {
|
|
38
|
+
return this.request('POST', '/v1/chat/completions', params);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* List available models
|
|
42
|
+
*/
|
|
43
|
+
async listModels() {
|
|
44
|
+
return this.request('GET', '/v1/models');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.BodhiClient = BodhiClient;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client"), exports);
|
|
18
|
+
__exportStar(require("./types/api"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bodhiapp/ts-client",
|
|
3
|
+
"version": "0.1.0-dev",
|
|
4
|
+
"description": "TypeScript client for Bodhi API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"bodhi",
|
|
12
|
+
"api",
|
|
13
|
+
"client",
|
|
14
|
+
"typescript"
|
|
15
|
+
],
|
|
16
|
+
"author": "Bodhi Team",
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bodhiapp/ts-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript client for Bodhi API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "npm run generate && tsc",
|
|
12
|
+
"generate": "npm run generate:openapi && npm run generate:types",
|
|
13
|
+
"generate:openapi": "cd .. && cargo run --package xtask openapi",
|
|
14
|
+
"generate:types": "openapi-typescript ../openapi.json --output src/types/api.d.ts --export-type components",
|
|
15
|
+
"prepare": "npm run build",
|
|
16
|
+
"prepublishOnly": "npm run test",
|
|
17
|
+
"test": "vitest run"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"bodhi",
|
|
21
|
+
"api",
|
|
22
|
+
"client",
|
|
23
|
+
"typescript"
|
|
24
|
+
],
|
|
25
|
+
"author": "Bodhi Team",
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"openapi-typescript": "^6.7.3",
|
|
29
|
+
"typescript": "^5.3.3",
|
|
30
|
+
"vitest": "^1.2.1"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|