diff --git a/docs/release_note.md b/docs/release_note.md index 3e1bfbc5..984e3845 100644 --- a/docs/release_note.md +++ b/docs/release_note.md @@ -5,6 +5,46 @@ To read the following content, you need to understand the basic use of GPTCache, - [Readme doc](https://github.com/zilliztech/GPTCache) - [Usage doc](https://github.com/zilliztech/GPTCache/blob/main/docs/usage.md) +## v0.1.16 (2023.4.18) + +1. Add StableDiffusion adapter (**experimental**) + +```python +import torch + +from gptcache.adapter.diffusers import StableDiffusionPipeline +from gptcache.processor.pre import get_prompt +from gptcache import cache + +cache.init( + pre_embedding_func=get_prompt, +) +model_id = "stabilityai/stable-diffusion-2-1" +pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) + +prompt = "a photo of an astronaut riding a horse on mars" +pipe(prompt=prompt).images[0] +``` + +2. Add speech to text bootcamp, [link](https://github.com/zilliztech/GPTCache/tree/main/docs/bootcamp/openai/speech_to_text.ipynb) + +3. More convenient management of cache files + +```python +from gptcache.manager.factory import manager_factory + +data_manager = manager_factory('sqlite,faiss', data_dir="test_cache", vector_params={"dimension": 5}) +``` + +4. Add a simple GPTCache server (**experimental**) + +After starting this server, you can: + +- put the data to cache, like: `curl -X PUT -d "receive a hello message" "http://localhost:8000?prompt=hello"` +- get the data from cache, like: `curl -X GET "http://localhost:8000?prompt=hello"` + +Currently the service is just a map cache, more functions are still under development. + ## v0.1.15 (2023.4.17) 1. Add GPTCache api, makes it easier to access other different llm models and applications diff --git a/gptcache_server/__init__.py b/gptcache_server/__init__.py new file mode 100644 index 00000000..f7f63984 --- /dev/null +++ b/gptcache_server/__init__.py @@ -0,0 +1 @@ +from gptcache_server.server import start_server diff --git a/gptcache_server/server.py b/gptcache_server/server.py new file mode 100644 index 00000000..e7231e49 --- /dev/null +++ b/gptcache_server/server.py @@ -0,0 +1,52 @@ +import argparse +import http.server +import json + +from gptcache import cache +from gptcache.adapter.api import get, put +from gptcache.processor.pre import get_prompt + + +class GPTCacheHandler(http.server.BaseHTTPRequestHandler): + # curl -X GET "http://localhost:8000?prompt=hello" + def do_GET(self): + params = self.path.split("?")[1] + prompt = params.split("=")[1] + + result = get(prompt) + + response = json.dumps(result) + + self.send_response(200) + self.send_header("Content-type", "application/json") + self.end_headers() + self.wfile.write(bytes(response, "utf-8")) + + # curl -X PUT -d "receive a hello message" "http://localhost:8000?prompt=hello" + def do_PUT(self): + params = self.path.split("?")[1] + prompt = params.split("=")[1] + content_length = int(self.headers.get("Content-Length", "0")) + data = self.rfile.read(content_length).decode("utf-8") + + put(prompt, data) + + self.send_response(200) + self.end_headers() + + +def start_server(host: str, port: int): + httpd = http.server.HTTPServer((host, port), GPTCacheHandler) + print(f"Starting server at {host}:{port}") + httpd.serve_forever() + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--host", default="localhost", help="the hostname to listen on") + parser.add_argument("--port", type=int, default=8000, help="the port to listen on") + args = parser.parse_args() + + cache.init(pre_embedding_func=get_prompt) + + start_server(args.host, args.port) diff --git a/setup.py b/setup.py index 8b097fb6..551565de 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ def parse_requirements(file_name: str) -> List[str]: setuptools.setup( name="gptcache", packages=find_packages(), - version="0.1.15", + version="0.1.16", author="SimFG", author_email="bang.fu@zilliz.com", description="GPTCache, a powerful caching library that can be used to speed up and lower the cost of chat "