1
0

V1Test.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. use HaoZiTeam\ChatGPT\V1;
  3. $accessToken = getenv('OPENAI_ACCESS_TOKEN');
  4. $chatGPT = new V1();
  5. $chatGPT->addAccount($accessToken, 0, 'gpt-4');
  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');
  41. it('should return plugins list', function () use ($chatGPT) {
  42. $return = $chatGPT->getPlugins();
  43. $this->assertIsArray($return);
  44. })->group('working');
  45. it('should change history and training status', function () use ($chatGPT) {
  46. $return = $chatGPT->setChatHistoryAndTraining(true);
  47. $this->assertTrue($return);
  48. })->group('working');