Skip to content

Commit 8304e3f

Browse files
authored
Merge branch 'main' into main
2 parents 418c729 + c4969e4 commit 8304e3f

File tree

11 files changed

+75
-42
lines changed

11 files changed

+75
-42
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Follow these steps to get the application running locally for development and te
2828
**1. Prerequisites:**
2929

3030
- Node.js and npm (or yarn/pnpm)
31-
- Python 3.8+
31+
- Python 3.11+
3232
- **`GEMINI_API_KEY`**: The backend agent requires a Google Gemini API key.
3333
1. Navigate to the `backend/` directory.
3434
2. Create a file named `.env` by copying the `backend/.env.example` file.

backend/src/agent/app.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# mypy: disable - error - code = "no-untyped-def,misc"
22
import pathlib
3-
from fastapi import FastAPI, Request, Response
3+
from fastapi import FastAPI, Response
44
from fastapi.staticfiles import StaticFiles
5-
import fastapi.exceptions
65

76
# Define the FastAPI app
87
app = FastAPI()
@@ -18,7 +17,6 @@ def create_frontend_router(build_dir="../frontend/dist"):
1817
A Starlette application serving the frontend.
1918
"""
2019
build_path = pathlib.Path(__file__).parent.parent.parent / build_dir
21-
static_files_path = build_path / "assets" # Vite uses 'assets' subdir
2220

2321
if not build_path.is_dir() or not (build_path / "index.html").is_file():
2422
print(
@@ -36,21 +34,7 @@ async def dummy_frontend(request):
3634

3735
return Route("/{path:path}", endpoint=dummy_frontend)
3836

39-
build_dir = pathlib.Path(build_dir)
40-
41-
react = FastAPI(openapi_url="")
42-
react.mount(
43-
"/assets", StaticFiles(directory=static_files_path), name="static_assets"
44-
)
45-
46-
@react.get("/{path:path}")
47-
async def handle_catch_all(request: Request, path: str):
48-
fp = build_path / path
49-
if not fp.exists() or not fp.is_file():
50-
fp = build_path / "index.html"
51-
return fastapi.responses.FileResponse(fp)
52-
53-
return react
37+
return StaticFiles(directory=build_path, html=True)
5438

5539

5640
# Mount the frontend under /app to not conflict with the LangGraph API routes

backend/src/agent/configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ class Configuration(BaseModel):
1616
)
1717

1818
reflection_model: str = Field(
19-
default="gemini-2.5-flash-preview-04-17",
19+
default="gemini-2.5-flash",
2020
metadata={
2121
"description": "The name of the language model to use for the agent's reflection."
2222
},
2323
)
2424

2525
answer_model: str = Field(
26-
default="gemini-2.5-pro-preview-05-06",
26+
default="gemini-2.5-pro",
2727
metadata={
2828
"description": "The name of the language model to use for the agent's answer."
2929
},

backend/src/agent/graph.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def generate_query(state: OverallState, config: RunnableConfig) -> QueryGenerati
7878
)
7979
# Generate the search queries
8080
result = structured_llm.invoke(formatted_prompt)
81-
return {"query_list": result.query}
81+
return {"search_query": result.query}
8282

8383

8484
def continue_to_web_research(state: QueryGenerationState):
@@ -88,7 +88,7 @@ def continue_to_web_research(state: QueryGenerationState):
8888
"""
8989
return [
9090
Send("web_research", {"search_query": search_query, "id": int(idx)})
91-
for idx, search_query in enumerate(state["query_list"])
91+
for idx, search_query in enumerate(state["search_query"])
9292
]
9393

9494

@@ -153,7 +153,7 @@ def reflection(state: OverallState, config: RunnableConfig) -> ReflectionState:
153153
configurable = Configuration.from_runnable_config(config)
154154
# Increment the research loop count and get the reasoning model
155155
state["research_loop_count"] = state.get("research_loop_count", 0) + 1
156-
reasoning_model = state.get("reasoning_model") or configurable.reasoning_model
156+
reasoning_model = state.get("reasoning_model", configurable.reflection_model)
157157

158158
# Format the prompt
159159
current_date = get_current_date()
@@ -231,7 +231,7 @@ def finalize_answer(state: OverallState, config: RunnableConfig):
231231
Dictionary with state update, including running_summary key containing the formatted final summary with sources
232232
"""
233233
configurable = Configuration.from_runnable_config(config)
234-
reasoning_model = state.get("reasoning_model") or configurable.reasoning_model
234+
reasoning_model = state.get("reasoning_model") or configurable.answer_model
235235

236236
# Format the prompt
237237
current_date = get_current_date()

backend/src/agent/state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Query(TypedDict):
3737

3838

3939
class QueryGenerationState(TypedDict):
40-
query_list: list[Query]
40+
search_query: list[Query]
4141

4242

4343
class WebSearchState(TypedDict):

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ volumes:
44
services:
55
langgraph-redis:
66
image: docker.io/redis:6
7+
container_name: langgraph-redis
78
healthcheck:
89
test: redis-cli ping
910
interval: 5s
1011
timeout: 1s
1112
retries: 5
1213
langgraph-postgres:
1314
image: docker.io/postgres:16
15+
container_name: langgraph-postgres
1416
ports:
1517
- "5433:5432"
1618
environment:
@@ -27,6 +29,7 @@ services:
2729
interval: 5s
2830
langgraph-api:
2931
image: gemini-fullstack-langgraph
32+
container_name: langgraph-api
3033
ports:
3134
- "8123:8000"
3235
depends_on:

frontend/src/App.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useState, useEffect, useRef, useCallback } from "react";
44
import { ProcessedEvent } from "@/components/ActivityTimeline";
55
import { WelcomeScreen } from "@/components/WelcomeScreen";
66
import { ChatMessagesView } from "@/components/ChatMessagesView";
7+
import { Button } from "@/components/ui/button";
78

89
export default function App() {
910
const [processedEventsTimeline, setProcessedEventsTimeline] = useState<
@@ -14,7 +15,7 @@ export default function App() {
1415
>({});
1516
const scrollAreaRef = useRef<HTMLDivElement>(null);
1617
const hasFinalizeEventOccurredRef = useRef(false);
17-
18+
const [error, setError] = useState<string | null>(null);
1819
const thread = useStream<{
1920
messages: Message[];
2021
initial_search_query_count: number;
@@ -26,15 +27,12 @@ export default function App() {
2627
: "http://localhost:8123",
2728
assistantId: "agent",
2829
messagesKey: "messages",
29-
onFinish: (event: any) => {
30-
console.log(event);
31-
},
3230
onUpdateEvent: (event: any) => {
3331
let processedEvent: ProcessedEvent | null = null;
3432
if (event.generate_query) {
3533
processedEvent = {
3634
title: "Generating Search Queries",
37-
data: event.generate_query.query_list.join(", "),
35+
data: event.generate_query?.search_query?.join(", ") || "",
3836
};
3937
} else if (event.web_research) {
4038
const sources = event.web_research.sources_gathered || [];
@@ -52,11 +50,7 @@ export default function App() {
5250
} else if (event.reflection) {
5351
processedEvent = {
5452
title: "Reflection",
55-
data: event.reflection.is_sufficient
56-
? "Search successful, generating final answer."
57-
: `Need more information, searching for ${event.reflection.follow_up_queries.join(
58-
", "
59-
)}`,
53+
data: "Analysing Web Research Results",
6054
};
6155
} else if (event.finalize_answer) {
6256
processedEvent = {
@@ -72,6 +66,9 @@ export default function App() {
7266
]);
7367
}
7468
},
69+
onError: (error: any) => {
70+
setError(error.message);
71+
},
7572
});
7673

7774
useEffect(() => {
@@ -161,6 +158,20 @@ export default function App() {
161158
isLoading={thread.isLoading}
162159
onCancel={handleCancel}
163160
/>
161+
) : error ? (
162+
<div className="flex flex-col items-center justify-center h-full">
163+
<div className="flex flex-col items-center justify-center gap-4">
164+
<h1 className="text-2xl text-red-400 font-bold">Error</h1>
165+
<p className="text-red-400">{JSON.stringify(error)}</p>
166+
167+
<Button
168+
variant="destructive"
169+
onClick={() => window.location.reload()}
170+
>
171+
Retry
172+
</Button>
173+
</div>
174+
</div>
164175
) : (
165176
<ChatMessagesView
166177
messages={thread.messages}

frontend/src/components/ChatMessagesView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ const AiMessageBubble: React.FC<AiMessageBubbleProps> = ({
203203
</ReactMarkdown>
204204
<Button
205205
variant="default"
206-
className="cursor-pointer bg-neutral-700 border-neutral-600 text-neutral-300 self-end"
206+
className={`cursor-pointer bg-neutral-700 border-neutral-600 text-neutral-300 self-end ${
207+
message.content.length > 0 ? "visible" : "hidden"
208+
}`}
207209
onClick={() =>
208210
handleCopy(
209211
typeof message.content === "string"
@@ -250,7 +252,6 @@ export function ChatMessagesView({
250252
console.error("Failed to copy text: ", err);
251253
}
252254
};
253-
254255
return (
255256
<div className="flex flex-col h-full">
256257
<ScrollArea className="flex-1 overflow-y-auto" ref={scrollAreaRef}>

frontend/src/components/InputForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const InputForm: React.FC<InputFormProps> = ({
4949
return (
5050
<form
5151
onSubmit={handleInternalSubmit}
52-
className={`flex flex-col gap-2 p-3 `}
52+
className={`flex flex-col gap-2 p-3 pb-4`}
5353
>
5454
<div
5555
className={`flex flex-row items-center justify-between text-white rounded-3xl rounded-bl-sm ${

frontend/src/components/ui/scroll-area.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function ScrollArea({
1717
<ScrollAreaPrimitive.Viewport
1818
data-slot="scroll-area-viewport"
1919
className="focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
20+
style={{ overscrollBehavior: 'none' }}
2021
>
2122
{children}
2223
</ScrollAreaPrimitive.Viewport>
@@ -38,16 +39,16 @@ function ScrollBar({
3839
className={cn(
3940
"flex touch-none p-px transition-colors select-none",
4041
orientation === "vertical" &&
41-
"h-full w-2.5 border-l border-l-transparent",
42+
"h-full w-1.5 border-l border-l-transparent",
4243
orientation === "horizontal" &&
43-
"h-2.5 flex-col border-t border-t-transparent",
44+
"h-1.5 flex-col border-t border-t-transparent",
4445
className
4546
)}
4647
{...props}
4748
>
4849
<ScrollAreaPrimitive.ScrollAreaThumb
4950
data-slot="scroll-area-thumb"
50-
className="bg-border relative flex-1 rounded-full"
51+
className="bg-neutral-600/30 relative flex-1 rounded-full"
5152
/>
5253
</ScrollAreaPrimitive.ScrollAreaScrollbar>
5354
)

0 commit comments

Comments
 (0)