Skip to main content

Take your best shot

Project description

🎯 FewShots: The best few shots with LLMs

Python 3.8+ License: MIT

Ever wished your AI model had a better memory? Meet FewShot - 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 few_shots.client import FewShot
from few_shots.embed.transformers import TransformersEmbedder
from few_shots.store.memory import MemoryStore

# Create a FewShot client
client = FewShot(
    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 few_shots.async_client import AsyncFewShot

client = AsyncFewShot(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 AsyncFewShot
from few_shots.embed.litellm import AsyncLiteLLMEmbedder

client = AsyncFewShot(
    embed=AsyncLiteLLMEmbedder(
        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 FewShot 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! 🌟

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

few_shots-0.1.2.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

few_shots-0.1.2-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file few_shots-0.1.2.tar.gz.

File metadata

  • Download URL: few_shots-0.1.2.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.2

File hashes

Hashes for few_shots-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a360f898dec4d38bd0a2296c4ff8a5ed8c49556c2440e1d31e54306c49fc6e8b
MD5 1b578af60912bb908c5a686d7d472384
BLAKE2b-256 142f256357e517ff70cedd961107d2eb8e7a66c9b043c3ad78c274b8a8d73d42

See more details on using hashes here.

File details

Details for the file few_shots-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: few_shots-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.2

File hashes

Hashes for few_shots-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 57fa6dea45fc1d764ac626ddd0bc89c85b47c40f85986e6905d624e9c42ceb30
MD5 20701a2097a4361261e5cb32bd923fb0
BLAKE2b-256 26b2a4d2777fb890170b628bb366b0a00f484c194c5c82a4286c91be193115ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page