DEV Community

Cover image for How to integrate OpenAPI Codex into VSCode IDE
gallau
gallau

Posted on • Updated on

How to integrate OpenAPI Codex into VSCode IDE

Thank you to @tyler36 who pointed out in the repo for Chatgpt helper
it states "This is an extension to quickly query OpenAI's Codex, an AI code assistant similar to ChatGPT, from VS Code.

Apologies for the mistake

Note:
Temporarily, the extension is using Codex, a similar model by OpenAI, instead of ChatGPT, since ChatGPT is near impossible to automate at this time."

Please subsite OpenAPI Codex for ChatGPT.

I've been exploring what ChatGPT can do, and I'm currently learning the Go programming language. I thought it might be helpful to use ChatGPT as a resource while I'm learning Go. ChatGPT is a large language model trained by OpenAI and has a lot of knowledge about various topics, including Go programming. If you have any questions about Go or need help with a specific aspect of the language, ChatGPT can provide explanations and guidance. Please note that ChatGPT is not able to execute code or directly interact with your code editor, but it can offer helpful insights as you work on your Go projects.

I initially used the ChatGPT UI to interact with the model, but I found it inconvenient to copy and paste text between applications. That's when I discovered the ChatGPT Helper VSCode extension. It gives me the ability to:

  1. Ask why my code isn't working
  2. Request explanations for my code
  3. Pose a free-form question

This extension has made it easier for me to use ChatGPT as I work on my Go projects.


Setup

Setting everything up is easy. Here's what you'll need:

A ChatGPT account
VSCode installed on your machine
ChatGPT Helper
Once you have all these items, you'll need to create an OpenAPI key. To do this, go to https://beta.openai.com/account/api-keys and click on "Create new secret key."

Copy the key and open VSCode. On a Windows machine, you can open the command palette by pressing the Ctrl + Shift + P keys. On a Mac, use the Command + Shift + P keys. This will bring up a prompt where you can paste the key.

VSCode prompt to ask ChatGPT a question

To use ChatGPT, you'll need to enter a text, like "hello world." You'll then be asked for the API Secret key that you created earlier. Paste the key into the prompt and press Enter.

Next, you can use the command palette to ask a question. On a Windows machine, you can open the command palette by pressing the Ctrl + Shift + P keys. On a Mac, use the Command + Shift + P keys. This will bring up a prompt where you can enter your question.


Examples

Below are a few examples of ChatGPT's Helper capabilities in Go.

Ask why your code's not working?



package main


func main() {
    fmt.Println("hello world")
}


Enter fullscreen mode Exit fullscreen mode

Below is the output

VSCode ChatGPT Output


Ask to explain your code



package main

import "fmt"

func main() {
    fmt.Println("hello world")
}


Enter fullscreen mode Exit fullscreen mode

Below is the output
ChatGPT explaining the above code


Ask a free-form question

Asking ChatGPT a question about how to loop in Go

And below was the output



<code>package main

import (
    "fmt"
)

func main() {

    fmt.Println("Hello, playground")

    for i := 0; i &lt; 100; i++ {

        fmt.Println("Hello, playground")

    }
}
</code>


A:

You can use <code>strings.Repeat</code>: https://play.golang.org/p/RQx6z0J8-q3.  It's not the most efficient way to do it, but it's a simple way to do it.  If you want to be more efficient, you can use <code>bytes.Buffer</code> and <code>io.CopyN</code>.  See https://play.golang.org/p/hZj_5YtX-q3 for an example of that approach.  The second approach is more efficient because it doesn't have to allocate a new string each time through the loop, but the first approach is simpler and easier to understand if you're just getting started with Go.  If you're going to be doing this a lot, then the second approach is probably better, but if you're just doing it once or twice in your program then the first approach is probably better because it's simpler and easier to understand and maintain.  The second approach is also more complicated because it uses <code>io</code>, which is a package that deals with input and output (I/O), which can be confusing for beginners because I/O can be complicated and confusing in general (and especially in Go).  The first approach doesn't use I/O at all, so it's simpler in that regard as well as being simpler overall (in my opinion).  But again, if you're going to be doing this a lot then the second approach might be better because of its efficiency (but only if efficiency matters).  If efficiency doesn't matter then the first approach is probably better because of its simplicity (again, in my opinion).


Enter fullscreen mode Exit fullscreen mode

Conclusion

In conclusion, the above post provides helpful information for getting started with ChatGPT. It's clear that ChatGPT can be a valuable resource for learning Go programming and improving your understanding of various concepts. It would be interesting to hear about other ways that people are using ChatGPT to enhance their learning experiences. Overall, ChatGPT seems like a useful tool for anyone looking to improve their skills and knowledge in the field of programming.


PS ChatGPT may of helped with the writing

Top comments (6)

Collapse
 
mjoycemilburn profile image
MartinJ

Thanks. That's handy. I'v been quite amazed both by the depth of ChatGPT's knowledge an its ability to present a clearly-expressed answer.

As an example, I've been getting ChatGPT to provide translations of boilerplate Firestore WebV9 collection code into Node.js - something that I personally find deeply tedious. ChatGPT saves me hours of unproductive cursing.

I think I'll be using ChatGPT quite a lot in future and this VSCode interface will save me yet more time

Collapse
 
tyler36 profile image
tyler36

If you are looking to test ChatGPT, be aware that ChatGPT Helper does NOT use ChatGPT.

There is a disclaimer on the site.

Temporarily, the extension is using Codex, a similar model by OpenAI, instead of ChatGPT, since ChatGPT is near impossible to automate at this time.

Collapse
 
gallau profile image
gallau

Thank you for pointing this out I will rename the article and put in your comment

Collapse
 
monimartin22 profile image
Moni Martin

Display ChatGPT response alongside Google Search results
This is a simple extension that show response from ChatGPT alongside Google and other search engines
You can try it through the following link:
ttps://chrome.google.com/webstore/detail/chatgpt-for-search-engine/feeonheemodpkdckaljcjogdncpiiban/related?hl=en-GB&authuser=0

Collapse
 
gallau profile image
gallau

Thank you

Collapse
 
suharyadi2112 profile image
Suharxxxx

nice