orhanerday / open-ai

OpenAI PHP SDK : Most downloaded, forked, contributed, huge community supported, and used PHP (Laravel , Symfony, Yii, Cake PHP or any PHP framework) SDK for OpenAI GPT-3 and DALL-E. It also supports chatGPT-like streaming. (ChatGPT AI is supported)
https://orhanerday.gitbook.io/openai-php-api-1/
MIT License
2.24k stars 287 forks source link

Open AI Ada text completion returns bad results in code but works in playground #41

Closed vedran-korponajic closed 1 year ago

vedran-korponajic commented 1 year ago

Describe the bug

I'm trying to use the Ada language processor of OpenAi to summarize a piece of text. When I try to use their playground, the function works and I get a summarization that makes sense and can be used by humans. This is the cURL from the playground:

curl https://api.openai.com/v1/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "text-ada-001", "prompt": "Please write a one paragraph professional synopsis:\n\nSome text", "temperature": 0, "max_tokens": 60, "top_p": 1, "frequency_penalty": 0, "presence_penalty": 0 }'

This is the code that I use in PHP:

`$open_ai_key = 'xxx'; $open_ai = new OpenAi($open_ai_key);

    $complete = $open_ai->completion([
        'model' => 'text-ada-001',
        'prompt' => 'Please write a one paragraph professional synopsis: ' . $text,
        'temperature' => 0,
        'max_tokens' => 60,
        'frequency_penalty' => 0,
        'presence_penalty' => 0,
    ]);

    return $complete;`

I have also tried to use a both ada and davinci and in both cases it returns nonsense. I'm saying nonsense, because the text that it returns is not something that can be read and said, 'Hey, this is a proffesional synopsis'. I'm going to give an example of a sentence that I got in one of the iterations:

'It's not pretty and no I thought to myself, oh look IT'S NOT THAT REPUBLICAN kids would kno one of these things. OH IT'S A RESTRICTIOUS SCHOOL'.

I can assure you, there are no mentions of republicans or kids in the text that I'm processing.

My question is, am I doing something wrong? Does OpenAi work differently on their playground and in code?

To Reproduce

  1. Write a new PHP function that will try to create a proffesional synopsis using the ada model.
  2. Paste in a piece of text and make the request
  3. Compare the results in the OpenAI playground and in code and see that they are wildly different.

Example text that I'm using:

Alright then. Uh So welcome to another episode of E. M. S. On the Mountain. This one from the mountain. Oh snap. This is the show for those interested in Austrian rulers medicine. I'm Sean as always joined by my backcountry partner mike. And today's show we're gonna talk about one of our cases we had, I don't know, probably a couple of years ago now, while back. Yeah, so this was mike's so he's going to lead us through this party. So I'm guessing because I'm so bad at the editing and the getting things online at a reasonable time that this will be the first case review that we put up on the interwebs. But this is a new thing we're trying out. We're uh we're gonna do a few shows from the mountain. So normally I sit in my basement and Sean sits in his basement. We stare at each other across the magic of the interwebs. But today we are literally sitting across the table from each other in a old old building in the middle of the woods, attempting to record something that's lively and exciting for you folks. So let's see how this goes. So, so if you hear background noise like no kidding animals, birds and random people, radios, people, doors, it's all part of the part of the party and it could be a train wreck, but I have a feeling that at least one person and only one person johnny b will give us his feedback on what he thinks about this and maybe our wives will care. But yeah, all right, so let's talk about this. We had a case a couple of years ago that started out as a normal, it's a normal saturday afternoon in the woods. And uh, the tones drop. No, the tones did not drop. I apologize. There was no tone drop it. There was a, there was a call on the radio from a uh, from a report of it went out as a person with a little trouble breathing. That was an understatement in a certain respect. And it was suggested that perhaps we go kind of check it out, see what's going on. So we jump in our magic buggy and bop on over, luckily this patient wasn't too too far away from where we were at the time. We head down trail we found said person, they were 100 yards off of a fire road. And that fire road was maybe 5200 yards from a paved road. So they weren't real deep in the woods. But they were definitely hiking. They were definitely on a trail. They were definitely about £400. Yes, Yes. They were just want to make sure we paint that map properly. So we're, we're about 100 50 yards down a rocky trail. Maybe 200. I said I'd go between two and 300. Okay, a little bit further. That trail led to eventually an intersection with a fire road and that fire road about 100 yards or so from hard top if you will. So here we are with a £400 individual who's breathing at a rate of, I don't know, 800 or so. It's more like it was, it was more like between 35 and 40. They were uh yeah, this patient was panting like a champion. Now let's back up because I love storytelling and I like to do it and completely jacked up time order because I didn't make notes prior to proceeding down trail. After we stepped out of our trusty steed, we were greeted by the patient's family member and this family member immediately informed us that they were within two or three minutes. They informed us that their family member was just having a quote sugar problem because they had the diabetes and that she was in fact a paramedic at one point but did not want to keep that up because they were going to make her do si es She didn't know she had to do si es tu research so she lost it real quick. Like but she definitely was a paramedic and she was definitely convinced that her family member was experiencing a sugar problem. Yeah. So I'm not so convinced that she was ever a paramedic. I'm just going by what I was dog hey, it is what it is. Yeah. So we also learned as we proceeded down to link up with said patient that a number of bystanders. Another a number. Excuse me not bystanders. A number of other hikers that had come by had provided various snacks and sugar free products because it was believed that this individual is experiencing a hypoglycemic event and needed more sugar. So upon arrival on scene, by the way, just a little note here, we did bring a cardiac monitor with us because it was only 100 yards or so. It was a report of a person having trouble breathing. The one and only time mike and I have ever taken a life pack down a trail. There was one other time. We'll talk about that one. That's when I carried it all the way down. Dark hollow for the girl with the weird chest thing. A 30 year old whatever. And I decided I was never doing that again. I'll have to cut out the dark hollow part because that's kind of Yeah, whatever carried it down that trail. So upon arrival, one of the first things a good paramedics gonna do is assess the scene. And then since it was reported that this person is having a sugar problem, we assess the state of her sugar needs keep in mind breathing at 35 to 40. Diaphragmatic. Sitting on a log, leaning against another nice bystander. Yeah. Trying to hold her upright so we get a quick finger prick. I don't remember what her blood pressure was off the top of my head. It wasn't astronomical. No, it was maybe upper one hundred's very low 200. Remember being better than mine. It wasn't. Yeah, nothing that made you go, Oh, she's good at, I mean she's breathing at like 40 And she's diaphragmatic. She's been out hiking. And did I mention that she's not a shrinking flower? So we grab the sugar and I will never forget the sugar number 768. And I thought to myself, uh, probably doesn't need any more sugar. So we do grab a quick 12 lead Until

Code snippets

No response

OS

Linux

PHP version

PHP 7.4

Library version

openai v3.4

orhanerday commented 1 year ago

Hi @vedran-korponajic , Can you produce the same test for openai-python? It should be straightforward to make. And please compare responses with my package. I'll be waiting for the results.

orhanerday commented 1 year ago

@vedran-korponajic can you reopen the issue after providing the info?

Now I’ll close the issue,

The reason why; need info