2013年12月22日 星期日

Eclipse AI generate c/c++ java python on Ubuntu/Windows

official source and system minimum require:
Ubuntu 18.04 above because need gtk version >= 3.22
openjdk-11-jdk

patched source and system minimum require:
Ubuntu 16.04
openjdk-8-jdk

~check gtk version
dpkg -l libgtk* | grep -e '^i' | grep -e 'libgtk-*[0-9]'

1.
rm -rf /usr/lib/python3/dist-packages/uaclient
pip3 install opcua-client

2.
sudo apt update
sudo apt install openjdk-11-jdk

3. 
~check java version
update-alternatives --config java
update-alternatives --config javac
update-alternatives --config javadoc

~set openjdk-11-jdk to the highest priority
update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-11-openjdk-amd64/jre/bin/java 1111
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111
update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/java-11-openjdk-amd64/bin/javadoc 1111

4.
Register account first, in API keys page create new secret key, rember that key!
https://platform.openai.com/account/api-keys

5.
https://www.eclipse.org/downloads/packages/release/2022-12/r
download -> Eclipse IDE for Eclipse Committers - Linux x86_64

6. start eclipse
tar -xvf ./eclipse-committers-2022-12-R-linux-gtk-x86_64.tar.gz -C /opt
mv -f /opt/eclipse /opt/eclipse_2022
~prevent eclipse edit window flashing
GTK_IM_MODULE=ibus /opt/eclipse_2022/eclipse
~or
export GTK_IM_MODULE=ibus
/opt/eclipse_2022/eclipse

7.
eclipse install plugin
(7.1)
Help -> Install New Software
Work with: http://download.eclipse.org/releases/2022-12
~enable only CDT
Eclipse C/C++ development tools
Eclipse C/C++ development tools SDK
(7.2)
Work with: https://www.micegroup.it/openai-site/site.xml
~enable all

must close and reopen eclipse 

8.
eclipse -> Window ->  Preferences -> OpenAI (in left side menu)
OpenAi Secrect Key: [paste API keys in step 4.]
Language: C++
Max token for each request: 4000
OpenAi Model: text-davinci-003

9. File -> New -> Other... -> C/C++ -> C/C++ Project -> All -> C++ Managed Build
Project name: hello
Project type: executable ->  Hello World C++ Project -> next -> -> next -> finish

10.
This is first version, so there is a small bug in the AI pluging.
You need change extension file name .cpp to .java.
Add a temporal file temp.java in src directory then write a comment in temp.java
for example: /*create a thread and print hello world in the thread*/
Mouse box the comment line -> right click -> Source -> Generate code with OpenAi...
https://www.mediafire.com/view/6ann6p7cnoha3mw/ai_cpp.jpg
~done and generate c++ source clip, copy it to hello.cpp

11. trace plugin source code (option)
git clone --recursive https://github.com/micegroupsrl/openaiplugin.git
cd openaiplugin
git log --all           (check all)
git log origin/dev (check dev)
git reset --hard origin/dev
~web view source 
https://github.com/micegroupsrl/openaiplugin/tree/dev
~plugin editor
https://users.drew.edu/bburd/eclipse/CreatingAnEclipsePlugin.html
~export plugin to jar
http://www.codenicer.com/content/how-build-jar-eclipse-plugin-project

12. bug fixed for .cpp in plugin.xml (option)
add follow clip after <extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.cdt.ui.source.menu?after=generateGroup">
        <command
                commandId="it.micegroup.openai.plugin.commands.generateCode"
                id="it.micegroup.openai.plugin.menus.generateCode">
        </command>
</menuContribution>

13. install patched full source to eclipse (option)
official source on openjdk 11
https://www.mediafire.com/file/jibobk9sw5wu1we/openai_eclipse_2022.tar.xz
patched source on openjdk 8
https://www.mediafire.com/file/m7hxv9t6vy505vi/openai_eclipse_luna_sr2.tar.xz
download one of the source
eclipse -> File -> Import -> Existing Project into Workspace -> [Select root directory]:
fill directory then clean build

14. install to eclipse
right click project [it.micegroup.openai.plugin] -> export -> Plug-in Development -> Deployable plug-ins and fragments
[Destination]:
[Install into host. Repository]: (enable this radio button)
$HOME/eclipse_workspace_2022/.metadata/.plugins/org.eclipse.pde.core/install/

15. install patched jar to eclipse with dropin directory (another install method)
https://wiki.eclipse.org/Equinox/p2/Getting_Started
right click project [it.micegroup.openai.plugin] -> export -> Plug-in Development -> Deployable plug-ins and fragments
[Destination]:
[Directory]: $HOME/openai/bin
cp -f $HOME/openai/bin/plugins/it.micegroup.openai.plugin_1.0.0.xxxx.jar /opt/eclipse_2022/dropins
~exit eclipse and restart eclipse with -clean
/opt/eclipse_2022/eclipse -clean

16. python user in eclipse
~match version
https://www.pydev.org/download.html
~download site and install plugin
https://www.pydev.org/update_sites

eclipse -> Window -> Preferences -> PyDev -> interpreters -> Python interpreter
click [Advanced Auto-Config]
select /usr/bin/python3.x

eclipse -> Window ->  Preferences -> OpenAI
OpenAi Secrect Key: [paste API keys in step 4.]
Language: Python

create a PyDev Project
mouse box the comment line -> ctrl + alt + o
~done and generate python source

17. OpenAI words limit in each minute
token test
https://platform.openai.com/tokenizer
words limit in each minute
https://platform.openai.com/docs/guides/rate-limits/overview
model select
https://platform.openai.com/docs/models/overview
https://platform.openai.com/docs/guides/rate-limits/request-increase

18. openai-java-0.12.0 for eclipse-luna-sr2 and openjdk-8, it is the newest way on April 2023
extract eclipseopenai_luna_sr2.tar.gz and open source project then clean build
install method is same as step 14.
~~~there is no need lombok.jar plugin
download: https://www.mediafire.com/file/5w1ggzvjczoyrpz/eclipseopenai_luna_sr2.tar.gz

refer to:
https://github.com/TheoKanning/openai-java
https://github.com/micegroupsrl/openaiplugin/tree/dev

demo video:
1. cpp
https://drive.google.com/file/d/1iBPb8oDhLBuouPVCwAer_OPS0fANv1eS/view
2. inline assembly - incredible!!!
https://drive.google.com/file/d/1LAXhNHNXeLugta6TOawR8h_QXU8HH_uO/view

1 則留言:

  1. bug I post here and wait for fixing
    https://github.com/micegroupsrl/openaiplugin/issues/2

    回覆刪除