@@ -161,3 +161,90 @@ def test_send_message_multi_turn_afc_enabled_FC_FR_parts(client):
161161 )
162162 with pytest_helper .exception_if_vertex (client , ClientError ):
163163 chat .send_message ('What is the stock price of symbol GOOG?' )
164+
165+
166+ @pytest .mark .asyncio
167+ async def test_async_send_message_function_tool_afc_disabled (client ):
168+ chat = client .aio .chats .create (
169+ model = MODEL_NAME ,
170+ config = {
171+ 'tools' : [get_weather ],
172+ },
173+ )
174+ await chat .send_message ('What is the weather in Boston?' )
175+ history = chat .get_history ()
176+ assert len (history ) == 2
177+ assert history [0 ].role == 'user'
178+ assert history [0 ].parts [0 ].text == 'What is the weather in Boston?'
179+ assert history [1 ].role == 'model'
180+ assert len (history [1 ].parts ) == 1
181+ assert history [1 ].parts [0 ].function_call .name == 'get_weather'
182+ assert history [1 ].parts [0 ].function_call .args == {'city' : 'Boston' }
183+
184+
185+ @pytest .mark .asyncio
186+ async def test_async_send_message_function_tool_afc_enabled (client ):
187+ chat = client .aio .chats .create (
188+ model = MODEL_NAME ,
189+ config = {
190+ 'tools' : [get_weather ],
191+ 'automatic_function_calling' : {'enable' : True },
192+ },
193+ )
194+ await chat .send_message ('What is the weather in Boston?' )
195+ history = chat .get_history ()
196+ assert len (history ) == 4
197+ assert history [0 ].role == 'user'
198+ assert history [0 ].parts [0 ].text == 'What is the weather in Boston?'
199+ assert history [1 ].role == 'model'
200+ assert history [1 ].parts [0 ].function_call .name == 'get_weather'
201+ assert history [1 ].parts [0 ].function_call .args == {'city' : 'Boston' }
202+ assert history [2 ].role == 'user'
203+ assert history [2 ].parts [0 ].function_response .name == 'get_weather'
204+ assert history [3 ].role == 'model'
205+ assert 'sunny' in history [3 ].parts [0 ].text .lower ()
206+
207+
208+ @pytest .mark .asyncio
209+ async def test_async_send_message_function_tool_afc_enabled_multi_turn (client ):
210+ chat = client .aio .chats .create (
211+ model = MODEL_NAME ,
212+ config = {
213+ 'tools' : [get_weather , get_stock_price ],
214+ 'automatic_function_calling' : {'enable' : True },
215+ },
216+ )
217+ await chat .send_message ('What is the weather in Boston?' )
218+ history = chat .get_history ()
219+ assert len (history ) == 4
220+ assert history [0 ].role == 'user'
221+ assert history [0 ].parts [0 ].text == 'What is the weather in Boston?'
222+ assert history [1 ].role == 'model'
223+ assert history [1 ].parts [0 ].function_call .name == 'get_weather'
224+ assert history [1 ].parts [0 ].function_call .args == {'city' : 'Boston' }
225+ assert history [2 ].role == 'user'
226+ assert history [2 ].parts [0 ].function_response .name == 'get_weather'
227+ assert history [3 ].role == 'model'
228+ assert 'sunny' in history [3 ].parts [0 ].text .lower ()
229+
230+ await chat .send_message ('What is the stock price of symbol GOOG?' )
231+ history = chat .get_history ()
232+ assert len (history ) == 8
233+ assert history [0 ].role == 'user'
234+ assert history [0 ].parts [0 ].text == 'What is the weather in Boston?'
235+ assert history [1 ].role == 'model'
236+ assert history [1 ].parts [0 ].function_call .name == 'get_weather'
237+ assert history [1 ].parts [0 ].function_call .args == {'city' : 'Boston' }
238+ assert history [2 ].role == 'user'
239+ assert history [2 ].parts [0 ].function_response .name == 'get_weather'
240+ assert history [3 ].role == 'model'
241+ assert 'sunny' in history [3 ].parts [0 ].text .lower ()
242+ assert history [4 ].role == 'user'
243+ assert history [4 ].parts [0 ].text == 'What is the stock price of symbol GOOG?'
244+ assert history [5 ].role == 'model'
245+ assert history [5 ].parts [0 ].function_call .name == 'get_stock_price'
246+ assert history [5 ].parts [0 ].function_call .args == {'symbol' : 'GOOG' }
247+ assert history [6 ].role == 'user'
248+ assert history [6 ].parts [0 ].function_response .name == 'get_stock_price'
249+ assert history [7 ].role == 'model'
250+ assert '1000' in history [7 ].parts [0 ].text
0 commit comments