refactor(ai): isolate reasoning options
This commit is contained in:
parent
96b030699c
commit
6a44aecc24
18
src/app/ai/chat/reasoning.ts
Normal file
18
src/app/ai/chat/reasoning.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import type { AIProviderID } from '@open-pencil/core/constants'
|
||||
|
||||
type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue }
|
||||
export type AIProviderOptions = Record<string, { [key: string]: JSONValue }>
|
||||
|
||||
export function buildReasoningProviderOptions(
|
||||
providerID: AIProviderID,
|
||||
reasoningEffort: string
|
||||
): AIProviderOptions | undefined {
|
||||
if (!reasoningEffort) return undefined
|
||||
if (providerID === 'openrouter') {
|
||||
return { openrouter: { reasoning: { effort: reasoningEffort } } }
|
||||
}
|
||||
if (providerID === 'openai' || providerID === 'openai-compatible') {
|
||||
return { openai: { reasoningEffort } }
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ import {
|
|||
type AIChatFailure
|
||||
} from '@/app/ai/chat/failure'
|
||||
import { resolveLanguageModelID } from '@/app/ai/chat/model'
|
||||
import { buildReasoningProviderOptions, type AIProviderOptions } from '@/app/ai/chat/reasoning'
|
||||
import SYSTEM_PROMPT from '@/app/ai/chat/system-prompt.md?raw'
|
||||
import { createAIModelRuntime } from '@/app/ai/models'
|
||||
import { MAX_AGENT_STEPS, createAITools, recordStepUsage, resetRunSteps } from '@/app/ai/tools'
|
||||
|
|
@ -49,23 +50,6 @@ function supportsAnthropicCaching(providerID: AIProviderID, modelID: string): bo
|
|||
)
|
||||
}
|
||||
|
||||
type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue }
|
||||
type AIProviderOptions = Record<string, { [key: string]: JSONValue }>
|
||||
|
||||
export function buildReasoningProviderOptions(
|
||||
providerID: AIProviderID,
|
||||
reasoningEffort: string
|
||||
): AIProviderOptions | undefined {
|
||||
if (!reasoningEffort) return undefined
|
||||
if (providerID === 'openrouter') {
|
||||
return { openrouter: { reasoning: { effort: reasoningEffort } } }
|
||||
}
|
||||
if (providerID === 'openai' || providerID === 'openai-compatible') {
|
||||
return { openai: { reasoningEffort } }
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function mergeProviderOptions(
|
||||
cacheOptions: typeof ANTHROPIC_CACHE_CONTROL | undefined,
|
||||
reasoningOptions: AIProviderOptions | undefined
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import * as v from 'valibot'
|
|||
|
||||
import { computeContentBounds } from '@open-pencil/core/io'
|
||||
|
||||
import { buildReasoningProviderOptions } from '@/app/ai/chat/transports'
|
||||
import { buildReasoningProviderOptions } from '@/app/ai/chat/reasoning'
|
||||
import { createAIModelRuntime } from '@/app/ai/models'
|
||||
import type { EditorStore } from '@/app/editor/active-store'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
||||
|
||||
import { buildReasoningProviderOptions } from '@/app/ai/chat/transports'
|
||||
import { buildReasoningProviderOptions } from '@/app/ai/chat/reasoning'
|
||||
import {
|
||||
aiModelSettings,
|
||||
createAIModelRuntime,
|
||||
|
|
|
|||
Loading…
Reference in a new issue