pub async fn call_gpt(
messages: Vec<Message>,
) -> Result<String, Box<dyn Error + Send>>
Expand description
Calls the OpenAI GPT API to get a response based on the provided chat messages.
§Arguments
messages
- A vector ofMessage
structs representing the conversation history.
§Returns
This function returns a Result
which contains:
- A
String
with the response content if the request is successful. - A boxed
dyn std::error::Error
if an error occurs during the request or response parsing.
§Errors
This function can fail in several ways:
- If the environment variables
OPEN_AI_KEY
orOPEN_AI_ORG
are not found. - If the HTTP request fails.
- If the JSON response parsing fails.