From 9830f856e880218332a5acf142cec1db8916880d Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Tue, 28 Jan 2025 02:14:46 +0300 Subject: [PATCH 01/10] Use match expression --- src/Traits/Queries/HasQueryParams.php | 41 ++++++++++----------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/Traits/Queries/HasQueryParams.php b/src/Traits/Queries/HasQueryParams.php index 453c7bb..627eb2b 100644 --- a/src/Traits/Queries/HasQueryParams.php +++ b/src/Traits/Queries/HasQueryParams.php @@ -35,24 +35,16 @@ private function getQueryParam(array $query, string $key, $default, string $type */ private function convertValue($value, string $type): mixed { - switch ($type) { - case DataTypes::STRING->value: - return (string) $value; - case DataTypes::INTEGER->value: - return (int) $value; - case DataTypes::FLOAT->value: - return (float) $value; - case DataTypes::ARRAY->value: - return (array) $value; - case DataTypes::OBJECT->value: - return (object) $value; - case DataTypes::BOOL->value: - return (bool) $value; - case DataTypes::JSON->value: - return json_decode((string) $value, true); - default: - return $value; - } + return match ($type) { + DataTypes::STRING->value => (string)$value, + DataTypes::INTEGER->value => (int)$value, + DataTypes::FLOAT->value => (float)$value, + DataTypes::ARRAY->value => (array)$value, + DataTypes::OBJECT->value => (object)$value, + DataTypes::BOOL->value => (bool)$value, + DataTypes::JSON->value => json_decode((string)$value, true), + default => $value, + }; } /** @@ -63,13 +55,10 @@ private function convertValue($value, string $type): mixed */ private function getDefaultForKey(string $key): mixed { - switch ($key) { - case QueryFlags::MODEL->value: - return $this->getDefaultModel(); - case QueryFlags::STREAM->value: - return $this->getDefaultStream(); - default: - return null; - } + return match ($key) { + QueryFlags::MODEL->value => $this->getDefaultModel(), + QueryFlags::STREAM->value => $this->getDefaultStream(), + default => null, + }; } } From cf7cea27c05fe9289aecf75a9bdc91c38ea4cc69 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Tue, 28 Jan 2025 02:17:35 +0300 Subject: [PATCH 02/10] Fix typo --- src/Models/ResultAbstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/ResultAbstract.php b/src/Models/ResultAbstract.php index 3349855..3b7ae46 100644 --- a/src/Models/ResultAbstract.php +++ b/src/Models/ResultAbstract.php @@ -14,7 +14,7 @@ abstract class ResultAbstract implements ResultContract protected ?int $statusCode; protected ?string $content; /** - * handel response comeing from request + * handel response coming from request * @var ResponseInterface|null */ protected ?ResponseInterface $response; From f6c7de8278c8625431a580d37b0d3648c57133c3 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Tue, 28 Jan 2025 02:22:44 +0300 Subject: [PATCH 03/10] Change namespace to DeepSeekPhp --- src/Contracts/DeepseekClientContract.php | 4 ++-- src/Contracts/Factories/ApiFactoryContract.php | 4 ++-- src/Contracts/Models/ResultContract.php | 2 +- src/Contracts/Resources/ResourceContract.php | 2 +- src/DeepseekClient.php | 18 +++++++++--------- src/Enums/Configs/DefaultConfigs.php | 2 +- src/Enums/Configs/TemperatureValues.php | 2 +- src/Enums/Data/DataTypes.php | 2 +- src/Enums/Queries/QueryRoles.php | 2 +- src/Enums/Requests/EndpointSuffixes.php | 2 +- src/Enums/Requests/HTTPState.php | 2 +- src/Enums/Requests/HeaderFlags.php | 2 +- src/Enums/Requests/QueryFlags.php | 2 +- src/Factories/ApiFactory.php | 8 ++++---- src/Models/BadResult.php | 2 +- src/Models/FailureResult.php | 2 +- src/Models/ResultAbstract.php | 6 +++--- src/Models/SuccessResult.php | 2 +- src/Resources/Chat.php | 2 +- src/Resources/Coder.php | 4 ++-- src/Resources/Resource.php | 2 +- src/Traits/Queries/HasQueryParams.php | 2 +- src/Traits/Resources/HasChat.php | 4 ++-- src/Traits/Resources/HasCoder.php | 4 ++-- tests/DeepseekTest.php | 2 +- tests/HandelResultDeepseekTest.php | 6 +++--- 26 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/Contracts/DeepseekClientContract.php b/src/Contracts/DeepseekClientContract.php index 0106b90..6df9032 100644 --- a/src/Contracts/DeepseekClientContract.php +++ b/src/Contracts/DeepseekClientContract.php @@ -1,8 +1,8 @@ Date: Tue, 28 Jan 2025 22:37:49 +0300 Subject: [PATCH 04/10] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6703567..4f92771 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ echo 'API Response:'.$response; ### [Laravel Deepseek Package](https://github.com/deepseek-php/deepseek-laravel) +### [Symfony Deepseek Package](https://github.com/deepseek-php/deepseek-symfony) + --- ## Testing From a2a111d2cb4bda3c64d3ddd3e835b3e9c4f3224c Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 1 Feb 2025 00:19:29 +0300 Subject: [PATCH 05/10] Remove unnecessary return from setStatusCode() --- src/Models/ResultAbstract.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Models/ResultAbstract.php b/src/Models/ResultAbstract.php index b1f4cd8..718cf0e 100644 --- a/src/Models/ResultAbstract.php +++ b/src/Models/ResultAbstract.php @@ -26,7 +26,6 @@ public function __construct(?int $statusCode = null, ?string $content = null) protected function setStatusCode(int $statusCode) { $this->statusCode = $statusCode; - return $this; } public function getStatusCode(): int { From 381ead656a4e4ae6cb8ed4451b819d3730cb0f2b Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Sat, 1 Feb 2025 01:00:31 +0300 Subject: [PATCH 06/10] change namespace and adding change logs --- MIGRATION.md | 31 +++ README.md | 180 +++++++++++------- composer.json | 54 ++---- src/Contracts/DeepseekClientContract.php | 4 +- .../Factories/ApiFactoryContract.php | 4 +- src/Contracts/Models/ResultContract.php | 5 +- src/Contracts/Resources/ResourceContract.php | 2 +- src/DeepseekClient.php | 28 +-- src/Enums/Configs/DefaultConfigs.php | 2 +- src/Enums/Configs/TemperatureValues.php | 2 +- src/Enums/Data/DataTypes.php | 2 +- src/Enums/Models.php | 2 +- src/Enums/Queries/QueryRoles.php | 2 +- src/Enums/Requests/EndpointSuffixes.php | 2 +- src/Enums/Requests/HTTPState.php | 2 +- src/Enums/Requests/HeaderFlags.php | 2 +- src/Enums/Requests/QueryFlags.php | 2 +- src/Factories/ApiFactory.php | 8 +- src/Models/BadResult.php | 5 +- src/Models/FailureResult.php | 5 +- src/Models/ResultAbstract.php | 7 +- src/Models/SuccessResult.php | 5 +- src/Resources/Chat.php | 2 +- src/Resources/Coder.php | 4 +- src/Resources/Resource.php | 26 +-- src/Traits/Queries/HasQueryParams.php | 6 +- src/Traits/Resources/HasChat.php | 4 +- src/Traits/Resources/HasCoder.php | 4 +- tests/DeepseekTest.php | 2 +- tests/HandelResultDeepseekTest.php | 12 +- 30 files changed, 233 insertions(+), 183 deletions(-) create mode 100644 MIGRATION.md diff --git a/MIGRATION.md b/MIGRATION.md new file mode 100644 index 0000000..53691e1 --- /dev/null +++ b/MIGRATION.md @@ -0,0 +1,31 @@ +# CHANGELOG + +## [2.x] - 2025-02-01 + +If you are upgrading from a version `1.x` to `2.x`, please perform the following steps: + +### Breaking Changes + +### 1. Namespace Change +- **Old Namespace:** `DeepseekPhp` +- **New Namespace:** `DeepSeek` + +**Action Required:** +Update all imports in your codebase. + +##### Replace: +```php +use DeepseekPhp\DeepseekClient; +``` + +##### With: +```php +use DeepSeek\DeepseekClient; +``` + +### Migration Guide +1. Replace all occurrences of `DeepseekPhp` with `DeepSeek` in your code. +3. Run tests to ensure everything works as expected. + +If you encounter issues, please refer to our documentation or open an issue on GitHub. + diff --git a/README.md b/README.md index 4f92771..a8311b9 100644 --- a/README.md +++ b/README.md @@ -1,85 +1,99 @@

- - Gpdf - +

DeepSeek PHP Client

+

๐Ÿš€ Community-Driven PHP SDK for DeepSeek AI API Integration

+ +

+ + Latest Version + + + PHP Version + + + License + + + Tests Status + +

-# Deepseek PHP Client - ## Table of Contents -- [Overview](#Overview) - - [Features](#key-Features) -- [Installation](#installation) -- [Quick Start Guide](#quick-start-guide) - - [Basic Usage](#basic-usage) - - [Advanced Usage](#advanced-usage) - - [Use With Frameworks](#use-with-frameworks) -- [Testing](#testing) -- [Contributors](#contributors-) -- [License](#license) +- [โœจ Features](#-features) +- [๐Ÿ“ฆ Installation](#-installation) +- [๐Ÿš€ Quick Start](#-quick-start) + - [Basic Usage](#basic-usage) + - [Advanced Configuration](#advanced-configuration) + - [Framework Integration](#-framework-integration) +- [๐Ÿ†• Migration Guide](#-migration-guide) +- [๐Ÿ“ Changelog](#-changelog) +- [๐Ÿงช Testing](#-testing) +- [๐Ÿ”’ Security](#-security) +- [๐Ÿค Contributors](#-contributors) +- [๐Ÿ“„ License](#-license) --- -## Overview -**Deepseek PHP Client** is a robust and community-driven PHP client library for seamless integration with the [Deepseek](https://www.deepseek.com/) API. -### Key Features -- **Easy Integration:** Simplifies interaction with the Deepseek API using a PHP client. -- **Method Chaining:** Supports fluent method chaining for building requests. -- **Customizable:** Allows setting different models, query roles, and streaming options. -- **PSR-18 Compliance:** Utilizes PSR-18 HTTP client for making API requests. + +## โœจ Features + +- **Seamless API Integration**: PHP-first interface for DeepSeek's AI capabilities +- **Fluent Builder Pattern**: Chainable methods for intuitive request building +- **Enterprise Ready**: PSR-18 compliant HTTP client integration +- **Model Flexibility**: Support for multiple DeepSeek models (Coder, Chat, etc.) +- **Streaming Ready**: Built-in support for real-time response handling +- **Framework Friendly**: Laravel & Symfony packages available --- -## Installation +## ๐Ÿ“ฆ Installation -You can install the package via Composer: +Require the package via Composer: ```bash composer require deepseek-php/deepseek-php-client ``` -**Ensure your project meets the following requirements:** -- PHP 8.1 or later +**Requirements**: +- PHP 8.1+ --- -## Quick Start Guide +## ๐Ÿš€ Quick Start ### Basic Usage -```php -use DeepseekPhp\DeepseekClient; +Get started with just two lines of code: -$apiKey = 'your-api-key'; +```php +use DeepSeek\DeepSeekClient; -$response = DeepseekClient::build($apiKey) - ->query('Hello Deepseek, how are you today?') +$response = DeepSeekClient::build('your-api-key') + ->query('Explain quantum computing in simple terms') ->run(); -echo 'API Response:'.$response; +echo $response; // "Quantum computing uses qubits to..." ``` -**Note**: in easy mode it will take defaults for all configs [Check Default Values](https://github.com/deepseek-php/deepseek-php-client/blob/master/src/Enums/Configs/DefaultConfigs.php) +๐Ÿ“Œ Defaults used: +- Model: `deepseek-chat` +- Temperature: 0.8 -### Advanced Usage +### Advanced Configuration ```php -use DeepseekPhp\DeepseekClient; -use DeepseekPhp\Enums\Queries\QueryRoles; -use DeepseekPhp\Enums\Models; +use DeepSeek\DeepSeekClient; +use DeepSeek\Enums\Models; -$apiKey = 'your-api-key'; - -$response = DeepseekClient::build($apiKey, 'https://api.deepseek.com/v2', 500) - ->query('System setup query', 'system') - ->query('User input message', 'user') - ->withModel(Models::CODER->value) - ->setTemperature(1.5) +$response = DeepSeekClient::build('your-api-key') + ->withBaseUrl('https://api.deepseek.com/v2') + ->withModel(Models::CODER) + ->withTemperature(1.2) ->run(); echo 'API Response:'.$response; ``` -## Use With Frameworks +### ๐Ÿ›  Framework Integration ### [Laravel Deepseek Package](https://github.com/deepseek-php/deepseek-laravel) @@ -87,66 +101,92 @@ echo 'API Response:'.$response; --- -## Testing +## ๐Ÿšง Migration Guide -tests will come soon . +Upgrading from v1.x? Check our comprehensive [Migration Guide](MIGRATION.md) for breaking changes and upgrade instructions. -## Changelog +--- -See [CHANGELOG](CHANGELOG.md) for recent changes. +## ๐Ÿ“ Changelog -## Contributors โœจ +Detailed release notes available in [CHANGELOG.md](CHANGELOG.md) -Thanks to these wonderful people for contributing to this project! ๐Ÿ’– +--- + +## ๐Ÿงช Testing + +```bash +composer test +``` + +Test coverage coming in v2.1. + +--- + +## ๐Ÿ”’ Security + +**Report Vulnerabilities**: to [omaralwi2010@gmail.com](mailto:omaralwi2010@gmail.com) + +--- + +## ๐Ÿค Contributors + +A huge thank you to these amazing people who have contributed to this project! ๐ŸŽ‰๐Ÿ’– + -
- Omar AlAlwi + Omar AlAlwi
- Omar AlAlwi + Omar AlAlwi

๐Ÿ† Creator
- ayman alhattami + Ayman Alhattami
- ayman alhattami + Ayman Alhattami

- ๐Ÿ† Contributer + โญ Contributor
- Mohammad Asaad + Mohammad Asaad
- Mohammad Asaad + Mohammad Asaad

- ๐Ÿ† Contributer + โญ Contributor
- Opada Alzaiede + Opada Alzaiede
- Opada Alzaiede + Opada Alzaiede

- ๐Ÿ† Contributer + โญ Contributor +
+ + Hisham Abdullah +
+ Hisham Abdullah +
+
+ โญ Contributor
-Want to contribute? Check out the [contributing guidelines](./CONTRIBUTING.md) and submit a pull request! ๐Ÿš€ - -## Security +**Want to contribute?** Check out the [contributing guidelines](./CONTRIBUTING.md) and submit a pull request! ๐Ÿš€ -If you discover any security-related issues, please email creator : `omaralwi2010@gmail.com`. +--- -## License +## ๐Ÿ“„ License -The MIT License (MIT). See [LICENSE](LICENSE.md) for more information. +This package is open-source software licensed under the [MIT License](LICENSE.md). diff --git a/composer.json b/composer.json index 2b23890..7e39749 100644 --- a/composer.json +++ b/composer.json @@ -3,48 +3,32 @@ "description": "deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.", "keywords": [ "deepseek", - "deepseek-php-client", - "deepseek-api", - "DeepSeek-R1", - "DeepSeek-R1-Zero", - "php-deepseek", - "deepseek-coder", - "deepseek-chat", - "deepseek-math", - "deepseek-integration", - "openai", + "ai", "sdk", - "codex", - "GPT-3", - "DALL-E", "api", + "php", "client", - "deepseek-sdk", + "llm", + "nlp", + "openai", + "qwen", + "machine-learning", "php-sdk", - "php-ai", - "ai-for-php", "ai-sdk", "ai-api", - "natural", - "language", - "processing", - "deepseek-php-library", - "deepseek-client", "natural-language-processing", - "ai-integration", - "machine-learning", - "php-machine-learning", - "php-iot", - "nlp", - "data-processing", - "deep-learning", - "deepseek-library", - "php-library", "api-integration", "php-api-client", "deepseek-ai", - "php-openai-alternative", - "ai-client-library" + "ai-client-library", + "text-generation", + "generative-ai", + "api-wrapper", + "rest-client", + "developer-tools", + "php-ai-integration", + "deepseek-api", + "openai-alternative" ], "homepage": "https://github.com/deepseek-php/deepseek-php-client", "license": "MIT", @@ -61,7 +45,7 @@ "role": "creator" } ], - "version": "1.0.2", + "version": "2.0.0", "require": { "php": "^8.1.0", "php-http/discovery": "^1.20.0", @@ -86,12 +70,12 @@ }, "autoload": { "psr-4": { - "DeepseekPhp\\": "src/" + "DeepSeek\\": "src/" } }, "autoload-dev": { "psr-4": { - "DeepseekPhp\\Tests\\": "tests/" + "DeepSeek\\Tests\\": "tests/" } }, "minimum-stability": "dev", diff --git a/src/Contracts/DeepseekClientContract.php b/src/Contracts/DeepseekClientContract.php index 6df9032..3e5316e 100644 --- a/src/Contracts/DeepseekClientContract.php +++ b/src/Contracts/DeepseekClientContract.php @@ -1,8 +1,8 @@ apiKey) + $deepseek = DeepSeekClient::build($this->apiKey) ->query('Hello Deepseek, how are you today?') ->setTemperature(1.5); $response = $deepseek->run(); @@ -28,7 +28,7 @@ public function test_ok_response() } public function test_can_not_access_with_api_expired_payment() { - $deepseek = DeepseekClient::build($this->expiredApiKey) + $deepseek = DeepSeekClient::build($this->expiredApiKey) ->query('Hello Deepseek, how are you today?') ->setTemperature(1.5); $response = $deepseek->run(); @@ -42,7 +42,7 @@ public function test_can_not_access_with_api_expired_payment() } public function test_access_with_wrong_api_key() { - $deepseek = DeepseekClient::build($this->apiKey."wrong-api-key") + $deepseek = DeepSeekClient::build($this->apiKey."wrong-api-key") ->query('Hello Deepseek, how are you today?') ->setTemperature(1.5); $response = $deepseek->run(); From f91945ca0cd2e7da7e1766085c45b3e612d53d0d Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Sat, 1 Feb 2025 01:06:46 +0300 Subject: [PATCH 07/10] update doc --- MIGRATION.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 53691e1..ccb5cb4 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -15,12 +15,12 @@ Update all imports in your codebase. ##### Replace: ```php -use DeepseekPhp\DeepseekClient; +use DeepseekPhp\Someclass; ``` ##### With: ```php -use DeepSeek\DeepseekClient; +use DeepSeek\Someclass; ``` ### Migration Guide From 5087ae6c99a2edc8bb5efa634dfb99b4138cfcac Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Sat, 1 Feb 2025 01:24:24 +0300 Subject: [PATCH 08/10] bugfix --- src/{DeepseekClient.php => DeepSeekClient.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/{DeepseekClient.php => DeepSeekClient.php} (98%) diff --git a/src/DeepseekClient.php b/src/DeepSeekClient.php similarity index 98% rename from src/DeepseekClient.php rename to src/DeepSeekClient.php index 184c23d..19d58df 100644 --- a/src/DeepseekClient.php +++ b/src/DeepSeekClient.php @@ -13,7 +13,7 @@ use DeepSeek\Enums\Configs\TemperatureValues; use DeepSeek\Traits\Resources\{HasChat, HasCoder}; -class DeepseekClient implements DeepseekClientContract +class DeepSeekClient implements DeepseekClientContract { use HasChat, HasCoder; From 66a3aa6070023e935b635c5700da28e88be691d2 Mon Sep 17 00:00:00 2001 From: Omar Alalwi Date: Sat, 1 Feb 2025 01:26:25 +0300 Subject: [PATCH 09/10] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7e39749..2946e66 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "role": "creator" } ], - "version": "2.0.0", + "version": "2.0.1", "require": { "php": "^8.1.0", "php-http/discovery": "^1.20.0", From a0c246e06b3191ed4bfb27ef550911887513d03b Mon Sep 17 00:00:00 2001 From: Omar Alalwi Date: Sat, 1 Feb 2025 01:27:43 +0300 Subject: [PATCH 10/10] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2946e66..7e39749 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "role": "creator" } ], - "version": "2.0.1", + "version": "2.0.0", "require": { "php": "^8.1.0", "php-http/discovery": "^1.20.0",