Skip to main content

A simple prompt tuning library for LLMs

Project description

TinyTune

TinyTune is a lightweight library designed for prompt tuning, enabling the use of Python functions as prompt sequences within an LLM-agnostic pipeline.

Prompt Jobs

Prompt jobs are functions designed to execute user-defined prompts on the specified LLM (Language Model) and enable performing logic on the results. This functionality is crucial for orchestrating complex interactions with the language model, such as querying information or generating responses based on input prompts. By defining prompt jobs, users can encapsulate specific tasks or actions within their pipeline, facilitating modular and organized development of prompt-based workflows.

Defining Prompt Jobs

Define prompt jobs using the @prompt_job decorator.

llmContext = LLMContext() 

@prompt_job(id="search", context=llmContext)
def Job(id: str, context: LLMContext, prevResult: Any):
    (context.Prompt(Message("user", "Do XYZ"))
            .Run(stream=True))
    return context.Messages[-1]

Pipelines

A pipeline is a managed container that maintains a queue of prompt jobs and runs them in a loop, one after another. The results of the current job are passed down to the next one in the queue, facilitating the sequential execution of tasks within the pipeline.

Defining Pipeline

Create a pipeline and add prompt jobs to it.

pipeline: Pipeline = Pipeline(context)
(pipeline.AddJob(Job)
        .AddJob(Job1))  # Job, and Job1 are prompt jobs, add more jobs if necessary

Example

This example demonstrates the usage of the TinyTune library to orchestrate interactions with language models. It sets up two prompt jobs: one for searching for Japanese restaurants in Vancouver using a PerplexityContext, and another for extracting data into JSON format using a GPTContext. These prompt jobs are then added to a pipeline, which executes them sequentially. The program showcases how to define prompt jobs, configure contexts, create pipelines, and run them to perform specific tasks such as searching for information and extracting data.

# Initializing contexts
context = GPTContext("gpt-4-0125-preview", str(os.getenv("OPENAI_KEY")))
pContext = PerplexityContext("pplx-70b-online", os.getenv("PERPLEXITY_KEY"))

# Callback function
def Callback(content):
    if (content != None):
        print(content, end="")
    else:   
        print()

context.OnGenerateCallback = Callback
pContext.OnGenerateCallback = Callback

# Define prompt job for searching
@prompt_job(id="search", context=pContext)
def Job(id: str, context: PerplexityContext, prevResult: Any):
    (context.Prompt(PerplexityMessage("user", "Find me Japanese restaurants in Vancouver"))
            .Run(stream=True))

    return context.Messages[-1]

# Define prompt job for extracting JSON
@prompt_job("extract json", context)
def Job1(id: str, context: GPTContext, prevResult: Any):
    print("prevResult: ", prevResult.ToDict())
    (context.Prompt(GPTMessage("user", f"""{prevResult.Content} extract this data into JSON, and only return the JSON, no formatting, backticks, or explanation"""))
            .Run(stream=True)) 

# Create pipeline
pipeline: Pipeline = Pipeline(context)

# Add prompt jobs to the pipeline
(pipeline.AddJob(Job)
        .AddJob(Job1))

# Run the pipeline
pipeline.Run()

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

tinytune-0.0.7.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinytune-0.0.7-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file tinytune-0.0.7.tar.gz.

File metadata

  • Download URL: tinytune-0.0.7.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.6

File hashes

Hashes for tinytune-0.0.7.tar.gz
Algorithm Hash digest
SHA256 c0005ed420812e444c9606da60e5d148532b5753c5a206a59580ba2e3f75793b
MD5 18637698f10aeb094e725e4d094ecb8e
BLAKE2b-256 e54a10419ff66e80fecb33e6cba737e33e97b3fddadb333c8205abf88e1463e0

See more details on using hashes here.

File details

Details for the file tinytune-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: tinytune-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.6

File hashes

Hashes for tinytune-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a344fe88858f4d17e637d9d112714da8e8321064f6c11b36db381e07ca13c0e8
MD5 6a95ddd8ad665743ab5da2c7e1e6c7bc
BLAKE2b-256 a36211f83f408853ade82f645daf1fe362df792ae6c195894145253b3eaa64a7

See more details on using hashes here.

Supported by

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