Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sixlive committed Sep 21, 2024
0 parents commit e7523ce
Show file tree
Hide file tree
Showing 27 changed files with 662 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Formatting

on:
push:
paths:
- "**.php"
- ".github/workflows/formatting.yml"

env:
phpv: 8.3

jobs:
formatting:
name: Formatting
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.phpv }}
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v3

- name: Run Pint
run: |
vendor/bin/pint
git diff --exit-code
- name: Run Rector
run: |
vendor/bin/rector
git diff --exit-code
31 changes: 31 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: PHPStan

on:
push:
paths:
- "**.php"
- "phpstan.neon.dist"
- ".github/workflows/phpstan.yml"

env:
phpv: 8.3

jobs:
phpstan:
name: phpstan
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.phpv }}
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v3

- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
55 changes: 55 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Tests

on:
push:
paths:
- "**.php"
- ".github/workflows/tests.yml"
- "phpunit.xml.dist"
- "composer.json"
- "composer.lock"

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.3]
laravel: [11.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
carbon: ^2.63

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.os == 'windows-latest' && '^^^' || '' }}${{ matrix.carbon }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: List Installed Dependencies
run: composer show -D

- name: Execute tests
run: vendor/bin/pest --ci
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/vendor/
composer.lock
/build/
task/
.idea/
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"pest_2.34.7","defects":[],"times":{"P\\Tests\\MessageTest::__pest_evaluable_it_can_be_created_for_a_each_role#(EchoLabs\\Sparkle\\Enums\\Role Enum (USER, 'user'))":0.001,"P\\Tests\\MessageTest::__pest_evaluable_it_can_be_created_for_a_each_role#(EchoLabs\\Sparkle\\Enums\\Role Enum (SYSTEM, 'system'))":0,"P\\Tests\\MessageTest::__pest_evaluable_it_can_be_created_for_a_each_role#(EchoLabs\\Sparkle\\Enums\\Role Enum (ASSISTANT, 'assistant'))":0}}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
![](docs/images/prism-banner.webp)

# Prism

Prism makes it easier to work with LLMs by offering a consistent integration
method for your app. This way, you can focus on developing outstanding AI
applications for your users without getting lost in the technical intricacies.

## Generating Text
27 changes: 27 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# https://taskfile.dev

version: "3"

tasks:
setup:
cmds:
- composer install
sources:
- composer.json
- composer.lock
generates:
- vendor/autoload.php

push:
cmds:
- git remote | xargs -I{} git push {{.CLI_ARGS}} {}

format:
cmds:
- vendor/bin/rector
- vendor/bin/pint

validate:
cmds:
- vendor/bin/pest --compact
- vendor/bin/phpstan
26 changes: 26 additions & 0 deletions bin/git-hooks/formatting
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

_print() {
printf "\e[38;5;4m%s\e[0m\n" "$1"
}

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

_print "Running pint..."
vendor/bin/pint --dirty

_print "Running rector..."
vendor/bin/rector process --no-diffs

files_after_format=$(git diff --name-only --diff-filter=d)

# Find files fixed by pint by comparing file lists before and after pint run
files_fixed_by_format=$(comm -13 <(sort <<<"$files_before_format") <(sort <<<"$files_after_format"))

# Re-stage files fixed by pint
_print "Re-staging changed files..."
for f in $files_fixed_by_format; do git add "$f"; done || exit
}

main "$@"
59 changes: 59 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "echolabs/prism",
"description": "AI",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"EchoLabs\\Prism\\": "src/"
}
},
"authors": [
{
"name": "TJ Miller",
"email": "hello@echolabs.dev"
}
],
"require": {
"laravel/framework": "^11.0"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
},
"require-dev": {
"pestphp/pest": "^2.34",
"laravel/pint": "^1.14",
"phpstan/phpstan": "^1.11",
"pestphp/pest-plugin-arch": "^2.7",
"pestphp/pest-plugin-laravel": "^2.4",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.2",
"rector/rector": "^1.1",
"projektgopher/whisky": "^0.7.0"
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"@clear",
"@prepare"
],
"phpstan": [
"phpstan analyse -c phpstan.neon.dist"
],
"format": [
"pint",
"rector process --no-diffs"
],
"test": [
"@php vendor/bin/pest"
]
}
}
16 changes: 16 additions & 0 deletions config/prism.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

return [
'providers' => [
'openai' => [
'driver' => 'openai',
'url' => env('OPENAI_URL', 'https://api.openai.com/v1'),
'api_key' => env('OPENAI_API_KEY'),
],
'anthropic' => [
'driver' => 'anthropic',
'api_key' => env('ANTHROPIC_API_KEY'),
'version' => env('ANTHROPIC_API_VERSION', '2023-06-01'),
],
],
];
Binary file added docs/images/prism-banner.webp
Binary file not shown.
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 8
paths:
- src
tmpDir: build/phpstan
reportUnmatchedIgnoredErrors: true
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./app</directory>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
17 changes: 17 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
35 changes: 35 additions & 0 deletions ray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

return [
/*
* This settings controls whether data should be sent to Ray.
*/
'enable' => $_ENV['RAY_ENABLED'] ?? false,

/*
* The host used to communicate with the Ray app.
*/
'host' => 'localhost',

/*
* The port number used to communicate with the Ray app.
*/
// 'port' => 23517,
// Buggerator config
'port' => 8000,

/*
* Absolute base path for your sites or projects in Homestead, Vagrant, Docker, or another remote development server.
*/
'remote_path' => null,

/*
* Absolute base path for your sites or projects on your local computer where your IDE or code editor is running on.
*/
'local_path' => null,

/*
* When this setting is enabled, the package will not try to format values sent to Ray.
*/
'always_send_raw_values' => false,
];
26 changes: 26 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return RectorConfig::configure()
->withParallel()
->withPaths([
__DIR__.'/src',
__DIR__.'/tests',
])
->withRules([
InlineConstructorDefaultToPropertyRector::class,
])
->withSets([
LevelSetList::UP_TO_PHP_83,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
SetList::EARLY_RETURN,
SetList::TYPE_DECLARATION,
SetList::PRIVATIZATION,
]);
Empty file added src/.gitkeep
Empty file.
7 changes: 7 additions & 0 deletions src/Contracts/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

namespace EchoLabs\Prism\Contracts;

interface Provider {}
Loading

0 comments on commit e7523ce

Please sign in to comment.