[go: up one dir, main page]

hx-chatgpt

Simple wrapper for the ChatGPT completion API HTTP endpoint
https://github.com/cardgdev/hx-chatgpt

To install, run:

haxelib install hx-chatgpt 0.0.2 

See using Haxelib in Haxelib documentation for more information.

README.md

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.systemMessage can be used to add a message with role: "system" to the request.
  • client.maxTokens throttles tokens returned by the request.
  • client.enrichRequest can be set to change the request JSON object before it is sent, thus allowing you to add custom params to the request.
  • ChatGPTClientPayload.content returns the simple content of the result, but the full payload can be accessed through ChatGPTClientPayload.fullTextPayload or ChatGPTClientPayload.fullJsonPayload.
Contributors
cgdev
Version
0.0.2
Published
2 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub