Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio committed Jun 22, 2023
1 parent 9d377b2 commit f613822
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/EdgeGPT/EdgeGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,41 @@ async def ask(
if final:
if not simplify_response:
return response
message = next(
(
s
for s in reversed(response["item"]["messages"])
if "messageType" not in s and "adaptiveCards" in s
),
response["item"]["messages"][-1],
for msg in reversed(response["item"]["messages"]):
if msg.get("adaptiveCards") and msg["adaptiveCards"][0]["body"][
0
].get("text"):
message = msg
break
suggestions = [
suggestion["text"]
for suggestion in message.get("suggestedResponses", [])
]
adaptive_cards = message.get("adaptiveCards", [])
adaptive_text = (
adaptive_cards[0]["body"][0].get("text") if adaptive_cards else None
)
sources = (
adaptive_cards[0]["body"][0].get("text") if adaptive_cards else None
)
sources_text = (
adaptive_cards[0]["body"][-1].get("text")
if adaptive_cards
else None
)
return {
"text": message["text"],
"author": message["author"],
"sources": message.get("sourceAttributions"),
"sources_text": message["adaptiveCards"][0]["body"][-1]["text"],
"suggestions": [
suggestion["text"]
for suggestion in message["suggestedResponses"]
],
"sources": sources,
"sources_text": sources_text,
"suggestions": suggestions,
"messages_left": response["item"]["throttling"][
"maxNumUserMessagesInConversation"
]
- response["item"]["throttling"]["numUserMessagesInConversation"],
"adaptive_text": message["adaptiveCards"][0]["body"][0].get("text"),
"total_messages": response["item"]["throttling"][
"maxNumUserMessagesInConversation"
],
- response["item"]["throttling"].get(
"numUserMessagesInConversation", 0
),
"adaptive_text": adaptive_text,
}
return {}

Expand Down

0 comments on commit f613822

Please sign in to comment.