About
A simple wrapper for OpenAI's ChatGPT API completion HTTP endpoint. Usable on any target. An API key from OpenAI will be required, obviously.
Example usage:
var client = new ChatGPTClient(/*API KEY HERE*/, GPT_4);
var result = client.completion("This is a test, please acknowledge.");
switch result {
case Success(result):{
trace("success: " + result.content);
}
case Error(errorMessage): {
trace("error: " + errorMessage);
}
case Promise(success, error): {
success.listen((data) -> {
trace("async success: " + data.content);
});
error.listen((data) -> {
trace("async error: " + data);
});
}
}
client.completion() returns an enum value:
enum ChatGPTClientResult {
Success(result: ChatGPTClientPayload);
Error(errorMessage: String);
Promise(success: HxPromise<ChatGPTClientPayload>, error: HxPromise<String>);
}
On concurrent targets client.completion() will block and return ChatGPTClientResult.Success or ChatGPTClientResult.Error. If concurrency is not supported or client.async == true then ChatGPTClientResult.Promise will be returned, in which case data can be retrieved by success.listen().
Other features:
client.systemMessagecan be used to add a message withrole: "system"to the request.client.maxTokensthrottles tokens returned by the request.client.enrichRequestcan be set to change the request JSON object before it is sent, thus allowing you to add custom params to the request.ChatGPTClientPayload.contentreturns the simple content of the result, but the full payload can be accessed throughChatGPTClientPayload.fullTextPayloadorChatGPTClientPayload.fullJsonPayload.