Skip to content

luyaxi/CodeLinker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

The we can define the schema of the return value:

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!

The function wrapped by cl.smartFunc will have extra key-world arguments that can be used to control the output of the model:

  • messages: a list of messages that will be inserted into the beginning of the prompt
  • images: a list of images that will be inserted into the end of the prompt, following openai's message image format
  • reply_format: a reply format is a instance of StructureSchema that helps the model to better understand the context of the conversation.

About

CodeLinker : Link your Code with Language Models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages