Skip to content

Commit

Permalink
Merge pull request #4 from PepijnMC/v1.4.0
Browse files Browse the repository at this point in the history
v1.4.0
  • Loading branch information
PepijnMC authored Jan 15, 2023
2 parents 50929e3 + 6e697bd commit d2a9a7d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
> This module does not require any credentials except for your API key, which is stored locally in your Foundry settings. All billing is done from your OpenAI account. This key could be accessed by other programs and modules although they would have little reason to do so, nevertheless be careful and once again make sure to set a monthly limit to avoid unsuspected costs.
GPT-3 is a text-based AI by [OpenAI](https://beta.openai.com/). This module provides a user-friendly implentation to communicate with its API from within your Foundry games to generate descriptions on the fly.
GPT-3 is a text-based AI by [OpenAI](https://beta.openai.com/). This module provides a user-friendly implentation to communicate with its API from within your Foundry games to generate descriptions on the fly. The module provides direct support for actors, items, attacks, spells, and features.

## System Support
By default your current rpg system is integrated into the prompt to give GPT-3 the context it needs. By the nature of GPT-3 it will work better for popular systems and worse for very niche systems. If your system produces subpar results you can manually change the system in the settings to something that provides more context than just the system's name.
Expand Down Expand Up @@ -41,7 +41,7 @@ There are two new commands available to the GM to send prompts to GPT-3.
- `/gpt send What would be a fun low level encounter for a dnd5e game set in a jungle?`

## Description Generator
All actors, items, and spells have a button added in their header for the GM to request a short description generated by the AI based on your rpg system and world/setting. Responses are put in the Foundry chat and can optionally only be whispered to you.
All actors, items, attacks, spells, and features have a button added in their header for the GM to request a short description generated by the AI based on your rpg system and world/setting. Responses are put in the Foundry chat and can optionally only be whispered to you.

![The button on the sheet](https://raw.githubusercontent.com/PepijnMC/FoundryVTT-AI-Description-Generator/main/media/Button.png)

Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "ai-description-generator",
"title": "AI Description Generator",
"description": "Utilizes the GPT-3 AI to generate descriptions from within Foundry.",
"version": "1.3.0",
"version": "1.4.0",
"authors": [
{
"name": "Pepijn Sietsema",
Expand Down
Binary file modified module.zip
Binary file not shown.
4 changes: 3 additions & 1 deletion scripts/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ export function constructPrompt(language, system, world, subject, subjectType, k
for (const [key, value] of Object.entries(prompt_mapping)) {
prompt = prompt.replace(key, value);
}
console.log(prompt);

//Send the prompt.
return sendPrompt(prompt, key)
//sendPrompt(prompt, key)
}

//Send a prompt the GPT-3.
Expand Down
51 changes: 37 additions & 14 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,44 @@ Hooks.on('getActorSheetHeaderButtons', (sheet, headerButtons) => {

//Add a new button the the header of the itme sheet. Spells are also considered items.
Hooks.on('getItemSheetHeaderButtons', (sheet, headerButtons) => {
headerButtons.unshift({
label: 'GPT-3',
icon: 'fas fa-comment-dots',
class: 'gpt-actor-button',
onclick: () => {
constructPrompt(
game.settings.get('ai-description-generator', 'language'),
game.settings.get('ai-description-generator', 'system'),
game.settings.get('ai-description-generator', 'world'),
sheet.object.name,
sheet.object.type == 'spell' ? 'spell': 'item',
game.settings.get('ai-description-generator', 'key')
);
const actor = sheet?.actor
var actorContext = ''
if (actor) {
switch (actor.type) {
case 'character':
actorContext = ' from a player character';
break;
case 'npc':
actorContext = ` from a ${actor.name} creature`;
break;
case 'vehicle':
actorContext = ` from a ${actor.name} vehicle`;
break;
case 'group':
actorContext = ` from a group of ${actor.name}`;
break;
}
})
}
const subjectTypeMapping = {'item': 'item', 'weapon': `attack${actorContext}`, 'spell': `spell${actorContext}`, 'feat': `feature${actorContext}`};
var subjectType = sheet.object.type;
if (subjectType in subjectTypeMapping) {
headerButtons.unshift({
label: 'GPT-3',
icon: 'fas fa-comment-dots',
class: 'gpt-actor-button',
onclick: () => {
constructPrompt(
game.settings.get('ai-description-generator', 'language'),
game.settings.get('ai-description-generator', 'system'),
game.settings.get('ai-description-generator', 'world'),
sheet.object.name,
subjectTypeMapping[subjectType],
game.settings.get('ai-description-generator', 'key')
);
}
})
}

})

Hooks.on('chatMessage', addChatCommands);

0 comments on commit d2a9a7d

Please sign in to comment.