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 ofMessagestructs representing the conversation history.
§Returns
This function returns a Result which contains:
- A
Stringwith the response content if the request is successful. - A boxed
dyn std::error::Errorif an error occurs during the request or response parsing.
§Errors
This function can fail in several ways:
- If the environment variables
OPEN_AI_KEYorOPEN_AI_ORGare not found. - If the HTTP request fails.
- If the JSON response parsing fails.