gathnex commited on
Commit
5dab16f
1 Parent(s): 364fe36

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +12 -0
  2. main.py +33 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY ./zephyr-7b-beta.Q4_K_S.gguf /code/zephyr-7b-beta.Q4_K_S.gguf
10
+ COPY ./main.py /code/main.py
11
+
12
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ctransformers import AutoModelForCausalLM
2
+ from fastapi import FastAPI, Form
3
+ from pydantic import BaseModel
4
+
5
+
6
+ llm = AutoModelForCausalLM.from_pretrained("zephyr-7b-beta.Q4_K_S.gguf",
7
+ model_type='mistral',
8
+ max_new_tokens = 1096,
9
+ threads = 1,
10
+ )
11
+
12
+
13
+ #Pydantic object
14
+ class validation(BaseModel):
15
+ prompt: str
16
+ #Fast API
17
+ app = FastAPI()
18
+ #Function contain tranlater API, RAG API, OpenAI API
19
+ @app.post("/llm_on_cpu")
20
+ async def stream(item: validation):
21
+ system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
22
+ E_INST = "</s>"
23
+ user, assistant = "<|user|>", "<|assistant|>"
24
+ prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt.strip()}{E_INST}\n{assistant}\n"
25
+ return llm(prompt)
26
+
27
+ #def stream(user_prompt)
28
+ # system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
29
+ # E_INST = "</s>"
30
+ # user, assistant = "<|user|>", "<|assistant|>"
31
+ # prompt = f"{system_prompt}{E_INST}\n{user}\n{user_prompt.strip()}{E_INST}\n{assistant}\n"
32
+ # for text in llm(prompt, stream=True):
33
+ # print(text, end="", flush=True)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ python-multipart
2
+ fastapi
3
+ pydantic
4
+ uvicorn
5
+ requests
6
+ ctransformers