Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const edgee = new Edgee("your-api-key");

// Send a simple request
const response = await edgee.send({
<<<<<<< HEAD
model: 'gpt-5.2',
=======
model: 'anthropic/claude-haiku-4-5',
>>>>>>> ecec4c8 (feat: update compression response to new API format)
input: 'What is the capital of France?',
});

Expand All @@ -34,7 +38,7 @@ The `send()` method makes non-streaming chat completion requests:

```typescript
const response = await edgee.send({
model: 'gpt-5.2',
model: 'anthropic/claude-haiku-4-5',
input: 'Hello, world!',
});

Expand All @@ -49,9 +53,10 @@ if (response.usage) {
}

if (response.compression) {
console.log(`Input tokens: ${response.compression.input_tokens}`);
console.log(`Saved tokens: ${response.compression.saved_tokens}`);
console.log(`Compression rate: ${response.compression.rate}`);
console.log(`Reduction: ${response.compression.reduction}%`);
console.log(`Cost savings: $${(response.compression.cost_savings / 1_000_000).toFixed(3)}`);
console.log(`Time: ${response.compression.time_ms} ms`);
}
```

Expand All @@ -60,7 +65,7 @@ if (response.compression) {
The `stream()` method enables real-time streaming responses:

```typescript
for await (const chunk of edgee.stream('gpt-5.2', 'Tell me a story')) {
for await (const chunk of edgee.stream('anthropic/claude-haiku-4-5', 'Tell me a story')) {
if (chunk.text) {
process.stdout.write(chunk.text);
}
Expand Down
35 changes: 17 additions & 18 deletions example/compression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ${LARGE_CONTEXT}
Based on this context, summarize the key milestones in AI development in 3 bullet points.`;

const response = await edgee.send({
model: "gpt-5.2",
model: "anthropic/claude-haiku-4-5",
input: {
messages: [{ role: "user", content: userMessage }],
enable_compression: true,
Expand All @@ -104,26 +104,25 @@ if (response.usage) {
// Display compression information
if (response.compression) {
console.log("Compression Metrics:");
console.log(` Input tokens: ${response.compression.input_tokens}`);
console.log(` Saved tokens: ${response.compression.saved_tokens}`);
console.log(` Reduction: ${response.compression.reduction}%`);
console.log(
` Compression rate: ${(response.compression.rate * 100).toFixed(2)}%`
);
const savingsPct =
response.compression.input_tokens > 0
? (response.compression.saved_tokens /
response.compression.input_tokens) *
100
: 0;
console.log(` Savings: ${savingsPct.toFixed(1)}% of input tokens saved!`);
console.log();
console.log(` 💡 Without compression, this request would have used`);
console.log(` ${response.compression.input_tokens} input tokens.`);
console.log(
` With compression, only ${
response.compression.input_tokens - response.compression.saved_tokens
} tokens were processed!`
` Cost savings: $${(response.compression.cost_savings / 1_000_000).toFixed(3)}`
);
console.log(` Time: ${response.compression.time_ms} ms`);
if (response.compression.reduction > 0) {
const originalTokens =
Math.floor(
(response.compression.saved_tokens * 100) / response.compression.reduction
);
const tokensAfter = originalTokens - response.compression.saved_tokens;
console.log();
console.log(` 💡 Without compression, this request would have used`);
console.log(` ${originalTokens} input tokens.`);
console.log(
` With compression, only ${tokensAfter} tokens were processed!`
);
}
} else {
console.log("No compression data available in response.");
console.log(
Expand Down
2 changes: 1 addition & 1 deletion example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"test": "npx tsx test.ts"
"test": "npx tsx test.ts",
"test:compression": "npx tsx compression.ts"
},
"dependencies": {
"edgee": "file:.."
Expand Down
19 changes: 16 additions & 3 deletions example/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const edgee = new Edgee(process.env.EDGEE_API_KEY || "test-key");
// Test 1: Simple string input
console.log("Test 1: Simple string input");
const response1 = await edgee.send({
model: "gpt-5.2",
model: "anthropic/claude-haiku-4-5",
input: "What is the capital of France?",
});
console.log("Content:", response1.choices[0].message.content);
Expand All @@ -15,7 +15,7 @@ console.log();
// Test 2: Full input object with messages
console.log("Test 2: Full input object with messages");
const response2 = await edgee.send({
model: "gpt-5.2",
model: "anthropic/claude-haiku-4-5",
input: {
messages: [
{ role: "system", content: "You are a helpful assistant." },
Expand All @@ -29,7 +29,7 @@ console.log();
// Test 3: With tools
console.log("Test 3: With tools");
const response3 = await edgee.send({
model: "gpt-5.2",
model: "anthropic/claude-haiku-4-5",
input: {
messages: [{ role: "user", content: "What is the weather in Paris?" }],
tools: [
Expand All @@ -56,3 +56,16 @@ console.log(
"Tool calls:",
JSON.stringify(response3.choices[0].message.tool_calls, null, 2)
);
console.log();

// Test 4: Streaming
console.log("Test 4: Streaming");
for await (const chunk of edgee.stream(
"anthropic/claude-haiku-4-5",
"What is Typescript?"
)) {
if (chunk.text) {
process.stdout.write(chunk.text);
}
}
console.log("\n");
Loading