Skip to content

Commit 7bccb99

Browse files
NicolasGirardotSachaMorardCLEMENTINATOR
authored
Feat/first implementation (#1)
Co-authored-by: SachaMorard <2254275+SachaMorard@users.noreply.github.com> Co-authored-by: Clement Bouvet <clement@cbouvet.fr>
1 parent 352d608 commit 7bccb99

11 files changed

Lines changed: 1067 additions & 3 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @edgee-cloud/edgeers

.github/workflows/check.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Check
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
jobs:
9+
Check:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Install uv
14+
uses: astral-sh/setup-uv@v4
15+
with:
16+
enable-cache: true
17+
- name: Set up Python
18+
run: uv python install 3.12
19+
- name: Install dependencies
20+
run: uv sync --all-extras
21+
- name: Ruff format check
22+
run: uv run ruff format --check .
23+
- name: Ruff lint
24+
run: uv run ruff check .
25+
- name: Run tests
26+
run: uv run pytest

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Release to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write # Required for trusted publishing
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.12"
21+
22+
- name: Install build dependencies
23+
run: pip install build
24+
25+
- name: Build package
26+
run: python -m build
27+
28+
- name: Publish to PyPI
29+
uses: pypa/gh-action-pypi-publish@release/v1
30+

README.md

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ response = edgee.send(
2424
input="What is the capital of France?",
2525
)
2626

27-
print(response.choices[0].message["content"])
27+
print(response.text)
2828
```
2929

3030
### Full Input with Messages
@@ -67,8 +67,40 @@ response = edgee.send(
6767
},
6868
)
6969

70-
if response.choices[0].message.get("tool_calls"):
71-
print(response.choices[0].message["tool_calls"])
70+
if response.tool_calls:
71+
print(response.tool_calls)
72+
```
73+
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+
```
83+
84+
#### Alternative: Using send(stream=True)
85+
86+
```python
87+
for chunk in edgee.send(model="gpt-4o", input="Tell me a story", stream=True):
88+
if chunk.text:
89+
print(chunk.text, end="", flush=True)
90+
```
91+
92+
#### Accessing Full Chunk Data
93+
94+
When you need complete access to the streaming response:
95+
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}")
72104
```
73105

74106
## Response
@@ -79,6 +111,12 @@ class SendResponse:
79111
choices: list[Choice]
80112
usage: Optional[Usage]
81113

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+
82120
@dataclass
83121
class Choice:
84122
index: int
@@ -91,3 +129,30 @@ class Usage:
91129
completion_tokens: int
92130
total_tokens: int
93131
```
132+
133+
### Streaming Response
134+
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+
```
157+
158+
To learn more about this SDK, please refer to the [dedicated documentation](https://www.edgee.cloud/docs/sdk/python).

0 commit comments

Comments
 (0)