Skip to main content

LLM provider abstraction layer.

Project description

oneping

Give me a ping, Vasily. One ping only, please.

One ping only, please.

This is a simple wrapper library for querying LLMs via URL or native package. Currently the following providers are supported: openai, anthropic, fireworks, and local (local models).

Requesting a local provider will target localhost and use an OpenAI-compatible API as in llama.cpp or llama-cpp-python. Also included is a simple function to start a llama-cpp-python server on the fly (oneping.server.run_llama_server).

The various native libraries are soft dependencies and the library can still partially function with or without any or all of them. The native packages for these providers are: openai, anthropic, and fireworks-ai.

There is also a Chat interface that automatically tracks message history. Kind of departing from the "one ping" notion, but oh well. This accepts a provider and system argument. Other parameters are passed by calling it (an alias for chat) or to stream.

Installation

For standard usage, install with:

pip install oneping

To include the native provider dependencies, install with:

pip install oneping[native]

To include the chat and web interface dependencies, install with:

pip install oneping[chat]

API Usage

Basic usage with Anthropic through the URL interface:

response = oneping.get_llm_response(prompt, provider='anthropic')

The get_llm_response function accepts a number of arguments including:

  • prompt (required): The prompt to send to the LLM (required)
  • provider = local: The provider to use: openai, anthropic, fireworks, or local
  • system = None: The system prompt to use (not required, but recommended)
  • prefill = None: Start "assistant" response with a string (Anthropic doesn't like newlines in this)
  • history = None: List of prior messages or True to request full history as return value
  • url = None: Override the default URL for the provider
  • port = 8000: Which port to use for local or custom provider
  • api_key = None: The API key to use for non-local providers
  • model = None: Indicate the desired model for the provider
  • max_tokens = 1024: The maximum number of tokens to return
  • stream = False: Whether to stream the response (returns a generator)

For example, to use the OpenAI API with a custom system prompt:

response = oneping.get_llm_response(prompt, provider='openai', system=system)

To conduct a full conversation with a local LLM:

history = True
history = oneping.get_llm_response(prompt1, provider='local', history=history)
history = oneping.get_llm_response(prompt2, provider='local', history=history)

For streaming, use the async function stream_llm_response and for async streaming, use async_llm_response. Both of these take the same arguments as get_llm_response.

CLI Interface

You can call the oneping module directly and access command from the command line:

  • reply: get a single response from the LLM
  • stream: stream a response from the LLM
  • console: start a console (Textual) chat
  • web: start a web (FastHTML) chat

These accept the arguments listed above for get_llm_response as command line arguments. For example:

python -m oneping stream "Does Jupiter have a solid core?" --provider anthropic

Or you can pipe in your query from stdin:

echo "Does Jupiter have a solid core?" | python -m oneping stream --provider anthropic

Chat Interface

The Chat interface is a simple wrapper for a conversation history. It can be used to chat with an LLM provider or to simply maintain a conversation history for your bot.

chat = oneping.Chat(provider='anthropic', system=system)
response1 = chat(prompt1)
response2 = chat(prompt2)

There is also a textual powered CLI interface and a fasthtml powered web interface. You can call these with: python -m oneping console or python -m oneping web.

Textual Chat FastHTML Chat

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

oneping-0.3.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

oneping-0.3-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file oneping-0.3.tar.gz.

File metadata

  • Download URL: oneping-0.3.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for oneping-0.3.tar.gz
Algorithm Hash digest
SHA256 edf32b5d70e04b915777eac0b4638a03c056a1a241a5b8fda343b55607bc2b7b
MD5 94c039885b38b7406b0fbba230b1170e
BLAKE2b-256 254f0f19a485790c983c6220353f97365b527a77750ade42e160620223b8eeee

See more details on using hashes here.

File details

Details for the file oneping-0.3-py3-none-any.whl.

File metadata

  • Download URL: oneping-0.3-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for oneping-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7ad7f75aa005b015a7b85a6c22c1323350fc9d21ae01da84936248b3e4dec84b
MD5 413b39495fd536b5e791ecf2a1d24b75
BLAKE2b-256 9b3bb531f607f11bcffc21ad35ed93e246c26f2c1536979845e90c4ad5d376b8

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