edgee 0.1.2 → 0.1.3
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 +18 -6
- package/dist/index.d.ts +12 -0
- package/dist/index.js +15 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Edgee TypeScript SDK
|
|
2
2
|
|
|
3
|
-
Lightweight, type-safe TypeScript SDK for the [Edgee AI Gateway](https://www.edgee.
|
|
3
|
+
Lightweight, type-safe TypeScript SDK for the [Edgee AI Gateway](https://www.edgee.ai).
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/edgee)
|
|
6
6
|
[](LICENSE)
|
|
@@ -42,6 +42,17 @@ const response = await edgee.send({
|
|
|
42
42
|
console.log(response.text); // Text content
|
|
43
43
|
console.log(response.finishReason); // Finish reason
|
|
44
44
|
console.log(response.toolCalls); // Tool calls (if any)
|
|
45
|
+
|
|
46
|
+
// Access usage and compression info
|
|
47
|
+
if (response.usage) {
|
|
48
|
+
console.log(`Tokens used: ${response.usage.total_tokens}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (response.compression) {
|
|
52
|
+
console.log(`Input tokens: ${response.compression.input_tokens}`);
|
|
53
|
+
console.log(`Saved tokens: ${response.compression.saved_tokens}`);
|
|
54
|
+
console.log(`Compression rate: ${response.compression.rate}`);
|
|
55
|
+
}
|
|
45
56
|
```
|
|
46
57
|
|
|
47
58
|
## Stream Method
|
|
@@ -67,19 +78,20 @@ for await (const chunk of edgee.stream('gpt-4o', 'Tell me a story')) {
|
|
|
67
78
|
- ✅ **Streaming** - Real-time response streaming
|
|
68
79
|
- ✅ **Tool calling** - Full support for function calling
|
|
69
80
|
- ✅ **Flexible input** - Accept strings or structured objects
|
|
81
|
+
- ✅ **Compression info** - Access token compression metrics in responses
|
|
70
82
|
- ✅ **Zero dependencies** - Lightweight and fast
|
|
71
83
|
|
|
72
84
|
## Documentation
|
|
73
85
|
|
|
74
86
|
For complete documentation, examples, and API reference, visit:
|
|
75
87
|
|
|
76
|
-
**👉 [Official TypeScript SDK Documentation](https://www.edgee.
|
|
88
|
+
**👉 [Official TypeScript SDK Documentation](https://www.edgee.ai/docs/sdk/typescript)**
|
|
77
89
|
|
|
78
90
|
The documentation includes:
|
|
79
|
-
- [Configuration guide](https://www.edgee.
|
|
80
|
-
- [Send method](https://www.edgee.
|
|
81
|
-
- [Stream method](https://www.edgee.
|
|
82
|
-
- [Tools](https://www.edgee.
|
|
91
|
+
- [Configuration guide](https://www.edgee.ai/docs/sdk/typescript/configuration) - Multiple ways to configure the SDK
|
|
92
|
+
- [Send method](https://www.edgee.ai/docs/sdk/typescript/send) - Complete guide to non-streaming requests
|
|
93
|
+
- [Stream method](https://www.edgee.ai/docs/sdk/typescript/stream) - Streaming responses guide
|
|
94
|
+
- [Tools](https://www.edgee.ai/docs/sdk/typescript/tools) - Function calling guide
|
|
83
95
|
|
|
84
96
|
## License
|
|
85
97
|
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,9 @@ export interface InputObject {
|
|
|
33
33
|
messages: Message[];
|
|
34
34
|
tools?: Tool[];
|
|
35
35
|
tool_choice?: ToolChoice;
|
|
36
|
+
tags?: string[];
|
|
37
|
+
enable_compression?: boolean;
|
|
38
|
+
compression_rate?: number;
|
|
36
39
|
}
|
|
37
40
|
export interface SendOptions {
|
|
38
41
|
model: string;
|
|
@@ -54,10 +57,19 @@ export declare class SendResponse {
|
|
|
54
57
|
completion_tokens: number;
|
|
55
58
|
total_tokens: number;
|
|
56
59
|
};
|
|
60
|
+
compression?: {
|
|
61
|
+
input_tokens: number;
|
|
62
|
+
saved_tokens: number;
|
|
63
|
+
rate: number;
|
|
64
|
+
};
|
|
57
65
|
constructor(choices: Choice[], usage?: {
|
|
58
66
|
prompt_tokens: number;
|
|
59
67
|
completion_tokens: number;
|
|
60
68
|
total_tokens: number;
|
|
69
|
+
}, compression?: {
|
|
70
|
+
input_tokens: number;
|
|
71
|
+
saved_tokens: number;
|
|
72
|
+
rate: number;
|
|
61
73
|
});
|
|
62
74
|
get text(): string | null;
|
|
63
75
|
get message(): {
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export class SendResponse {
|
|
2
|
-
constructor(choices, usage) {
|
|
2
|
+
constructor(choices, usage, compression) {
|
|
3
3
|
this.choices = choices;
|
|
4
4
|
this.usage = usage;
|
|
5
|
+
this.compression = compression;
|
|
5
6
|
}
|
|
6
7
|
get text() {
|
|
7
8
|
if (this.choices[0]?.message?.content) {
|
|
@@ -74,6 +75,12 @@ export default class Edgee {
|
|
|
74
75
|
body.tools = input.tools;
|
|
75
76
|
if (input.tool_choice)
|
|
76
77
|
body.tool_choice = input.tool_choice;
|
|
78
|
+
if (input.tags)
|
|
79
|
+
body.tags = input.tags;
|
|
80
|
+
if (input.enable_compression !== undefined)
|
|
81
|
+
body.enable_compression = input.enable_compression;
|
|
82
|
+
if (input.compression_rate !== undefined)
|
|
83
|
+
body.compression_rate = input.compression_rate;
|
|
77
84
|
}
|
|
78
85
|
const res = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
79
86
|
method: "POST",
|
|
@@ -88,7 +95,7 @@ export default class Edgee {
|
|
|
88
95
|
throw new Error(`API error ${res.status}: ${errorBody}`);
|
|
89
96
|
}
|
|
90
97
|
const data = await res.json();
|
|
91
|
-
return new SendResponse(data.choices, data.usage);
|
|
98
|
+
return new SendResponse(data.choices, data.usage, data.compression);
|
|
92
99
|
}
|
|
93
100
|
async *_handleStreamingResponse(url, body) {
|
|
94
101
|
const res = await fetch(url, {
|
|
@@ -149,6 +156,12 @@ export default class Edgee {
|
|
|
149
156
|
body.tools = input.tools;
|
|
150
157
|
if (input.tool_choice)
|
|
151
158
|
body.tool_choice = input.tool_choice;
|
|
159
|
+
if (input.tags)
|
|
160
|
+
body.tags = input.tags;
|
|
161
|
+
if (input.enable_compression !== undefined)
|
|
162
|
+
body.enable_compression = input.enable_compression;
|
|
163
|
+
if (input.compression_rate !== undefined)
|
|
164
|
+
body.compression_rate = input.compression_rate;
|
|
152
165
|
}
|
|
153
166
|
yield* this._handleStreamingResponse(`${this.baseUrl}/v1/chat/completions`, body);
|
|
154
167
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edgee",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/edgee-
|
|
9
|
+
"url": "https://github.com/edgee-ai/typescript-sdk"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|