Skip to main content
Version: 2.6

Using LLM Calls

The op-demo-simple-chat app contains several chat reaktors that showcase how to call an LLM with Operaide aktors. The snippet below is SimpleChat01.reaktor.ts.

Simple chat reaktor

import {
aktorAISettingProviderModel,
aktorAICall,
aktorPatchMessages,
registerChatReaktorDefinition,
} from '@operaide/ai';
import { aktorSetting } from '@operaide/aktor';
import { z } from 'zod';

registerChatReaktorDefinition({
reaktorDefinitionId: 'simple-chat-01',
label: 'Antworte mit allen details und smilies',
description: 'Mit smileis antworten',
createReaktor({ messages }) {
const systemMessage = aktorSetting(z.string(), 'Du antwortest sarkastisch', 'System Message');
const providerModel = aktorAISettingProviderModel();
return aktorAICall({
messages: aktorPatchMessages({
messages,
system: systemMessage,
}),
providerModel,
});
},
});

Key components

  • registerChatReaktorDefinition wires the reaktor into Operaide using the chat-specific schema.
  • aktorSetting lets operators change the system prompt at runtime without redeploying.
  • aktorPatchMessages injects the system message before sending the conversation to the model.
  • aktorAICall performs the actual LLM invocation using the provider configured through aktorAISettingProviderModel.

Sample request

After deploying the app, send a request similar to SimpleChat01.http:

POST http://localhost:8811/api/v1/aktor/simple-chat-01/run
Content-Type: application/json

{
"messages": [
{
"role": "user",
"content": "Kannst du mir etwas über Operaide erzählen?"
}
]
}

The response contains the LLM answer and follows the standard chat output schema.