forktex-intelligence 0.2.3__py3-none-any.whl

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,152 @@
1
+ # Copyright (C) 2026 FORKTEX S.R.L.
2
+ #
3
+ # SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-ForkTex-Commercial
4
+ #
5
+ # This file is part of forktex-intelligence.
6
+ #
7
+ # For commercial licensing -- including use in proprietary products, SaaS
8
+ # deployments, or any context where AGPL obligations cannot be met -- you
9
+ # MUST obtain a commercial license from FORKTEX S.R.L. (info@forktex.com).
10
+ #
11
+ # This program is free software: you can redistribute it and/or modify
12
+ # it under the terms of the GNU Affero General Public License as published by
13
+ # the Free Software Foundation, either version 3 of the License, or
14
+ # (at your option) any later version.
15
+ #
16
+ # This program is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ # GNU Affero General Public License for more details.
20
+ #
21
+ # You should have received a copy of the GNU Affero General Public License
22
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
23
+
24
+ """SSE stream consumer and event parser for the Intelligence API.
25
+
26
+ Parses Server-Sent Events from the Intelligence API into typed event
27
+ objects. Handles the tool intercept flow where the CLI must execute
28
+ local tools and post results back.
29
+
30
+ SSE event types:
31
+ delta - Text chunk from the LLM
32
+ tool_call - Agent called a server-side tool (informational)
33
+ tool_result_needed - Agent needs a LOCAL tool executed by the CLI
34
+ usage - Token usage statistics
35
+ error - Server-side error
36
+ done - Stream complete
37
+ """
38
+
39
+ from __future__ import annotations
40
+
41
+ import json
42
+ from enum import Enum
43
+ from typing import Any, AsyncIterator, Dict, Optional
44
+
45
+ from pydantic import BaseModel, Field
46
+
47
+
48
+ class SSEEventType(str, Enum):
49
+ DELTA = "delta"
50
+ TOOL_CALL = "tool_call"
51
+ TOOL_RESULT_NEEDED = "tool_result_needed"
52
+ USAGE = "usage"
53
+ ERROR = "error"
54
+ DONE = "done"
55
+
56
+
57
+ class SSEEvent(BaseModel):
58
+ """Parsed SSE event from the Intelligence API."""
59
+
60
+ event: SSEEventType
61
+ data: Dict[str, Any] = Field(default_factory=dict)
62
+
63
+ # Convenience accessors
64
+ @property
65
+ def delta_text(self) -> str:
66
+ """Text chunk for delta events."""
67
+ return self.data.get("text", "")
68
+
69
+ @property
70
+ def tool_name(self) -> str:
71
+ """Tool name for tool_call / tool_result_needed events."""
72
+ return self.data.get("name", "")
73
+
74
+ @property
75
+ def tool_call_id(self) -> str:
76
+ """Call ID for tool_result_needed events."""
77
+ return self.data.get("call_id", "")
78
+
79
+ @property
80
+ def tool_arguments(self) -> Dict[str, Any]:
81
+ """Arguments for tool_result_needed events."""
82
+ return self.data.get("arguments", {})
83
+
84
+ @property
85
+ def input_tokens(self) -> int:
86
+ return self.data.get("input_tokens", 0)
87
+
88
+ @property
89
+ def output_tokens(self) -> int:
90
+ return self.data.get("output_tokens", 0)
91
+
92
+ @property
93
+ def error_message(self) -> str:
94
+ return self.data.get("message", "")
95
+
96
+
97
+ async def parse_sse_stream(raw_lines: AsyncIterator[bytes]) -> AsyncIterator[SSEEvent]:
98
+ """Parse raw SSE lines into typed SSEEvent objects.
99
+
100
+ Handles the standard SSE format:
101
+ event: <type>
102
+ data: <json>
103
+
104
+ (blank line separates events)
105
+ """
106
+ event_type: Optional[str] = None
107
+ data_lines: list[str] = []
108
+
109
+ async for raw in raw_lines:
110
+ line = raw.decode("utf-8") if isinstance(raw, bytes) else raw
111
+ line = line.rstrip("\n\r")
112
+
113
+ if not line:
114
+ # Blank line = end of event
115
+ if event_type and data_lines:
116
+ data_str = "\n".join(data_lines)
117
+ try:
118
+ data = json.loads(data_str)
119
+ except json.JSONDecodeError:
120
+ data = {"text": data_str}
121
+
122
+ try:
123
+ evt_type = SSEEventType(event_type)
124
+ except ValueError:
125
+ evt_type = SSEEventType.DELTA
126
+
127
+ yield SSEEvent(event=evt_type, data=data)
128
+
129
+ event_type = None
130
+ data_lines = []
131
+ continue
132
+
133
+ if line.startswith("event:"):
134
+ event_type = line[len("event:") :].strip()
135
+ elif line.startswith("data:"):
136
+ data_lines.append(line[len("data:") :].strip())
137
+ elif line.startswith(":"):
138
+ # SSE comment, ignore
139
+ continue
140
+
141
+ # Handle trailing event without blank line
142
+ if event_type and data_lines:
143
+ data_str = "\n".join(data_lines)
144
+ try:
145
+ data = json.loads(data_str)
146
+ except json.JSONDecodeError:
147
+ data = {"text": data_str}
148
+ try:
149
+ evt_type = SSEEventType(event_type)
150
+ except ValueError:
151
+ evt_type = SSEEventType.DELTA
152
+ yield SSEEvent(event=evt_type, data=data)
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: forktex-intelligence
3
+ Version: 0.2.3
4
+ Summary: Standalone Python SDK for the ForkTex Intelligence API — chat, agent runs, embeddings, retrieval, ecosystem indexing
5
+ License-Expression: AGPL-3.0-only
6
+ License-File: LICENSE
7
+ License-File: NOTICE
8
+ Author: FORKTEX
9
+ Author-email: info@forktex.com
10
+ Requires-Python: >=3.12
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Requires-Dist: httpx (>=0.27.0,<1.0.0)
23
+ Requires-Dist: httpx-sse (>=0.4.0,<1.0.0)
24
+ Requires-Dist: pydantic (>=2.11.10,<3.0.0)
25
+ Project-URL: Bug Tracker, https://github.com/forktex/intelligence/issues
26
+ Project-URL: Homepage, https://intelligence.forktex.com
27
+ Project-URL: Repository, https://github.com/forktex/intelligence
28
+ Description-Content-Type: text/markdown
29
+
30
+ # forktex-intelligence
31
+
32
+ [![PyPI](https://img.shields.io/pypi/v/forktex-intelligence.svg)](https://pypi.org/project/forktex-intelligence/)
33
+ [![Python](https://img.shields.io/pypi/pyversions/forktex-intelligence.svg)](https://pypi.org/project/forktex-intelligence/)
34
+ [![License](https://img.shields.io/pypi/l/forktex-intelligence.svg)](https://github.com/forktex/intelligence/blob/master/sdk-py/LICENSE)
35
+
36
+ Standalone Python SDK for the [ForkTex Intelligence](https://intelligence.forktex.com) API.
37
+
38
+ `forktex-intelligence` is the high-level Python client for the ForkTex Intelligence platform: multi-provider LLM chat (streaming + structured), embeddings, vector search, content extraction (PDF / DOCX / HTML), and image / audio generation. It backs the `forktex intelligence ask / run / scrape` CLI commands and is also usable directly from any Python application.
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ pip install forktex-intelligence
44
+ ```
45
+
46
+ **Requires Python 3.12+.** Tested on 3.12, 3.13, 3.14.
47
+
48
+ ## Quick Start
49
+
50
+ ### Single-shot prompt
51
+
52
+ ```python
53
+ from forktex_intelligence import Intelligence
54
+
55
+ async with Intelligence(endpoint="https://intelligence.forktex.com/api", api_key="sk-...") as ai:
56
+ response = await ai.chat("Summarize the ForkTex stack in one sentence.")
57
+ print(response.text)
58
+ ```
59
+
60
+ ### Structured response (Pydantic schema)
61
+
62
+ ```python
63
+ from pydantic import BaseModel
64
+ from forktex_intelligence import Intelligence
65
+
66
+ class Summary(BaseModel):
67
+ title: str
68
+ bullets: list[str]
69
+
70
+ async with Intelligence(endpoint="...", api_key="...") as ai:
71
+ result = await ai.extract_structured(
72
+ prompt="Summarize the ForkTex stack.",
73
+ schema=Summary,
74
+ )
75
+ print(result.parsed.title, result.parsed.bullets)
76
+ ```
77
+
78
+ ### Streaming
79
+
80
+ ```python
81
+ from forktex_intelligence import Intelligence
82
+
83
+ async with Intelligence(endpoint="...", api_key="...") as ai:
84
+ async for chunk in ai.stream("Tell me a story."):
85
+ print(chunk, end="", flush=True)
86
+ ```
87
+
88
+ ## Configuration
89
+
90
+ Pass endpoint and API key explicitly:
91
+
92
+ ```python
93
+ Intelligence(endpoint="https://intelligence.forktex.com/api", api_key="sk-...")
94
+ ```
95
+
96
+ Or via an `IntelligenceSettings` object:
97
+
98
+ ```python
99
+ from forktex_intelligence import IntelligenceSettings, Intelligence
100
+
101
+ settings = IntelligenceSettings(endpoint="...", api_key="...")
102
+ async with Intelligence(settings=settings) as ai:
103
+ ...
104
+ ```
105
+
106
+ When used via the `forktex` CLI, settings are loaded from environment variables and `.forktex/` config files automatically.
107
+
108
+ | Variable | Description | Default |
109
+ |----------|-------------|---------|
110
+ | `FORKTEX_INTELLIGENCE_ENDPOINT` | Intelligence API endpoint | `https://intelligence.forktex.com/api` |
111
+ | `FORKTEX_INTELLIGENCE_API_KEY` | Intelligence API key | *(required)* |
112
+
113
+ ### Local dev (point at your `make local` stack)
114
+
115
+ ```bash
116
+ export FORKTEX_INTELLIGENCE_ENDPOINT=http://localhost:8001/api
117
+ export FORKTEX_INTELLIGENCE_API_KEY=dev-key
118
+ ```
119
+
120
+ Or programmatically:
121
+
122
+ ```python
123
+ from forktex_intelligence import Intelligence
124
+ intel = Intelligence(endpoint="http://localhost:8001/api", api_key="dev-key")
125
+ ```
126
+
127
+ ## What's in the package
128
+
129
+ | Module | Purpose |
130
+ |--------|---------|
131
+ | `forktex_intelligence.api` | High-level `Intelligence` client (chat, structured, stream) |
132
+ | `forktex_intelligence.client` | Low-level `ForktexIntelligenceClient` (raw HTTP, advanced use) |
133
+ | `forktex_intelligence.client.generated` | Wire-level Pydantic models (`ChatMessage`, `ChatResponse`, …) generated from the OpenAPI spec |
134
+ | `forktex_intelligence.streams` | SSE event types and parser |
135
+ | `forktex_intelligence.config` | `IntelligenceSettings` — endpoint, API key |
136
+
137
+ All response models come from the OpenAPI codegen pipeline — one source of truth shared between the server and every consumer.
138
+
139
+ ## Repository
140
+
141
+ This SDK lives inside the [`forktex/intelligence`](https://github.com/forktex/intelligence) monorepo alongside the API server (`api/`). The SDK package is independently versioned and published to PyPI.
142
+
143
+ ## Development
144
+
145
+ The [`Makefile`](Makefile) is generated by `forktex fsd makefile sync` from [`forktex.json`](forktex.json) — do not hand-edit.
146
+
147
+ ```bash
148
+ make help # list every available target
149
+ make deps # editable install with the dev group
150
+ make format # ruff format
151
+ make lint # ruff check
152
+ make test # pytest tests/
153
+ make codegen-check # verify the generated client imports cleanly
154
+ make build # python3 -m build → dist/
155
+ make ci # format-check + lint + license-check + audit + test + build
156
+ make clean # remove caches and dist/
157
+ ```
158
+
159
+ `make ci` is the single command that gates a publish: format-check, lint, dual-license header check, dependency CVE audit, full test suite, and `python -m build` + `twine check`.
160
+
161
+ ### License headers
162
+
163
+ Every source file carries the AGPL-3.0 + Commercial dual-license SPDX header, applied idempotently via:
164
+
165
+ ```bash
166
+ make license-check # CI gate — fails if any source file is missing the header
167
+ make license-fix # add or refresh headers across src/, tests/, scripts/
168
+ make license-strip # remove headers (used before license-model changes)
169
+ ```
170
+
171
+ ## License
172
+
173
+ Dual-licensed — **AGPL-3.0-or-later** for open-source use, **commercial** for everything else (proprietary products, SaaS without source release, redistribution in closed-source form). See [`LICENSE`](LICENSE) and [`NOTICE`](NOTICE) for the full terms.
174
+
175
+ Commercial licensing inquiries: info@forktex.com.
176
+
177
+ The 1.0.0 release on PyPI remains under MIT; from **0.2.3** onwards the package ships AGPL-3.0+Commercial.
178
+
@@ -0,0 +1,12 @@
1
+ forktex_intelligence/__init__.py,sha256=VNHIHg8baW5riWebwQfFa0XWH8nN5RVhC-Oh4oIrMfo,2973
2
+ forktex_intelligence/api.py,sha256=yVVmQTXdLKdYRDX59hfJbF-F2cB6DtqGhgYSovkMAuo,18891
3
+ forktex_intelligence/client/__init__.py,sha256=7ObrskJeZU3PFTP7fMyAbKj0F1JadCosYvgPmEOJqfY,1791
4
+ forktex_intelligence/client/client.py,sha256=QXCvC-LhhAZ2fRv9-GHNF6aadG4xSUbYXKG18FAQ1Lg,13520
5
+ forktex_intelligence/client/generated/__init__.py,sha256=7PxlOmmIJkDNiTWnWG5TkbKQ6KdIn1NPLm6n1WyIZWg,24946
6
+ forktex_intelligence/config.py,sha256=ALmcCBV5N3eXXyjLVPGq--sesUz3HC77T9Qsio6aN1A,1592
7
+ forktex_intelligence/streams.py,sha256=UfTTZ2Hj8P6bar4Ecf42iiaIpbUmrkJKk7o6V5-r794,4870
8
+ forktex_intelligence-0.2.3.dist-info/METADATA,sha256=9pfrFHfMJGKkGgVmMC2ffWMyBvw7bAUUyWS9uCvY1lk,6846
9
+ forktex_intelligence-0.2.3.dist-info/WHEEL,sha256=Vz2fHgx6HFtSwhs8KvkHLqH5Ea4w1_rner5uNVGCeIE,88
10
+ forktex_intelligence-0.2.3.dist-info/licenses/LICENSE,sha256=GDi3ClhZX_dyu2vvf5itrkTAyXulhKwrPMfcLV6y4dw,1928
11
+ forktex_intelligence-0.2.3.dist-info/licenses/NOTICE,sha256=quL5izPaAI8iJZvXNTPnD0gZpAZ--k_VxECDbz-enro,1051
12
+ forktex_intelligence-0.2.3.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.3.2
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,45 @@
1
+ forktex-intelligence -- Dual License
2
+
3
+ Copyright (C) 2026 FORKTEX S.R.L.
4
+
5
+ This software is licensed under a dual-license model:
6
+
7
+ ============================================================================
8
+
9
+ 1. OPEN-SOURCE LICENSE -- GNU Affero General Public License v3.0 (AGPL-3.0)
10
+
11
+ You may use, modify, and redistribute this software under the terms of the
12
+ GNU Affero General Public License v3.0 or later, as published by the Free
13
+ Software Foundation. The full license text is available at:
14
+ https://www.gnu.org/licenses/agpl-3.0.html
15
+
16
+ Key obligations under AGPL-3.0:
17
+ - Any modified version MUST be released under the same AGPL-3.0 license.
18
+ - If you run a modified version on a server and let users interact with it
19
+ over a network, you MUST make the complete source code available to those
20
+ users under AGPL-3.0.
21
+ - You MUST preserve all copyright notices and attribution to FORKTEX S.R.L.
22
+
23
+ ============================================================================
24
+
25
+ 2. COMMERCIAL LICENSE
26
+
27
+ If you wish to use this software without the obligations of AGPL-3.0 --
28
+ for example, to keep your modifications proprietary, to embed this software
29
+ in a closed-source product, or to operate it as part of a commercial service
30
+ without releasing your source code -- you MUST obtain a commercial license
31
+ from FORKTEX S.R.L.
32
+
33
+ Commercial licensing includes, but is not limited to:
34
+ - SaaS / hosted deployments generating revenue
35
+ - Embedding in proprietary products or platforms
36
+ - Redistribution in closed-source form
37
+ - Use by organizations exceeding the AGPL-3.0 compliance scope
38
+
39
+ For commercial licensing inquiries, contact:
40
+ info@forktex.com
41
+
42
+ ============================================================================
43
+
44
+ Unless you have obtained a separate commercial license from FORKTEX S.R.L.,
45
+ your use of this software is governed exclusively by the AGPL-3.0 license.
@@ -0,0 +1,22 @@
1
+ forktex-intelligence
2
+ Copyright (C) 2026 FORKTEX S.R.L.
3
+
4
+ forktex-intelligence is the standalone Python SDK for the ForkTex Intelligence
5
+ API. It provides the typed httpx-based client (sync + streaming over SSE),
6
+ generated Pydantic models for the Intelligence OpenAPI surface, and helpers
7
+ for chat, agent runs, embeddings, retrieval, and ecosystem indexing.
8
+
9
+ This program is free software: you can redistribute it and/or modify
10
+ it under the terms of the GNU Affero General Public License as published by
11
+ the Free Software Foundation, either version 3 of the License, or
12
+ (at your option) any later version.
13
+
14
+ This program is distributed in the hope that it will be useful,
15
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ GNU Affero General Public License for more details.
18
+
19
+ You should have received a copy of the GNU Affero General Public License
20
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
21
+
22
+ For commercial licensing inquiries, contact: info@forktex.com