Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat API continuous thread #75

Closed
developer-gurpreet opened this issue Mar 22, 2023 · 1 comment
Closed

Chat API continuous thread #75

developer-gurpreet opened this issue Mar 22, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@developer-gurpreet
Copy link

Describe the bug

When script send next request to chat API, it returns different response, how can we continue same thread?

To Reproduce

Continue thread

Code snippets

No response

OS

MAC

PHP version

PHP latest

Library version

latest

@developer-gurpreet developer-gurpreet added the bug Something isn't working label Mar 22, 2023
@orhanerday
Copy link
Owner

orhanerday commented Mar 22, 2023

Please append ai response to as another element to the messages array, The request should be dynamic

<?php

require __DIR__ . '/vendor/autoload.php'; // remove this line if you use a PHP Framework.

use Orhanerday\OpenAi\OpenAi;

$open_ai_key = getenv('OPENAI_API_KEY');
$open_ai = new OpenAi($open_ai_key);

$complete = $open_ai->chat([
   'model' => 'gpt-3.5-turbo',
   'messages' => [
       [
           "role" => "system",
           "content" => "You are a helpful assistant."
       ],
       [
           "role" => "user",
           "content" => "Who won the world series in 2020?"
       ],
       [
           "role" => "assistant",
           "content" => "The Los Angeles Dodgers won the World Series in 2020."
       ],
       [
           "role" => "user",
           "content" => "Where was it played?"
       ],

       [
           "role" => "assistant",
           "content" => "Los Angeles"
       ],
       [
           "role" => "user",
           "content" => "Where is Los Angeles?"
       ],
   ],
   'temperature' => 1.0,
   'max_tokens' => 4000,
   'frequency_penalty' => 0,
   'presence_penalty' => 0,
]);

var_dump($complete); 

As you can see I add two elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants