2013年12月22日 星期日

Eclipse AI generate c/c++ java python on cross-platform

Official system require:
Ubuntu 18.04 above because need gtk version >= 3.22
openjdk-11-jdk

Patched system 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: 2000
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 openjdk 11
https://www.mediafire.com/file/jibobk9sw5wu1we/openai_eclipse_2022.tar.xz
patched openjdk 8
https://www.mediafire.com/file/m7hxv9t6vy505vi/openai_eclipse_luna_sr2.tar.xz
download one of patches for eclipse then clean & rebuild
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/

14. 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

demo:
https://www.mediafire.com/file/m36siyiphydribd/openai_cpp.mp4

1 則留言:

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

    回覆刪除