V1Test.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. use HaoZiTeam\ChatGPT\V1;
  3. $accessToken = getenv('OPENAI_ACCESS_TOKEN');
  4. $chatGPT = new V1();
  5. $chatGPT->addAccount($accessToken);
  6. $test = $chatGPT->ask('Hello');
  7. foreach ($test as $answer) {
  8. $conversationId = $answer['conversation_id'];
  9. $parentId = $answer['id'];
  10. }
  11. it('should get a new conversation', function () use ($chatGPT) {
  12. $return = $chatGPT->ask('Hello');
  13. foreach ($return as $answer) {
  14. $this->assertArrayHasKey('answer', $answer);
  15. }
  16. })->group('working');
  17. it('should get a conversations array', function () use ($chatGPT) {
  18. $return = $chatGPT->getConversations();
  19. $this->assertIsArray($return);
  20. })->group('working');
  21. it('should get an array of a conversation', function () use ($chatGPT, $conversationId, $parentId) {
  22. $return = $chatGPT->getConversationMessages($conversationId);
  23. $this->assertIsArray($return);
  24. })->group('working');
  25. it('should auto generate conversation title', function () use ($chatGPT, $conversationId, $parentId) {
  26. $return = $chatGPT->generateConversationTitle($conversationId, $parentId);
  27. $this->assertTrue($return);
  28. })->group('working');
  29. it('should setting conversation title', function () use ($chatGPT, $conversationId, $parentId) {
  30. $return = $chatGPT->updateConversationTitle($conversationId, 'test');
  31. $this->assertTrue($return);
  32. })->group('working');
  33. it('should delete conversation', function () use ($chatGPT, $conversationId, $parentId) {
  34. $return = $chatGPT->deleteConversation($conversationId);
  35. $this->assertTrue($return);
  36. })->group('working');
  37. it('should delete conversations', function () use ($chatGPT) {
  38. $return = $chatGPT->clearConversations();
  39. $this->assertTrue($return);
  40. })->group('working');