AI Functions on the Server
The callAI
method is a server-side function available within the Game
class. This method allows you to make requests to the Rocket Networking AI service, powered by OpenAI, to generate AI-based responses using the GPT-3.5 Turbo model. You can call this function in every Game
instance to interact with the AI service.
Method Signature
Parameters
messagesArray (Array of objects): An array of message objects that form the conversation context. Each message object should have a
role
(either 'system', 'user', or 'assistant') andcontent
containing the text of the message.temperature (number): A floating-point value controlling the randomness of the AI's response. Higher values (e.g., 0.8) make the response more random, while lower values (e.g., 0.2) make it more deterministic.
Returns
A Promise that resolves to the AI response data.
Usage
You can use the callAI
method within a Game
instance to make AI requests as follows:
Error Handling
If there's an error in making the AI request (e.g., network issues), the method will catch the error and return the string "error."
Last updated