2
2
3
3
PHP library for building LLM-based and AI-based features and applications.
4
4
5
- This library is not a stable yet, but still rather experimental. Feel free to try it out, give feedback, ask questions,
6
- contribute or share your use cases. Abstractions, concepts and interfaces are not final and potentially subject of change.
5
+ This library is not stable yet, but still rather experimental. Feel free to try it out, give feedback, ask questions,
6
+ contribute, or share your use cases. Abstractions, concepts, and interfaces are not final and potentially subject of change.
7
7
8
8
## Requirements
9
9
@@ -21,7 +21,7 @@ When using Symfony Framework, check out the integration bundle [php-llm/llm-chai
21
21
22
22
## Examples
23
23
24
- See [ examples] ( examples ) folder to run example implementations using this library.
24
+ See [ the examples folder ] ( examples ) to run example implementations using this library.
25
25
Depending on the example you need to export different environment variables
26
26
for API keys or deployment configurations or create a ` .env.local ` based on ` .env ` file.
27
27
@@ -34,10 +34,10 @@ For a more sophisticated demo, see the [Symfony Demo Application](https://github
34
34
### Models & Platforms
35
35
36
36
LLM Chain categorizes two main types of models: ** Language Models** and ** Embeddings Models** . On top of that, there are
37
- other models, like text-to-speech, image generation or classification models that are also supported.
37
+ other models, like text-to-speech, image generation, or classification models that are also supported.
38
38
39
- Language Models, like GPT, Claude and Llama, as essential centerpiece of LLM applications
40
- and Embeddings Models as supporting models to provide vector representations of text.
39
+ Language Models, like GPT, Claude, and Llama, as essential centerpiece of LLM applications
40
+ and Embeddings Models as supporting models to provide vector representations of a text.
41
41
42
42
Those models are provided by different ** platforms** , like OpenAI, Azure, Google, Replicate, and others.
43
43
@@ -112,8 +112,8 @@ The second parameter of the `call` method is an array of options, which can be u
112
112
chain, like ` stream ` , ` output_structure ` , or ` response_format ` . This behavior is a combination of features provided by
113
113
the underlying model and platform, or additional features provided by processors registered to the chain.
114
114
115
- Options design for additional features provided by LLM Chain can be found in this documentation. For model and platform
116
- specific options, please refer to the respective documentation.
115
+ Options designed for additional features provided by LLM Chain can be found in this documentation. For model- and
116
+ platform- specific options, please refer to the respective documentation.
117
117
118
118
``` php
119
119
// Chain and MessageBag instantiation
@@ -126,13 +126,15 @@ $response = $chain->call($messages, [
126
126
127
127
#### Code Examples
128
128
129
- 1 . ** Anthropic's Claude** : [ chat-claude-anthropic.php] ( examples/chat-claude-anthropic.php )
130
- 1 . ** OpenAI's GPT with Azure** : [ chat-gpt-azure.php] ( examples/chat-gpt-azure.php )
131
- 1 . ** OpenAI's GPT** : [ chat-gpt-openai.php] ( examples/chat-gpt-openai.php )
132
- 1 . ** OpenAI's o1** : [ chat-o1-openai.php] ( examples/chat-o1-openai.php )
133
- 1 . ** Meta's Llama with Ollama** : [ chat-llama-ollama.php] ( examples/chat-llama-ollama.php )
134
- 1 . ** Meta's Llama with Replicate** : [ chat-llama-replicate.php] ( examples/chat-llama-replicate.php )
135
- 1 . ** Google's Gemini with OpenRouter** : [ chat-gemini-openrouter.php] ( examples/chat-gemini-openrouter.php )
129
+ 1 . [ Anthropic's Claude] ( examples/anthropic/chat.php )
130
+ 1 . [ OpenAI's GPT with Azure] ( examples/azure/chat-gpt.php )
131
+ 1 . [ OpenAI's GPT] ( examples/openai/chat.php )
132
+ 1 . [ OpenAI's o1] ( examples/openai/chat-o1.php )
133
+ 1 . [ Meta's Llama with Azure] ( examples/azure/chat-llama.php )
134
+ 1 . [ Meta's Llama with Ollama] ( examples/ollama/chat-llama.php )
135
+ 1 . [ Meta's Llama with Replicate] ( examples/replicate/chat-llama.php )
136
+ 1 . [ Google's Gemini with Google] ( examples/google/chat.php )
137
+ 1 . [ Google's Gemini with OpenRouter] ( examples/openrouter/chat-gemini.php )
136
138
137
139
### Tools
138
140
@@ -340,14 +342,14 @@ $eventDispatcher->addListener(ToolCallsExecuted::class, function (ToolCallsExecu
340
342
341
343
#### Code Examples (with built-in tools)
342
344
343
- 1 . ** Brave Tool** : [ toolbox-brave.php ] ( examples/toolbox- brave.php )
344
- 1 . ** Clock Tool** : [ toolbox-clock.php ] ( examples/toolbox- clock.php )
345
- 1 . ** Crawler Tool** : [ toolbox-brave.php ] ( examples/toolbox- brave.php )
346
- 1 . ** SerpAPI Tool** : [ toolbox-serpapi.php ] ( examples/toolbox- serpapi.php )
347
- 1 . ** Tavily Tool** : [ toolbox-tavily.php ] ( examples/toolbox- tavily.php )
348
- 1 . ** Weather Tool with Event Listener** : [ toolbox-weather-event.php ] ( examples/toolbox- weather-event.php )
349
- 1 . ** Wikipedia Tool** : [ toolbox-wikipedia.php ] ( examples/toolbox-wikipedia .php )
350
- 1 . ** YouTube Transcriber Tool** : [ toolbox-youtube.php ] ( examples/toolbox-youtube .php ) (with streaming)
345
+ 1 . [ Brave Tool] ( examples/toolbox/ brave.php )
346
+ 1 . [ Clock Tool] ( examples/toolbox/ clock.php )
347
+ 1 . [ Crawler Tool] ( examples/toolbox/ brave.php )
348
+ 1 . [ SerpAPI Tool] ( examples/toolbox/ serpapi.php )
349
+ 1 . [ Tavily Tool] ( examples/toolbox/ tavily.php )
350
+ 1 . [ Weather Tool with Event Listener] ( examples/toolbox/ weather-event.php )
351
+ 1 . [ Wikipedia Tool] ( examples/anthropic/ toolbox.php )
352
+ 1 . [ YouTube Transcriber Tool] ( examples/openai/ toolbox.php ) (with streaming)
351
353
352
354
### Document Embedding, Vector Stores & Similarity Search (RAG)
353
355
@@ -383,7 +385,7 @@ foreach ($entities as $entity) {
383
385
$documents[] = new TextDocument(
384
386
id: $entity->getId(), // UUID instance
385
387
content: $entity->toString(), // Text representation of relevant data for embedding
386
- metadata: new Metadata($entity->toArray()), // Array representation of entity to be stored additionally
388
+ metadata: new Metadata($entity->toArray()), // Array representation of an entity to be stored additionally
387
389
);
388
390
}
389
391
```
@@ -421,8 +423,8 @@ $response = $chain->call($messages);
421
423
422
424
#### Code Examples
423
425
424
- 1. ** MongoDB Store**: [store-mongodb-similarity-search.php ](examples/store-mongodb-similarity-search.php)
425
- 1. ** Pinecone Store**: [store-pinecone-similarity-search.php ](examples/store-pinecone-similarity-search.php)
426
+ 1. [ MongoDB Store](examples/store-mongodb-similarity-search.php)
427
+ 1. [ Pinecone Store](examples/store-pinecone-similarity-search.php)
426
428
427
429
#### Supported Stores
428
430
@@ -442,7 +444,7 @@ by features like **Structured Output** or providing a **Response Format**.
442
444
443
445
#### PHP Classes as Output
444
446
445
- LLM Chain support that use-case by abstracting the hustle of defining and providing schemas to the LLM and converting
447
+ LLM Chain supports that use-case by abstracting the hustle of defining and providing schemas to the LLM and converting
446
448
the response back to PHP objects.
447
449
448
450
To achieve this, a specific chain processor needs to be registered:
@@ -505,8 +507,8 @@ dump($response->getContent()); // returns an array
505
507
506
508
#### Code Examples
507
509
508
- 1. ** Structured Output** ( PHP class): [structured-output-math.php ](examples/structured-output-math.php)
509
- 1. ** Structured Output** (array): [structured-output-clock.php ](examples/structured-output-clock.php)
510
+ 1. [ Structured Output with PHP class)](examples/openai /structured-output-math.php)
511
+ 1. [ Structured Output with array ](examples/openai /structured-output-clock.php)
510
512
511
513
### Response Streaming
512
514
@@ -539,8 +541,8 @@ needs to be used.
539
541
540
542
#### Code Examples
541
543
542
- 1. ** Streaming Claude**: [stream-claude-anthropic.php ](examples/stream-claude- anthropic.php)
543
- 1. ** Streaming GPT**: [stream-gpt-openai.php ](examples/stream-gpt- openai.php)
544
+ 1. [ Streaming Claude](examples/anthropic/stream .php)
545
+ 1. [ Streaming GPT](examples/openai/stream .php)
544
546
545
547
### Image Processing
546
548
@@ -567,8 +569,8 @@ $response = $chain->call($messages);
567
569
568
570
#### Code Examples
569
571
570
- 1. ** Image Description**: [image-describer-binary.php ](examples/image-describer -binary.php) (with binary file )
571
- 1. ** Image Description**: [image-describer-url.php ](examples/image-describer -url.php) (with URL )
572
+ 1. [Binary Image Input with GPT ](examples/openai/ image-input -binary.php)
573
+ 1. [ Image URL Input with GPT ](examples/openai/ image-input -url.php)
572
574
573
575
### Audio Processing
574
576
@@ -592,11 +594,11 @@ $response = $chain->call($messages);
592
594
593
595
#### Code Examples
594
596
595
- 1. ** Audio Description**: [audio-describer.php ](examples/audio-describer .php)
597
+ 1. [ Audio Input with GPT ](examples/openai/ audio-input .php)
596
598
597
599
### Embeddings
598
600
599
- Creating embeddings of word, sentences or paragraphs is a typical use case around the interaction with LLMs and
601
+ Creating embeddings of word, sentences, or paragraphs is a typical use case around the interaction with LLMs, and
600
602
therefore LLM Chain implements a `EmbeddingsModel` interface with various models, see above.
601
603
602
604
The standalone usage results in an `Vector` instance:
@@ -615,8 +617,8 @@ dump($vectors[0]->getData()); // Array of float values
615
617
616
618
#### Code Examples
617
619
618
- 1. ** OpenAI' s Emebddings**: [embeddings-openai.php ](examples /embeddings- openai.php)
619
- 1. ** Voyage' s Embeddings**: [embeddings-voyage.php ](examples/embeddings- voyage.php)
620
+ 1. [ OpenAI' s Emebddings](examples /openai / embeddings .php)
621
+ 1. [ Voyage' s Embeddings](examples/voyage/embeddings .php)
620
622
621
623
### Parallel Platform Calls
622
624
@@ -639,11 +641,11 @@ foreach ($responses as $response) {
639
641
640
642
#### Code Examples
641
643
642
- 1. ** Parallel GPT Calls**: [parallel-chat-gpt.php ](examples/parallel-chat-gpt.php)
643
- 1. ** Parallel Embeddings Calls**: [parallel-embeddings.php ](examples/parallel-embeddings.php)
644
+ 1. [ Parallel GPT Calls](examples/parallel-chat-gpt.php)
645
+ 1. [ Parallel Embeddings Calls](examples/parallel-embeddings.php)
644
646
645
647
> [!NOTE]
646
- > Please be aware that some embeddings models also support batch processing out of the box.
648
+ > Please be aware that some embedding models also support batch processing out of the box.
647
649
648
650
### Input & Output Processing
649
651
@@ -733,7 +735,7 @@ final class MyProcessor implements OutputProcessor, ChainAwareProcessor
733
735
## HuggingFace
734
736
735
737
LLM Chain comes out of the box with an integration for [HuggingFace](https://huggingface.co/) which is a platform for
736
- hosting and sharing all kind of models, including LLMs, embeddings, image generation and classification models.
738
+ hosting and sharing all kinds of models, including LLMs, embeddings, image generation, and classification models.
737
739
738
740
You can just instantiate the Platform with the corresponding HuggingFace bridge and use it with the `task` option:
739
741
```php
@@ -800,7 +802,7 @@ echo $response->getContent().PHP_EOL;
800
802
801
803
#### Code Examples
802
804
803
- 1 . [ Text Generation with TransformersPHP] ( examples/transformers- text-generation.php )
805
+ 1 . [ Text Generation with TransformersPHP] ( examples/transformers/ text-generation.php )
804
806
805
807
## Contributions
806
808
0 commit comments