OpenAIGPT4 - Interact with the OpenAI GPT-3,4 API
Version 0.18
use OpenAIGPT4; my $gpt = 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 = $gpt->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 } }
OpenAIGPT4 is a Perl module that enables developers to interface with the OpenAI GPT-3,4 API. With this module, you can easily generate natural language text. It also supports a debug flag to log HTTP request and response details.
my $gpt = OpenAIGPT4->new('<your_api_key>', 'http://open_ai_host_url', 1);
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. The last parameter is the debug flag. If set to 1, the module will print HTTP request and response details to STDOUT.
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-0613'. It returns the generated text.
Kawamura Shingo, <pannakoota@gmail.com>
Copyright 2023 Kawamura Shingo.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install OpenAIGPT4, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OpenAIGPT4
CPAN shell
perl -MCPAN -e shell install OpenAIGPT4
For more information on module installation, please visit the detailed CPAN module installation guide.