poe 0.1.0__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.
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ name: Test Python ${{ matrix.python-version }}
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ python-version: ["3.9", "3.12", "3.13"]
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python ${{ matrix.python-version }}
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+
24
+ - name: Install dependencies
25
+ run: |
26
+ python -m pip install --upgrade pip
27
+ pip install -e ".[dev]"
28
+
29
+ - name: Run tests
30
+ run: pytest tests/ -v
@@ -0,0 +1,80 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ # Allow manual trigger
8
+ workflow_dispatch:
9
+
10
+ permissions:
11
+ contents: read
12
+ id-token: write # Required for trusted publishing (OIDC)
13
+
14
+ jobs:
15
+ test:
16
+ name: Run tests
17
+ runs-on: ubuntu-latest
18
+ strategy:
19
+ matrix:
20
+ python-version: ["3.9", "3.12", "3.13"]
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+
24
+ - name: Set up Python ${{ matrix.python-version }}
25
+ uses: actions/setup-python@v5
26
+ with:
27
+ python-version: ${{ matrix.python-version }}
28
+
29
+ - name: Install dependencies
30
+ run: |
31
+ python -m pip install --upgrade pip
32
+ pip install -e ".[dev]"
33
+
34
+ - name: Run tests
35
+ run: pytest tests/ -v
36
+
37
+ build:
38
+ name: Build package
39
+ runs-on: ubuntu-latest
40
+ needs: test
41
+ steps:
42
+ - uses: actions/checkout@v4
43
+
44
+ - name: Set up Python
45
+ uses: actions/setup-python@v5
46
+ with:
47
+ python-version: "3.13"
48
+
49
+ - name: Install build tools
50
+ run: python -m pip install --upgrade pip build
51
+
52
+ - name: Build sdist and wheel
53
+ run: python -m build
54
+
55
+ - name: Upload build artifacts
56
+ uses: actions/upload-artifact@v4
57
+ with:
58
+ name: dist
59
+ path: dist/
60
+
61
+ publish:
62
+ name: Publish to PyPI
63
+ runs-on: ubuntu-latest
64
+ needs: build
65
+ environment:
66
+ name: pypi
67
+ url: https://pypi.org/p/poe
68
+ steps:
69
+ - name: Download build artifacts
70
+ uses: actions/download-artifact@v4
71
+ with:
72
+ name: dist
73
+ path: dist/
74
+
75
+ - name: Publish to PyPI
76
+ uses: pypa/gh-action-pypi-publish@release/v1
77
+ # Uses trusted publishing (OIDC) — no API token needed.
78
+ # Trusted publisher already configured on PyPI for:
79
+ # repo: poe-platform/poe-python
80
+ # workflow: pypi.yml
poe-0.1.0/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ *.egg
8
+ .eggs/
9
+ .pytest_cache/
10
+ .mypy_cache/
11
+ .venv/
12
+ venv/
13
+ env/
14
+ *.so
15
+ .DS_Store
16
+ *.swp
17
+ *.swo
poe-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Poe Platform
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
poe-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: poe
3
+ Version: 0.1.0
4
+ Summary: Python client for the Poe API (api.poe.com)
5
+ Project-URL: Homepage, https://github.com/poe-platform/poe-python
6
+ Project-URL: Repository, https://github.com/poe-platform/poe-python
7
+ Project-URL: Documentation, https://developer.poe.com
8
+ Project-URL: Issues, https://github.com/poe-platform/poe-python/issues
9
+ Author-email: Poe Platform <support@poe.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Requires-Dist: httpx>=0.25.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
26
+ Requires-Dist: pytest>=7.0; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # poe
30
+
31
+ Official Python client for the [Poe](https://poe.com) chat completions API.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install poe
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ```python
42
+ from poe import PoeClient
43
+
44
+ client = PoeClient(api_key="your-poe-api-key")
45
+
46
+ # Simple chat
47
+ response = client.chat("What is Python?", model="GPT-4o")
48
+ print(response["choices"][0]["message"]["content"])
49
+ ```
50
+
51
+ ## Streaming
52
+
53
+ ```python
54
+ for chunk in client.stream("Tell me a story", model="GPT-4o"):
55
+ print(chunk, end="", flush=True)
56
+ ```
57
+
58
+ ## Options
59
+
60
+ ```python
61
+ client = PoeClient(
62
+ api_key="your-key",
63
+ timeout=120.0, # request timeout in seconds
64
+ )
65
+
66
+ response = client.chat(
67
+ "Explain quantum computing",
68
+ model="GPT-4o",
69
+ temperature=0.7,
70
+ max_tokens=1024,
71
+ system_prompt="You are a helpful physics teacher.",
72
+ )
73
+ ```
74
+
75
+ ## Context Manager
76
+
77
+ ```python
78
+ with PoeClient(api_key="your-key") as client:
79
+ resp = client.chat("Hello!")
80
+ print(resp["choices"][0]["message"]["content"])
81
+ ```
82
+
83
+ ## API Key
84
+
85
+ Get your API key from [poe.com/api_key](https://poe.com/api_key).
86
+
87
+ ## License
88
+
89
+ MIT
poe-0.1.0/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # poe
2
+
3
+ Official Python client for the [Poe](https://poe.com) chat completions API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install poe
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```python
14
+ from poe import PoeClient
15
+
16
+ client = PoeClient(api_key="your-poe-api-key")
17
+
18
+ # Simple chat
19
+ response = client.chat("What is Python?", model="GPT-4o")
20
+ print(response["choices"][0]["message"]["content"])
21
+ ```
22
+
23
+ ## Streaming
24
+
25
+ ```python
26
+ for chunk in client.stream("Tell me a story", model="GPT-4o"):
27
+ print(chunk, end="", flush=True)
28
+ ```
29
+
30
+ ## Options
31
+
32
+ ```python
33
+ client = PoeClient(
34
+ api_key="your-key",
35
+ timeout=120.0, # request timeout in seconds
36
+ )
37
+
38
+ response = client.chat(
39
+ "Explain quantum computing",
40
+ model="GPT-4o",
41
+ temperature=0.7,
42
+ max_tokens=1024,
43
+ system_prompt="You are a helpful physics teacher.",
44
+ )
45
+ ```
46
+
47
+ ## Context Manager
48
+
49
+ ```python
50
+ with PoeClient(api_key="your-key") as client:
51
+ resp = client.chat("Hello!")
52
+ print(resp["choices"][0]["message"]["content"])
53
+ ```
54
+
55
+ ## API Key
56
+
57
+ Get your API key from [poe.com/api_key](https://poe.com/api_key).
58
+
59
+ ## License
60
+
61
+ MIT
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "poe"
7
+ version = "0.1.0"
8
+ description = "Python client for the Poe API (api.poe.com)"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.9"
12
+ authors = [
13
+ { name = "Poe Platform", email = "support@poe.com" },
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Topic :: Software Development :: Libraries :: Python Modules",
26
+ ]
27
+ dependencies = [
28
+ "httpx>=0.25.0",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ dev = [
33
+ "pytest>=7.0",
34
+ "pytest-asyncio>=0.21",
35
+ ]
36
+
37
+ [tool.hatch.build.targets.wheel]
38
+ packages = ["src/poe"]
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/poe-platform/poe-python"
42
+ Repository = "https://github.com/poe-platform/poe-python"
43
+ Documentation = "https://developer.poe.com"
44
+ Issues = "https://github.com/poe-platform/poe-python/issues"
@@ -0,0 +1,6 @@
1
+ """Python client for the Poe API."""
2
+
3
+ from poe.client import PoeClient
4
+
5
+ __all__ = ["PoeClient"]
6
+ __version__ = "0.1.0"
@@ -0,0 +1,150 @@
1
+ """Poe API client for chat completions."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Generator, Iterator
6
+
7
+ import httpx
8
+
9
+ BASE_URL = "https://api.poe.com/v1"
10
+
11
+
12
+ class PoeClient:
13
+ """Client for the Poe chat completions API.
14
+
15
+ Usage::
16
+
17
+ from poe import PoeClient
18
+
19
+ client = PoeClient(api_key="your-api-key")
20
+
21
+ # Non-streaming
22
+ response = client.chat("What is Python?", model="GPT-4o")
23
+ print(response["choices"][0]["message"]["content"])
24
+
25
+ # Streaming
26
+ for chunk in client.stream("Tell me a story", model="GPT-4o"):
27
+ print(chunk, end="", flush=True)
28
+ """
29
+
30
+ def __init__(
31
+ self,
32
+ api_key: str,
33
+ *,
34
+ base_url: str = BASE_URL,
35
+ timeout: float = 60.0,
36
+ ) -> None:
37
+ self.api_key = api_key
38
+ self.base_url = base_url.rstrip("/")
39
+ self._http = httpx.Client(
40
+ base_url=self.base_url,
41
+ headers={
42
+ "Authorization": f"Bearer {api_key}",
43
+ "Content-Type": "application/json",
44
+ },
45
+ timeout=timeout,
46
+ )
47
+
48
+ # -- public API -----------------------------------------------------------
49
+
50
+ def chat(
51
+ self,
52
+ message: str,
53
+ *,
54
+ model: str = "GPT-4o",
55
+ temperature: float | None = None,
56
+ max_tokens: int | None = None,
57
+ system_prompt: str | None = None,
58
+ ) -> dict[str, Any]:
59
+ """Send a chat completion request and return the full response."""
60
+ body = self._build_body(
61
+ message,
62
+ model=model,
63
+ stream=False,
64
+ temperature=temperature,
65
+ max_tokens=max_tokens,
66
+ system_prompt=system_prompt,
67
+ )
68
+ resp = self._http.post("/chat/completions", json=body)
69
+ resp.raise_for_status()
70
+ return resp.json()
71
+
72
+ def stream(
73
+ self,
74
+ message: str,
75
+ *,
76
+ model: str = "GPT-4o",
77
+ temperature: float | None = None,
78
+ max_tokens: int | None = None,
79
+ system_prompt: str | None = None,
80
+ ) -> Iterator[str]:
81
+ """Stream a chat completion, yielding content deltas as strings."""
82
+ body = self._build_body(
83
+ message,
84
+ model=model,
85
+ stream=True,
86
+ temperature=temperature,
87
+ max_tokens=max_tokens,
88
+ system_prompt=system_prompt,
89
+ )
90
+ with self._http.stream("POST", "/chat/completions", json=body) as resp:
91
+ resp.raise_for_status()
92
+ yield from self._iter_sse(resp)
93
+
94
+ # -- internals ------------------------------------------------------------
95
+
96
+ @staticmethod
97
+ def _build_body(
98
+ message: str,
99
+ *,
100
+ model: str,
101
+ stream: bool,
102
+ temperature: float | None,
103
+ max_tokens: int | None,
104
+ system_prompt: str | None,
105
+ ) -> dict[str, Any]:
106
+ messages: list[dict[str, str]] = []
107
+ if system_prompt:
108
+ messages.append({"role": "system", "content": system_prompt})
109
+ messages.append({"role": "user", "content": message})
110
+
111
+ body: dict[str, Any] = {
112
+ "model": model,
113
+ "messages": messages,
114
+ "stream": stream,
115
+ }
116
+ if temperature is not None:
117
+ body["temperature"] = temperature
118
+ if max_tokens is not None:
119
+ body["max_tokens"] = max_tokens
120
+ return body
121
+
122
+ @staticmethod
123
+ def _iter_sse(resp: httpx.Response) -> Generator[str, None, None]:
124
+ """Parse an SSE stream and yield content deltas."""
125
+ import json as _json
126
+
127
+ for line in resp.iter_lines():
128
+ if not line or not line.startswith("data: "):
129
+ continue
130
+ payload = line[len("data: "):]
131
+ if payload.strip() == "[DONE]":
132
+ return
133
+ try:
134
+ chunk = _json.loads(payload)
135
+ except _json.JSONDecodeError:
136
+ continue
137
+ delta = chunk.get("choices", [{}])[0].get("delta", {})
138
+ content = delta.get("content")
139
+ if content:
140
+ yield content
141
+
142
+ def close(self) -> None:
143
+ """Close the underlying HTTP client."""
144
+ self._http.close()
145
+
146
+ def __enter__(self) -> "PoeClient":
147
+ return self
148
+
149
+ def __exit__(self, *exc: Any) -> None:
150
+ self.close()
File without changes
@@ -0,0 +1,41 @@
1
+ """Basic unit tests for PoeClient."""
2
+
3
+ from poe.client import PoeClient
4
+
5
+
6
+ def test_build_body_minimal():
7
+ body = PoeClient._build_body("Hello", model="GPT-4o", stream=False, temperature=None, max_tokens=None, system_prompt=None)
8
+ assert body == {
9
+ "model": "GPT-4o",
10
+ "messages": [{"role": "user", "content": "Hello"}],
11
+ "stream": False,
12
+ }
13
+
14
+
15
+ def test_build_body_with_all_options():
16
+ body = PoeClient._build_body(
17
+ "Hi",
18
+ model="Claude-3.5-Sonnet",
19
+ stream=True,
20
+ temperature=0.5,
21
+ max_tokens=100,
22
+ system_prompt="Be concise.",
23
+ )
24
+ assert body["model"] == "Claude-3.5-Sonnet"
25
+ assert body["stream"] is True
26
+ assert body["temperature"] == 0.5
27
+ assert body["max_tokens"] == 100
28
+ assert body["messages"][0] == {"role": "system", "content": "Be concise."}
29
+ assert body["messages"][1] == {"role": "user", "content": "Hi"}
30
+
31
+
32
+ def test_client_context_manager():
33
+ client = PoeClient(api_key="test-key")
34
+ with client:
35
+ assert client.api_key == "test-key"
36
+
37
+
38
+ def test_client_default_base_url():
39
+ client = PoeClient(api_key="k")
40
+ assert client.base_url == "https://api.poe.com/v1"
41
+ client.close()