Coder Social home page Coder Social logo

Comments (21)

davidblanco-m avatar davidblanco-m commented on May 20, 2024 7

Hello,

Had the same issue, it seems to be related to the SSL certificate as @silicahd mentioned, I managed to get around it by adding the following flags in the $curl_info variable:

CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,

at the end of the open-ai/src/OpenAi.php file

thank you @orhanerday for this amazing repo πŸ‘

from open-ai.

orhanerday avatar orhanerday commented on May 20, 2024 1

Sorry about that, Let's try with Docker then. I'll be waiting for your response.

from open-ai.

geosem42 avatar geosem42 commented on May 20, 2024 1

It finally worked! I got curl to finally work.

Thank you for your patience, I can't wait to see the limits of this library.

from open-ai.

orhanerday avatar orhanerday commented on May 20, 2024 1

That's great to hear that! it's not boring, so I don't need any patience :). I feel glad while helping you guys.

Have a great day!

from open-ai.

silicahd avatar silicahd commented on May 20, 2024 1

For anybody running into this if you are using something like aaPanel or others likely your certificate is expired.

Credit to this fix to the guys from the aaPanel forum.
@orhanerday thank you for the support and the amazing package.

mkdir -p /etc/pki/tls/certs wget -O /etc/pki/tls/certs/ca-bundle.crt https://curl.se/ca/cacert.pem --no-check-certificate chmod 444 /etc/pki/tls/certs/ca-bundle.crt

from open-ai.

orhanerday avatar orhanerday commented on May 20, 2024

I test on my local (Laravel v9.17.0 (PHP v8.1.6), and I didn't find any issue like that.

returned $engines
image
Returned $data
image

I don't recommend using dd, because they didn't have a friendly JSON format, return data then use JSON viewer instead of.

TROUBLESHOOTING

  • Did you install the package with composer require orhanerday/open-ai ?
  • Please check your OpenAI credit.
  • You should get an error when providing a wrong API key, just in case; check your API key twice.

from open-ai.

geosem42 avatar geosem42 commented on May 20, 2024

I am stumped. I get a blank page when I return $data or return $engines.

Yes, I have installed orhanerday/open-ai and I have plenty of credits in my account.

But what's weird is that I am not getting an error when I put a wrong API key.

from open-ai.

orhanerday avatar orhanerday commented on May 20, 2024

Could you please run the following curl command?

curl https://api.openai.com/v1/completions \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{
  "model": "text-davinci-002",
  "prompt": "Say this is a test",
  "max_tokens": 5
}'

You should see response like this;

{
  "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
  "object": "text_completion",
  "created": 1589478378,
  "model": "text-davinci-002",
  "choices": [
    {
      "text": "\n\nThis is a test",
      "index": 0,
      "logprobs": null,
      "finish_reason": "length"
    }
  ]
}

I just wanna check if you can easily access OpenAI servers. If you see any error notice me.

After that, I need your PHP, and laravel versions.
Also, I need to check (should returned 1) cURL exists in PHP, for that put the following code to your index function;

public function index(){
      return function_exists('curl_version');
...

from open-ai.

geosem42 avatar geosem42 commented on May 20, 2024

The curl command works in gitbash

curl

function_exists('curl_version') returns 1
Curl version is 7.79.1
Laravel version 9.17.0
PHP version 8.1.0

from open-ai.

orhanerday avatar orhanerday commented on May 20, 2024

I didn't catch any reason for the bug. So I prepare another troubleshooting

  • lets pretty sure our curl is working. For this, put code your PHP file

// From URL to get webpage contents.
$url = "https://www.geeksforgeeks.org/";
 
// Initialize a CURL session.
$ch = curl_init();
 
// Return Page contents.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
//grab URL and pass it to the variable.
curl_setopt($ch, CURLOPT_URL, $url);
 
$result = curl_exec($ch);
 
echo $result; 

Did you see the gfg page?

  • Also can you install laravel with docker?

from open-ai.

geosem42 avatar geosem42 commented on May 20, 2024

I am still getting a blank page.

Very weird, because curl -V works.

I am downloading Docker Desktop but I've never used it before.

from open-ai.

orhanerday avatar orhanerday commented on May 20, 2024

I think cURL is disabled in PHP, for enabling can you apply these steps?

  • Open php.ini (it’s usually in /etc/ or in the PHP folder on the server).
  • Search for extension=php_curl.dll. Uncomment it by removing the semi-colon( ; ) in front of it.
  • Restart the Apache Server.

from open-ai.

geosem42 avatar geosem42 commented on May 20, 2024

Thank you for taking the time to help me out, I appreciate it.

extension=curl was uncommented, I changed it to php_curl and php_curl.dll but got the same blank page.

Also please note I am using wampserver and curl is enabled

wampserver

from open-ai.

silicahd avatar silicahd commented on May 20, 2024

return function_exists('curl_version');

How did you fix this issue? I have been going at it for about two days and I am getting the same thing on multiple systems.

from open-ai.

silicahd avatar silicahd commented on May 20, 2024

I didn't catch any reason for the bug. So I prepare another troubleshooting

  • lets pretty sure our curl is working. For this, put code your PHP file

// From URL to get webpage contents.
$url = "https://www.geeksforgeeks.org/";
 
// Initialize a CURL session.
$ch = curl_init();
 
// Return Page contents.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
//grab URL and pass it to the variable.
curl_setopt($ch, CURLOPT_URL, $url);
 
$result = curl_exec($ch);
 
echo $result; 

Did you see the gfg page?

  • Also can you install laravel with docker?

I think there might be an issue, because the code you posted does not work. But this code works. Sorry for reopening this but i have not been able to get this to work for a few days now. works in terminal but not once i install it.

https://www.plus2net.com/php_tutorial/curl-demo.php

from open-ai.

silicahd avatar silicahd commented on May 20, 2024

I didn't catch any reason for the bug. So I prepare another troubleshooting

  • lets pretty sure our curl is working. For this, put code your PHP file

// From URL to get webpage contents.
$url = "https://www.geeksforgeeks.org/";
 
// Initialize a CURL session.
$ch = curl_init();
 
// Return Page contents.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
//grab URL and pass it to the variable.
curl_setopt($ch, CURLOPT_URL, $url);
 
$result = curl_exec($ch);
 
echo $result; 

Did you see the gfg page?

  • Also can you install laravel with docker?

This is so odd. The code you posted does not work.
$url = 'https://api.plos.org/search?q=title:DNA'; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer API CODE HERE' )); curl_setopt($ch, CURLOPT_URL,$url); $result=curl_exec($ch); curl_close($ch); return $result;

This code works just fine

        $url = 'https://api.plos.org/search?q=title:DNA';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER,     array(
            'Authorization: Bearer API CODE HERE'
            ));
        curl_setopt($ch, CURLOPT_URL,$url);
        $result=curl_exec($ch);
        curl_close($ch);
        return $result;

But if i change the URL to
https://api.openai.com/v1/models
and add my api it will return null

The odd thing is that i can test this via Postman or Curl terminal with no issues. I am sure this is not something on the code side but i just cant figure this out it baffles me.

from open-ai.

orhanerday avatar orhanerday commented on May 20, 2024

hey @silicahd, could you create an index.php and put following example.

<?php

require __DIR__ . '/vendor/autoload.php'; 

use Orhanerday\OpenAi\OpenAi;

$open_ai = new OpenAi('sk-gjtv.....');

$complete = $open_ai->complete([
    'engine' => 'davinci',
    'prompt' => 'Hello',
    'temperature' => 0.9,
    'max_tokens' => 150,
    'frequency_penalty' => 0,
    'presence_penalty' => 0.6,
]);

var_dump($complete);

can you share your response?

from open-ai.

silicahd avatar silicahd commented on May 20, 2024

hey @silicahd, could you create an index.php and put following example.

<?php

require __DIR__ . '/vendor/autoload.php'; 

use Orhanerday\OpenAi\OpenAi;

$open_ai = new OpenAi('sk-gjtv.....');

$complete = $open_ai->complete([
    'engine' => 'davinci',
    'prompt' => 'Hello',
    'temperature' => 0.9,
    'max_tokens' => 150,
    'frequency_penalty' => 0,
    'presence_penalty' => 0.6,
]);

var_dump($complete);

can you share your response?

I found the issue but cant figure out how to fix it. I add the line to get the error from Curl and it came back to "SSL certificate problem: certificate has expired" . My SSL is there so i am trying to figure out if we can do insecure so figure out why CURL gives this response.

from open-ai.

orhanerday avatar orhanerday commented on May 20, 2024

I'm so glad for everything solved out. Also thank you so much for good wishes.

from open-ai.

Thefrenchdev avatar Thefrenchdev commented on May 20, 2024

Edit : Neevermind after 24hours it works

I'm having the same issue with Symfony.
here's my service.php :

public function getAnswer(string $question) : string
    {
        $open_ai_key = $this->parameterBag->get('OPENAI_API_KEY');
        $open_ai = new OpenAi($open_ai_key);
        $complete = $open_ai->completion([
            'model' => 'davinci',
            'prompt' => 'Hello',
            'temperature' => 0.9,
            'max_tokens' => 150,
            'frequency_penalty' => 0,
            'presence_penalty' => 0.6,        ]);
        $json = json_decode($complete, true);        
        var_dump($json);
        return $complete;
    }

from open-ai.

bdkoder avatar bdkoder commented on May 20, 2024

Hello,

Had the same issue, it seems to be related to the SSL certificate as @silicahd mentioned, I managed to get around it by adding the following flags in the $curl_info variable:

CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,

at the end of the open-ai/src/OpenAi.php file

thank you @orhanerday for this amazing repo πŸ‘

Thank you very much. It's saved me hours of time.

from open-ai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.