Skip to content

Commit fb3b630

Browse files
committed
Fixed streaming after LLM connectivity refactoring
1 parent 5c5bac7 commit fb3b630

File tree

22 files changed

+371
-1185
lines changed

22 files changed

+371
-1185
lines changed

config/http.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Cognesy\Instructor\Features\Http\Enums\HttpClientType;
44

55
return [
6-
'defaultClient' => 'laravel',
6+
'defaultClient' => 'guzzle',
77

88
'cache' => [
99
'enabled' => false,

config/llm.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@
144144
'contextLength' => 128_000,
145145
'maxOutputLength' => 4096,
146146
],
147+
'minimaxi' => [
148+
'providerType' => LLMProviderType::Minimaxi->value,
149+
'apiUrl' => 'https://api.minimaxi.chat/v1',
150+
'apiKey' => Env::get('MINIMAXI_API_KEY', ''),
151+
'endpoint' => '/text/chatcompletion_v2',
152+
'defaultModel' => 'abab6.5s-chat', // 'MiniMax-Text-01',
153+
'defaultMaxTokens' => 1024,
154+
'contextLength' => 1_000_000,
155+
'maxOutputLength' => 4096,
156+
],
147157
'ollama' => [
148158
'providerType' => LLMProviderType::Ollama->value,
149159
'apiUrl' => 'http://localhost:11434/v1',

evals/LLMModes/run.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@
4545
),
4646
);
4747

48-
//Debug::enable();
49-
//$connections = array_keys(Settings::get('llm', 'connections'));
48+
Debug::enable();
49+
$connections = ['minimaxi']; // array_keys(Settings::get('llm', 'connections'));
50+
$modes = [Mode::Tools];//, Mode::JsonSchema, Mode::Json, Mode::MdJson, Mode::Text];
51+
$stream = [false]; // [true, false];
5052

5153
$experiment = new Experiment(
52-
//cases: InferenceCases::only($connections, [Mode::Tools], [true]),
53-
cases: InferenceCases::all(),
54+
cases: InferenceCases::only($connections, $modes, $stream),
55+
//cases: InferenceCases::all(),
5456
executor: new RunInference($data),
5557
processors: [
5658
new CompanyEval(

examples/A05_Extras/ChatWithSummary/run.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
```php
1313
<?php
1414

15-
use Cognesy\Instructor\Extras\Chat\ChatWithSummary;
15+
use Cognesy\Instructor\Extras\Chat\Pipelines\ChatWithSummary;
1616
use Cognesy\Instructor\Extras\Chat\Utils\SummarizeMessages;
1717
use Cognesy\Instructor\Features\LLM\Inference;
1818
use Cognesy\Instructor\Features\LLM\LLM;
@@ -24,14 +24,14 @@
2424
$loader = require 'vendor/autoload.php';
2525
$loader->add('Cognesy\\Instructor\\', __DIR__ . '../../src/');
2626

27-
$maxSteps = 10;
27+
$maxSteps = 5;
2828
$sys = [
2929
'You are helpful assistant explaining Challenger Sale method, you answer questions. Provide very brief answers, not more than one sentence. Simplify things, don\'t go into details, but be very pragmatic and focused on practical bizdev problems.',
30-
'You are curious novice growth expert interested in improving promoting Instructor library, you keep asking questions. Ask short, simple questions. Always ask a single question. Use your knowledge of Instructor library and marketing of tech products for developers.',
30+
'You are curious novice growth expert working to promote Instructor library, you keep asking questions. Use your knowledge of Instructor library and marketing of tech products for developers. Ask short, simple questions. Always ask a single question.',
3131
];
3232
$startMessage = new Message('assistant', 'Help me get better sales results. Be brief and concise.');
3333

34-
$readme = "# CONTEXT\n\n" . file_get_contents(__DIR__ . '/summary.md');
34+
$context = "# CONTEXT\n\n" . file_get_contents(__DIR__ . '/summary.md');
3535

3636
$summarizer = new SummarizeMessages(
3737
//prompt: 'Summarize the messages.',
@@ -40,13 +40,21 @@
4040
tokenLimit: 1024,
4141
);
4242

43-
$chat = new ChatWithSummary(
44-
null,
43+
//$chat = new ChatWithSummary(
44+
// null,
45+
// 256,
46+
// 256,
47+
// 1024,
48+
// true,
49+
// true,
50+
// $summarizer,
51+
//);
52+
53+
$chat = ChatWithSummary::create(
4554
256,
4655
256,
4756
1024,
48-
true,
49-
true,
57+
$summarizer,
5058
);
5159
$chat->script()->section('main')->appendMessage($startMessage);
5260

@@ -55,10 +63,13 @@
5563
for($i = 0; $i < $maxSteps; $i++) {
5664
$chat->script()
5765
->section('system')
58-
->withMessages(Messages::fromString($sys[$i % 2], 'system'))
59-
->appendMessage(Message::fromString($readme, 'system'));
66+
->withMessages(Messages::fromString($sys[$i % 2], 'system'));
67+
$chat->script()
68+
->section('context')
69+
->withMessages(Messages::fromString($context, 'system'));
70+
6071
$messages = $chat->script()
61-
->select(['system','summary','buffer','main'])
72+
->select(['system', 'context', 'summary', 'buffer', 'main'])
6273
->toMessages()
6374
->remapRoles(['assistant' => 'user', 'user' => 'assistant', 'system' => 'system']);
6475

@@ -73,6 +84,6 @@
7384
echo "\n";
7485
dump('>>> '.$response);
7586
echo "\n";
76-
$chat->appendMessage(new Message(role: 'assistant', content: $response));
87+
$chat->appendMessage(new Message(role: 'assistant', content: $response), 'main');
7788
}
7889
//dump($chat->script());

examples/A05_Extras/ComplexExtraction/run.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ enum StakeholderRole: string {
9797
case Other = 'other';
9898
}
9999

100-
//Debug::enable();
100+
Debug::enable();
101101

102102
$instructor = new Instructor;
103103

0 commit comments

Comments
 (0)