krupakar-reddy commited on
Commit
9c06b10
·
verified ·
1 Parent(s): 9bc9de8

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +12 -0
  2. main.py +29 -0
  3. requirements.txt +7 -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 ./mistral-7b-instruct-v0.2.Q4_K_M.gguf /code/mistral-7b-instruct-v0.2.Q4_K_M.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,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ctransformers import AutoModelForCausalLM
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+
5
+
6
+ llm = AutoModelForCausalLM.from_pretrained("mistral-7b-instruct-v0.2.Q4_K_M.gguf",
7
+ model_type='mistral',
8
+ max_new_tokens = 2048,
9
+ threads = 3,
10
+ )
11
+
12
+ class DSAPrompt(BaseModel):
13
+ prompt: str
14
+
15
+ app = FastAPI()
16
+
17
+ @app.post("/solve_dsa_problem")
18
+ async def stream(item: DSAPrompt):
19
+ system_prompt = '''
20
+ You are a Data Structures and Algorithm problem solver. You are given the following problem and you need to solve it.
21
+ Give a detailed explanation of the solution approach and the code in C++, Java, or Python.
22
+ If the input is not a DSA problem, politely refuse their request and reinsist to provide a DSA problem.
23
+ '''
24
+
25
+ E_INST = "</s>"
26
+ user, assistant = "<|user|>", "<|assistant|>"
27
+
28
+ prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt}{E_INST}\n{assistant}\n"
29
+ return llm(prompt)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ python-multipart
2
+ fastapi
3
+ pydantic
4
+ uvicorn
5
+ requests
6
+ python-dotenv
7
+ ctransformers