Spaces:
Running
Running
LangServe deploy attempt 1
Browse files- Dockerfile +2 -2
- app/__init__.py +0 -0
- app/__pycache__/__init__.cpython-311.pyc +0 -0
- app/__pycache__/server.cpython-311.pyc +0 -0
- app/server.py +56 -0
- langserve_index/index.faiss +0 -0
- langserve_index/index.pkl +3 -0
- packages/README.md +0 -0
- pyproject.toml +23 -0
Dockerfile
CHANGED
@@ -16,6 +16,6 @@ COPY ./app ./app
|
|
16 |
|
17 |
RUN poetry install --no-interaction --no-ansi
|
18 |
|
19 |
-
EXPOSE
|
20 |
|
21 |
-
CMD exec uvicorn app.server:app --host 0.0.0.0 --port
|
|
|
16 |
|
17 |
RUN poetry install --no-interaction --no-ansi
|
18 |
|
19 |
+
EXPOSE 7860
|
20 |
|
21 |
+
CMD exec uvicorn app.server:app --host 0.0.0.0 --port 7860
|
app/__init__.py
ADDED
File without changes
|
app/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (229 Bytes). View file
|
|
app/__pycache__/server.cpython-311.pyc
ADDED
Binary file (2.49 kB). View file
|
|
app/server.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from fastapi.responses import RedirectResponse
|
3 |
+
from langserve import add_routes
|
4 |
+
from langchain.vectorstores import FAISS
|
5 |
+
from langchain.llms import HuggingFaceHub
|
6 |
+
import os
|
7 |
+
from langchain.prompts import ChatPromptTemplate
|
8 |
+
from langchain_core.runnables import RunnablePassthrough, RunnableParallel
|
9 |
+
from langchain.schema import StrOutputParser
|
10 |
+
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
|
11 |
+
|
12 |
+
app = FastAPI()
|
13 |
+
|
14 |
+
hf_llm = HuggingFaceHub(
|
15 |
+
repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
16 |
+
huggingfacehub_api_token=os.environ["HF_TOKEN"],
|
17 |
+
task="text-generation",
|
18 |
+
model_kwargs={"temperature":0.01, "max_new_tokens" : 250}
|
19 |
+
)
|
20 |
+
|
21 |
+
embedding_model_id = 'WhereIsAI/UAE-Large-V1'
|
22 |
+
embeddings_model = HuggingFaceEmbeddings(model_name=embedding_model_id)
|
23 |
+
|
24 |
+
faiss_index = FAISS.load_local("../langserve_index", embeddings_model)
|
25 |
+
retriever = faiss_index.as_retriever()
|
26 |
+
# retriever = faiss_index.as_retriever(search_kwargs={"k": 2})
|
27 |
+
|
28 |
+
prompt_template = """\
|
29 |
+
Use the provided context to answer the user's question. If you don't know the answer, say you don't know.
|
30 |
+
|
31 |
+
Context:
|
32 |
+
{context}
|
33 |
+
|
34 |
+
Question:
|
35 |
+
{question}"""
|
36 |
+
|
37 |
+
rag_prompt = ChatPromptTemplate.from_template(prompt_template)
|
38 |
+
|
39 |
+
entry_point_chain = RunnableParallel(
|
40 |
+
{"context": retriever, "question": RunnablePassthrough()}
|
41 |
+
)
|
42 |
+
rag_chain = entry_point_chain | rag_prompt | hf_llm | StrOutputParser()
|
43 |
+
|
44 |
+
@app.get("/")
|
45 |
+
async def redirect_root_to_docs():
|
46 |
+
return RedirectResponse("/docs")
|
47 |
+
|
48 |
+
|
49 |
+
# Edit this to add the chain you want to add
|
50 |
+
add_routes(app, rag_chain, path="/rag")
|
51 |
+
|
52 |
+
if __name__ == "__main__":
|
53 |
+
import uvicorn
|
54 |
+
|
55 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
56 |
+
# uvicorn.run(app, host="0.0.0.0", port=7860)
|
langserve_index/index.faiss
ADDED
Binary file (102 kB). View file
|
|
langserve_index/index.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1474088fe4c981d0e0b77b81ec35863e3d177cc59cb262f60b2cc067cd06a0b1
|
3 |
+
size 13050
|
packages/README.md
ADDED
File without changes
|
pyproject.toml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "langserve_test"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = ""
|
5 |
+
authors = ["Your Name <[email protected]>"]
|
6 |
+
readme = "README.md"
|
7 |
+
packages = [
|
8 |
+
{ include = "app" },
|
9 |
+
]
|
10 |
+
|
11 |
+
[tool.poetry.dependencies]
|
12 |
+
python = "^3.11"
|
13 |
+
uvicorn = "^0.23.2"
|
14 |
+
langserve = {extras = ["server"], version = ">=0.0.30"}
|
15 |
+
pydantic = "<2"
|
16 |
+
|
17 |
+
|
18 |
+
[tool.poetry.group.dev.dependencies]
|
19 |
+
langchain-cli = ">=0.0.15"
|
20 |
+
|
21 |
+
[build-system]
|
22 |
+
requires = ["poetry-core"]
|
23 |
+
build-backend = "poetry.core.masonry.api"
|