ChatGPT Fails At Creating Python Code For ChatGPT API Requests

avatar

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.



0
0
0.000
26 comments
avatar

I haven't really used ChatGPT but I do think it's quite inaccurate. I remember seeing some articles about lawyers using it to find cases and they made up cases that did not exist.

I am wondering if the reason why it could not find the correct code and used depreciated code is because the training data was a few years back. I don't know if it can even access the new libraries to make the correct code.

0
0
0.000
avatar

Without it going public. They would not have enough information and data sets to build something that will be closed and used by entities to take advantage and profit big tech. Personally I think they are still testing it and using the general public as lab rats. lol. Do not trust free lunch from large corporations they always have an angle.

0
0
0.000
avatar

Failure is part of the process to it getting it right. Given its constant development I am sure it will do more even on the part it failed given the same task next time.

0
0
0.000
avatar

Gpt and other A.I tools are still a long way from replacing humans. However they are not to be underrated on how much distraction they will bring in the process. Beautiful article

0
0
0.000
avatar

We are using AI throughout all our SUBs projects. Sometimes I think all we are doing is sowing the seeds of our own redundancy!
untitled.gif

0
0
0.000
avatar

I just know it won’t be easy for AI to take place of human just like that… I’ve used ChatGPT before but it isn’t very perfect to me

0
0
0.000
avatar

oh, have you tried it in the latest version or in the version free available for the public? I mean chatgpt-3 or 4? I have heard people creating codes for their app using chatgpt and they were very happy about it.

0
0
0.000
avatar

Paid version, gpt4.

0
0
0.000
avatar

oh that's bad, sad to know you had a bad experience while using Chatgpt 4

0
0
0.000
avatar
(Edited)

Writing an article now that fit into recurrent issues of life can't be perfectly done with CHATGPT and AI. One's proven experience still count very well. They might get it right later, but for now that's still a long way.

0
0
0.000
avatar

Ai are pretty Amazing, and you only see whats public, Guess military field how can be...if It can write code its the end for developers😅

Probably that chat gtp needed more train on coding and new libraries

0
0
0.000
avatar

Humans are just observing and sharpening there skills. A.I will find it hard to fully replace them. It’s a good to to assist man’s reign

0
0
0.000
avatar

Perhaps no one has tried to do it before. And now that it’s on the list off the an archived stuff. They will build it for and find ways of it being executed for the betterment of the technology

0
0
0.000
avatar

Programmers can not be overtaken they are going to switch there skills into builder better bots

0
0
0.000
avatar

This article has made my day Great!

It has helped to know that sometimes AI do make mistakes and sometimes won't even do as was directed, well I do know that programmers would make further researches in order to modify the AI system but still Human intelligence still stands Great.

Nice write up tho.

0
0
0.000
avatar

Why is Chat-GPT called AI when it is really VI? Virtual Intelligence is limited in scope and not "self aware" and that is what Chat GPT is, a limited virtual intelligence that is not self aware. So why is it misnomered as "AI" when true AI does not exist yet?

0
0
0.000
avatar

i have had a go at using chatgpt and i also asked it to code me a mobile game in python, it did to a certain point. However I think if i had more experience using python i could well go that step further and create a simple mobile game. i think also knowing the prompts to use in chatgpt can sometimes be challenging. i do believe chatgpt will also become a lot more sophisticated over time.

0
0
0.000
avatar

Not sure what to say. I guess Chat GPT is not 100% perfect yet and not every time it will create correct code or even functioning code. I guess it also depends what parameters were inputted in it. It is scary to think that Chat GPT may render writers, artists, designers, coders, engineers, and maybe even think tanks completely obsolete, though.

And on an unrelated note to all: Please follow me, I follow back! I'm new, trying to get... somewhere, anywhere.

0
0
0.000
avatar

We have to accept that these software will never be able to do the work that humans can do. Because of them, our life becomes a little easier and some special knowledge definitely gives us this.

0
0
0.000
avatar

I use co-pilot a lot as it has made me far more productive, however I do need to correct 95% of what it outputs due to hallucinated libraries or methods but even with the need to do this the logic it provides is generally ok. Its also good for reviewing and improving code if youve written something you are dubious about.

0
0
0.000
avatar

Ultimately, It's a learning process, and your experiences will likely contribute to the enhancement of your skills and understanding of the technology. Keep experimenting, learning, and sharing your experiences , it's all part of the journey towards mastering the ChatGPT API .

0
0
0.000
avatar

I had written a python code from Chat GPT and that was amazing 😍

0
0
0.000