Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,10 @@ from pydantic import BaseModel
|
|
3 |
from typing import Optional
|
4 |
|
5 |
from llama_index.core import Document, ServiceContext
|
6 |
-
from llama_index.llms.
|
7 |
-
from llama_index.core.node_parser import SemanticSplitterNodeParser
|
8 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
|
|
|
|
9 |
import os
|
10 |
|
11 |
app = FastAPI()
|
@@ -19,19 +20,20 @@ class ChunkRequest(BaseModel):
|
|
19 |
type: Optional[str] = None
|
20 |
|
21 |
# 🔹 Endpoint principal
|
|
|
22 |
@app.post("/chunk")
|
23 |
async def chunk_text(data: ChunkRequest):
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
29 |
)
|
30 |
|
31 |
-
# 🔹 Embedding open source gratuit
|
32 |
embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
|
33 |
|
34 |
-
# 🔹 Service Context avec LLM + embeddings
|
35 |
service_context = ServiceContext.from_defaults(
|
36 |
llm=llm,
|
37 |
embed_model=embed_model
|
@@ -51,3 +53,8 @@ async def chunk_text(data: ChunkRequest):
|
|
51 |
}
|
52 |
except Exception as e:
|
53 |
return {"error": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from typing import Optional
|
4 |
|
5 |
from llama_index.core import Document, ServiceContext
|
6 |
+
from llama_index.llms.llama_cpp import LlamaCPP
|
|
|
7 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
8 |
+
from llama_index.core.node_parser import SemanticSplitterNodeParser
|
9 |
+
|
10 |
import os
|
11 |
|
12 |
app = FastAPI()
|
|
|
20 |
type: Optional[str] = None
|
21 |
|
22 |
# 🔹 Endpoint principal
|
23 |
+
|
24 |
@app.post("/chunk")
|
25 |
async def chunk_text(data: ChunkRequest):
|
26 |
+
llm = LlamaCPP(
|
27 |
+
model_path="/models/mistral-7b-instruct.gguf",
|
28 |
+
temperature=0.1,
|
29 |
+
max_new_tokens=512,
|
30 |
+
context_window=2048,
|
31 |
+
generate_kwargs={"top_p": 0.95},
|
32 |
+
model_kwargs={"n_gpu_layers": 1},
|
33 |
)
|
34 |
|
|
|
35 |
embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
|
36 |
|
|
|
37 |
service_context = ServiceContext.from_defaults(
|
38 |
llm=llm,
|
39 |
embed_model=embed_model
|
|
|
53 |
}
|
54 |
except Exception as e:
|
55 |
return {"error": str(e)}
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
+
|