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

[Migration]: upgrade pydantic to v2 with sdk compatibility #1705

Conversation

aybruhm
Copy link
Member

@aybruhm aybruhm commented May 25, 2024

Description

This PR improves compatibility with the latest version of Pydantic (v2), ensuring the SDK remains up-to-date.

Changes done:

  • Improved and ensured the SDK types are compatible with pydantic>=2.
  • Updated function_signature to handle type annotations to allow fastapi to translate SDK type.
  • Refactored override_schema to align with Pydantic v2 schema definitions.
  • Updated the behaviour of the getBodySchemaName function in openapi_parser.ts to return the appropriate schema $ref due to the upgrade to Pydantic version 2.

Minor Changes done:

  • Updated Docker templates in docker-assets/ to ensure agenta installation precedes application dependency installation.

Copy link

vercel bot commented May 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
agenta ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 4, 2024 11:29am

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 25, 2024
@dosubot dosubot bot added enhancement New feature or request SDK labels May 25, 2024
@aybruhm aybruhm requested a review from mmabrouk May 25, 2024 18:00
@aybruhm aybruhm marked this pull request as draft May 25, 2024 18:14
@aybruhm aybruhm changed the title Feature/age 234 migration upgrade pydantic to v2 with sdk backward [Migration]: upgrade pydantic to v2 with sdk backward compatibility May 25, 2024
@aybruhm aybruhm marked this pull request as ready for review May 25, 2024 19:04
@aybruhm aybruhm changed the title [Migration]: upgrade pydantic to v2 with sdk backward compatibility [Migration]: upgrade pydantic to v2 with sdk compatibility May 25, 2024
…n the appropriate schema due to pydantic v2 upgrade
@aybruhm
Copy link
Member Author

aybruhm commented Jun 3, 2024

Thanks for the great work @aybruhm

In its current form, the PR did not work for me. Not sure why it did for you. I created #1736 as a candidate fix that works for me. Not sure why it works and how it works. So please take a long look into it to understand the issue and the fix before merging.

Please also take the time to QA the PR in detail to make sure we don't introduce bugs here.

I tested both the previous and current versions of pydantic with two different variants, and both worked with the candidate fix (thank you). However, I'm unable to reproduce the issue that led to the previous solution that I did in the openapi_parser.ts file. I suspect I might have made a mistake while debugging the pydantic v2 upgrade with the SDK compatibility last week. 😕

@aybruhm
Copy link
Member Author

aybruhm commented Jun 3, 2024

Hi @bekossy ,

When you see this, could you please check why the frontend tests are failing? To reproduce, update the backend environment, AGENTA_TEMPLATE_REPO, to stage_templates. Thank you.

@bekossy
Copy link
Member

bekossy commented Jun 4, 2024

@aybruhm I was able to reproduce the issue and it turns out that it is from the code and not the tests
I ran the docker-compose.test.yml file and created a new app from the UI but got stuck here

Screen Shot 2024-06-04 at 7 42 36 AM

@aybruhm
Copy link
Member Author

aybruhm commented Jun 4, 2024

@aybruhm I was able to reproduce the issue and it turns out that it is from the code and not the tests I ran the docker-compose.test.yml file and created a new app from the UI but got stuck here

Screen Shot 2024-06-04 at 7 42 36 AM

Thanks, @bekossy! I've reproduced the issue. Could you please pull and test again? I've fixed the problem. @mmabrouk, the issue was the body schema of the LLM application that was created from the UI. Here it is:

image

It turns out that the body schema for an LLM app created from the UI is different from the one created from the CLI.

Next steps for QA:

  • Create and run an app locally from the CLI and UI using the current agenta version (with pydantic v1).
  • Checkout this PR branch and repeat the above steps. Before creating an app from the UI, update the backend environment variable AGENTA_TEMPLATE_REPO to stage_templates and start the Docker Compose.

@mmabrouk
Copy link
Member

mmabrouk commented Jun 4, 2024

@aybruhm I was able to reproduce the issue and it turns out that it is from the code and not the tests I ran the docker-compose.test.yml file and created a new app from the UI but got stuck here
Screen Shot 2024-06-04 at 7 42 36 AM

Thanks, @bekossy! I've reproduced the issue. Could you please pull and test again? I've fixed the problem. @mmabrouk, the issue was the body schema of the LLM application that was created from the UI. Here it is:

image

It turns out that the body schema for an LLM app created from the UI is different from the one created from the CLI.

Next steps for QA:

  • Create and run an app locally from the CLI and UI using the current agenta version (with pydantic v1).
  • Checkout this PR branch and repeat the above steps. Before creating an app from the UI, update the backend environment variable AGENTA_TEMPLATE_REPO to stage_templates and start the Docker Compose.

I would say instead of trying to use the templates. A much easier solution is to serve applications from the CLI using the poetry shell with agenta pointing to this branch, then again with the CLI using the production branch and make sure that everything is working.

Specifically:

  • All types of parameters are shown and work (for this we should serve both the chat application and the single prompt application as they have all types of parameters)
  • The application can be used from the playground (generate endpoint) and in production using the endpoint shown under deployments (after publishing the application). We need to make sure that the deployed endpoint has the correct version of the configuration. For this please change the prompt dramatically (e.g. add answer only in chinese) then deploy the application

@aybruhm
Copy link
Member Author

aybruhm commented Jun 4, 2024

That's all I have been doing. :-)

@aybruhm I was able to reproduce the issue and it turns out that it is from the code and not the tests I ran the docker-compose.test.yml file and created a new app from the UI but got stuck here
Screen Shot 2024-06-04 at 7 42 36 AM

Thanks, @bekossy! I've reproduced the issue. Could you please pull and test again? I've fixed the problem. @mmabrouk, the issue was the body schema of the LLM application that was created from the UI. Here it is:
image
It turns out that the body schema for an LLM app created from the UI is different from the one created from the CLI.
Next steps for QA:

  • Create and run an app locally from the CLI and UI using the current agenta version (with pydantic v1).
  • Checkout this PR branch and repeat the above steps. Before creating an app from the UI, update the backend environment variable AGENTA_TEMPLATE_REPO to stage_templates and start the Docker Compose.

I would say instead of trying to use the templates. A much easier solution is to serve applications from the CLI using the poetry shell with agenta pointing to this branch, then again with the CLI using the production branch and make sure that everything is working.

Specifically:

  • All types of parameters are shown and work (for this we should serve both the chat application and the single prompt application as they have all types of parameters)
  • The application can be used from the playground (generate endpoint) and in production using the endpoint shown under deployments (after publishing the application). We need to make sure that the deployed endpoint has the correct version of the configuration. For this please change the prompt dramatically (e.g. add answer only in chinese) then deploy the application

@aybruhm aybruhm requested a review from mmabrouk June 4, 2024 09:57
@aybruhm
Copy link
Member Author

aybruhm commented Jun 4, 2024

Everything LGTM! 👍🏾

Copy link
Member

@mmabrouk mmabrouk left a comment

Choose a reason for hiding this comment

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

Great job @aybruhm
I think this only needs cleaning up the changes and it's ready to merge. Then let's update the templates (to catch any potential bugs early).

docker-compose.test.yml Show resolved Hide resolved
.github/workflows/run-frontend-tests.yml Show resolved Hide resolved
examples/baby_name_generator/requirements.txt Outdated Show resolved Hide resolved
Copy link
Member

@mmabrouk mmabrouk left a comment

Choose a reason for hiding this comment

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

Thanks @aybruhm for solving this challenging issue, great work!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 4, 2024
@mmabrouk mmabrouk merged commit e830680 into main Jun 4, 2024
13 checks passed
@mmabrouk mmabrouk deleted the feature/age-234-migration-upgrade-pydantic-to-v2-with-sdk-backward branch June 4, 2024 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer SDK size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants