Skip to content

Commit c07ada3

Browse files
committed
Added foundations to support logging via Monolog
1 parent 6d30cc5 commit c07ada3

Some content is hidden

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

45 files changed

+374
-41
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
"symfony/yaml": "^7.0",
6060
"phpdocumentor/reflection-docblock": "^5.4",
6161
"symfony/type-info": "^7.1",
62-
"phpstan/phpdoc-parser": "^1.29"
62+
"phpstan/phpdoc-parser": "^1.29",
63+
"psr/log": "^3.0",
64+
"monolog/monolog": "^3.6"
6365
}
6466
}

composer.lock

Lines changed: 102 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/autowire.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@
2323
use Cognesy\Instructor\Deserialization\Contracts\CanDeserializeClass;
2424
use Cognesy\Instructor\Deserialization\Symfony\Deserializer;
2525
use Cognesy\Instructor\Events\EventDispatcher;
26+
use Cognesy\Instructor\Logging\EventLogger;
2627
use Cognesy\Instructor\Schema\Factories\SchemaFactory;
2728
use Cognesy\Instructor\Schema\Factories\ToolCallBuilder;
2829
use Cognesy\Instructor\Schema\Utils\ReferenceQueue;
2930
use Cognesy\Instructor\Validation\Contracts\CanValidateObject;
3031
use Cognesy\Instructor\Validation\Symfony\Validator;
32+
use DateTimeZone;
33+
use Monolog\Handler\StreamHandler;
34+
use Monolog\Level;
35+
use Monolog\Logger;
36+
use Psr\Log\LoggerInterface;
37+
use Psr\Log\LogLevel;
3138

3239
function autowire(
3340
Configuration $config,
@@ -55,6 +62,27 @@ class: EventDispatcher::class,
5562
reference: $events
5663
);
5764

65+
$config->declare(
66+
class: Logger::class,
67+
name: LoggerInterface::class,
68+
context: [
69+
'name' => 'instructor',
70+
'handlers' => [
71+
new StreamHandler('php://stdout', Level::Debug)
72+
],
73+
'processors' => [],
74+
'timezone' => new DateTimeZone('UTC'),
75+
],
76+
);
77+
78+
$config->declare(
79+
class: EventLogger::class,
80+
context: [
81+
'logger' => $config->reference(LoggerInterface::class),
82+
'level' => LogLevel::INFO,
83+
],
84+
);
85+
5886
/// CONTEXT //////////////////////////////////////////////////////////////////////////////
5987

6088
$config->declare(
@@ -82,6 +110,10 @@ class: ModelFactory::class,
82110
'anthropic:claude-3-opus' => $config->reference('anthropic:claude-3-opus'),
83111
'anyscale:mixtral-8x7b' => $config->reference('anyscale:mixtral-8x7b'),
84112
'azure:gpt-3.5-turbo' => $config->reference('azure:gpt-3.5-turbo'),
113+
'cohere:command-r' => $config->reference('cohere:command-r'),
114+
'cohere:command-r-plus' => $config->reference('cohere:command-r-plus'),
115+
'cohere:command' => $config->reference('cohere:command'),
116+
'cohere:command-light' => $config->reference('cohere:command-light'),
85117
'fireworks:mixtral-8x7b' => $config->reference('fireworks:mixtral-8x7b'),
86118
'groq:llama3-8b' => $config->reference('groq:llama3-8b'),
87119
'groq:llama3-70b' => $config->reference('groq:llama3-70b'),

config/models/cohere.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class: ModelParams::class,
4444

4545
$config->declare(
4646
class: ModelParams::class,
47-
name: 'cohere:cohere',
47+
name: 'cohere:command',
4848
context: [
4949
'label' => 'Cohere Command',
5050
'type' => 'cohere',

examples/02_Advanced/LanguagePrograms/run.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,7 @@ public function forward(string $directory) : EmailStats {
172172
$emailStats = $getStats->with(EmailStats::for('inbox'));
173173

174174
echo "Results:\n";
175-
dump($emailStats->get());
175+
dump($emailStats->get());
176+
?>
177+
```
178+

hub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
$loader = require 'vendor/autoload.php';
1010
$loader->add('Cognesy\\InstructorHub\\', __DIR__ . '../src-hub/');
1111

12-
$config = hub(new Configuration());
12+
$config = hub(Configuration::instance());
1313
$app = new Cognesy\InstructorHub\Hub($config);
1414
$app->run($argc, $argv);

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ nav:
242242
- Support for Anthropic API: 'hub/api_support/llm_support_anthropic.md'
243243
- Support for Anyscale API: 'hub/api_support/llm_support_anyscale.md'
244244
- Support for Azure OpenAI API: 'hub/api_support/llm_support_azure_oai.md'
245+
- Support for Cohere API: 'hub/api_support/llm_support_cohere.md'
245246
- Support for Fireworks.ai API: 'hub/api_support/llm_support_fireworks_ai.md'
246247
- Support for Groq API: 'hub/api_support/llm_support_groq.md'
247248
- Support for Mistral API: 'hub/api_support/llm_support_mistral.md'

notes/releases/r_0_8.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
- Support for Cohere API
33
- Composite language programs with Module classes (inspired by DSPy)
44
- `FunctionCall` helper class for extracting arguments for callable objects
5+
- Consolidated message building logic to support formats required by different APIs
6+
- Additions to docs and examples

src/ApiClient/ApiClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class ApiClient implements CanCallApi
2525
public function __construct(
2626
EventDispatcher $events = null,
2727
) {
28-
$this->withEventDispatcher($events ?? new EventDispatcher());
28+
$this->withEventDispatcher($events ?? new EventDispatcher('api-client'));
2929
}
3030

3131
/// PUBLIC API //////////////////////////////////////////////////////////////////////////////////////////

src/Configuration/ComponentConfig.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
* @property callable $getInstance Callback to create the instance (overrides provided class name), receives $context values
2323
* @property bool $injectContext Force attempt to set provided context values into the instance public properties (if they exist)
2424
*/
25-
class ComponentConfig {
25+
class ComponentConfig
26+
{
2627
use HandlesEvents;
2728

2829
public function __construct(

0 commit comments

Comments
 (0)