Skip to main content

🎯 BestShot: The best few shots with LLMs

Python 3.8+ License: MIT

Ever wished your AI model had a better memory? Meet BestShot - the simple yet powerful library for managing and retrieving few-shot examples with style! 🧠✨

🌟 Features

  • 🚀 Lightning Fast: Both sync and async implementations for maximum flexibility
  • 🎮 Easy to Use: Simple, intuitive API for managing your AI's example database
  • 🔄 Structured Output: Support for structured outputs

🚀 Quick Start

from sentence_transformers import SentenceTransformer # Can also use OpenAI, etc.
from best_shot.client import BestShot
from best_shot.embed.transformers import TransformersEmbedder
from best_shot.store.memory import MemoryStore

# Create a BestShot client
client = BestShot(
    embed=TransformersEmbedder(model=SentenceTransformer("all-MiniLM-L6-v2")),
    store=MemoryStore()
)

# Add some examples
client.add(
    inputs="How do I make a pizza?",
    outputs="1. Make the dough 2. Add toppings 3. Bake at 450°F"
)

# Find similar examples
results = client.list("What's the recipe for pizza?", limit=1)
for shot, similarity in results:
    print(f"Found match (similarity: {similarity:.2f}):")
    print(f"Q: {shot.inputs}")
    print(f"A: {shot.outputs}")

🔧 Installation

pip install best-shot
rye add best-shot
poetry add best-shot

🎮 Usage Examples

Working with Structured Output I/O

# Add structured data
client.add(
    inputs={"type": "greeting", "language": "English"},
    outputs={"text": "Hello, world!"}
)

# Search with similar inputs
results = client.list({"type": "greeting", "language": "English"})

Async Support

from best_shot.async_client import AsyncBestShot

client = AsyncBestShot(embed=async_embedder, store=async_store)

# Add examples asynchronously
await client.add(
    inputs="What's the weather like?",
    outputs="I don't have access to real-time weather data."
)

# Search asynchronously
results = await client.list("How's the weather today?", limit=1)

Using LiteLLM for Embeddings

from functools import partial
from litellm import aembedding
from fewshot import AsyncBestShot
from best_shot.embed.litellm import AsyncLiteLLMEmbedder

client = AsyncBestShot(
    embed=AsyncLiteLLMEmbedder(
        embed=partial(aembedding, model="...", **kwargs),
    ),
    store=MemoryStore()
)

🛠️ Core Components

  • Shot: The fundamental unit representing an input-output pair with a unique ID (you can use your own ID or let BestShot hash the inputs)
  • Embedder: Converts inputs into vector embeddings for similarity search
  • Store: Manages storage and retrieval of examples
  • Client: Ties everything together with a clean, simple interface

💡 Use Cases

  • 🤖 Enhance your chatbot with dynamic example retrieval
  • 📚 Build a self-improving knowledge base
  • 🎯 Implement context-aware few-shot learning
  • 🧪 Test and experiment with different few-shot strategies

🤝 Contributing

We love contributions! Feel free to:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

📝 License

MIT License - feel free to use it in your projects!


Made with ❤️ by developers who believe in the power of learning from examples.

Remember: The best AI is the one that learns from experience! 🌟

Metadata

Release files for best-shot 0.1.1

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

Source distribution (sdist)

Source distribution for best-shot 0.1.1
File Size Uploaded Provenance Actions
best_shot-0.1.1.tar.gz 12.5 kB Without provenance Details for best_shot-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for best-shot 0.1.1
File Interpreter ABI Platform Actions
best_shot-0.1.1-py3-none-any.whl Python 3 none any Details for best_shot-0.1.1-py3-none-any.whl

Total release size: 25.0 kB

Release files / best_shot-0.1.1.tar.gz

Download URL best_shot-0.1.1.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
688ab0b6b9d3bc68b8176e7fbb98195876fa05346801526d101105a13bc811dc
BLAKE2b-256 checksum
How to use checksums
82f9e969515da79ce954e9e81df6c3146d47fbe15baeb350917d705b044de740
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.2

Release files / best_shot-0.1.1-py3-none-any.whl

Download URL best_shot-0.1.1-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b5dd43e9ef6185a309f865005db2e43a7608b12ebfbc81b51a734843e6bea1d
BLAKE2b-256 checksum
How to use checksums
7a684f4a97d30744a3f5ec766bd961bdffade9ccc1f389c9b0360299a7e42578
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.2

Security for best-shot 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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