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 @@ -28,7 +28,11 @@ func main() {
log.Fatal(err)
}

<<<<<<< HEAD
response, err := client.Send("gpt-5.2", "What is the capital of France?")
=======
response, err := client.Send("anthropic/claude-haiku-4-5", "What is the capital of France?")
>>>>>>> d846ba2 (feat: update compression response to new API format)
if err != nil {
log.Fatal(err)
}
Expand All @@ -43,7 +47,7 @@ func main() {
The `Send()` method makes non-streaming chat completion requests:

```go
response, err := client.Send("gpt-5.2", "Hello, world!")
response, err := client.Send("anthropic/claude-haiku-4-5", "Hello, world!")
if err != nil {
log.Fatal(err)
}
Expand All @@ -59,9 +63,10 @@ if response.Usage != nil {
}

if response.Compression != nil {
fmt.Printf("Input tokens: %d\n", response.Compression.InputTokens)
fmt.Printf("Saved tokens: %d\n", response.Compression.SavedTokens)
fmt.Printf("Compression rate: %.2f\n", response.Compression.Rate)
fmt.Printf("Reduction: %.1f%%\n", response.Compression.Reduction)
fmt.Printf("Cost savings: $%.3f\n", float64(response.Compression.CostSavings)/1000000)
fmt.Printf("Time: %d ms\n", response.Compression.TimeMs)
}
```

Expand All @@ -70,7 +75,7 @@ if response.Compression != nil {
The `Stream()` method enables real-time streaming responses:

```go
chunkChan, errChan := client.Stream("gpt-5.2", "Tell me a story")
chunkChan, errChan := client.Stream("anthropic/claude-haiku-4-5", "Tell me a story")

for {
select {
Expand Down
5 changes: 3 additions & 2 deletions edgee/edgee.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ type Usage struct {

// Compression represents compression information
type Compression struct {
InputTokens int `json:"input_tokens"`
SavedTokens int `json:"saved_tokens"`
Rate float64 `json:"rate"`
CostSavings int `json:"cost_savings"` // micro-units (e.g. 27000 = $0.027)
Reduction float64 `json:"reduction"` // percentage (e.g. 48 = 48%, may be fractional)
TimeMs int `json:"time_ms"` // milliseconds
}

// SendResponse represents the response from a non-streaming request
Expand Down
18 changes: 11 additions & 7 deletions edgee/edgee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,10 @@ func TestClient_SendWithCompression(t *testing.T) {
TotalTokens: 150,
},
Compression: &Compression{
InputTokens: 100,
SavedTokens: 42,
Rate: 0.6102003642987249,
CostSavings: 27000,
Reduction: 48.0,
TimeMs: 150,
},
}

Expand All @@ -726,14 +727,17 @@ func TestClient_SendWithCompression(t *testing.T) {
if response.Compression == nil {
t.Fatal("Expected compression data, got nil")
}
if response.Compression.InputTokens != 100 {
t.Errorf("Expected input_tokens 100, got %d", response.Compression.InputTokens)
}
if response.Compression.SavedTokens != 42 {
t.Errorf("Expected saved_tokens 42, got %d", response.Compression.SavedTokens)
}
if response.Compression.Rate != 0.6102003642987249 {
t.Errorf("Expected rate 0.6102003642987249, got %f", response.Compression.Rate)
if response.Compression.CostSavings != 27000 {
t.Errorf("Expected cost_savings 27000, got %d", response.Compression.CostSavings)
}
if response.Compression.Reduction != 48.0 {
t.Errorf("Expected reduction 48, got %f", response.Compression.Reduction)
}
if response.Compression.TimeMs != 150 {
t.Errorf("Expected time_ms 150, got %d", response.Compression.TimeMs)
}
})

Expand Down
8 changes: 4 additions & 4 deletions example/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {

// Test 1: Simple string input
fmt.Println("Test 1: Simple string input")
response1, err := client.ChatCompletion("mistral/mistral-small-latest", "What is the capital of France?")
response1, err := client.ChatCompletion("anthropic/claude-haiku-4-5", "What is the capital of France?")
if err != nil {
log.Printf("Error: %v\n", err)
} else {
Expand All @@ -29,7 +29,7 @@ func main() {

// Test 2: Full input object with messages
fmt.Println("Test 2: Full input object with messages")
response2, err := client.ChatCompletion("mistral/mistral-small-latest", map[string]interface{}{
response2, err := client.ChatCompletion("anthropic/claude-haiku-4-5", map[string]interface{}{
"messages": []map[string]string{
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Say hello!"},
Expand All @@ -44,7 +44,7 @@ func main() {

// Test 3: With tools
fmt.Println("Test 3: With tools")
response3, err := client.ChatCompletion("gpt-5.2", map[string]interface{}{
response3, err := client.ChatCompletion("anthropic/claude-haiku-4-5", map[string]interface{}{
"messages": []map[string]string{
{"role": "user", "content": "What is the weather in Paris?"},
},
Expand Down Expand Up @@ -81,7 +81,7 @@ func main() {

// Test 4: Streaming
fmt.Println("Test 4: Streaming")
chunkChan, errChan := client.Stream("mistral/mistral-small-latest", "What is Go?")
chunkChan, errChan := client.Stream("anthropic/claude-haiku-4-5", "What is Go?")
for {
select {
case chunk, ok := <-chunkChan:
Expand Down
24 changes: 11 additions & 13 deletions example/compression/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Based on this context, summarize the key milestones in AI development in 3 bulle
input.EnableCompression = &enableCompression
input.CompressionRate = &compressionRate

response, err := client.Send("gpt-5.2", input)
response, err := client.Send("anthropic/claude-haiku-4-5", input)
if err != nil {
log.Fatalf("Error: %v", err)
}
Expand All @@ -115,20 +115,18 @@ Based on this context, summarize the key milestones in AI development in 3 bulle
// Display compression information
if response.Compression != nil {
fmt.Println("Compression Metrics:")
fmt.Printf(" Input tokens: %d\n", response.Compression.InputTokens)
fmt.Printf(" Saved tokens: %d\n", response.Compression.SavedTokens)
fmt.Printf(" Compression rate: %.2f%%\n", response.Compression.Rate*100)

var savingsPct float64
if response.Compression.InputTokens > 0 {
savingsPct = (float64(response.Compression.SavedTokens) / float64(response.Compression.InputTokens)) * 100
fmt.Printf(" Reduction: %.1f%%\n", response.Compression.Reduction)
fmt.Printf(" Cost savings: $%.3f\n", float64(response.Compression.CostSavings)/1000000)
fmt.Printf(" Time: %d ms\n", response.Compression.TimeMs)
if response.Compression.Reduction > 0 {
originalTokens := int(float64(response.Compression.SavedTokens) * 100 / response.Compression.Reduction)
tokensAfter := originalTokens - response.Compression.SavedTokens
fmt.Println()
fmt.Println(" 💡 Without compression, this request would have used")
fmt.Printf(" %d input tokens.\n", originalTokens)
fmt.Printf(" With compression, only %d tokens were processed!\n", tokensAfter)
}
fmt.Printf(" Savings: %.1f%% of input tokens saved!\n", savingsPct)
fmt.Println()
fmt.Println(" 💡 Without compression, this request would have used")
fmt.Printf(" %d input tokens.\n", response.Compression.InputTokens)
fmt.Printf(" With compression, only %d tokens were processed!\n",
response.Compression.InputTokens-response.Compression.SavedTokens)
} else {
fmt.Println("No compression data available in response.")
fmt.Println("Note: Compression data is only returned when compression is enabled")
Expand Down
Loading