-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from spryker-eco/feature/demo/dev-ai-integrations
AI Feature integrations
- Loading branch information
Showing
39 changed files
with
1,467 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,13 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at https://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.bat] | ||
end_of_line = crlf |
This file contains 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,31 @@ | ||
# Set the default behavior, in case people don't have core.autocrlf set. | ||
* eol=lf | ||
* text=auto | ||
|
||
# Denote all files that are truly binary and should not be modified. | ||
*.png binary | ||
*.jpg binary | ||
*.gif binary | ||
*.jpeg binary | ||
*.zip binary | ||
*.phar binary | ||
*.ttf binary | ||
*.woff binary | ||
*.woff2 binary | ||
*.eot binary | ||
*.ico binary | ||
*.mo binary | ||
*.pdf binary | ||
*.xsd binary | ||
*.ts binary | ||
*.exe binary | ||
|
||
# Remove files for archives generated using `git archive` | ||
dependency.json export-ignore | ||
.coveralls.yml export-ignore | ||
.travis.yml export-ignore | ||
.editorconfig export-ignore | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
architecture-baseline.json export-ignore | ||
psalm-report.json export-ignore linguist-generated=true |
This file contains 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,58 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
validation: | ||
name: Validation | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.2' | ||
extensions: mbstring, intl, bcmath | ||
coverage: none | ||
|
||
- name: Composer Install | ||
run: composer install --prefer-dist --no-interaction --profile | ||
|
||
- name: Run validation | ||
run: composer validate | ||
|
||
- name: Syntax check | ||
run: find ./src -path src -prune -o -type f -name '*.php' -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v "No syntax errors detected" ) | ||
|
||
- name: Run CodeStyle checks | ||
run: composer cs-check | ||
|
||
- name: Run PHPStan | ||
run: composer stan | ||
|
||
lowest: | ||
name: Prefer Lowest | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.1' | ||
extensions: mbstring, intl, bcmath | ||
coverage: none | ||
|
||
- name: Composer Install | ||
run: composer install --prefer-dist --no-interaction --profile | ||
|
||
- name: Composer Update | ||
run: composer update --prefer-lowest --prefer-dist --no-interaction --profile -vvv |
This file contains 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,30 @@ | ||
# IDEs | ||
/.idea | ||
/.project | ||
/nbproject | ||
/.buildpath | ||
/.settings | ||
*.sublime-* | ||
*.AppleDouble | ||
*.AppleDB | ||
*.AppleDesktop | ||
|
||
# built client resources | ||
/src/*/Zed/*/Static/Public | ||
/src/*/Zed/*/Static/Assets/sprite | ||
|
||
# propel classes | ||
/src/*/Zed/*/Persistence/Propel/Base/* | ||
/src/*/Zed/*/Persistence/Propel/Map/* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# grunt stuff | ||
.grunt | ||
.sass-cache | ||
/node_modules/ | ||
/tests/_output/* | ||
!/tests/_output/.gitkeep | ||
vendor | ||
composer.lock |
This file contains 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,4 @@ | ||
/** | ||
* MIT License | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ |
This file contains 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,3 @@ | ||
# ImageSearchAi Changelog | ||
|
||
[Release Changelog](https://github.com/spryker-eco/image-search-ai/releases) |
This file contains 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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016-present Spryker Systems GmbH | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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 |
---|---|---|
@@ -1 +1,9 @@ | ||
# image-search-ai | ||
# ImageSearchAi Module | ||
|
||
ImageSearchAi module provides the functionality to search by image using AI. | ||
|
||
## Installation | ||
|
||
``` | ||
composer require spryker-eco/image-search-ai | ||
``` |
This file contains 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 @@ | ||
[] |
This file contains 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,48 @@ | ||
{ | ||
"name": "spryker-eco/image-search-ai", | ||
"type": "library", | ||
"description": "ImageSearchAi module", | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=8.1", | ||
"spryker-eco/open-ai": "^0.1.0", | ||
"spryker/catalog": "^5.0.0", | ||
"spryker/kernel": "^3.73.0", | ||
"spryker/symfony": "^3.0.0", | ||
"spryker/transfer": "^3.27.0", | ||
"spryker/util-encoding": "^2.0.0", | ||
"spryker/util-text": "^1.1.0" | ||
}, | ||
"require-dev": { | ||
"phpstan/phpstan": "*", | ||
"spryker/code-sniffer": "*", | ||
"spryker/router": "*" | ||
}, | ||
"suggest": { | ||
"spryker/router": "Use this module when you want to use the Router." | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SprykerEco\\": "src/SprykerEco/" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"scripts": { | ||
"cs-check": "phpcs -p -s --standard=vendor/spryker/code-sniffer/SprykerStrict/ruleset.xml src/", | ||
"cs-fix": "phpcbf -p --standard=vendor/spryker/code-sniffer/SprykerStrict/ruleset.xml src/", | ||
"stan": "phpstan analyse -c phpstan.neon -l 8 src/" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0.x-dev" | ||
} | ||
}, | ||
"config": { | ||
"sort-packages": true, | ||
"allow-plugins": { | ||
"dealerdirect/phpcodesniffer-composer-installer": true, | ||
"php-http/discovery": false | ||
} | ||
} | ||
} |
This file contains 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,5 @@ | ||
{ | ||
"include": { | ||
"spryker/transfer": "Provides transfer objects definition with strict types." | ||
} | ||
} |
This file contains 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,10 @@ | ||
parameters: | ||
level: 8 | ||
paths: | ||
- src/ | ||
ignoreErrors: | ||
- '#Call to method .+ on an unknown class .+Transfer#' | ||
- '#Instantiated class .+Transfer not found#' | ||
- '#Method .+ has invalid return type .+Transfer#' | ||
- '#Parameter .+ has invalid type .+Transfer#' | ||
- '#Call .+ on an unknown class .+AutoCompletion.#' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
src/SprykerEco/Shared/ImageSearchAi/Transfer/image_search_ai.transfer.xml
This file contains 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,14 @@ | ||
<?xml version="1.0"?> | ||
<transfers xmlns="spryker:transfer-01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="spryker:transfer-01 http://static.spryker.com/transfer-01.xsd"> | ||
|
||
<transfer name="OpenAiChatRequest" strict="true"> | ||
<property name="promptData" type="array" singular="promptData"/> | ||
<property name="model" type="string"/> | ||
</transfer> | ||
|
||
<transfer name="OpenAiChatResponse" strict="true"> | ||
<property name="message" type="string"/> | ||
<property name="isSuccessful" type="bool"/> | ||
</transfer> | ||
|
||
</transfers> |
83 changes: 83 additions & 0 deletions
83
src/SprykerEco/Yves/ImageSearchAi/Controller/ImageSearchController.php
This file contains 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,83 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SprykerEco\Yves\ImageSearchAi\Controller; | ||
|
||
use Spryker\Service\UtilText\Model\Url\Url; | ||
use Spryker\Yves\Kernel\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @method \SprykerEco\Yves\ImageSearchAi\ImageSearchAiFactory getFactory() | ||
*/ | ||
class ImageSearchController extends AbstractController | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected const REQUEST_BODY_CONTENT_KEY_IMAGE = 'image'; | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* | ||
* @return \Symfony\Component\HttpFoundation\JsonResponse | ||
*/ | ||
public function findTermsAction(Request $request): JsonResponse | ||
{ | ||
$requestContent = (string)$request->getContent(); | ||
|
||
if (!$requestContent) { | ||
return $this->createAjaxErrorResponse(); | ||
} | ||
|
||
$requestBodyContent = $this->getFactory() | ||
->getUtilEncodingService() | ||
->decodeJson($requestContent, true); | ||
|
||
if (!is_array($requestBodyContent)) { | ||
return $this->createAjaxErrorResponse(); | ||
} | ||
|
||
$isRequestValid = $this->getFactory() | ||
->createImageSearchAiValidator() | ||
->validate($requestBodyContent); | ||
|
||
if (!$isRequestValid) { | ||
return $this->createAjaxErrorResponse(); | ||
} | ||
|
||
$openAiChatResponseTransfer = $this->getFactory()->createImageToSearchTermsTransformer()->transform( | ||
$requestBodyContent[static::REQUEST_BODY_CONTENT_KEY_IMAGE], | ||
); | ||
|
||
if (!$openAiChatResponseTransfer->getIsSuccessful() || !$openAiChatResponseTransfer->getMessage()) { | ||
return $this->jsonResponse(); | ||
} | ||
|
||
$searchResults = $this | ||
->getFactory() | ||
->getCatalogClient() | ||
->catalogSuggestSearch($openAiChatResponseTransfer->getMessage()); | ||
|
||
return new JsonResponse([ | ||
'success' => true, | ||
'firstMatchProductUrl' => !empty($searchResults['suggestionByType']['product_abstract'][0]['url']) | ||
? Url::generate($searchResults['suggestionByType']['product_abstract'][0]['url'])->build() | ||
: '', | ||
]); | ||
} | ||
|
||
/** | ||
* @return \Symfony\Component\HttpFoundation\JsonResponse | ||
*/ | ||
protected function createAjaxErrorResponse(): JsonResponse | ||
{ | ||
return $this->jsonResponse(['success' => false], Response::HTTP_BAD_REQUEST); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/SprykerEco/Yves/ImageSearchAi/Dependency/Client/ImageSearchAiToCatalogClientBridge.php
This file contains 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,35 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SprykerEco\Yves\ImageSearchAi\Dependency\Client; | ||
|
||
class ImageSearchAiToCatalogClientBridge implements ImageSearchAiToCatalogClientInterface | ||
{ | ||
/** | ||
* @var \Spryker\Client\Catalog\CatalogClientInterface | ||
*/ | ||
protected $catalogClient; | ||
|
||
/** | ||
* @param \Spryker\Client\Catalog\CatalogClientInterface $catalogClient | ||
*/ | ||
public function __construct($catalogClient) | ||
{ | ||
$this->catalogClient = $catalogClient; | ||
} | ||
|
||
/** | ||
* @param string $searchString | ||
* @param array<string, mixed> $requestParameters | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function catalogSuggestSearch(string $searchString, array $requestParameters = []): array | ||
{ | ||
return $this->catalogClient->catalogSuggestSearch($searchString, $requestParameters); | ||
} | ||
} |
Oops, something went wrong.