mellea 0.0.1__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.
- mellea-0.0.1/LICENSE +203 -0
- mellea-0.0.1/PKG-INFO +242 -0
- mellea-0.0.1/README.md +197 -0
- mellea-0.0.1/cli/__init__.py +1 -0
- mellea-0.0.1/cli/alora/__init__.py +2 -0
- mellea-0.0.1/cli/alora/commands.py +50 -0
- mellea-0.0.1/cli/alora/train.py +173 -0
- mellea-0.0.1/cli/alora/upload.py +46 -0
- mellea-0.0.1/cli/decomp/__init__.py +2 -0
- mellea-0.0.1/cli/decomp/prompts/__init__.py +1 -0
- mellea-0.0.1/cli/decomp/prompts/metaprompts/README.md +1 -0
- mellea-0.0.1/cli/decomp/prompts/metaprompts/__init__.py +12 -0
- mellea-0.0.1/cli/decomp/prompts/metaprompts/metaprompt_get_input_data.py +65 -0
- mellea-0.0.1/cli/decomp/prompts/metaprompts/metaprompt_subtask_gen.py +135 -0
- mellea-0.0.1/cli/decomp/prompts/metaprompts/metaprompt_subtask_list_tags.py +101 -0
- mellea-0.0.1/cli/decomp/run.py +168 -0
- mellea-0.0.1/cli/decomp/task_compiler.py +60 -0
- mellea-0.0.1/cli/decomp/task_decomposer.py +195 -0
- mellea-0.0.1/cli/decomp/task_executor.py +56 -0
- mellea-0.0.1/cli/decomp/utils.py +141 -0
- mellea-0.0.1/cli/m.py +27 -0
- mellea-0.0.1/cli/serve/app.py +85 -0
- mellea-0.0.1/cli/serve/models.py +103 -0
- mellea-0.0.1/mellea/__init__.py +15 -0
- mellea-0.0.1/mellea/backends/__init__.py +75 -0
- mellea-0.0.1/mellea/backends/aloras/__init__.py +57 -0
- mellea-0.0.1/mellea/backends/aloras/huggingface/__init__.py +1 -0
- mellea-0.0.1/mellea/backends/aloras/huggingface/granite_aloras.py +210 -0
- mellea-0.0.1/mellea/backends/aloras/openai/__init__.py +1 -0
- mellea-0.0.1/mellea/backends/aloras/openai/granite_aloras.py +86 -0
- mellea-0.0.1/mellea/backends/cache.py +63 -0
- mellea-0.0.1/mellea/backends/dummy.py +40 -0
- mellea-0.0.1/mellea/backends/formatter.py +453 -0
- mellea-0.0.1/mellea/backends/huggingface.py +683 -0
- mellea-0.0.1/mellea/backends/model_ids.py +162 -0
- mellea-0.0.1/mellea/backends/ollama.py +467 -0
- mellea-0.0.1/mellea/backends/openai.py +674 -0
- mellea-0.0.1/mellea/backends/tools.py +106 -0
- mellea-0.0.1/mellea/backends/types.py +100 -0
- mellea-0.0.1/mellea/backends/watsonx.py +405 -0
- mellea-0.0.1/mellea/helpers/__init__.py +1 -0
- mellea-0.0.1/mellea/helpers/fancy_logger.py +126 -0
- mellea-0.0.1/mellea/stdlib/__init__.py +1 -0
- mellea-0.0.1/mellea/stdlib/base.py +464 -0
- mellea-0.0.1/mellea/stdlib/chat.py +120 -0
- mellea-0.0.1/mellea/stdlib/docs/__init__.py +1 -0
- mellea-0.0.1/mellea/stdlib/docs/richdocument.py +177 -0
- mellea-0.0.1/mellea/stdlib/genslot.py +304 -0
- mellea-0.0.1/mellea/stdlib/instruction.py +149 -0
- mellea-0.0.1/mellea/stdlib/mify.py +409 -0
- mellea-0.0.1/mellea/stdlib/mobject.py +222 -0
- mellea-0.0.1/mellea/stdlib/reqlib/md.py +60 -0
- mellea-0.0.1/mellea/stdlib/requirement.py +184 -0
- mellea-0.0.1/mellea/stdlib/safety/__init__.py +1 -0
- mellea-0.0.1/mellea/stdlib/safety/guardian.py +157 -0
- mellea-0.0.1/mellea/stdlib/sampling.py +203 -0
- mellea-0.0.1/mellea/stdlib/session.py +574 -0
- mellea-0.0.1/mellea/templates/prompts/default/ContentBlock.jinja2 +1 -0
- mellea-0.0.1/mellea/templates/prompts/default/GenerativeSlot.jinja2 +14 -0
- mellea-0.0.1/mellea/templates/prompts/default/Instruction.jinja2 +44 -0
- mellea-0.0.1/mellea/templates/prompts/default/LLMaJRequirement.jinja2 +15 -0
- mellea-0.0.1/mellea/templates/prompts/default/MObject.jinja2 +1 -0
- mellea-0.0.1/mellea/templates/prompts/default/Query.jinja2 +6 -0
- mellea-0.0.1/mellea/templates/prompts/default/Requirement.jinja2 +15 -0
- mellea-0.0.1/mellea/templates/prompts/default/Table.jinja2 +1 -0
- mellea-0.0.1/mellea/templates/prompts/default/TableQuery.jinja2 +6 -0
- mellea-0.0.1/mellea/templates/prompts/default/TableTransform.jinja2 +10 -0
- mellea-0.0.1/mellea/templates/prompts/default/Transform.jinja2 +6 -0
- mellea-0.0.1/mellea/templates/prompts/granite/Instruction.jinja2 +44 -0
- mellea-0.0.1/pyproject.toml +154 -0
mellea-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
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.
|
|
203
|
+
|
mellea-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mellea
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: mellea is a library for writing generative programs
|
|
5
|
+
Author-Email: Nathan Fulton <nathan@ibm.com>, Hendrik Strobelt <hendrik.strobelt@ibm.com>, Avinash Balakrishnan <avinash.bala@us.ibm.com>, Elron Bandel <elron.bandel@ibm.com>, Masataro Asai <masataro.asai@ibm.com>, Supriya Lall <supriya.lall@partner.ibm.com>, Xiaojie Guo <xiaojie.guo@ibm.com>, Jake LoRocco <jake.lorocco@ibm.com>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Requires-Dist: pydantic
|
|
11
|
+
Requires-Dist: outlines<1.0.0
|
|
12
|
+
Requires-Dist: openai
|
|
13
|
+
Requires-Dist: jinja2
|
|
14
|
+
Requires-Dist: transformers
|
|
15
|
+
Requires-Dist: torchvision
|
|
16
|
+
Requires-Dist: accelerate>=0.26.0
|
|
17
|
+
Requires-Dist: json5
|
|
18
|
+
Requires-Dist: docling==2.28.1
|
|
19
|
+
Requires-Dist: ollama>=0.5.1
|
|
20
|
+
Requires-Dist: alora==0.2.0
|
|
21
|
+
Requires-Dist: ansicolors
|
|
22
|
+
Requires-Dist: datasets
|
|
23
|
+
Requires-Dist: ibm-watsonx-ai
|
|
24
|
+
Requires-Dist: requests>=2.32.3
|
|
25
|
+
Requires-Dist: uvicorn
|
|
26
|
+
Requires-Dist: fastapi
|
|
27
|
+
Requires-Dist: types-requests
|
|
28
|
+
Requires-Dist: types-tqdm
|
|
29
|
+
Requires-Dist: typer
|
|
30
|
+
Requires-Dist: click<8.2.0
|
|
31
|
+
Requires-Dist: mistletoe>=1.4.0
|
|
32
|
+
Requires-Dist: trl==0.19.0
|
|
33
|
+
Requires-Dist: peft
|
|
34
|
+
Requires-Dist: torch
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: mypy; extra == "dev"
|
|
37
|
+
Requires-Dist: mypy-extensions; extra == "dev"
|
|
38
|
+
Requires-Dist: tomli; extra == "dev"
|
|
39
|
+
Requires-Dist: codespell; extra == "dev"
|
|
40
|
+
Provides-Extra: sphinx
|
|
41
|
+
Requires-Dist: sphinx_rtd_theme; extra == "sphinx"
|
|
42
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == "sphinx"
|
|
43
|
+
Requires-Dist: sphinx_mdinclude; extra == "sphinx"
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
<img src="docs/mellea_draft_logo_300.png" height=100>
|
|
47
|
+
|
|
48
|
+
# Mellea
|
|
49
|
+
|
|
50
|
+
Mellea is a library for writing generative programs.
|
|
51
|
+
Generative programming replaces flaky agents and brittle prompts
|
|
52
|
+
with structured, maintainable, robust, and efficient AI workflows.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
[//]: # ([](https://arxiv.org/abs/2408.09869))
|
|
56
|
+
[](https://docs.mellea.ai/)
|
|
57
|
+
[](https://pypi.org/project/mellea/)
|
|
58
|
+
[](https://pypi.org/project/mellea/)
|
|
59
|
+
[](https://github.com/astral-sh/uv)
|
|
60
|
+
[](https://github.com/astral-sh/ruff)
|
|
61
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
62
|
+

|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Features
|
|
66
|
+
|
|
67
|
+
* A standard library of opinionated prompting patterns.
|
|
68
|
+
* Sampling strategies for inference-time scaling.
|
|
69
|
+
* Clean integration between verifiers and samplers.
|
|
70
|
+
- Batteries-included library of verifiers.
|
|
71
|
+
- Support for efficient checking of specialized requirements using
|
|
72
|
+
activated LoRAs.
|
|
73
|
+
- Train your own verifiers on proprietary classifier data.
|
|
74
|
+
* Compatible with many inference services and model families. Control cost
|
|
75
|
+
and quality by easily lifting and shifting workloads between:
|
|
76
|
+
- inference providers
|
|
77
|
+
- model families
|
|
78
|
+
- model sizes
|
|
79
|
+
* Easily integrate the power of LLMs into legacy code-bases (mify).
|
|
80
|
+
* Sketch applications by writing specifications and letting `mellea` fill in
|
|
81
|
+
the details (generative slots).
|
|
82
|
+
* Get started by decomposing your large unwieldy prompts into structured and maintainable mellea problems.
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## Getting Started
|
|
87
|
+
|
|
88
|
+
You can get started with a local install, or by using Colab notebooks.
|
|
89
|
+
|
|
90
|
+
### Getting Started with Local Infernece
|
|
91
|
+
|
|
92
|
+
<img src="docs/GetStarted_py.png" style="max-width:800px">
|
|
93
|
+
|
|
94
|
+
Install with pip:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
uv pip install mellea
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
> [!NOTE]
|
|
101
|
+
> If running on an Intel mac, you may get errors related to torch/torchvision versions. Conda maintains updated versions of these packages. You will need to create a conda environment and run `conda install 'torchvision>=0.22.0'` (this should also install pytorch and torchvision-extra). Then, you should be able to run `uv pip install .`. To run the examples, you will need to use `python <filename>` inside the conda environment instead of `uv run --with mellea <filename>`.
|
|
102
|
+
|
|
103
|
+
> [!NOTE]
|
|
104
|
+
> If you are using python >= 3.13, you may encounter an issue where outlines cannot be installed due to rust compiler issues (`error: can't find Rust compiler`). You can either downgrade to python 3.12 or install the [rust compiler](https://www.rust-lang.org/tools/install) to build the wheel for outlines locally.
|
|
105
|
+
|
|
106
|
+
For running a simple LLM request locally (using Ollama with Granite model), this is the starting code:
|
|
107
|
+
```python
|
|
108
|
+
# file: https://github.com/generative-computing/mellea/blob/main/docs/examples/tutorial/example.py
|
|
109
|
+
import mellea
|
|
110
|
+
|
|
111
|
+
m = mellea.start_session()
|
|
112
|
+
print(m.chat("What is the etymology of mellea?").content)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
Then run it:
|
|
117
|
+
> NOTE: Before we get started, you will need to download and install [ollama](https://ollama.com/). Mellea can work with many different types of backends, but everything in this tutorial will "just work" on a Macbook running IBM's Granite 3.3 8B model.
|
|
118
|
+
```shell
|
|
119
|
+
uv run --with mellea docs/examples/tutorial/example.py
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Get Started with Colab
|
|
123
|
+
|
|
124
|
+
| Notebook | Try in Colab | Goal |
|
|
125
|
+
|----------|--------------|------|
|
|
126
|
+
| Hello, World | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/example.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Quick‑start demo |
|
|
127
|
+
| Simple Email | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/simple_email.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Using the `m.instruct` primitive |
|
|
128
|
+
| Instruct-Validate-Repair | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/instruct_validate_repair.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Introduces our first generative programming design pattern |
|
|
129
|
+
| Model Options | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notsbooks/model_options_example.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Demonstrates how to pass model options through to backends |
|
|
130
|
+
| Sentiment Classifier | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/sentiment_classifier.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Introduces the `@generative` decorator |
|
|
131
|
+
| Managing Context | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main//docs/examples/notebooks/context_example.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Shows how to construct and manage context in a `MelleaSession` |
|
|
132
|
+
| Generative OOP | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/table_mobject.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Demonstrates object-oriented generative programming in Mellea |
|
|
133
|
+
| Rich Documents | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/document_mobject.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | A generative program that uses Docling to work with rich-text documents |
|
|
134
|
+
| Composing Generative Functions | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/compositionality_with_generative_slots.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Demonstrates contract-oriented programming in Mellea |
|
|
135
|
+
| `m serve` | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/m_serve_example.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Serve a generative program as an openai-compatible model endpoint |
|
|
136
|
+
| MCP | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/mcp_example.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Mellea + MCP |
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
### Installing from source
|
|
140
|
+
|
|
141
|
+
Fork and clone the repositoy:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
git clone ssh://git@github.com/<my-username>/mellea.git && cd mellea/
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Setup a virtual environment:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
uv venv .venv && source .venv/bin/activate
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Use `uv pip` to install from source with the editable flag:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
uv pip install -e .
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Ensure that you install the precommit hooks:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
pre-commit install
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Getting started with validation
|
|
166
|
+
|
|
167
|
+
Mellea supports validation of generation results through a **instruct-validate-repair** pattern.
|
|
168
|
+
Below, the request for *"Write an email.."* is constrained by the requirements of *"be formal"* and *"Use 'Dear interns' as greeting."*.
|
|
169
|
+
Using a simple rejection sampling strategy, the request is sent up to three (loop_budget) times to the model and
|
|
170
|
+
the output is checked against the constraints using (in this case) LLM-as-a-judge.
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
# file: https://github.com/generative-computing/mellea/blob/main/docs/examples/instruct_validate_repair/101_email_with_validate.py
|
|
175
|
+
from mellea import MelleaSession
|
|
176
|
+
from mellea.backends.types import ModelOption
|
|
177
|
+
from mellea.backends.ollama import OllamaModelBackend
|
|
178
|
+
from mellea.backends import model_ids
|
|
179
|
+
from mellea.stdlib.sampling import RejectionSamplingStrategy
|
|
180
|
+
|
|
181
|
+
# create a session with Mistral running on Ollama
|
|
182
|
+
m = MelleaSession(
|
|
183
|
+
backend=OllamaModelBackend(
|
|
184
|
+
model_id=model_ids.MISTRALAI_MISTRAL_0_3_7B,
|
|
185
|
+
model_options={ModelOption.MAX_NEW_TOKENS: 300},
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
# run an instruction with requirements
|
|
190
|
+
email_v1 = m.instruct(
|
|
191
|
+
"Write an email to invite all interns to the office party.",
|
|
192
|
+
requirements=["be formal", "Use 'Dear interns' as greeting."],
|
|
193
|
+
strategy=RejectionSamplingStrategy(loop_budget=3),
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
# print result
|
|
197
|
+
print(f"***** email ****\n{str(email_v1)}\n*******")
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
## Getting Started with Generative Slots
|
|
202
|
+
|
|
203
|
+
Generative slots allow you to define functions without implementing them.
|
|
204
|
+
The `@generative` decorator marks a function as one that should be interpreted by querying an LLM.
|
|
205
|
+
The example below demonstrates how an LLM's sentiment classification
|
|
206
|
+
capability can be wrapped up as a function using Mellea's generative slots and
|
|
207
|
+
a local LLM.
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
# file: https://github.com/generative-computing/mellea/blob/main/docs/examples/tutorial/sentiment_classifier.py#L1-L13
|
|
212
|
+
from typing import Literal
|
|
213
|
+
from mellea import generative, start_session
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
@generative
|
|
217
|
+
def classify_sentiment(text: str) -> Literal["positive", "negative"]:
|
|
218
|
+
"""Classify the sentiment of the input text as 'positive' or 'negative'."""
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
if __name__ == "__main__":
|
|
222
|
+
m = start_session()
|
|
223
|
+
sentiment = classify_sentiment(m, text="I love this!")
|
|
224
|
+
print("Output sentiment is:", sentiment)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
## Tutorial
|
|
230
|
+
|
|
231
|
+
See the [tutorial](docs/tutorial.md)
|
|
232
|
+
|
|
233
|
+
## Contributing
|
|
234
|
+
|
|
235
|
+
Please refer to the [Contributor Guide](docs/tutorial.md#appendix-contributing-to-mellea) for detailed instructions on how to contribute.
|
|
236
|
+
|
|
237
|
+
### IBM ❤️ Open Source AI
|
|
238
|
+
|
|
239
|
+
Mellea has been started by IBM Research in Cambridge, MA.
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
mellea-0.0.1/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<img src="docs/mellea_draft_logo_300.png" height=100>
|
|
2
|
+
|
|
3
|
+
# Mellea
|
|
4
|
+
|
|
5
|
+
Mellea is a library for writing generative programs.
|
|
6
|
+
Generative programming replaces flaky agents and brittle prompts
|
|
7
|
+
with structured, maintainable, robust, and efficient AI workflows.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
[//]: # ([](https://arxiv.org/abs/2408.09869))
|
|
11
|
+
[](https://docs.mellea.ai/)
|
|
12
|
+
[](https://pypi.org/project/mellea/)
|
|
13
|
+
[](https://pypi.org/project/mellea/)
|
|
14
|
+
[](https://github.com/astral-sh/uv)
|
|
15
|
+
[](https://github.com/astral-sh/ruff)
|
|
16
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
* A standard library of opinionated prompting patterns.
|
|
23
|
+
* Sampling strategies for inference-time scaling.
|
|
24
|
+
* Clean integration between verifiers and samplers.
|
|
25
|
+
- Batteries-included library of verifiers.
|
|
26
|
+
- Support for efficient checking of specialized requirements using
|
|
27
|
+
activated LoRAs.
|
|
28
|
+
- Train your own verifiers on proprietary classifier data.
|
|
29
|
+
* Compatible with many inference services and model families. Control cost
|
|
30
|
+
and quality by easily lifting and shifting workloads between:
|
|
31
|
+
- inference providers
|
|
32
|
+
- model families
|
|
33
|
+
- model sizes
|
|
34
|
+
* Easily integrate the power of LLMs into legacy code-bases (mify).
|
|
35
|
+
* Sketch applications by writing specifications and letting `mellea` fill in
|
|
36
|
+
the details (generative slots).
|
|
37
|
+
* Get started by decomposing your large unwieldy prompts into structured and maintainable mellea problems.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Getting Started
|
|
42
|
+
|
|
43
|
+
You can get started with a local install, or by using Colab notebooks.
|
|
44
|
+
|
|
45
|
+
### Getting Started with Local Infernece
|
|
46
|
+
|
|
47
|
+
<img src="docs/GetStarted_py.png" style="max-width:800px">
|
|
48
|
+
|
|
49
|
+
Install with pip:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
uv pip install mellea
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
> [!NOTE]
|
|
56
|
+
> If running on an Intel mac, you may get errors related to torch/torchvision versions. Conda maintains updated versions of these packages. You will need to create a conda environment and run `conda install 'torchvision>=0.22.0'` (this should also install pytorch and torchvision-extra). Then, you should be able to run `uv pip install .`. To run the examples, you will need to use `python <filename>` inside the conda environment instead of `uv run --with mellea <filename>`.
|
|
57
|
+
|
|
58
|
+
> [!NOTE]
|
|
59
|
+
> If you are using python >= 3.13, you may encounter an issue where outlines cannot be installed due to rust compiler issues (`error: can't find Rust compiler`). You can either downgrade to python 3.12 or install the [rust compiler](https://www.rust-lang.org/tools/install) to build the wheel for outlines locally.
|
|
60
|
+
|
|
61
|
+
For running a simple LLM request locally (using Ollama with Granite model), this is the starting code:
|
|
62
|
+
```python
|
|
63
|
+
# file: https://github.com/generative-computing/mellea/blob/main/docs/examples/tutorial/example.py
|
|
64
|
+
import mellea
|
|
65
|
+
|
|
66
|
+
m = mellea.start_session()
|
|
67
|
+
print(m.chat("What is the etymology of mellea?").content)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Then run it:
|
|
72
|
+
> NOTE: Before we get started, you will need to download and install [ollama](https://ollama.com/). Mellea can work with many different types of backends, but everything in this tutorial will "just work" on a Macbook running IBM's Granite 3.3 8B model.
|
|
73
|
+
```shell
|
|
74
|
+
uv run --with mellea docs/examples/tutorial/example.py
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Get Started with Colab
|
|
78
|
+
|
|
79
|
+
| Notebook | Try in Colab | Goal |
|
|
80
|
+
|----------|--------------|------|
|
|
81
|
+
| Hello, World | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/example.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Quick‑start demo |
|
|
82
|
+
| Simple Email | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/simple_email.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Using the `m.instruct` primitive |
|
|
83
|
+
| Instruct-Validate-Repair | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/instruct_validate_repair.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Introduces our first generative programming design pattern |
|
|
84
|
+
| Model Options | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notsbooks/model_options_example.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Demonstrates how to pass model options through to backends |
|
|
85
|
+
| Sentiment Classifier | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/sentiment_classifier.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Introduces the `@generative` decorator |
|
|
86
|
+
| Managing Context | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main//docs/examples/notebooks/context_example.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Shows how to construct and manage context in a `MelleaSession` |
|
|
87
|
+
| Generative OOP | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/table_mobject.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Demonstrates object-oriented generative programming in Mellea |
|
|
88
|
+
| Rich Documents | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/document_mobject.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | A generative program that uses Docling to work with rich-text documents |
|
|
89
|
+
| Composing Generative Functions | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/compositionality_with_generative_slots.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Demonstrates contract-oriented programming in Mellea |
|
|
90
|
+
| `m serve` | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/m_serve_example.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Serve a generative program as an openai-compatible model endpoint |
|
|
91
|
+
| MCP | <a href="https://colab.research.google.com/github/generative-computing/mellea/blob/main/docs/examples/notebooks/mcp_example.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | Mellea + MCP |
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
### Installing from source
|
|
95
|
+
|
|
96
|
+
Fork and clone the repositoy:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
git clone ssh://git@github.com/<my-username>/mellea.git && cd mellea/
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Setup a virtual environment:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
uv venv .venv && source .venv/bin/activate
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Use `uv pip` to install from source with the editable flag:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
uv pip install -e .
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Ensure that you install the precommit hooks:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pre-commit install
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Getting started with validation
|
|
121
|
+
|
|
122
|
+
Mellea supports validation of generation results through a **instruct-validate-repair** pattern.
|
|
123
|
+
Below, the request for *"Write an email.."* is constrained by the requirements of *"be formal"* and *"Use 'Dear interns' as greeting."*.
|
|
124
|
+
Using a simple rejection sampling strategy, the request is sent up to three (loop_budget) times to the model and
|
|
125
|
+
the output is checked against the constraints using (in this case) LLM-as-a-judge.
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
# file: https://github.com/generative-computing/mellea/blob/main/docs/examples/instruct_validate_repair/101_email_with_validate.py
|
|
130
|
+
from mellea import MelleaSession
|
|
131
|
+
from mellea.backends.types import ModelOption
|
|
132
|
+
from mellea.backends.ollama import OllamaModelBackend
|
|
133
|
+
from mellea.backends import model_ids
|
|
134
|
+
from mellea.stdlib.sampling import RejectionSamplingStrategy
|
|
135
|
+
|
|
136
|
+
# create a session with Mistral running on Ollama
|
|
137
|
+
m = MelleaSession(
|
|
138
|
+
backend=OllamaModelBackend(
|
|
139
|
+
model_id=model_ids.MISTRALAI_MISTRAL_0_3_7B,
|
|
140
|
+
model_options={ModelOption.MAX_NEW_TOKENS: 300},
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
# run an instruction with requirements
|
|
145
|
+
email_v1 = m.instruct(
|
|
146
|
+
"Write an email to invite all interns to the office party.",
|
|
147
|
+
requirements=["be formal", "Use 'Dear interns' as greeting."],
|
|
148
|
+
strategy=RejectionSamplingStrategy(loop_budget=3),
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# print result
|
|
152
|
+
print(f"***** email ****\n{str(email_v1)}\n*******")
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
## Getting Started with Generative Slots
|
|
157
|
+
|
|
158
|
+
Generative slots allow you to define functions without implementing them.
|
|
159
|
+
The `@generative` decorator marks a function as one that should be interpreted by querying an LLM.
|
|
160
|
+
The example below demonstrates how an LLM's sentiment classification
|
|
161
|
+
capability can be wrapped up as a function using Mellea's generative slots and
|
|
162
|
+
a local LLM.
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
# file: https://github.com/generative-computing/mellea/blob/main/docs/examples/tutorial/sentiment_classifier.py#L1-L13
|
|
167
|
+
from typing import Literal
|
|
168
|
+
from mellea import generative, start_session
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@generative
|
|
172
|
+
def classify_sentiment(text: str) -> Literal["positive", "negative"]:
|
|
173
|
+
"""Classify the sentiment of the input text as 'positive' or 'negative'."""
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
if __name__ == "__main__":
|
|
177
|
+
m = start_session()
|
|
178
|
+
sentiment = classify_sentiment(m, text="I love this!")
|
|
179
|
+
print("Output sentiment is:", sentiment)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
## Tutorial
|
|
185
|
+
|
|
186
|
+
See the [tutorial](docs/tutorial.md)
|
|
187
|
+
|
|
188
|
+
## Contributing
|
|
189
|
+
|
|
190
|
+
Please refer to the [Contributor Guide](docs/tutorial.md#appendix-contributing-to-mellea) for detailed instructions on how to contribute.
|
|
191
|
+
|
|
192
|
+
### IBM ❤️ Open Source AI
|
|
193
|
+
|
|
194
|
+
Mellea has been started by IBM Research in Cambridge, MA.
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""cli for the M library."""
|