shroominic / codeinterpreter-api

👾 Open source implementation of the ChatGPT Code Interpreter
https://discord.gg/Vaq25XJvvW
MIT License
3.76k stars 402 forks source link

ValueError: I/O operation on closed pipe #47

Open TheZaind opened 1 year ago

TheZaind commented 1 year ago

This is my code:

    from codeinterpreterapi import CodeInterpreterSession, File
    import os, dotenv
    import openai

    ###     Lade Variabeln      ###
    os.environ["OPENAI_API_KEY"] = "sk-XXXXXXXXXXX-Its my key:)YYYYYY"

    async def main():
        # context manager for auto start/stop of the session
        async with CodeInterpreterSession(openai_api_key="OPENAI_API_KEY", model="gpt-3.5-turbo") as session:
            # define the user request
            user_request = "Analyze this dataset and plot something interesting about it."
            files = [
                File.from_path("./bitcoin_csv.csv"),
            ]

            # generate the response
            response = await session.generate_response(
                user_request, files=files
            )

            # output to the user
            print("AI: ", response.content)
            for i, file in enumerate(response.files):
                with open(f'image_{i}.png', 'wb') as f:
                    f.write(file)

    if __name__ == "__main__":
        import asyncio

        asyncio.run(main())

but i only get this as my Traceback:

        AI:  Sorry, something went while generating your response.Please try again or restart the session.
        Exception ignored in: <function BaseSubprocessTransport.__del__ at 0x0000013F2E2A7920>
        Traceback (most recent call last):
          File "C:\Users\zaind\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_subprocess.py", line 125, in __del__
            _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "C:\Users\zaind\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_subprocess.py", line 78, in __repr__
            info.append(f'stdout={stdout.pipe}')
                        ^^^^^^^^^^^^^^^^^^^^^^^
          File "C:\Users\zaind\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 80, in __repr__
            info.append(f'fd={self._sock.fileno()}')
                              ^^^^^^^^^^^^^^^^^^^
          File "C:\Users\zaind\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_utils.py", line 102, in fileno
            raise ValueError("I/O operation on closed pipe")
        ValueError: I/O operation on closed pipe
        Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000013F2E2D1120>
        Traceback (most recent call last):
          File "C:\Users\zaind\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 116, in __del__
            _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "C:\Users\zaind\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 80, in __repr__
            info.append(f'fd={self._sock.fileno()}')
                              ^^^^^^^^^^^^^^^^^^^
          File "C:\Users\zaind\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_utils.py", line 102, in fileno
            raise ValueError("I/O operation on closed pipe")
        ValueError: I/O operation on closed pipe
        Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000013F2E2D1120>
        Traceback (most recent call last):
          File "C:\Users\zaind\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 116, in __del__
            _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "C:\Users\zaind\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 80, in __repr__
            info.append(f'fd={self._sock.fileno()}')
                              ^^^^^^^^^^^^^^^^^^^
          File "C:\Users\zaind\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_utils.py", line 102, in fileno
            raise ValueError("I/O operation on closed pipe")
        ValueError: I/O operation on closed pipe`

it worked one time but then never again. Anyone got an idea or can help?

Thanks :)

Bishop-Cui commented 1 year ago

I met this problem too but a little bit differently, I asked the session to "Plot the bitcoin chart of 2023 YTD", and it actually plotted a chart but empty, and it replied, "Here is the Bitcoin chart for the year-to-date of 2023".

pavantyagi commented 1 year ago

Anyone found a workaround for this issue as of yet?

Al-aminI commented 1 year ago

am getting thesame issue to