Browse Source
- Bump the `ignoreDeprecations` option in `tsconfig.json` and `tsconfig.node.json` from "5.0" to "6.0" to align with the latest TypeScript standards. - Introduce a new `.env` file in the example package to manage environment variables for DeepSeek integration. - Refactor the handling of `thinking` and `reasoningEffort` parameters to use `providerExtras` for better compatibility with DeepSeek-style requests. - Update various demo files and README documentation to reflect changes in parameter handling and provide clearer usage examples.main
24 changed files with 752 additions and 227 deletions
@ -0,0 +1,16 @@ |
|||||
|
VITE_XLLM_PROVIDER=deepseek |
||||
|
VITE_XLLM_MODEL=deepseek-v4-flash |
||||
|
VITE_XLLM_API_KEY=sk-688d15ac28a640b6827f0e700d42df8d |
||||
|
VITE_XLLM_BASE_URL=https://api.deepseek.com |
||||
|
|
||||
|
VITE_XLLM_PROVIDER_2=openai-compatible |
||||
|
VITE_XLLM_MODEL_2=deepseek-v4-flash |
||||
|
VITE_XLLM_API_KEY_2=sk-688d15ac28a640b6827f0e700d42df8d |
||||
|
VITE_XLLM_BASE_URL_2=https://api.deepseek.com |
||||
|
|
||||
|
VITE_XLLM_DEMO_IMAGE_URL= |
||||
|
VITE_XLLM_TOOL_ERROR_STRATEGY=throw |
||||
|
VITE_XLLM_FORCE_TOOL_FAILURE=0 |
||||
|
# DeepSeek 思考模式:enabled | disabled;强度 high | medium | low | max | xhigh(@dm/xllm 会映射为 high/max) |
||||
|
VITE_XLLM_THINKING=enabled |
||||
|
VITE_XLLM_REASONING_EFFORT=high |
||||
@ -0,0 +1,97 @@ |
|||||
|
import { XllmError } from "../core/errors"; |
||||
|
import type { |
||||
|
XChatWithToolsOptions, |
||||
|
XClientOptions, |
||||
|
XMessage, |
||||
|
XRequest, |
||||
|
XToolCall, |
||||
|
XToolErrorStrategy, |
||||
|
XToolExecutorMap, |
||||
|
} from "../core/types"; |
||||
|
import { resolveConfig } from "../runtime/config"; |
||||
|
import { runToolCall } from "./tool-loop-shared"; |
||||
|
|
||||
|
export interface ToolLoopConfig { |
||||
|
provider: string; |
||||
|
maxRounds: number; |
||||
|
strategy: XToolErrorStrategy; |
||||
|
} |
||||
|
|
||||
|
export interface ToolLoopAccumulator { |
||||
|
rounds: number; |
||||
|
toolCallsExecuted: number; |
||||
|
currentMessages: XMessage[]; |
||||
|
} |
||||
|
|
||||
|
export const createToolLoopConfig = ( |
||||
|
input: XChatWithToolsOptions, |
||||
|
options: XClientOptions, |
||||
|
): ToolLoopConfig => { |
||||
|
const resolved = resolveConfig(input, options); |
||||
|
const maxRounds = input.maxRounds ?? 5; |
||||
|
const strategy = input.toolErrorStrategy ?? "throw"; |
||||
|
if (maxRounds < 1) { |
||||
|
throw new XllmError({ |
||||
|
code: "INVALID_REQUEST", |
||||
|
message: "maxRounds must be >= 1", |
||||
|
provider: resolved.provider, |
||||
|
}); |
||||
|
} |
||||
|
return { provider: resolved.provider, maxRounds, strategy }; |
||||
|
}; |
||||
|
|
||||
|
export const buildRequestBase = ( |
||||
|
input: XChatWithToolsOptions, |
||||
|
stream: boolean, |
||||
|
): Omit<XRequest, "messages"> => ({ |
||||
|
tools: input.tools, |
||||
|
toolChoice: input.toolChoice, |
||||
|
stream, |
||||
|
temperature: input.temperature, |
||||
|
topP: input.topP, |
||||
|
maxTokens: input.maxTokens, |
||||
|
metadata: input.metadata, |
||||
|
provider: input.provider, |
||||
|
model: input.model, |
||||
|
apiKey: input.apiKey, |
||||
|
baseURL: input.baseURL, |
||||
|
providerExtras: input.providerExtras, |
||||
|
}); |
||||
|
|
||||
|
export const buildAssistantMessage = ( |
||||
|
text: string, |
||||
|
toolCalls: XToolCall[], |
||||
|
reasoning?: string, |
||||
|
): XMessage => ({ |
||||
|
role: "assistant", |
||||
|
content: text, |
||||
|
toolCalls, |
||||
|
...(reasoning ? { reasoningContent: reasoning } : {}), |
||||
|
}); |
||||
|
|
||||
|
export const executeToolCalls = async ( |
||||
|
provider: string, |
||||
|
toolCalls: XToolCall[], |
||||
|
executors: XToolExecutorMap, |
||||
|
strategy: XToolErrorStrategy, |
||||
|
): Promise<{ toolMessages: XMessage[]; toolCallsExecuted: number }> => { |
||||
|
const toolMessages: XMessage[] = []; |
||||
|
let toolCallsExecuted = 0; |
||||
|
for (const toolCall of toolCalls) { |
||||
|
const toolRunResult = await runToolCall(provider, toolCall, executors, strategy); |
||||
|
if (!toolRunResult.handled || !toolRunResult.message) { |
||||
|
continue; |
||||
|
} |
||||
|
toolMessages.push(toolRunResult.message); |
||||
|
toolCallsExecuted += 1; |
||||
|
} |
||||
|
return { toolMessages, toolCallsExecuted }; |
||||
|
}; |
||||
|
|
||||
|
export function throwIfMaxRoundsExceeded(config: ToolLoopConfig): never { |
||||
|
throw new XllmError({ |
||||
|
code: "PROVIDER_ERROR", |
||||
|
message: `Tool loop exceeded maxRounds=${config.maxRounds}`, |
||||
|
provider: config.provider, |
||||
|
}); |
||||
|
} |
||||
Loading…
Reference in new issue