Skip to content

Commit

Permalink
Merge pull request #10 from felipearosr/Reranker-Set-Sources-Uplift
Browse files Browse the repository at this point in the history
feat: Add function to set and display message sources.
  • Loading branch information
felipearosr committed Apr 12, 2024
2 parents f34e461 + 8bfe79e commit 90da17c
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions 3.Reranker - Q.Transformation - Res.Synthesis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ async def start():
).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):
query_engine = cl.user_session.get("query_engine")
Expand Down Expand Up @@ -93,21 +113,5 @@ async def main(message: cl.Message):
message_history = message_history[-6:]
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 90da17c

Please sign in to comment.