Skip to main content

keeptalking

A simple, pythonic interface to any OpenAI-compatible LLM server. You will never type response.choices[0].message.content ever again.

Installation

pip install keeptalking

Usage

The entire library is 3 functions:

from keeptalking import talk, write, vibe

Conversation

talk(model='google/gemini-2.5-flash', 
     roles=['system', 'user'], 
     messages=['Solve a math problem', 'Sum up all possible bases in which 97 is divisible by 17'],
     structure=int,
     tokens=10)

will use grammar constrained decoding and return a single integer with the answer. The return value of talk will always be of type structure, which defaults to str is omitted. If roles are omitted, the first message is considered a system message, the rest are user messages. If model is omitted, gemini-2.5-flash is used (default model can be overriden by setting the MODEL environment variable). If tokens is omitted, generation is limited to 2048 new tokens (default token limit can be overridden by setting the TOKENS environment variable).

The only parameter that should not be omitted is messages:

talk(['Solve a math problem. Provide your reasoning', 'Sum up all possible bases in which 97 is divisible by 17'])

write is an asynchronous version of talk that lets you beautifully parallelize batch requests:

asyncio.gather(
    write(model='google/gemini-2.5-flash', 
          roles=['system', 'user'], 
          messages=[sys, berry],
          structure=int,
          tokens=10)
    for berry in ['Strawberry', 'Blackberry', 'Raspberry', 'Blueberry', 'Canterbury']
)

write automatically self-throttles as necessary so it's safe to call thousands of write()s in parallel with no external rate limiting.

Vibe functions

Vibe functions are functions defined in natural language.

@vibe(model='google/gemini-2.5-flash', tokens=10)
def do_job(job_details):
    """System message"""
    return f"User message with {job_details}"

ELL users will notice that this format is shamelessly stolen inspired by ELL. However, keeptalking is much simpler than ELL. Despite being much simpler, keeptalking supports additional features like async vibe functions

@vibe()
async def homework_assistant(topic, pages=5):
    """Help the student with their homework"""
    return f"Write a {pages}-page essay on {topic}"

fully parallelizable like so

asyncio.gather(
    homework_assistant('Math'),
    homework_assistant('History'),
    homework_assistant('English')
)

and enabling structured outputs with a single type hint:

@vibe()
def count_rs(request) -> int:
    """Count how many Rs are in the request"""
    return request

unlike in the rest of the Python ecosystem, in vibe functions type hints actually ensure that the return value is always of the type in question

Backend configuration

The model server to be used is defined via environment variables. It can be defined directly by setting BASE_URL and API_KEY. If those are not set, keeptalking will default to OpenRouter if OPENROUTER_API_KEY is set, then OpenAI if OPENAI_API_KEY is set. Perv advanced users can monkey patch keeptalking.client_sync and keeptalking.client_async instead.

Example

You will find a detailed example in example.py. It takes top 10 models from openrouter's model catalog and reads text description of each model to filter out specialized models like coding or edit models, then runs a small test on each to check if they are working.

Metadata

Release files for keeptalking 0.3.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 keeptalking 0.3.3
File Size Uploaded Provenance Actions
keeptalking-0.3.3.tar.gz 3.7 kB Without provenance Details for keeptalking-0.3.3.tar.gz

Built distribution (wheel)

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

Total release size: 8.0 kB

Release files / keeptalking-0.3.3.tar.gz

Download URL keeptalking-0.3.3.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c1c1f52bac5f587f3398464ccb40ad8e7aa2fcb691462eb630c1429f2a4a6862
BLAKE2b-256 checksum
How to use checksums
d9145c74044f648ab44a41b27b54b1583847c7d5e09e8eac178612faffdbc98b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.12.11 Darwin/24.5.0

Release files / keeptalking-0.3.3-py3-none-any.whl

Download URL keeptalking-0.3.3-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54c8172442aad3046ef004fd337d83fec018e3d45a392f13dc02eeaa53bd7dd6
BLAKE2b-256 checksum
How to use checksums
da861127475debd8fb1c38e81cee48ba7261d4f26173341d30b7764e23a54305
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.12.11 Darwin/24.5.0

Security for keeptalking 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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