check_chat_completion Subroutine

private impure elemental subroutine check_chat_completion(this, error)

Type Bound

ChatCompletion

Arguments

Type IntentOptional Attributes Name
class(ChatCompletion), intent(inout) :: this
integer, intent(out) :: error

Called by

proc~~check_chat_completion~~CalledByGraph proc~check_chat_completion foropenai_ChatCompletion::ChatCompletion%check_chat_completion proc~create_chat_completion foropenai_ChatCompletion::ChatCompletion%create_chat_completion proc~create_chat_completion->proc~check_chat_completion proc~conversation foropenai_ChatCompletion::ChatCompletion%conversation proc~conversation->proc~create_chat_completion program~test_chatcompletion test_ChatCompletion program~test_chatcompletion->proc~create_chat_completion

Source Code

   elemental impure subroutine check_chat_completion(this, error)
      class(ChatCompletion), intent(inout) :: this
      integer,               intent(out)   :: error
      integer                              :: i

      if (len_trim(this%api_key) == 0) then
         print '(A)', 'Error: api_key is not set.'
         error = 1
         stop
      end if

      if (len_trim(this%url) == 0) then
         print '(A)', 'Error: url is not set.'
         error = 2
         stop
      end if

      if (len_trim(this%model) == 0) then
         print '(A)', 'Error: model is not set.'
         error = 3
         stop
      end if

      if (.not. allocated(this%messages)) then
         print '(A)', 'Error: messages is not set.'
         error = 4
         stop
      end if

      do i = 1, size(this%messages)
         if (len_trim(this%messages(i)%role) == 0) then
            print '(A,I1,A)', 'Error: messages(',i,')%role is not set.'
            error = 5
            stop
         end if
      end do

      do i = 1, size(this%messages)
         if (.not. allocated(this%messages(i)%content)) then
            print '(A,I1,A)', 'Error: messages(',i,')%content is not set.'
            error = 6
            stop
         end if
      end do

      if (this%temperature < 0.0 .or. this%temperature > 2.0) then
         print '(A)', 'Error: temperature must be between 0.0 and 2.0.'
         error = 7
         stop
      end if

      if (this%max_tokens < 1) then
         print '(A)', 'Error: max_tokens must be greater than 1'
         error = 8
         stop
      end if

      if (len_trim(this%user_name) == 0) then
         print '(A)', 'Error: user_name is not set.'
         error = 9
         stop
      end if

      error = 0

   end subroutine check_chat_completion