-
Notifications
You must be signed in to change notification settings - Fork 77
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
Create set_name endpoint #692
Conversation
**Disclaimer:** I know this is 400+ lines changed, but ~300 of those are just adding/refactoring automated tests!!! We already had `get_prompt_parameters`, but this isn't good enough if parameters aren't defined locally and we want to bubble up to the aiconfig defaults. See comment in #661 (comment). This is important so that we can ensure we have valid params if not defined in the correct section of our AIConfig schema. This is similar in theme to #600 The only callsite we have today for this is in python in the `params.py` function, so I updated that callsite too. I don't know why it doesn't exist in Typescript (cc @rholinshead) but I also added this functionality in typescript in #669 (I'm not as familiar with automated testing there so will ask Ryan for a code pointer to help get me started) ## Test plan Added a bunch of automated tests which you can run by doing going to the `aiconfig/python` dir and running `pytest`
… defined before Before this function would have failed to set any parameters if: 1. The prompt_name was passed in but `prompt.metadata` (possible) or `prompt.metadata.parameters` (not possible because it defaults to `{}`) was `None` 2. The prompt_name was not passed in (so update aiconfig) but the `aiconfig.metadata.parameters` was `None` (this is actually never possible because we default to using `{}`, but still just good to be thorough and future-proof) See example below <img width="410" alt="Screenshot 2023-12-29 at 01 04 48" src="https://github.com/lastmile-ai/aiconfig/assets/151060367/d3db50c7-866c-4f05-a279-284baf97d595"> ## Test plan Added automated tests: `pytest -vv`
TSIA, backend implementation of `update_model()`. The other changes were from running the auto-formatter: ``` fd --glob '*.py' python/src/aiconfig/editor/server | xargs python -m 'scripts.lint' --mode=fix --files ``` ## Test Plan Follow dev README to setup the local editor: https://github.com/lastmile-ai/aiconfig/tree/main/python/src/aiconfig/editor#dev, then run this command ``` curl http://localhost:8080/api/update_model -d curl http://localhost:8080/api/update_model -d '{"prompt_name":"get_activities", "model_name": "gpt-4", "settings": {"top_p": 0.9}}' -X POST -H 'Content-Type: application/json' ``` Notice that the model name is updated to `gpt-4`, and the `top_p` is now at 0.9 https://github.com/lastmile-ai/aiconfig/assets/151060367/3031fa59-8925-495c-a5eb-e56ec65b7fba
TSIA, this relies on #670 being unblocked ## Test Plan Follow dev README to setup the local editor: https://github.com/lastmile-ai/aiconfig/tree/main/python/src/aiconfig/editor#dev, then run this command ``` curl http://localhost:8080/api/set_parameter -d '{"prompt_name":"get_activities", "parameter_name": "city", "parameter_value": "New York"}' -X POST -H 'Content-Type: application/json' ``` Notice that the parameters are now set. We already have automated testing from #670 so we know the functionality works as long as this is connected to the client (pretty great!) https://github.com/lastmile-ai/aiconfig/assets/151060367/1be05d7e-63fe-4d6d-9036-6f8d4d004134
TSIA ## Test Plan Follow dev README to setup the local editor: https://github.com/lastmile-ai/aiconfig/tree/main/python/src/aiconfig/editor#dev, then run this command ``` curl http://localhost:8080/api/delete_parameter -d '{"prompt_name":"get_activities", "parameter_name": "city"}' -X POST -H 'Content-Type: application/json' ``` Notice that the parameters are now deleted Prompt-level https://github.com/lastmile-ai/aiconfig/assets/151060367/866db51d-6b84-438d-ac4e-483d0cfbaa40 AIConfig-level https://github.com/lastmile-ai/aiconfig/assets/151060367/dcd47f62-875c-40ac-9e81-efcd8cf9b45a
TSIA ## Test Plan Follow dev README to setup the local editor: https://github.com/lastmile-ai/aiconfig/tree/main/python/src/aiconfig/editor#dev, then run this command ``` curl http://localhost:8080/api/set_name -d '{"name":"cool_new_name"}' -X POST -H 'Content-Type: application/json' ``` https://github.com/lastmile-ai/aiconfig/assets/151060367/efcb7ceb-e390-4208-93b3-3effd5d66f8b
operation_args: Result[OpArgs, str] = result.Ok(OpArgs({"parameter_name": parameter_name, "prompt_name": prompt_name})) | ||
return run_aiconfig_operation_with_op_args(aiconfig, "delete_parameter", operation, operation_args) |
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.
Is this auto-linting? Can you try to do that atomically for large sets of files in their own PRs, or even better do it before submitting the PR that modifies that specific code?
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.
You're right, my bad I forgot to do it last time
name: str | None = request_json.get("name") | ||
|
||
operation = make_op_run_method(MethodName("set_name")) | ||
operation_args: Result[OpArgs, str] = result.Ok(OpArgs({"name": name})) | ||
return run_aiconfig_operation_with_op_args(aiconfig, "set_name", operation, operation_args) |
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.
I'm fairly sure you can use the wrapper function here (see a previous comment). If not, at this point I would probably refactor a bit to make it usable. I usually use the rule of thumb that a set of 3 cases justifies an abstraction.
If we hadn't done that to define make_op_run_method()
and run_aiconfig_operation_with_op_args()
in the first place, we would have either a lot more code duplication than this or a lot less robust error handling. We can probably go a little further here.
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.
Yea you're right, I was just copy pasting stuff
[python] Created `get_parameters` API **Disclaimer:** I know this is 400+ lines changed, but ~300 of those are just adding/refactoring automated tests!!! We already had `get_prompt_parameters`, but this isn't good enough if parameters aren't defined locally and we want to bubble up to the aiconfig defaults. See comment in #661 (comment). This is important so that we can ensure we have valid params if not defined in the correct section of our AIConfig schema. This is similar in theme to #600 The only callsite we have today for this is in python in the `params.py` function, so I updated that callsite too. I don't know why it doesn't exist in Typescript (cc @rholinshead) but I also added this functionality in typescript in #669 (I'm not as familiar with automated testing there so will ask Ryan for a code pointer to help get me started) ## Test plan Added a bunch of automated tests which you can run by doing going to the `aiconfig/python` dir and running `pytest` --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/668). * #693 * #692 * #691 * #690 * #688 * #670 * __->__ #668
Create update_model endpoint TSIA, backend implementation of `update_model()`. The other changes were from running the auto-formatter: ``` fd --glob '*.py' python/src/aiconfig/editor/server | xargs python -m 'scripts.lint' --mode=fix --files ``` ## Test Plan Follow dev README to setup the local editor: https://github.com/lastmile-ai/aiconfig/tree/main/python/src/aiconfig/editor#dev, then run this command ``` curl http://localhost:8080/api/update_model -d curl http://localhost:8080/api/update_model -d '{"prompt_name":"get_activities", "model_name": "gpt-4", "settings": {"top_p": 0.9}}' -X POST -H 'Content-Type: application/json' ``` Notice that the model name is updated to `gpt-4`, and the `top_p` is now at 0.9 https://github.com/lastmile-ai/aiconfig/assets/151060367/3031fa59-8925-495c-a5eb-e56ec65b7fba --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/688). * #693 * #692 * #691 * #690 * __->__ #688 * #670 * #668
Create delete_parameter endpoint TSIA ## Test Plan Follow dev README to setup the local editor: https://github.com/lastmile-ai/aiconfig/tree/main/python/src/aiconfig/editor#dev, then run this command ``` curl http://localhost:8080/api/delete_parameter -d '{"prompt_name":"get_activities", "parameter_name": "city"}' -X POST -H 'Content-Type: application/json' ``` Notice that the parameters are now deleted Prompt-level https://github.com/lastmile-ai/aiconfig/assets/151060367/866db51d-6b84-438d-ac4e-483d0cfbaa40 AIConfig-level https://github.com/lastmile-ai/aiconfig/assets/151060367/dcd47f62-875c-40ac-9e81-efcd8cf9b45a --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/691). * #693 * #692 * __->__ #691 * #690 * #688 * #670 * #668
Create set_description endpoint TSIA ## Test Plan Follow dev README to setup the local editor: https://github.com/lastmile-ai/aiconfig/tree/main/python/src/aiconfig/editor#dev, then run this command ``` curl http://localhost:8080/api/set_description -d '{"description":"yo this is a cool new description get rekt dont @ me bro"}' -X POST -H 'Content-Type: application/json' ``` https://github.com/lastmile-ai/aiconfig/assets/151060367/0db278b3-8273-4178-8010-380538dcd0ca --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/693). * __->__ #693 * #692 * #691 * #690 * #688 * #670 * #668
Create set_name endpoint
TSIA
Test Plan
Follow dev README to setup the local editor: https://github.com/lastmile-ai/aiconfig/tree/main/python/src/aiconfig/editor#dev, then run this command
Screen.Recording.2024-01-01.at.23.32.44.mov
Stack created with Sapling. Best reviewed with ReviewStack.
set_parameter()
to work if parameters haven't been defined before #670get_parameters
API #668