krupakar-reddy commited on
Commit
6efe7b3
·
verified ·
1 Parent(s): fca2aca

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -11
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(request: Request, 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
- async with 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
- stream=True
34
- ) as stream_result:
35
 
36
- async for chunk in stream_result:
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