modelcall 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.
- modelcall-0.1.0/LICENSE +202 -0
- modelcall-0.1.0/PKG-INFO +257 -0
- modelcall-0.1.0/README.md +216 -0
- modelcall-0.1.0/modelcall/__init__.py +3 -0
- modelcall-0.1.0/modelcall/__main__.py +203 -0
- modelcall-0.1.0/modelcall/agent.py +322 -0
- modelcall-0.1.0/modelcall/agent_tools.py +465 -0
- modelcall-0.1.0/modelcall/app.py +137 -0
- modelcall-0.1.0/modelcall/batches.py +134 -0
- modelcall-0.1.0/modelcall/checker.py +534 -0
- modelcall-0.1.0/modelcall/cli.py +636 -0
- modelcall-0.1.0/modelcall/doctor.py +113 -0
- modelcall-0.1.0/modelcall/evaluator.py +174 -0
- modelcall-0.1.0/modelcall/export.py +244 -0
- modelcall-0.1.0/modelcall/inference.py +710 -0
- modelcall-0.1.0/modelcall/matcher.py +276 -0
- modelcall-0.1.0/modelcall/mcp_server.py +218 -0
- modelcall-0.1.0/modelcall/migrate.py +120 -0
- modelcall-0.1.0/modelcall/profiling.py +186 -0
- modelcall-0.1.0/modelcall/providers/__init__.py +20 -0
- modelcall-0.1.0/modelcall/providers/anthropic.py +223 -0
- modelcall-0.1.0/modelcall/providers/base.py +89 -0
- modelcall-0.1.0/modelcall/providers/fake.py +140 -0
- modelcall-0.1.0/modelcall/providers/openai_compat.py +345 -0
- modelcall-0.1.0/modelcall/resolver.py +303 -0
- modelcall-0.1.0/modelcall/review.py +354 -0
- modelcall-0.1.0/modelcall/schema.py +107 -0
- modelcall-0.1.0/modelcall/serve.py +15 -0
- modelcall-0.1.0/modelcall/settings.py +50 -0
- modelcall-0.1.0/modelcall/sql/bridge/http.sql +53 -0
- modelcall-0.1.0/modelcall/sql/bridge/plpython3u.sql +56 -0
- modelcall-0.1.0/modelcall/sql/install.sql +26 -0
- modelcall-0.1.0/modelcall/sql/migrations/0001_core.sql +589 -0
- modelcall-0.1.0/modelcall/sql/migrations/0002_tasks.sql +941 -0
- modelcall-0.1.0/modelcall/sql/migrations/0003_agent.sql +644 -0
- modelcall-0.1.0/modelcall/sql/migrations/0004_master_data.sql +585 -0
- modelcall-0.1.0/modelcall/sql/migrations/0005_mappings.sql +900 -0
- modelcall-0.1.0/modelcall/sql/migrations/0006_providers.sql +32 -0
- modelcall-0.1.0/modelcall/sql/migrations/0007_ledger.sql +735 -0
- modelcall-0.1.0/modelcall/sql/migrations/0008_evaluation.sql +919 -0
- modelcall-0.1.0/modelcall/sql/migrations/0009_semantics.sql +852 -0
- modelcall-0.1.0/modelcall/sql/migrations/0010_conformance.sql +779 -0
- modelcall-0.1.0/modelcall/sql/migrations/0011_standardization.sql +540 -0
- modelcall-0.1.0/modelcall/sql/migrations/0012_entities.sql +686 -0
- modelcall-0.1.0/modelcall/sql/migrations/0013_check_controls.sql +107 -0
- modelcall-0.1.0/modelcall/sql/migrations/0014_preview_categories.sql +37 -0
- modelcall-0.1.0/modelcall/sql/migrations/0015_agent_and_rules.sql +385 -0
- modelcall-0.1.0/modelcall/sql/migrations/0016_check_population.sql +82 -0
- modelcall-0.1.0/modelcall/sql/migrations/0017_rename_to_modelcall.sql +125 -0
- modelcall-0.1.0/modelcall/sql/migrations/0018_routing.sql +260 -0
- modelcall-0.1.0/modelcall/sql/migrations/0019_measured_routing.sql +207 -0
- modelcall-0.1.0/modelcall/sql/migrations/0020_watch_costs_categories.sql +271 -0
- modelcall-0.1.0/modelcall/text.py +45 -0
- modelcall-0.1.0/modelcall/worker.py +307 -0
- modelcall-0.1.0/modelcall.egg-info/PKG-INFO +257 -0
- modelcall-0.1.0/modelcall.egg-info/SOURCES.txt +78 -0
- modelcall-0.1.0/modelcall.egg-info/dependency_links.txt +1 -0
- modelcall-0.1.0/modelcall.egg-info/entry_points.txt +2 -0
- modelcall-0.1.0/modelcall.egg-info/requires.txt +20 -0
- modelcall-0.1.0/modelcall.egg-info/top_level.txt +1 -0
- modelcall-0.1.0/pyproject.toml +61 -0
- modelcall-0.1.0/setup.cfg +4 -0
- modelcall-0.1.0/tests/test_agent.py +417 -0
- modelcall-0.1.0/tests/test_api.py +50 -0
- modelcall-0.1.0/tests/test_cli.py +564 -0
- modelcall-0.1.0/tests/test_conformance.py +301 -0
- modelcall-0.1.0/tests/test_entities.py +148 -0
- modelcall-0.1.0/tests/test_evaluation.py +243 -0
- modelcall-0.1.0/tests/test_inference.py +128 -0
- modelcall-0.1.0/tests/test_install_sql.py +50 -0
- modelcall-0.1.0/tests/test_mapping.py +328 -0
- modelcall-0.1.0/tests/test_master_data.py +281 -0
- modelcall-0.1.0/tests/test_providers.py +345 -0
- modelcall-0.1.0/tests/test_routing.py +336 -0
- modelcall-0.1.0/tests/test_schema.py +68 -0
- modelcall-0.1.0/tests/test_semantics.py +268 -0
- modelcall-0.1.0/tests/test_sql.py +125 -0
- modelcall-0.1.0/tests/test_standardization.py +152 -0
- modelcall-0.1.0/tests/test_throughput.py +191 -0
- modelcall-0.1.0/tests/test_worker.py +484 -0
modelcall-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
modelcall-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: modelcall
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AI functions for PostgreSQL: classify, extract, check and reconcile data in SQL with the model you choose
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/tconwell/modelcall
|
|
7
|
+
Project-URL: Documentation, https://github.com/tconwell/modelcall/blob/main/docs/guide.md
|
|
8
|
+
Project-URL: Source, https://github.com/tconwell/modelcall
|
|
9
|
+
Project-URL: Issues, https://github.com/tconwell/modelcall/issues
|
|
10
|
+
Keywords: postgresql,sql,llm,ai,classification,extraction,data-quality,master-data
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: SQL
|
|
18
|
+
Classifier: Topic :: Database
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: anthropic>=1.0
|
|
24
|
+
Requires-Dist: fastapi>=0.115
|
|
25
|
+
Requires-Dist: jsonschema>=4.23
|
|
26
|
+
Requires-Dist: openai>=1.60
|
|
27
|
+
Requires-Dist: psycopg[binary,pool]>=3.2
|
|
28
|
+
Requires-Dist: pydantic>=2.7
|
|
29
|
+
Requires-Dist: pydantic-settings>=2.4
|
|
30
|
+
Requires-Dist: python-dotenv>=1.0
|
|
31
|
+
Requires-Dist: uvicorn[standard]>=0.30
|
|
32
|
+
Provides-Extra: bedrock
|
|
33
|
+
Requires-Dist: anthropic[bedrock]>=1.0; extra == "bedrock"
|
|
34
|
+
Provides-Extra: vertex
|
|
35
|
+
Requires-Dist: anthropic[vertex]>=1.0; extra == "vertex"
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: httpx>=0.27; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# modelcall
|
|
43
|
+
|
|
44
|
+
**AI functions for PostgreSQL. Your database, your model.**
|
|
45
|
+
|
|
46
|
+
modelcall lets you classify text, extract structured fields, check data quality and reconcile entities with SQL, using the model you choose: Claude, GPT, Gemini or a local model through Ollama or vLLM. Every answer is typed and validated, every call is recorded in the database, and anything that would change your schema or master data is a proposal that a person reviews first.
|
|
47
|
+
|
|
48
|
+
```sql
|
|
49
|
+
SELECT mod.classify(body, ARRAY['billing', 'bug', 'feature']) FROM support.tickets LIMIT 20;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Snowflake ([Cortex AISQL](https://docs.snowflake.com/en/user-guide/snowflake-cortex/aisql)), Databricks ([AI Functions](https://docs.databricks.com/aws/en/large-language-models/ai-functions)) and BigQuery ([generative AI functions](https://docs.cloud.google.com/bigquery/docs/generative-ai-overview)) offer the same kind of functions inside their platforms. modelcall brings them to the PostgreSQL you already run, adds the work around the calls (estimates, budgets, evaluation, review), and extends them to enrichment, data quality and master data. See [how it compares](https://github.com/tconwell/modelcall/blob/main/docs/comparison.md).
|
|
53
|
+
|
|
54
|
+
- **Any PostgreSQL, 15 to 18.** Self-hosted or managed: it needs no superuser, and the `mod` schema and the worker need no database extensions. Inline calls such as `SELECT mod.classify(...)` additionally need a sync bridge using `plpython3u` or `http`.
|
|
55
|
+
- **Any model.** Anthropic, Amazon Bedrock, Google Vertex AI, Microsoft Foundry, OpenAI, and any OpenAI-compatible endpoint, including local models. Different tasks can use different model profiles.
|
|
56
|
+
- **Work you can manage.** Estimate a job before it runs, cap it with a budget, measure accuracy on labelled examples, and query the ledger of every call for cost and latency.
|
|
57
|
+
|
|
58
|
+
## Features
|
|
59
|
+
|
|
60
|
+
| | What you get |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| **AI functions in SQL** | `mod.classify`, `mod.filter`, `mod.extract` (into a table's row type), `mod.extract_json`, `mod.generate` and named tasks with `mod.run`, callable from any query. [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#ai-functions-in-sql) |
|
|
63
|
+
| **Enrichment that stays current** | Attach a task to a table and a worker fills a column (or a side table) for every row, then keeps it current as rows are inserted or changed. Only changed inputs cost a call. [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#tasks-over-tables) |
|
|
64
|
+
| **Definitions** | An agent reads the catalog and, where you allow it, the data, and proposes a business definition for every table and column. Approved definitions become `COMMENT`s, dbt docs and context for your agents. [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#definitions-and-the-agent) |
|
|
65
|
+
| **Semantic data quality** | Checks whether each column holds what its definition says, judging distinct values instead of rows, and reports what the other values are. A `carrier` column where a fifth of the rows say "Store pickup" or "TBD" passes every not-null and format test, but not this one. [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#semantic-data-quality) |
|
|
66
|
+
| **Master data** | Maps raw values to your code sets through approved crosswalks. Known values never call a model; each unknown value is asked about once, and the answer is a proposal. [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#master-data) |
|
|
67
|
+
| **Entity resolution** | One master record per real-world entity across sources, with reviewed matches, golden records by survivorship rules, and undo. [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#entity-resolution) |
|
|
68
|
+
| **Bronze-to-silver mappings** | A JSON spec, never model-written SQL, compiled to an idempotent upsert, previewed against the real data, reviewed, and rerun on every load. [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#bronze-to-silver-mappings) |
|
|
69
|
+
| **Evaluation** | Accuracy, precision, cost and latency per model on your labelled examples. Corrections become examples, and auto-approval is allowed only on measured precision. [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#evaluation) |
|
|
70
|
+
| **Review and governance** | Proposals reviewed in the terminal, on a web page or as a migration file in a pull request, and a data policy that decides which columns a model may see. [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#review-and-governance) |
|
|
71
|
+
| **For agents and tools** | `modelcall mcp` serves definitions, quality results and mappings to coding and analytics agents; `modelcall export` writes dbt `schema.yml`, SQL or JSON. [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#agents-dbt-and-bi-tools) |
|
|
72
|
+
| **Cost control** | Model routing, where a small model picks the least expensive tier each task needs; short inputs packed many to a call, prompt caching, provider batch APIs at about half price, cascades from a cheap model to a stronger one, and a cache that serves repeated calls for free. [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#cost-and-throughput) |
|
|
73
|
+
|
|
74
|
+
## How it works
|
|
75
|
+
|
|
76
|
+
- **The `mod` schema** holds model profiles, named tasks, definitions, proposals, checks and the ledger of every call, as tables, views and functions.
|
|
77
|
+
- **The engine** (`modelcall serve`) is a small Python service. It holds provider credentials, calls the model, validates every answer against a JSON Schema, and records the call in `mod.calls`.
|
|
78
|
+
- **The worker** (`modelcall worker`, or `modelcall serve --worker`) processes the queues: attached tasks, values waiting for a mapping, agent runs, evaluations, checks and matching. Run as many as you like; they coordinate through the database.
|
|
79
|
+
- **One-shot commands** (`modelcall check`, `annotate`, `classify`, `run`) install the schema if needed, do the work in one process and exit. Nothing to deploy.
|
|
80
|
+
- **The sync bridge** (optional, `plpython3u` or the `http` extension) lets SQL functions such as `mod.classify` call the engine directly. Without it, use attached tasks and the one-shot commands.
|
|
81
|
+
|
|
82
|
+
What it guarantees:
|
|
83
|
+
|
|
84
|
+
- **Typed, validated outputs.** Every call has an output schema. Answers are validated locally, with one repair attempt, and an invalid answer is never returned as a success.
|
|
85
|
+
- **Explicit outcomes.** Every call ends `ok`, `abstain` (the input doesn't contain the answer), `invalid`, `refused` or `error`.
|
|
86
|
+
- **A ledger that is also the cache.** `mod.calls` records model, task version, outcome, tokens, latency and cost on its own connection, so the record survives a rollback. A repeated identical call is served from it.
|
|
87
|
+
- **No secrets in the database.** A model profile names an environment variable, and a trigger rejects keys in its settings.
|
|
88
|
+
- **People decide.** The agent can only read. Anything that would change your schema, master data or pipelines is a proposal, applied by plain SQL with the reviewer's own privileges.
|
|
89
|
+
|
|
90
|
+
## Install
|
|
91
|
+
|
|
92
|
+
Requirements: PostgreSQL 15 or later, a UTF8 database, and Python 3.12 or later where the engine runs. The installing role must be able to create schemas and roles; on managed services that's the admin user (see [installing on managed PostgreSQL](https://github.com/tconwell/modelcall/blob/main/docs/install-managed.md)).
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
pip install modelcall
|
|
96
|
+
export MODELCALL_DATABASE_URL=postgresql://admin@localhost/app
|
|
97
|
+
modelcall doctor # checks version, encoding, privileges and notifications
|
|
98
|
+
modelcall migrate # creates or upgrades the mod schema
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`modelcall migrate` creates the schema `mod` and five `NOLOGIN` roles: `modelcall_user` (call functions, read results), `modelcall_admin` (models, tasks, policy, agent runs), `modelcall_reviewer` (approve and apply proposals), `modelcall_engine` (what the engine connects as) and `modelcall_agent` (what the agent reads as). Can't run Python next to the database? `modelcall sql > install.sql` prints the same SQL for any client.
|
|
102
|
+
|
|
103
|
+
For Claude on Amazon Bedrock or Google Vertex AI, install the extras: `pip install "modelcall[bedrock,vertex]"`.
|
|
104
|
+
|
|
105
|
+
To keep tasks and checks current, run the engine with its worker as a login that is a member of `modelcall_engine`:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
psql -c "CREATE ROLE modelcall_engine_login LOGIN PASSWORD '...' IN ROLE modelcall_engine"
|
|
109
|
+
export MODELCALL_DATABASE_URL=postgresql://modelcall_engine_login:...@localhost/app
|
|
110
|
+
export MODELCALL_API_KEY=$(openssl rand -hex 24) # protects the engine's HTTP API
|
|
111
|
+
modelcall serve --worker # the engine on 127.0.0.1:8420, plus a worker
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Optional: `modelcall install-bridge --engine-url http://127.0.0.1:8420` installs the sync bridge where `plpython3u` is available (add `--kind http` for the `http` extension, as on Supabase). Check it with `SELECT mod.test_connection();`.
|
|
115
|
+
|
|
116
|
+
With Docker, for local development (Postgres with `plpython3u`, the engine, and Ollama with `--profile local`):
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
git clone https://github.com/tconwell/modelcall && cd modelcall
|
|
120
|
+
cp .env.example .env # set MODELCALL_API_KEY, POSTGRES_PASSWORD and a provider key
|
|
121
|
+
docker compose up --build -d
|
|
122
|
+
docker compose exec engine modelcall install-bridge --engine-url http://engine:8420
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Connect a model
|
|
126
|
+
|
|
127
|
+
A model profile is a row in `mod.models`. Calls and tasks can name a profile; the rest run on a routed tier (below) or on `mod.settings.default_model`.
|
|
128
|
+
|
|
129
|
+
```sql
|
|
130
|
+
INSERT INTO mod.models (name, provider, model, params) VALUES
|
|
131
|
+
('fast', 'anthropic', 'claude-haiku-5-5', '{"effort": "low", "max_tokens": 2048}'),
|
|
132
|
+
('smart', 'anthropic', 'claude-opus-5-5', '{"effort": "medium"}'),
|
|
133
|
+
('local', 'openai', 'llama3.1', '{"base_url": "http://localhost:11434/v1", "structured_output": false}');
|
|
134
|
+
|
|
135
|
+
UPDATE mod.settings SET value = 'fast' WHERE key = 'default_model';
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| Provider | Models | Credentials (engine side only) |
|
|
139
|
+
| --- | --- | --- |
|
|
140
|
+
| `anthropic` | Claude on the Anthropic API | `ANTHROPIC_API_KEY`, or the variable named in `params.api_key_env` |
|
|
141
|
+
| `bedrock` | Claude on Amazon Bedrock | The AWS credential chain; `params.aws_region` |
|
|
142
|
+
| `vertex` | Claude on Google Cloud Vertex AI | Application Default Credentials; `params.project_id`, `params.region` |
|
|
143
|
+
| `foundry` | Claude on Microsoft Foundry | `params.resource` and `params.api_key_env` |
|
|
144
|
+
| `openai` | OpenAI, and any compatible endpoint: Azure OpenAI, Databricks model serving, Gemini, Mistral, Groq, OpenRouter, vLLM, Ollama | `OPENAI_API_KEY` or `params.api_key_env`; `params.base_url` |
|
|
145
|
+
|
|
146
|
+
Add `params.pricing` (`{"input_per_mtok": 1.0, "output_per_mtok": 5.0}`, USD per million tokens) and every call records what it cost. On the command line, `--model` takes a profile name or `provider:model` (`anthropic:claude-opus-5-5`, `openai:gpt-5-mini`, `ollama:llama3.2`); while no tiers are set, the first one you use becomes the default. More in the [guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#model-profiles).
|
|
147
|
+
|
|
148
|
+
**Model tiers.** Give modelcall a low, medium and high model, and work that names no model is routed. The first time a task, checked column or inline call runs, the low model reads its instructions, output schema and a few sample inputs and picks the least expensive tier that will do it reliably. Every row after that runs on that tier. Once a subject has labelled examples, the guess is replaced by measurement: modelcall evaluates it on all three tiers and keeps the cheapest one that scores as well as the best (`modelcall evaluate task_name --route`). The decisions and their reasons are in `mod.routes`, and `mod.set_route('task_name', 'high')` overrides one. A model named on the call or the task always wins. More in the [guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md#model-tiers-and-routing).
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
modelcall models --low anthropic:claude-haiku-5-5 --medium anthropic:claude-sonnet-5-5 --high anthropic:claude-opus-5-5
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Usage
|
|
155
|
+
|
|
156
|
+
**Check a schema's data quality** in one command. It lists the columns whose values it would send to the model and asks first. The output below is illustrative:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
modelcall check postgresql://localhost/shop --schema shop --model anthropic:claude-opus-5-5
|
|
160
|
+
# shop.orders.carrier: 22% of rows violate (delivery_method 17%, placeholder 5%)
|
|
161
|
+
# value rows category rationale
|
|
162
|
+
# Store pickup 2104 delivery_method a way to receive the order, not a carrier
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**Write definitions** for a schema. The agent proposes; you review:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
modelcall annotate --schema sales
|
|
169
|
+
modelcall review --kind comment # one key per decision: approve, apply, reject, edit
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Label every row of a table**, and keep the labels current as rows change (with a worker running):
|
|
173
|
+
|
|
174
|
+
```sql
|
|
175
|
+
ALTER TABLE support.tickets ADD COLUMN category text;
|
|
176
|
+
SELECT mod.create_task('ticket_category', 'Categorise the support ticket.',
|
|
177
|
+
mod.enum_of('billing', 'bug', 'feature', 'other'));
|
|
178
|
+
SELECT * FROM mod.estimate('ticket_category', 'support.tickets', input => $$subject || E'\n' || body$$);
|
|
179
|
+
SELECT mod.attach('ticket_category', 'support.tickets',
|
|
180
|
+
input => $$subject || E'\n' || body$$,
|
|
181
|
+
output => 'category',
|
|
182
|
+
budget => '{"max_calls": 50000}');
|
|
183
|
+
SELECT * FROM mod.job_status;
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Call a model inline** (with the sync bridge installed), for example to extract typed fields from text:
|
|
187
|
+
|
|
188
|
+
```sql
|
|
189
|
+
SELECT r.*
|
|
190
|
+
FROM bronze.invoice_text t
|
|
191
|
+
CROSS JOIN LATERAL mod.extract(t.body, NULL::silver.invoice) r; -- the row type's columns, types and comments are the schema
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Map messy values to a code set**, asking a model only about values it hasn't seen:
|
|
195
|
+
|
|
196
|
+
```sql
|
|
197
|
+
SELECT mod.create_domain('country', 'ref.countries', key => 'iso2', label => 'name', aliases => ARRAY['iso3']);
|
|
198
|
+
SELECT mod.resolve('country', country_raw, context => source_system) FROM bronze.customers;
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**See what it cost:**
|
|
202
|
+
|
|
203
|
+
```sql
|
|
204
|
+
SELECT * FROM mod.usage ORDER BY day DESC; -- calls, cache hits, tokens and cost per day, model and task
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
The [tutorial](https://github.com/tconwell/modelcall/blob/main/docs/tutorial.md) walks through all of this on a small sample database, with real output, in about twenty minutes.
|
|
208
|
+
|
|
209
|
+
## Command line
|
|
210
|
+
|
|
211
|
+
| Command | Does |
|
|
212
|
+
| --- | --- |
|
|
213
|
+
| `modelcall check` | Semantic data quality report for a schema |
|
|
214
|
+
| `modelcall annotate` | The agent proposes definitions for a schema |
|
|
215
|
+
| `modelcall classify` | Labels every row of a table into a column |
|
|
216
|
+
| `modelcall evaluate` | Accuracy, precision, cost and latency per model |
|
|
217
|
+
| `modelcall models` | Sets the default model and the low, medium and high tiers; shows the routes |
|
|
218
|
+
| `modelcall review` | Reviews proposals in the terminal |
|
|
219
|
+
| `modelcall export` | Definitions, rules and proposals as SQL, dbt or JSON |
|
|
220
|
+
| `modelcall mcp` | MCP server (stdio) for coding and analytics agents |
|
|
221
|
+
| `modelcall run` | Runs SQL, then processes every queue to completion |
|
|
222
|
+
| `modelcall serve`, `modelcall worker` | The engine and the worker |
|
|
223
|
+
| `modelcall migrate`, `modelcall doctor` | Installs or upgrades the schema; checks a database |
|
|
224
|
+
|
|
225
|
+
Commands take the database as an optional first argument or read `MODELCALL_DATABASE_URL`. Every command and option is in the [reference](https://github.com/tconwell/modelcall/blob/main/docs/reference.md#command-line).
|
|
226
|
+
|
|
227
|
+
## Documentation
|
|
228
|
+
|
|
229
|
+
- [Tutorial](https://github.com/tconwell/modelcall/blob/main/docs/tutorial.md): enrich a small shop database, step by step, with real output.
|
|
230
|
+
- [Guide](https://github.com/tconwell/modelcall/blob/main/docs/guide.md): every capability, from AI functions in SQL to entity resolution, plus running in production.
|
|
231
|
+
- [Reference](https://github.com/tconwell/modelcall/blob/main/docs/reference.md): every SQL function, view, command, setting and role.
|
|
232
|
+
- [Managed PostgreSQL](https://github.com/tconwell/modelcall/blob/main/docs/install-managed.md): installing on RDS, Aurora, Cloud SQL and Azure without extensions or a superuser.
|
|
233
|
+
- [How it compares](https://github.com/tconwell/modelcall/blob/main/docs/comparison.md): the AI functions of Snowflake, Databricks, BigQuery, Azure, AlloyDB and Aurora beside modelcall's.
|
|
234
|
+
- [Threat model](https://github.com/tconwell/modelcall/blob/main/docs/threat-model.md): what a model can see, and how untrusted text in your data is handled.
|
|
235
|
+
- [Case study](https://github.com/tconwell/modelcall/blob/main/docs/case-study-findata.md): modelcall on 8.5 million rows of public market data, with every figure and the query behind it.
|
|
236
|
+
- [Agent-accuracy benchmark](https://github.com/tconwell/modelcall/blob/main/docs/agent-accuracy-findata.md): does an agent answer more questions right with modelcall's labels and definitions?
|
|
237
|
+
- [demo_db/](https://github.com/tconwell/modelcall/tree/main/demo_db): sample data with runnable queries and walkthroughs for every feature.
|
|
238
|
+
|
|
239
|
+
## Status
|
|
240
|
+
|
|
241
|
+
modelcall is young: version 0.1. Everything described here is built and covered by tests that run against a real PostgreSQL (15 to 18 in CI) with a deterministic fake model provider. The tutorial, case study and benchmark were run with OpenAI models. Calls through the other providers, installation on actual managed services, and the Docker images are implemented but not yet verified end to end; [design-v1.md](https://github.com/tconwell/modelcall/blob/main/docs/design-v1.md#implementation-status) tracks what is.
|
|
242
|
+
|
|
243
|
+
Issues and pull requests are welcome.
|
|
244
|
+
|
|
245
|
+
## Development
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
git clone https://github.com/tconwell/modelcall && cd modelcall
|
|
249
|
+
pip install -e ".[dev]"
|
|
250
|
+
MODELCALL_TEST_ADMIN_URL=postgresql://postgres@localhost:5432/postgres pytest
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
The tests need a PostgreSQL superuser connection with `plpython3u` available, and no API keys. Each run creates and drops its own database. CI ([.github/workflows/test.yml](https://github.com/tconwell/modelcall/blob/main/.github/workflows/test.yml)) runs the suite on PostgreSQL 15, 16, 17 and 18 with Python 3.12 and 3.13, builds the wheel, and builds the Docker images. Pushing a tag such as `v0.1.0` runs the same checks and then publishes that version to PyPI ([release.yml](https://github.com/tconwell/modelcall/blob/main/.github/workflows/release.yml)).
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
[Apache-2.0](https://github.com/tconwell/modelcall/blob/main/LICENSE).
|