-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Obs AI Assistant] Improve error handling in the evaluation framework #212991
base: main
Are you sure you want to change the base?
[Obs AI Assistant] Improve error handling in the evaluation framework #212991
Conversation
Pinging @elastic/obs-ai-assistant (Team:Obs AI Assistant) |
const inferenceMessages: InferenceMessage[] = []; | ||
|
||
messages.forEach((message) => { | ||
if (message.message.role === MessageRole.Assistant) { | ||
let parsedArguments; | ||
if (message.message.function_call?.name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of this change is to not validate the arguments JSON object here because any errors in the function call will be caught in the function validation step.
For example:
When the LLLM hallucinates the function name/arguments such as:
{
"content": "",
"function_call": {
"name": "elasticsearchelasticsearch",
"arguments": "{\"method\": \"POST\", \"path\": \"/testing_ai_assistant/_doc\", \"body\": {\"type\": \"alert\", \"message\": \"This test is for alerts\"}}{\"method\": \"POST\", \"path\": \"/testing_ai_assistant/_doc\", \"body\": {\"type\": \"esql\", \"message\": \"This test is for esql\"}}",
"trigger": "assistant"
},
"role": "assistant"
}
At present, since the JSON is invalid, this is the error thrown:
ERROR ChatCompletionError: SyntaxError: Unexpected non-whitespace character after JSON at position 56
at Object.next (throw_serialized_chat_completion_errors.ts:29:17)
at /Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/tap.ts:189:31
at OperatorSubscriber._this._next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts:70:13)
at OperatorSubscriber.Subscriber.next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Subscriber.ts:75:12)
at /Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/mergeInternals.ts:85:24
at OperatorSubscriber._this._next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts:70:13)
at OperatorSubscriber.Subscriber.next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Subscriber.ts:75:12)
at Observable._subscribe (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/observable/innerFrom.ts:78:18)
at Observable._trySubscribe (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Observable.ts:244:19)
at /Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Observable.ts:234:18
at Object.errorContext (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/util/errorContext.ts:29:5)
at Observable.subscribe (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Observable.ts:220:5)
at doInnerSub (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/mergeInternals.ts:71:40)
at outerNext (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/mergeInternals.ts:53:58)
at OperatorSubscriber._this._next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts:70:13)
at OperatorSubscriber.Subscriber.next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Subscriber.ts:75:12)
at /Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/switchMap.ts:115:42
at OperatorSubscriber._this._next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts:70:13)
at OperatorSubscriber.next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Subscriber.ts:75:12)
at processStream (stream_into_observable.ts:17:20)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'internalError',
meta: {}
}
With this change (By not propagating the invalid JSON error), we can see the actual error in the terminal:
ERROR ChatCompletionError: Could not find tool call request for elasticsearchelasticsearch
at Object.next (throw_serialized_chat_completion_errors.ts:29:17)
at /Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/tap.ts:189:31
at OperatorSubscriber._this._next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts:70:13)
at OperatorSubscriber.Subscriber.next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Subscriber.ts:75:12)
at /Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/mergeInternals.ts:85:24
at OperatorSubscriber._this._next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts:70:13)
at OperatorSubscriber.Subscriber.next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Subscriber.ts:75:12)
at Observable._subscribe (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/observable/innerFrom.ts:78:18)
at Observable._trySubscribe (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Observable.ts:244:19)
at /Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Observable.ts:234:18
at Object.errorContext (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/util/errorContext.ts:29:5)
at Observable.subscribe (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Observable.ts:220:5)
at doInnerSub (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/mergeInternals.ts:71:40)
at outerNext (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/mergeInternals.ts:53:58)
at OperatorSubscriber._this._next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts:70:13)
at OperatorSubscriber.Subscriber.next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Subscriber.ts:75:12)
at /Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/switchMap.ts:115:42
at OperatorSubscriber._this._next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts:70:13)
at OperatorSubscriber.next (/Users/viduni/Workspace/Elastic/kibana/node_modules/rxjs/src/internal/Subscriber.ts:75:12)
at processStream (stream_into_observable.ts:17:20)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'internalError',
meta: {}
}
💚 Build Succeeded
Metrics [docs]
cc @viduni94 |
Closes https://github.com/elastic/obs-ai-assistant-team/issues/196
Summary
This PR implements the follows:
429
errorsconvertMessagesForInference
to surface errors related to function callsChecklist
release_note:*
label is applied per the guidelines