Client

Client

OpenAI chat client wrapper. Builds the conversation payload, sends it to OpenAI, and returns the reply with an inferred confidence score.

Constructor

new Client(apiKey, optsopt)

Initializes a new client.
Source:
Parameters:
Name Type Attributes Default Description
apiKey string OpenAI API key.
opts object <optional>
{} Client options.
Name Type Attributes Default Description
model string <optional>
'gpt-5.2' Chat completion model.
instructions string <optional>
Base developer instructions.
enableSecurityInstructions boolean <optional>
true Append security instructions to the base instructions.

Methods

_clampConfidenceScore(confidenceScore) → {number}

Clamp a confidence score to the range 0..1.
Source:
Parameters:
Name Type Description
confidenceScore number Raw confidence score.
Returns:
Type:
number
Clamped confidence score.

_extractConfidenceScore(choice) → {number}

Extract a confidence score from an OpenAI completion choice.
Source:
Parameters:
Name Type Description
choice object OpenAI completion choice.
Returns:
Type:
number
Confidence score.

(async) chat(memory, player, message) → {Promise.<{reply: string, confidenceScore: number}>}

Send a message to OpenAI and return the generated reply.
Source:
Parameters:
Name Type Description
memory Memory Per-player conversation memory.
player string Player name or id.
message string Player message.
Returns:
Type:
Promise.<{reply: string, confidenceScore: number}>
Reply and confidence score.

(async) moderate(message) → {Promise.<object>}

Use OpenAI's moderation API to check if the message violates content policy.
Source:
Parameters:
Name Type Description
message string Message text to moderate.
Returns:
Type:
Promise.<object>
Moderation result object.