Skip to main content

Context for lavague able to cache and proxy to LLM and MM LLM designed to save up tokens and make model calls deterministic

Project description

Cache for LLM, Multimodal LLM and embeddings

Overview

LaVague Context Cache is a caching layer designed for Language Models, Multimodal Language Models and embeddings. It ensures deterministic results, avoids unnecessary token consumption, and speeds up local development by caching responses and embeddings.

This tool is ideal for:

  • Developers seeking to streamline their workflow when working with models.
  • Builders aiming to reduce model costs and enhance performance when agent objectives are stable.

Key features:

  • Guarantees consistent results in both automated and manual testing by caching previous responses
  • Reduces API token consumption by reusing cached results, avoiding redundant API calls
  • Speeds up local development by eliminating the need to repeatedly query the same results
  • Cached scenario can be replayed offline

Installation

From pypi

pip install lavague-contexts-cache

From the sources

pip install -e lavague-integrations/contexts/lavague-contexts-cache

Usage

Using wrappers

from lavague.contexts.cache import LLMCache
from llama_index.llms.openai import OpenAI

llm = LLMCache(yml_prompts_file="llm.yml", fallback=OpenAI(model = "gpt-4o"))
from lavague.contexts.cache import MultiModalLLMCache
from llama_index.multi_modal_llms.openai import OpenAIMultiModal

mm_llm = MultiModalLLMCache(yml_prompts_file="mmllm.yml", fallback=OpenAIMultiModal(model = "gpt-4o"))
from lavague.contexts.cache import EmbeddingCache
from llama_index.embeddings.openai import OpenAIEmbedding

embedding = EmbeddingCache(yml_prompts_file="embeddings.yml", fallback=OpenAIEmbedding(model = "text-embedding-3-large"))

Using LaVague context

from lavague.core import WorldModel, ActionEngine
from lavague.core.agents import WebAgent
from lavague.drivers.selenium import SeleniumDriver
from lavague.core.context import get_default_context
from lavague.contexts.cache import ContextCache

driver = SeleniumDriver()
context = get_default_context()
cached_context = ContextCache.from_context(context)
world_model = WorldModel.from_context(cached_context)
action_engine = ActionEngine.from_context(cached_context, driver)
agent = WebAgent(world_model, action_engine)

Performance

Cached values are stored in YAML files and loaded into memory by default. While this approach works well for a few runs, it can consume excessive memory when applied to various websites. For production use cases, we recommend using an optimized storage system (database, cache, ...).

To do so, pass a store that implements abstract PromptsStore methods.

from lavague.contexts.cache import LLMCache
from lavague.contexts.cache.prompts_store import PromptsStore
from llama_index.llms.openai import OpenAI

class MyDataBaseStore(PromptsStore[str]):
  def _get_for_prompt(self, prompt: str) -> str:
    # return from DB with prompt key
    pass

  def _add_prompt(self, prompt: str, output: str):
    # store in DB
    pass

my_database_store = MyDataBaseStore()

llm = LLMCache(yml_prompts_file="llm.yml", fallback=OpenAI(model = "gpt-4o"), store=store)

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

lavague_contexts_cache-0.0.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

lavague_contexts_cache-0.0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file lavague_contexts_cache-0.0.1.tar.gz.

File metadata

  • Download URL: lavague_contexts_cache-0.0.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for lavague_contexts_cache-0.0.1.tar.gz
Algorithm Hash digest
SHA256 60706f05654f694b9e32a8c27783cf725d1e96b910500b588e0b1ea965c602d9
MD5 8afed0a5d05c8f15cecee9d8efdfe281
BLAKE2b-256 99162f0644b551edacc34a7f95af98ccd2660df99b2cd5807342633f4de034da

See more details on using hashes here.

File details

Details for the file lavague_contexts_cache-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: lavague_contexts_cache-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for lavague_contexts_cache-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 95754f84b94ebb7e1449fb73097303efb4b9c13da6df0f26fc6a5e146e6d9d20
MD5 38bd673f378252b8bb35f2031e27c7f5
BLAKE2b-256 f4ee9ac8096852da7ec8a242d7b5095a7086d01042ca720af9bad87a5da42161

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