Skip to content

Commit 05abf54

Browse files
authored
feat: Refactor Anthropic/OpenAI driver, streaming protocols and more (#16)
* feat: Refactor Anthropic driver * wip * wip * wip * wip * fix * stan * wip * update tests * stan * wip * fix and refactor * add caching support * wip * wip * wip * vercel * improvements * streaming protocols * wip * pass through thread id * wip * wip * wip * wip * wip * wip * wip * wip * 🎨 * stan * wip * update tests * update tests * fixes * 🎨 * wip * agents as tools * tweak * fix error streaming * wip * use internal package * skills * fixes * updates * fix * wip * improvements * add logger * wip * fixes * fix constraint * cleanup * initial docs
1 parent d3414a4 commit 05abf54

File tree

470 files changed

+37025
-4634
lines changed

Some content is hidden

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

470 files changed

+37025
-4634
lines changed

.cursor/commands/fix-stan.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ trim_trailing_whitespace = true
1111
[*.md]
1212
trim_trailing_whitespace = false
1313

14-
[*.yml,*.yaml,*.neon]
14+
[*.yml,*.yaml,*.neon,*.tsx,*.ts]
1515
indent_style = space
1616
indent_size = 2

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
/README.md export-ignore
99
/testbench.yaml export-ignore
1010
/ecs.php export-ignore
11+
/rector.php export-ignore
1112
/tests export-ignore
1213
/phpstan.neon export-ignore
1314
/workbench export-ignore
15+
/scratchpad.php export-ignore
16+
/phpstan.dist.neon export-ignore
17+
/package.json export-ignore
18+
/vite.config.ts export-ignore
19+
/tsconfig.json export-ignore
20+
/eslint.config.js export-ignore

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ updates:
77
labels:
88
- "dependencies"
99
- "composer"
10-
versioning-strategy: "widen"
10+
versioning-strategy: "increase-if-necessary"
1111
open-pull-requests-limit: 10
1212

1313
- package-ecosystem: "github-actions"

.github/workflows/run-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Tests
22

3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
37
on: [push]
48

59
concurrency:

.github/workflows/static-analysis.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Static Analysis
22

3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
37
on: [push]
48

59
concurrency:
@@ -65,5 +69,8 @@ jobs:
6569
restore-keys: |
6670
ecs-cache-
6771
68-
- name: Run format checks
69-
run: composer format --no-progress-bar
72+
- name: Run Rector
73+
run: ./vendor/bin/rector process --dry-run --no-progress-bar --no-diffs --output-format=github
74+
75+
- name: Run ECS
76+
run: ./vendor/bin/ecs check --no-progress-bar --no-diffs --output-format=checkstyle

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ composer.lock
44
.env
55
.DS_Store
66
.phpstan-cache
7+
node_modules
8+
public

composer.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,31 @@
1717
],
1818
"require": {
1919
"php": "^8.4",
20-
"adhocore/json-fixer": "^1.0",
21-
"cortexphp/json-schema": "dev-main",
20+
"cortexphp/json-repair": "^0.4",
21+
"cortexphp/json-schema": "^1.0",
2222
"cortexphp/model-info": "^0.3",
23-
"illuminate/collections": "^12.0",
23+
"guzzlehttp/psr7": "^2.8",
24+
"illuminate/collections": "^12.49",
2425
"laravel/prompts": "^0.3.8",
25-
"mozex/anthropic-php": "^1.1",
2626
"openai-php/client": "^0.18",
2727
"php-mcp/client": "^1.0",
2828
"psr-discovery/cache-implementations": "^1.2",
2929
"psr-discovery/event-dispatcher-implementations": "^1.1",
3030
"react/async": "^4.3",
31-
"spatie/laravel-package-tools": "^1.17"
31+
"saloonphp/cache-plugin": "^3.0",
32+
"saloonphp/saloon": "^3.14",
33+
"spatie/laravel-package-tools": "^1.17",
34+
"spatie/yaml-front-matter": "^2.1"
3235
},
3336
"require-dev": {
37+
"beyondcode/laravel-dump-server": "^2.1",
3438
"guzzlehttp/guzzle": "^7.9",
3539
"hkulekci/qdrant": "^0.5.8",
40+
"inertiajs/inertia-laravel": "^2.0",
41+
"laravel/wayfinder": "^0.1.13",
3642
"league/event": "^3.0",
3743
"mockery/mockery": "^1.6",
44+
"monolog/monolog": "^3.10",
3845
"orchestra/testbench": "^10.6",
3946
"pestphp/pest": "^4.0",
4047
"pestphp/pest-plugin-type-coverage": "^4.0",
@@ -60,7 +67,7 @@
6067
}
6168
},
6269
"scripts": {
63-
"test": "pest",
70+
"test": "pest --parallel",
6471
"ecs": "ecs check --fix",
6572
"rector": "rector process",
6673
"stan": "phpstan analyse",
@@ -86,6 +93,10 @@
8693
"Composer\\Config::disableProcessTimeout",
8794
"@build",
8895
"@php vendor/bin/testbench serve --ansi"
96+
],
97+
"dev": [
98+
"Composer\\Config::disableProcessTimeout",
99+
"npx concurrently 'composer serve' 'npm run dev' -c '#a78bfa,#34d399' --names=server,vite --kill-others"
89100
]
90101
},
91102
"config": {

config/cortex.php

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
declare(strict_types=1);
44

55
use Cortex\LLM\Enums\LLMDriver;
6+
use Cortex\LLM\Enums\StreamingProtocol;
67
use Cortex\Agents\Prebuilt\WeatherAgent;
7-
use Cortex\ModelInfo\Enums\ModelProvider;
88
use Cortex\ModelInfo\Providers\OllamaModelInfoProvider;
99
use Cortex\ModelInfo\Providers\LiteLLMModelInfoProvider;
1010
use Cortex\ModelInfo\Providers\LMStudioModelInfoProvider;
@@ -23,33 +23,23 @@
2323
'llm' => [
2424
'default' => env('CORTEX_DEFAULT_LLM', 'openai'),
2525

26-
'openai' => [
27-
'driver' => LLMDriver::OpenAIChat,
28-
'options' => [
29-
'api_key' => env('OPENAI_API_KEY', ''),
30-
'base_uri' => env('OPENAI_BASE_URI'),
31-
'organization' => env('OPENAI_ORGANIZATION'),
32-
],
33-
'default_model' => 'gpt-4.1-mini',
34-
'default_parameters' => [
35-
'temperature' => null,
36-
'max_tokens' => 1024,
37-
'top_p' => null,
38-
],
26+
'cache' => [
27+
'enabled' => env('CORTEX_LLM_CACHE_ENABLED', false),
28+
'store' => env('CORTEX_LLM_CACHE_STORE'),
29+
'ttl' => env('CORTEX_LLM_CACHE_TTL', 3600),
3930
],
4031

41-
'openai_responses' => [
32+
'openai' => [
4233
'driver' => LLMDriver::OpenAIResponses,
43-
'model_provider' => ModelProvider::OpenAI,
4434
'options' => [
4535
'api_key' => env('OPENAI_API_KEY', ''),
4636
'base_uri' => env('OPENAI_BASE_URI'),
4737
'organization' => env('OPENAI_ORGANIZATION'),
4838
],
49-
'default_model' => 'gpt-5-mini',
39+
'default_model' => 'gpt-4.1-mini',
5040
'default_parameters' => [
5141
'temperature' => null,
52-
'max_tokens' => null,
42+
'max_output_tokens' => 1024,
5343
'top_p' => null,
5444
],
5545
],
@@ -68,41 +58,42 @@
6858
],
6959
],
7060

71-
'groq' => [
61+
'ollama' => [
7262
'driver' => LLMDriver::OpenAIChat,
63+
// 'driver' => LLMDriver::Anthropic,
7364
'options' => [
74-
'api_key' => env('GROQ_API_KEY', ''),
75-
'base_uri' => env('GROQ_BASE_URI', 'https://api.groq.com/openai/v1'),
65+
'api_key' => 'ollama',
66+
'base_uri' => env('OLLAMA_BASE_URI', 'http://localhost:11434/v1'),
7667
],
77-
'default_model' => 'llama-3.1-8b-instant',
68+
'default_model' => 'gpt-oss:20b',
7869
'default_parameters' => [
7970
'temperature' => null,
80-
'max_tokens' => null,
71+
'max_tokens' => 1024,
8172
'top_p' => null,
8273
],
8374
],
8475

85-
'ollama' => [
86-
'driver' => LLMDriver::OpenAIChat,
76+
'lmstudio' => [
77+
'driver' => LLMDriver::OpenAIResponses,
8778
'options' => [
88-
'api_key' => 'ollama',
89-
'base_uri' => env('OLLAMA_BASE_URI', 'http://localhost:11434/v1'),
79+
'api_key' => 'lmstudio',
80+
'base_uri' => env('LMSTUDIO_BASE_URI', 'http://localhost:1234/v1'),
9081
],
91-
'default_model' => 'gemma3:12b',
82+
'default_model' => 'openai/gpt-oss-20b',
9283
'default_parameters' => [
9384
'temperature' => null,
94-
'max_tokens' => null,
85+
'max_tokens' => 1024,
9586
'top_p' => null,
9687
],
9788
],
9889

99-
'lmstudio' => [
90+
'groq' => [
10091
'driver' => LLMDriver::OpenAIChat,
10192
'options' => [
102-
'api_key' => 'lmstudio',
103-
'base_uri' => env('LMSTUDIO_BASE_URI', 'http://localhost:1234/v1'),
93+
'api_key' => env('GROQ_API_KEY', ''),
94+
'base_uri' => env('GROQ_BASE_URI', 'https://api.groq.com/openai/v1'),
10495
],
105-
'default_model' => 'qwen2.5-14b-instruct-mlx',
96+
'default_model' => 'llama-3.1-8b-instant',
10697
'default_parameters' => [
10798
'temperature' => null,
10899
'max_tokens' => null,
@@ -365,4 +356,16 @@
365356
'agents' => [
366357
WeatherAgent::class,
367358
],
359+
360+
/*
361+
|--------------------------------------------------------------------------
362+
| Default Streaming Protocol
363+
|--------------------------------------------------------------------------
364+
|
365+
| The default streaming protocol to use for streaming responses.
366+
|
367+
| Supported protocols: "raw", "agui", "vercel", "text"
368+
|
369+
*/
370+
'default_streaming_protocol' => StreamingProtocol::Vercel,
368371
];

docs/assets/favicon.svg

Lines changed: 13 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)