Skip to content

This repository includes an unofficial wrapper for LLMs, such as OpenAI API and HuggingFace models, mainly for caching LLM responses to avoid duplicate inference with the identical prompts.

License

Notifications You must be signed in to change notification settings

ryokamoi/llm_wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LLM Wrapper

This is an unofficial wrapper for LLM APIs.

  • OpenAI models
  • Google Palm
  • Cohere Commands

Setup

pip install git+https://github.com/ryokamoi/llm_wrapper
pip install --upgrade chardet  # for llama2

Example

from llm_wrapper import llm_api
print(llm_api("gpt-3.5-turbo", prompt="Translate this sentence into Japanese: I am GPT-3.5."))
# {'prompt': 'Translate this sentence into Japanese: I am GPT-3.5.', 'response': '私はGPT-3.5です。 (Watashi wa GPT-3.5 desu.)'}

# When temperature=0. (default), this wrapper will store and read cached results.
llm_api("gpt-3.5-turbo", prompt="Translate this sentence into Japanese: I am GPT-3.5.")
# read cache from llm_cache/554a571588d632d02bd8cc330fee66fea40adf7d242763b462a7691ee858afd4d3a852caaa02058db5e9810edac0fee5021754c0f4479842d374e915a7cb21c0.json
# {'prompt': 'Translate this sentence into Japanese: I am GPT-3.5.', 'response': '私はGPT-3.5です。 (Watashi wa GPT-3.5 desu.)'}
  • You can overwrite the cache by setting cache_overwrite=True.
  • You can overwrite the temperature by setting updated_parameters={"temperature": 0.5}. You can update any parameters in the same way.

About

This repository includes an unofficial wrapper for LLMs, such as OpenAI API and HuggingFace models, mainly for caching LLM responses to avoid duplicate inference with the identical prompts.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages