You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add support for Hugging Face Inference API (#279)
* 1st Commit: Christopher
* 2nd Commit: Claude Desktop with Jetbrains MCP:
> I'm writing a PHP library that is similar to langchain but should also
cover the HuggingFace inference API - like their library.
You can access my terminal and my IDE via tools.
Please have a look at the different tasks that should be available in
src/Bridge/HuggingFace/Task.php and see the example implementation in
examples/huggingface/text-classification.php in combination with the
namespace PhpLlm\LlmChain\Bridge\HuggingFace.
Your task is to implement the response conversion, corresponding DTOs
and examples for all other tasks than text-classification.
* 3rd Commit: Claude Desktop with Jetbrains MCP:
> please have a look at the other examples in the examples/ folder using
audio, image or text input and refactor the ones you just created.
all new example files are located in
/home/christopher/Projects/PHP-LLM/llm-chain/examples/huggingface -
please verify they're working by executing them - and patch bugs if
there are any
* 4th Commit: Claude Desktop with Jetbrains MCP:
> please create an example runner for huggingface examples, based on the
/example file in root directory
* 5th Commit: Christopher making it work.
Copy file name to clipboardExpand all lines: README.md
+53-5
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
# LLM Chain
2
2
3
-
PHP library for building LLM-based features and applications.
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, contribute or share your use cases.
6
-
Abstractions, concepts and interfaces are not final and potentially subject of change.
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.
7
7
8
8
## Requirements
9
9
@@ -25,15 +25,16 @@ See [examples](examples) folder to run example implementations using this librar
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
28
-
To run all examples, use `make run-examples` or `php example`.
28
+
To run all examples, use `make run-examples` or `php example` and `php huggingface` for all HuggingFace related examples.
29
29
30
30
For a more sophisticated demo, see the [Symfony Demo Application](https://github.com/php-llm/symfony-demo).
31
31
32
32
## Basic Concepts & Usage
33
33
34
34
### Models & Platforms
35
35
36
-
LLM Chain categorizes two main types of models: **Language Models** and **Embeddings Models**.
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
38
38
39
Language Models, like GPT, Claude and Llama, as essential centerpiece of LLM applications
39
40
and Embeddings Models as supporting models to provide vector representations of text.
@@ -71,6 +72,8 @@ $embeddings = new Embeddings();
71
72
* Other Models
72
73
*[OpenAI's Dall·E](https://platform.openai.com/docs/guides/image-generation) with [OpenAI](https://platform.openai.com/docs/overview) as Platform
73
74
*[OpenAI's Whisper](https://platform.openai.com/docs/guides/speech-to-text) with [OpenAI](https://platform.openai.com/docs/overview) and [Azure](https://learn.microsoft.com/azure/ai-services/openai/concepts/models) as Platform
75
+
* All models provided by [HuggingFace](https://huggingface.co/) can be listed with `make huggingface-models`
76
+
And more filtered with `php examples/huggingface/_model-listing.php --provider=hf-inference --task=object-detection`
74
77
75
78
See [issue #28](https://github.com/php-llm/llm-chain/issues/28) for planned support of other models and platforms.
76
79
@@ -725,6 +728,51 @@ final class MyProcessor implements OutputProcessor, ChainAwareProcessor
725
728
}
726
729
```
727
730
731
+
## HuggingFace
732
+
733
+
LLM Chain comes out of the box with an integration for [HuggingFace](https://huggingface.co/) which is a platform for
734
+
hosting and sharing all kind of models, including LLMs, embeddings, image generation and classification models.
735
+
736
+
You can just instantiate the Platform with the corresponding HuggingFace bridge and use it with the `task` option:
737
+
```php
738
+
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
739
+
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
0 commit comments