Qore OpenAiRestClient Module Reference 1.1
Loading...
Searching...
No Matches

OpenAiRestClient Introduction

The OpenAiRestClient module provides an API for calling OpenAi REST API services.

To use this module, use "%requires OpenAiRestClient" in your code.

All the public symbols in the module are defined in the OpenAiRestClient namespace.

The main classes are:

  • OpenAiRestClient: this class provides the REST client API for communuication with the OpenAi REST API; it also automates authentication and authorization to the target
  • OpenAiRestConnection: provides a REST connection object to OpenAi cloud services (based on the ConnectionProvider module)
Example:
//!/usr/bin/env qore
%modern
%requires OpenAiRestClient
%requires ConnectionProvider
OpenAiRestClient rest = get_connection("my-openai-connection");
hash<auto> ans = rest.get("/calendar/users/me/calendarList");
printf("%N\n", ans.body);
Streaming Example:
OpenAiRestClient rest = get_connection("my-openai-connection");
OpenAiResponseSseStream stream = rest.openResponsesStream({
"model": "gpt-4o-mini",
"stream": True,
"input": (
{
"input_item": {
"role": "user",
"content": (
{
"type": "input_text",
"text": "Stream a response",
},
),
},
},
),
});
while (hash<SseMessageInfo> evt = stream.readEvent(5s)) {
if (evt.data == "[DONE]") {
break;
}
printf("%s\n", evt.data);
}
stream.close();

Release Notes

OpenAiRestClient v1.1

  • added SSE helper for streaming responses

OpenAiRestClient v1.0

  • the initial version of the OpenAiRestClient module