-
Notifications
You must be signed in to change notification settings - Fork 1
Add app_oracle API prediction mode for AppWorld benchmarks #18
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """API prediction for AppWorld tasks.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import appworld_experiments | ||
| from appworld.task import Task | ||
| from appworld_experiments.code.common.api_predictor import APIPredictor | ||
|
|
||
| EXPERIMENTS_PATH = Path(appworld_experiments.__file__).parent | ||
| SYSTEM_APP_NAME = "supervisor" | ||
|
|
||
|
|
||
| def _get_ground_truth_apis(task: Task) -> list[str]: | ||
| """Get exact API list from ground truth using APIPredictor.""" | ||
| prompt_path = EXPERIMENTS_PATH / "prompts" / "api_predictor.txt" | ||
| predictor = APIPredictor( | ||
| prompt_file_path=str(prompt_path), | ||
| demo_task_ids=[], | ||
| app_api_separator="__", | ||
| mode="ground_truth", | ||
| ) | ||
| return predictor.non_predicted_apis(task) | ||
|
|
||
|
|
||
| def _predict_apis_using_model(task: Task, model_name: str) -> list[str]: | ||
| raise NotImplementedError( | ||
| "Predicted mode requires language model configuration. " | ||
| "Use mode='ground_truth' (train/dev only) or mode='all' instead." | ||
| ) | ||
|
|
||
|
|
||
| def predict_apis( | ||
| task_id: str, | ||
| mode: str = "predicted", | ||
| model_name: str = "gpt-4o-mini", | ||
| ) -> list[str]: | ||
| """ | ||
| Predict which APIs are needed for a task. | ||
|
|
||
| Args: | ||
| task_id: AppWorld task ID | ||
| mode: predicted/ground_truth/app_oracle/all | ||
| model_name: Model for prediction (only used if mode="predicted") | ||
|
|
||
| Returns: | ||
| List of API names in format "app__method" | ||
| - ground_truth: ~6-10 specific APIs from oracle | ||
| - app_oracle: ~50-100 APIs from oracle-identified apps | ||
| - all: All available APIs (no limit) | ||
| """ | ||
| needs_ground_truth = mode in ("ground_truth", "app_oracle") | ||
| task = Task.load( | ||
| task_id=task_id, | ||
| storage_type="memory", | ||
| load_ground_truth=needs_ground_truth, | ||
| ground_truth_mode="full" if needs_ground_truth else "minimal", | ||
| ) | ||
|
|
||
| if mode == "ground_truth": | ||
| return _get_ground_truth_apis(task) | ||
|
|
||
| elif mode == "predicted": | ||
| return _predict_apis_using_model(task, model_name) | ||
|
|
||
| elif mode == "app_oracle": | ||
| ground_truth_apis_list = _get_ground_truth_apis(task) | ||
| required_apps = {api.split("__", 1)[0] for api in ground_truth_apis_list} | ||
|
|
||
| system_apis = [api for api in ground_truth_apis_list if api.startswith(f"{SYSTEM_APP_NAME}__")] | ||
| domain_apis = [ | ||
| f"{app_name}__{api_name}" | ||
| for app_name, api_docs in task.api_docs.items() | ||
| if app_name in required_apps and app_name != SYSTEM_APP_NAME | ||
| for api_name in api_docs.keys() | ||
| ] | ||
|
|
||
| return system_apis + domain_apis | ||
|
|
||
| elif mode == "all": | ||
| return [ | ||
| f"{app_name}__{api_name}" for app_name, api_docs in task.api_docs.items() for api_name in api_docs.keys() | ||
| ] | ||
|
|
||
| raise ValueError(f"Invalid mode: {mode}") | ||
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
47 changes: 2 additions & 45 deletions
47
...s/benchmarks/appworld/appworld_helpers.py → tests/benchmarks/appworld/prompts.py
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.