openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Use the openai library in conjunction with the kivy library.

Open FoxyCTG21 opened this issue 2 years ago • 4 comments

Hi everyone, I'm messing around with the library a bit as I try to use it in conjunction with Kivy. The project as such works when executing the venv virtualization window within Windows, but when passing the project to .APK it closes unexpectedly.

I have tried simpler projects in the conversion from .py to .apk using the Kivy library and they work perfectly. When I apply my OpenAI command lines the APK does not respond.

I have the project in this repository for possible viewing: https://github.com/FoxyCTG21/chatbotapp_public

For the conversion from .py to .apk I use the buildozer library in a Google Colab notebook: https://colab.research.google.com/github/MagnoEfren/kivy/blob/main/KivyApp_a_APK.ipynb?hl=es

I hope I can understand why I can't use the library at the end.

FoxyCTG21 avatar Dec 15 '22 12:12 FoxyCTG21

Hi @FoxyCTG21! Thanks for the issue.

We'll try to help where we can though we've tended to find that issues like this are application specific and are thus a bit outside of what we can do on our end to help. Can you tell me a bit more about your issue? Are you getting any logs that might be helpful to debug the issue we can look at?

hallacy avatar Dec 23 '22 18:12 hallacy

log fail.txt I don't have much experience in programming, but I give you the log that I always end up seeing when I use android studio to virtualize an android to run the apk. In the log it is displayed that it indicates that the X library is missing. The problem is that now it is X then it is Y then it is Z then it is H and then it is an infinity of libraries and this every time I pass the project from .py to .apk in google colab as mentioned before.

The tests in the project commenting the lines of code that openai appears, ends up in an APK that is executable. Based on this, I ended up deducing that there is some controversy in passing an openai library to APK to use it on Android.

FoxyCTG21 avatar Dec 23 '22 23:12 FoxyCTG21

This unfortunately looks like an issue with the build system you're using and not with this library. I'm happy to look at this again if you think the issue is on our end but given that most users have been able to install our package and all of the requirements, I'm inclined to think the issue isn't with our requirements.

hallacy avatar Dec 24 '22 21:12 hallacy

I'll keep working on it then. If I can find the error, I will comment on this thread, in case it is going to be closed due to time, there is no problem.

FoxyCTG21 avatar Dec 25 '22 00:12 FoxyCTG21

I'm going to close this for now. Feel free to reopen it if there's an update

hallacy avatar Jan 01 '23 21:01 hallacy

You must import urllib3 in your builsozer scpec cuz its missing Traceback (most recent call last): 2022-12-14 23:06:03.299 9964-9992/org.test.chatapp I/python: File "/content/.buildozer/android/app/main.py", line 2, in 2022-12-14 23:06:03.301 9964-9992/org.test.chatapp I/python: File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/chatapp/arm64-v8a/openai/init.py", line 8, in 2022-12-14 23:06:03.302 9964-9992/org.test.chatapp I/python: File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/chatapp/arm64-v8a/openai/api_resources/init.py", line 1, in 2022-12-14 23:06:03.304 9964-9992/org.test.chatapp I/python: File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/chatapp/arm64-v8a/openai/api_resources/answer.py", line 1, in 2022-12-14 23:06:03.306 9964-9992/org.test.chatapp I/python: File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/chatapp/arm64-v8a/openai/openai_object.py", line 6, in 2022-12-14 23:06:03.307 9964-9992/org.test.chatapp I/python: File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/chatapp/arm64-v8a/openai/api_requestor.py", line 9, in 2022-12-14 23:06:03.309 9964-9992/org.test.chatapp I/python: File "/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/chatapp/arm64-v8a/requests/init.py", line 43, in 2022-12-14 23:06:03.310 9964-9992/org.test.chatapp I/python: ModuleNotFoundError: No module named 'urllib3'----------like here 2022-12-14 23:06:03.311 9964-9992/org.test.chatapp I/python: Python for android ended.

rEHui-MbIcJIu avatar Mar 25 '23 10:03 rEHui-MbIcJIu

requirements = python3, kivy, openai, aiohttp==3.8.4, aiosignal, frozenlist, async-timeout==4.0.2, attrs, multidict, yarl, idna, typing-extensions==4.4.0, charset_normalizer==2.1.1, urllib3, tqdm, requests.This worked for me, hope it works for you.

TLQB avatar Apr 01 '23 06:04 TLQB

Thank you @TLQB for sharing this information. I can build the app but get an error while using openai in: api_requestor.py line 409 -> platform.platform() The error is: IsADirectoryError: [Errno 21] Is a directory: '/data/data/org.test.myapp/files/app'

I tried a few things to modify the openai (modify and use it as a local package, to patch it in a recipe as so on) but nothing seems to work good in buildozer. Any ideas please?

airmaciej avatar Apr 25 '23 08:04 airmaciej

@airmaciej You have to change line 409 in file buildozer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/"your-app"/armeabi-v7a/openai/api_requestor.py (build-armeabi-v7a or build-arm64-v8a_armeabi-v7a ,...) : from "platform": platform.platform() to "platform": 'Windows-10-10.0.19044-SP0' or "platform":'Linux-5.15.0-69-generic-x86_64-with-glibc2.29'

And for it to work you need to make sure the changes have been applied during deploy android builder debug. For me, I switched to a sub "requirements" build that proceeds to build (comment (1) and open (2)) and back to the official "requirements" (comment (2) and open (1)) and build back, it will be working!

Screenshot from 2023-04-25 16-36-44

Sorry my english is not good!

TLQB avatar Apr 25 '23 09:04 TLQB

Thanks!

вт, 25 апр. 2023 г., 12:51 TranLeQuyBao @.***>:

@airmaciej https://github.com/airmaciej You have to change line 409 in file buildozer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/"your-app"/armeabi-v7a/openai/api_requestor.py (build-armeabi-v7a or build-arm64-v8a_armeabi-v7a ,...) : from "platform": platform.platform() to "platform": 'Windows-10-10.0.19044-SP0' or "platform":'Linux-5.15.0-69-generic-x86_64-with-glibc2.29'

And for it to work you need to make sure the changes have been applied during deploy android builder debug. For me, I switched to a sub "requirements" build that proceeds to build (comment (1) and open (2)) and back to the official "requirements" (comment (2) and open (1)) and build back, it will be working!

[image: Screenshot from 2023-04-25 16-36-44] https://user-images.githubusercontent.com/59725425/234237131-77716c88-747c-46df-82fa-bebdcc353665.png

Sorry my english is not good!

— Reply to this email directly, view it on GitHub https://github.com/openai/openai-python/issues/152#issuecomment-1521502306, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3WXFHH3X2HZ4IS2IX3UMOTXC6NBHANCNFSM6AAAAAAS7V2UCE . You are receiving this because you commented.Message ID: @.***>

rEHui-MbIcJIu avatar Apr 25 '23 10:04 rEHui-MbIcJIu

Thank you @TLQB ! My problem was that I couldn't get the modified openai module to link properly into the buildozer. I am sure there is a better way doing it, what was warked for me is: -> downloading openai python package (with setup.py and so on) into the ./libs -> in buildozer.spec requirements = python3, openai @ file:///mnt/c/path_to_downloaded_package (I didn't use relative path here) -> building for the first time failed because p4a generates wrong requirements.txt tile (with @ operator at the beginning of the file) -> I modified requirements.txt manually and write protected it -> I modified build.py in p4a to catch error if the requirements.txt cannot be regenerated -> started build process again -> it worked

I am aware that this is ugly workaround, but maybe someone will get some usefull information reading this :)

Maybe final information: I used it all in WSL under Windows 10

airmaciej avatar Apr 25 '23 12:04 airmaciej