feat: handle Claude API; update temperature default
This commit is contained in:
@@ -24,7 +24,7 @@ export function parseLLMConfig(config: LLMConfig): Required<LLMConfig> {
|
|||||||
baseURL: config.baseURL ?? DEFAULT_BASE_URL,
|
baseURL: config.baseURL ?? DEFAULT_BASE_URL,
|
||||||
apiKey: config.apiKey ?? DEFAULT_API_KEY,
|
apiKey: config.apiKey ?? DEFAULT_API_KEY,
|
||||||
modelName: config.modelName ?? DEFAULT_MODEL_NAME,
|
modelName: config.modelName ?? DEFAULT_MODEL_NAME,
|
||||||
temperature: config.temperature ?? 0.0,
|
temperature: config.temperature ?? 0.5, // higher randomness helps auto-recovery
|
||||||
maxTokens: config.maxTokens ?? 4096,
|
maxTokens: config.maxTokens ?? 4096,
|
||||||
maxRetries: config.maxRetries ?? LLM_MAX_RETRIES,
|
maxRetries: config.maxRetries ?? LLM_MAX_RETRIES,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,12 @@ import { InvokeError, InvokeErrorType } from './errors'
|
|||||||
import type { InvokeResult, LLMClient, Message, OpenAIClientConfig, Tool } from './types'
|
import type { InvokeResult, LLMClient, Message, OpenAIClientConfig, Tool } from './types'
|
||||||
import { zodToOpenAITool } from './utils'
|
import { zodToOpenAITool } from './utils'
|
||||||
|
|
||||||
|
// Claude's openAI-API has different format for some fields
|
||||||
|
const CLAUDE_PATCH = {
|
||||||
|
tool_choice: { type: 'tool', name: 'AgentOutput' },
|
||||||
|
thinking: { type: 'disabled' },
|
||||||
|
}
|
||||||
|
|
||||||
export class OpenAIClient implements LLMClient {
|
export class OpenAIClient implements LLMClient {
|
||||||
config: OpenAIClientConfig
|
config: OpenAIClientConfig
|
||||||
|
|
||||||
@@ -21,7 +27,7 @@ export class OpenAIClient implements LLMClient {
|
|||||||
const openaiTools = Object.entries(tools).map(([name, tool]) => zodToOpenAITool(name, tool))
|
const openaiTools = Object.entries(tools).map(([name, tool]) => zodToOpenAITool(name, tool))
|
||||||
|
|
||||||
// 2. Detect if Claude (auto-compatibility)
|
// 2. Detect if Claude (auto-compatibility)
|
||||||
// const isClaude = this.config.model.toLowerCase().includes('claude')
|
const isClaude = this.config.model.toLowerCase().startsWith('claude')
|
||||||
|
|
||||||
// 3. Call API
|
// 3. Call API
|
||||||
let response: Response
|
let response: Response
|
||||||
@@ -34,18 +40,21 @@ export class OpenAIClient implements LLMClient {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: this.config.model,
|
model: this.config.model,
|
||||||
messages,
|
|
||||||
parallel_tool_calls: false,
|
|
||||||
tools: openaiTools,
|
|
||||||
tool_choice: 'required',
|
|
||||||
// tool_choice: { type: 'function', function: { name: 'my_function' } },
|
|
||||||
// reasoning_effort: 'minimal',
|
|
||||||
// verbosity: 'low',
|
|
||||||
|
|
||||||
// Claude doesn't support tool_choice: 'required', auto-omit
|
|
||||||
// ...(isClaude ? {} : { tool_choice: 'required' }),
|
|
||||||
temperature: this.config.temperature,
|
temperature: this.config.temperature,
|
||||||
max_tokens: this.config.maxTokens,
|
max_tokens: this.config.maxTokens,
|
||||||
|
messages,
|
||||||
|
|
||||||
|
tools: openaiTools,
|
||||||
|
// tool_choice: 'required',
|
||||||
|
tool_choice: { type: 'function', function: { name: 'AgentOutput' } },
|
||||||
|
|
||||||
|
// model specific params
|
||||||
|
|
||||||
|
// reasoning_effort: 'minimal',
|
||||||
|
// verbosity: 'low',
|
||||||
|
parallel_tool_calls: false,
|
||||||
|
|
||||||
|
...(isClaude ? CLAUDE_PATCH : {}),
|
||||||
}),
|
}),
|
||||||
signal: abortSignal,
|
signal: abortSignal,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user