fix(openai-sdk-python): don't fail get_profile for users with no memories - #1759
Open
Atharvsinh-codez wants to merge 1 commit into
Open
Atharvsinh-codez wants to merge 1 commit into
Atharvsinh-codez wants to merge 1 commit into
Conversation
…ries The API returns a null profile for a user who has no stored memories yet (the same case as supermemoryai#1027 for the pipecat package). get_profile passed it straight to _model_to_dict, which raises TypeError for None, so the tool came back as success=False with "Profile fetch failed: Unsupported SDK response type: NoneType" for every new user. Return an empty profile ({"static": [], "dynamic": []}) in that case, like the cartesia and pipecat packages already do. Added a test for the null-profile response.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
For a user who has no stored memories yet, the API returns a null
profile(this is the same case as #1027, which was fixed for the pipecat package).SupermemoryTools.get_profilepassed that straight to_model_to_dict, which raisesTypeErrorforNone. The broadexceptthen turned it into a failed tool call:So the model sees a failing
getProfilecall for every new user, instead of an empty profile.Repro
On
mainthis returns the error above. With this change it returnssuccess=Trueandprofile={"static": [], "dynamic": []}.The fix
When
response.profileisNone, return an empty profile. This matches what the cartesia and pipecat packages already do.search_resultswas already handled forNone, so it is unchanged.I only changed
get_profile. I didn't touchdocument_list, since I haven't seen the API return a nullpagination.Tests
Added
test_get_profile_handles_user_with_no_memoriesintests/test_tools.py. It fails onmainand passes with the fix. The fulltests/run gives 32 passed, 11 skipped (the skipped ones need a real API key), andblack --checkis clean.