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 10 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
}
}
}
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 communicat with the models.'
cableman marked this conversation as resolved.
Show resolved Hide resolved
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'
cableman marked this conversation as resolved.
Show resolved Hide resolved
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'
cableman marked this conversation as resolved.
Show resolved Hide resolved
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>
12 changes: 12 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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\(\).#'

36 changes: 36 additions & 0 deletions scripts/code-analysis
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

script_dir=$(pwd)
module_name=$(basename "$script_dir")
drupal_dir=vendor/drupal-module-code-analysis
# Relative to $drupal_dir
module_path=web/modules/contrib/$module_name

cd "$script_dir" || exit

drupal_composer() {
composer --working-dir="$drupal_dir" --no-interaction "$@"
}

# Create new Drupal 9 project
if [ ! -f "$drupal_dir/composer.json" ]; then
composer --no-interaction create-project drupal/recommended-project:^10 "$drupal_dir"
fi
# Copy our code into the modules folder
mkdir -p "$drupal_dir/$module_path"
# https://stackoverflow.com/a/15373763
rsync --archive --compress . --filter=':- .gitignore' --exclude "$drupal_dir" --exclude .git "$drupal_dir/$module_path"

drupal_composer config minimum-stability dev

# Allow ALL plugins
# https://getcomposer.org/doc/06-config.md#allow-plugins
drupal_composer config --no-plugins allow-plugins true

drupal_composer require wikimedia/composer-merge-plugin
drupal_composer config extra.merge-plugin.include "$module_path/composer.json"
# https://www.drupal.org/project/drupal/issues/3220043#comment-14845434
drupal_composer require --dev symfony/phpunit-bridge

# Run PHPStan
(cd "$drupal_dir" && vendor/bin/phpstan --configuration="$module_path/phpstan.neon")
Loading
Loading