Skip to content

Commit

Permalink
reorgnize
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed May 28, 2024
1 parent 2fb3486 commit a942121
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/protocols/ChatGPT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,7 @@ contract ChatGPT {
body = abi.encodePacked(body, temperature);
body = abi.encodePacked(body, '}');

Suave.HttpRequest memory request;
request.method = "POST";
request.url = "https://api.openai.com/v1/chat/completions";
request.headers = new string[](2);
request.headers[0] = string.concat("Authorization: Bearer ", apiKey);
request.headers[1] = "Content-Type: application/json";
request.body = body;

bytes memory output = Suave.doHTTPRequest(request);

// decode responses
JSONParserLib.Item memory item = string(output).parse();
string memory result = trimQuotes(item.at('"choices"').at(0).at('"message"').at('"content"').value());

return result;
return doGptRequest(body);
}

/// @notice complete a chat with the OpenAI ChatGPT.
Expand All @@ -91,6 +77,10 @@ contract ChatGPT {
}
body = abi.encodePacked(body, '], "temperature": 0.7}');

return doGptRequest(body);
}

function doGptRequest(bytes memory body) private returns (string memory) {
Suave.HttpRequest memory request;
request.method = "POST";
request.url = "https://api.openai.com/v1/chat/completions";
Expand Down

0 comments on commit a942121

Please sign in to comment.