Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/llm-core/platform/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export abstract class BasePlatformClient<

const maxRetries = cfg.value.maxRetries ?? 5

while (retryCount < (maxRetries ?? 1)) {
while (retryCount <= maxRetries) {
let oldConfig: ClientConfigWrapper<T> | undefined

try {
Expand All @@ -93,7 +93,7 @@ export abstract class BasePlatformClient<
return false
}

if (retryCount === maxRetries - 1) {
if (retryCount >= maxRetries) {
if (oldConfig == null) {
this.ctx.logger.error(e)
unlock()
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/llm-core/platform/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class ChatLunaChatModel extends BaseChatModel<ChatLunaModelCallOptions> {
runManager?: CallbackManagerForLLMRun,
reportUsage = true
): AsyncGenerator<ChatGenerationChunk> {
const maxRetries = Math.max(1, this._options.maxRetries ?? 1)
const maxAttempts = Math.max(1, (this._options.maxRetries ?? 0) + 1)
let promptTokens = 0

if (reportUsage) {
Expand All @@ -247,7 +247,7 @@ export class ChatLunaChatModel extends BaseChatModel<ChatLunaModelCallOptions> {
input: messages
}

for (let attempt = 0; attempt < maxRetries; attempt++) {
for (let attempt = 0; attempt < maxAttempts; attempt++) {
const latestTokenUsage = this._createTokenUsageTracker()
let stream: AsyncGenerator<ChatGenerationChunk> | null = null
let hasChunk = false
Expand Down Expand Up @@ -303,7 +303,7 @@ export class ChatLunaChatModel extends BaseChatModel<ChatLunaModelCallOptions> {
error,
hasChunk,
attempt,
maxRetries
maxAttempts
)
) {
if (hasChunk) {
Expand All @@ -323,7 +323,7 @@ export class ChatLunaChatModel extends BaseChatModel<ChatLunaModelCallOptions> {
}

logger.debug(
`Stream failed before first chunk (attempt ${attempt + 1}/${maxRetries}), retrying...`,
`Stream failed before first chunk (attempt ${attempt + 1}/${maxAttempts}), retrying...`,
error
)
await sleep(2000 * 2 ** attempt)
Expand Down Expand Up @@ -470,10 +470,10 @@ export class ChatLunaChatModel extends BaseChatModel<ChatLunaModelCallOptions> {
error: unknown,
hasChunk: boolean,
attempt: number,
maxRetries: number
maxAttempts: number
): boolean {
return (
this._isAbortError(error) || hasChunk || attempt === maxRetries - 1
this._isAbortError(error) || hasChunk || attempt === maxAttempts - 1
)
}

Expand Down Expand Up @@ -630,10 +630,10 @@ export class ChatLunaChatModel extends BaseChatModel<ChatLunaModelCallOptions> {
options: this['ParsedCallOptions'],
runManager?: CallbackManagerForLLMRun
): Promise<ChatGeneration> {
const maxRetries = Math.max(1, this._options.maxRetries ?? 1)
const maxAttempts = Math.max(1, (this._options.maxRetries ?? 0) + 1)

const generateWithRetry = async () => {
for (let attempt = 0; attempt < maxRetries; attempt++) {
for (let attempt = 0; attempt < maxAttempts; attempt++) {
try {
let response: ChatGeneration

Expand Down Expand Up @@ -675,7 +675,7 @@ export class ChatLunaChatModel extends BaseChatModel<ChatLunaModelCallOptions> {
if (
options.stream ||
this._isAbortError(error) ||
attempt === maxRetries - 1
attempt === maxAttempts - 1
) {
throw error
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ export namespace ChatLunaPlugin {
Schema.const('default'),
Schema.const('balance')
]).default('default'),
maxRetries: Schema.number().min(1).max(6).default(5),
maxRetries: Schema.number().min(0).max(6).default(5),
timeout: Schema.number().default(300 * 1000),
proxyMode: Schema.union([
Schema.const('system'),
Expand Down
Loading