% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/help_functions.R
\name{ask_openai}
\alias{ask_openai}
\title{Send Prompt to OpenAI API}
\usage{
ask_openai(prompt, temp = NULL, topp = 1, model = NULL)
}
\arguments{
\item{prompt}{Character. The text prompt to send to the AI model.}

\item{temp}{Numeric. Temperature parameter controlling randomness (0-1).
Lower values make output more deterministic. If NULL, retrieved from set_api_specs().}

\item{topp}{Numeric. Top-p parameter controlling diversity (0-1). Default is 1.}

\item{model}{Character. OpenAI model to use. If NULL, retrieved from set_api_specs().}
}
\value{
Character. The AI model's response to the prompt, or NA if an error occurs.
}
\description{
This function sends a text prompt to the OpenAI API and returns the model's
response. It includes robust error handling and uses the openai package for API communication.
}
\details{
The function uses the openai package to communicate with OpenAI's API. It includes
comprehensive error handling that returns NA if the API call fails or returns
an unexpected format. The function expects the OPENAI_API_KEY environment variable
to be set via \code{set_api_specs()}.
}
\examples{
\dontrun{
# Set API specifications first
set_api_specs(provider = "OpenAI", model = "gpt-4", temp = 0.7, api_key = "your_api_key")

# Send a simple prompt
response <- ask_openai("What is the capital of France?")

# Use different parameters
response <- ask_openai("Analyze this text", temp = 0.3, topp = 0.9)
}

}
\seealso{
\code{\link[=ask_groq]{ask_groq()}}, \code{\link[=set_api_specs]{set_api_specs()}}
}
