Add Python server setup and dependencies installation

This commit is contained in:
kwaroran
2024-01-14 05:57:33 +09:00
parent 012168d9a1
commit a1a38d5ad2
6 changed files with 73 additions and 11 deletions

View File

@@ -2,10 +2,15 @@ from fastapi import FastAPI, Header
from fastapi.responses import StreamingResponse
from llamacpp import LlamaItem, stream_chat_llamacpp
from typing import Annotated, Union
import uuid
import os
app = FastAPI()
key_dir = os.path.join(os.getcwd(), "key.txt")
if not os.path.exists(key_dir):
f = open(key_dir, 'w')
f.write(str(uuid.uuid4()))
f.close()
f = open(key_dir, 'r')
key = f.read()
f.close()

View File

@@ -0,0 +1,4 @@
pydantic
llama-cpp-python
uvicorn[standard]
fastapi

View File

@@ -1,13 +1,9 @@
import uvicorn
import os
import uuid
import subprocess
import sys
if __name__ == "__main__":
key_dir = os.path.join(os.getcwd(), "key.txt")
with open(key_dir, "w") as f:
f.write(uuid.uuid4().hex)
subprocess.check_call([sys.executable, "-m", "pip", "install", "pydantic"])
subprocess.check_call([sys.executable, "-m", "pip", "install", "llama-cpp-python"])
uvicorn.run("main:app", host="0.0.0.0", port=8912)