The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

OpenAIGPT4 - Interact with the OpenAI GPT-4 API

VERSION

Version 0.12

SYNOPSIS

    use OpenAIGPT4;

    my $gpt = OpenAIGPT4->new('<your_api_key>');
    my $response = $gpt->generate_text('Hello, how are you?');
    print $response;

DESCRIPTION

This module provides a Perl interface to the OpenAI GPT-4 API. It currently supports generating text given a prompt.

METHODS

new

    my $gpt = OpenAIGPT4->new('<your_api_key>', 'http://open_ai_host_url');

This constructor returns a new OpenAIGPT4 object. You must pass your OpenAI API key as the argument. The open ai host url is optional, and can be used for running against a LocalAI API server.

generate_text

    my $response = $gpt->generate_text('Hello, how are you?', 'gpt-4');

This method generates text given a prompt. The first argument should be a string containing the prompt. The second argument is optional and can be used to specify the model to be used for the generation. If no model is specified, it defaults to 'gpt-3.5-turbo'. It returns the generated text.

AUTHOR

Kawamura Shingo, <pannakoota@gmail.com>

LICENSE AND COPYRIGHT

Copyright 2023 Kawamura Shingo.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SYNOPSIS

    use OpenAIGPT4;

    my $gpt4 = OpenAIGPT4->new('<your_api_key>');
    print "ChatGPT: Hello! Let's start a conversation.\n";

    while (1) {
        print "User: ";
        my $user_input = <STDIN>;
        chomp $user_input;

        # Send the user's input to the API and receive a response
        my $response = $gpt4->generate_text($user_input);

        # Display the response
        print "ChatGPT: $response\n";

        # Check for exit condition (e.g., input of the keyword "exit")
        if ($user_input eq 'exit') {
            last; # Exit the loop to end the conversation
        }
    }

SEE ALSO

LocalAI - LocalAI is an OpenAI API compatible system for locally hosting models