interfaze 1.0.1__tar.gz → 1.0.2__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.
- {interfaze-1.0.1 → interfaze-1.0.2}/.github/workflows/ci.yml +4 -21
- {interfaze-1.0.1 → interfaze-1.0.2}/.github/workflows/publish.yml +5 -5
- {interfaze-1.0.1 → interfaze-1.0.2}/.github/workflows/qa-live.yml +2 -4
- {interfaze-1.0.1 → interfaze-1.0.2}/LICENSE +1 -1
- interfaze-1.0.2/PKG-INFO +367 -0
- interfaze-1.0.2/README.md +343 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/pyproject.toml +3 -15
- {interfaze-1.0.1 → interfaze-1.0.2}/src/interfaze/__init__.py +9 -4
- {interfaze-1.0.1 → interfaze-1.0.2}/src/interfaze/_chat.py +3 -18
- {interfaze-1.0.1 → interfaze-1.0.2}/src/interfaze/_client.py +0 -8
- interfaze-1.0.2/src/interfaze/_errors.py +5 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/src/interfaze/_guard.py +0 -1
- {interfaze-1.0.1 → interfaze-1.0.2}/src/interfaze/_inputs.py +1 -7
- {interfaze-1.0.1 → interfaze-1.0.2}/src/interfaze/_schema.py +0 -6
- {interfaze-1.0.1 → interfaze-1.0.2}/src/interfaze/_stream.py +3 -11
- {interfaze-1.0.1 → interfaze-1.0.2}/src/interfaze/_tasks.py +0 -4
- {interfaze-1.0.1 → interfaze-1.0.2}/src/interfaze/_types.py +0 -4
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/assets.py +2 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/conftest.py +1 -1
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/test_inputs_and_client.py +8 -8
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/test_stream.py +2 -2
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/test_tasks.py +1 -1
- interfaze-1.0.2/uv.lock +1194 -0
- interfaze-1.0.1/PKG-INFO +0 -168
- interfaze-1.0.1/README.md +0 -141
- interfaze-1.0.1/src/interfaze/_errors.py +0 -9
- interfaze-1.0.1/src/interfaze/langchain.py +0 -220
- interfaze-1.0.1/tests/test_langchain.py +0 -183
- interfaze-1.0.1/uv.lock +0 -2279
- {interfaze-1.0.1 → interfaze-1.0.2}/.gitignore +0 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/scripts/qa_live.py +0 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/src/interfaze/_constants.py +0 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/src/interfaze/py.typed +0 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/test_async.py +0 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/test_chat.py +0 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/test_compliance.py +0 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/test_errors.py +0 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/test_guard.py +0 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/test_models.py +0 -0
- {interfaze-1.0.1 → interfaze-1.0.2}/tests/test_schema.py +0 -0
|
@@ -16,10 +16,10 @@ jobs:
|
|
|
16
16
|
strategy:
|
|
17
17
|
fail-fast: false
|
|
18
18
|
matrix:
|
|
19
|
-
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
19
|
+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
|
|
20
20
|
steps:
|
|
21
|
-
- uses: actions/checkout@
|
|
22
|
-
- uses: astral-sh/setup-uv@
|
|
21
|
+
- uses: actions/checkout@v5
|
|
22
|
+
- uses: astral-sh/setup-uv@v9.0.0
|
|
23
23
|
with:
|
|
24
24
|
python-version: ${{ matrix.python-version }}
|
|
25
25
|
enable-cache: true
|
|
@@ -33,28 +33,11 @@ jobs:
|
|
|
33
33
|
- name: Unit tests
|
|
34
34
|
run: uv run pytest -q
|
|
35
35
|
|
|
36
|
-
test-core-py39:
|
|
37
|
-
name: test (py3.9, core only)
|
|
38
|
-
runs-on: ubuntu-latest
|
|
39
|
-
steps:
|
|
40
|
-
- uses: actions/checkout@v4
|
|
41
|
-
- uses: astral-sh/setup-uv@v6
|
|
42
|
-
with:
|
|
43
|
-
python-version: "3.9"
|
|
44
|
-
enable-cache: true
|
|
45
|
-
# langchain-openai is gated python_version>='3.10', so it's skipped on 3.9 and its tests no-op.
|
|
46
|
-
- name: Install (dev extras; langchain skipped on 3.9)
|
|
47
|
-
run: uv sync --extra dev
|
|
48
|
-
- name: Lint (ruff)
|
|
49
|
-
run: uv run ruff check src tests scripts
|
|
50
|
-
- name: Unit tests
|
|
51
|
-
run: uv run pytest -q
|
|
52
|
-
|
|
53
36
|
secret-scan:
|
|
54
37
|
name: secret scan (gitleaks)
|
|
55
38
|
runs-on: ubuntu-latest
|
|
56
39
|
steps:
|
|
57
|
-
- uses: actions/checkout@
|
|
40
|
+
- uses: actions/checkout@v5
|
|
58
41
|
- name: Scan working tree for leaked tokens/secrets
|
|
59
42
|
run: |
|
|
60
43
|
curl -sSfL "https://github.com/gitleaks/gitleaks/releases/download/v8.21.2/gitleaks_8.21.2_linux_x64.tar.gz" | tar -xz gitleaks
|
|
@@ -11,15 +11,15 @@ jobs:
|
|
|
11
11
|
build:
|
|
12
12
|
runs-on: ubuntu-latest
|
|
13
13
|
steps:
|
|
14
|
-
- uses: actions/checkout@
|
|
15
|
-
- uses: astral-sh/setup-uv@
|
|
14
|
+
- uses: actions/checkout@v5
|
|
15
|
+
- uses: astral-sh/setup-uv@v9.0.0
|
|
16
16
|
with:
|
|
17
17
|
python-version: "3.12"
|
|
18
18
|
- name: Build sdist + wheel
|
|
19
19
|
run: uv build
|
|
20
20
|
- name: Verify metadata
|
|
21
21
|
run: uvx twine check dist/*
|
|
22
|
-
- uses: actions/upload-artifact@
|
|
22
|
+
- uses: actions/upload-artifact@v7
|
|
23
23
|
with:
|
|
24
24
|
name: dist
|
|
25
25
|
path: dist/
|
|
@@ -34,7 +34,7 @@ jobs:
|
|
|
34
34
|
permissions:
|
|
35
35
|
id-token: write
|
|
36
36
|
steps:
|
|
37
|
-
- uses: actions/download-artifact@
|
|
37
|
+
- uses: actions/download-artifact@v7
|
|
38
38
|
with:
|
|
39
39
|
name: dist
|
|
40
40
|
path: dist/
|
|
@@ -52,7 +52,7 @@ jobs:
|
|
|
52
52
|
permissions:
|
|
53
53
|
id-token: write
|
|
54
54
|
steps:
|
|
55
|
-
- uses: actions/download-artifact@
|
|
55
|
+
- uses: actions/download-artifact@v7
|
|
56
56
|
with:
|
|
57
57
|
name: dist
|
|
58
58
|
path: dist/
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
name: Live QA
|
|
2
2
|
|
|
3
|
-
# Live e2e against the real API; gated on the INTERFAZE_API_KEY secret (never on PRs).
|
|
4
|
-
|
|
5
3
|
on:
|
|
6
4
|
workflow_dispatch:
|
|
7
5
|
schedule:
|
|
@@ -16,8 +14,8 @@ jobs:
|
|
|
16
14
|
name: live QA (multimodal + token usage + tasks)
|
|
17
15
|
runs-on: ubuntu-latest
|
|
18
16
|
steps:
|
|
19
|
-
- uses: actions/checkout@
|
|
20
|
-
- uses: astral-sh/setup-uv@
|
|
17
|
+
- uses: actions/checkout@v5
|
|
18
|
+
- uses: astral-sh/setup-uv@v9.0.0
|
|
21
19
|
with:
|
|
22
20
|
python-version: "3.12"
|
|
23
21
|
enable-cache: true
|
interfaze-1.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: interfaze
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: Interfaze Python SDK.
|
|
5
|
+
Project-URL: Homepage, https://interfaze.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/InterfazeAI/interfaze-python
|
|
7
|
+
Author: InterfazeAI
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ai,interfaze,ocr,openai,sdk,speech-to-text,web-search
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Typing :: Typed
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Requires-Dist: openai<3,>=2
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
18
|
+
Requires-Dist: pydantic>=2; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
|
|
20
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
21
|
+
Requires-Dist: respx>=0.21; extra == 'dev'
|
|
22
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# Interfaze Python SDK
|
|
26
|
+
|
|
27
|
+
The official [Interfaze](https://interfaze.ai) SDK for Python
|
|
28
|
+
|
|
29
|
+
[Docs](https://interfaze.ai/docs) · [limits](https://interfaze.ai/docs/limits) · [pricing](https://interfaze.ai/pricing) · [dashboard](https://interfaze.ai) · [TypeScript / JavaScript SDK](https://github.com/InterfazeAI/interfaze-js)
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install interfaze
|
|
35
|
+
# or: uv add interfaze · poetry add interfaze
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Setup
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from interfaze import Interfaze
|
|
42
|
+
|
|
43
|
+
interfaze = Interfaze(api_key="sk_...") # or set INTERFAZE_API_KEY and call Interfaze()
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Async is identical via `AsyncInterfaze` - every call becomes `await`-able.
|
|
47
|
+
|
|
48
|
+
## Your first request
|
|
49
|
+
|
|
50
|
+
This guide will get you started with your first request to Interfaze, which follows the Chat Completions API standard.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import json
|
|
54
|
+
from interfaze import Interfaze, response_format
|
|
55
|
+
|
|
56
|
+
interfaze = Interfaze()
|
|
57
|
+
|
|
58
|
+
res = interfaze.chat.completions.create(
|
|
59
|
+
messages=[
|
|
60
|
+
{
|
|
61
|
+
"role": "user",
|
|
62
|
+
"content": [
|
|
63
|
+
{"type": "text", "text": "Extract the details from this ID."},
|
|
64
|
+
{"type": "image_url", "image_url": {"url": "https://r2public.jigsawstack.com/interfaze/examples/id.jpg"}},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
response_format=response_format(
|
|
69
|
+
{
|
|
70
|
+
"type": "object",
|
|
71
|
+
"properties": {
|
|
72
|
+
"first_name": {"type": "string"},
|
|
73
|
+
"last_name": {"type": "string"},
|
|
74
|
+
"dob": {"type": "string", "description": "Date of birth on the ID"},
|
|
75
|
+
"licence_number": {"type": "string"},
|
|
76
|
+
},
|
|
77
|
+
"required": ["first_name", "last_name", "dob", "licence_number"],
|
|
78
|
+
},
|
|
79
|
+
"id_card",
|
|
80
|
+
),
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
id_card = json.loads(res.choices[0].message.content or "{}")
|
|
84
|
+
print(id_card)
|
|
85
|
+
print("OCR result:", res.precontext[0].result if res.precontext else None) # the raw OCR that produced it
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Precontext
|
|
89
|
+
|
|
90
|
+
Alongside the answer, a response carries `precontext` - the raw metadata Interfaze produced while answering:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
for p in res.precontext or []:
|
|
94
|
+
print(p.name, p.result) # e.g. "ocr" -> { text, boxes, confidence, … }
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Chat
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
res = interfaze.chat.completions.create(
|
|
101
|
+
messages=[{"role": "user", "content": "Which US public companies reported earnings today?"}],
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
res.choices[0].message.content
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The result is a standard `ChatCompletion` with `precontext` and `reasoning` added (a web search backs the answer here).
|
|
108
|
+
|
|
109
|
+
### Streaming
|
|
110
|
+
|
|
111
|
+
Stream the reply as it's generated; the final completion still carries `precontext` and `reasoning`.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
stream = interfaze.chat.completions.stream(
|
|
115
|
+
messages=[{"role": "user", "content": "Summarize this week's top AI research and cite your sources."}],
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
for text in stream.text_deltas():
|
|
119
|
+
print(text, end="", flush=True)
|
|
120
|
+
|
|
121
|
+
final = stream.get_final_completion() # .precontext (the sources), .reasoning
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`text_deltas()` yields display-ready text - the inline `<think>`/`<precontext>` side-channels are stripped and returned structured on `get_final_completion()`. Iterate the stream directly (`for event in stream`) for typed events, or `create(stream=True)` for the raw chunk iterator.
|
|
125
|
+
|
|
126
|
+
### Structured output
|
|
127
|
+
|
|
128
|
+
`response_format()` takes a JSON Schema and normalizes it for Interfaze:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
import json
|
|
132
|
+
from interfaze import inputs, response_format
|
|
133
|
+
|
|
134
|
+
res = interfaze.chat.completions.create(
|
|
135
|
+
messages=[
|
|
136
|
+
{
|
|
137
|
+
"role": "user",
|
|
138
|
+
"content": [
|
|
139
|
+
{"type": "text", "text": "Extract this receipt."},
|
|
140
|
+
inputs.image("https://jigsawstack.com/preview/vocr-example.jpg"),
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
response_format=response_format(
|
|
145
|
+
{
|
|
146
|
+
"type": "object",
|
|
147
|
+
"properties": {
|
|
148
|
+
"merchant": {"type": "string"},
|
|
149
|
+
"total": {"type": "number"},
|
|
150
|
+
"items": {
|
|
151
|
+
"type": "array",
|
|
152
|
+
"items": {
|
|
153
|
+
"type": "object",
|
|
154
|
+
"properties": {"name": {"type": "string"}, "price": {"type": "number"}},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
"required": ["merchant", "total", "items"],
|
|
159
|
+
},
|
|
160
|
+
"receipt",
|
|
161
|
+
),
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
receipt = json.loads(res.choices[0].message.content or "{}") # {"merchant": ..., "total": ..., "items": [...]}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`message.content` comes back as a JSON string, so parse it - and keep the root an `object`, since a non-object root is wrapped under a `result` key. Prefer Pydantic? Use `interfaze.chat.completions.parse(response_format=YourModel, …)` and read `choices[0].message.parsed`.
|
|
168
|
+
|
|
169
|
+
### Tools and function calling
|
|
170
|
+
|
|
171
|
+
Interfaze supports tools - define `tools`, read `message.tool_calls`, run them, then pass the results back for the final answer.
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
import json
|
|
175
|
+
|
|
176
|
+
def get_weather(city: str) -> str:
|
|
177
|
+
return json.dumps({"city": city, "temp_c": 21, "condition": "clear"})
|
|
178
|
+
|
|
179
|
+
tools = [
|
|
180
|
+
{
|
|
181
|
+
"type": "function",
|
|
182
|
+
"function": {
|
|
183
|
+
"name": "get_weather",
|
|
184
|
+
"description": "Get the current weather for a city.",
|
|
185
|
+
"parameters": {
|
|
186
|
+
"type": "object",
|
|
187
|
+
"properties": {"city": {"type": "string", "description": "e.g. Tokyo"}},
|
|
188
|
+
"required": ["city"],
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
]
|
|
193
|
+
|
|
194
|
+
messages = [{"role": "user", "content": "What's the weather in Tokyo?"}]
|
|
195
|
+
res = interfaze.chat.completions.create(messages=messages, tools=tools, tool_choice="auto")
|
|
196
|
+
|
|
197
|
+
message = res.choices[0].message
|
|
198
|
+
messages.append(message.model_dump()) # the assistant turn, carrying any tool_calls
|
|
199
|
+
|
|
200
|
+
for call in message.tool_calls or []:
|
|
201
|
+
args = json.loads(call.function.arguments)
|
|
202
|
+
messages.append({"role": "tool", "tool_call_id": call.id, "content": get_weather(args["city"])})
|
|
203
|
+
|
|
204
|
+
final = interfaze.chat.completions.create(messages=messages, tools=tools, tool_choice="auto")
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Reasoning
|
|
208
|
+
|
|
209
|
+
Ask for reasoning with `reasoning_effort`; the text comes back on `res.reasoning`.
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
res = interfaze.chat.completions.create(
|
|
213
|
+
reasoning_effort="high", # also accepts Interfaze's "on" / "off" / "auto"
|
|
214
|
+
messages=[{"role": "user", "content": "Which region should we launch in first, and why?"}],
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
res.reasoning # reasoning text - present with reasoning_effort and no schema
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Multimodal Inputs
|
|
221
|
+
|
|
222
|
+
Interfaze handles images, PDFs, audio, video, and CSV. The simplest way is to drop a public URL into the prompt - Interfaze fetches and reads it:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
interfaze.chat.completions.create(
|
|
226
|
+
messages=[{"role": "user", "content": "Summarize this document: https://arxiv.org/pdf/1706.03762"}],
|
|
227
|
+
)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Or attach it as a content part - a `file` part for documents, audio, and video; `image_url` for images:
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
interfaze.chat.completions.create(
|
|
234
|
+
messages=[
|
|
235
|
+
{
|
|
236
|
+
"role": "user",
|
|
237
|
+
"content": [
|
|
238
|
+
{"type": "text", "text": "Summarize this document."},
|
|
239
|
+
{"type": "file", "file": {"filename": "paper.pdf", "file_data": "https://arxiv.org/pdf/1706.03762"}},
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
`file_data` also takes a base64 data URI:
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
{"type": "file", "file": {"filename": "report.pdf", "file_data": f"data:application/pdf;base64,{base64}"}}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`inputs.*` is a typed shortcut that builds these parts - and turns raw bytes or a local file into a data URI for you:
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
from interfaze import inputs
|
|
256
|
+
|
|
257
|
+
inputs.image("https://…/photo.png") # image_url part
|
|
258
|
+
inputs.file("https://…/report.pdf") # file part
|
|
259
|
+
inputs.audio("https://…/call.wav") # input_audio part
|
|
260
|
+
inputs.file(inputs.data_url(pdf_bytes, "application/pdf"), filename="report.pdf") # from raw bytes
|
|
261
|
+
inputs.image(inputs.from_path("./photo.png")) # read a local file
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Interfaze rejects `image/gif` and `image/avif` client-side.
|
|
265
|
+
|
|
266
|
+
## Tasks
|
|
267
|
+
|
|
268
|
+
A task ([run_task](https://interfaze.ai/docs/run-tasks)) runs one built-in tool instead of the full model - faster and cheaper, but limited to that tool and its fixed output structure. So `task` can't be combined with a custom `response_format`; reach for a full completion (like [your first request](#your-first-request)) when you need the whole model or your own schema.
|
|
269
|
+
|
|
270
|
+
The `tasks.*` helpers are the shortest way - each takes a source and returns the raw result:
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
interfaze.tasks.ocr(url)
|
|
274
|
+
interfaze.tasks.object_detection(url)
|
|
275
|
+
interfaze.tasks.gui_detection(url)
|
|
276
|
+
interfaze.tasks.web_search(query)
|
|
277
|
+
interfaze.tasks.scrape(url)
|
|
278
|
+
interfaze.tasks.transcribe(url)
|
|
279
|
+
interfaze.tasks.translate(text, to="Spanish")
|
|
280
|
+
interfaze.tasks.forecast(csv_url, periods=30, unit="days")
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
For a multi-part message (text plus an input), set `task` on a normal `create` call - the result comes back on `message.content`:
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
import json
|
|
287
|
+
|
|
288
|
+
res = interfaze.chat.completions.create(
|
|
289
|
+
task="ocr",
|
|
290
|
+
messages=[{"role": "user", "content": [{"type": "text", "text": "Extract the total."}, inputs.image(url)]}],
|
|
291
|
+
)
|
|
292
|
+
result = json.loads(res.choices[0].message.content or "{}").get("result") # same output as tasks.ocr()
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Or a `<task>…</task>` system message plus an empty response schema:
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
import json
|
|
299
|
+
from interfaze import empty_task_schema
|
|
300
|
+
|
|
301
|
+
res = interfaze.chat.completions.create(
|
|
302
|
+
messages=[
|
|
303
|
+
{"role": "system", "content": "<task>ocr</task>"},
|
|
304
|
+
{"role": "user", "content": [{"type": "text", "text": "Extract the total."}, inputs.image(url)]},
|
|
305
|
+
],
|
|
306
|
+
response_format=empty_task_schema(), # an empty JSON schema
|
|
307
|
+
)
|
|
308
|
+
result = json.loads(res.choices[0].message.content or "{}").get("result")
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Guardrails
|
|
312
|
+
|
|
313
|
+
Enable safety categories with `guard`; a blocked request comes back as a normal completion, not an exception.
|
|
314
|
+
|
|
315
|
+
```python
|
|
316
|
+
res = interfaze.chat.completions.create(
|
|
317
|
+
guard=["S1", "S10", "S12_IMAGE"],
|
|
318
|
+
messages=[{"role": "user", "content": "..."}],
|
|
319
|
+
)
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
A match returns the plain string `unsafe S1` as `message.content` - so check for it. See the exported `GUARD_CODES`.
|
|
323
|
+
|
|
324
|
+
## Client options
|
|
325
|
+
|
|
326
|
+
Set router, cache, and streaming behavior once on the client:
|
|
327
|
+
|
|
328
|
+
```python
|
|
329
|
+
interfaze = Interfaze(
|
|
330
|
+
show_additional_info=True, # stream <precontext> deltas as they're produced
|
|
331
|
+
bypass_moe=True, # skip the mixture-of-experts router
|
|
332
|
+
bypass_cache=True, # skip the semantic cache
|
|
333
|
+
)
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Errors
|
|
337
|
+
|
|
338
|
+
Interfaze re-exports typed error classes to catch and narrow on:
|
|
339
|
+
|
|
340
|
+
```python
|
|
341
|
+
from interfaze import BadRequestError, InterfazeError, RateLimitError
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
`InterfazeError` is client-side (missing key, invalid guard code, stream misuse). Everything else is an `APIError` subclass carrying `status_code` and `code` - `BadRequestError` (400), `AuthenticationError` (401), `RateLimitError` (429), and so on.
|
|
345
|
+
|
|
346
|
+
## Capabilities
|
|
347
|
+
|
|
348
|
+
| Use case | Entry point |
|
|
349
|
+
| --------------------------------------- | ----------------------------------------------- |
|
|
350
|
+
| [Chat](#chat) | `chat.completions.create` |
|
|
351
|
+
| [Streaming](#streaming) | `chat.completions.stream` |
|
|
352
|
+
| [Structured output](#structured-output) | `response_format()` |
|
|
353
|
+
| [Reasoning](#reasoning) | `reasoning_effort` |
|
|
354
|
+
| [Tools](#tools-and-function-calling) | `tools` |
|
|
355
|
+
| [Multimodal inputs](#multimodal-inputs) | `inputs.*` |
|
|
356
|
+
| [OCR](#tasks) | `tasks.ocr` |
|
|
357
|
+
| [Object and GUI detection](#tasks) | `tasks.object_detection`, `tasks.gui_detection` |
|
|
358
|
+
| [Web search and scraping](#tasks) | `tasks.web_search`, `tasks.scrape` |
|
|
359
|
+
| [Speech to text](#tasks) | `tasks.transcribe` |
|
|
360
|
+
| [Translation](#tasks) | `tasks.translate` |
|
|
361
|
+
| [Forecasting](#tasks) | `tasks.forecast` |
|
|
362
|
+
| [Guardrails](#guardrails) | `guard` |
|
|
363
|
+
| [Precontext](#precontext) | `res.precontext` |
|
|
364
|
+
|
|
365
|
+
## License
|
|
366
|
+
|
|
367
|
+
MIT
|