byllm 0.4.1__py2.py3-none-any.whl → 0.4.2__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of byllm might be problematic. Click here for more details.

byllm/schema.py CHANGED
@@ -6,7 +6,7 @@ and to validate instances against these schemas.
6
6
 
7
7
  from dataclasses import is_dataclass
8
8
  from enum import Enum
9
- from types import FunctionType, UnionType
9
+ from types import FunctionType, MethodType, UnionType
10
10
  from typing import Callable, Union, get_args, get_origin, get_type_hints
11
11
 
12
12
  from pydantic import TypeAdapter
@@ -129,7 +129,7 @@ def _type_to_schema(ty: type, title: str = "", desc: str = "") -> dict:
129
129
  }
130
130
 
131
131
  # Handle functions
132
- if isinstance(ty, FunctionType):
132
+ if isinstance(ty, (FunctionType, MethodType)):
133
133
  hints = get_type_hints(ty)
134
134
  hints.pop("return", None)
135
135
  params = {
byllm/types.py CHANGED
@@ -8,6 +8,7 @@ tool calls, and tools that can be used in LLM requests and responses.
8
8
  import base64
9
9
  import mimetypes
10
10
  import os
11
+ from contextlib import suppress
11
12
  from dataclasses import dataclass
12
13
  from enum import StrEnum
13
14
  from io import BytesIO
@@ -90,14 +91,15 @@ class Tool:
90
91
 
91
92
  def __post_init__(self) -> None:
92
93
  """Post-initialization to validate the function."""
93
- self.func.__annotations__ = get_type_hints(self.func)
94
+ annotations = get_type_hints(self.func)
95
+ with suppress(Exception):
96
+ self.func.__annotations__ = annotations
97
+
94
98
  self.description = Tool.get_func_description(self.func)
95
99
  if hasattr(self.func, "_jac_semstr_inner"):
96
100
  self.params_desc = self.func._jac_semstr_inner # type: ignore
97
101
  else:
98
- self.params_desc = {
99
- name: str(type) for name, type in self.func.__annotations__.items()
100
- }
102
+ self.params_desc = {name: str(type) for name, type in annotations.items()}
101
103
 
102
104
  def __call__(self, *args: list, **kwargs: dict) -> object:
103
105
  """Call the tool function with the provided arguments."""
@@ -152,7 +154,13 @@ class Tool:
152
154
  def parse_arguments(self, args_json: dict) -> dict:
153
155
  """Parse the arguments from JSON to the function's expected format."""
154
156
  args = {}
155
- annotations = self.func.__annotations__
157
+
158
+ annotations: dict = {}
159
+ try:
160
+ annotations = self.func.__annotations__
161
+ except AttributeError:
162
+ annotations = get_type_hints(self.func)
163
+
156
164
  for arg_name, arg_json in args_json.items():
157
165
  if arg_type := annotations.get(arg_name):
158
166
  args[arg_name] = TypeAdapter(arg_type).validate_python(arg_json)
@@ -0,0 +1,188 @@
1
+ Metadata-Version: 2.4
2
+ Name: byllm
3
+ Version: 0.4.2
4
+ Summary: byLLM Provides Easy to use APIs for different LLM Providers to be used with Jaseci's Jaclang Programming Language.
5
+ License: MIT
6
+ Keywords: llm,jaclang,jaseci,byLLM
7
+ Author: Jason Mars
8
+ Author-email: jason@jaseci.org
9
+ Maintainer: Jason Mars
10
+ Maintainer-email: jason@jaseci.org
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 2
13
+ Classifier: Programming Language :: Python :: 2.7
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.4
16
+ Classifier: Programming Language :: Python :: 3.5
17
+ Classifier: Programming Language :: Python :: 3.6
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Programming Language :: Python :: 3.14
26
+ Provides-Extra: tools
27
+ Provides-Extra: video
28
+ Requires-Dist: jaclang (>=0.8.7)
29
+ Requires-Dist: litellm (>=1.75.5.post1)
30
+ Requires-Dist: loguru (>=0.7.2,<0.8.0)
31
+ Requires-Dist: pillow (>=10.4.0,<10.5.0)
32
+ Description-Content-Type: text/markdown
33
+
34
+ <div align="center">
35
+ <img src="../docs/docs/assets/byLLM_name_logo.png" height="150">
36
+
37
+ [About byLLM] | [Get started] | [Usage docs] | [Research Paper]
38
+ </div>
39
+
40
+ [About byLLM]: https://www.jac-lang.org/learn/jac-byllm/with_llm/
41
+ [Get started]: https://www.jac-lang.org/learn/jac-byllm/quickstart/
42
+ [Usage docs]: https://www.jac-lang.org/learn/jac-byllm/usage/
43
+ [Research Paper]: https://arxiv.org/abs/2405.08965
44
+
45
+ # byLLM : Language Abstrations for AI-Integrated Programming.
46
+ > Prompt No More!
47
+
48
+ [![PyPI version](https://img.shields.io/pypi/v/byllm.svg)](https://pypi.org/project/byllm/) [![tests](https://github.com/jaseci-labs/jaseci/actions/workflows/test-jaseci.yml/badge.svg?branch=main)](https://github.com/jaseci-labs/jaseci/actions/workflows/test-jaseci.yml)
49
+
50
+ byLLM is an innovative AI integration framework built for the Jaseci ecosystem, implementing the cutting-edge Meaning Typed Programming (MTP) paradigm. MTP revolutionizes AI integration by embedding prompt engineering directly into code semantics, making AI interactions more natural and maintainable. While primarily designed to complement the Jac programming language, byLLM also provides a powerful Python library interface.
51
+
52
+ Installation is simple via PyPI:
53
+
54
+ ```bash
55
+ pip install byllm
56
+ ```
57
+
58
+ ## Basic Example
59
+
60
+ Consider building an application that translates english to other languages using an LLM. This can be simply built as follows:
61
+
62
+ ```python
63
+ import from byllm { Model }
64
+
65
+ glob llm = Model(model_name="gpt-4o");
66
+
67
+ def translate_to(language: str, phrase: str) -> str by llm();
68
+
69
+ with entry {
70
+ output = translate_to(language="Welsh", phrase="Hello world");
71
+ print(output);
72
+ }
73
+ ```
74
+
75
+ This simple piece of code replaces traditional prompt engineering without introducing additional complexity.
76
+
77
+ ## Power Types with LLMs
78
+
79
+ Consider a program that detects the personality type of a historical figure from their name. This can eb built in a way that LLM picks from an enum and the output strictly adhere this type.
80
+
81
+ ```python
82
+ import from byllm { Model }
83
+ glob llm = Model(model_name="gemini/gemini-2.0-flash");
84
+
85
+ enum Personality {
86
+ INTROVERT, EXTROVERT, AMBIVERT
87
+ }
88
+
89
+ def get_personality(name: str) -> Personality by llm();
90
+
91
+ with entry {
92
+ name = "Albert Einstein";
93
+ result = get_personality(name);
94
+ print(f"{result} personality detected for {name}");
95
+ }
96
+ ```
97
+
98
+ > Similarly, custom types can be used as output types which force the LLM to adhere to the specified type and produce a valid result.
99
+
100
+ ## Control! Control! Control!
101
+
102
+ Even if we are elimination prompt engineering entierly, we allow specific ways to enrich code semantics through **docstrings** and **semstrings**.
103
+
104
+ ```python
105
+ """Represents the personal record of a person"""
106
+ obj Person {
107
+ has name;
108
+ has dob;
109
+ has ssn;
110
+ }
111
+
112
+ sem Person.name = "Full name of the person";
113
+ sem Person.dob = "Date of Birth";
114
+ sem Person.ssn = "Last four digits of the Social Security Number of a person";
115
+
116
+ """Calculate eligibility for various services based on person's data."""
117
+ def check_eligibility(person: Person, service_type: str) -> bool by llm();
118
+
119
+ ```
120
+
121
+ Docstrings naturally enhance the semantics of their associated code constructs, while the `sem` keyword provides an elegant way to enrich the meaning of class attributes and function arguments. Our research shows these concise semantic strings are more effective than traditional multi-line prompts.
122
+
123
+ ## How well does byLLM work?
124
+
125
+ byLLM is built using the underline priciple of Meaning Typed Programming and we shown our evaluation data compared with two such AI integration frameworks for python, such as DSPy and LMQL. We show significant performance gain against LMQL while allowing on par or better performance to DSPy, while having a lower cost and faster runtime.
126
+
127
+ <div align="center">
128
+ <img src="../docs/docs/assets/correctness_comparison.png" alt="Correctness Comparison" width="600" style="max-width: 100%;">
129
+ <br>
130
+ <em>Figure: Correctness comparison of byLLM with DSPy and LMQL on benchmark tasks.</em>
131
+ </div>
132
+
133
+ **📚 Full Documentation**: [Jac byLLM Documentation](https://www.jac-lang.org/learn/jac-byllm/with_llm/)
134
+
135
+ **🎮 Complete Examples**:
136
+ - [Fantasy Trading Game](https://www.jac-lang.org/learn/examples/mtp_examples/fantasy_trading_game/) - Interactive RPG with AI-generated characters
137
+ - [RPG Level Generator](https://www.jac-lang.org/learn/examples/mtp_examples/rpg_game/) - AI-powered game level creation
138
+ - [RAG Chatbot Tutorial](https://www.jac-lang.org/learn/examples/rag_chatbot/Overview/) - Building chatbots with document retrieval
139
+
140
+ **🔬 Research**: The research journey of MTP is available on [Arxiv](https://arxiv.org/abs/2405.08965) and accepted for OOPSLA 2025.
141
+
142
+ ## Quick Links
143
+
144
+ - [Getting Started Guide](https://www.jac-lang.org/learn/jac-byllm/quickstart/)
145
+ - [Jac Language Documentation](https://www.jac-lang.org/)
146
+ - [GitHub Repository](https://github.com/jaseci-labs/jaseci)
147
+
148
+ ## Contributing
149
+
150
+ We welcome contributions to byLLM! Whether you're fixing bugs, improving documentation, or adding new features, your help is appreciated.
151
+
152
+ Areas we actively seek contributions:
153
+ - 🐛 Bug fixes and improvements
154
+ - 📚 Documentation enhancements
155
+ - ✨ New examples and tutorials
156
+ - 🧪 Test cases and benchmarks
157
+
158
+ Please see our [Contributing Guide](https://www.jac-lang.org/internals/contrib/) for detailed instructions.
159
+
160
+ If you find a bug or have a feature request, please [open an issue](https://github.com/jaseci-labs/jaseci/issues/new/choose).
161
+
162
+ ## Community
163
+
164
+ Join our vibrant community:
165
+ - [Discord Server](https://discord.gg/6j3QNdtcN6) - Chat with the team and community
166
+
167
+ ## License
168
+
169
+ This project is licensed under the MIT License.
170
+
171
+ ### Third-Party Dependencies
172
+
173
+ byLLM integrates with various LLM providers (OpenAI, Anthropic, Google, etc.) through LiteLLM.
174
+
175
+ ## Cite our research
176
+
177
+
178
+ > Jayanaka L. Dantanarayana, Yiping Kang, Kugesan Sivasothynathan, Christopher Clarke, Baichuan Li, Savini
179
+ Kashmira, Krisztian Flautner, Lingjia Tang, and Jason Mars. 2025. MTP: A Meaning-Typed Language Ab-
180
+ straction for AI-Integrated Programming. Proc. ACM Program. Lang. 9, OOPSLA2, Article 314 (October 2025),
181
+ 29 pages. https://doi.org/10.1145/3763092
182
+
183
+
184
+ ## Jaseci Contributors
185
+
186
+ <a href="https://github.com/jaseci-labs/jaseci/graphs/contributors">
187
+ <img src="https://contrib.rocks/image?repo=jaseci-labs/jaseci" />
188
+ </a>
@@ -0,0 +1,11 @@
1
+ byllm/__init__.py,sha256=Iqi_KAnRkr5vC9OYMWa9e5vZE3PiR2ror_Th1wa8F9Q,226
2
+ byllm/llm.py,sha256=fjraqQaT1uiwxTjLW7Wm8TDnnl7N5xDztA2KhyUfIQE,3560
3
+ byllm/llm_connector.py,sha256=XK8ftsafTYWq7aAjDxk4R4OeyJ1P1ou2qrZAXOU9xmU,8546
4
+ byllm/mtir.py,sha256=V4fpc0-j_7pb8rVMV8yskc9XczUCtHczrj5OZGXKA8g,7083
5
+ byllm/plugin.py,sha256=T_uSAkiyuPiufo5SEUNcgMOU0Ns5Zbg7BPfMo_ihC9s,1132
6
+ byllm/schema.py,sha256=q5Tnfv9sNDxkiK9579MJ4SXgtXzirIbsJYCzZ5mstUM,8838
7
+ byllm/types.py,sha256=rS_ISxYeHmXQiP1rv9qMKDiojdwk_x7bckOhn8_DFJk,11311
8
+ byllm-0.4.2.dist-info/METADATA,sha256=edJ9DvRcQzm01stAEFNzkJoFPJkp1qTXbH0OMKon8Ps,7639
9
+ byllm-0.4.2.dist-info/WHEEL,sha256=hHsm7XBrBXzBRNffhH1pmcsQOxyb5EETurgI-_j97X0,92
10
+ byllm-0.4.2.dist-info/entry_points.txt,sha256=hUzQdaP8qTKkAqHfBpcqxQK02wixeyyzx3y-s6KyrQg,37
11
+ byllm-0.4.2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.3
2
+ Generator: poetry-core 2.2.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2.py3-none-any
@@ -1,102 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: byllm
3
- Version: 0.4.1
4
- Summary: byLLM Provides Easy to use APIs for different LLM Providers to be used with Jaseci's Jaclang Programming Language.
5
- License: MIT
6
- Keywords: llm,jaclang,jaseci,byLLM
7
- Author: Jason Mars
8
- Author-email: jason@jaseci.org
9
- Maintainer: Jason Mars
10
- Maintainer-email: jason@jaseci.org
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Programming Language :: Python :: 2
13
- Classifier: Programming Language :: Python :: 2.7
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.4
16
- Classifier: Programming Language :: Python :: 3.5
17
- Classifier: Programming Language :: Python :: 3.6
18
- Classifier: Programming Language :: Python :: 3.7
19
- Classifier: Programming Language :: Python :: 3.8
20
- Classifier: Programming Language :: Python :: 3.9
21
- Classifier: Programming Language :: Python :: 3.10
22
- Classifier: Programming Language :: Python :: 3.11
23
- Classifier: Programming Language :: Python :: 3.12
24
- Classifier: Programming Language :: Python :: 3.13
25
- Provides-Extra: tools
26
- Provides-Extra: video
27
- Requires-Dist: jaclang (==0.8.5)
28
- Requires-Dist: litellm (>=1.75.5.post1)
29
- Requires-Dist: loguru (>=0.7.2,<0.8.0)
30
- Requires-Dist: pillow (>=10.4.0,<10.5.0)
31
- Description-Content-Type: text/markdown
32
-
33
- # byLLM - AI Integration Framework for Jac-lang
34
-
35
- [![PyPI version](https://img.shields.io/pypi/v/mtllm.svg)](https://pypi.org/project/mtllm/) [![tests](https://github.com/jaseci-labs/jaseci/actions/workflows/test-jaseci.yml/badge.svg?branch=main)](https://github.com/jaseci-labs/jaseci/actions/workflows/test-jaseci.yml)
36
-
37
- Meaning Typed Programming (MTP) is a programming paradigm for AI integration where prompt engineering is hidden through code semantics. byLLM is the plugin built, exploring this hypothesis. byLLM is built as a plugin to the Jaseci ecosystem. This plugin can be installed as a PyPI package.
38
-
39
- ```bash
40
- pip install byllm
41
- ```
42
-
43
- ## Basic Example
44
-
45
- A basic usecase of MTP can be demonstrated as follows:
46
-
47
- ```python
48
- import from byllm {Model}
49
-
50
- glob llm = Model(model_name="openai\gpt-4o");
51
-
52
- def translate_to(language: str, phrase: str) -> str by llm();
53
-
54
- with entry {
55
- output = translate_to(language="Welsh", phrase="Hello world");
56
- print(output);
57
- }
58
- ```
59
-
60
- ## AI-Powered Object Generation
61
-
62
- ```python
63
- import from byllm {Model}
64
-
65
- glob llm = Model(model_name="gpt-4o");
66
-
67
- obj Task {
68
- has description: str,
69
- priority: int,
70
- estimated_time: int;
71
- }
72
-
73
- sem Task.priority = "priority between 0 (highest priority) and 10(lowest priority)";
74
-
75
- def create_task(description: str, previous_tasks: list[Task]) -> Task by llm();
76
-
77
- with entry {
78
- tasks = [];
79
- new_task = create_task("Write documentation for the API", tasks);
80
- print(f"Task: {new_task.description}, Priority: {new_task.priority}, Time: {new_task.estimated_time}min");
81
- }
82
- ```
83
-
84
- The `by` abstraction allows to automate semantic extraction from existing code semantics, eliminating manual prompt engineering while leveraging type annotations for structured AI responses.
85
-
86
- ## Documentation and Examples
87
-
88
- **📚 Full Documentation**: [Jac byLLM Documentation](https://www.jac-lang.org/learn/jac-byllm/with_llm/)
89
-
90
- **🎮 Complete Examples**:
91
- - [Fantasy Trading Game](https://www.jac-lang.org/learn/examples/mtp_examples/fantasy_trading_game/) - Interactive RPG with AI-generated characters
92
- - [RPG Level Generator](https://www.jac-lang.org/learn/examples/mtp_examples/rpg_game/) - AI-powered game level creation
93
- - [RAG Chatbot Tutorial](https://www.jac-lang.org/learn/examples/rag_chatbot/Overview/) - Building chatbots with document retrieval
94
-
95
- **🔬 Research**: The research journey of MTP is available on [Arxiv](https://arxiv.org/abs/2405.08965).
96
-
97
- ## Quick Links
98
-
99
- - [Getting Started Guide](https://www.jac-lang.org/learn/jac-byllm/with_llm/)
100
- - [Model Configuration](https://www.jac-lang.org/learn/jac-byllm/model_declaration/)
101
- - [Jac Language Documentation](https://www.jac-lang.org/)
102
- - [GitHub Repository](https://github.com/jaseci-labs/jaseci)
@@ -1,11 +0,0 @@
1
- byllm/__init__.py,sha256=Iqi_KAnRkr5vC9OYMWa9e5vZE3PiR2ror_Th1wa8F9Q,226
2
- byllm/llm.py,sha256=fjraqQaT1uiwxTjLW7Wm8TDnnl7N5xDztA2KhyUfIQE,3560
3
- byllm/llm_connector.py,sha256=XK8ftsafTYWq7aAjDxk4R4OeyJ1P1ou2qrZAXOU9xmU,8546
4
- byllm/mtir.py,sha256=V4fpc0-j_7pb8rVMV8yskc9XczUCtHczrj5OZGXKA8g,7083
5
- byllm/plugin.py,sha256=T_uSAkiyuPiufo5SEUNcgMOU0Ns5Zbg7BPfMo_ihC9s,1132
6
- byllm/schema.py,sha256=PGaEiNlbm9CjIJu1lE2kv8QrfudfD2I3LvHfkMqxQkI,8812
7
- byllm/types.py,sha256=Uh6j0AcdHZ0zZ_KESu-ZBBpI9yoA7kw4yU550N4E-Tk,11117
8
- byllm-0.4.1.dist-info/METADATA,sha256=RQYnecvetizswVO-4TmSJ6r3G4aFrgkK99rjnK_isw0,3990
9
- byllm-0.4.1.dist-info/WHEEL,sha256=5druYqcII7zHXzX7qmN0TH895Jg3yuTtfjMgJIVBrKE,92
10
- byllm-0.4.1.dist-info/entry_points.txt,sha256=hUzQdaP8qTKkAqHfBpcqxQK02wixeyyzx3y-s6KyrQg,37
11
- byllm-0.4.1.dist-info/RECORD,,