Skip to content
Snippets Groups Projects
Select Git revision
  • 8d62939b910ba195fa8ca3e84b4b0b366375f4a8
  • main default protected
  • Iteration_1
3 results

OpenAIClient.php

Blame
  • OpenAIClient.php 1.46 KiB
    <?php
    class OpenAIClient
    {
        private string $question;
        private string $code;
        private string $test;
    
    
        public function __construct(string $question)
        {
            $this->question = $question;
            $this->code = $this->genCode();
            $this->test = $this->genTest();
        }
    
    
        public function genCode(): string
        {
            $client = OpenAI::client('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');
            $result = $client->completions()->create([
                'model' => 'text-davinci-003',
                'prompt' => $this->question,
            ]);
    
            return $result['choices'][0]['text'];
        }
    
        public function genTest(): string
        {
            $client = OpenAI::client('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');
            $result = $client->completions()->create([
                'model' => 'text-davinci-003',
                'prompt' => $this->question,
            ]);
    
            return $result['choices'][0]['text'];
        }
    
    
        public function getQuestion(): string
        {
            return $this->question;
        }
    
        public function setQuestion(string $question): void
        {
            $this->question = $question;
        }
    
        public function getCode(): string
        {
            return $this->code;
        }
    
        public function setCode(string $code): void
        {
            $this->code = $code;
        }
    
        public function getTest(): string
        {
            return $this->test;
        }
    
        public function setTest(string $test): void
        {
            $this->test = $test;
        }
    }