Skip to content

Commit

Permalink
fix: 🐛 failed attempt handler
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpetrov committed Nov 27, 2023
1 parent 5e0828a commit 74b03be
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 357 deletions.
3 changes: 3 additions & 0 deletions packages/lib/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Source } from './types/document';
import { ChatRequest, HttpToolSchema, ToolSchema } from './types/dtos';
import { ChatModelConfigSchema } from './types/dtos';
import createPromptContext from './create-prompt-context';
import failedAttemptHandler from './lc-failed-attempt-hanlder';
import promptInject from './prompt-inject';
import {
ANSWER_IN_SAME_LANGUAGE,
Expand Down Expand Up @@ -74,6 +75,7 @@ export default class AgentManager {
modelName: 'gpt-4-1106-preview',
temperature: 0,
streaming: Boolean(props.stream),
onFailedAttempt: failedAttemptHandler,
callbacks: [
{
handleLLMNewToken: props.stream,
Expand Down Expand Up @@ -166,6 +168,7 @@ export default class AgentManager {
modelName: 'gpt-4',
temperature: 0,
streaming: Boolean(props.stream),
onFailedAttempt: failedAttemptHandler,
callbacks: [
{
handleLLMNewToken: props.stream,
Expand Down
4 changes: 4 additions & 0 deletions packages/lib/api-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum ApiErrorType {
EMPTY_DATASOURCE = 'EMPTY_DATASOURCE',
ALREADY_INVITED = 'ALREADY_INVITED',
INTEGRATION_CREDENTIALS_INVALID = 'INTEGRATION_CREDENTIALS_INVALID',
RATE_LIMIT = 'RATE_LIMIT',
}

export class ApiError extends Error {
Expand Down Expand Up @@ -36,6 +37,9 @@ export class ApiError extends Error {
case ApiErrorType.INTEGRATION_CREDENTIALS_INVALID:
this.status = 403;
break;
case ApiErrorType.RATE_LIMIT:
this.status = 429;
break;
default:
this.status = 500;
break;
Expand Down
354 changes: 0 additions & 354 deletions packages/lib/chat.ts

This file was deleted.

Loading

0 comments on commit 74b03be

Please sign in to comment.