ky32/Email_Classification
0
1from fastapi import FastAPI, HTTPException2from transformers import AutoModelForCausalLM, AutoTokenizer3import os4import copy5import time6import llama_cpp7from llama_cpp import Llama8from huggingface_hub import hf_hub_download 9 10import transformers11import torch12 13 14app = FastAPI()15 16"""17model_path = hf_hub_download(18 repo_id="TheBloke/Mistral-7B-v0.1-GGUF",19 filename="mistral-7b-v0.1.Q4_K_M.gguf")20 21llm = Llama(22 model_path=model_path,23 n_ctx=2048,24 n_threads=225) 26"""27 28@app.get("/")29async def generate_text():30 try:31 """32 output = llm(33 "Q: Name the planets in the solar system? A: ", 34 max_tokens=32, 35 stop=["Q:", "\n"], 36 echo=True)37 output = llm.create_chat_completion(38 messages=[39 {40 "role": "system",41 "content": "You are a helpful assistant that outputs in JSON.",42 },43 {"role": "user", "content": "Who won the world series in 2020"},44 ],45 response_format={46 "type": "json_object",47 },48 temperature=0.7,49)50 """51 model_id = "meta-llama/Meta-Llama-3-8B"52 pipeline = transformers.pipeline("text-generation", model=model_id, model_kwargs={"torch_dtype": torch.bfloat16}, device_map="auto")53 pipeline("Hey how are you doing today?")54 return pipeline("Hey how are you doing today?")55 except Exception as e:56 raise HTTPException(status_code=500, detail=str(e))