Spaces:
Paused
Paused
jeevan
commited on
Commit
·
31e2acf
1
Parent(s):
8e4dbc7
enabled langsmith
Browse files- .gitignore +1 -4
- app.py +8 -2
- requirements.txt +0 -1
.gitignore
CHANGED
|
@@ -1,8 +1,5 @@
|
|
| 1 |
venv/*
|
| 2 |
.env
|
| 3 |
-
__pycache__
|
| 4 |
-
__pycache__/app.cpython-311.pyc
|
| 5 |
-
__pycache__/Chunking.cpython-39.pyc
|
| 6 |
-
__pycache__/Chunking.cpython-311.pyc
|
| 7 |
.vscode/launch.json
|
| 8 |
.vscode/settings.json
|
|
|
|
| 1 |
venv/*
|
| 2 |
.env
|
| 3 |
+
__pycache__/*
|
|
|
|
|
|
|
|
|
|
| 4 |
.vscode/launch.json
|
| 5 |
.vscode/settings.json
|
app.py
CHANGED
|
@@ -12,12 +12,17 @@ from langchain_community.vectorstores import Qdrant
|
|
| 12 |
import chainlit as cl
|
| 13 |
from chainlit.types import AskFileResponse
|
| 14 |
from chainlit.cli import run_chainlit
|
| 15 |
-
|
| 16 |
import tempfile
|
| 17 |
|
| 18 |
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
|
| 19 |
GPT_MODEL = "gpt-4o-mini"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Utility functions
|
| 22 |
def save_file(file: AskFileResponse,file_ext:str) -> str:
|
| 23 |
if file_ext == "application/pdf":
|
|
@@ -78,6 +83,7 @@ async def on_chat_start():
|
|
| 78 |
## Load file and split into chunks
|
| 79 |
msg = cl.Message(content=f"Processing `{files[0].name}`...")
|
| 80 |
await msg.send()
|
|
|
|
| 81 |
current_file_path = save_file(files[0], files[0].type)
|
| 82 |
loader_splitter = TextLoaderAndSplitterWrapper(ChunkingStrategy.RECURSIVE_CHARACTER_CHAR_SPLITTER, current_file_path)
|
| 83 |
documents = loader_splitter.load_documents()
|
|
@@ -116,7 +122,7 @@ async def on_chat_start():
|
|
| 116 |
async def main(message: cl.Message):
|
| 117 |
chain = cl.user_session.get("chain")
|
| 118 |
msg = cl.Message(content="")
|
| 119 |
-
response = chain.invoke({"question": message.content})
|
| 120 |
msg.content= response["response"].content
|
| 121 |
await msg.send()
|
| 122 |
cl.user_session.set("chain", chain)
|
|
|
|
| 12 |
import chainlit as cl
|
| 13 |
from chainlit.types import AskFileResponse
|
| 14 |
from chainlit.cli import run_chainlit
|
| 15 |
+
from uuid import uuid4
|
| 16 |
import tempfile
|
| 17 |
|
| 18 |
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
|
| 19 |
GPT_MODEL = "gpt-4o-mini"
|
| 20 |
|
| 21 |
+
# Used for Langsmith
|
| 22 |
+
unique_id = uuid4().hex[0:8]
|
| 23 |
+
os.environ["LANGCHAIN_TRACING_V2"] = "true"
|
| 24 |
+
os.environ["LANGCHAIN_PROJECT"] = f"LangSmith LCEL RAG - {unique_id}"
|
| 25 |
+
|
| 26 |
# Utility functions
|
| 27 |
def save_file(file: AskFileResponse,file_ext:str) -> str:
|
| 28 |
if file_ext == "application/pdf":
|
|
|
|
| 83 |
## Load file and split into chunks
|
| 84 |
msg = cl.Message(content=f"Processing `{files[0].name}`...")
|
| 85 |
await msg.send()
|
| 86 |
+
|
| 87 |
current_file_path = save_file(files[0], files[0].type)
|
| 88 |
loader_splitter = TextLoaderAndSplitterWrapper(ChunkingStrategy.RECURSIVE_CHARACTER_CHAR_SPLITTER, current_file_path)
|
| 89 |
documents = loader_splitter.load_documents()
|
|
|
|
| 122 |
async def main(message: cl.Message):
|
| 123 |
chain = cl.user_session.get("chain")
|
| 124 |
msg = cl.Message(content="")
|
| 125 |
+
response = chain.invoke({"question": message.content}, {"tags" : ["Demo Run"]})
|
| 126 |
msg.content= response["response"].content
|
| 127 |
await msg.send()
|
| 128 |
cl.user_session.set("chain", chain)
|
requirements.txt
CHANGED
|
@@ -114,4 +114,3 @@ wrapt==1.16.0
|
|
| 114 |
wsproto==1.2.0
|
| 115 |
yarl==1.9.6
|
| 116 |
zipp==3.20.1
|
| 117 |
-
|
|
|
|
| 114 |
wsproto==1.2.0
|
| 115 |
yarl==1.9.6
|
| 116 |
zipp==3.20.1
|
|
|