Skip to content

Commit 7b145d8

Browse files
committed
Initial release
1 parent e7523ce commit 7b145d8

File tree

91 files changed

+3432
-165
lines changed

Some content is hidden

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

91 files changed

+3432
-165
lines changed

Diff for: .github/CONTRIBUTING.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
Please read and understand the contribution guide before creating an issue or pull request.
6+
7+
## Etiquette
8+
9+
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10+
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11+
extremely unfair for them to suffer abuse or anger for their hard work.
12+
13+
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14+
world that developers are civilized and selfless people.
15+
16+
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17+
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18+
19+
## Viability
20+
21+
When requesting or submitting new features, first consider whether it might be useful to others. Open
22+
source projects are used by many developers, who may have entirely different needs to your own. Think about
23+
whether or not your feature is likely to be used by other users of the project.
24+
25+
## Procedure
26+
27+
Before filing an issue:
28+
29+
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30+
- Check to make sure your feature suggestion isn't already present within the project.
31+
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32+
- Check the pull requests tab to ensure that the feature isn't already in progress.
33+
34+
Before submitting a pull request:
35+
36+
- Check the codebase to ensure that your feature doesn't already exist.
37+
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38+
39+
## Requirements
40+
41+
If the project maintainer has any additional requirements, you will find them listed here.
42+
43+
- **Pint Coding Standard** - The easiest way to apply the conventions is to install [Laravel Pint](https://laravel.com/docs/11.x/pint).
44+
45+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46+
47+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48+
49+
- **Consider our release cycle** - We try to follow [](http://semver.org/). Randomly breaking public APIs is not an option.
50+
51+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52+
53+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

Diff for: .github/SECURITY.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Reporting Security Issues
2+
If you believe you have found a security vulnerability in Prism, we encourage you to let us know right away.
3+
4+
We will investigate all legitimate reports and do our best to quickly fix the problem.
5+
6+
Email `[email protected]` to disclose any security vulnerabilities.

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ composer.lock
33
/build/
44
task/
55
.idea/
6+
scratch
7+
phpunit.xml

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 TJ MIller
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+46-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,51 @@
22

33
# Prism
44

5-
Prism makes it easier to work with LLMs by offering a consistent integration
6-
method for your app. This way, you can focus on developing outstanding AI
5+
Prism is a powerful Laravel package for integrating Large Language Models (LLMs) into your applications. It provides a fluent interface for generating text, handling multi-step conversations, and utilizing tools with various AI providers. This way, you can focus on developing outstanding AI
76
applications for your users without getting lost in the technical intricacies.
87

9-
## Generating Text
8+
Official documentation can be found at [prism.echolabs.dev](https://prism.echolabs.dev).
9+
10+
## Installation
11+
12+
### Step 1: Composer Installation
13+
14+
First, let's add Prism to your project using Composer. Open your terminal, navigate to your project directory, and run:
15+
16+
```shell
17+
composer require echolabsdev/prism
18+
```
19+
20+
This command will download Prism and its dependencies into your project.
21+
22+
### Step 2: Publish the Configuration
23+
24+
Prism comes with a configuration file that you'll want to customize. Publish it to your config directory by running:
25+
26+
```shell
27+
php artisan vendor:publish --tag=prism-config
28+
```
29+
30+
This will create a new file at `config/prism.php`. We'll explore how to configure Prism in the next section.
31+
32+
## Usage
33+
34+
```php
35+
<?php
36+
37+
$response = Prism::using('anthropic', 'claude-3-5-sonnet-20240620')
38+
->generateText()
39+
->withSystemMessage(view('prompts.nyx'))
40+
->withPrompt('Explain quantum computing to a 5-year-old.')();
41+
42+
echo $response->text;
43+
```
44+
45+
## Authors
46+
47+
This library is created by [TJ Miller](https://tjmiller.me) with contributions from the [Open Source Community](https://github.com/vercel/ai/graphs/contributors).
48+
49+
## License
50+
51+
The MIT License (MIT). Please see [License File](LICENSE) for more information.
52+

Diff for: bin/git-hooks/formatting

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/usr/bin/env bash
22

3-
_print() {
3+
_header() {
44
printf "\e[38;5;4m%s\e[0m\n" "$1"
55
}
66

77
main() {
88
files_before_format=$(git diff --name-only --diff-filter=d)
99

10-
_print "Running pint..."
10+
_header "Running pint..."
1111
vendor/bin/pint --dirty
1212

13-
_print "Running rector..."
13+
_header "Running rector..."
1414
vendor/bin/rector process --no-diffs
1515

1616
files_after_format=$(git diff --name-only --diff-filter=d)
@@ -19,7 +19,8 @@ main() {
1919
files_fixed_by_format=$(comm -13 <(sort <<<"$files_before_format") <(sort <<<"$files_after_format"))
2020

2121
# Re-stage files fixed by pint
22-
_print "Re-staging changed files..."
22+
_header "Re-staging changed files..."
23+
for f in $files_fixed_by_format; do echo "Re-staging: $f"; done || exit
2324
for f in $files_fixed_by_format; do git add "$f"; done || exit
2425
}
2526

Diff for: composer.json

+44-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "echolabs/prism",
3-
"description": "AI",
2+
"name": "echolabsdev/prism",
3+
"description": "A powerful Laravel package for integrating Large Language Models (LLMs) into your applications.",
44
"type": "library",
55
"license": "MIT",
66
"autoload": {
@@ -15,6 +15,7 @@
1515
}
1616
],
1717
"require": {
18+
"php": "^8.3",
1819
"laravel/framework": "^11.0"
1920
},
2021
"config": {
@@ -25,22 +26,33 @@
2526
}
2627
},
2728
"require-dev": {
28-
"pestphp/pest": "^2.34",
29+
"pestphp/pest": "^3.0",
2930
"laravel/pint": "^1.14",
3031
"phpstan/phpstan": "^1.11",
31-
"pestphp/pest-plugin-arch": "^2.7",
32-
"pestphp/pest-plugin-laravel": "^2.4",
32+
"pestphp/pest-plugin-arch": "^3.0",
33+
"pestphp/pest-plugin-laravel": "^3.0",
3334
"phpstan/extension-installer": "^1.3",
3435
"phpstan/phpstan-deprecation-rules": "^1.2",
3536
"rector/rector": "^1.1",
36-
"projektgopher/whisky": "^0.7.0"
37+
"projektgopher/whisky": "^0.7.0",
38+
"orchestra/testbench": "^9.4",
39+
"mockery/mockery": "^1.6"
3740
},
3841
"autoload-dev": {
3942
"psr-4": {
40-
"Tests\\": "tests/"
43+
"Tests\\": "tests/",
44+
"Workbench\\App\\": "workbench/app/",
45+
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
46+
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
4147
}
4248
},
4349
"scripts": {
50+
"post-install-cmd": [
51+
"whisky update"
52+
],
53+
"post-update-cmd": [
54+
"whisky update"
55+
],
4456
"post-autoload-dump": [
4557
"@clear",
4658
"@prepare"
@@ -54,6 +66,31 @@
5466
],
5567
"test": [
5668
"@php vendor/bin/pest"
69+
],
70+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
71+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
72+
"build": "@php vendor/bin/testbench workbench:build --ansi",
73+
"serve": [
74+
"Composer\\Config::disableProcessTimeout",
75+
"@build",
76+
"@php vendor/bin/testbench serve --ansi"
77+
],
78+
"lint": [
79+
"@php vendor/bin/pint --ansi",
80+
"@php vendor/bin/phpstan analyse --verbose --ansi"
81+
],
82+
"toc": [
83+
"markdown-toc -i README.md"
5784
]
85+
},
86+
"extra": {
87+
"laravel": {
88+
"providers": [
89+
"EchoLabs\\Prism\\PrismServiceProvider"
90+
],
91+
"aliases": {
92+
"PrismServer": "EchoLabs\\Prism\\Facades\\PrismServer"
93+
}
94+
}
5895
}
5996
}

Diff for: config/prism.php

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

33
return [
4+
'prism_server' => [
5+
'enabled' => env('PRISM_SERVER_ENABLED', true),
6+
],
47
'providers' => [
58
'openai' => [
69
'driver' => 'openai',
@@ -12,5 +15,9 @@
1215
'api_key' => env('ANTHROPIC_API_KEY'),
1316
'version' => env('ANTHROPIC_API_VERSION', '2023-06-01'),
1417
],
18+
'ollama' => [
19+
'driver' => 'openai',
20+
'url' => env('OLLAMA_URL', 'http://localhost:11434/v1'),
21+
],
1522
],
1623
];

Diff for: docs/images/prism-sever-open-webui.png

289 KB
Loading

Diff for: phpunit.xml

-18
This file was deleted.

Diff for: ray.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/*
55
* This settings controls whether data should be sent to Ray.
66
*/
7-
'enable' => $_ENV['RAY_ENABLED'] ?? false,
7+
'enable' => true,
88

99
/*
1010
* The host used to communicate with the Ray app.
@@ -16,7 +16,7 @@
1616
*/
1717
// 'port' => 23517,
1818
// Buggerator config
19-
'port' => 8000,
19+
'port' => 8001,
2020

2121
/*
2222
* Absolute base path for your sites or projects in Homestead, Vagrant, Docker, or another remote development server.

Diff for: src/Concerns/HandlesToolCalls.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace EchoLabs\Prism\Concerns;
6+
7+
use EchoLabs\Prism\Exceptions\PrismException;
8+
use EchoLabs\Prism\Tool;
9+
use EchoLabs\Prism\ValueObjects\ToolCall;
10+
use Illuminate\Support\ItemNotFoundException;
11+
use Illuminate\Support\MultipleItemsFoundException;
12+
use Throwable;
13+
14+
trait HandlesToolCalls
15+
{
16+
/**
17+
* @param array<int, Tool> $tools
18+
*/
19+
protected function handleToolCall(array $tools, ToolCall $toolCall): string
20+
{
21+
try {
22+
/** @var Tool $tool */
23+
$tool = collect($tools)
24+
->sole(fn (Tool $tool): bool => $tool->name() === $toolCall->name);
25+
26+
return call_user_func_array($tool->handle(...), $toolCall->arguments());
27+
} catch (ItemNotFoundException $e) {
28+
throw PrismException::toolNotFound($toolCall, $e);
29+
} catch (MultipleItemsFoundException $e) {
30+
throw PrismException::multipleToolsFound($toolCall, $e);
31+
} catch (Throwable $e) {
32+
throw PrismException::toolCallFailed($toolCall, $e);
33+
}
34+
}
35+
}

Diff for: src/Concerns/HasDriver.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace EchoLabs\Prism\Concerns;
6+
7+
use EchoLabs\Prism\Contracts\Driver;
8+
9+
trait HasDriver
10+
{
11+
protected Driver $driver;
12+
13+
public function using(string $provider, string $model): self
14+
{
15+
$this->driver = app('prism-manager')->resolve($provider);
16+
$this->driver->usingModel($model);
17+
18+
return $this;
19+
}
20+
}

Diff for: src/Concerns/HasModel.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace EchoLabs\Prism\Concerns;
6+
7+
trait HasModel
8+
{
9+
protected string $model;
10+
}

0 commit comments

Comments
 (0)