Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Readme
Lightweight wrapper to cache expensive function results in-memory or on disk.
pip install cheapi
from cheapi import CachingWrapper
import openai
def _ask_chatgpt(prompt):
res = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a helpful assistant for a software engineer."},
{"role": "user", "content": prompt}
],
temperature=0,
timeout=10,
)
choice, *_ = res["choices"]
usage = res["usage"]["total_tokens"]
print(f"OpenAI usage: {usage}")
result = choice["message"]["content"]
return result
ash_chatgpt = CachingWrapper(_ask_chatgpt, cache_backend="memory")
for i in range(2):
print(ash_chatgpt("Write a short joke about caching?") + "\n")
or even simpler:
from cheapi import cached
@cached(cache_backend="memory")
def ask_chatgpt(prompt):
...
for i in range(2):
print(ask_chatgpt("Write a short joke about caching?") + "\n")
Using memory backend is mostly equivalent to using functools.lru_cache
but with more configuration.
SQLite backend is useful for persistent caching, and is similar to joblib.Memory
.
Cloud backend is being dreamed of, but not implemented yet.
FAQs
Make API usage cheap! Caching wrapper for third party APIs.
We found that cheapi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.