feat: add streaming mode support to AI execution and request types
This commit is contained in:
1 parent
9572b0a2ee
commit
884fcee312
3 files changed
+9
-1
No files matched your search
@@ -25,6 +25,7 @@ export const createBrainNode = (input: { ctx: AiRunContext; cache: HumanRuntimeC
|
||||
schema: humanThoughtDecisionSchema,
|
||||
schemaName: 'human_brain_decision',
|
||||
temperature: 0.1,
|
||||
streamingMode: 'force_non_stream',
|
||||
contextBudgetSnapshot: state.execution.contextBudget
|
||||
})
|
||||
const inputTokens = result.usage?.inputTokens
|
||||
|
||||
@@ -113,6 +113,7 @@ export type AiLlmTextRequest = {
|
||||
system: string
|
||||
user: string
|
||||
temperature?: number
|
||||
streamingMode?: AiLlmStreamingMode
|
||||
onTextDelta?: (text: string) => void
|
||||
}
|
||||
|
||||
@@ -124,6 +125,7 @@ export type AiLlmStructuredRequest<T extends Record<string, unknown>> = {
|
||||
user: string
|
||||
schema: z.ZodType<T>
|
||||
temperature?: number
|
||||
streamingMode?: AiLlmStreamingMode
|
||||
contextBudgetSnapshot?: BrainContextBudgetSnapshot
|
||||
}
|
||||
|
||||
@@ -706,7 +708,7 @@ export const createAiLlmExecutor = (input: {
|
||||
checkCancelled: () => void
|
||||
driver?: AiLlmDriver
|
||||
}): AiLlmExecutor => {
|
||||
const streamingMode = resolveStreamingMode(input.runtimeSettings)
|
||||
const defaultStreamingMode = resolveStreamingMode(input.runtimeSettings)
|
||||
|
||||
return {
|
||||
chatStructured: async <T extends Record<string, unknown>>(
|
||||
@@ -716,6 +718,7 @@ export const createAiLlmExecutor = (input: {
|
||||
usage?: AiLlmUsage
|
||||
}> => {
|
||||
input.checkCancelled()
|
||||
const streamingMode = request.streamingMode || defaultStreamingMode
|
||||
const cfg = await input.getConfig()
|
||||
const result = await runLlmCallWithActivity<Record<string, unknown>>({
|
||||
ctx: input.eventCtx,
|
||||
@@ -777,6 +780,7 @@ export const createAiLlmExecutor = (input: {
|
||||
|
||||
chatText: async (request: AiLlmTextRequest): Promise<string> => {
|
||||
input.checkCancelled()
|
||||
const streamingMode = request.streamingMode || defaultStreamingMode
|
||||
const cfg = await input.getConfig()
|
||||
const result = await runLlmCallWithActivity<string>({
|
||||
ctx: input.eventCtx,
|
||||
|
||||
@@ -16,6 +16,7 @@ import type {
|
||||
AiApprovalBatchDecision,
|
||||
AiApprovalBatchItem,
|
||||
AiLlmIoRecord,
|
||||
AiLlmStreamingMode,
|
||||
AiLlmUsage,
|
||||
AiRuntimeSettings,
|
||||
AiRunEvent,
|
||||
@@ -135,6 +136,7 @@ export type AiRunContext = {
|
||||
schema: z.ZodType<T>
|
||||
schemaName: string
|
||||
temperature?: number
|
||||
streamingMode?: AiLlmStreamingMode
|
||||
contextBudgetSnapshot?: BrainContextBudgetSnapshot
|
||||
}) => Promise<{
|
||||
output: T
|
||||
@@ -147,6 +149,7 @@ export type AiRunContext = {
|
||||
user: string
|
||||
schemaName: string
|
||||
temperature?: number
|
||||
streamingMode?: AiLlmStreamingMode
|
||||
onTextDelta?: (text: string) => void
|
||||
}) => Promise<string>
|
||||
sendEvent: (event: AiRunEvent) => void
|
||||
|
||||
Reference in new issue
Block a user