Skip to main content

No project description provided

Project description

Logo Logo

Cursive is a universal and intuitive framework for interacting with LLMs.

It works in any JavaScript runtime and has a heavy focus on extensibility and developer experience.

highlights

Extensible - You can easily hook into any part of a completion life cycle. Be it to log, cache, or modify the results.

Functions - Easily describe functions that the LLM can use along with its definition, with any model (currently supporting GPT-4, GPT-3.5, Claude 2, and Claude Instant)

Universal - Cursive's goal is to bridge as many capabilities between different models as possible. Ultimately, this means that with a single interface, you can allow your users to choose any model.

Informative - Cursive comes with built-in token usage and costs calculations, as accurate as possible.

Reliable - Cursive comes with automatic retry and model expanding upon exceeding context length. Which you can always configure.

quickstart

  1. Install.
poetry add cursivepy
# or
pip install cursivepy
  1. Start using.
from cursive import Cursive

const cursive = Cursive()

response = cursive.ask(
    prompt='What is the meaning of life?',
)

print(response.answer)

usage

Conversation

Chaining a conversation is easy with cursive. You can pass any of the options you're used to with OpenAI's API.

res_a = cursive.ask(
    prompt='Give me a good name for a gecko.',
    model='gpt-4',
    max_tokens=16,
)

print(res_a.answer) # Zephyr

res_b = res_b.conversation.ask(
    prompt='How would you say it in Portuguese?'
)

print(res_b.answer) # Zéfiro

Streaming

Streaming is also supported, and we also keep track of the tokens for you!

result = cursive.ask(
    prompt='Count to 10',
    stream=True,
    on_token=lambda partial: print(partial['content'])
)

print(result.usage.total_tokens) # 40

Functions

You can use very easily to define and describe functions, along side with their execution code.

from cursive import cursive_function, Cursive

cursive = Cursive()

@cursive_function()
def add(a: float, b: float):
    """
    Adds two numbers.
    
    a: The first number.
    b: The second number.
    """
    return a + b

res = cursive.ask(
    prompt='What is the sum of 232 and 243?',
    functions=[sum],
)

print(answer) # The sum of 232 and 243 is 475.

The functions' result will automatically be fed into the conversation and another completion will be made. If you want to prevent this, you can add pause to your function definition.

@cursive_function(pause=True)
def create_character(name: str, age: str):
    """
    Creates a character.
    
    name: The name of the character.
    age: The age of the character.
    """
    return {
        'name': name,
        'age': age,
    }

res = cursive.ask({
    prompt='Create a character named John who is 23 years old.',
    functions=[createCharacter],
})

print(res.function_result) # { name: 'John', age: 23 }

Hooks

You can hook into any part of the completion life cycle.

cursive.on('completion:after', lambda result: print(
    result.data.cost.total,
    result.data.usage.total_tokens,
))

cursive.on('completion:error', lambda result: print(
    result.error,
))

cursive.ask({
    prompt: 'Can androids dream of electric sheep?',
})

# 0.0002185
# 113

Embedding

You can create embeddings pretty easily with cursive.

embedding = cursive.embed('This should be a document.')

This will support different types of documents and integrations pretty soon.

Reliability

Cursive comes with automatic retry with backoff upon failing completions, and model expanding upon exceeding context length -- which means that it tries again with a model with a bigger context length when it fails by running out of it.

You can configure this behavior by passing the retry and expand options to useCursive.

cursive = Cursive(
    max_retries=5, # 0 disables it completely
    expand={
        'enable': true,
        'defaults_to': 'gpt-3.5-turbo-16k',
        'model_mapping': {
            'gpt-3.5-turbo': 'gpt-3.5-turbo-16k',
            'gpt-4': 'claude-2',
        },
    },
)

roadmap

vendor support

  • Anthropic
  • Cohere
  • Azure OpenAI models
  • Huggingface
  • Replicate

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

cursivepy-0.1.5.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

cursivepy-0.1.5-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file cursivepy-0.1.5.tar.gz.

File metadata

  • Download URL: cursivepy-0.1.5.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.5.0

File hashes

Hashes for cursivepy-0.1.5.tar.gz
Algorithm Hash digest
SHA256 c19e7963484bde010c347354256db62e038e71cc8e12d18dffa577706a66cd8f
MD5 4dd3c8252fa3df9204e3fbfa0176901d
BLAKE2b-256 05105a6da04b9ad70bf04d83536bc390ccd367d8e18c470bb76dcc7be2b57dd0

See more details on using hashes here.

File details

Details for the file cursivepy-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: cursivepy-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.5.0

File hashes

Hashes for cursivepy-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 86095700b3f8624ce017a4019dd719b91e10f2c70adad05b7ec1ccf3bcd17eba
MD5 d477e103acb271b8ca5e977d98f5d68e
BLAKE2b-256 a3879e96f4b5b6c773f9855b38c2c5de36691c436aee4713553109a6611f0037

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