Skip to main content

Unit Tests

Kork alt The Parrot

Kork is an experimental Langchain chain that helps build natural language APIs powered by LLMs.

Features

  1. Assemble a natural language API from a set of python functions.
  2. Generate a prompt to help the LLM write a correct program.
  3. Execute the program generated by the LLM safely.
  4. Program generation takes a single LLM call, as opposed to agents that use a call per action taken.

Show me! 😹

Image manipulation API using PIL

Cats!!!

How

The chain takes a user query, translates it into a program, and executes it using the Kork interpreter.

The interpreter is used to run code written in the Kork programming language.

The language is limited by design to variable declarations, function invocations and arithmetic operations.

This limitation allows controlling the kind of programs the LLMs can generate, making the output of the LLM more predictable and safer to execute in a production setting. (An agent with access to "constrained" tools has similar benefits, but requires a call per action taken.)

Kork adds a few additional tricks (e.g., retriever interfaces for examples and foreign functions) to help guide the LLM to generate a correct program.

What?

No loops, no conditionals, no file access, no network access, no arbitrary code execution. WHAT?!

The ability to invoke custom functions goes a long way in terms of the kinds of programs that can be written! (You can always add a write_to_file function!)

Limitations

  • Kork cannot write arbitrary code. If that's what you need, save yourself some time and use docker and a real programming language.
  • The Kork chain is not an Agent, so it cannot inspect intermediate steps, instead it generates a pre-defined set of function calls that need to be executed. (But remember that function calls can involve calls to an agent!)
  • The Kork language and interpreter are limited to function invocation, variable declaration and basic arithmetic (no function declaration, loops etc.)
  • Only supporting int, float, str, type(None), bool types. No support for lists or object types.
  • Very limited type annotations.

Quality

The short version: No benchmarks yet!

The long version: Quality of generated programs depends on many factors.

You can experiment with tweaking the prompt (e.g., explain the syntax of the language), changing the foreign function retriever (e.g., retrieve the most relevant foreign functions based on the user query), or providing examples in the form of (query, expected program).

The prompt, examples and syntax of the language can trip up the LLM to assume it's programming in a specific language (e.g., typescript or python) and assume that it can use language features that are not supported by Kork or to import libraries that are not available.

Safety

Nothing is bulletproof when humans are involved.

  • Don't do silly things like exposing eval as a foreign function.
  • If a foreign function allocates memory, the LLM could ask for more memory than is available crashing the process.
  • Think carefully before using the output of an LLM. If the LLM behaves maliciously, is it safe to use an LLM in the given context?

Future Work

Let us know if you're interested in contributing or have ideas for improvements!

  • Allow enabling/disabling language features
  • Allow changing underlying language syntax
  • Add support for objects
  • Add other language features (e.g., loops)
  • Provide foreign function retriever implementations based on similarity to user query

Compatibility

Kork is tested against python 3.8, 3.9, 3.10, 3.11.

Installation

pip install kork

🙏 Appreciation

© Contributing

If you have any ideas or feature requests, please open an issue and share!

See CONTRIBUTING.md for more information.

🎶 Why the name?

Fast to type and maybe sufficiently unique.

Metadata

Release files for kork 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kork 0.0.3
File Size Uploaded
kork-0.0.3.tar.gz 22.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kork 0.0.3
File Interpreter ABI Platform
kork-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 46.4 kB

Release files / kork-0.0.3.tar.gz

Download URL kork-0.0.3.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ba02eb494cb53489cd8fd567868f6a895b2f5250d436a8503827d13a0f048935
BLAKE2b-256 checksum
How to use checksums
a66b27a45d91976c5d0b477c801f28798696b56118b75bcc5521e705aa5f62c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-1037-azure

Release files / kork-0.0.3-py3-none-any.whl

Download URL kork-0.0.3-py3-none-any.whl
Size 24.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dbf572091b2c5504cd9e95fd2c65f7a7f304a2e084b79ab0058505ec71472395
BLAKE2b-256 checksum
How to use checksums
372ad87b8b62731f063cef8e126458a2581310ab18b782b0e5c6f98d989474ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-1037-azure

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page