V2Test.php 858 B

1234567891011121314151617181920212223242526
  1. <?php
  2. use HaoZiTeam\ChatGPT\V2;
  3. $secretKey = getenv('OPENAI_SECRET_KEY');
  4. $chatGPT = new V2($secretKey);
  5. $chatGPT->addMessage(
  6. 'You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.',
  7. 'system'
  8. );
  9. it('should get a new conversation', function () use ($chatGPT) {
  10. $return = $chatGPT->ask('Hello, how are you?');
  11. foreach ($return as $answer) {
  12. $this->assertArrayHasKey('answer', $answer);
  13. }
  14. })->group('working');
  15. it('should get a answer contact the context', function () use ($chatGPT) {
  16. $chatGPT->ask('Hello, how are you?');
  17. $return = $chatGPT->ask('What did I ask you just now?');
  18. foreach ($return as $answer) {
  19. $this->assertArrayHasKey('answer', $answer);
  20. $this->assertStringContainsString('Hello, how are you?', $answer['answer']);
  21. }
  22. })->group('working');