openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.57k stars 466 forks source link

How can I execute runs with exististing thread #270

Closed kaemmi84 closed 7 months ago

kaemmi84 commented 7 months ago

`public function postMessage($user, $content, $role) { $this->getOrCreateThreat(); $now = Carbon::now(); //create user content $response = $this->openAIClient->threads()->messages()->create($this->threadId, [ 'role' => $role, 'content' => "$now:::\n\n {$content}",

    ]);
    foreach ($response->content as $content) {
        $message = new Message;
        $message->role = $response->role;
        $message->content = $content->text->value;
        $user->messages()->save($message);
    }

    //run thread
    $response = $this->openAIClient->threads()->?
}`

I don't find a function to run existing threads in the documentation

EDIT: Ok I find $this->openAIClient->threads()->runs()->create how can I use this?
gehrisandro commented 7 months ago

Hi @kaemmi84

You need to provide the thread_id. See: https://github.com/openai-php/client/tree/0.8.x#threads-runs-resource-beta

Hope this helps. Otherwise, let me know.