ChatGPT Fails At Creating Python Code For ChatGPT API Requests

chatGPT.png

I would like start this post with this simple statement that represents how I feel about it - ChatGPT is Awesome! What it can do has been beyond impressive. I remember a few years ago when article was published either by OpenAI or about OpenAI when they were testing the initial closed versions of ChatGPT. The article stated that early closed version was producing impressive results writing articles. They also mentioned that the level of sophistication was scary that it would almost be impossible to distinguish the generated article from the human created ones. While made early version available for researchers to test and contribute, they weren't sure if it would be a good idea to release it for public. At that time my thought was such tools would never become public, because corporations would hold monopoly and take advantage of this technology to make more profits.

Profits have not been out of the questions, which is totally ok, and great. What was surprising that OpenAI decided to make the tool available for public. In retrospect it seems it would always going to be available for public. This play actually put OpenAI ahead of everybody else in this competition for perfecting AI tech. Now everybody wants to be in AI, every tech company is rushing to gain the market share. Big tech always had the edge and they were always ahead, but they did fail here. It could be because they had no intentions of sharing these tools with the public. Now everybody producing their versions and trying catch up. Competition is healthy. There is still a lot to be developed, a lot to be discussed, and worked out to shape the future with AI.

I don't use ChatGPT as much as I would like to. I do have paid subscription and use it once in a while. There are times it does help with getting some real world tasks done quickly. Nothing major, simple tasks. I haven't had a time and dedication to explore it more. Recently, I wanted to see how ChatGPT API worked. This tool with combination of automation could unlock many possibilities to create more efficiency and save time. I have heard, read, and seen how ChatGPT and similar tools are good at writing code. There are many articles exploring the idea of such AI tools replacing developers. I haven't bought into this idea yet. However, seeing how fast things are improving, I am sure these tools will be utilized to make development process more efficient and productive.

So what I wanted to do to get started and explore automating ChatGPT prompts is find a simple template. I didn't want to read through documentation and tutorials to accomplish this. This was an experiment to see if ChatGPT could speed up the process itself. If it can write code, surely it should be able to create a very simple template that connects to ChatGPT API and fetch results for various prompts. Many have been testing and using ChatGPT API for a while now.

Unfortunately, my first attempt did not produce expected results. I asked ChatGPT to create me a python code that would allow connecting to ChatGPT API and getting results for various prompts. It did generate a code, but it didn't work. The reason it didn't work was the classes and/or methods used were deprecated. Probably the gone generated worked in the past with older version of the library. This time it wasn't doing what it was supposed to do. That was disappointing. Now I did have to read documentation and tutorials. Even if ChatGPT failed, I wasn't going to.

I thought having a paid subscription was enough to get API keys and gain access to ChatGPT programmatically. I was wrong. OpenAI's API program seems to be separate from its online tools regardless if the user is on a paid plan or not. Despite this getting an API key wasn't a problem. I just had to set up a paid plan for API, which only charges based on usage. Setting things up was very fast and in no time I had valid API keys. Even if ChatGPT failed and sharing a working python code, surely there had to be many sharing their experiments and codes online. Worst case scenario documentation would have everything.

After spending an hour it became clear what the problem was. I was able to quickly edit the code get it work. Results were impressive. Initially! Now that I am connected, I just had to experiment with few different ideas. Everything wasn't working as great as the online version does. I wasn't getting accurate results for simple things. For example, if I ask generate 50 quotes. I wouldn't get 50 quotes, the numbers would slightly vary occasionally. If I wanted the results to be in certain formatting, that too wouldn't be consistent. However, I believe part of it could be my errors and fully understanding and be able to create proper prompts. Since than I haven't used it much. Just now before writing this post I wanted to give it a try again. Maybe it has improved.

Interestingly, the code ChatGPT generated this time was completely different. In my initial attempts the code generated used openai library. This time it wasn't using openai at all. Instead it was only using requests. Maybe this fixed things, I thought. Unfortunately, this code did not work either. It seems it has to do with deprecated code again. One of the error messages I got is as following:

This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?

Even after changing endpoint, code still didn't work. Last time when I was test, I did ask ChatGPT to improve the code and went back and forth a few times. Results were unsuccessful. I am not planning to continue the same discussion with the aibot for now. Maybe in time things will improve. Maybe in time I will learn more to see if it is actually a ChatGPT's fault or my mistakes that producing these useless results. I do have a working code and have been experimenting with that for now. Everything works great so far. There is a lot more to explore. I will continue utilizing it old fashion way through reading tutorials, documentations, and discussions.

While this simple code requests failed, doesn't mean other would fail as well. I plan to experiment with generating code more and see where it will lead me. I did find it funny how ChatGPT couldn't write a code that utilizes it. It is still awesome. I am sure a year from now thing will be 10 times better is not 100 times more sophisticated. Let me know your experiences with ChatGPT in the comments.

H2
H3
H4
3 columns
2 columns
1 column
25 Comments
Ecency