File tree Expand file tree Collapse file tree 16 files changed +81
-18
lines changed Expand file tree Collapse file tree 16 files changed +81
-18
lines changed Original file line number Diff line number Diff line change
1
+ # You only need to fill in the values when running the examples, see examples/
2
+
3
+ # For using GPT on OpenAI
4
+ OPENAI_API_KEY =
5
+
6
+ # For using Claude on Anthropic
7
+ ANTHROPIC_API_KEY =
8
+
9
+ # For using GPT on Azure
10
+ AZURE_OPENAI_BASEURL =
11
+ AZURE_OPENAI_DEPLOYMENT =
12
+ AZURE_OPENAI_VERSION =
13
+ AZURE_OPENAI_KEY =
14
+
15
+ # For using SerpApi (tool)
16
+ SERP_API_KEY =
Original file line number Diff line number Diff line change 3
3
.php-cs-fixer.cache
4
4
.phpunit.cache
5
5
coverage
6
+ .env.local
Original file line number Diff line number Diff line change @@ -9,7 +9,19 @@ qa-lowest:
9
9
vendor/bin/php-cs-fixer fix --diff --verbose
10
10
vendor/bin/phpstan
11
11
vendor/bin/phpunit
12
- git restore composer.lock
13
12
14
13
coverage :
15
14
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage
15
+
16
+ run-all-examples :
17
+ php ./examples/chat-claude-anthropic.php
18
+ php ./examples/chat-gpt-azure.php
19
+ php ./examples/chat-gpt-openai.php
20
+ php ./examples/image-describer.php
21
+ php ./examples/reasoning-openai.php
22
+ php ./examples/structured-output-math.php
23
+ php ./examples/toolbox-clock.php
24
+ php ./examples/toolbox-serpapi.php
25
+ php ./examples/toolbox-weather.php
26
+ php ./examples/toolbox-wikipedia.php
27
+ php ./examples/toolbox-youtube.php
Original file line number Diff line number Diff line change @@ -62,7 +62,10 @@ Usage Examples
62
62
--------------
63
63
64
64
See [ examples] ( examples ) to run example implementations using this library.
65
- Depending on the example you need to export different environment variables for API keys or deployment configurations:
65
+ Depending on the example you need to export different environment variables
66
+ for API keys or deployment configurations or create a ` .env.local ` based on ` .env ` file.
67
+
68
+ To run all examples, just use ` make run-all-examples ` .
66
69
67
70
### Chat Examples
68
71
@@ -120,13 +123,21 @@ Depending on the example you need to export different environment variables for
120
123
php examples/toolbox-youtube.php
121
124
```
122
125
123
- ### Structured Output
126
+ ### Structured Output Example
124
127
125
128
1 . Structured Output Example: OpenAI's GPT
126
129
``` bash
127
130
export OPENAI_API_KEY=sk-...
128
131
php examples/structured-output-math.php
129
132
```
133
+
134
+ ### Reasoning Example
135
+
136
+ 1 . Reasoning Example: OpenAI's o1
137
+ ``` bash
138
+ export OPENAI_API_KEY=sk-...
139
+ php examples/reasoning-openai.php
140
+ ```
130
141
131
142
Contributions
132
143
-------------
Original file line number Diff line number Diff line change 34
34
"symfony/console" : " ^6.4 || ^7.1" ,
35
35
"symfony/css-selector" : " ^6.4 || ^7.1" ,
36
36
"symfony/dom-crawler" : " ^6.4 || ^7.1" ,
37
+ "symfony/dotenv" : " ^6.4 || ^7.1" ,
37
38
"symfony/var-dumper" : " ^6.4 || ^7.1"
38
39
},
39
40
"suggest" : {
Original file line number Diff line number Diff line change 5
5
use PhpLlm \LlmChain \Chain ;
6
6
use PhpLlm \LlmChain \Message \Message ;
7
7
use PhpLlm \LlmChain \Message \MessageBag ;
8
+ use Symfony \Component \Dotenv \Dotenv ;
8
9
use Symfony \Component \HttpClient \HttpClient ;
9
10
10
11
require_once dirname (__DIR__ ).'/vendor/autoload.php ' ;
12
+ (new Dotenv ())->loadEnv (dirname (__DIR__ ).'/.env ' );
11
13
12
- $ platform = new Anthropic (HttpClient::create (), getenv ( 'ANTHROPIC_API_KEY ' ) );
14
+ $ platform = new Anthropic (HttpClient::create (), $ _ENV [ 'ANTHROPIC_API_KEY ' ] );
13
15
$ llm = new Claude ($ platform );
14
16
15
17
$ chain = new Chain ($ llm );
Original file line number Diff line number Diff line change 6
6
use PhpLlm \LlmChain \OpenAI \Model \Gpt ;
7
7
use PhpLlm \LlmChain \OpenAI \Model \Gpt \Version ;
8
8
use PhpLlm \LlmChain \OpenAI \Platform \Azure ;
9
+ use Symfony \Component \Dotenv \Dotenv ;
9
10
use Symfony \Component \HttpClient \HttpClient ;
10
11
11
12
require_once dirname (__DIR__ ).'/vendor/autoload.php ' ;
13
+ (new Dotenv ())->loadEnv (dirname (__DIR__ ).'/.env ' );
12
14
13
15
$ platform = new Azure (HttpClient::create (),
14
- getenv ( 'AZURE_OPENAI_BASEURL ' ) ,
15
- getenv ( 'AZURE_OPENAI_DEPLOYMENT ' ) ,
16
- getenv ( 'AZURE_OPENAI_VERSION ' ) ,
17
- getenv ( 'AZURE_OPENAI_KEY ' )
16
+ $ _ENV [ 'AZURE_OPENAI_BASEURL ' ] ,
17
+ $ _ENV [ 'AZURE_OPENAI_DEPLOYMENT ' ] ,
18
+ $ _ENV [ 'AZURE_OPENAI_VERSION ' ] ,
19
+ $ _ENV [ 'AZURE_OPENAI_KEY ' ],
18
20
);
19
21
$ llm = new Gpt ($ platform , Version::gpt4oMini ());
20
22
Original file line number Diff line number Diff line change 6
6
use PhpLlm \LlmChain \OpenAI \Model \Gpt ;
7
7
use PhpLlm \LlmChain \OpenAI \Model \Gpt \Version ;
8
8
use PhpLlm \LlmChain \OpenAI \Platform \OpenAI ;
9
+ use Symfony \Component \Dotenv \Dotenv ;
9
10
use Symfony \Component \HttpClient \HttpClient ;
10
11
11
12
require_once dirname (__DIR__ ).'/vendor/autoload.php ' ;
13
+ (new Dotenv ())->loadEnv (dirname (__DIR__ ).'/.env ' );
12
14
13
- $ platform = new OpenAI (HttpClient::create (), getenv ( 'OPENAI_API_KEY ' ) );
15
+ $ platform = new OpenAI (HttpClient::create (), $ _ENV [ 'OPENAI_API_KEY ' ] );
14
16
$ llm = new Gpt ($ platform , Version::gpt4oMini (), [
15
17
'temperature ' => 0.5 , // default options for the model
16
18
]);
Original file line number Diff line number Diff line change 7
7
use PhpLlm \LlmChain \OpenAI \Model \Gpt ;
8
8
use PhpLlm \LlmChain \OpenAI \Model \Gpt \Version ;
9
9
use PhpLlm \LlmChain \OpenAI \Platform \OpenAI ;
10
+ use Symfony \Component \Dotenv \Dotenv ;
10
11
use Symfony \Component \HttpClient \HttpClient ;
11
12
12
13
require_once dirname (__DIR__ ).'/vendor/autoload.php ' ;
14
+ (new Dotenv ())->loadEnv (dirname (__DIR__ ).'/.env ' );
13
15
14
- $ platform = new OpenAI (HttpClient::create (), getenv ( 'OPENAI_API_KEY ' ) );
16
+ $ platform = new OpenAI (HttpClient::create (), $ _ENV [ 'OPENAI_API_KEY ' ] );
15
17
$ llm = new Gpt ($ platform , Version::gpt4oMini ());
16
18
17
19
$ chain = new Chain ($ llm );
Original file line number Diff line number Diff line change 6
6
use PhpLlm \LlmChain \OpenAI \Model \Gpt ;
7
7
use PhpLlm \LlmChain \OpenAI \Model \Gpt \Version ;
8
8
use PhpLlm \LlmChain \OpenAI \Platform \OpenAI ;
9
+ use Symfony \Component \Dotenv \Dotenv ;
9
10
use Symfony \Component \HttpClient \HttpClient ;
10
11
11
12
require_once dirname (__DIR__ ).'/vendor/autoload.php ' ;
13
+ (new Dotenv ())->loadEnv (dirname (__DIR__ ).'/.env ' );
12
14
13
- $ platform = new OpenAI (HttpClient::create (), getenv ( 'OPENAI_API_KEY ' ) );
15
+ $ platform = new OpenAI (HttpClient::create (), $ _ENV [ 'OPENAI_API_KEY ' ] );
14
16
$ llm = new Gpt ($ platform , Version::o1Preview ());
15
17
16
18
$ prompt = <<<PROMPT
Original file line number Diff line number Diff line change 9
9
use PhpLlm \LlmChain \StructuredOutput \ResponseFormatFactory ;
10
10
use PhpLlm \LlmChain \StructuredOutput \SchemaFactory ;
11
11
use PhpLlm \LlmChain \Tests \StructuredOutput \Data \MathReasoning ;
12
+ use Symfony \Component \Dotenv \Dotenv ;
12
13
use Symfony \Component \HttpClient \HttpClient ;
13
14
use Symfony \Component \Serializer \Encoder \JsonEncoder ;
14
15
use Symfony \Component \Serializer \Normalizer \ObjectNormalizer ;
15
16
use Symfony \Component \Serializer \Serializer ;
16
17
17
18
require_once dirname (__DIR__ ).'/vendor/autoload.php ' ;
19
+ (new Dotenv ())->loadEnv (dirname (__DIR__ ).'/.env ' );
18
20
19
- $ platform = new OpenAI (HttpClient::create (), getenv ( 'OPENAI_API_KEY ' ) );
21
+ $ platform = new OpenAI (HttpClient::create (), $ _ENV [ 'OPENAI_API_KEY ' ] );
20
22
$ llm = new Gpt ($ platform , Version::gpt4oMini ());
21
23
$ responseFormatFactory = new ResponseFormatFactory (SchemaFactory::create ());
22
24
$ serializer = new Serializer ([new ObjectNormalizer ()], [new JsonEncoder ()]);
Original file line number Diff line number Diff line change 10
10
use PhpLlm \LlmChain \ToolBox \ToolAnalyzer ;
11
11
use PhpLlm \LlmChain \ToolBox \ToolBox ;
12
12
use Symfony \Component \Clock \Clock as SymfonyClock ;
13
+ use Symfony \Component \Dotenv \Dotenv ;
13
14
use Symfony \Component \HttpClient \HttpClient ;
14
15
15
16
require_once dirname (__DIR__ ).'/vendor/autoload.php ' ;
17
+ (new Dotenv ())->loadEnv (dirname (__DIR__ ).'/.env ' );
16
18
17
- $ platform = new OpenAI (HttpClient::create (), getenv ( 'OPENAI_API_KEY ' ) );
19
+ $ platform = new OpenAI (HttpClient::create (), $ _ENV [ 'OPENAI_API_KEY ' ] );
18
20
$ llm = new Gpt ($ platform , Version::gpt4oMini ());
19
21
20
22
$ clock = new Clock (new SymfonyClock ());
Original file line number Diff line number Diff line change 9
9
use PhpLlm \LlmChain \ToolBox \Tool \SerpApi ;
10
10
use PhpLlm \LlmChain \ToolBox \ToolAnalyzer ;
11
11
use PhpLlm \LlmChain \ToolBox \ToolBox ;
12
+ use Symfony \Component \Dotenv \Dotenv ;
12
13
use Symfony \Component \HttpClient \HttpClient ;
13
14
14
15
require_once dirname (__DIR__ ).'/vendor/autoload.php ' ;
16
+ (new Dotenv ())->loadEnv (dirname (__DIR__ ).'/.env ' );
15
17
16
18
$ httpClient = HttpClient::create ();
17
- $ platform = new OpenAI ($ httpClient , getenv ( 'OPENAI_API_KEY ' ) );
19
+ $ platform = new OpenAI ($ httpClient , $ _ENV [ 'OPENAI_API_KEY ' ] );
18
20
$ llm = new Gpt ($ platform , Version::gpt4oMini ());
19
21
20
- $ serpApi = new SerpApi ($ httpClient , getenv ( 'SERP_API_KEY ' ) );
22
+ $ serpApi = new SerpApi ($ httpClient , $ _ENV [ 'SERP_API_KEY ' ] );
21
23
$ toolBox = new ToolBox (new ToolAnalyzer (), [$ serpApi ]);
22
24
$ chain = new Chain ($ llm , $ toolBox );
23
25
Original file line number Diff line number Diff line change 9
9
use PhpLlm \LlmChain \ToolBox \Tool \OpenMeteo ;
10
10
use PhpLlm \LlmChain \ToolBox \ToolAnalyzer ;
11
11
use PhpLlm \LlmChain \ToolBox \ToolBox ;
12
+ use Symfony \Component \Dotenv \Dotenv ;
12
13
use Symfony \Component \HttpClient \HttpClient ;
13
14
14
15
require_once dirname (__DIR__ ).'/vendor/autoload.php ' ;
16
+ (new Dotenv ())->loadEnv (dirname (__DIR__ ).'/.env ' );
15
17
16
18
$ httpClient = HttpClient::create ();
17
- $ platform = new OpenAI ($ httpClient , getenv ( 'OPENAI_API_KEY ' ) );
19
+ $ platform = new OpenAI ($ httpClient , $ _ENV [ 'OPENAI_API_KEY ' ] );
18
20
$ llm = new Gpt ($ platform , Version::gpt4oMini ());
19
21
20
22
$ wikipedia = new OpenMeteo ($ httpClient );
Original file line number Diff line number Diff line change 9
9
use PhpLlm \LlmChain \ToolBox \Tool \Wikipedia ;
10
10
use PhpLlm \LlmChain \ToolBox \ToolAnalyzer ;
11
11
use PhpLlm \LlmChain \ToolBox \ToolBox ;
12
+ use Symfony \Component \Dotenv \Dotenv ;
12
13
use Symfony \Component \HttpClient \HttpClient ;
13
14
14
15
require_once dirname (__DIR__ ).'/vendor/autoload.php ' ;
16
+ (new Dotenv ())->loadEnv (dirname (__DIR__ ).'/.env ' );
15
17
16
18
$ httpClient = HttpClient::create ();
17
- $ platform = new OpenAI ($ httpClient , getenv ( 'OPENAI_API_KEY ' ) );
19
+ $ platform = new OpenAI ($ httpClient , $ _ENV [ 'OPENAI_API_KEY ' ] );
18
20
$ llm = new Gpt ($ platform , Version::gpt4oMini ());
19
21
20
22
$ wikipedia = new Wikipedia ($ httpClient );
Original file line number Diff line number Diff line change 9
9
use PhpLlm \LlmChain \ToolBox \Tool \YouTubeTranscriber ;
10
10
use PhpLlm \LlmChain \ToolBox \ToolAnalyzer ;
11
11
use PhpLlm \LlmChain \ToolBox \ToolBox ;
12
+ use Symfony \Component \Dotenv \Dotenv ;
12
13
use Symfony \Component \HttpClient \HttpClient ;
13
14
14
15
require_once dirname (__DIR__ ).'/vendor/autoload.php ' ;
16
+ (new Dotenv ())->loadEnv (dirname (__DIR__ ).'/.env ' );
15
17
16
18
$ httpClient = HttpClient::create ();
17
- $ platform = new OpenAI ($ httpClient , getenv ( 'OPENAI_API_KEY ' ) );
19
+ $ platform = new OpenAI ($ httpClient , $ _ENV [ 'OPENAI_API_KEY ' ] );
18
20
$ llm = new Gpt ($ platform , Version::gpt4oMini ());
19
21
20
22
$ transcriber = new YouTubeTranscriber ($ httpClient );
You can’t perform that action at this time.
0 commit comments