microsoft / TaskWeaver

A code-first agent framework for seamlessly planning and executing data analytics tasks.
https://microsoft.github.io/TaskWeaver/
MIT License
5.38k stars 689 forks source link

running taskwaver via python notebook showing error on gemini prompt #100

Closed yadavj2008 closed 10 months ago

yadavj2008 commented 11 months ago

Describe the bug I'm trying to run the taskwearver on colab notebook by importing taskweaver as python package, i was able to create the session with Gemini model but when I tried running the prompt I faced below error.

To Reproduce

Steps to reproduce the behavior:

1. Start prompt with Gemini session.

user_query = "hello, what can you do?"
response_round = session.send_message(user_query,
                                      event_handler=lambda _type, _msg: print(f"{_type}:\n{_msg}"))

2. See error

INFO:taskweaver.logging:Use back up engine: False
ERROR:taskweaver.logging:Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/google/protobuf/json_format.py", line 544, in _ConvertFieldValuePair
    raise ParseError(
google.protobuf.json_format.ParseError: Message type "google.ai.generativelanguage.v1beta.GenerateContentResponse" has no field named "error" at "GenerateContentResponse".
 Available Fields(except extensions): "['candidates', 'promptFeedback']"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/google/generativeai/types/generation_types.py", line 345, in rewrite_stream_error
    yield
  File "/usr/local/lib/python3.10/dist-packages/google/generativeai/types/generation_types.py", line 388, in from_iterator
    response = next(iterator)
  File "/usr/local/lib/python3.10/dist-packages/google/api_core/rest_streaming.py", line 106, in __next__
    return self._grab()
  File "/usr/local/lib/python3.10/dist-packages/google/api_core/rest_streaming.py", line 110, in _grab
    return self._response_message_cls.from_json(self._ready_objs.popleft())
  File "/usr/local/lib/python3.10/dist-packages/proto/message.py", line 428, in from_json
    Parse(payload, instance._pb, ignore_unknown_fields=ignore_unknown_fields)
  File "/usr/local/lib/python3.10/dist-packages/google/protobuf/json_format.py", line 436, in Parse
    return ParseDict(js, message, ignore_unknown_fields, descriptor_pool,
  File "/usr/local/lib/python3.10/dist-packages/google/protobuf/json_format.py", line 461, in ParseDict
    parser.ConvertMessage(js_dict, message, '')
  File "/usr/local/lib/python3.10/dist-packages/google/protobuf/json_format.py", line 502, in ConvertMessage
    self._ConvertFieldValuePair(value, message, path)
  File "/usr/local/lib/python3.10/dist-packages/google/protobuf/json_format.py", line 629, in _ConvertFieldValuePair
    raise ParseError(str(e))
google.protobuf.json_format.ParseError: Message type "google.ai.generativelanguage.v1beta.GenerateContentResponse" has no field named "error" at "GenerateContentResponse".
 Available Fields(except extensions): "['candidates', 'promptFeedback']"

Expected behavior The prompt should run just fine and able to parse the gemini response.

Environment Information (please complete the following information):

Additional context

ShilinHe commented 10 months ago

Hi @yadavj2008, which version of google.generativeai are you using? I cannot reproduce your issue with google-generativeai==0.3.1

yadavj2008 commented 10 months ago

Thanks for the guidance @ShilinHe

The previous error I was getting on google.generative==0.3.2 version, then I downgraded the version to 0.3.1 and getting below error now. please help

[/content/TaskWeaver/taskweaver/session/session.py](https://localhost:8080/#) in send_message(self, message, event_handler, files)
    195 
    196         with self.event_emitter.handle_events_ctx(event_handler):
--> 197             return self._send_text_message(message_prefix + message)
    198 
    199     def _upload_file(self, name: str, path: Optional[str] = None, content: Optional[bytes] = None) -> str:

[/content/TaskWeaver/taskweaver/session/session.py](https://localhost:8080/#) in _send_text_message(self, message)
     97     def _send_text_message(self, message: str) -> Round:
     98         chat_round = self.memory.create_round(user_query=message)
---> 99         self.event_emitter.start_round(chat_round.id)
    100 
    101         def _send_message(recipient: str, post: Post) -> Post:

[/content/TaskWeaver/taskweaver/module/event_emitter.py](https://localhost:8080/#) in start_round(self, round_id)
    229     def start_round(self, round_id: str):
    230         self.current_round_id = round_id
--> 231         self.emit(
    232             TaskWeaverEvent(
    233                 EventScope.round,

[/content/TaskWeaver/taskweaver/module/event_emitter.py](https://localhost:8080/#) in emit(self, event)
    225     def emit(self, event: TaskWeaverEvent):
    226         for handler in self.handlers:
--> 227             handler.handle(event)
    228 
    229     def start_round(self, round_id: str):

AttributeError: 'function' object has no attribute 'handle'
ShilinHe commented 10 months ago

Hi @yadavj2008, I still cannot reproduce your issue. My code is as follows:

from taskweaver.app.app import TaskWeaverApp

# This is the folder that contains the taskweaver_config.json file and not the repo root. Defaults to "./project/"
app_dir = "./project/"
app = TaskWeaverApp(app_dir=app_dir)
session = app.get_session()

user_query = "hello, what can you do?"
response_round = session.send_message(user_query)
print(response_round.to_dict())

The code is same as the one in the documents. I just put the code in a Jupyter Notebook (in the TaskWeaver folder, same level as the project) and install the genmini package via pip install google-generativeai.

ShilinHe commented 10 months ago

Close as no activity.