Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
Chatbot_dialogue
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Việt Anh
Chatbot_dialogue
Commits
615fddf5
Commit
615fddf5
authored
5 months ago
by
Anh26535D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
suacode
parent
5a242a6c
master
No related merge requests found
Pipeline
#275
failed with stages
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
app.py
app.py
+13
-2
No files found.
app.py
View file @
615fddf5
...
...
@@ -33,13 +33,24 @@ context_memory = []
# yield gr.update(value=chat_history)
def
generate_response_stream
(
chat_history
,
user_input
):
global
context_memory
try
:
sql_query
=
generate_query_with_gemini
(
user_input
,
api_key
,
model
,
index
,
documents
)
# Thêm câu hỏi của người dùng vào context_memory
context_memory
.
append
({
"role"
:
"user"
,
"content"
:
user_input
})
# Chuyển đổi định dạng tin nhắn thành dictionary với "role" và "content"
# Gộp toàn bộ context_memory thành một chuỗi văn bản để truyền vào truy vấn
combined_context
=
"
\n
"
.
join
([
f"
{
msg
[
'role'
]
}
:
{
msg
[
'content'
]
}
"
for
msg
in
context_memory
])
# Gửi truy vấn bao gồm bối cảnh đến Gemini API
sql_query
=
generate_query_with_gemini
(
combined_context
,
api_key
,
model
,
index
,
documents
)
# Thêm phản hồi của chatbot vào cả chat_history và context_memory
chat_history
.
append
({
"role"
:
"user"
,
"content"
:
user_input
})
chat_history
.
append
({
"role"
:
"assistant"
,
"content"
:
sql_query
})
# Lưu phản hồi của chatbot vào context_memory để làm bối cảnh cho tương tác sau
context_memory
.
append
({
"role"
:
"assistant"
,
"content"
:
sql_query
})
yield
gr
.
update
(
value
=
chat_history
)
except
Exception
as
e
:
chat_history
.
append
({
"role"
:
"assistant"
,
"content"
:
f"Error:
{
str
(
e
)
}
"
})
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment