I’m new to LangChain and having issues with Langsmith tracking in my Colab notebook. My code runs fine but nothing shows up in the Langsmith dashboard.
from langchain_core.documents import Document
from langchain.chains.combine_documents import create_stuff_documents_chain
from langchain_community.document_loaders import WebBaseLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.prompts import ChatPromptTemplate
from langchain_community.vectorstores.faiss import FAISS
from langchain_openai import OpenAIEmbeddings
from langchain.chains import create_retrieval_chain
from langchain_core.messages import HumanMessage, AIMessage
from langchain_core.prompts import MessagesPlaceholder
def load_web_content(website_url):
web_loader = WebBaseLoader(website_url)
documents = web_loader.load()
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=500,
chunk_overlap=50
)
split_documents = text_splitter.split_documents(documents)
return split_documents
def setup_vector_store(documents):
embedding_model = OpenAIEmbeddings(model="text-embedding-ada-002")
vector_db = FAISS.from_documents(documents, embedding_model)
return vector_db
def build_chat_chain(vector_db):
system_prompt = ChatPromptTemplate.from_messages([
("system", "Please answer based on this context: {context}"),
MessagesPlaceholder(variable_name="history"),
("user", "{input}")
])
document_chain = create_stuff_documents_chain(
llm=chat_model,
prompt=system_prompt
)
search_retriever = vector_db.as_retriever(search_kwargs={"k": 2})
final_chain = create_retrieval_chain(search_retriever, document_chain)
return final_chain
def handle_user_message(chain, user_question, conversation_history):
result = chain.invoke({
"input": user_question,
"history": conversation_history
})
return result["answer"]
conversation_history = []
if __name__ == "__main__":
web_docs = load_web_content("https://docs.smith.langchain.com/")
db = setup_vector_store(web_docs)
chat_chain = build_chat_chain(db)
while True:
question = input("Ask: ")
if question.lower() == "quit":
break
answer = handle_user_message(chat_chain, question, conversation_history)
conversation_history.append(HumanMessage(content=question))
conversation_history.append(AIMessage(content=answer))
print("Answer:", answer)
The chatbot works perfectly but I don’t see any traces in Langsmith. What am I missing here? Any help would be great!