Skip to content

fix llamaindex CompletionResponse serialize error#906

Closed
nightosong wants to merge 1 commit into
langfuse:mainfrom
nightosong:test
Closed

fix llamaindex CompletionResponse serialize error#906
nightosong wants to merge 1 commit into
langfuse:mainfrom
nightosong:test

Conversation

@nightosong
Copy link
Copy Markdown
Contributor

@nightosong nightosong commented Sep 4, 2024

While I use langfuse with llamaindex, I get an error output:

received error response: {'message': 'Invalid request data', 'errors': ['Expected object, received string']}
Received 400 error by Langfuse server, not retrying: {'message': 'Invalid request data', 'errors': ['Expected object, received string']}

Then I debug the task_manager file and find this code data = json.dumps(kwargs, cls=EventSerializer) .
In my case, the output object in body is type of <class 'llama_index.core.base.llms.types.CompletionResponse'>.
When it executes this line of default() in EventSerializer, a TypeError will be thrown.
TypeError: 'MockValSer' object cannot be converted to 'SchemaSerializer' (pydantic 2.8.2)

if isinstance(obj, BaseModel):
    return obj.dict()

I just realized that this issue is caused by the type from llamaindex.
Would there be any risks if I handle all of the CompletionResponse here?

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Sep 4, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: Experimental PR review

PR Summary

This pull request addresses a serialization issue with LlamaIndex's CompletionResponse object in the EventSerializer class, resolving an 'Invalid request data' error when using langfuse with llamaindex.

  • Modified EventSerializer.default() in langfuse/serializer.py to handle CompletionResponse objects by converting them to strings
  • Added "CompletionResponse" to the condition checking for LlamaIndex objects that require special handling
  • This change ensures proper serialization of CompletionResponse objects, preventing TypeError exceptions
  • The fix maintains consistency with how StreamingResponse objects are already handled in the serializer
  • Users working with LlamaIndex and langfuse should no longer encounter the 'Invalid request data' error related to CompletionResponse serialization

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@nightosong nightosong marked this pull request as draft September 4, 2024 06:37
@nightosong nightosong marked this pull request as ready for review September 4, 2024 06:45
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: Experimental PR review

PR Summary

This pull request addresses a serialization issue with LlamaIndex's CompletionResponse object in the EventSerializer class of the langfuse-python library.

  • Modified EventSerializer.default() to handle CompletionResponse objects by converting them to strings
  • The fix resolves the 'Invalid request data' error when using langfuse with llamaindex
  • While effective, this solution may not be optimal long-term as it loses the structured data of CompletionResponse objects
  • Consider exploring a more robust serialization method that preserves CompletionResponse structure in future updates
  • Recommend adding tests in /tests/test_llama_index.py to verify the serialization of CompletionResponse objects

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants