class ChatGPT::Client

Overview

Define the Client class that handles communication with the ChatGPT API

Defined in:

chatgpt/client.cr

Constant Summary

API_ENDPOINT = "https://api.openai.com"

Set the API endpoint URL

Constructors

Instance Method Summary

Constructor Detail

def self.new #

Initialize the Client object by building the required HTTP headers


[View source]

Instance Method Detail

def build_http_headers #

Build the required HTTP headers using the API key from environment variables


[View source]
def fetch_api_key #

Fetch the API key from the environment variables or display an error if not present


[View source]
def post_request(request_data) #

Send a POST request with the provided request data to the ChatGPT API


[View source]
def send_chat_request(request_data) #

Send a chat request to the ChatGPT API and log the request and response data if in debug mode


[View source]