Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ dist/
coverage/
.nyc_output/


# Environment
.env
15 changes: 0 additions & 15 deletions example/package.json

This file was deleted.

58 changes: 0 additions & 58 deletions example/test.ts

This file was deleted.

11 changes: 0 additions & 11 deletions example/tsconfig.json

This file was deleted.

2 changes: 2 additions & 0 deletions examples/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EDGEE_API_KEY=your_api_key_here
EDGEE_BASE_URL=https://api.edgee.ai
25 changes: 25 additions & 0 deletions examples/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Full input object with messages
*
* Use the messages array for multi-turn conversations
* and system prompts.
*/
import "dotenv/config";
import Edgee from "edgee";

const edgee = new Edgee({
apiKey: process.env.EDGEE_API_KEY,
baseUrl: process.env.EDGEE_BASE_URL,
});

const response = await edgee.send({
model: "devstral2",
input: {
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Say hello!" },
],
},
});

console.log("Content:", response.text);
31 changes: 28 additions & 3 deletions example/package-lock.json → examples/package-lock.json

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

22 changes: 22 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "edgee-sdk-examples",
"version": "1.0.0",
"type": "module",
"scripts": {
"simple": "npx tsx simple.ts",
"messages": "npx tsx messages.ts",
"tools:manual": "npx tsx tools_manual.ts",
"tools:auto": "npx tsx tools_auto.ts",
"tools:multiple": "npx tsx tools_multiple.ts",
"stream": "npx tsx stream.ts",
"stream:tools": "npx tsx stream_tools.ts",
"all": "npm run simple && npm run messages && npm run tools:manual && npm run tools:auto && npm run tools:multiple && npm run stream && npm run stream:tools"
},
"dependencies": {
"dotenv": "^17.2.3",
"edgee": "file:.."
},
"devDependencies": {
"tsx": "^4.7.0"
}
}
20 changes: 20 additions & 0 deletions examples/simple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Simple string input example
*
* The most basic way to use the SDK - just pass a string prompt.
*/
import "dotenv/config";
import Edgee from "edgee";

const edgee = new Edgee({
apiKey: process.env.EDGEE_API_KEY,
baseUrl: process.env.EDGEE_BASE_URL,
});

const response = await edgee.send({
model: "devstral2",
input: "What is the capital of France?",
});

console.log("Content:", response.text);
console.log("Usage:", response.usage);
20 changes: 20 additions & 0 deletions examples/stream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Simple streaming without tools
*
* Stream responses token by token for real-time output.
*/
import "dotenv/config";
import Edgee from "edgee";

const edgee = new Edgee({
apiKey: process.env.EDGEE_API_KEY,
baseUrl: process.env.EDGEE_BASE_URL,
});

process.stdout.write("Response: ");

for await (const chunk of edgee.stream("devstral2", "Say hello in 10 words!")) {
process.stdout.write(chunk.text ?? "");
}

console.log();
99 changes: 99 additions & 0 deletions examples/stream_tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* Streaming with automatic tool execution
*
* Combine streaming with auto tool execution.
* You receive events for chunks, tool starts, and tool results.
*/
import "dotenv/config";
import Edgee, { StreamEvent, Tool, z } from "edgee";

const edgee = new Edgee({
apiKey: process.env.EDGEE_API_KEY,
baseUrl: process.env.EDGEE_BASE_URL,
});

// Weather tool
const weatherTool = new Tool({
name: "get_weather",
description: "Get the current weather for a location",
schema: z.object({
location: z.string().describe("The city name"),
}),
handler: async (args) => {
const weatherData: Record<
string,
{ temperature: number; condition: string }
> = {
Paris: { temperature: 18, condition: "partly cloudy" },
London: { temperature: 12, condition: "rainy" },
"New York": { temperature: 22, condition: "sunny" },
};
const data = weatherData[args.location] || {
temperature: 20,
condition: "unknown",
};
return {
location: args.location,
temperature: data.temperature,
condition: data.condition,
};
},
});

// Calculator tool
const calculatorTool = new Tool({
name: "calculate",
description: "Perform basic arithmetic operations",
schema: z.object({
operation: z.enum(["add", "subtract", "multiply", "divide"]),
a: z.number(),
b: z.number(),
}),
handler: async ({ operation, a, b }) => {
const ops = {
add: a + b,
subtract: a - b,
multiply: a * b,
divide: b !== 0 ? a / b : "Error: division by zero",
};
return { operation, a, b, result: ops[operation] };
},
});

console.log("Streaming with tools...\n");
process.stdout.write("Response: ");

const stream: AsyncGenerator<StreamEvent> = edgee.stream({
model: "devstral2",
input: "What's 15 multiplied by 7, and what's the weather in Paris?",
tools: [weatherTool, calculatorTool],
});

for await (const event of stream) {
switch (event.type) {
case "chunk":
// Stream content as it arrives
process.stdout.write(event.chunk.text ?? "");
break;

case "tool_start":
// Tool is about to be executed
console.log(`\n [Tool starting: ${event.toolCall.function.name}]`);
break;

case "tool_result":
// Tool finished executing
console.log(
` [Tool result: ${event.toolName} -> ${JSON.stringify(event.result)}]`
);
process.stdout.write("Response: ");
break;

case "iteration_complete":
// One iteration of the tool loop completed
console.log(` [Iteration ${event.iteration} complete, continuing...]`);
break;
}
}

console.log();
Loading