Skip to content

Commit

Permalink
feat: Add functionality to set sources in response message.
Browse files Browse the repository at this point in the history
  • Loading branch information
felipearosr committed Apr 12, 2024
1 parent f412356 commit 4f3f438
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions 2.Pinecone - HybridRetriever - Adv.Ingestion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ async def start():
author="Assistant", content="Hello! Im an AI assistant. How may I help you?"
).send()

async def set_sources(response, response_message):
label_list = []
count = 1
for sr in response.source_nodes:
elements = [
cl.Text(
name="S" + str(count),
content=f"{sr.node.text}",
display="side",
size="small",
)
]
response_message.elements = elements
label_list.append("S" + str(count))
await response_message.update()
count += 1
response_message.content += "\n\nSources: " + ", ".join(label_list)
await response_message.update()

@cl.on_message
async def main(message: cl.Message):
Expand Down Expand Up @@ -79,21 +97,5 @@ async def main(message: cl.Message):
message_history = message_history[-4:]
cl.user_session.set("message_history", message_history)

label_list = []
count = 1

for sr in response.source_nodes:
elements = [
cl.Text(
name="S" + str(count),
content=f"{sr.node.text}",
display="side",
size="small",
)
]
response_message.elements = elements
label_list.append("S" + str(count))
await response_message.update()
count += 1
response_message.content += "\n\nSources: " + ", ".join(label_list)
await response_message.update()
if response.source_nodes:
await set_sources(response, response_message)

0 comments on commit 4f3f438

Please sign in to comment.