-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ebbf96b
Showing
7 changed files
with
769 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
![saplings](https://github.com/kanopi/saplings/assets/5177009/a6377e32-deb2-49d8-873a-f3dd5a36fa7c) | ||
|
||
# Saplings - AI | ||
|
||
Helpful AI functionality for content creators. | ||
|
||
## Features | ||
|
||
### Summary from OpenAI - Post | ||
|
||
This ECA workflow uses chatGPT to write a summary of the article and save it to | ||
the Description field on save if the field does not have one. If the Description | ||
has any content at all, the workflow is not run. | ||
|
||
OpenAI APIs have costs associated with them. [Pricing](https://openai.com/api/pricing/) | ||
|
||
## Roadmap | ||
|
||
* Summary from OpenAI - Page Workflow | ||
* Summary from OpenAI - Event Workflow | ||
* Featured Image from OpenAI (DALL-E) Workflow | ||
* Text to Audio Workflow | ||
* Audio to Text Workflow | ||
* CKEditor integration(s) | ||
|
||
## Installation | ||
|
||
``` | ||
composer require kanopi/saplings-ai | ||
cd web && php core/scripts/drupal recipe ../recipes/saplings-ai | ||
``` | ||
|
||
There are a couple of patches that are needed momentarily. | ||
|
||
Add the following to your project's composer.json | ||
|
||
``` | ||
"patches": { | ||
"drupal/openai": { | ||
"Return type declaration error": "https://www.drupal.org/files/issues/2024-06-28/openai-OpenAIActionBase_return_type-3450196-6.patch", | ||
"Misspelled property triggers errors in ECA module": "https://git.drupalcode.org/project/openai/-/merge_requests/92.diff" | ||
} | ||
} | ||
``` | ||
|
||
Then run `composer update drupal/openai` | ||
|
||
### Configure OpenAI | ||
|
||
Create an account and an User API key at https://platform.openai.com | ||
|
||
Add the OpenAI User key and organization ID to: `/admin/config/openai/settings` | ||
|
||
Save an you are ready to start AI-ing! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "kanopi/saplings-ai", | ||
"type": "drupal-recipe", | ||
"description": "Helpful AI functionality for content creators.", | ||
"license": "GPL-2.0-or-later", | ||
"require": { | ||
"drupal/bpmn_io": "*", | ||
"drupal/eca": "*", | ||
"drupal/openai": "*", | ||
"kanopi/saplings-content-types": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
langcode: en | ||
status: true | ||
dependencies: | ||
config: | ||
- field.field.node.sa_page.sa_description | ||
- field.field.node.sa_post.sa_body | ||
- field.field.node.sa_post.sa_description | ||
- field.storage.node.sa_body | ||
- field.storage.node.sa_description | ||
- node.type.sa_post | ||
module: | ||
- eca_base | ||
- eca_content | ||
- openai_eca | ||
id: process_openai_summary_post | ||
modeller: bpmn_io | ||
label: 'Summary from OpenAI - Post' | ||
version: '1.0' | ||
weight: 0 | ||
events: | ||
Event_save_post: | ||
plugin: 'content_entity:presave' | ||
label: 'Save Post' | ||
configuration: | ||
type: 'node sa_post' | ||
successors: | ||
- | ||
id: Activity_get_body_field | ||
condition: Flow_validate_empty_description | ||
conditions: | ||
Flow_validate_empty_description: | ||
plugin: eca_entity_field_value_empty | ||
configuration: | ||
negate: false | ||
field_name: sa_description | ||
entity: '' | ||
Flow_summary_exists: | ||
plugin: eca_token_exists | ||
configuration: | ||
negate: false | ||
token_name: body_summary | ||
Flow_validate_ai_summary: | ||
plugin: eca_token_exists | ||
configuration: | ||
negate: false | ||
token_name: ai_summary | ||
Flow_validate_desc_not_empty: | ||
plugin: eca_entity_field_value_empty | ||
configuration: | ||
field_name: sa_description | ||
negate: true | ||
entity: '' | ||
gateways: { } | ||
actions: | ||
Activity_get_body_field: | ||
plugin: eca_get_field_value | ||
label: 'Get body field' | ||
configuration: | ||
field_name: sa_body | ||
token_name: body_summary | ||
object: '' | ||
successors: | ||
- | ||
id: Activity_ai_summary | ||
condition: Flow_summary_exists | ||
Activity_ai_summary: | ||
plugin: openai_eca_execute_chat | ||
label: 'AI summary' | ||
configuration: | ||
model: gpt-4o-mini | ||
prompt: |- | ||
Please generate a summary under 300 characters of the following body_text: | ||
<body_text> | ||
[body_summary] | ||
</body_text> | ||
Return a paragraph. | ||
system: 'You are an expert in content editing and an assistant to a user writing content for their website. Please return all answers without using first, second, or third person voice.' | ||
temperature: '0.4' | ||
max_tokens: '256' | ||
token_input: body_summary | ||
token_result: ai_summary | ||
successors: | ||
- | ||
id: Activity_write_description | ||
condition: Flow_validate_ai_summary | ||
Activity_write_description: | ||
plugin: eca_set_field_value | ||
label: 'Write description' | ||
configuration: | ||
field_name: sa_description | ||
field_value: '[ai_summary]' | ||
method: 'set:empty' | ||
strip_tags: false | ||
trim: false | ||
save_entity: true | ||
object: '' | ||
successors: | ||
- | ||
id: Activity_message_complete | ||
condition: Flow_validate_desc_not_empty | ||
Activity_message_complete: | ||
plugin: action_message_action | ||
label: 'Message summary is saved' | ||
configuration: | ||
replace_tokens: false | ||
message: |- | ||
The following description was written by AI: | ||
[node:sa_description] | ||
successors: { } |
Oops, something went wrong.