byLLM as a Library for Python#
The byLLM module is a Jaclang plugin that provides AI functionality. Since Jaclang supersets Python, byLLM can be integrated into Python applications. This guide demonstrates how to use byLLM in Python.
byLLM is a Python package that needs to be installed using:
Importing byLLM in Python#
byLLM functionality is accessed by importing the byllm
module and using the by
decorator on functions.
NOTE:
Here byLLM can only use primitive types and dataclasses as input and output types. We are working to resolve this limitation.
Model Hyper-parameters#
In Jaclang, hyper-parameters are set by passing them to the LLM model:
The temperature
hyper-parameter controls the randomness of the output. Lower values produce more deterministic output, while higher values produce more random output.
In Python, hyper-parameters are passed as follows:
Using Python Functions as Tools#
Python functions can be used as tools in byLLM. Functions defined in Python are callable by the LLM to perform specific tasks:
Using Semstrings for Semantic Enrichment#
In Jac we introduced the sem
keyword as a means to attach additional semantics to code objects such as object attributes and function argument. The syntax in jac is as follows.
obj Person {
has name:str;
has age:int;
has ssn: int;
}
sem Person.ssn = "last four digits of the Social Security number"
Using sem
functionality in python is a bit diferent as the attachment is done using a @sem
decorator.
from jaclang import JacMachineInterface as Jac
from byllm.lib import Model, by
@Jac.sem('<Person Semstring>', {
'name' : '<name semstring>',
'age' : '<age semstring>',
'ssn' : "<ssn semstring>"
}
)
@datclass
class Person:
name: str
age: int
ssn: int
Note
The sem
implementation in Python is a work-in-progress. The Python way of adding semstrings may change in future releases of byLLM.