Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, AIMessageChunk, ToolMessage
from dotenv import load_dotenv
from langchain_groq import ChatGroq
from langchain_community.tools.tavily_search import TavilySearchResults
from fastapi import FastAPI, Query
from fastapi.responses import StreamingResponse
Expand Down Expand Up @@ -74,6 +75,15 @@ async def tool_node(state):
# Add the tool messages to the state
return {"messages": tool_messages}

#adding the system prompt to protec the ai from hallucinating and stop it from searching everything online
system_prompt =SystemMessage(content=
"You are a helpful assistant. "
"Use the search tool *only if the user asks about factual, external knowledge* "
"that you are not confident about. "
"For casual conversation (like greetings, introductions, chit-chat), "
"do NOT use any tools."
)

graph_builder = StateGraph(State)

graph_builder.add_node("model", model)
Expand Down Expand Up @@ -120,7 +130,7 @@ async def generate_chat_responses(message: str, checkpoint_id: Optional[str] = N

# Initialize with first message
events = graph.astream_events(
{"messages": [HumanMessage(content=message)]},
{"messages": [system_prompt,HumanMessage(content=message)]},
version="v2",
config=config
)
Expand Down
1 change: 1 addition & 0 deletions server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ uvicorn==0.34.1
xxhash==3.5.0
yarl==1.20.0
zstandard==0.23.0
langchain-tavily==0.2.11