ChatCompletion Derived Type

type, public, extends(openai) :: ChatCompletion


Inherits

type~~chatcompletion~~InheritsGraph type~chatcompletion ChatCompletion type~chatcompletion_messages ChatCompletion_messages type~chatcompletion->type~chatcompletion_messages messages type~openai openai type~chatcompletion->type~openai type~usage usage type~chatcompletion->type~usage usage

Components

Type Visibility Attributes Name Initial
character(len=:), public, allocatable :: organization
character(len=:), public, allocatable :: api_key
character(len=:), public, allocatable :: file_name
character(len=14), public :: api_key_env = 'OPENAI_API_KEY'
character(len=10), public :: organization_env = 'OPENAI_ORG'
character(len=:), public, allocatable :: url
character(len=:), public, allocatable :: model
character(len=:), public, allocatable :: user_name
character(len=256), public, allocatable :: model_list(:)
type(ChatCompletion_messages), public, allocatable :: messages(:)
integer, public :: max_tokens
type(usage), public :: usage
real, public :: temperature = 1.0
real, public :: presence_penalty = 0.0
real, public :: frequency_penalty = 0.0
real, public :: top_p = 1.0
logical, public :: stream = .false.
integer, public :: n = 1
character(len=:), public, allocatable :: finish_reason

Type-Bound Procedures

procedure, public :: load_base_data

  • private impure elemental subroutine load_base_data(this, file_name)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, public :: print_api_key

  • private impure elemental subroutine print_api_key(this)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(openai), intent(inout) :: this

procedure, public :: print_organization

  • private impure elemental subroutine print_organization(this)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(openai), intent(inout) :: this

procedure, public :: print_file_name

  • private impure elemental subroutine print_file_name(this)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(openai), intent(inout) :: this

procedure, public :: set_file_name

  • private pure elemental subroutine set_file_name(this, file_name)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, public :: set_base_data

  • private impure elemental subroutine set_base_data(this, file_name, api_key, organization)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(openai), intent(inout) :: this
    character(len=*), intent(in), optional :: file_name
    character(len=*), intent(in), optional :: api_key
    character(len=*), intent(in), optional :: organization

procedure, public :: check => check_chat_completion

  • private impure elemental subroutine check_chat_completion(this, error)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, public :: create => create_chat_completion

  • private impure elemental subroutine create_chat_completion(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, public :: conversation

  • private impure elemental subroutine conversation(this, file_name_base, file_name_ChatCompletion, input_file, output_file, inputfile_command, exit_command)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(inout) :: this
    character(len=*), intent(in) :: file_name_base
    character(len=*), intent(in) :: file_name_ChatCompletion
    character(len=*), intent(in) :: input_file
    character(len=*), intent(in) :: output_file
    character(len=*), intent(in) :: inputfile_command
    character(len=*), intent(in) :: exit_command

procedure, private :: deallocate_messages

  • private pure elemental subroutine deallocate_messages(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: deallocate_model_list

  • private pure elemental subroutine deallocate_model_list(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: deallocate_url

  • private pure elemental subroutine deallocate_url(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: deallocate_model

  • private pure elemental subroutine deallocate_model(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: deallocate_user_name

  • private pure elemental subroutine deallocate_user_name(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: deallocate_finish_reason

procedure, public :: finalize => deallocate_ChatCompletion

procedure, private :: get_assistant_response

  • private pure function get_assistant_response(this) result(response)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(in) :: this

    Return Value character(len=:), allocatable

procedure, private :: get_user_message

  • private pure function get_user_message(this) result(message)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(in) :: this

    Return Value character(len=:), allocatable

procedure, public :: init_messages

  • private pure elemental subroutine init_messages(this, n)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(inout) :: this
    integer, intent(in) :: n

procedure, private :: load => load_ChatCompletion_data

  • private impure elemental subroutine load_ChatCompletion_data(this, file_name)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: load_user_name

  • private impure elemental subroutine load_user_name(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: load_url

  • private impure elemental subroutine load_url(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: load_model

  • private impure elemental subroutine load_model(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: load_temperature

  • private impure elemental subroutine load_temperature(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: load_presence_penalty

  • private impure elemental subroutine load_presence_penalty(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: load_frequency_penalty

  • private impure elemental subroutine load_frequency_penalty(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: load_top_p

  • private impure elemental subroutine load_top_p(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: load_n

  • private impure elemental subroutine load_n(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: load_stream

  • private impure elemental subroutine load_stream(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: load_max_tokens

  • private impure elemental subroutine load_max_tokens(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: read_user_message

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

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: print_user_name

  • private impure elemental subroutine print_user_name(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: print_model_list

  • private impure elemental subroutine print_model_list(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: print_model

  • private impure elemental subroutine print_model(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: print_temperature

  • private impure elemental subroutine print_temperature(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: print_presence_penalty

  • private impure elemental subroutine print_presence_penalty(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: print_frequency_penalty

procedure, private :: print_top_p

  • private impure elemental subroutine print_top_p(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: print_n

  • private impure elemental subroutine print_n(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: print_stream

  • private impure elemental subroutine print_stream(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: print_max_tokens

  • private impure elemental subroutine print_max_tokens(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, public :: print_user_message

  • private impure elemental subroutine print_user_message(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, public :: print_assistant_response

procedure, private :: set_user_name

  • private pure elemental subroutine set_user_name(this, user_name)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: set_url

  • private pure elemental subroutine set_url(this, url)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: set_model

  • private pure elemental subroutine set_model(this, model)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: set_model_list

  • private pure elemental subroutine set_model_list(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: select_model

  • private pure elemental subroutine select_model(this, n)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(inout) :: this
    integer, intent(in) :: n

procedure, private :: set_temperature

  • private pure elemental subroutine set_temperature(this, temperature)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(inout) :: this
    real, intent(in) :: temperature

procedure, private :: set_presence_penalty

  • private pure elemental subroutine set_presence_penalty(this, presence_penalty)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(inout) :: this
    real, intent(in) :: presence_penalty

procedure, private :: set_frequency_penalty

  • private pure elemental subroutine set_frequency_penalty(this, frequency_penalty)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(inout) :: this
    real, intent(in) :: frequency_penalty

procedure, private :: set_top_p

  • private pure elemental subroutine set_top_p(this, top_p)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(inout) :: this
    real, intent(in) :: top_p

procedure, private :: set_n

  • private pure elemental subroutine set_n(this, n)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(inout) :: this
    integer, intent(in) :: n

procedure, private :: set_stream

  • private pure elemental subroutine set_stream(this, stream)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(inout) :: this
    logical, intent(in) :: stream

procedure, private :: set_max_tokens

  • private pure elemental subroutine set_max_tokens(this, max_tokens)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(inout) :: this
    integer, intent(in) :: max_tokens

procedure, private :: set_asisstant_response

  • private pure elemental subroutine set_asisstant_response(this, response)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: set_user_message

  • private pure elemental subroutine set_user_message(this, message)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, public :: set => set_ChatCompletion_data

  • private impure elemental subroutine set_ChatCompletion_data(this, file_name, url, model, user_name, temperature, presence_penalty, frequency_penalty, top_p, n, stream, max_tokens)

    Author
    Seyed Ali Ghasemi

    Arguments

    Type IntentOptional Attributes Name
    class(ChatCompletion), intent(inout) :: this
    character(len=*), intent(in), optional :: file_name
    character(len=*), intent(in), optional :: url
    character(len=*), intent(in), optional :: model
    character(len=*), intent(in), optional :: user_name
    real, intent(in), optional :: temperature
    real, intent(in), optional :: presence_penalty
    real, intent(in), optional :: frequency_penalty
    real, intent(in), optional :: top_p
    integer, intent(in), optional :: n
    logical, intent(in), optional :: stream
    integer, intent(in), optional :: max_tokens

procedure, private :: write_history

  • private impure elemental subroutine write_history(this, file_name)

    Author
    Seyed Ali Ghasemi

    Arguments

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

procedure, private :: print_finish_reason

  • private impure elemental subroutine print_finish_reason(this)

    Author
    Seyed Ali Ghasemi

    Arguments

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

Source Code

   type, extends(openai) :: ChatCompletion
      character(len=:),              allocatable :: url
      character(len=:),              allocatable :: model
      character(len=:),              allocatable :: user_name
      character(len=256),            allocatable :: model_list(:)
      type(ChatCompletion_messages), allocatable :: messages(:)
      integer                                    :: max_tokens
      type(usage)                                :: usage
      real                                       :: temperature=1.0
      real                                       :: presence_penalty=0.0
      real                                       :: frequency_penalty=0.0
      real                                       :: top_p=1.0
      logical                                    :: stream=.false.
      integer                                    :: n=1
      character(len=:),              allocatable :: finish_reason
   contains
      procedure :: check => check_chat_completion
      procedure :: create => create_chat_completion
      procedure :: conversation
      procedure, private :: deallocate_messages
      procedure, private :: deallocate_model_list
      procedure, private :: deallocate_url
      procedure, private :: deallocate_model
      procedure, private :: deallocate_user_name
      procedure, private :: deallocate_finish_reason
      procedure :: finalize => deallocate_ChatCompletion
      procedure, private :: get_assistant_response
      procedure, private :: get_user_message
      procedure :: init_messages
      procedure, private :: load => load_ChatCompletion_data
      procedure, private :: load_user_name
      procedure, private :: load_url
      procedure, private :: load_model
      procedure, private :: load_temperature
      procedure, private :: load_presence_penalty
      procedure, private :: load_frequency_penalty
      procedure, private :: load_top_p
      procedure, private :: load_n
      procedure, private :: load_stream
      procedure, private :: load_max_tokens
      procedure, private :: read_user_message
      procedure, private :: print_user_name
      procedure, private :: print_model_list
      procedure, private :: print_model
      procedure, private :: print_temperature
      procedure, private :: print_presence_penalty
      procedure, private :: print_frequency_penalty
      procedure, private :: print_top_p
      procedure, private :: print_n
      procedure, private :: print_stream
      procedure, private :: print_max_tokens
      procedure :: print_user_message
      procedure :: print_assistant_response
      procedure, private :: set_user_name
      procedure, private :: set_url
      procedure, private :: set_model
      procedure, private :: set_model_list
      procedure, private :: select_model
      procedure, private :: set_temperature
      procedure, private :: set_presence_penalty
      procedure, private :: set_frequency_penalty
      procedure, private :: set_top_p
      procedure, private :: set_n
      procedure, private :: set_stream
      procedure, private :: set_max_tokens
      procedure, private :: set_asisstant_response
      procedure, private :: set_user_message
      procedure :: set => set_ChatCompletion_data
      procedure, private :: write_history
      procedure, private :: print_finish_reason
   end type ChatCompletion