@@ -802,6 +802,158 @@ direction LR
802
802
Tool "1" o-- "0..1" WebSearch
803
803
```
804
804
805
+ ## HTTP Communication Layer
806
+
807
+ This section describes the HTTP communication architecture that differs from the original design. Instead of models directly using PSR-18 HTTP clients, we introduce a layer of abstraction that provides better separation of concerns and flexibility.
808
+
809
+ ### Design Principles
810
+
811
+ 1 . ** Custom Request/Response Objects** : Models create and receive custom Request and Response objects specific to this library
812
+ 2 . ** HttpTransporter** : A dedicated class that handles the translation between custom objects and PSR standards
813
+ 3 . ** PSR Compliance** : The transporter uses PSR-7 (HTTP messages), PSR-17 (HTTP factories), and PSR-18 (HTTP client) internally
814
+ 4 . ** No Direct Coupling** : The library remains decoupled from any specific HTTP client implementation
815
+
816
+ ### HTTP Communication Flow
817
+
818
+ ``` mermaid
819
+ sequenceDiagram
820
+ participant Model
821
+ participant HttpTransporter
822
+ participant PSR17Factory
823
+ participant PSR18Client
824
+
825
+ Model->>HttpTransporter: send(Request)
826
+ HttpTransporter->>PSR17Factory: createRequest(Request)
827
+ PSR17Factory-->>HttpTransporter: PSR-7 Request
828
+ HttpTransporter->>PSR18Client: sendRequest(PSR-7 Request)
829
+ PSR18Client-->>HttpTransporter: PSR-7 Response
830
+ HttpTransporter->>PSR17Factory: parseResponse(PSR-7 Response)
831
+ PSR17Factory-->>HttpTransporter: Response
832
+ HttpTransporter-->>Model: Response
833
+ ```
834
+
835
+ ### HTTP Components Class Diagram
836
+
837
+ ``` mermaid
838
+ ---
839
+ config:
840
+ class:
841
+ hideEmptyMembersBox: true
842
+ ---
843
+ classDiagram
844
+ direction TB
845
+ namespace AiClientNamespace.Http.DTO {
846
+ class Request {
847
+ +getMethod() string
848
+ +getUri() string
849
+ +getHeaders() array< string, string|string[] >
850
+ +getBody() string|null
851
+ +withHeader(string $name, string|string[] $value) self
852
+ +withBody(string $body) self
853
+ +getJsonSchema() array< string, mixed >$
854
+ }
855
+
856
+ class Response {
857
+ +getStatusCode() int
858
+ +getHeaders() array< string, string|string[] >
859
+ +getBody() string
860
+ +getReasonPhrase() string
861
+ +isSuccessful() bool
862
+ +getJsonSchema() array< string, mixed >$
863
+ }
864
+ }
865
+
866
+ namespace AiClientNamespace.Http.Contracts {
867
+ class HttpTransporterInterface {
868
+ +send(Request $request) Response
869
+ }
870
+ }
871
+
872
+ namespace AiClientNamespace.Http {
873
+ class HttpTransporter {
874
+ -requestFactory Psr17RequestFactoryInterface
875
+ -streamFactory Psr17StreamFactoryInterface
876
+ -client Psr18ClientInterface
877
+ +__construct(Psr17RequestFactoryInterface $requestFactory, Psr17StreamFactoryInterface $streamFactory, Psr18ClientInterface $client)
878
+ +send(Request $request) Response
879
+ -convertToPsr7Request(Request $request) Psr7RequestInterface
880
+ -convertFromPsr7Response(Psr7ResponseInterface $response) Response
881
+ }
882
+ }
883
+
884
+ namespace PSR {
885
+ class Psr17RequestFactoryInterface {
886
+ <<interface>>
887
+ +createRequest(string $method, UriInterface|string $uri) RequestInterface
888
+ }
889
+
890
+ class Psr17StreamFactoryInterface {
891
+ <<interface>>
892
+ +createStream(string $content) StreamInterface
893
+ }
894
+
895
+ class Psr18ClientInterface {
896
+ <<interface>>
897
+ +sendRequest(RequestInterface $request) ResponseInterface
898
+ }
899
+
900
+ class Psr7RequestInterface {
901
+ <<interface>>
902
+ }
903
+
904
+ class Psr7ResponseInterface {
905
+ <<interface>>
906
+ }
907
+ }
908
+
909
+ <<interface>> HttpTransporterInterface
910
+
911
+ HttpTransporter ..|> HttpTransporterInterface
912
+ HttpTransporter --> Psr17RequestFactoryInterface : uses
913
+ HttpTransporter --> Psr17StreamFactoryInterface : uses
914
+ HttpTransporter --> Psr18ClientInterface : uses
915
+ HttpTransporter ..> Request : receives
916
+ HttpTransporter ..> Response : creates
917
+ HttpTransporter ..> Psr7RequestInterface : creates
918
+ HttpTransporter ..> Psr7ResponseInterface : receives
919
+ ```
920
+
921
+ ### Integration with Models
922
+
923
+ Models that need HTTP communication will use the ` HttpTransporterInterface ` :
924
+
925
+ ``` mermaid
926
+ ---
927
+ config:
928
+ class:
929
+ hideEmptyMembersBox: true
930
+ ---
931
+ classDiagram
932
+ namespace AiClientNamespace.Providers.Models.Contracts {
933
+ class WithHttpTransporterInterface {
934
+ +setHttpTransporter(HttpTransporterInterface $transporter) void
935
+ +getHttpTransporter() HttpTransporterInterface
936
+ }
937
+ }
938
+
939
+ namespace AiClientNamespace.Providers.Models.TextGeneration {
940
+ class SomeProviderTextGenerationModel {
941
+ -transporter HttpTransporterInterface
942
+ +generateTextResult(Message[] $prompt) GenerativeAiResult
943
+ -createApiRequest(Message[] $prompt) Request
944
+ -parseApiResponse(Response $response) GenerativeAiResult
945
+ }
946
+ }
947
+
948
+ <<interface>> WithHttpTransporterInterface
949
+
950
+ SomeProviderTextGenerationModel ..|> TextGenerationModelInterface
951
+ SomeProviderTextGenerationModel ..|> WithHttpTransporterInterface
952
+ SomeProviderTextGenerationModel --> HttpTransporterInterface : uses
953
+ SomeProviderTextGenerationModel --> Request : creates
954
+ SomeProviderTextGenerationModel --> Response : receives
955
+ ```
956
+
805
957
### Details: Class diagram for AI extenders
806
958
807
959
``` mermaid
@@ -826,13 +978,9 @@ direction LR
826
978
827
979
namespace AiClientNamespace.Providers.Contracts {
828
980
class AuthenticationInterface {
829
- +authenticate(RequestInterface $request) void
981
+ +authenticate(Request $request) void
830
982
+getJsonSchema() array< string, mixed >$
831
983
}
832
- class HttpClientInterface {
833
- +send(RequestInterface $request, array< string, mixed > $options) ResponseInterface
834
- +request(string $method, string $uri, array< string, mixed > $options) ResponseInterface
835
- }
836
984
class ModelMetadataDirectoryInterface {
837
985
+listModelMetadata() ModelMetadata[]
838
986
+hasModelMetadata(string $modelId) bool
@@ -885,15 +1033,9 @@ direction LR
885
1033
+setAuthentication(AuthenticationInterface $authentication) void
886
1034
+getAuthentication() AuthenticationInterface
887
1035
}
888
- class WithEmbeddingOperationsInterface {
889
- +getOperation(string $operationId) EmbeddingOperation
890
- }
891
- class WithGenerativeAiOperationsInterface {
892
- +getOperation(string $operationId) GenerativeAiOperation
893
- }
894
- class WithHttpClientInterface {
895
- +setHttpClient(HttpClientInterface $client) void
896
- +getHttpClient() HttpClientInterface
1036
+ class WithHttpTransporterInterface {
1037
+ +setHttpTransporter(HttpTransporterInterface $transporter) void
1038
+ +getHttpTransporter() HttpTransporterInterface
897
1039
}
898
1040
}
899
1041
@@ -973,14 +1115,6 @@ direction LR
973
1115
}
974
1116
}
975
1117
976
- namespace AiClientNamespace.Providers.Models.EmbeddingGeneration.Contracts {
977
- class EmbeddingGenerationModelInterface {
978
- +generateEmbeddingsResult(Message[] $input) EmbeddingResult
979
- }
980
- class EmbeddingGenerationOperationModelInterface {
981
- +generateEmbeddingsOperation(Message[] $input) EmbeddingOperation
982
- }
983
- }
984
1118
985
1119
namespace AiClientNamespace.Providers.Models.ImageGeneration.Contracts {
986
1120
class ImageGenerationModelInterface {
@@ -1050,20 +1184,15 @@ direction LR
1050
1184
<<interface>> ModelInterface
1051
1185
<<interface>> ProviderAvailabilityInterface
1052
1186
<<interface>> ModelMetadataDirectoryInterface
1053
- <<interface>> WithGenerativeAiOperationsInterface
1054
- <<interface>> WithEmbeddingOperationsInterface
1055
1187
<<interface>> TextGenerationModelInterface
1056
1188
<<interface>> ImageGenerationModelInterface
1057
1189
<<interface>> TextToSpeechConversionModelInterface
1058
1190
<<interface>> SpeechGenerationModelInterface
1059
- <<interface>> EmbeddingGenerationModelInterface
1060
1191
<<interface>> TextGenerationOperationModelInterface
1061
1192
<<interface>> ImageGenerationOperationModelInterface
1062
1193
<<interface>> TextToSpeechConversionOperationModelInterface
1063
1194
<<interface>> SpeechGenerationOperationModelInterface
1064
- <<interface>> EmbeddingGenerationOperationModelInterface
1065
- <<interface>> WithHttpClientInterface
1066
- <<interface>> HttpClientInterface
1195
+ <<interface>> WithHttpTransporterInterface
1067
1196
<<interface>> WithAuthenticationInterface
1068
1197
<<interface>> AuthenticationInterface
1069
1198
<<Enumeration>> CapabilityEnum
@@ -1095,10 +1224,8 @@ direction LR
1095
1224
ModelInterface <|-- ImageGenerationModelInterface
1096
1225
ModelInterface <|-- TextToSpeechConversionModelInterface
1097
1226
ModelInterface <|-- SpeechGenerationModelInterface
1098
- ModelInterface <|-- EmbeddingGenerationModelInterface
1099
1227
ModelInterface <|-- TextGenerationOperationModelInterface
1100
1228
ModelInterface <|-- ImageGenerationOperationModelInterface
1101
1229
ModelInterface <|-- TextToSpeechConversionOperationModelInterface
1102
1230
ModelInterface <|-- SpeechGenerationOperationModelInterface
1103
- ModelInterface <|-- EmbeddingGenerationOperationModelInterface
1104
1231
```
0 commit comments