Comments (21)
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.
Sorry about that, Let's try with Docker then. I'll be waiting for your response.
from open-ai.
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.
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.
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.
I test on my local (Laravel v9.17.0 (PHP v8.1.6), and I didn't find any issue like that.
returned $engines
Returned $data
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.
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.
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.
The curl command works in gitbash
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.
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.
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.
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.
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
from open-ai.
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.
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.
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.
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.
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.
I'm so glad for everything solved out. Also thank you so much for good wishes.
from open-ai.
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.
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)
- 'answers' is not one of ['fine-tune'] - 'purpose' HOT 1
- Where are the error codes from the OpenAI documentation ? HOT 4
- OpenAI now has gpt-turbo-3.5 fine tuning the one you have currently is deprecated can you add the new api calls? HOT 4
- Auto-continuing when max_token limit reached HOT 1
- there is a responsibility for the temperature values HOT 1
- ChatGPT 4 API Support HOT 1
- text-davinci-003 is deprecated HOT 2
- The data returned is confusing when use stream HOT 11
- ChatGPT request very slowly, up to 2-3 mins HOT 3
- Model API route no longer returning permissions HOT 3
- DALLE-3 HOT 1
- New Assistants API support? HOT 10
- Does the new speech-to-text api offer support? HOT 1
- Chat API: first event line gets split into two for streamed response HOT 1
- Sorry, you have been blocked HOT 5
- tts support HOT 2
- json_object HOT 2
- Obsolete README
- Function calling HOT 1
- Function Calling? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from open-ai.