Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thejimbirch committed Aug 7, 2024
0 parents commit ebbf96b
Show file tree
Hide file tree
Showing 7 changed files with 769 additions and 0 deletions.
339 changes: 339 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions README.md
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!
12 changes: 12 additions & 0 deletions composer.json
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": "*"
}
}
112 changes: 112 additions & 0 deletions config/eca.eca.process_openai_summary_post.yml
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: { }
Loading

0 comments on commit ebbf96b

Please sign in to comment.