Skip to content

Commit 9fb9e29

Browse files
committed
2023.04.03 Update 1.0.1
[Settings] - Add model property on settings. [Script Generator Window] - Fix error FileName and SavePath doesn't insert value.
1 parent f2c60b2 commit 9fb9e29

8 files changed

+72
-10
lines changed

Editor/ChatGPTAnswer.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ public void SendAnswer()
2121
{
2222
Debug.Log("Answer Sent");
2323
var settings = Resources.Load<ChatGPTSettings>("ChatGPTSettings");
24-
EditorBackgroundUtility.StartBackgroundTask(GenerateResponse(settings.apiKey, question, SetAnswer));
24+
EditorBackgroundUtility.StartBackgroundTask(GenerateResponse(settings.apiKey, settings.aiModel,question, SetAnswer));
2525
}
2626

2727
private void SetAnswer(string _answer)
2828
{
2929
answer = _answer.Trim();
3030
}
3131

32-
private IEnumerator GenerateResponse(string apiKey, string prompt, Action<string> resultAction)
32+
private IEnumerator GenerateResponse(string apiKey, string model, string prompt, Action<string> resultAction)
3333
{
3434
ChatGPTCompletionData completionData = new ChatGPTCompletionData
3535
{
36-
model = "text-davinci-003",
36+
model = model,
3737
prompt = prompt,
3838
max_tokens = 1000,
3939
temperature = 0,
@@ -63,9 +63,8 @@ private IEnumerator GenerateResponse(string apiKey, string prompt, Action<string
6363
Debug.Log("ChatGPT Answered!");
6464
var result = JsonUtility.FromJson<ChatGPTResult>(request.downloadHandler.text);
6565
resultAction?.Invoke(result.choices[0].text);
66-
67-
answerSent = false;
6866
}
67+
answerSent = false;
6968
}
7069
}
7170

Editor/ChatGPTAnswerEditor.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ChatGPTAnswerEditor : Editor
1515
private const string standbyMessage = "Ready to Answer.";
1616

1717
private const string apiKeyErrorMessage = "API Key is Empty.";
18+
private const string modelErrorMessage = "Model Name is Empty.";
1819
private const string settingErrorMessage = "ChatGPTSettings not Exists.";
1920

2021
private Vector2 scrollA;
@@ -38,20 +39,20 @@ public override void OnInspectorGUI()
3839

3940
EditorGUILayout.Separator();
4041

41-
EditorGUILayout.TextField("File Name", answerAsset.fileName);
42+
answerAsset.fileName = EditorGUILayout.TextField("File Name", answerAsset.fileName);
4243

43-
EditorGUILayout.TextField("Save Path", answerAsset.savePath);
44+
answerAsset.savePath = EditorGUILayout.TextField("Save Path", answerAsset.savePath);
4445

4546
EditorGUILayout.Separator();
4647

47-
if (!settings || settings.ApiKeyIsEmpty()) GUI.enabled = false;
48+
if (!settings || settings.ApiKeyIsEmpty() || settings.ModelIsEmpty()) GUI.enabled = false;
4849
if (GUILayout.Button("Send Answer"))
4950
{
5051
answerAsset.SendAnswer();
5152
answerAsset.answerSent = true;
5253
}
5354

54-
if (!settings || settings.ApiKeyIsEmpty()) GUI.enabled = true;
55+
if (!settings || settings.ApiKeyIsEmpty() || settings.ModelIsEmpty()) GUI.enabled = true;
5556

5657
EditorGUILayout.BeginHorizontal();
5758
GUILayout.FlexibleSpace();
@@ -71,6 +72,10 @@ public override void OnInspectorGUI()
7172
{
7273
GUILayout.Label(apiKeyErrorMessage);
7374
}
75+
else if (settings.ModelIsEmpty())
76+
{
77+
GUILayout.Label(modelErrorMessage);
78+
}
7479
else
7580
{
7681
GUILayout.Label(standbyMessage);

Editor/ChatGPTAnswers.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/ChatGPTSettings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ namespace BKK.ChatGPTEditor
77
public class ChatGPTSettings : ScriptableObject
88
{
99
[SerializeField] private string openAiApiKey;
10+
[SerializeField] private string model = "text-davinci-003";
1011
[SerializeField] private string createAssetPath = "Assets/Editor/ChatGPTAnswers";
1112

1213
public string apiKey => openAiApiKey;
14+
public string aiModel => model;
1315
public string createPath => createAssetPath;
1416

1517
public const string settingPath = "Assets/Editor/Resources";
@@ -37,5 +39,10 @@ public bool ApiKeyIsEmpty()
3739
{
3840
return string.IsNullOrEmpty(apiKey) || string.IsNullOrWhiteSpace(apiKey);
3941
}
42+
43+
public bool ModelIsEmpty()
44+
{
45+
return string.IsNullOrEmpty(model) || string.IsNullOrWhiteSpace(model);
46+
}
4047
}
4148
}

Editor/ChatGPTSettingsEditor.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace BKK.ChatGPTEditor
6+
{
7+
[CustomEditor(typeof(ChatGPTSettings))]
8+
public class ChatGPTSettingsEditor : Editor
9+
{
10+
private ChatGPTSettings chatGptSettings;
11+
private SerializedProperty m_OpenAiApiKey;
12+
private SerializedProperty m_Model;
13+
private SerializedProperty m_CreateAssetPath;
14+
15+
private void OnEnable()
16+
{
17+
chatGptSettings = target as ChatGPTSettings;
18+
19+
m_OpenAiApiKey = serializedObject.FindProperty("openAiApiKey");
20+
m_Model = serializedObject.FindProperty("model");
21+
m_CreateAssetPath = serializedObject.FindProperty("createAssetPath");
22+
}
23+
24+
public override void OnInspectorGUI()
25+
{
26+
EditorGUILayout.PropertyField(m_OpenAiApiKey);
27+
EditorGUILayout.PropertyField(m_Model, new GUIContent("Model( Current text-davinci-003 Only )"));
28+
EditorGUILayout.PropertyField(m_CreateAssetPath);
29+
}
30+
}
31+
}

Editor/ChatGPTSettingsEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Resources/ChatGPTSettings.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ MonoBehaviour:
1313
m_Name: ChatGPTSettings
1414
m_EditorClassIdentifier:
1515
openAiApiKey:
16+
model: text-davinci-003
1617
createAssetPath: Assets/Editor/ChatGPTAnswers

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.bkk.chatgptscriptgenerator",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"displayName": "ChatGPT Script Generator",
55
"description": "ChatGPT Script Generator provides question ask to ChatGPT and script save in asset folder.",
66
"unity": "2020.3",

0 commit comments

Comments
 (0)