Some newbie issues related to code-davinci-002

I’ve experimented with ChatGPT recently (I was and pretty much still am not very convinced about AI and coding, but I have had to stand corrected!)
The results where pretty surprising.
I asked ChatGPT to refactor a whole class I wrote in past (PHP), and it did that pretty well. I asked it to write a whole new class that does specific things, and boy that thing delivered pretty nice code. Initially unsafe, so I asked it to please escape outputs and sanitise inputs, and it went on doing that like it never did anything else.

Thus, intrigued, I created an API Key and started playing with the different models. I focused on code-davinci-002
And the results are catastrophic :rofl:

For example this prompt gives me either nothing (infinite request, never stops), or it says it is busy I shall retry later, or, it gives me a completely empty response!

The only way I got “some” responses was by limiting the max tokens to an unrealistic 20 or so tokens. Which gives useless, incomplete responses.
When I tried to set stream to true, instead, it delivered many responses… but all the same!

This is an example request I make:

curl --location 'https://api.openai.com/v1/completions' \
--header 'Authorization: Bearer XXX' \
--header 'OpenAI-Organization: XXX' \
--header 'Content-Type: application/json' \
--data '{
    "model":"code-davinci-002",
    "prompt":"Write a Class in Object Oriented PHP that outputs the main SEO Relevant metae tags for a WordPress theme. The code should be dynamic and therefore output content related to the current type of content shown (single post, archive, etc).",
    "user":"XXX",
    "max_tokens":1024
}'

The “best” reply I got is something along these lines (as said this was with a hard limit of tokens)

{
    "id": "cmpl-XX",
    "object": "text_completion",
    "created": 1679480654,
    "model": "code-davinci-002",
    "choices": [
        {
            "text": "\n//\n//The class should adhere to the single responsibility principle, the",
            "index": 0,
            "logprobs": null,
            "finish_reason": "length"
        }
    ],
    "usage": {
        "prompt_tokens": 47,
        "completion_tokens": 16,
        "total_tokens": 63
    }
}

So, it clearly seems to work, but only when I limit tokens to a hard cap?
Why? What am I doing wrong?

As ChatGPT 4 is not available in the API yet, and I think to do code-related requests the code-davinci-002 would be more adequate (?) I would like to use that, at least to understand more how it works, and what it can and cannot do.

Thanks for any inputs!

1 Like

I think I recently saw a post from Open AI where they mentioned that they would discontinue the Codex API on March 26 as it was always meant to be a beta and GPT-3.5 far eclipses it’s performance. Try 3.5-turbo and see how it does.

2 Likes

Sorry I did not mention that. One of the reasons I did not use turbo is this response:
As an AI language model, I cannot provide you with the exact code for this task

Yet, online ChatGPT can do that - and I read somewhere that the online thing is just the code- models, but tuned.

Not sure if that is true, but definitely seem the gpt-3.5-turbo model cannot return actual code.

Welcome to the community @smileBeda

Codex series models will be discontinued for general users on 23rd March.

However since you mentioned, gpt-3.5-turbo and codex series are vastly different models, the key difference being that the codex series models are trained for code while the gpt-3.5-turbo models are trained for conversation, this means that the prompts for the models will be different for the same task.

Seems like and implementation error. Also it’s worth noting that larger max_tokens lead to higher response times. Also even with low token count, you can take the current prompt + current response to create a new prompt and call the endpoint. Do this as long as the code isn’t complete or context length of model isn’t reached.

I ran your prompt in the playground

Also make the prompt as clear and concise if you want to use codex models, they are optimized for code not chat.

There are a lot of insightful posts about codex series models on the community. I’d recommend that you search and read them.

Also here’s the output when I optimized your prompt for codex series.

/* SeoMT is a class that returns the SEO relevant meta tags for a WordPress theme. SeoMT considers the type of content shown (single post, archive, etc) in order to derive the meta tags. */
class SeoMT {
	
	/* The constructor for SeoMT. */
	function SeoMT() {
		
		/* The default values for the meta tags. */
		$this->default_title = get_bloginfo('name');
		$this->default_description = get_bloginfo('description');
		$this->default_keywords = '';
		
		/* The default values for the Open Graph tags. */
		$this->default_og_title = $this->default_title;
		$this->default_og_type = 'blog';
		$this->default_og_url = get_bloginfo('url');
		$this->default_og_image = '';
		$this->default_og_site_name = $this->default_title;
		$this
		->default_og_description = $this->default_description;
		
		/* The default values for the Dublin Core tags. */
		$this->default_dc_title = $this->default_title;
		$this->default_dc_description = $this->default_description;
		$this->default_dc_subject = '';
		$this->default_dc_creator = get_bloginfo('admin_email');
		$this->default_dc_publisher = get_bloginfo('name');
		$this->default_dc_contributor = '';
		$this->default_dc_date = date('Y-m-d');
		$this->default_dc_type = 'Text';
		$this->default_dc_format = 'text/html';
		$this->default_dc_identifier = get_bloginfo('url');
		$this->default_dc_source = get_bloginfo('url');
		$this->default_dc_language = get_bloginfo('language');
		$this->default_dc_relation = '';
		$this->default_dc_coverage = '';
		$this->default_dc_rights = '';
		
		/* The default values for the Twitter Card tags. */
		$this->default_twitter_card = 'summary';
		$this->default_twitter_site = '';
		

Here’s the link to playground preset.

Hope this helps.

2 Likes

Thanks!

When looking at the preset, and viewing the code (cURL) I see this prompt is used:

  "prompt": "/* SeoMT is a class that returns the SEO relevant meta tags for a WordPress theme. SeoMT considers the type of content shown (single post, archive, etc) in order to derive the meta tags. */\nclass SeoMT {\n\t\n\t/* The constructor for SeoMT. */\n\tfunction SeoMT() {\n\t\t\n\t\t/* The default values for the meta tags. */\n\t\t$this->default_title = get_bloginfo('name');\n\t\t$this->default_description = get_bloginfo('description');\n\t\t$this->default_keywords = '';\n\t\t\n\t\t/* The default values for the Open Graph tags. */\n\t\t$this->default_og_title = $this->default_title;\n\t\t$this->default_og_type = 'blog';\n\t\t$this->default_og_url = get_bloginfo('url');\n\t\t$this->default_og_image = '';\n\t\t$this->default_og_site_name = $this->default_title;\n\t\t$this\n\t\t->default_og_description = $this->default_description;\n\t\t\n\t\t/* The default values for the Dublin Core tags. */\n\t\t$this->default_dc_title = $this->default_title;\n\t\t$this->default_dc_description = $this->default_description;\n\t\t$this->default_dc_subject = '';\n\t\t$this->default_dc_creator = get_bloginfo('admin_email');\n\t\t$this->default_dc_publisher = get_bloginfo('name');\n\t\t$this->default_dc_contributor = '';\n\t\t$this->default_dc_date = date('Y-m-d');\n\t\t$this->default_dc_type = 'Text';\n\t\t$this->default_dc_format = 'text/html';\n\t\t$this->default_dc_identifier = get_bloginfo('url');\n\t\t$this->default_dc_source = get_bloginfo('url');\n\t\t$this->default_dc_language = get_bloginfo('language');\n\t\t$this->default_dc_relation = '';\n\t\t$this->default_dc_coverage = '';\n\t\t$this->default_dc_rights = '';\n\t\t\n\t\t/* The default values for the Twitter Card tags. */\n\t\t$this->default_twitter_card = 'summary';\n\t\t$this->default_twitter_site = '';\n\t\t",

That is the whole code it actually returned as response.
I guess there is something wrong with my understanding of what the prompt is in the code on the sandbox, or, the prompt actually was… the response?

When I run the cURL suggested by the sandbox you shared, I obviously would get that exact response - but this is understandably not the goal.
May I ask what prompt you used on the sandbox?
It certainly was not the whole code?

I tried with “my” original prompt in the sandbox and … got That model is currently overloaded with other requests. You can retry your request, or contact us through our help center at help.openai.com if the error persists. (Please include the request ID 4433b7e2c82623b1a17d127284793b8b in your message.)
When I tried again, it threw The server experienced an error while processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if the error persists.
Basically, no matter what I try (this was in the link you shared with me) it seems to fail

However, as this will be discontinued anyway… tomorrow! I guess it is futile to try with that model anyway?
And I should just wait for the gpt-4 to be opening to public?

1 Like

3.5 does code just fine. I don’t know how you got the idea it doesn’t. You need to be very specific to get it out of “conversational” mode.

1 Like

This is how I got that idea:

I also was under the impression it would do code, yet it states it won’t?

Just to clarify that the online chatGPT 4 generates almost state of the art code on that prompt. Which is the whole and sole reason I was impressed and wanted to use the api :grimacing:

The prompt in that example was

rest of it was the completion.

You should start experimenting with gpt-3.5-turbo and it’ll most likely suffice. In case it doesn’t, try gpt-4.

Even OpenAI recommends that once you make something work on GPT-4, you should try to replicate it on gpt-3.5-turbo because it’s very inexpensive to consume.

Since you are new, I’d recommend reading the docs to get yourself familiar with the API and make better use of it.

1 Like