Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ from fastapi import FastAPI, HTTPException
|
|
2 |
from pydantic import BaseModel
|
3 |
from huggingface_hub import InferenceClient
|
4 |
import os
|
|
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
@@ -40,58 +41,4 @@ async def chat(request: ChatRequest):
|
|
40 |
|
41 |
return {"response": response.choices[0].message.content}
|
42 |
except Exception as e:
|
43 |
-
raise HTTPException(status_code=500, detail=str(e))
|
44 |
-
|
45 |
-
# from fastapi import FastAPI, HTTPException
|
46 |
-
# from pydantic import BaseModel
|
47 |
-
# from huggingface_hub import InferenceClient
|
48 |
-
# import os
|
49 |
-
|
50 |
-
# app = FastAPI()
|
51 |
-
|
52 |
-
# # Get the token from the environment variable
|
53 |
-
# hf_token = os.environ.get("HF_TOKEN")
|
54 |
-
|
55 |
-
# if hf_token:
|
56 |
-
# client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=hf_token)
|
57 |
-
# else:
|
58 |
-
# raise ValueError("HF_TOKEN environment variable not set. Please add it as a secret in your Hugging Face Space.")
|
59 |
-
|
60 |
-
# # Rest of your code...
|
61 |
-
|
62 |
-
# class ChatRequest(BaseModel):
|
63 |
-
# message: str
|
64 |
-
# history: list[tuple[str, str]] = []
|
65 |
-
# system_message: str = "You are a friendly Chatbot."
|
66 |
-
# max_tokens: int = 512
|
67 |
-
# temperature: float = 0.7
|
68 |
-
# top_p: float = 0.95
|
69 |
-
|
70 |
-
# class ChatResponse(BaseModel):
|
71 |
-
# response: str
|
72 |
-
|
73 |
-
# @app.post("/chat", response_model=ChatResponse)
|
74 |
-
# async def chat(request: ChatRequest):
|
75 |
-
# try:
|
76 |
-
# messages = [{"role": "system", "content": request.system_message}]
|
77 |
-
# for val in request.history:
|
78 |
-
# if val[0]:
|
79 |
-
# messages.append({"role": "user", "content": val[0]})
|
80 |
-
# if val[1]:
|
81 |
-
# messages.append({"role": "assistant", "content": val[1]})
|
82 |
-
# messages.append({"role": "user", "content": request.message})
|
83 |
-
|
84 |
-
# response = ""
|
85 |
-
# for message in client.chat_completion(
|
86 |
-
# messages,
|
87 |
-
# max_tokens=request.max_tokens,
|
88 |
-
# stream=True,
|
89 |
-
# temperature=request.temperature,
|
90 |
-
# top_p=request.top_p,
|
91 |
-
# ):
|
92 |
-
# token = message.choices[0].delta.content
|
93 |
-
# response += token
|
94 |
-
|
95 |
-
# return {"response": response}
|
96 |
-
# except Exception as e:
|
97 |
-
# raise HTTPException(status_code=500, detail=str(e))
|
|
|
2 |
from pydantic import BaseModel
|
3 |
from huggingface_hub import InferenceClient
|
4 |
import os
|
5 |
+
import ollama
|
6 |
|
7 |
app = FastAPI()
|
8 |
|
|
|
41 |
|
42 |
return {"response": response.choices[0].message.content}
|
43 |
except Exception as e:
|
44 |
+
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|