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

[Bug]: Validation error for Request calling createAndRun() #333

Open
bobbingwide opened this issue Feb 8, 2024 · 1 comment
Open

[Bug]: Validation error for Request calling createAndRun() #333

bobbingwide opened this issue Feb 8, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@bobbingwide
Copy link

Description

I'm trying to use Assistants and Threads in order to benefit from the Code interpreter functionality.
Unfortunately I've failed at the second hurdle - using CreateAndRun
The first was realising that I didn't need to create an Assistant for each request.

My call is basically straight out of the book.

$this->client = OpenAI::client( $this->OpenAIKey );

$response = $this->client->threads()->createAndRun(
			[ 'assistant_id' => $this->assistant_id,
				'thread' => [
					'messages' =>
					[ 'role' => 'user',
						'content' => 'what time is 1706918400'
					]
				]
			]
		);

where $this->assistant_id is the ID of an assistant I've created either manually in OpenAI or using the API.
An exception is produced but I do not know what to do to fix it.

{
  "error": {
    "message": "1 validation error for Request\nbody -> thread -> messages\n  value is not a valid list (type=type_error.list)",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }

Stack trace:

#0 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\vendor\openai-php\client\src\Transporters\HttpTransporter.php(57): OpenAI\Transporters\HttpTransporter->throwIfJsonError(Array, '{\n  "error": {\n...')
#1 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\vendor\openai-php\client\src\Resources\Threads.php(51): OpenAI\Transporters\HttpTransporter->requestObject(Object(OpenAI\ValueObjects\Transporter\Payload))
#2 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\classes\class-Oik-AI.php(217): OpenAI\Resources\Threads->createAndRun(Array)
#3 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\oik-ai.php(87): Oik_AI->assist('what time is 17...')
#4 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\oik-ai.php(43): oik_ai_invoke_assist(Object(Oik_AI))
#5 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\oik-ai.php(32): oik_ai_loaded_batch()
#6 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\oik-ai.php(107): oik_ai_loaded()
#7 C:\apache\htdocs\wordpress\wp-content\plugins\oik-batch\libs\oik-cli.php(611): require_once('C:\\apache\\htdoc...')
#8 C:\apache\htdocs\wordpress\wp-content\plugins\oik-batch\libs\oik-cli.php(579): oik_batch_run_script('oik-ai.php')
#9 C:\apache\htdocs\wordpress\wp-content\plugins\oik-batch\oik-wp.php(141): oik_batch_run()
#10 C:\apache\htdocs\wordpress\wp-content\plugins\oik-batch\oik-wp.php(180): oik_wp_loaded()
#11 {main}
  thrown in C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\vendor\openai-php\client\src\Transporters\HttpTransporter.php on line 133

I do understand this could be a question for the OpenAI Community forum.

Someone's having a similar problem, well a similar message, at https://community.openai.com/t/api-calls-to-v1-threads-thread-id-messages-fails-with-file-and-file-ids/613781

The problem that I am trying to resolve by using Assistants is documented in bobbingwide/oik-ai#10
thanks in advance for any help, Herb

PS. The answer that I'm hoping to get is along the lines of "The timestamp 1706918400 corresponds to the date and time 2024-02-03 00:00:00 UTC."

Steps To Reproduce

  1. Write code to make the calls above.
  2. Run the code from your PC in a command prompt

OpenAI PHP Client Version

v0.8.4

PHP Version

8.3.0

Notes

Sorry, but I haven't yet created the minimum code to demonstrate this problem. I'm hoping someone's experienced something similar and can explain the error message.

@bobbingwide bobbingwide added the bug Something isn't working label Feb 8, 2024
@bobbingwide
Copy link
Author

The minimum code to demonstrate the problem.
I created a subfolder called tests with a file called assistant.php
Source code of assistant.php with apiKey and assistant_id obfuscated.

<?php
/**
 * Simple test of the Assistant API
 *
 */
require '../vendor/autoload.php';
$client = OpenAI::client( 'sk-obfuscated' );
//print_r( $client );
$response = $client->threads()->createAndRun(
	[ 'assistant_id' => 'asst_obfuscated',
	  'thread' => [
		  'messages' =>
			  [ 'role' => 'user',
			    'content' => 'what time is 1706918400'
			  ]
	  ]
	]
);

When I run "php assistant.php" I get


Fatal error: Uncaught OpenAI\Exceptions\ErrorException: 1 validation error for Request
body -> thread -> messages
  value is not a valid list (type=type_error.list) in C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\vendor\openai-php\client\src\Transporters\HttpTransporter.php:133
Stack trace:
#0 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\vendor\openai-php\client\src\Transporters\HttpTransporter.php(57): OpenAI\Transporters\HttpTransporter->throwIfJsonError(Array, '{\n  "error": {\n...')
#1 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\vendor\openai-php\client\src\Resources\Threads.php(51): OpenAI\Transporters\HttpTransporter->requestObject(Object(OpenAI\ValueObjects\Transporter\Payload))
#2 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\tests\assistant.php(9): OpenAI\Resources\Threads->createAndRun(Array)
#3 {main}
  thrown in C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\vendor\openai-php\client\src\Transporters\HttpTransporter.php on line 133

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

1 participant