Spaces:
Sleeping
Sleeping
Commit ·
96d3de1
1
Parent(s): cc0b687
switched embedding models
Browse files
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
app.py
CHANGED
|
@@ -12,34 +12,38 @@ from typing import cast
|
|
| 12 |
import os
|
| 13 |
|
| 14 |
from dotenv import load_dotenv
|
|
|
|
| 15 |
load_dotenv()
|
| 16 |
|
| 17 |
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 18 |
-
|
|
|
|
| 19 |
vector_store = InMemoryVectorStore(embedding_model)
|
| 20 |
|
| 21 |
|
| 22 |
def load_sys_prompt(file_path="system_message.txt"):
|
| 23 |
-
with open(file_path,
|
| 24 |
return f.read().strip()
|
| 25 |
|
|
|
|
| 26 |
system_prompt = load_sys_prompt()
|
| 27 |
|
|
|
|
| 28 |
@tool(response_format="content_and_artifact")
|
| 29 |
def retrieve_context(query: str) -> str:
|
| 30 |
-
"""Call this tool ONLY when the user asks specific questions about Jake's
|
| 31 |
-
career, skills, experience, or resume.
|
| 32 |
-
|
| 33 |
DO NOT call this tool for greetings, small talk, or general questions.
|
| 34 |
"""
|
| 35 |
|
| 36 |
-
print(f"DEBUG: Tool called with query: {query}")
|
| 37 |
retrieved_docs = vector_store.similarity_search(query, k=2)
|
| 38 |
|
| 39 |
if not retrieved_docs:
|
| 40 |
print("DEBUG: No documents found in vector store!")
|
| 41 |
return "No relevant documents found.", []
|
| 42 |
-
|
| 43 |
print(f"{len(retrieved_docs)} document(s) found in vector store.")
|
| 44 |
print(f"First document: {retrieved_docs[0].page_content[:50]}...")
|
| 45 |
|
|
@@ -49,17 +53,18 @@ def retrieve_context(query: str) -> str:
|
|
| 49 |
)
|
| 50 |
return serialized, retrieved_docs
|
| 51 |
|
|
|
|
| 52 |
@cl.on_chat_start
|
| 53 |
async def on_chat_start():
|
| 54 |
|
| 55 |
try:
|
| 56 |
-
|
| 57 |
snapshot_download(
|
| 58 |
repo_id="jakewatson91/sherlock-rag-docs",
|
| 59 |
repo_type="dataset",
|
| 60 |
local_dir="data/",
|
| 61 |
allow_patterns="*.pdf",
|
| 62 |
-
token=True
|
| 63 |
)
|
| 64 |
except Exception as e:
|
| 65 |
print(f"Error downloading data: {e}")
|
|
@@ -81,21 +86,20 @@ async def on_chat_start():
|
|
| 81 |
vector_store.add_documents(all_splits)
|
| 82 |
|
| 83 |
llm = init_chat_model(
|
| 84 |
-
model="moonshotai/kimi-k2-instruct-0905",
|
| 85 |
model_provider="groq",
|
| 86 |
streaming=True,
|
| 87 |
-
temperature=0
|
| 88 |
-
|
| 89 |
-
|
| 90 |
runnable = create_agent(
|
| 91 |
-
model=llm,
|
| 92 |
-
tools=[retrieve_context],
|
| 93 |
-
system_prompt=system_prompt
|
| 94 |
)
|
| 95 |
|
| 96 |
cl.user_session.set("runnable", runnable)
|
| 97 |
cl.user_session.set("memory", [])
|
| 98 |
|
|
|
|
| 99 |
# Send a response back to the user
|
| 100 |
@cl.on_message
|
| 101 |
async def on_message(message: cl.Message):
|
|
@@ -109,20 +113,16 @@ async def on_message(message: cl.Message):
|
|
| 109 |
async for msg, metadata in runnable.astream(
|
| 110 |
{"messages": memory},
|
| 111 |
stream_mode="messages",
|
| 112 |
-
config=RunnableConfig(
|
| 113 |
-
|
| 114 |
-
run_name="Sherlock Search")
|
| 115 |
-
):
|
| 116 |
-
|
| 117 |
if (
|
| 118 |
-
msg.content
|
| 119 |
-
and metadata.get("langgraph_node") == "model"
|
| 120 |
and not getattr(msg, "tool_calls", None)
|
| 121 |
-
|
| 122 |
-
|
| 123 |
print("METADATA: ", metadata)
|
| 124 |
print("MESSAGE: ", msg)
|
| 125 |
-
|
| 126 |
await res.stream_token(msg.content)
|
| 127 |
|
| 128 |
memory.append({"role": "assistant", "content": res.content})
|
|
@@ -130,11 +130,12 @@ async def on_message(message: cl.Message):
|
|
| 130 |
|
| 131 |
await res.send()
|
| 132 |
|
|
|
|
| 133 |
if __name__ == "__main__":
|
| 134 |
snapshot_download(
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
)
|
|
|
|
| 12 |
import os
|
| 13 |
|
| 14 |
from dotenv import load_dotenv
|
| 15 |
+
|
| 16 |
load_dotenv()
|
| 17 |
|
| 18 |
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
| 19 |
+
|
| 20 |
+
embedding_model = GoogleGenerativeAIEmbeddings(model="models/gemini-embedding-001")
|
| 21 |
vector_store = InMemoryVectorStore(embedding_model)
|
| 22 |
|
| 23 |
|
| 24 |
def load_sys_prompt(file_path="system_message.txt"):
|
| 25 |
+
with open(file_path, "r") as f:
|
| 26 |
return f.read().strip()
|
| 27 |
|
| 28 |
+
|
| 29 |
system_prompt = load_sys_prompt()
|
| 30 |
|
| 31 |
+
|
| 32 |
@tool(response_format="content_and_artifact")
|
| 33 |
def retrieve_context(query: str) -> str:
|
| 34 |
+
"""Call this tool ONLY when the user asks specific questions about Jake's
|
| 35 |
+
career, skills, experience, or resume.
|
| 36 |
+
|
| 37 |
DO NOT call this tool for greetings, small talk, or general questions.
|
| 38 |
"""
|
| 39 |
|
| 40 |
+
print(f"DEBUG: Tool called with query: {query}") # See this in your terminal
|
| 41 |
retrieved_docs = vector_store.similarity_search(query, k=2)
|
| 42 |
|
| 43 |
if not retrieved_docs:
|
| 44 |
print("DEBUG: No documents found in vector store!")
|
| 45 |
return "No relevant documents found.", []
|
| 46 |
+
|
| 47 |
print(f"{len(retrieved_docs)} document(s) found in vector store.")
|
| 48 |
print(f"First document: {retrieved_docs[0].page_content[:50]}...")
|
| 49 |
|
|
|
|
| 53 |
)
|
| 54 |
return serialized, retrieved_docs
|
| 55 |
|
| 56 |
+
|
| 57 |
@cl.on_chat_start
|
| 58 |
async def on_chat_start():
|
| 59 |
|
| 60 |
try:
|
| 61 |
+
# download rag data files from private HF dataset
|
| 62 |
snapshot_download(
|
| 63 |
repo_id="jakewatson91/sherlock-rag-docs",
|
| 64 |
repo_type="dataset",
|
| 65 |
local_dir="data/",
|
| 66 |
allow_patterns="*.pdf",
|
| 67 |
+
token=True,
|
| 68 |
)
|
| 69 |
except Exception as e:
|
| 70 |
print(f"Error downloading data: {e}")
|
|
|
|
| 86 |
vector_store.add_documents(all_splits)
|
| 87 |
|
| 88 |
llm = init_chat_model(
|
| 89 |
+
model="moonshotai/kimi-k2-instruct-0905",
|
| 90 |
model_provider="groq",
|
| 91 |
streaming=True,
|
| 92 |
+
temperature=0,
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
runnable = create_agent(
|
| 96 |
+
model=llm, tools=[retrieve_context], system_prompt=system_prompt
|
|
|
|
|
|
|
| 97 |
)
|
| 98 |
|
| 99 |
cl.user_session.set("runnable", runnable)
|
| 100 |
cl.user_session.set("memory", [])
|
| 101 |
|
| 102 |
+
|
| 103 |
# Send a response back to the user
|
| 104 |
@cl.on_message
|
| 105 |
async def on_message(message: cl.Message):
|
|
|
|
| 113 |
async for msg, metadata in runnable.astream(
|
| 114 |
{"messages": memory},
|
| 115 |
stream_mode="messages",
|
| 116 |
+
config=RunnableConfig(callbacks=[cb], run_name="Sherlock Search"),
|
| 117 |
+
):
|
|
|
|
|
|
|
|
|
|
| 118 |
if (
|
| 119 |
+
msg.content
|
| 120 |
+
and metadata.get("langgraph_node") == "model"
|
| 121 |
and not getattr(msg, "tool_calls", None)
|
| 122 |
+
):
|
|
|
|
| 123 |
print("METADATA: ", metadata)
|
| 124 |
print("MESSAGE: ", msg)
|
| 125 |
+
|
| 126 |
await res.stream_token(msg.content)
|
| 127 |
|
| 128 |
memory.append({"role": "assistant", "content": res.content})
|
|
|
|
| 130 |
|
| 131 |
await res.send()
|
| 132 |
|
| 133 |
+
|
| 134 |
if __name__ == "__main__":
|
| 135 |
snapshot_download(
|
| 136 |
+
repo_id="jakewatson91/sherlock-rag-docs",
|
| 137 |
+
repo_type="dataset",
|
| 138 |
+
local_dir="data/",
|
| 139 |
+
allow_patterns="*.pdf",
|
| 140 |
+
token=os.environ.get("HF_TOKEN"),
|
| 141 |
+
)
|