Skip to content

Commit 3ae50b8

Browse files
committed
Initial commit
0 parents  commit 3ae50b8

36 files changed

Lines changed: 2229 additions & 0 deletions

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml,*.yaml,*.neon]
15+
indent_style = space
16+
indent_size = 2

.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* text=auto
2+
3+
/.editorconfig export-ignore
4+
/.gitattributes export-ignore
5+
/.gitignore export-ignore
6+
/.github export-ignore
7+
/.markdownlint.json export-ignore
8+
/phpunit.xml.dist export-ignore
9+
/phpstan.dist.neon export-ignore
10+
/README.md export-ignore
11+
/ecs.php export-ignore
12+
/rector.php export-ignore
13+
/tests export-ignore

.github/dependabot.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "composer"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
labels:
8+
- "dependencies"
9+
- "composer"
10+
versioning-strategy: "widen"
11+
open-pull-requests-limit: 5
12+
13+
- package-ecosystem: "github-actions"
14+
directory: "/"
15+
schedule:
16+
interval: "daily"
17+
labels:
18+
- "dependencies"
19+
- "github-actions"

.github/workflows/run-tests.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Tests
2+
3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
7+
on: [push]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: true
18+
matrix:
19+
os: [ubuntu-latest, windows-latest]
20+
php: [8.3, 8.4]
21+
stability: [prefer-lowest, prefer-stable]
22+
23+
name: PHP${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: ${{ matrix.php }}
33+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
34+
coverage: pcov
35+
36+
- name: Setup problem matchers
37+
run: |
38+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
39+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
40+
41+
- name: Install dependencies
42+
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction
43+
44+
- name: Execute tests with mutation
45+
if: ${{ matrix.os == 'ubuntu-latest' }}
46+
run: vendor/bin/pest --colors=always --mutate --parallel --min=80
47+
48+
- name: Execute tests
49+
if: ${{ matrix.os != 'ubuntu-latest' }}
50+
run: vendor/bin/pest --colors=always
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Static Analysis
2+
3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
7+
on: [push]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
phpstan:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup PHP
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: 8.3
25+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
26+
27+
- name: Get Composer Cache Directory
28+
id: composer-cache
29+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
30+
31+
- name: Cache Composer dependencies
32+
uses: actions/cache@v4
33+
with:
34+
path: ${{ steps.composer-cache.outputs.dir }}
35+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
36+
restore-keys: |
37+
${{ runner.os }}-composer-
38+
39+
- name: Install dependencies
40+
run: composer install --prefer-dist --no-interaction --no-progress
41+
42+
- name: Cache phpstan results
43+
uses: actions/cache@v4
44+
with:
45+
path: .phpstan-cache
46+
key: "result-cache-${{ github.run_id }}" # always write a new cache
47+
restore-keys: |
48+
result-cache-
49+
50+
- name: Run phpstan
51+
run: vendor/bin/phpstan analyse -c phpstan.dist.neon --no-progress --error-format=github
52+
53+
type-coverage:
54+
runs-on: ubuntu-latest
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@v4
58+
59+
- name: Setup PHP
60+
uses: shivammathur/setup-php@v2
61+
with:
62+
php-version: 8.3
63+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
64+
65+
- name: Get Composer Cache Directory
66+
id: composer-cache
67+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
68+
69+
- name: Cache Composer dependencies
70+
uses: actions/cache@v4
71+
with:
72+
path: ${{ steps.composer-cache.outputs.dir }}
73+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
74+
restore-keys: |
75+
${{ runner.os }}-composer-
76+
77+
- name: Install dependencies
78+
run: composer install --prefer-dist --no-interaction --no-progress
79+
80+
- name: Check type coverage
81+
run: vendor/bin/pest --type-coverage --min=100

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
vendor
2+
composer.lock
3+
.vscode
4+
.env
5+
.DS_Store
6+
.phpstan-cache
7+
coverage

.markdownlint.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"default": true,
3+
"MD013": false,
4+
"MD033": false,
5+
"MD041": false,
6+
"no-hard-tabs": true
7+
}

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Sean Tymon <tymon148@gmail.com>
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
13+
all 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
21+
THE SOFTWARE.

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# A unified way to get AI model info from various providers
2+
3+
[![Latest Version](https://img.shields.io/packagist/v/cortexphp/model-info.svg?style=flat-square&logo=composer)](https://packagist.org/packages/cortexphp/model-info)
4+
![GitHub Actions Test Workflow Status](https://img.shields.io/github/actions/workflow/status/cortexphp/model-info/run-tests.yml?style=flat-square&logo=github)
5+
![GitHub License](https://img.shields.io/github/license/cortexphp/model-info?style=flat-square&logo=github)
6+
7+
## Features
8+
9+
- Get model information from various AI providers (Ollama, LiteLLM)
10+
- PSR-16 Simple Cache support for caching model information
11+
- Retrieve available models for supported providers
12+
- Get detailed model information for specific models
13+
- Extensible provider system
14+
15+
## Requirements
16+
17+
- PHP 8.3+
18+
19+
## Installation
20+
21+
```bash
22+
composer require cortexphp/model-info
23+
```
24+
25+
## Usage
26+
27+
```php
28+
use Cortex\ModelInfo\ModelInfoFactory;
29+
use Cortex\ModelInfo\Enums\ModelProvider;
30+
31+
// Create a new factory instance
32+
$factory = new ModelInfoFactory();
33+
34+
// Get all available models for a provider
35+
$models = $factory->getModels(ModelProvider::Ollama);
36+
37+
// Get information about a specific model
38+
$modelInfo = $factory->getModelInfo(ModelProvider::Ollama, 'llama3.1');
39+
40+
```
41+
42+
```php
43+
44+
// Using with custom cache implementation
45+
use Psr\SimpleCache\CacheInterface;
46+
47+
$factory = new ModelInfoFactory(
48+
cache: $yourPsr16CacheImplementation
49+
);
50+
51+
// Force fetch (bypass cache) with exception handling
52+
try {
53+
$models = $factory->getModelsOrFail(ModelProvider::LiteLLM);
54+
$modelInfo = $factory->getModelInfoOrFail(ModelProvider::LiteLLM, 'gpt-4');
55+
} catch (ModelInfoException $e) {
56+
// Handle exception
57+
}
58+
59+
// Clear the cache
60+
$factory->flushCache();
61+
```
62+
63+
## Credits
64+
65+
- [Sean Tymon](https://github.com/tymondesigns)
66+
- [All Contributors](../../contributors)
67+
68+
## License
69+
70+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "cortexphp/model-info",
3+
"description": "A unified way to get AI model info from various providers",
4+
"keywords": [
5+
"llm",
6+
"ai",
7+
"model-info",
8+
"cortex"
9+
],
10+
"homepage": "https://github.com/cortexphp/model-info",
11+
"type": "library",
12+
"license": "MIT",
13+
"authors": [
14+
{
15+
"name": "Sean Tymon",
16+
"email": "tymon148@gmail.com",
17+
"role": "Developer"
18+
}
19+
],
20+
"require": {
21+
"php": "^8.3",
22+
"psr-discovery/cache-implementations": "^1.2",
23+
"psr-discovery/container-implementations": "^1.2",
24+
"psr-discovery/http-client-implementations": "^1.4",
25+
"psr-discovery/http-factory-implementations": "^1.2"
26+
},
27+
"require-dev": {
28+
"guzzlehttp/guzzle": "^7.9",
29+
"pestphp/pest": "^3.0",
30+
"pestphp/pest-plugin-type-coverage": "^3.2",
31+
"phpstan/phpstan": "^2.0",
32+
"phpstan/phpstan-strict-rules": "^2.0",
33+
"rector/rector": "^2.0",
34+
"symplify/easy-coding-standard": "^12.5"
35+
},
36+
"autoload": {
37+
"psr-4": {
38+
"Cortex\\ModelInfo\\": "src/"
39+
}
40+
},
41+
"autoload-dev": {
42+
"psr-4": {
43+
"Cortex\\ModelInfo\\Tests\\": "tests/"
44+
}
45+
},
46+
"scripts": {
47+
"test": "pest",
48+
"ecs": "ecs check --fix",
49+
"rector": "rector process",
50+
"stan": "phpstan analyse",
51+
"type-coverage": "pest --type-coverage --min=100",
52+
"format": [
53+
"@rector",
54+
"@ecs"
55+
],
56+
"check": [
57+
"@format",
58+
"@test",
59+
"@stan",
60+
"@type-coverage"
61+
]
62+
},
63+
"config": {
64+
"sort-packages": true,
65+
"allow-plugins": {
66+
"pestphp/pest-plugin": true
67+
}
68+
},
69+
"minimum-stability": "dev",
70+
"prefer-stable": true
71+
}

0 commit comments

Comments
 (0)