-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: SimFG <[email protected]>
- Loading branch information
Showing
4 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from gptcache_server.server import start_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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="[email protected]", | ||
description="GPTCache, a powerful caching library that can be used to speed up and lower the cost of chat " | ||
|