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
registerChatReaktorDefinitionwires the reaktor into Operaide using the chat-specific schema.aktorSettinglets operators change the system prompt at runtime without redeploying.aktorPatchMessagesinjects the system message before sending the conversation to the model.aktorAICallperforms the actual LLM invocation using the provider configured throughaktorAISettingProviderModel.
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.