Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codelinker-0.3.25.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

codelinker-0.3.25-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file codelinker-0.3.25.tar.gz.

File metadata

  • Download URL: codelinker-0.3.25.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

Hashes for codelinker-0.3.25.tar.gz
Algorithm Hash digest
SHA256 c8ca4e102506b193fc10bb5c8420c91717ccd9d63b5c74bbbe2bd9e3d3eb0578
MD5 308351dcd7d3f773d8bec9672cd5971f
BLAKE2b-256 1c57d55e19de99e14f7949c8354f0c1b31771b25d2afc4e0e182f3beaa04abc7

See more details on using hashes here.

File details

Details for the file codelinker-0.3.25-py3-none-any.whl.

File metadata

  • Download URL: codelinker-0.3.25-py3-none-any.whl
  • Upload date:
  • Size: 21.9 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

Hashes for codelinker-0.3.25-py3-none-any.whl
Algorithm Hash digest
SHA256 bf727843bc0dd0b26609b3b7edaa8aa759f1e41a6089fdf6fb1a790ab37a3c74
MD5 0073105f612cfdffb61809476e67478e
BLAKE2b-256 38c13f268c506b3b6e4da18b95302b5df34e38f5cde983d2f7aa18cac4583fb0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page