edgee 1.0.0__tar.gz → 1.0.1__tar.gz
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.
- edgee-1.0.1/.github/CODEOWNERS +1 -0
- {edgee-1.0.0 → edgee-1.0.1}/PKG-INFO +20 -10
- {edgee-1.0.0 → edgee-1.0.1}/README.md +16 -6
- {edgee-1.0.0 → edgee-1.0.1}/edgee/__init__.py +39 -1
- edgee-1.0.1/example/compression.py +135 -0
- {edgee-1.0.0 → edgee-1.0.1}/pyproject.toml +13 -18
- {edgee-1.0.0 → edgee-1.0.1}/tests/test_edgee.py +47 -0
- {edgee-1.0.0 → edgee-1.0.1}/uv.lock +1 -1
- edgee-1.0.0/.github/CODEOWNERS +0 -1
- {edgee-1.0.0 → edgee-1.0.1}/.github/workflows/check.yml +0 -0
- {edgee-1.0.0 → edgee-1.0.1}/.github/workflows/release.yml +0 -0
- {edgee-1.0.0 → edgee-1.0.1}/.gitignore +0 -0
- {edgee-1.0.0 → edgee-1.0.1}/LICENSE +0 -0
- {edgee-1.0.0 → edgee-1.0.1}/edgee/py.typed +0 -0
- {edgee-1.0.0 → edgee-1.0.1}/example/test.py +0 -0
- {edgee-1.0.0 → edgee-1.0.1}/tests/__init__.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @edgee-ai/edgeers
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: edgee
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.1
|
|
4
4
|
Summary: Lightweight Python SDK for Edgee AI Gateway
|
|
5
|
-
Project-URL: Homepage, https://github.com/edgee-
|
|
6
|
-
Project-URL: Repository, https://github.com/edgee-
|
|
7
|
-
Author-email: Edgee <support@edgee.
|
|
5
|
+
Project-URL: Homepage, https://github.com/edgee-ai/python-sdk
|
|
6
|
+
Project-URL: Repository, https://github.com/edgee-ai/python-sdk
|
|
7
|
+
Author-email: Edgee <support@edgee.ai>
|
|
8
8
|
License-Expression: Apache-2.0
|
|
9
9
|
License-File: LICENSE
|
|
10
10
|
Keywords: ai,anthropic,gateway,llm,openai
|
|
@@ -24,7 +24,7 @@ Description-Content-Type: text/markdown
|
|
|
24
24
|
|
|
25
25
|
# Edgee Python SDK
|
|
26
26
|
|
|
27
|
-
Lightweight, type-safe Python SDK for the [Edgee AI Gateway](https://www.edgee.
|
|
27
|
+
Lightweight, type-safe Python SDK for the [Edgee AI Gateway](https://www.edgee.ai).
|
|
28
28
|
|
|
29
29
|
[]( )
|
|
30
30
|
[](LICENSE)
|
|
@@ -66,6 +66,15 @@ response = edgee.send(
|
|
|
66
66
|
print(response.text) # Text content
|
|
67
67
|
print(response.finish_reason) # Finish reason
|
|
68
68
|
print(response.tool_calls) # Tool calls (if any)
|
|
69
|
+
|
|
70
|
+
# Access usage and compression info
|
|
71
|
+
if response.usage:
|
|
72
|
+
print(f"Tokens used: {response.usage.total_tokens}")
|
|
73
|
+
|
|
74
|
+
if response.compression:
|
|
75
|
+
print(f"Input tokens: {response.compression.input_tokens}")
|
|
76
|
+
print(f"Saved tokens: {response.compression.saved_tokens}")
|
|
77
|
+
print(f"Compression rate: {response.compression.rate}")
|
|
69
78
|
```
|
|
70
79
|
|
|
71
80
|
## Stream Method
|
|
@@ -88,19 +97,20 @@ for chunk in edgee.stream("gpt-4o", "Tell me a story"):
|
|
|
88
97
|
- ✅ **Streaming** - Real-time response streaming with generators
|
|
89
98
|
- ✅ **Tool calling** - Full support for function calling
|
|
90
99
|
- ✅ **Flexible input** - Accept strings, dicts, or InputObject
|
|
100
|
+
- ✅ **Compression info** - Access token compression metrics in responses
|
|
91
101
|
- ✅ **Zero dependencies** - Uses only Python standard library
|
|
92
102
|
|
|
93
103
|
## Documentation
|
|
94
104
|
|
|
95
105
|
For complete documentation, examples, and API reference, visit:
|
|
96
106
|
|
|
97
|
-
**👉 [Official Python SDK Documentation](https://www.edgee.
|
|
107
|
+
**👉 [Official Python SDK Documentation](https://www.edgee.ai/docs/sdk/python)**
|
|
98
108
|
|
|
99
109
|
The documentation includes:
|
|
100
|
-
- [Configuration guide](https://www.edgee.
|
|
101
|
-
- [Send method](https://www.edgee.
|
|
102
|
-
- [Stream method](https://www.edgee.
|
|
103
|
-
- [Tools](https://www.edgee.
|
|
110
|
+
- [Configuration guide](https://www.edgee.ai/docs/sdk/python/configuration) - Multiple ways to configure the SDK
|
|
111
|
+
- [Send method](https://www.edgee.ai/docs/sdk/python/send) - Complete guide to non-streaming requests
|
|
112
|
+
- [Stream method](https://www.edgee.ai/docs/sdk/python/stream) - Streaming responses guide
|
|
113
|
+
- [Tools](https://www.edgee.ai/docs/sdk/python/tools) - Function calling guide
|
|
104
114
|
|
|
105
115
|
## License
|
|
106
116
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Edgee Python SDK
|
|
2
2
|
|
|
3
|
-
Lightweight, type-safe Python SDK for the [Edgee AI Gateway](https://www.edgee.
|
|
3
|
+
Lightweight, type-safe Python SDK for the [Edgee AI Gateway](https://www.edgee.ai).
|
|
4
4
|
|
|
5
5
|
[]( )
|
|
6
6
|
[](LICENSE)
|
|
@@ -42,6 +42,15 @@ response = edgee.send(
|
|
|
42
42
|
print(response.text) # Text content
|
|
43
43
|
print(response.finish_reason) # Finish reason
|
|
44
44
|
print(response.tool_calls) # Tool calls (if any)
|
|
45
|
+
|
|
46
|
+
# Access usage and compression info
|
|
47
|
+
if response.usage:
|
|
48
|
+
print(f"Tokens used: {response.usage.total_tokens}")
|
|
49
|
+
|
|
50
|
+
if response.compression:
|
|
51
|
+
print(f"Input tokens: {response.compression.input_tokens}")
|
|
52
|
+
print(f"Saved tokens: {response.compression.saved_tokens}")
|
|
53
|
+
print(f"Compression rate: {response.compression.rate}")
|
|
45
54
|
```
|
|
46
55
|
|
|
47
56
|
## Stream Method
|
|
@@ -64,19 +73,20 @@ for chunk in edgee.stream("gpt-4o", "Tell me a story"):
|
|
|
64
73
|
- ✅ **Streaming** - Real-time response streaming with generators
|
|
65
74
|
- ✅ **Tool calling** - Full support for function calling
|
|
66
75
|
- ✅ **Flexible input** - Accept strings, dicts, or InputObject
|
|
76
|
+
- ✅ **Compression info** - Access token compression metrics in responses
|
|
67
77
|
- ✅ **Zero dependencies** - Uses only Python standard library
|
|
68
78
|
|
|
69
79
|
## Documentation
|
|
70
80
|
|
|
71
81
|
For complete documentation, examples, and API reference, visit:
|
|
72
82
|
|
|
73
|
-
**👉 [Official Python SDK Documentation](https://www.edgee.
|
|
83
|
+
**👉 [Official Python SDK Documentation](https://www.edgee.ai/docs/sdk/python)**
|
|
74
84
|
|
|
75
85
|
The documentation includes:
|
|
76
|
-
- [Configuration guide](https://www.edgee.
|
|
77
|
-
- [Send method](https://www.edgee.
|
|
78
|
-
- [Stream method](https://www.edgee.
|
|
79
|
-
- [Tools](https://www.edgee.
|
|
86
|
+
- [Configuration guide](https://www.edgee.ai/docs/sdk/python/configuration) - Multiple ways to configure the SDK
|
|
87
|
+
- [Send method](https://www.edgee.ai/docs/sdk/python/send) - Complete guide to non-streaming requests
|
|
88
|
+
- [Stream method](https://www.edgee.ai/docs/sdk/python/stream) - Streaming responses guide
|
|
89
|
+
- [Tools](https://www.edgee.ai/docs/sdk/python/tools) - Function calling guide
|
|
80
90
|
|
|
81
91
|
## License
|
|
82
92
|
|
|
@@ -45,6 +45,13 @@ class InputObject:
|
|
|
45
45
|
messages: list[dict]
|
|
46
46
|
tools: list[dict] | None = None
|
|
47
47
|
tool_choice: str | dict | None = None
|
|
48
|
+
tags: list[str] | None = None
|
|
49
|
+
enable_compression: bool | None = (
|
|
50
|
+
None # Enable token compression (gateway-internal, not sent to providers)
|
|
51
|
+
)
|
|
52
|
+
compression_rate: float | None = (
|
|
53
|
+
None # Compression rate 0.0-1.0 (gateway-internal, not sent to providers)
|
|
54
|
+
)
|
|
48
55
|
|
|
49
56
|
|
|
50
57
|
@dataclass
|
|
@@ -61,10 +68,18 @@ class Usage:
|
|
|
61
68
|
total_tokens: int
|
|
62
69
|
|
|
63
70
|
|
|
71
|
+
@dataclass
|
|
72
|
+
class Compression:
|
|
73
|
+
input_tokens: int
|
|
74
|
+
saved_tokens: int
|
|
75
|
+
rate: float
|
|
76
|
+
|
|
77
|
+
|
|
64
78
|
@dataclass
|
|
65
79
|
class SendResponse:
|
|
66
80
|
choices: list[Choice]
|
|
67
81
|
usage: Usage | None = None
|
|
82
|
+
compression: Compression | None = None
|
|
68
83
|
|
|
69
84
|
@property
|
|
70
85
|
def text(self) -> str | None:
|
|
@@ -188,14 +203,23 @@ class Edgee:
|
|
|
188
203
|
messages = [{"role": "user", "content": input}]
|
|
189
204
|
tools = None
|
|
190
205
|
tool_choice = None
|
|
206
|
+
tags = None
|
|
207
|
+
enable_compression = None
|
|
208
|
+
compression_rate = None
|
|
191
209
|
elif isinstance(input, InputObject):
|
|
192
210
|
messages = input.messages
|
|
193
211
|
tools = input.tools
|
|
194
212
|
tool_choice = input.tool_choice
|
|
213
|
+
tags = input.tags
|
|
214
|
+
enable_compression = input.enable_compression
|
|
215
|
+
compression_rate = input.compression_rate
|
|
195
216
|
else:
|
|
196
217
|
messages = input.get("messages", [])
|
|
197
218
|
tools = input.get("tools")
|
|
198
219
|
tool_choice = input.get("tool_choice")
|
|
220
|
+
tags = input.get("tags")
|
|
221
|
+
enable_compression = input.get("enable_compression")
|
|
222
|
+
compression_rate = input.get("compression_rate")
|
|
199
223
|
|
|
200
224
|
body: dict = {"model": model, "messages": messages}
|
|
201
225
|
if stream:
|
|
@@ -204,6 +228,12 @@ class Edgee:
|
|
|
204
228
|
body["tools"] = tools
|
|
205
229
|
if tool_choice:
|
|
206
230
|
body["tool_choice"] = tool_choice
|
|
231
|
+
if tags:
|
|
232
|
+
body["tags"] = tags
|
|
233
|
+
if enable_compression is not None:
|
|
234
|
+
body["enable_compression"] = enable_compression
|
|
235
|
+
if compression_rate is not None:
|
|
236
|
+
body["compression_rate"] = compression_rate
|
|
207
237
|
|
|
208
238
|
request = Request(
|
|
209
239
|
f"{self.base_url}{API_ENDPOINT}",
|
|
@@ -246,7 +276,15 @@ class Edgee:
|
|
|
246
276
|
total_tokens=data["usage"]["total_tokens"],
|
|
247
277
|
)
|
|
248
278
|
|
|
249
|
-
|
|
279
|
+
compression = None
|
|
280
|
+
if "compression" in data:
|
|
281
|
+
compression = Compression(
|
|
282
|
+
input_tokens=data["compression"]["input_tokens"],
|
|
283
|
+
saved_tokens=data["compression"]["saved_tokens"],
|
|
284
|
+
rate=data["compression"]["rate"],
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
return SendResponse(choices=choices, usage=usage, compression=compression)
|
|
250
288
|
|
|
251
289
|
def _handle_streaming_response(self, request: Request):
|
|
252
290
|
"""Handle streaming response, yielding StreamChunk objects."""
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Example: Token compression with Edgee Gateway SDK
|
|
2
|
+
|
|
3
|
+
This example demonstrates how to:
|
|
4
|
+
1. Enable compression for a request with a large input context
|
|
5
|
+
2. Set a custom compression rate
|
|
6
|
+
3. Access compression metrics from the response
|
|
7
|
+
|
|
8
|
+
IMPORTANT: Only USER messages are compressed. System messages are not compressed.
|
|
9
|
+
This example includes a large context in the user message to demonstrate meaningful
|
|
10
|
+
compression savings.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
# Add parent directory to path for local testing
|
|
17
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
18
|
+
|
|
19
|
+
from edgee import Edgee
|
|
20
|
+
|
|
21
|
+
# Initialize the client
|
|
22
|
+
edgee = Edgee(os.environ.get("EDGEE_API_KEY"))
|
|
23
|
+
|
|
24
|
+
# Large context document to demonstrate input compression
|
|
25
|
+
LARGE_CONTEXT = """
|
|
26
|
+
The History and Impact of Artificial Intelligence
|
|
27
|
+
|
|
28
|
+
Artificial intelligence (AI) has evolved from a theoretical concept to a
|
|
29
|
+
transformative technology that influences nearly every aspect of modern life.
|
|
30
|
+
The field began in earnest in the 1950s when pioneers like Alan Turing and
|
|
31
|
+
John McCarthy laid the groundwork for machine intelligence.
|
|
32
|
+
|
|
33
|
+
Early developments focused on symbolic reasoning and expert systems. These
|
|
34
|
+
rule-based approaches dominated the field through the 1970s and 1980s, with
|
|
35
|
+
systems like MYCIN demonstrating practical applications in medical diagnosis.
|
|
36
|
+
However, these early systems were limited by their inability to learn from data
|
|
37
|
+
and adapt to new situations.
|
|
38
|
+
|
|
39
|
+
The resurgence of neural networks in the 1980s and 1990s, particularly with
|
|
40
|
+
backpropagation algorithms, opened new possibilities. Yet it wasn't until the
|
|
41
|
+
2010s, with the advent of deep learning and the availability of massive datasets
|
|
42
|
+
and computational power, that AI truly began to revolutionize industries.
|
|
43
|
+
|
|
44
|
+
Modern AI applications span numerous domains:
|
|
45
|
+
- Natural language processing enables machines to understand and generate human language
|
|
46
|
+
- Computer vision allows machines to interpret visual information from the world
|
|
47
|
+
- Robotics combines AI with mechanical systems for autonomous operation
|
|
48
|
+
- Healthcare uses AI for diagnosis, drug discovery, and personalized treatment
|
|
49
|
+
- Finance leverages AI for fraud detection, algorithmic trading, and risk assessment
|
|
50
|
+
- Transportation is being transformed by autonomous vehicles and traffic optimization
|
|
51
|
+
|
|
52
|
+
The development of large language models like GPT, BERT, and others has
|
|
53
|
+
particularly accelerated progress in natural language understanding and generation.
|
|
54
|
+
These models, trained on vast amounts of text data, can perform a wide range of
|
|
55
|
+
language tasks with remarkable proficiency.
|
|
56
|
+
|
|
57
|
+
Despite remarkable progress, significant challenges remain. Issues of bias,
|
|
58
|
+
interpretability, safety, and ethical considerations continue to be areas of
|
|
59
|
+
active research and debate. The AI community is working to ensure that these
|
|
60
|
+
powerful technologies are developed and deployed responsibly, with consideration
|
|
61
|
+
for their societal impact.
|
|
62
|
+
|
|
63
|
+
Looking forward, AI is expected to continue advancing rapidly, with potential
|
|
64
|
+
breakthroughs in areas like artificial general intelligence, quantum machine
|
|
65
|
+
learning, and brain-computer interfaces. The integration of AI into daily life
|
|
66
|
+
will likely deepen, raising important questions about human-AI collaboration,
|
|
67
|
+
workforce transformation, and the future of human cognition itself.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
print("=" * 70)
|
|
71
|
+
print("Edgee Token Compression Example")
|
|
72
|
+
print("=" * 70)
|
|
73
|
+
print()
|
|
74
|
+
|
|
75
|
+
# Example: Request with compression enabled and large input
|
|
76
|
+
print("Example: Large user message with compression enabled")
|
|
77
|
+
print("-" * 70)
|
|
78
|
+
print(f"Input context length: {len(LARGE_CONTEXT)} characters")
|
|
79
|
+
print()
|
|
80
|
+
|
|
81
|
+
# NOTE: Only USER messages are compressed
|
|
82
|
+
# Put the large context in the user message to demonstrate compression
|
|
83
|
+
user_message = f"""Here is some context about AI:
|
|
84
|
+
|
|
85
|
+
{LARGE_CONTEXT}
|
|
86
|
+
|
|
87
|
+
Based on this context, summarize the key milestones in AI development in 3 bullet points."""
|
|
88
|
+
|
|
89
|
+
response = edgee.send(
|
|
90
|
+
model="gpt-4o",
|
|
91
|
+
input={
|
|
92
|
+
"messages": [
|
|
93
|
+
{"role": "user", "content": user_message},
|
|
94
|
+
],
|
|
95
|
+
"enable_compression": True,
|
|
96
|
+
"compression_rate": 0.5,
|
|
97
|
+
},
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
print(f"Response: {response.text}")
|
|
101
|
+
print()
|
|
102
|
+
|
|
103
|
+
# Display usage information
|
|
104
|
+
if response.usage:
|
|
105
|
+
print("Token Usage:")
|
|
106
|
+
print(f" Prompt tokens: {response.usage.prompt_tokens}")
|
|
107
|
+
print(f" Completion tokens: {response.usage.completion_tokens}")
|
|
108
|
+
print(f" Total tokens: {response.usage.total_tokens}")
|
|
109
|
+
print()
|
|
110
|
+
|
|
111
|
+
# Display compression information
|
|
112
|
+
if response.compression:
|
|
113
|
+
print("Compression Metrics:")
|
|
114
|
+
print(f" Input tokens: {response.compression.input_tokens}")
|
|
115
|
+
print(f" Saved tokens: {response.compression.saved_tokens}")
|
|
116
|
+
print(f" Compression rate: {response.compression.rate:.2%}")
|
|
117
|
+
savings_pct = (
|
|
118
|
+
(response.compression.saved_tokens / response.compression.input_tokens * 100)
|
|
119
|
+
if response.compression.input_tokens > 0
|
|
120
|
+
else 0
|
|
121
|
+
)
|
|
122
|
+
print(f" Savings: {savings_pct:.1f}% of input tokens saved!")
|
|
123
|
+
print()
|
|
124
|
+
print(" 💡 Without compression, this request would have used")
|
|
125
|
+
print(f" {response.compression.input_tokens} input tokens.")
|
|
126
|
+
print(
|
|
127
|
+
f" With compression, only {response.compression.input_tokens - response.compression.saved_tokens} tokens were processed!"
|
|
128
|
+
)
|
|
129
|
+
else:
|
|
130
|
+
print("No compression data available in response.")
|
|
131
|
+
print("Note: Compression data is only returned when compression is enabled")
|
|
132
|
+
print(" and supported by your API key configuration.")
|
|
133
|
+
|
|
134
|
+
print()
|
|
135
|
+
print("=" * 70)
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "edgee"
|
|
3
|
-
version = "1.0.
|
|
3
|
+
version = "1.0.1"
|
|
4
4
|
description = "Lightweight Python SDK for Edgee AI Gateway"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
7
7
|
requires-python = ">=3.10"
|
|
8
8
|
dependencies = []
|
|
9
|
-
authors = [
|
|
10
|
-
{ name = "Edgee", email = "support@edgee.cloud" }
|
|
11
|
-
]
|
|
9
|
+
authors = [{ name = "Edgee", email = "support@edgee.ai" }]
|
|
12
10
|
keywords = ["ai", "llm", "gateway", "openai", "anthropic"]
|
|
13
11
|
classifiers = [
|
|
14
12
|
"Development Status :: 4 - Beta",
|
|
@@ -22,8 +20,8 @@ classifiers = [
|
|
|
22
20
|
]
|
|
23
21
|
|
|
24
22
|
[project.urls]
|
|
25
|
-
Homepage = "https://github.com/edgee-
|
|
26
|
-
Repository = "https://github.com/edgee-
|
|
23
|
+
Homepage = "https://github.com/edgee-ai/python-sdk"
|
|
24
|
+
Repository = "https://github.com/edgee-ai/python-sdk"
|
|
27
25
|
|
|
28
26
|
[project.optional-dependencies]
|
|
29
27
|
dev = ["pytest>=8.0.0", "ruff>=0.8.0"]
|
|
@@ -41,16 +39,16 @@ line-length = 100
|
|
|
41
39
|
|
|
42
40
|
[tool.ruff.lint]
|
|
43
41
|
select = [
|
|
44
|
-
"E",
|
|
45
|
-
"W",
|
|
46
|
-
"F",
|
|
47
|
-
"I",
|
|
48
|
-
"B",
|
|
49
|
-
"C4",
|
|
50
|
-
"UP",
|
|
42
|
+
"E", # pycodestyle errors
|
|
43
|
+
"W", # pycodestyle warnings
|
|
44
|
+
"F", # pyflakes
|
|
45
|
+
"I", # isort
|
|
46
|
+
"B", # flake8-bugbear
|
|
47
|
+
"C4", # flake8-comprehensions
|
|
48
|
+
"UP", # pyupgrade
|
|
51
49
|
]
|
|
52
50
|
ignore = [
|
|
53
|
-
"E501",
|
|
51
|
+
"E501", # line too long (handled by formatter)
|
|
54
52
|
]
|
|
55
53
|
|
|
56
54
|
[tool.ruff.format]
|
|
@@ -58,7 +56,4 @@ quote-style = "double"
|
|
|
58
56
|
indent-style = "space"
|
|
59
57
|
|
|
60
58
|
[dependency-groups]
|
|
61
|
-
dev = [
|
|
62
|
-
"pytest>=8.0.0",
|
|
63
|
-
"ruff>=0.8.0",
|
|
64
|
-
]
|
|
59
|
+
dev = ["pytest>=8.0.0", "ruff>=0.8.0"]
|
|
@@ -306,3 +306,50 @@ class TestEdgeeSend:
|
|
|
306
306
|
|
|
307
307
|
call_args = mock_urlopen.call_args[0][0]
|
|
308
308
|
assert call_args.full_url == f"{config_base_url}/v1/chat/completions"
|
|
309
|
+
|
|
310
|
+
@patch("edgee.urlopen")
|
|
311
|
+
def test_send_with_compression_response(self, mock_urlopen):
|
|
312
|
+
"""Should handle response with compression field"""
|
|
313
|
+
mock_response_data = {
|
|
314
|
+
"choices": [
|
|
315
|
+
{
|
|
316
|
+
"index": 0,
|
|
317
|
+
"message": {"role": "assistant", "content": "Response"},
|
|
318
|
+
"finish_reason": "stop",
|
|
319
|
+
}
|
|
320
|
+
],
|
|
321
|
+
"usage": {"prompt_tokens": 100, "completion_tokens": 50, "total_tokens": 150},
|
|
322
|
+
"compression": {
|
|
323
|
+
"input_tokens": 100,
|
|
324
|
+
"saved_tokens": 42,
|
|
325
|
+
"rate": 0.6102003642987249,
|
|
326
|
+
},
|
|
327
|
+
}
|
|
328
|
+
mock_urlopen.return_value = self._mock_response(mock_response_data)
|
|
329
|
+
|
|
330
|
+
client = Edgee("test-api-key")
|
|
331
|
+
result = client.send(model="gpt-4", input="Test")
|
|
332
|
+
|
|
333
|
+
assert result.compression is not None
|
|
334
|
+
assert result.compression.input_tokens == 100
|
|
335
|
+
assert result.compression.saved_tokens == 42
|
|
336
|
+
assert result.compression.rate == 0.6102003642987249
|
|
337
|
+
|
|
338
|
+
@patch("edgee.urlopen")
|
|
339
|
+
def test_send_without_compression_response(self, mock_urlopen):
|
|
340
|
+
"""Should handle response without compression field"""
|
|
341
|
+
mock_response_data = {
|
|
342
|
+
"choices": [
|
|
343
|
+
{
|
|
344
|
+
"index": 0,
|
|
345
|
+
"message": {"role": "assistant", "content": "Response"},
|
|
346
|
+
"finish_reason": "stop",
|
|
347
|
+
}
|
|
348
|
+
],
|
|
349
|
+
}
|
|
350
|
+
mock_urlopen.return_value = self._mock_response(mock_response_data)
|
|
351
|
+
|
|
352
|
+
client = Edgee("test-api-key")
|
|
353
|
+
result = client.send(model="gpt-4", input="Test")
|
|
354
|
+
|
|
355
|
+
assert result.compression is None
|
edgee-1.0.0/.github/CODEOWNERS
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
* @edgee-cloud/edgeers
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|