FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PrepGraph/app.py at main · 07Codex07/PrepGraph · GitHub
07Codex07
/
PrepGraph
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PrepGraph
/
app.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (27 loc) · 1.03 KB
Breadcrumbs
PrepGraph
/
app.py
Copy path
File metadata and controls
32 lines (27 loc) · 1.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import
gradio
as
gr
from
langchain_core
.
messages
import
HumanMessage
from
chatbot
import
chatbot
# compiled graph
def
chat_fn
(
message
,
history
):
try
:
# Send only the NEW user message; the checkpointer keeps the rest
response
=
chatbot
.
invoke
(
{
"messages"
: [
HumanMessage
(
content
=
message
)]},
config
=
{
"configurable"
: {
"thread_id"
:
"chat-session-1"
}}
)
# Get the latest AI reply from the returned state
messages
=
response
[
"messages"
]
# Prefer the last AI message explicitly:
ai
=
next
((
m
for
m
in
reversed
(
messages
)
if
getattr
(
m
,
"type"
,
""
)
==
"ai"
),
None
)
bot_text
=
ai
.
content
if
ai
else
messages
[
-
1
].
content
return
bot_text
except
Exception
as
e
:
return
f"⚠️ Error:
{
e
}
"
demo
=
gr
.
ChatInterface
(
fn
=
chat_fn
,
title
=
"LangGraph 🤖 Chatbot"
,
description
=
"A simple chatbot powered by LangGraph + Groq LLM"
,
theme
=
"soft"
,
type
=
"messages"
# avoids the deprecation warning
)
if
__name__
==
"__main__"
:
demo
.
launch
()
Back
|
FazBrowse Home
|
New Git URL