-
Notifications
You must be signed in to change notification settings - Fork 1
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 the basic structure for src/ #1
Draft
aghorianducalis
wants to merge
1
commit into
jjrohrer:main
Choose a base branch
from
aghorianducalis:src-structure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 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 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 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,81 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jjr\RobustChat; | ||
|
||
use Jjr\RobustChat\Contracts\ServiceProviderInterface; | ||
use Jjr\RobustChat\DTO\Response\Response; | ||
|
||
/** | ||
* Client class for interacting with AI service providers. | ||
*/ | ||
class Client | ||
{ | ||
/** | ||
* The AI service provider instance. | ||
* | ||
* @var \Jjr\RobustChat\Contracts\ServiceProviderInterface | ||
*/ | ||
protected ServiceProviderInterface $provider; | ||
|
||
/** | ||
* Client constructor. | ||
* | ||
* @param \Jjr\RobustChat\Contracts\ServiceProviderInterface $provider The AI service provider instance. | ||
*/ | ||
public function __construct(ServiceProviderInterface $provider) | ||
{ | ||
$this->provider = $provider; | ||
} | ||
|
||
/** | ||
* Set the AI service provider instance. | ||
* | ||
* @param \Jjr\RobustChat\Contracts\ServiceProviderInterface $provider The AI service provider instance. | ||
* @return void | ||
*/ | ||
public function setProvider(ServiceProviderInterface $provider): void | ||
{ | ||
$this->provider = $provider; | ||
} | ||
|
||
/** | ||
* Generate a response using the AI service provider. | ||
* | ||
* @param string $input The input text or data for generating the response. | ||
* @param array $options Additional options for the request. | ||
* @return \Jjr\RobustChat\DTO\Response\Response The generated response. | ||
* @throws \Jjr\RobustChat\Exceptions\AIException If an error occurs during the request. | ||
*/ | ||
public function generateResponse(string $input, array $options = []): Response | ||
{ | ||
return $this->provider->generateResponse($input, $options); | ||
} | ||
|
||
/** | ||
* Classify text using the AI service provider. | ||
* | ||
* @param string $text The text to classify. | ||
* @param array $options Additional options for the request. | ||
* @return \Jjr\RobustChat\DTO\Response\Response The classification result. | ||
* @throws \Jjr\RobustChat\Exceptions\AIException If an error occurs during the request. | ||
*/ | ||
public function classifyText(string $text, array $options = []): Response | ||
{ | ||
return $this->provider->classifyText($text, $options); | ||
} | ||
|
||
/** | ||
* Get a completion for the given prompt using the AI service provider. | ||
* | ||
* @param string $prompt The prompt for which to generate a completion. | ||
* @param array $options Additional options for the request. | ||
* @return \Jjr\RobustChat\DTO\Response\Response The generated completion. | ||
* @throws \Jjr\RobustChat\Exceptions\AIException If an error occurs during the request. | ||
*/ | ||
public function getCompletion(string $prompt, array $options = []): Response | ||
{ | ||
return $this->provider->getCompletion($prompt, $options); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jjr\RobustChat; | ||
|
||
/** | ||
* Configuration class for the AI service provider. | ||
*/ | ||
readonly class Configuration | ||
{ | ||
public function __construct( | ||
protected ?string $apiKey = null, | ||
protected ?string $apiKeyForOrganization = null, | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* Get the API key for organization for the AI service provider. | ||
* | ||
* @return string|null The API key. | ||
*/ | ||
public function getApiKeyForOrganization(): ?string | ||
{ | ||
return $this->apiKeyForOrganization; | ||
} | ||
|
||
/** | ||
* Get the API key for the AI service provider. | ||
* | ||
* @return string|null The API key. | ||
*/ | ||
public function getApiKey(): ?string | ||
{ | ||
return $this->apiKey; | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jjr\RobustChat\Contracts; | ||
|
||
use Jjr\RobustChat\DTO\Response\Response; | ||
|
||
/** | ||
* Interface defining methods for interacting with AI service providers. | ||
*/ | ||
interface ServiceProviderInterface | ||
{ | ||
/** | ||
* Generate a response from the AI service provider. | ||
* | ||
* @param string $input The input text or data for generating the response. | ||
* @param array $options Additional options for the request (e.g., parameters for the AI model). | ||
* @return \Jjr\RobustChat\DTO\Response\Response The generated response from the AI service. | ||
* @throws \Jjr\RobustChat\Exceptions\AIException If an error occurs during the request. | ||
*/ | ||
public function generateResponse(string $input, array $options = []): Response; | ||
|
||
/** | ||
* Classify text using the AI service provider. | ||
* | ||
* @param string $text The text to classify. | ||
* @param array $options Additional options for the request (e.g., parameters for the classification model). | ||
* @return Response The classification result. | ||
* @throws \Jjr\RobustChat\Exceptions\AIException If an error occurs during the request. | ||
*/ | ||
public function classifyText(string $text, array $options = []): Response; | ||
|
||
/** | ||
* Get a completion for the given prompt using the AI service provider. | ||
* | ||
* @param string $prompt The prompt for which to generate a completion. | ||
* @param array $options Additional options for the request (e.g., parameters for the AI model). | ||
* @return Response The generated completion. | ||
* @throws \Jjr\RobustChat\Exceptions\AIException If an error occurs during the request. | ||
*/ | ||
public function getCompletion(string $prompt, array $options = []): Response; | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jjr\RobustChat\DTO\Response; | ||
|
||
class OpenAIResponse extends Response | ||
{ | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jjr\RobustChat\DTO\Response; | ||
|
||
class Response | ||
{ | ||
public function __construct(protected readonly ?object $rawResponseData = null) | ||
{ | ||
} | ||
|
||
/** | ||
* @return object|null | ||
*/ | ||
public function getRawResponseData(): ?object | ||
{ | ||
return $this->rawResponseData; | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jjr\RobustChat\Exceptions; | ||
|
||
use Exception; | ||
|
||
/** | ||
* Exception class for AI service provider errors. | ||
*/ | ||
class AIException extends Exception | ||
{ | ||
/** | ||
* AIException constructor. | ||
* | ||
* @inheritdoc | ||
*/ | ||
public function __construct($message = "", $code = 0, Exception $previous = null) | ||
{ | ||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
/** | ||
* Get a string representation of the exception. | ||
* | ||
* @inheritdoc | ||
*/ | ||
public function __toString(): string | ||
{ | ||
return __CLASS__ . ": [$this->code]: $this->message\n"; | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jjr\RobustChat\Exceptions; | ||
|
||
/** | ||
* Exception class for OpenAI service errors. | ||
*/ | ||
class OpenAIException extends AIException | ||
{ | ||
} |
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jjr\RobustChat\Providers; | ||
|
||
use Jjr\RobustChat\Configuration; | ||
use Jjr\RobustChat\Contracts\ServiceProviderInterface; | ||
use Jjr\RobustChat\DTO\Response\Response; | ||
|
||
/** | ||
* Abstract class implementing common functionality for AI service providers. | ||
*/ | ||
abstract class AbstractServiceProvider implements ServiceProviderInterface | ||
{ | ||
/** | ||
* AbstractServiceProvider constructor. | ||
* | ||
* @param Configuration $configuration The API configuration for the AI service provider. | ||
*/ | ||
public function __construct( | ||
protected readonly Configuration $configuration, | ||
protected $apiClient | ||
) | ||
{ | ||
} | ||
|
||
abstract public function generateResponse(string $input, array $options = []): Response; | ||
|
||
abstract public function classifyText(string $text, array $options = []): Response; | ||
|
||
abstract public function getCompletion(string $prompt, array $options = []): Response; | ||
} |
Oops, something went wrong.
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.
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.
@aghorianducalis In general, I'd like avoid a comment like this because it is clear from the function __construct about it's main role.
Just add a comment when it clarifies what is happening, or is a note to other devs about the state of the code