66from .chathub import *
77from .conversation import *
88from .request import *
9- from re_edge_gpt .utils .utilities import *
109
1110
1211class Chatbot :
@@ -53,7 +52,8 @@ async def ask(
5352 locale : str = guess_locale (),
5453 simplify_response : bool = False ,
5554 attachment : dict [str , str ] = None ,
56- autosave : bool = True
55+ remove_options : list = None ,
56+ add_options : list = None
5757 ):
5858 """
5959 Ask a question to the bot
@@ -72,7 +72,8 @@ async def ask(
7272 attachment={"filename": r"<file_path>"})
7373 For base64 image using
7474 attachment={"base64_image": r"<base64_image_str>"})
75- :param autosave: add autosave on request
75+ :param remove_options remove options from Style
76+ :param add_options add options to Style
7677 """
7778 async for final , response in self .chat_hub .ask_stream (
7879 prompt = prompt ,
@@ -82,47 +83,56 @@ async def ask(
8283 search_result = search_result ,
8384 locale = locale ,
8485 attachment = attachment ,
85- autosave = autosave
86+ remove_options = remove_options ,
87+ add_options = add_options
8688 ):
8789 if final :
8890 if not simplify_response :
8991 return response
90- messages_left = response ["item" ]["throttling" ][
91- "maxNumUserMessagesInConversation"
92- ] - response ["item" ]["throttling" ].get (
92+ messages_left = (response .get ("item" ).get ("throttling" ).get ("maxNumUserMessagesInConversation" )
93+ - response .get ("item" ).get ("throttling" ).get (
9394 "numUserMessagesInConversation" ,
9495 0 ,
95- )
96+ ))
9697 if messages_left == 0 :
9798 raise Exception ("Max messages reached" )
98- message = ""
99- for msg in reversed (response ["item" ]["messages" ]):
100- if msg .get ("adaptiveCards" ) and msg ["adaptiveCards" ][0 ]["body" ][
101- 0
102- ].get ("text" ):
103- message = msg
104- break
99+ message = {}
100+ for msg in reversed (response .get ("item" ).get ("messages" )):
101+ if msg .get ("author" ) == "bot" :
102+ old_message = message .get ("text" )
103+ if old_message :
104+ old_message = old_message + " \n "
105+ else :
106+ old_message = ""
107+ message .update ({
108+ "author" : "bot" ,
109+ "text" : old_message + msg .get ("text" )
110+ })
105111 if not message :
106112 raise Exception ("No message found" )
107- suggestions = [
108- suggestion ["text" ]
109- for suggestion in message .get ("suggestedResponses" , [])
110- ]
111- adaptive_cards = message .get ("adaptiveCards" , [])
112- sources = (
113- adaptive_cards [0 ]["body" ][0 ].get ("text" ) if adaptive_cards else None
114- )
115- sources_link = (
116- adaptive_cards [0 ]["body" ][- 1 ].get ("text" )
117- if adaptive_cards
118- else None
119- )
113+ image_create_text = ""
114+ suggestions = []
115+ source_texts = []
116+ source_links = []
117+ for detail in reversed (response .get ("item" ).get ("messages" )):
118+ suggestion_responses = detail .get ("suggestedResponses" , {})
119+ source_attr = detail .get ("sourceAttributions" , {})
120+ if suggestion_responses :
121+ for suggestion in suggestion_responses :
122+ suggestions .append (suggestion .get ("text" ))
123+ if source_attr :
124+ for source in source_attr :
125+ source_texts .append (source .get ("providerDisplayName" ))
126+ source_links .append (source .get ("seeMoreUrl" ))
127+ if detail .get ("contentType" ) == "IMAGE" and detail .get ("messageType" ) == "GenerateContentQuery" :
128+ image_create_text = detail .get ("text" )
120129 return {
121130 "text" : message ["text" ],
122131 "author" : message ["author" ],
123- "sources " : sources ,
124- "sources_link " : sources_link ,
132+ "source_texts " : source_texts ,
133+ "source_links " : source_links ,
125134 "suggestions" : suggestions ,
135+ "image_create_text" : image_create_text ,
126136 "messages_left" : messages_left ,
127137 "max_messages" : response ["item" ]["throttling" ][
128138 "maxNumUserMessagesInConversation"
@@ -139,7 +149,8 @@ async def ask_stream(
139149 webpage_context : str | None = None ,
140150 search_result : bool = False ,
141151 locale : str = guess_locale (),
142- autosave : bool = True
152+ remove_options : list = None ,
153+ add_options : list = None
143154 ) -> Generator [bool , dict | str , None ]:
144155 """
145156 Ask a question to the bot
@@ -152,7 +163,8 @@ async def ask_stream(
152163 webpage_context = webpage_context ,
153164 search_result = search_result ,
154165 locale = locale ,
155- autosave = autosave
166+ remove_options = remove_options ,
167+ add_options = add_options
156168 ):
157169 yield response
158170
0 commit comments