-
Notifications
You must be signed in to change notification settings - Fork 113
Closed
Labels
Description
I'm trying to implement a Shiny Chat using the Gemini language model, following the example. The initial interaction with the model works fine, but subsequent interactions result in the error: "Error in Effect: 400 Please use a valid role: user, model".
The error occurs after the first successful interaction with the model. I have included a screenshot of the error message.
Here's the traceback from the terminal:
Traceback (most recent call last):
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\shiny\ui\_chat.py", line 322, in handle_user_input
await afunc()
File "C:\Users\Dell\Downloads\gemini\app.py", line 38, in _
response = llm.generate_content(
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\google\generativeai\generative_models.py", line 325, in generate_content
iterator = self._client.stream_generate_content(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\google\ai\generativelanguage_v1beta\services\generative_service\client.py", line 1122, in stream_generate_content
response = rpc(
^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\google\api_core\gapic_v1\method.py", line 131, in __call__
return wrapped_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\google\api_core\retry\retry_unary.py", line 293, in retry_wrapped_func
return retry_target(
^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\google\api_core\retry\retry_unary.py", line 153, in retry_target
_retry_error_helper(
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\google\api_core\retry\retry_base.py", line 212, in _retry_error_helper
raise final_exc from source_exc
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\google\api_core\retry\retry_unary.py", line 144, in retry_target
result = target()
^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\google\api_core\timeout.py", line 120, in func_with_timeout
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\google\api_core\grpc_helpers.py", line 174, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 Please use a valid role: user, model.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\shiny\reactive\_reactives.py", line 584, in _run
await self._fn()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\shiny\reactive\_reactives.py", line 885, in new_user_async_fn
return await user_fn()
^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\shiny\ui\_chat.py", line 324, in handle_user_input
await self._raise_exception(e)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\shiny\ui\_chat.py", line 344, in _raise_exception
raise NotifyException(str(e), sanitize=sanitize)
shiny.types.NotifyException: 400 Please use a valid role: user, model.
Could you provide guidance on how to ensure that the correct roles are being assigned or passed during subsequent interactions with the Gemini model?