Skip to content

Commit c6fb9f9

Browse files
committed
Fixed tests to remove live LLM API call
1 parent c3e6a3f commit c6fb9f9

File tree

82 files changed

+867
-747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+867
-747
lines changed

docs-build/http/1-overview.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ HttpClient
9494
└── withRequest() - Create pending request for execution
9595
└── pool() - Execute multiple requests concurrently
9696
└── withPool() - Create pending pool for deferred execution
97-
// @doctest id="3481"
97+
// @doctest id="d696"
9898
```
9999

100100
### Middleware Layer
@@ -105,7 +105,7 @@ The middleware system allows for processing requests and responses through a cha
105105
Request -> Middleware 1 -> Middleware 2 -> ... -> Driver -> External API
106106
107107
Response <- Middleware 1 <- Middleware 2 <- ... <- Driver <- HTTP Response
108-
// @doctest id="8e34"
108+
// @doctest id="8c7a"
109109
```
110110

111111
Key components:
@@ -123,7 +123,7 @@ CanHandleHttpRequest (interface)
123123
├── SymfonyDriver
124124
├── LaravelDriver
125125
└── MockHttpDriver (for testing)
126-
// @doctest id="90fb"
126+
// @doctest id="3caa"
127127
```
128128

129129
### Adapter Layer
@@ -136,7 +136,7 @@ HttpResponse (interface)
136136
├── SymfonyHttpResponse
137137
├── LaravelHttpResponse
138138
└── MockHttpResponse
139-
// @doctest id="0b24"
139+
// @doctest id="742b"
140140
```
141141

142142
## Supported HTTP Clients

docs-build/http/10-middleware.mdx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface HttpMiddleware
3434
{
3535
public function handle(HttpClientRequest $request, CanHandleHttpRequest $next): HttpResponse;
3636
}
37-
// @doctest id="cd49"
37+
// @doctest id="3b27"
3838
```
3939

4040
The `handle` method takes two parameters:
@@ -85,7 +85,7 @@ abstract class BaseMiddleware implements HttpMiddleware
8585
return $response;
8686
}
8787
}
88-
// @doctest id="7c48"
88+
// @doctest id="d29b"
8989
```
9090

9191
By extending `BaseMiddleware`, you only need to override the methods relevant to your middleware's functionality, making the code more focused and maintainable.
@@ -120,7 +120,7 @@ $client->withMiddleware(
120120
new RetryMiddleware(),
121121
new TimeoutMiddleware()
122122
);
123-
// @doctest id="956a"
123+
// @doctest id="313a"
124124
```
125125

126126
Named middleware are useful when you need to reference them later, for example, to remove or replace them.
@@ -132,7 +132,7 @@ You can remove middleware from the stack by name:
132132
```php
133133
// Remove a middleware by name
134134
$client->middleware()->remove('cache');
135-
// @doctest id="88a9"
135+
// @doctest id="2a4b"
136136
```
137137

138138
### Replacing Middleware
@@ -142,7 +142,7 @@ You can replace a middleware with another one:
142142
```php
143143
// Replace a middleware with a new one
144144
$client->middleware()->replace('cache', new ImprovedCachingMiddleware());
145-
// @doctest id="2f47"
145+
// @doctest id="e9ee"
146146
```
147147

148148
### Clearing Middleware
@@ -152,7 +152,7 @@ You can remove all middleware from the stack:
152152
```php
153153
// Clear all middleware
154154
$client->middleware()->clear();
155-
// @doctest id="0092"
155+
// @doctest id="93e5"
156156
```
157157

158158
### Checking Middleware
@@ -164,7 +164,7 @@ You can check if a middleware exists in the stack:
164164
if ($client->middleware()->has('rate-limit')) {
165165
// The 'rate-limit' middleware exists
166166
}
167-
// @doctest id="a2a2"
167+
// @doctest id="53f9"
168168
```
169169

170170
### Getting Middleware
@@ -177,7 +177,7 @@ $rateLimitMiddleware = $client->middleware()->get('rate-limit');
177177

178178
// Get a middleware by index
179179
$firstMiddleware = $client->middleware()->get(0);
180-
// @doctest id="0456"
180+
// @doctest id="5fe1"
181181
```
182182

183183
### Middleware Order
@@ -229,7 +229,7 @@ $request = new HttpRequest(
229229
// 6. RetryMiddleware processes the response (may retry on certain status codes)
230230
// 7. LoggingMiddleware processes the response (logs incoming response)
231231
$response = $client->withRequest($request)->get();
232-
// @doctest id="b67a"
232+
// @doctest id="8c63"
233233
```
234234

235235
## Built-in Middleware
@@ -248,7 +248,7 @@ $client->withMiddleware(new DebugMiddleware());
248248

249249
// Or use the convenience method
250250
$client->withDebugPreset('on');
251-
// @doctest id="95e7"
251+
// @doctest id="fbe9"
252252
```
253253

254254
The debug middleware logs:
@@ -275,7 +275,7 @@ return [
275275
'responseStreamByLine' => true, // Dump stream as full lines or raw chunks
276276
],
277277
];
278-
// @doctest id="ddff"
278+
// @doctest id="600f"
279279
```
280280

281281
### BufferResponse Middleware
@@ -287,7 +287,7 @@ use Cognesy\Http\Middleware\BufferResponse\BufferResponseMiddleware;
287287

288288
// Add buffer response middleware
289289
$client->withMiddleware(new BufferResponseMiddleware());
290-
// @doctest id="b2ee"
290+
// @doctest id="eecf"
291291
```
292292

293293
This middleware is useful when you need to access a response body or stream multiple times, as it stores the data after the first access.
@@ -301,7 +301,7 @@ use Cognesy\Http\Middleware\StreamByLine\StreamByLineMiddleware;
301301

302302
// Add stream by line middleware
303303
$client->withMiddleware(new StreamByLineMiddleware());
304-
// @doctest id="cb33"
304+
// @doctest id="1e97"
305305
```
306306

307307
You can customize how lines are processed by providing a parser function:
@@ -316,7 +316,7 @@ $lineParser = function (string $line) {
316316
};
317317

318318
$client->withMiddleware(new StreamByLineMiddleware($lineParser));
319-
// @doctest id="9d21"
319+
// @doctest id="455c"
320320
```
321321

322322

@@ -332,7 +332,7 @@ $client->withMiddleware(
332332
new BufferResponseMiddleware(), // Buffer responses for reuse
333333
new DebugMiddleware() // Log requests and responses
334334
);
335-
// @doctest id="cd98"
335+
// @doctest id="bcc6"
336336
```
337337

338338
#### API Client Setup
@@ -345,7 +345,7 @@ $client->withMiddleware(
345345
new RateLimitingMiddleware(maxRequests: 100), // Respect rate limits
346346
new LoggingMiddleware() // Log API interactions
347347
);
348-
// @doctest id="8ca0"
348+
// @doctest id="886d"
349349
```
350350

351351
#### Testing Setup
@@ -355,7 +355,7 @@ $client = new HttpClient();
355355
$client->withMiddleware(
356356
new RecordReplayMiddleware(RecordReplayMiddleware::MODE_REPLAY) // Replay recorded responses
357357
);
358-
// @doctest id="bd3f"
358+
// @doctest id="2ff2"
359359
```
360360

361361
#### Streaming Setup
@@ -366,7 +366,7 @@ $client->withMiddleware(
366366
new StreamByLineMiddleware(), // Process streaming responses line by line
367367
new BufferResponseMiddleware() // Buffer responses for reuse
368368
);
369-
// @doctest id="805e"
369+
// @doctest id="d120"
370370
```
371371

372372
By combining middleware components, you can create a highly customized HTTP client that handles complex requirements while keeping your application code clean and focused.

docs-build/http/11-processing-with-middleware.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ $client->withMiddleware(new class implements HttpMiddleware {
7070
return $response;
7171
}
7272
});
73-
// @doctest id="7666"
73+
// @doctest id="2758"
7474
```
7575

7676
This approach is concise but less reusable than defining a named class.
@@ -131,7 +131,7 @@ Then add the middleware to your client:
131131
```php
132132
$client = new HttpClient();
133133
$client->withMiddleware(new JsonStreamMiddleware());
134-
// @doctest id="3d52"
134+
// @doctest id="edf9"
135135
```
136136

137137
### Response Decoration for Transforming Content
@@ -169,7 +169,7 @@ class XmlToJsonDecorator extends BaseResponseDecorator
169169
return $headers;
170170
}
171171
}
172-
// @doctest id="65a4"
172+
// @doctest id="3dde"
173173
```
174174

175175
And the corresponding middleware:
@@ -199,7 +199,7 @@ class XmlToJsonMiddleware extends BaseMiddleware
199199
return new XmlToJsonDecorator($request, $response);
200200
}
201201
}
202-
// @doctest id="92af"
202+
// @doctest id="ca2a"
203203
```
204204

205205
## Advanced Middleware Examples
@@ -257,7 +257,7 @@ class AnalyticsMiddleware extends BaseMiddleware
257257
return $response;
258258
}
259259
}
260-
// @doctest id="f6a4"
260+
// @doctest id="5931"
261261
```
262262

263263
### Circuit Breaker Middleware
@@ -347,7 +347,7 @@ class CircuitBreakerMiddleware extends BaseMiddleware
347347
}
348348
}
349349
}
350-
// @doctest id="b989"
350+
// @doctest id="9021"
351351
```
352352

353353
### Conditional Middleware
@@ -387,7 +387,7 @@ class ConditionalMiddleware implements HttpMiddleware
387387
return $next->handle($request);
388388
}
389389
}
390-
// @doctest id="2a82"
390+
// @doctest id="df58"
391391
```
392392

393393
Usage example:
@@ -401,7 +401,7 @@ $conditionalCaching = new ConditionalMiddleware(
401401
);
402402

403403
$client->withMiddleware($conditionalCaching);
404-
// @doctest id="f2e2"
404+
// @doctest id="9fa4"
405405
```
406406

407407
### Request ID Middleware
@@ -454,7 +454,7 @@ class RequestIdMiddleware extends BaseMiddleware
454454
return $response;
455455
}
456456
}
457-
// @doctest id="3fa3"
457+
// @doctest id="e19f"
458458
```
459459

460460
### OpenTelemetry Tracing Middleware
@@ -537,7 +537,7 @@ class TracingMiddleware extends BaseMiddleware
537537
}
538538
}
539539
}
540-
// @doctest id="e67b"
540+
// @doctest id="6022"
541541
```
542542

543543
### Customizing Middleware for LLM APIs
@@ -643,7 +643,7 @@ class LlmStreamingMiddleware extends BaseMiddleware
643643
};
644644
}
645645
}
646-
// @doctest id="e211"
646+
// @doctest id="2a4d"
647647
```
648648

649649
### Combining Multiple Middleware Components
@@ -687,7 +687,7 @@ $client->withMiddleware(
687687

688688
// Now the client is ready to use with a complete middleware pipeline
689689
$response = $client->withRequest($request)->get();
690-
// @doctest id="5451"
690+
// @doctest id="caba"
691691
```
692692

693693
With this setup, requests and responses flow through the middleware in the following order:

docs-build/http/2-getting-started.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can install it separately via Composer:
1616

1717
```bash
1818
composer require cognesy/instructor-http-client
19-
# @doctest id="51bf"
19+
# @doctest id="8bda"
2020
```
2121

2222
### Dependencies
@@ -26,13 +26,13 @@ The Instructor HTTP client API requires at least one of the supported HTTP clien
2626
**For Guzzle:**
2727
```bash
2828
composer require guzzlehttp/guzzle
29-
# @doctest id="a34b"
29+
# @doctest id="2893"
3030
```
3131

3232
**For Symfony HTTP Client:**
3333
```bash
3434
composer require symfony/http-client
35-
# @doctest id="b358"
35+
# @doctest id="9c30"
3636
```
3737

3838
**For Laravel HTTP Client:**
@@ -82,7 +82,7 @@ $body = $response->body();
8282

8383
echo "Status: $statusCode\n";
8484
echo "Body: $body\n";
85-
// @doctest id="69e2"
85+
// @doctest id="60eb"
8686
```
8787

8888
### Error Handling
@@ -99,7 +99,7 @@ try {
9999
echo "Request failed: {$e->getMessage()}\n";
100100
// Handle the error
101101
}
102-
// @doctest id="3783"
102+
// @doctest id="e5f1"
103103
```
104104

105105
## Configuration
@@ -162,7 +162,7 @@ return [
162162
'responseStreamByLine' => true, // dump stream as full lines or raw chunks
163163
],
164164
];
165-
// @doctest id="74aa"
165+
// @doctest id="131f"
166166
```
167167

168168
### Runtime Configuration
@@ -181,7 +181,7 @@ $client = (new HttpClientBuilder())
181181
->withPreset('guzzle')
182182
->withDebugPreset('on')
183183
->create();
184-
// @doctest id="21a0"
184+
// @doctest id="26a1"
185185
```
186186

187187
## Simple Request Example
@@ -234,7 +234,7 @@ try {
234234

235235
// You might want to log the error or retry the request
236236
}
237-
// @doctest id="3e70"
237+
// @doctest id="8a56"
238238
```
239239

240240
### Example: Fetching Data
@@ -282,7 +282,7 @@ try {
282282
} catch (HttpRequestException $e) {
283283
echo "Request failed: {$e->getMessage()}\n";
284284
}
285-
// @doctest id="c04e"
285+
// @doctest id="dc32"
286286
```
287287

288288
These examples demonstrate the basic usage of the Instructor HTTP client API for common HTTP operations. In the following chapters, we'll explore more advanced features and customization options.

0 commit comments

Comments
 (0)