read_user_message Subroutine

private impure elemental subroutine read_user_message(this, file_name, command)

Uses

    • face
  • proc~~read_user_message~~UsesGraph proc~read_user_message foropenai_ChatCompletion::ChatCompletion%read_user_message face face proc~read_user_message->face

Type Bound

ChatCompletion

Arguments

Type IntentOptional Attributes Name
class(ChatCompletion), intent(inout) :: this
character(len=*), intent(in) :: file_name
character(len=*), intent(in) :: command

Calls

proc~~read_user_message~~CallsGraph proc~read_user_message foropenai_ChatCompletion::ChatCompletion%read_user_message colorize colorize proc~read_user_message->colorize proc~set_user_message foropenai_ChatCompletion::ChatCompletion%set_user_message proc~read_user_message->proc~set_user_message proc~set_content foropenai_ChatCompletion::ChatCompletion_messages%set_content proc~set_user_message->proc~set_content

Called by

proc~~read_user_message~~CalledByGraph proc~read_user_message foropenai_ChatCompletion::ChatCompletion%read_user_message proc~conversation foropenai_ChatCompletion::ChatCompletion%conversation proc~conversation->proc~read_user_message

Source Code

   elemental impure subroutine read_user_message(this, file_name, command)
      use face, only: colorize
      class(ChatCompletion),         intent(inout) :: this
      character(len=*),              intent(in)    :: file_name
      character(len=*),              intent(in)    :: command
      character(len=:), allocatable                :: message
      character(len=:), allocatable                :: whole_message
      character(len=1000000)                       :: tmp
      integer                                      :: iounit, iostat

      write(*,"(A,': ')",advance='no') colorize(trim(this%user_name), color_bg='green')
      read*, tmp
      message = trim(tmp)
      if (trim(message) == trim(command)) then
         open(newunit=iounit, file=trim(file_name), status='old', action='read')
         whole_message = ''
         do
            read(iounit,'(A)',iostat=iostat) tmp
            if (iostat /= 0) exit
            whole_message = trim(whole_message) // trim(tmp)  // new_line(' ')
         end do
         close(iounit)
         call this%set_user_message(message=whole_message)
      else
         call this%set_user_message(message=message)
      end if
   end subroutine read_user_message