instructor-ainative 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AINative Studio
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.
@@ -0,0 +1,189 @@
1
+ Metadata-Version: 2.4
2
+ Name: instructor-ainative
3
+ Version: 0.1.0
4
+ Summary: Pre-configured instructor client for structured output extraction via AINative's free LLM API
5
+ Author-email: AINative Studio <dev@ainative.studio>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/AINative-Studio/instructor-ainative
8
+ Project-URL: Documentation, https://docs.ainative.studio/instructor
9
+ Project-URL: Repository, https://github.com/AINative-Studio/instructor-ainative
10
+ Project-URL: Issues, https://github.com/AINative-Studio/instructor-ainative/issues
11
+ Keywords: instructor,instructor-plugin,structured-output,pydantic,json-extraction,free-llm,ainative,zerodb,openai-compatible,llama,qwen,deepseek,auto-provisioning,claude,cursor,function-calling,schema-extraction,data-extraction,llm-structured,json-mode
12
+ Classifier: Development Status :: 4 - Beta
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 :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: instructor>=1.0.0
27
+ Requires-Dist: openai>=1.0.0
28
+ Requires-Dist: requests>=2.28
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0; extra == "dev"
31
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
32
+ Requires-Dist: responses>=0.23; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ # instructor-ainative
36
+
37
+ Pre-configured [instructor](https://github.com/jxnl/instructor) client for structured output extraction using AINative's free LLM API.
38
+
39
+ **Zero setup.** Works with Llama 3.3 70B, Qwen3, DeepSeek 4, and Kimi K2 — all free.
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ pip install instructor-ainative
45
+ ```
46
+
47
+ ## Quick Start
48
+
49
+ ```python
50
+ from instructor_ainative import get_client
51
+ from pydantic import BaseModel
52
+
53
+ class User(BaseModel):
54
+ name: str
55
+ age: int
56
+
57
+ client = get_client() # Auto-provisions free API key
58
+ user = client.chat.completions.create(
59
+ model="meta-llama/Llama-3.3-70B-Instruct",
60
+ response_model=User,
61
+ messages=[{"role": "user", "content": "Extract: John is 30"}],
62
+ )
63
+ print(user) # User(name='John', age=30)
64
+ ```
65
+
66
+ ## How It Works
67
+
68
+ `instructor-ainative` wraps [instructor](https://python.useinstructor.com/) with a pre-configured OpenAI client pointing at AINative's free, OpenAI-compatible API. You get structured Pydantic output extraction from open-source models without any API key setup.
69
+
70
+ On first use, the package auto-provisions a free API key (72-hour TTL). Claim your account at [ainative.studio/signup](https://ainative.studio/signup) for permanent access.
71
+
72
+ ## Available Models
73
+
74
+ Use aliases or full model IDs:
75
+
76
+ ```python
77
+ from instructor_ainative import get_model, MODELS
78
+
79
+ # Aliases
80
+ get_model("llama") # meta-llama/Llama-3.3-70B-Instruct
81
+ get_model("qwen") # qwen3-coder-flash
82
+ get_model("deepseek") # deepseek-4-flash
83
+ get_model("kimi") # kimi-k2
84
+ ```
85
+
86
+ ## Async Support
87
+
88
+ ```python
89
+ import asyncio
90
+ from instructor_ainative import get_async_client
91
+ from pydantic import BaseModel
92
+
93
+ class User(BaseModel):
94
+ name: str
95
+ age: int
96
+
97
+ async def main():
98
+ client = get_async_client()
99
+ user = await client.chat.completions.create(
100
+ model="meta-llama/Llama-3.3-70B-Instruct",
101
+ response_model=User,
102
+ messages=[{"role": "user", "content": "Extract: John is 30"}],
103
+ )
104
+ print(user)
105
+
106
+ asyncio.run(main())
107
+ ```
108
+
109
+ ## Configuration
110
+
111
+ ### API Key Resolution Order
112
+
113
+ 1. Explicit `api_key` parameter
114
+ 2. `AINATIVE_API_KEY` environment variable
115
+ 3. `ZERODB_API_KEY` environment variable
116
+ 4. `~/.zerodb/credentials.json` (shared with ZeroDB ecosystem)
117
+ 5. Auto-provision (free, 72-hour TTL)
118
+
119
+ ### Bring Your Own Key
120
+
121
+ ```bash
122
+ export AINATIVE_API_KEY=your-key-here
123
+ ```
124
+
125
+ ```python
126
+ # Or pass directly
127
+ client = get_client(api_key="your-key-here")
128
+ ```
129
+
130
+ ### Custom Base URL
131
+
132
+ ```python
133
+ client = get_client(base_url="https://your-proxy.example.com/v1")
134
+ ```
135
+
136
+ ### Instructor Mode
137
+
138
+ ```python
139
+ import instructor
140
+ client = get_client(mode=instructor.Mode.TOOLS) # Default is JSON mode
141
+ ```
142
+
143
+ ## Complex Extraction
144
+
145
+ ```python
146
+ from instructor_ainative import get_client
147
+ from pydantic import BaseModel, Field
148
+ from typing import List
149
+
150
+ class Address(BaseModel):
151
+ street: str
152
+ city: str
153
+ state: str
154
+ zip_code: str = Field(description="5-digit ZIP code")
155
+
156
+ class Contact(BaseModel):
157
+ name: str
158
+ email: str
159
+ phone: str
160
+ addresses: List[Address]
161
+
162
+ client = get_client()
163
+ contact = client.chat.completions.create(
164
+ model="meta-llama/Llama-3.3-70B-Instruct",
165
+ response_model=Contact,
166
+ messages=[{
167
+ "role": "user",
168
+ "content": """
169
+ Extract contact info: Jane Smith, jane@example.com, 555-0123.
170
+ Lives at 123 Main St, Austin TX 78701 and
171
+ 456 Oak Ave, Denver CO 80202.
172
+ """
173
+ }],
174
+ )
175
+ ```
176
+
177
+ ## Why instructor-ainative?
178
+
179
+ | Feature | instructor + OpenAI | instructor-ainative |
180
+ |---------|-------------------|-------------------|
181
+ | Setup | Get API key, set env var | `pip install` and go |
182
+ | Cost | Pay per token | Free |
183
+ | Models | GPT-4o, etc. | Llama 70B, Qwen, DeepSeek |
184
+ | Structured output | Yes | Yes |
185
+ | Auto-provisioning | No | Yes |
186
+
187
+ ## License
188
+
189
+ MIT
@@ -0,0 +1,155 @@
1
+ # instructor-ainative
2
+
3
+ Pre-configured [instructor](https://github.com/jxnl/instructor) client for structured output extraction using AINative's free LLM API.
4
+
5
+ **Zero setup.** Works with Llama 3.3 70B, Qwen3, DeepSeek 4, and Kimi K2 — all free.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install instructor-ainative
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```python
16
+ from instructor_ainative import get_client
17
+ from pydantic import BaseModel
18
+
19
+ class User(BaseModel):
20
+ name: str
21
+ age: int
22
+
23
+ client = get_client() # Auto-provisions free API key
24
+ user = client.chat.completions.create(
25
+ model="meta-llama/Llama-3.3-70B-Instruct",
26
+ response_model=User,
27
+ messages=[{"role": "user", "content": "Extract: John is 30"}],
28
+ )
29
+ print(user) # User(name='John', age=30)
30
+ ```
31
+
32
+ ## How It Works
33
+
34
+ `instructor-ainative` wraps [instructor](https://python.useinstructor.com/) with a pre-configured OpenAI client pointing at AINative's free, OpenAI-compatible API. You get structured Pydantic output extraction from open-source models without any API key setup.
35
+
36
+ On first use, the package auto-provisions a free API key (72-hour TTL). Claim your account at [ainative.studio/signup](https://ainative.studio/signup) for permanent access.
37
+
38
+ ## Available Models
39
+
40
+ Use aliases or full model IDs:
41
+
42
+ ```python
43
+ from instructor_ainative import get_model, MODELS
44
+
45
+ # Aliases
46
+ get_model("llama") # meta-llama/Llama-3.3-70B-Instruct
47
+ get_model("qwen") # qwen3-coder-flash
48
+ get_model("deepseek") # deepseek-4-flash
49
+ get_model("kimi") # kimi-k2
50
+ ```
51
+
52
+ ## Async Support
53
+
54
+ ```python
55
+ import asyncio
56
+ from instructor_ainative import get_async_client
57
+ from pydantic import BaseModel
58
+
59
+ class User(BaseModel):
60
+ name: str
61
+ age: int
62
+
63
+ async def main():
64
+ client = get_async_client()
65
+ user = await client.chat.completions.create(
66
+ model="meta-llama/Llama-3.3-70B-Instruct",
67
+ response_model=User,
68
+ messages=[{"role": "user", "content": "Extract: John is 30"}],
69
+ )
70
+ print(user)
71
+
72
+ asyncio.run(main())
73
+ ```
74
+
75
+ ## Configuration
76
+
77
+ ### API Key Resolution Order
78
+
79
+ 1. Explicit `api_key` parameter
80
+ 2. `AINATIVE_API_KEY` environment variable
81
+ 3. `ZERODB_API_KEY` environment variable
82
+ 4. `~/.zerodb/credentials.json` (shared with ZeroDB ecosystem)
83
+ 5. Auto-provision (free, 72-hour TTL)
84
+
85
+ ### Bring Your Own Key
86
+
87
+ ```bash
88
+ export AINATIVE_API_KEY=your-key-here
89
+ ```
90
+
91
+ ```python
92
+ # Or pass directly
93
+ client = get_client(api_key="your-key-here")
94
+ ```
95
+
96
+ ### Custom Base URL
97
+
98
+ ```python
99
+ client = get_client(base_url="https://your-proxy.example.com/v1")
100
+ ```
101
+
102
+ ### Instructor Mode
103
+
104
+ ```python
105
+ import instructor
106
+ client = get_client(mode=instructor.Mode.TOOLS) # Default is JSON mode
107
+ ```
108
+
109
+ ## Complex Extraction
110
+
111
+ ```python
112
+ from instructor_ainative import get_client
113
+ from pydantic import BaseModel, Field
114
+ from typing import List
115
+
116
+ class Address(BaseModel):
117
+ street: str
118
+ city: str
119
+ state: str
120
+ zip_code: str = Field(description="5-digit ZIP code")
121
+
122
+ class Contact(BaseModel):
123
+ name: str
124
+ email: str
125
+ phone: str
126
+ addresses: List[Address]
127
+
128
+ client = get_client()
129
+ contact = client.chat.completions.create(
130
+ model="meta-llama/Llama-3.3-70B-Instruct",
131
+ response_model=Contact,
132
+ messages=[{
133
+ "role": "user",
134
+ "content": """
135
+ Extract contact info: Jane Smith, jane@example.com, 555-0123.
136
+ Lives at 123 Main St, Austin TX 78701 and
137
+ 456 Oak Ave, Denver CO 80202.
138
+ """
139
+ }],
140
+ )
141
+ ```
142
+
143
+ ## Why instructor-ainative?
144
+
145
+ | Feature | instructor + OpenAI | instructor-ainative |
146
+ |---------|-------------------|-------------------|
147
+ | Setup | Get API key, set env var | `pip install` and go |
148
+ | Cost | Pay per token | Free |
149
+ | Models | GPT-4o, etc. | Llama 70B, Qwen, DeepSeek |
150
+ | Structured output | Yes | Yes |
151
+ | Auto-provisioning | No | Yes |
152
+
153
+ ## License
154
+
155
+ MIT
@@ -0,0 +1,30 @@
1
+ """
2
+ instructor-ainative — Structured output extraction via AINative's free LLM API.
3
+
4
+ Pre-configured instructor client that connects to AINative's OpenAI-compatible
5
+ endpoint. Supports Llama, Qwen, and DeepSeek models with auto-provisioning.
6
+
7
+ Usage:
8
+ from instructor_ainative import get_client
9
+ from pydantic import BaseModel
10
+
11
+ class User(BaseModel):
12
+ name: str
13
+ age: int
14
+
15
+ client = get_client()
16
+ user = client.chat.completions.create(
17
+ model="meta-llama/Llama-3.3-70B-Instruct",
18
+ response_model=User,
19
+ messages=[{"role": "user", "content": "Extract: John is 30"}],
20
+ )
21
+ print(user) # User(name='John', age=30)
22
+
23
+ Refs #3950
24
+ """
25
+
26
+ from instructor_ainative.client import get_client, get_async_client
27
+ from instructor_ainative.models import MODELS, get_model
28
+
29
+ __all__ = ["get_client", "get_async_client", "MODELS", "get_model"]
30
+ __version__ = "0.1.0"
@@ -0,0 +1,118 @@
1
+ """
2
+ instructor-ainative — Client Factory
3
+
4
+ Creates pre-configured instructor clients that connect to AINative's
5
+ OpenAI-compatible API for structured output extraction.
6
+
7
+ Refs #3950
8
+ """
9
+
10
+ from typing import Optional
11
+
12
+ import instructor
13
+ from openai import OpenAI, AsyncOpenAI
14
+
15
+ from instructor_ainative.provision import resolve_api_key
16
+
17
+ BASE_URL = "https://api.ainative.studio/api/v1"
18
+
19
+
20
+ def get_client(
21
+ api_key: Optional[str] = None,
22
+ base_url: Optional[str] = None,
23
+ mode: instructor.Mode = instructor.Mode.JSON,
24
+ **kwargs,
25
+ ) -> instructor.Instructor:
26
+ """
27
+ Create a pre-configured instructor client for structured output extraction.
28
+
29
+ Uses AINative's free OpenAI-compatible API. If no API key is provided,
30
+ auto-provisions a free account.
31
+
32
+ Args:
33
+ api_key: Explicit API key. Falls back to env vars, credentials file,
34
+ or auto-provisioning.
35
+ base_url: Override the API base URL. Defaults to AINative's endpoint.
36
+ mode: instructor mode for structured output. Defaults to JSON mode
37
+ which works best with open-source models.
38
+ **kwargs: Additional arguments passed to instructor.from_openai().
39
+
40
+ Returns:
41
+ An instructor-patched OpenAI client ready for structured output.
42
+
43
+ Example:
44
+ from instructor_ainative import get_client
45
+ from pydantic import BaseModel
46
+
47
+ class User(BaseModel):
48
+ name: str
49
+ age: int
50
+
51
+ client = get_client()
52
+ user = client.chat.completions.create(
53
+ model="meta-llama/Llama-3.3-70B-Instruct",
54
+ response_model=User,
55
+ messages=[{"role": "user", "content": "Extract: John is 30"}],
56
+ )
57
+ """
58
+ key = resolve_api_key(api_key)
59
+ base = base_url or BASE_URL
60
+
61
+ base_client = OpenAI(
62
+ api_key=key,
63
+ base_url=base,
64
+ )
65
+
66
+ return instructor.from_openai(base_client, mode=mode, **kwargs)
67
+
68
+
69
+ def get_async_client(
70
+ api_key: Optional[str] = None,
71
+ base_url: Optional[str] = None,
72
+ mode: instructor.Mode = instructor.Mode.JSON,
73
+ **kwargs,
74
+ ) -> instructor.AsyncInstructor:
75
+ """
76
+ Create a pre-configured async instructor client for structured output extraction.
77
+
78
+ Same as get_client() but uses AsyncOpenAI for async/await usage.
79
+
80
+ Args:
81
+ api_key: Explicit API key. Falls back to env vars, credentials file,
82
+ or auto-provisioning.
83
+ base_url: Override the API base URL. Defaults to AINative's endpoint.
84
+ mode: instructor mode for structured output. Defaults to JSON mode.
85
+ **kwargs: Additional arguments passed to instructor.from_openai().
86
+
87
+ Returns:
88
+ An async instructor-patched OpenAI client.
89
+
90
+ Example:
91
+ import asyncio
92
+ from instructor_ainative import get_async_client
93
+ from pydantic import BaseModel
94
+
95
+ class User(BaseModel):
96
+ name: str
97
+ age: int
98
+
99
+ async def main():
100
+ client = get_async_client()
101
+ user = await client.chat.completions.create(
102
+ model="meta-llama/Llama-3.3-70B-Instruct",
103
+ response_model=User,
104
+ messages=[{"role": "user", "content": "Extract: John is 30"}],
105
+ )
106
+ print(user)
107
+
108
+ asyncio.run(main())
109
+ """
110
+ key = resolve_api_key(api_key)
111
+ base = base_url or BASE_URL
112
+
113
+ base_client = AsyncOpenAI(
114
+ api_key=key,
115
+ base_url=base,
116
+ )
117
+
118
+ return instructor.from_openai(base_client, mode=mode, **kwargs)
@@ -0,0 +1,55 @@
1
+ """
2
+ instructor-ainative — Supported Models
3
+
4
+ Model aliases and catalog for AINative's OpenAI-compatible endpoint.
5
+ All models support structured output extraction via instructor.
6
+
7
+ Refs #3950
8
+ """
9
+
10
+ from typing import Optional
11
+
12
+ # Model aliases -> full model identifiers
13
+ MODELS = {
14
+ # Meta Llama
15
+ "llama": "meta-llama/Llama-3.3-70B-Instruct",
16
+ "llama-70b": "meta-llama/Llama-3.3-70B-Instruct",
17
+ "llama-8b": "meta-llama/Llama-3.1-8B-Instruct",
18
+ # Qwen
19
+ "qwen": "qwen3-coder-flash",
20
+ "qwen-coder": "qwen3-coder-flash",
21
+ # DeepSeek
22
+ "deepseek": "deepseek-4-flash",
23
+ "deepseek-flash": "deepseek-4-flash",
24
+ # Kimi
25
+ "kimi": "kimi-k2",
26
+ }
27
+
28
+ # Default model for get_client()
29
+ DEFAULT_MODEL = "meta-llama/Llama-3.3-70B-Instruct"
30
+
31
+
32
+ def get_model(alias: str) -> str:
33
+ """
34
+ Resolve a model alias to its full identifier.
35
+
36
+ Args:
37
+ alias: Short alias (e.g. "llama", "qwen") or full model ID.
38
+
39
+ Returns:
40
+ Full model identifier string.
41
+
42
+ Examples:
43
+ >>> get_model("llama")
44
+ 'meta-llama/Llama-3.3-70B-Instruct'
45
+ >>> get_model("qwen")
46
+ 'qwen3-coder-flash'
47
+ >>> get_model("meta-llama/Llama-3.3-70B-Instruct")
48
+ 'meta-llama/Llama-3.3-70B-Instruct'
49
+ """
50
+ return MODELS.get(alias, alias)
51
+
52
+
53
+ def list_models() -> dict:
54
+ """Return all available model aliases and their full identifiers."""
55
+ return dict(MODELS)