OpenAIChatBuilder

Overview

OpenAiChatBuilder is a builder for configuring and creating OpenAI chat clients. Allows setting API key, model name, temperature, and memory token limits for the OpenAI model.

Methods Summarized

Type
Name
Summary

void

Adds a system message to the chat context.

Sets the OpenAI API key.

Builds and returns a ChatClient configured with the specified OpenAI model settings.

Creates a new ToolBuilder for defining a custom tool for the AI agent.

Sets the maximum number of memory tokens for chat history.

Sets the OpenAI model name.

Sets the temperature for the OpenAI model.

void

Injects the built-in Servoy tools (such as user info) into the AI agent.

Methods Detailed

addSystemMessage(message)

Adds a system message to the chat context. This can be a message how the model must behave for this chat session.

Parameters

  • String message The system message to add.

Returns: voidThis builder instance for chaining.

apiKey(key)

Sets the OpenAI API key.

Parameters

Returns: OpenAiChatBuilder This builder instance.

build()

Builds and returns a ChatClient configured with the specified OpenAI model settings.

Returns: ChatClient A configured ChatClient instance.

createTool(toolFunction, name, description)

Creates a new ToolBuilder for defining a custom tool for the AI agent.

Parameters

  • Function toolFunction the function representing the tool's logic

  • String name the name of the tool

  • String description the description of the tool

Returns: ToolBuilder a ToolBuilder instance for further configuration

maxMemoryTokens(tokens)

Sets the maximum number of memory tokens for chat history.

Parameters

  • Number tokens The maximum number of tokens.

Returns: OpenAiChatBuilder This builder instance.

modelName(modelName)

Sets the OpenAI model name.

Parameters

  • String modelName The model name.

Returns: OpenAiChatBuilder This builder instance.

temperature(temperature)

Sets the temperature for the OpenAI model.

Parameters

  • Number temperature The temperature value.

Returns: OpenAiChatBuilder This builder instance.

useBuiltInTools(useBuiltInTools)

Injects the built-in Servoy tools (such as user info) into the AI agent.

Parameters

  • Boolean useBuiltInTools Boolean to indicate whether to use built-in tools.

Returns: voidThis builder instance for chaining.


Last updated

Was this helpful?