Abhinav7 commited on
Commit
27d8de0
1 Parent(s): ac58288

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +14 -14
main.py CHANGED
@@ -1,21 +1,21 @@
1
  from fastapi import FastAPI, Form
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from pydantic import BaseModel
4
- from transformers import AutoModelForCausalLM
5
 
6
- # Model loading
7
- llm = AutoModelForCausalLM.from_pretrained(
8
- "zephyr-7b-beta.Q4_K_S.gguf",
9
- model_type='mistral',
10
- max_new_tokens=1096,
11
- threads=3,
12
  )
 
13
 
14
- # Pydantic object
15
- class Validation(BaseModel):
16
  prompt: str
17
-
18
- # Fast API
19
  app = FastAPI()
20
 
21
  # Set up CORS
@@ -32,11 +32,11 @@ app.add_middleware(
32
  allow_headers=["*"],
33
  )
34
 
35
- # Zephyr completion
36
  @app.post("/llm_on_cpu")
37
- async def stream(item: Validation):
38
  system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
39
  E_INST = "</s>"
40
- user, assistant = "", ""
41
  prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt.strip()}{E_INST}\n{assistant}\n"
42
  return llm(prompt)
 
1
  from fastapi import FastAPI, Form
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from pydantic import BaseModel
4
+ from ctransformers import AutoModelForCausalLM
5
 
6
+ #Model loading
7
+ llm = AutoModelForCausalLM.from_pretrained("zephyr-7b-beta.Q4_K_S.gguf",
8
+ model_type='mistral',
9
+ max_new_tokens = 1096,
10
+ threads = 3,
 
11
  )
12
+
13
 
14
+ #Pydantic object
15
+ class validation(BaseModel):
16
  prompt: str
17
+
18
+ #Fast API
19
  app = FastAPI()
20
 
21
  # Set up CORS
 
32
  allow_headers=["*"],
33
  )
34
 
35
+ #Zephyr completion
36
  @app.post("/llm_on_cpu")
37
+ async def stream(item: validation):
38
  system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
39
  E_INST = "</s>"
40
+ user, assistant = "<|user|>", "<|assistant|>"
41
  prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt.strip()}{E_INST}\n{assistant}\n"
42
  return llm(prompt)