Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the module rulling #1

Merged
merged 17 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#### Link to ticket

Please add a link to the ticket being addressed by this change.

#### Description

Please include a short description of the suggested change and the reasoning behind the approach you have chosen.

#### Screenshot of the result

If your change affects the user interface you should include a screenshot of the result with the pull request.

#### Checklist

- [ ] My code passes our static analysis suite.
- [ ] My code passes our continuous integration process.

If your code does not pass all the requirements on the checklist you have to add a comment explaining why this change
should be exempt from the list.

#### Additional comments or questions

If you have any further comments or questions for the reviewer please add them here.
154 changes: 154 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
on: pull_request
name: Review
jobs:
changelog:
runs-on: ubuntu-latest
name: Changelog should be updated
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Git fetch
run: git fetch

- name: Check that changelog has been updated.
run: git diff --exit-code origin/${{ github.base_ref }} -- CHANGELOG.md && exit 1 || exit 0

test-composer-files:
name: Validate composer
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.3' ]
dependency-version: [ prefer-lowest, prefer-stable ]
steps:
- uses: actions/checkout@master

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: json
coverage: none
tools: composer:v2

# https://github.com/shivammathur/setup-php#cache-composer-dependencies
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Validate composer files
run: |
composer validate --strict composer.json
# Check that dependencies resolve.
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

php-coding-standards:
name: PHP coding standards
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.3' ]
steps:
- uses: actions/checkout@master

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: json
coverage: none
tools: composer:v2

# https://github.com/shivammathur/setup-php#cache-composer-dependencies
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Dependencies
run: |
composer install --no-interaction --no-progress

- name: PHPCS
run: |
composer coding-standards-check/phpcs

php-code-analysis:
name: PHP code analysis
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.3' ]
steps:
- uses: actions/checkout@master

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: json
coverage: none
tools: composer:v2
# https://github.com/shivammathur/setup-php#cache-composer-dependencies

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Code analysis
run: |
./scripts/code-analysis

markdownlint:
runs-on: ubuntu-latest
name: markdownlint
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache yarn packages
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Yarn install
uses: actions/setup-node@v2
with:
node-version: '20'
- run: yarn install

- name: markdownlint
run: yarn coding-standards-check/markdownlint
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor
composer.lock
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- markdownlint-disable MD024 -->
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- First version of the module

[Unreleased]: https://github.com/itk-dev/llm_services/compare/develop...HEAD
64 changes: 64 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "itkdev/llm_services",
"type": "drupal-module",
"description": "Drupal large language module service integration module",
"minimum-stability": "dev",
"prefer-stable": true,
"license": "EUPL-1.2",
"repositories": {
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
},
"assets": {
"type": "composer",
"url": "https://asset-packagist.org"
}
},
"require": {
"php": "^8.3",
"openai-php/client": "^0.8.5",
"theodo-group/llphant": "^0.6.10"
},
"require-dev": {
"drupal/coder": "^8.3",
"mglaman/phpstan-drupal": "^1.2",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.2",
"vincentlanglet/twig-cs-fixer": "^2.9"
},
"extra" : {
"composer-exit-on-patch-failure": false,
"enable-patching" : true,
"patches": {
}
},
"scripts": {
"code-analysis/phpstan": [
"phpstan analyse"
],
"code-analysis": [
"@code-analysis/phpstan"
],
"coding-standards-check/phpcs": [
"phpcs --standard=phpcs.xml.dist"
],
"coding-standards-check": [
"@coding-standards-check/phpcs"
],
"coding-standards-apply/phpcs": [
"phpcbf --standard=phpcs.xml.dist"
],
"coding-standards-apply": [
"@coding-standards-apply/phpcs"
]
},
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"php-http/discovery": true
}
}
}
28 changes: 28 additions & 0 deletions drush.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
llm.service.completion.command:
class: Drupal\llm_services\Commands\ModelCompletionCommand
arguments:
- '@plugin.manager.llm_services'
tags:
- { name: console.command }

llm.service.install.command:
class: Drupal\llm_services\Commands\ProviderInstallCommand
arguments:
- '@plugin.manager.llm_services'
tags:
- { name: console.command }

llm.service.list.command:
class: Drupal\llm_services\Commands\ProviderListCommand
arguments:
- '@plugin.manager.llm_services'
tags:
- { name: console.command }

llm.service.char.command:
class: Drupal\llm_services\Commands\ModelChatCommand
arguments:
- '@plugin.manager.llm_services'
tags:
- { name: console.command }
5 changes: 5 additions & 0 deletions llm_services.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: "Large language model services"
description: 'Large language module services to communicate with the models.'
type: module
core_version_requirement: ^10
configure: llm_services.plugin_settings_local_tasks
5 changes: 5 additions & 0 deletions llm_services.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
llm_services.admin_settings:
title: 'LLM services settings'
parent: system.admin_config_system
description: 'Settings for the LLM services'
route_name: llm_services.plugin_settings_local_tasks
5 changes: 5 additions & 0 deletions llm_services.links.task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
llm_services.plugin_settings_tasks:
title: 'LLM services settings'
route_name: llm_services.plugin_settings_local_tasks
base_route: llm_services.plugin_settings_local_tasks
deriver: Drupal\llm_services\Plugin\Derivative\LocalTask
8 changes: 8 additions & 0 deletions llm_services.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
llm_services.plugin_settings_local_tasks:
path: '/admin/config/llm_services/settings/{type}'
defaults:
_controller: '\Drupal\llm_services\Controller\LocalTasksController::dynamicTasks'
_title: 'LLM services settings'
type: ''
requirements:
_permission: 'administer site'
6 changes: 6 additions & 0 deletions llm_services.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
plugin.manager.llm_services:
class: Drupal\llm_services\Plugin\LLModelProviderManager
parent: default_plugin_manager
arguments:
- '@config.factory'
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"license": "UNLICENSED",
"private": true,
"devDependencies": {
"markdownlint-cli": "^0.32.2"
},
"scripts": {
"coding-standards-check/markdownlint": "yarn markdownlint --ignore LICENSE.md --ignore vendor --ignore node_modules '*.md' 'modules/llm_services/**/*.md'",
"coding-standards-check": "yarn coding-standards-check/markdownlint",
"coding-standards-apply/markdownlint": "yarn markdownlint --ignore LICENSE.md --ignore vendor --ignore node_modules '*.md' 'modules/llm_services/**/*.md' --fix",
"coding-standards-apply": "yarn coding-standards-apply/markdownlint"
}
}
23 changes: 23 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="PHP_CodeSniffer">
<description>LLM services PHP Code Sniffer configuration</description>

<file>.</file>
<exclude-pattern>vendor/</exclude-pattern>
<exclude-pattern>node_modules/</exclude-pattern>

<!-- Show progress of the run -->
<arg value="p"/>

<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,yml"/>
<config name="drupal_core_version" value="9"/>


<rule ref="Drupal">
<!-- We want to be able to use "package" and "version" in our custom modules -->
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Project"/>
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Version"/>
</rule>

<rule ref="DrupalPractice"/>
</ruleset>
31 changes: 31 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
parameters:
level: 6
paths:
- ./
excludePaths:
# @see https://github.com/mglaman/drupal-check/issues/261#issuecomment-1030141772/
- vendor
- '*/node_modules/*'
ignoreErrors:
# This is how drupal works....
- '#Unsafe usage of new static\(\).#'
- '#\Drupal calls should be avoided in classes, use dependency injection instead#'
- '#getEditableConfigNames\(\) return type has no value type specified in iterable type array#'
- '#buildForm\(\) has parameter \$form with no value type specified in iterable type array.#'
- '#buildForm\(\) return type has no value type specified in iterable type array.#'
- '#validateForm\(\) has parameter \$form with no value type specified in iterable type array.#'
- '#submitForm\(\) has parameter \$form with no value type specified in iterable type array.#'
- '#getDerivativeDefinitions\(\) has parameter \$base_plugin_definition with no value type specified in iterable type array.#'
- '#getDerivativeDefinitions\(\) return type has no value type specified in iterable type array.#'
- '#__construct\(\) has parameter \$configuration with no value type specified in iterable type array.#'
- '#getConfiguration\(\) return type has no value type specified in iterable type array.#'
- '#setConfiguration\(\) has parameter \$configuration with no value type specified in iterable type array.#'
- '#buildConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#'
- '#buildConfigurationForm\(\) return type has no value type specified in iterable type array.#'
- '#validateConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#'
- '#submitConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#'
- '#getForm\(\) invoked with 2 parameters, 1 required.#'
- '#While loop condition is always true.#'
- '#has parameter \$configuration with no value type specified in iterable type array.#'
- '#has parameter \$namespaces with no value type specified in iterable type Traversable.#'
- '#Call to an undefined method Symfony\\Component\\Console\\Helper\\HelperInterface::ask\(\).#'
Loading
Loading