Petro commited on
Commit
48afe02
·
1 Parent(s): 461052c

First model version

Browse files
Files changed (2) hide show
  1. main.py +13 -5
  2. requirements.txt +1 -1
main.py CHANGED
@@ -1,18 +1,26 @@
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,4 +28,4 @@ async def stream(item: validation):
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)
 
1
+ from langchain.llms import CTransformers
2
  from fastapi import FastAPI
3
  from pydantic import BaseModel
4
 
5
+ file_name = "zephyr-7b-beta.Q4_K_S.gguf"
6
+ config = {
7
+ "max_new_tokens": 1024,
8
+ "model_type": "mistral",
9
+ # "stream": True,
10
+ }
11
+ llm = CTransformers(
12
+ model=file_name,
13
+ **config
14
+ )
15
 
16
 
17
  class validation(BaseModel):
18
  prompt: str
19
+ #Fast API
20
 
21
 
22
  app = FastAPI()
23
 
 
24
  @app.post("/llm_on_cpu")
25
  async def stream(item: validation):
26
  system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
 
28
  user, assistant = "<|user|>", "<|assistant|>"
29
  prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt}{E_INST}\n{assistant}\n"
30
 
31
+ return llm(prompt)
requirements.txt CHANGED
@@ -5,4 +5,4 @@ uvicorn
5
  requests
6
  python-dotenv
7
  ctransformers
8
- llama-cpp-python
 
5
  requests
6
  python-dotenv
7
  ctransformers
8
+ langchain