|
1 | | -# Edgee Gateway SDK |
| 1 | +# Edgee Python SDK |
2 | 2 |
|
3 | | -Lightweight Python SDK for Edgee AI Gateway. |
| 3 | +Lightweight, type-safe Python SDK for the [Edgee AI Gateway](https://www.edgee.cloud). |
| 4 | + |
| 5 | +[]( ) |
| 6 | +[](LICENSE) |
4 | 7 |
|
5 | 8 | ## Installation |
6 | 9 |
|
7 | 10 | ```bash |
8 | 11 | pip install edgee |
9 | 12 | ``` |
10 | 13 |
|
11 | | -## Usage |
| 14 | +## Quick Start |
12 | 15 |
|
13 | 16 | ```python |
14 | 17 | from edgee import Edgee |
15 | 18 |
|
16 | | -edgee = Edgee(os.environ.get("EDGEE_API_KEY")) |
17 | | -``` |
18 | | - |
19 | | -### Simple Input |
| 19 | +edgee = Edgee("your-api-key") |
20 | 20 |
|
21 | | -```python |
| 21 | +# Send a simple request |
22 | 22 | response = edgee.send( |
23 | 23 | model="gpt-4o", |
24 | | - input="What is the capital of France?", |
| 24 | + input="What is the capital of France?" |
25 | 25 | ) |
26 | 26 |
|
27 | 27 | print(response.text) |
| 28 | +# "The capital of France is Paris." |
28 | 29 | ``` |
29 | 30 |
|
30 | | -### Full Input with Messages |
| 31 | +## Send Method |
31 | 32 |
|
32 | | -```python |
33 | | -response = edgee.send( |
34 | | - model="gpt-4o", |
35 | | - input={ |
36 | | - "messages": [ |
37 | | - {"role": "system", "content": "You are a helpful assistant."}, |
38 | | - {"role": "user", "content": "Hello!"}, |
39 | | - ], |
40 | | - }, |
41 | | -) |
42 | | -``` |
43 | | - |
44 | | -### With Tools |
| 33 | +The `send()` method makes non-streaming chat completion requests: |
45 | 34 |
|
46 | 35 | ```python |
47 | 36 | response = edgee.send( |
48 | 37 | model="gpt-4o", |
49 | | - input={ |
50 | | - "messages": [{"role": "user", "content": "What's the weather in Paris?"}], |
51 | | - "tools": [ |
52 | | - { |
53 | | - "type": "function", |
54 | | - "function": { |
55 | | - "name": "get_weather", |
56 | | - "description": "Get weather for a location", |
57 | | - "parameters": { |
58 | | - "type": "object", |
59 | | - "properties": { |
60 | | - "location": {"type": "string"}, |
61 | | - }, |
62 | | - }, |
63 | | - }, |
64 | | - }, |
65 | | - ], |
66 | | - "tool_choice": "auto", |
67 | | - }, |
| 38 | + input="Hello, world!" |
68 | 39 | ) |
69 | 40 |
|
70 | | -if response.tool_calls: |
71 | | - print(response.tool_calls) |
| 41 | +# Access response |
| 42 | +print(response.text) # Text content |
| 43 | +print(response.finish_reason) # Finish reason |
| 44 | +print(response.tool_calls) # Tool calls (if any) |
72 | 45 | ``` |
73 | 46 |
|
74 | | -### Streaming |
75 | | - |
76 | | -Access chunk properties for streaming: |
77 | | - |
78 | | -```python |
79 | | -for chunk in edgee.stream(model="gpt-4o", input="Tell me a story"): |
80 | | - if chunk.text: |
81 | | - print(chunk.text, end="", flush=True) |
82 | | -``` |
| 47 | +## Stream Method |
83 | 48 |
|
84 | | -#### Alternative: Using send(stream=True) |
| 49 | +The `stream()` method enables real-time streaming responses: |
85 | 50 |
|
86 | 51 | ```python |
87 | | -for chunk in edgee.send(model="gpt-4o", input="Tell me a story", stream=True): |
| 52 | +for chunk in edgee.stream("gpt-4o", "Tell me a story"): |
88 | 53 | if chunk.text: |
89 | 54 | print(chunk.text, end="", flush=True) |
| 55 | + |
| 56 | + if chunk.finish_reason: |
| 57 | + print(f"\nFinished: {chunk.finish_reason}") |
90 | 58 | ``` |
91 | 59 |
|
92 | | -#### Accessing Full Chunk Data |
| 60 | +## Features |
93 | 61 |
|
94 | | -When you need complete access to the streaming response: |
| 62 | +- ✅ **Type-safe** - Full type hints with dataclasses |
| 63 | +- ✅ **OpenAI-compatible** - Works with any model supported by Edgee |
| 64 | +- ✅ **Streaming** - Real-time response streaming with generators |
| 65 | +- ✅ **Tool calling** - Full support for function calling |
| 66 | +- ✅ **Flexible input** - Accept strings, dicts, or InputObject |
| 67 | +- ✅ **Zero dependencies** - Uses only Python standard library |
95 | 68 |
|
96 | | -```python |
97 | | -for chunk in edgee.stream(model="gpt-4o", input="Hello"): |
98 | | - if chunk.role: |
99 | | - print(f"Role: {chunk.role}") |
100 | | - if chunk.text: |
101 | | - print(chunk.text, end="", flush=True) |
102 | | - if chunk.finish_reason: |
103 | | - print(f"\nFinish: {chunk.finish_reason}") |
104 | | -``` |
| 69 | +## Documentation |
105 | 70 |
|
106 | | -## Response |
| 71 | +For complete documentation, examples, and API reference, visit: |
107 | 72 |
|
108 | | -```python |
109 | | -@dataclass |
110 | | -class SendResponse: |
111 | | - choices: list[Choice] |
112 | | - usage: Optional[Usage] |
113 | | - |
114 | | - # Convenience properties for easy access |
115 | | - text: str | None # Shortcut for choices[0].message["content"] |
116 | | - message: dict | None # Shortcut for choices[0].message |
117 | | - finish_reason: str | None # Shortcut for choices[0].finish_reason |
118 | | - tool_calls: list | None # Shortcut for choices[0].message["tool_calls"] |
119 | | - |
120 | | -@dataclass |
121 | | -class Choice: |
122 | | - index: int |
123 | | - message: dict # {"role": str, "content": str | None, "tool_calls": list | None} |
124 | | - finish_reason: str | None |
125 | | - |
126 | | -@dataclass |
127 | | -class Usage: |
128 | | - prompt_tokens: int |
129 | | - completion_tokens: int |
130 | | - total_tokens: int |
131 | | -``` |
| 73 | +**👉 [Official Python SDK Documentation](https://www.edgee.cloud/docs/sdk/python)** |
132 | 74 |
|
133 | | -### Streaming Response |
| 75 | +The documentation includes: |
| 76 | +- [Configuration guide](https://www.edgee.cloud/docs/sdk/python/configuration) - Multiple ways to configure the SDK |
| 77 | +- [Send method](https://www.edgee.cloud/docs/sdk/python/send) - Complete guide to non-streaming requests |
| 78 | +- [Stream method](https://www.edgee.cloud/docs/sdk/python/stream) - Streaming responses guide |
| 79 | +- [Tools](https://www.edgee.cloud/docs/sdk/python/tools) - Function calling guide |
134 | 80 |
|
135 | | -```python |
136 | | -@dataclass |
137 | | -class StreamChunk: |
138 | | - choices: list[StreamChoice] |
139 | | - |
140 | | - # Convenience properties for easy access |
141 | | - text: str | None # Shortcut for choices[0].delta.content |
142 | | - role: str | None # Shortcut for choices[0].delta.role |
143 | | - finish_reason: str | None # Shortcut for choices[0].finish_reason |
144 | | - |
145 | | -@dataclass |
146 | | -class StreamChoice: |
147 | | - index: int |
148 | | - delta: StreamDelta |
149 | | - finish_reason: str | None |
150 | | - |
151 | | -@dataclass |
152 | | -class StreamDelta: |
153 | | - role: str | None # Only present in first chunk |
154 | | - content: str | None |
155 | | - tool_calls: list[dict] | None |
156 | | -``` |
| 81 | +## License |
157 | 82 |
|
158 | | -To learn more about this SDK, please refer to the [dedicated documentation](https://www.edgee.cloud/docs/sdk/python). |
| 83 | +Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details. |
0 commit comments