-
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
Showing
16 changed files
with
494 additions
and
149 deletions.
There are no files selected for viewing
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 @@ | ||
releases |
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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
2.0 | ||
- Global refactoring | ||
- Adds a new "Dummy" GPT provider with test data instead of a checkbox. | ||
- Adds support for other languages generated by the GPT provider. | ||
|
||
1.0 | ||
- The module is born. |
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
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
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,68 @@ | ||
export class ChatGPTTD { | ||
|
||
get name() { | ||
return 'ChatGPT Temporary Demo'; | ||
} | ||
|
||
/** | ||
* Get a response from ChatGPT | ||
* @param prompt | ||
* @param full_or_sections | ||
* @returns {Promise<any|null>} | ||
*/ | ||
async getCompletion(prompt, full_or_sections = "section") { | ||
|
||
if (!game.settings.get('place-gpt', 'openaiAPIToken')) { | ||
ui.notifications.error(game.i18n.localize('place-gpt.error.no_api_token')); | ||
return null; | ||
} | ||
|
||
const apiUrl = 'https://api.openai.com/v1/chat/completions'; | ||
|
||
let full_or_sections_prompt = game.i18n.localize("place-gpt.prompt_section"); | ||
if (full_or_sections === "full") { | ||
full_or_sections_prompt = game.i18n.localize("place-gpt.prompt_full") | ||
} | ||
|
||
const headers = { | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer OPENAITEMPDEMO' | ||
}; | ||
|
||
const body = { | ||
'model': 'gpt-3.5-turbo-0301', | ||
'temperature': 0.2, | ||
'messages': [ | ||
{'role': 'system', 'content': full_or_sections_prompt}, | ||
{'role': 'system', 'content': "Answer in the language of user request but keep the JSON valid."}, | ||
{'role': 'user', 'content': prompt} | ||
] | ||
}; | ||
|
||
const requestOptions = { | ||
method: 'POST', | ||
headers: headers, | ||
body: JSON.stringify(body) | ||
}; | ||
|
||
try { | ||
// @todo add different http error handling e.g. 429 is out of credits. | ||
const response = await fetch(apiUrl, requestOptions); | ||
const data = await response.json(); | ||
|
||
// Retrieve the assistant's reply from the API response | ||
// Try to decode JSON (if the response is JSON) | ||
try { | ||
return JSON.parse(data.choices[0].message.content); | ||
} | ||
catch { | ||
// If the response is not JSON, return the raw string | ||
return null; | ||
} | ||
} catch (error) { | ||
console.error('Error:', error); | ||
// Handle error | ||
return null; | ||
} | ||
} | ||
} |
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
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,53 @@ | ||
export class Dummy { | ||
|
||
get name() { | ||
return 'Dummy'; | ||
} | ||
|
||
/** | ||
* Get a response from ChatGPT | ||
* @param prompt | ||
* @param full_or_sections | ||
* @returns {Promise<any|null>} | ||
*/ | ||
async getCompletion(prompt, full_or_sections= "section") { | ||
|
||
console.log(full_or_sections); | ||
let apiUrl = '/modules/place-gpt/assets/dummy_section.json'; | ||
if (full_or_sections === "full") { | ||
apiUrl = '/modules/place-gpt/assets/dummy_full.json'; | ||
} | ||
|
||
const headers = { | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
const requestOptions = { | ||
method: 'GET', | ||
headers: headers | ||
}; | ||
|
||
try { | ||
|
||
await new Promise(r => setTimeout(r, 2000)); | ||
|
||
const response = await fetch(apiUrl, requestOptions); | ||
const data = await response.json(); | ||
|
||
// Retrieve the assistant's reply from the API response | ||
// Try to decode JSON (if the response is JSON) | ||
try { | ||
return data; | ||
} | ||
catch(error) { | ||
// If the response is not JSON, return the raw string | ||
console.error('place-gpt Error:', error); | ||
return null; | ||
} | ||
} catch (error) { | ||
console.error('place-gpt Error:', error); | ||
// Handle error | ||
return null; | ||
} | ||
} | ||
} |
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,35 @@ | ||
[{ | ||
"name": "Entrance", | ||
"exits": { | ||
"north": "Storage Room", | ||
"east": "Weapons Section", | ||
"south": "Food Section" | ||
} | ||
}, { | ||
"name": "Storage Room", | ||
"exits": { | ||
"south": "Entrance" | ||
} | ||
}, { | ||
"name": "Weapons Section", | ||
"exits": { | ||
"west": "Entrance", | ||
"north": "Armor Section" | ||
} | ||
}, { | ||
"name": "Armor Section", | ||
"exits": { | ||
"south": "Weapons Section" | ||
} | ||
}, { | ||
"name": "Food Section", | ||
"exits": { | ||
"north": "Entrance", | ||
"east": "Drink Section" | ||
} | ||
}, { | ||
"name": "Drink Section", | ||
"exits": { | ||
"west": "Food Section" | ||
} | ||
}] |
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,48 @@ | ||
[ | ||
{ | ||
"name": "Living Room", | ||
"description": "The living room is cozy and inviting, with a plush sofa and armchair arranged around a coffee table. A TV sits on a stand against one wall, and a bookshelf lines another. A large window lets in plenty of natural light, and there is a door leading to the front porch.", | ||
"exits": { | ||
"east": "Kitchen", | ||
"south": "Main Hallway" | ||
} | ||
}, | ||
{ | ||
"name": "Kitchen", | ||
"description": "The kitchen is small but functional, with a stove, refrigerator, and sink. There is a small table with two chairs for dining. A window above the sink looks out onto the backyard, and there is a door leading to the back porch.", | ||
"exits": { | ||
"west": "Living Room" | ||
} | ||
}, | ||
{ | ||
"name": "Main Hallway", | ||
"description": "The main hallway runs the length of the house, with doors leading to the various rooms. There is a coat closet by the front door, and a staircase leading to the second floor.", | ||
"exits": { | ||
"north": "Living Room", | ||
"east": "Bathroom", | ||
"south": "Bedroom 1", | ||
"west": "Bedroom 2" | ||
} | ||
}, | ||
{ | ||
"name": "Bathroom", | ||
"description": "The bathroom is small but functional, with a sink, toilet, and shower/tub combo. There is a small window for ventilation.", | ||
"exits": { | ||
"west": "Main Hallway" | ||
} | ||
}, | ||
{ | ||
"name": "Bedroom 1", | ||
"description": "This bedroom is cozy and comfortable, with a double bed, dresser, and closet. A window looks out onto the front yard.", | ||
"exits": { | ||
"north": "Main Hallway" | ||
} | ||
}, | ||
{ | ||
"name": "Bedroom 2", | ||
"description": "This bedroom is slightly larger than the other, with a queen bed, dresser, and closet. A window looks out onto the backyard.", | ||
"exits": { | ||
"east": "Main Hallway" | ||
} | ||
} | ||
] |
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,42 @@ | ||
[ | ||
{ | ||
"name": "Living Room", | ||
"exits": { | ||
"east": "Kitchen", | ||
"south": "Main Hallway" | ||
} | ||
}, | ||
{ | ||
"name": "Kitchen", | ||
"exits": { | ||
"west": "Living Room" | ||
} | ||
}, | ||
{ | ||
"name": "Main Hallway", | ||
"exits": { | ||
"north": "Living Room", | ||
"east": "Bathroom", | ||
"south": "Bedroom 1", | ||
"west": "Bedroom 2" | ||
} | ||
}, | ||
{ | ||
"name": "Bathroom", | ||
"exits": { | ||
"west": "Main Hallway" | ||
} | ||
}, | ||
{ | ||
"name": "Bedroom 1", | ||
"exits": { | ||
"north": "Main Hallway" | ||
} | ||
}, | ||
{ | ||
"name": "Bedroom 2", | ||
"exits": { | ||
"east": "Main Hallway" | ||
} | ||
} | ||
] |
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
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
Oops, something went wrong.