Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,22 @@
|
|
1 |
from vllm import LLM
|
2 |
from vllm.sampling_params import SamplingParams
|
3 |
-
import mergekit
|
4 |
from fastapi import FastAPI
|
5 |
from uvicorn import run
|
6 |
|
7 |
app = FastAPI()
|
8 |
|
9 |
model_name = "Hjgugugjhuhjggg/mergekit-ties-tzamfyy"
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
SYSTEM_PROMPT = "¡Hola! Soy un modelo de lenguaje avanzado. Estoy aquí para ayudarte con cualquier pregunta o tema que desees discutir. ¿En qué puedo ayudarte hoy?"
|
13 |
|
@@ -32,7 +41,6 @@ def divide_texto(texto, max_tokens=512):
|
|
32 |
async def chat(texto: str):
|
33 |
mensajes = divide_texto(texto)
|
34 |
|
35 |
-
# Nuevo mensaje
|
36 |
mensaje = {"role": "user", "content": []}
|
37 |
|
38 |
for mensaje_texto in mensajes:
|
@@ -45,11 +53,18 @@ async def chat(texto: str):
|
|
45 |
|
46 |
sampling_params = SamplingParams(max_tokens=512)
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
if __name__ == "__main__":
|
55 |
run(app, host="0.0.0.0", port=8000)
|
|
|
1 |
from vllm import LLM
|
2 |
from vllm.sampling_params import SamplingParams
|
|
|
3 |
from fastapi import FastAPI
|
4 |
from uvicorn import run
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
8 |
model_name = "Hjgugugjhuhjggg/mergekit-ties-tzamfyy"
|
9 |
+
|
10 |
+
# Verifica si mergekit tiene el atributo correcto
|
11 |
+
try:
|
12 |
+
import mergekit
|
13 |
+
if hasattr(mergekit, "MergeKitModel"):
|
14 |
+
mergekit_model = mergekit.MergeKitModel(model_name)
|
15 |
+
else:
|
16 |
+
raise ImportError("MergeKitModel no encontrado en mergekit. Verifica la instalación.")
|
17 |
+
except ImportError as e:
|
18 |
+
print(f"Error importando mergekit: {e}")
|
19 |
+
mergekit_model = None
|
20 |
|
21 |
SYSTEM_PROMPT = "¡Hola! Soy un modelo de lenguaje avanzado. Estoy aquí para ayudarte con cualquier pregunta o tema que desees discutir. ¿En qué puedo ayudarte hoy?"
|
22 |
|
|
|
41 |
async def chat(texto: str):
|
42 |
mensajes = divide_texto(texto)
|
43 |
|
|
|
44 |
mensaje = {"role": "user", "content": []}
|
45 |
|
46 |
for mensaje_texto in mensajes:
|
|
|
53 |
|
54 |
sampling_params = SamplingParams(max_tokens=512)
|
55 |
|
56 |
+
try:
|
57 |
+
llm = LLM(
|
58 |
+
model=mergekit_model if mergekit_model else model_name,
|
59 |
+
config_format="llama",
|
60 |
+
load_format="llama",
|
61 |
+
tokenizer_mode="llama",
|
62 |
+
tensor_parallel_size=8
|
63 |
+
)
|
64 |
+
outputs = llm.chat(messages, sampling_params=sampling_params)
|
65 |
+
return {"response": outputs[0].outputs[0].text}
|
66 |
+
except Exception as e:
|
67 |
+
return {"error": str(e)}
|
68 |
|
69 |
if __name__ == "__main__":
|
70 |
run(app, host="0.0.0.0", port=8000)
|