Skip to content

Commit 88af736

Browse files
committed
Fixes after refactoring - inference, embeddings
1 parent 7515e03 commit 88af736

File tree

36 files changed

+117
-215
lines changed

36 files changed

+117
-215
lines changed

examples/A01_Basics/ValidationWithLLM/run.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ public function validate() : ValidationResult {
4545

4646
private function hasPII() : bool {
4747
$data = implode('\n', $this->details);
48-
return (new StructuredOutput)->with(
49-
messages: "Context:\n$data\n",
50-
responseModel: Scalar::boolean('hasPII', 'Does the context contain any PII?'),
51-
)->create()->getBoolean();
48+
return (new StructuredOutput)
49+
->with(
50+
messages: "Context:\n$data\n",
51+
responseModel: Scalar::boolean('hasPII', 'Does the context contain any PII?'),
52+
)
53+
->getBoolean();
5254
}
5355
}
5456

examples/A05_Extras/SchemaDynamic/run.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,10 @@
5555
echo "ASSISTANT:\n";
5656
dump($data);
5757

58+
assert(is_array($data), 'Response should be an array');
59+
assert(isset($data['name']), 'Response should have "name" field');
60+
assert(strpos($data['name'], 'Paris') !== false, 'City name should be Paris');
61+
assert(isset($data['population']), 'Response should have "population" field');
62+
assert(isset($data['founded']), 'Response should have "founded" field');
5863
?>
5964
```

examples/B01_LLM/LLMJson/run.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,10 @@
5252
echo "ASSISTANT:\n";
5353
dump($data);
5454

55+
assert(is_array($data), 'Response should be an array');
56+
assert(isset($data['name']), 'Response should have "name" field');
57+
assert(strpos($data['name'], 'Paris') !== false, 'City name should be Paris');
58+
assert(isset($data['population']), 'Response should have "population" field');
59+
assert(isset($data['founded']), 'Response should have "founded" field');
5560
?>
5661
```

examples/B01_LLM/LLMJsonSchema/run.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,10 @@
6868
echo "ASSISTANT:\n";
6969
dump($data);
7070

71+
assert(is_array($data), 'Response should be an array');
72+
assert(isset($data['name']), 'Response should have "name" field');
73+
assert(strpos($data['name'], 'Paris') !== false, 'City name should be Paris');
74+
assert(isset($data['population']), 'Response should have "population" field');
75+
assert(isset($data['founded']), 'Response should have "founded" field');
7176
?>
7277
```

examples/B01_LLM/LLMMdJson/run.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@
4343
echo "ASSISTANT:\n";
4444
dump($data);
4545

46+
assert(is_array($data), 'Response should be an array');
47+
assert(isset($data['name']), 'Response should have "name" field');
48+
assert(strpos($data['name'], 'Paris') !== false, 'City name should be Paris');
49+
assert(isset($data['population']), 'Response should have "population" field');
50+
assert(isset($data['founded']), 'Response should have "founded" field');
4651
?>
4752
```

examples/B01_LLM/LLMTools/run.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,10 @@
7070
echo "ASSISTANT:\n";
7171
dump($data);
7272

73+
assert(is_array($data), 'Response should be an array');
74+
assert(isset($data['name']), 'Response should have "name" field');
75+
assert(strpos($data['name'], 'Paris') !== false, 'City name should be Paris');
76+
assert(isset($data['population']), 'Response should have "population" field');
77+
assert(isset($data['founded']), 'Response should have "founded" field');
7378
?>
7479
```

examples/B01_LLM/LLMWithSchemaHelper/run.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,11 @@
3434
messages: [
3535
['role' => 'user', 'content' => 'What is capital of France? Respond with JSON data.']
3636
],
37-
responseFormat: [
38-
'type' => 'json_schema',
39-
'description' => 'City data',
40-
'json_schema' => [
41-
'name' => 'city_data',
42-
'schema' => $schema->toJsonSchema(),
43-
'strict' => true,
44-
],
45-
],
37+
responseFormat: $schema->toResponseFormat(
38+
schemaName: 'city_data',
39+
schemaDescription: 'City data',
40+
strict: true,
41+
),
4642
options: ['max_tokens' => 64],
4743
mode: OutputMode::JsonSchema,
4844
)

examples/B02_LLMAdvanced/CustomLLMDriver/run.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function handle(InferenceRequest $request): HttpClientResponse {
4848

4949
$answer = (new Inference)
5050
->withConfig($config)
51-
->withMessages([['role' => 'user', 'content' => 'What is the capital of France']])
51+
->withMessage(['role' => 'user', 'content' => 'What is the capital of France'])
5252
->withOptions(['max_tokens' => 64])
5353
->toText();
5454

examples/C01_ZeroShot/AutoRefine/run.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ class RefineAndSolve {
4444

4545
public function __invoke(string $problem) : int {
4646
$rewrittenPrompt = $this->rewritePrompt($problem);
47-
return (new StructuredOutput)->with(
48-
messages: "{$rewrittenPrompt->relevantContext}\nQuestion: {$rewrittenPrompt->userQuery}",
49-
responseModel: Scalar::integer('answer'),
50-
)->create()->getInt();
47+
return (new StructuredOutput)
48+
->with(
49+
messages: "{$rewrittenPrompt->relevantContext}\nQuestion: {$rewrittenPrompt->userQuery}",
50+
responseModel: Scalar::integer('answer'),
51+
)
52+
->getInt();
5153
}
5254

5355
private function rewritePrompt(string $query) : RewrittenTask {

examples/C01_ZeroShot/SimulatePerspective/run.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ private function answerQuestion(string $entity, string $query, array $knownFacts
9494
),
9595
responseModel: Scalar::string('location'),
9696
)
97-
->create()
9897
->getString();
9998
}
10099
}

0 commit comments

Comments
 (0)