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

Add puzzle API #1372

Merged
merged 10 commits into from
May 17, 2024
Merged

Add puzzle API #1372

merged 10 commits into from
May 17, 2024

Conversation

bgrgicak
Copy link
Collaborator

@bgrgicak bgrgicak commented May 9, 2024

What is this PR doing?

It adds an API for the Playground puzzle app.

What problem is it solving?

It allows the Playground puzzle app to communicate with OpenAI.

How is the problem addressed?

By creating a PHP API.

Testing Instructions

cd packages/playground/website/public 
docker run -d -p 8787:80 -v "$PWD":/var/www/html php:8.0-apache
  • Test endpoints
curl --location 'http://localhost:8787/puzzle.php' \
--form 'action="site-name"' \
--form 'api_key="test"'
curl --location 'http://localhost:8787/puzzle.php' \
--form 'action="post"' \
--form 'api_key="test"'
curl --location 'http://localhost:8787/puzzle.php' \
--form 'action="read-image"' \
--form 'api_key="test"' \
--form 'image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG8AAAArCAYAAAB2DNYaAAAABHNCSVQICAgIfAhkiAAAABl0RVh0U29mdHdhcmUAZ25vbWUtc2NyZWVuc2hvdO8Dvz4AAAAudEVYdENyZWF0aW9uIFRpbWUARnJpIDEwIE1heSAyMDI0IDEyOjA5OjMwIFBNIENFU1QFGPa3AAAHAklEQVR4nO2bf0ic5x3AP92Nk4U3WN6bmW/XeQb6HhmeHTkduTCmK1hXcslIQskRmAZilKmBGlk0bJqt1rFoRuqg6phpoVEQCzNCc2PYG+4cmReWXGF9peKFxZObb2l3L5O8sfVlx/ZHLEvU89Rpzre8n//u+L7Pr8/zPj/vnnrw4MF/sDAlX8p0ASw2jyXPxFjyTIwlz8RY8kyMJc/EWPJMjCXPxFjyTIwlz8R8eUtS0YK0nm4jpKWJs9kRRIl8dxGl5cc49h0n9i0pwA5hIUxXzSWmX7xMzyl527PbGnn2XFxuN4kELM7PEI3r2HNkXH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iteGround
- Yoast
If the text is invalid, don't return it.
If you do not see puzzle pieces of paper with valid text on them, simply output 'NO'",
Copy link
Member

Choose a reason for hiding this comment

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

Will the "NO" be seen by humans, or is it a value for an app to interpret? If it will be seen by people, perhaps something like "Unrecognized" would sound more gentle.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, this is internal. We only show a message if a piece was successfully recognized.

@bgrgicak bgrgicak marked this pull request as ready for review May 10, 2024 10:12
@bgrgicak bgrgicak added [Type] Marketing [Type] New API New API to be used by package users. labels May 10, 2024
@bgrgicak bgrgicak changed the title Add/puzzle api Add puzzle API May 14, 2024
@@ -229,6 +229,30 @@ function playground_maybe_set_environment( $requested_path ) {
return true;
}

if (str_ends_with($requested_path, 'puzzle.php')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (str_ends_with($requested_path, 'puzzle.php')) {
if (str_ends_with($requested_path, '/puzzle.php')) {

Copy link
Member

Choose a reason for hiding this comment

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

I agree with this change. The rest in this function ought to have been given preceding slashes as well. I think there was a reason for omitting them like an impression I got from one of the htaccess files. But it probably matches our intent to give them all preceding slashes.

Copy link
Collaborator

@adamziel adamziel left a comment

Choose a reason for hiding this comment

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

LGTM. What do you think @brandonpayton ?

adamziel pushed a commit that referenced this pull request May 16, 2024
It moves the [Playground puzzle
app](https://github.com/bgrgicak/playground-puzzle) into a Playground
package.

## What problem is it solving?

It enables us to deploy the puzzle app to the Playground server.

## How is the problem addressed?

By creating a new Playground package and updating the code to work with
Vite.

## Testing Instructions

- Follow the readme instructions to start a dev server
- Setup the [puzzle API using these
instructions](#1372)
- [Update this line
](https://github.com/WordPress/wordpress-playground/pull/1385/files#diff-36e03a13c2f651337a0595e14c5aacbcd9e41ed263b271d973d0b0ef6425016fR1)to
point to your development API
- Open the app and click on _Build your site_
- Write [one of the action
keys](https://github.com/WordPress/wordpress-playground/pull/1385/files#diff-ea60a008cc4118065c2be0703f529a8f2176ad4b38504f94fd68d25550892177R21)
like _multisite_ on a piece of paper (text should be clear and bold)
- Scan it
- Confirm that an action was added
- Click on _Take me to my site_
- Confirm that the site load and the actions were applied

**Note let's address design feedback and improvements in separate PRs to
unblock sponsors from updating their blueprints**

$secrets = new Atomic_Persistent_Data;
if (isset(
$secrets->OPEN_AI_API_KEY,
Copy link
Member

Choose a reason for hiding this comment

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

@bgrgicak I can help set the secrets until we can get a hosting dashboard that is available to the whole team. Please just ping me when you want to set them.

if (!isset($_POST["api_key"])) {
response("error", "Please provide an API key.");
}
if ($_POST["api_key"] !== $api_key) {
Copy link
Member

Choose a reason for hiding this comment

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

Where will our users be getting this API key? I apologize if I've missed discussion about this elsewhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's hardcoded here.

It's only purpose is to allow us to disable the API in case we start having problems.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! I will send you the details.

Copy link
Member

@brandonpayton brandonpayton left a comment

Choose a reason for hiding this comment

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

I have not tested this, but in reading the code, I don't have any concerns except for one question asked as a "single comment".

@bgrgicak bgrgicak merged commit 31f1bcd into trunk May 17, 2024
5 checks passed
@bgrgicak bgrgicak deleted the add/puzzle-api branch May 17, 2024 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Marketing [Type] New API New API to be used by package users.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants