Petro commited on
Commit
461052c
1 Parent(s): 2d3c757

First model version

Browse files
Files changed (2) hide show
  1. main.py +7 -10
  2. requirements.txt +1 -1
main.py CHANGED
@@ -1,21 +1,18 @@
1
- from ctransformers import AutoModelForCausalLM
2
  from fastapi import FastAPI
3
  from pydantic import BaseModel
4
 
5
- file_name = "zephyr-7b-beta.Q4_K_S.gguf"
6
- llm = AutoModelForCausalLM.from_pretrained(file_name,
7
- model_type='mistral',
8
- max_new_tokens = 1096,
9
- threads = 3,
10
- )
11
 
12
- #Pydantic object
13
  class validation(BaseModel):
14
  prompt: str
15
- #Fast API
16
 
17
  app = FastAPI()
18
 
 
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.'
@@ -23,4 +20,4 @@ async def stream(item: validation):
23
  user, assistant = "<|user|>", "<|assistant|>"
24
  prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt}{E_INST}\n{assistant}\n"
25
 
26
- return llm(prompt)
 
1
+ from llama_cpp import Llama
2
  from fastapi import FastAPI
3
  from pydantic import BaseModel
4
 
5
+ model_file = "zephyr-7b-beta.Q4_K_S.gguf"
6
+ llm = Llama(model_path=model_file, n_ctx=512, n_batch=126)
7
+
 
 
 
8
 
 
9
  class validation(BaseModel):
10
  prompt: str
11
+
12
 
13
  app = FastAPI()
14
 
15
+
16
  @app.post("/llm_on_cpu")
17
  async def stream(item: validation):
18
  system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
 
20
  user, assistant = "<|user|>", "<|assistant|>"
21
  prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt}{E_INST}\n{assistant}\n"
22
 
23
+ return llm("What is an LLM?", max_tokens=100)
requirements.txt CHANGED
@@ -5,4 +5,4 @@ uvicorn
5
  requests
6
  python-dotenv
7
  ctransformers
8
- huggingface-hub
 
5
  requests
6
  python-dotenv
7
  ctransformers
8
+ llama-cpp-python