Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

viduni94
Copy link
Contributor

@viduni94 viduni94 commented Mar 3, 2025

Closes https://github.com/elastic/obs-ai-assistant-team/issues/196

Summary

This PR implements the follows:

  • Slightly increase the backoff delay for 429 errors
  • Improve convertMessagesForInference to surface errors related to function calls
  • Improve the KB retrieval scenario criteria

Checklist

  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

@viduni94 viduni94 added release_note:skip Skip the PR/issue when compiling release notes Team:Obs AI Assistant Observability AI Assistant backport:version Backport to applied version labels v9.1.0 v8.19.0 labels Mar 3, 2025
@viduni94 viduni94 self-assigned this Mar 3, 2025
@viduni94 viduni94 requested a review from a team as a code owner March 3, 2025 21:19
@elasticmachine
Copy link
Contributor

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) {
Copy link
Contributor Author

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: {}
      }

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

cc @viduni94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:Obs AI Assistant Observability AI Assistant v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants