A tool to link the code with large language models.
Project description
CodeLinker : Link your code with Language Models
CodeLinker aims to provide functions to link your code with language models. It builds on top of the Pydatic library and Tool Calling abilities introduced by OpenAI, which enabling models to generate content according to Json Schema.
Usage
The core concept of this package is to treat language models as a function handler. By defining a schema for return value of the function, we can call the function and let the model generate the return value.
To start with, we need to first define the configuration that will be used during exection:
config = CodeLinkerConfig(api_keys={
"gpt-3.5-turbo-16k":[{
"api_key": "your api key here",
"model": "model name alias here"
}]
})
cl = CodeLinker(config)
Learn more about the configuration in the Configuration page.
Structured Generation
Currently, the package support two types of structured generation with language models: Function Definition
and Return Declearation
.
Function Definition
You can define the schema of the return value with pydantic package:
class HelloWorldSchema(BaseModel):
message: str = Field(description="the message to be returned")
Then we can use the cl
object to wrap the function you want to call:
@cl.smartFunc()
def hello_world() -> HelloWorldSchema:
"""Say hello to the world"""
The function's docstring will be passed to models as instruction about what this function should do. Now we can call the function and let the model generate the return value:
result = hello_world()
print(result.message)
# sample output:
# Hello, World!
Return Declearation
Other wise, if you do not want to define the function, you can use the exec
method to call the function:
result = await cl.exec(return_type=HelloWorldSchema)
To be noticed, the exec
method is an async method, so you need to use await
to call it.
More details about structured generation can be found in the Structured Generation page.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file codelinker-0.3.27.tar.gz
.
File metadata
- Download URL: codelinker-0.3.27.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: poetry/1.8.4 CPython/3.10.14 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f94d03ddf52474ce5ed1bbb9fc963ed54ab132bdb736fb245c1fdb91aeea5840 |
|
MD5 | a7148580de0e7000e35db48ee5e0750e |
|
BLAKE2b-256 | 5b7dd9f7e011efe5ea35fcc0c1840bfcee429402c0a5bf42109ade1575312b6f |
File details
Details for the file codelinker-0.3.27-py3-none-any.whl
.
File metadata
- Download URL: codelinker-0.3.27-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: poetry/1.8.4 CPython/3.10.14 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0d5d12a9fff288ac35ae5c047f808be7e1f27284f0821cd55c36899badf51bb |
|
MD5 | d0b6c8e5b52bea56715432d9bcbc93a5 |
|
BLAKE2b-256 | d6abb372b1bacf966291a3a248baebf35f2ebec9066e14d1a5e6e38e49592467 |