Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -5,9 +5,9 @@ from llama_cpp import Llama
|
|
| 5 |
model_path = "mistral-7b-v0.1.Q4_K_M.gguf"
|
| 6 |
|
| 7 |
llm = Llama(
|
| 8 |
-
model_path=model_path,
|
| 9 |
-
n_ctx=4096,
|
| 10 |
-
n_threads=4,
|
| 11 |
)
|
| 12 |
|
| 13 |
app = FastAPI()
|
|
@@ -16,22 +16,20 @@ class DSAPrompt(BaseModel):
|
|
| 16 |
prompt: str
|
| 17 |
|
| 18 |
@app.post("/solve_dsa_problem")
|
| 19 |
-
async def solve_dsa_problem(
|
| 20 |
system_prompt = '''
|
| 21 |
You are a Data Structures and Algorithm problem solver. You are given the following problem and you need to solve it.
|
| 22 |
Give a detailed explanation of the solution approach and the code in C++, Java, or Python.
|
| 23 |
If the input is not a DSA problem, politely refuse their request and reinsist to provide a DSA problem.
|
| 24 |
'''
|
| 25 |
|
| 26 |
-
|
| 27 |
messages=[
|
| 28 |
{"role": "system", "content": system_prompt},
|
| 29 |
{"role": "user", "content": item.prompt}
|
| 30 |
],
|
| 31 |
-
temperature=0.9,
|
| 32 |
-
max_tokens=2048,
|
| 33 |
-
|
| 34 |
-
) as stream_result:
|
| 35 |
|
| 36 |
-
|
| 37 |
-
yield chunk
|
|
|
|
| 5 |
model_path = "mistral-7b-v0.1.Q4_K_M.gguf"
|
| 6 |
|
| 7 |
llm = Llama(
|
| 8 |
+
model_path = model_path,
|
| 9 |
+
n_ctx = 4096,
|
| 10 |
+
n_threads = 4,
|
| 11 |
)
|
| 12 |
|
| 13 |
app = FastAPI()
|
|
|
|
| 16 |
prompt: str
|
| 17 |
|
| 18 |
@app.post("/solve_dsa_problem")
|
| 19 |
+
async def solve_dsa_problem(item: DSAPrompt):
|
| 20 |
system_prompt = '''
|
| 21 |
You are a Data Structures and Algorithm problem solver. You are given the following problem and you need to solve it.
|
| 22 |
Give a detailed explanation of the solution approach and the code in C++, Java, or Python.
|
| 23 |
If the input is not a DSA problem, politely refuse their request and reinsist to provide a DSA problem.
|
| 24 |
'''
|
| 25 |
|
| 26 |
+
res = llm.create_chat_completion(
|
| 27 |
messages=[
|
| 28 |
{"role": "system", "content": system_prompt},
|
| 29 |
{"role": "user", "content": item.prompt}
|
| 30 |
],
|
| 31 |
+
temperature = 0.9,
|
| 32 |
+
max_tokens = 2048,
|
| 33 |
+
)
|
|
|
|
| 34 |
|
| 35 |
+
return res
|
|
|