diff --git a/Editor/ChatGPTAnswer.cs b/Editor/ChatGPTAnswer.cs index 6b9126b..e992b4e 100644 --- a/Editor/ChatGPTAnswer.cs +++ b/Editor/ChatGPTAnswer.cs @@ -21,7 +21,7 @@ public void SendAnswer() { Debug.Log("Answer Sent"); var settings = Resources.Load("ChatGPTSettings"); - EditorBackgroundUtility.StartBackgroundTask(GenerateResponse(settings.apiKey, question, SetAnswer)); + EditorBackgroundUtility.StartBackgroundTask(GenerateResponse(settings.apiKey, settings.aiModel,question, SetAnswer)); } private void SetAnswer(string _answer) @@ -29,11 +29,11 @@ private void SetAnswer(string _answer) answer = _answer.Trim(); } - private IEnumerator GenerateResponse(string apiKey, string prompt, Action resultAction) + private IEnumerator GenerateResponse(string apiKey, string model, string prompt, Action resultAction) { ChatGPTCompletionData completionData = new ChatGPTCompletionData { - model = "text-davinci-003", + model = model, prompt = prompt, max_tokens = 1000, temperature = 0, @@ -63,9 +63,8 @@ private IEnumerator GenerateResponse(string apiKey, string prompt, Action(request.downloadHandler.text); resultAction?.Invoke(result.choices[0].text); - - answerSent = false; } + answerSent = false; } } diff --git a/Editor/ChatGPTAnswerEditor.cs b/Editor/ChatGPTAnswerEditor.cs index 4ad7517..111ca75 100644 --- a/Editor/ChatGPTAnswerEditor.cs +++ b/Editor/ChatGPTAnswerEditor.cs @@ -15,6 +15,7 @@ public class ChatGPTAnswerEditor : Editor private const string standbyMessage = "Ready to Answer."; private const string apiKeyErrorMessage = "API Key is Empty."; + private const string modelErrorMessage = "Model Name is Empty."; private const string settingErrorMessage = "ChatGPTSettings not Exists."; private Vector2 scrollA; @@ -38,20 +39,20 @@ public override void OnInspectorGUI() EditorGUILayout.Separator(); - EditorGUILayout.TextField("File Name", answerAsset.fileName); + answerAsset.fileName = EditorGUILayout.TextField("File Name", answerAsset.fileName); - EditorGUILayout.TextField("Save Path", answerAsset.savePath); + answerAsset.savePath = EditorGUILayout.TextField("Save Path", answerAsset.savePath); EditorGUILayout.Separator(); - if (!settings || settings.ApiKeyIsEmpty()) GUI.enabled = false; + if (!settings || settings.ApiKeyIsEmpty() || settings.ModelIsEmpty()) GUI.enabled = false; if (GUILayout.Button("Send Answer")) { answerAsset.SendAnswer(); answerAsset.answerSent = true; } - if (!settings || settings.ApiKeyIsEmpty()) GUI.enabled = true; + if (!settings || settings.ApiKeyIsEmpty() || settings.ModelIsEmpty()) GUI.enabled = true; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); @@ -71,6 +72,10 @@ public override void OnInspectorGUI() { GUILayout.Label(apiKeyErrorMessage); } + else if (settings.ModelIsEmpty()) + { + GUILayout.Label(modelErrorMessage); + } else { GUILayout.Label(standbyMessage); diff --git a/Editor/ChatGPTAnswers.meta b/Editor/ChatGPTAnswers.meta new file mode 100644 index 0000000..01d9364 --- /dev/null +++ b/Editor/ChatGPTAnswers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d4c9ee504b40a544d9dab7750300673b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ChatGPTSettings.cs b/Editor/ChatGPTSettings.cs index b6ce1d1..eeef06a 100644 --- a/Editor/ChatGPTSettings.cs +++ b/Editor/ChatGPTSettings.cs @@ -7,9 +7,11 @@ namespace BKK.ChatGPTEditor public class ChatGPTSettings : ScriptableObject { [SerializeField] private string openAiApiKey; + [SerializeField] private string model = "text-davinci-003"; [SerializeField] private string createAssetPath = "Assets/Editor/ChatGPTAnswers"; public string apiKey => openAiApiKey; + public string aiModel => model; public string createPath => createAssetPath; public const string settingPath = "Assets/Editor/Resources"; @@ -37,5 +39,10 @@ public bool ApiKeyIsEmpty() { return string.IsNullOrEmpty(apiKey) || string.IsNullOrWhiteSpace(apiKey); } + + public bool ModelIsEmpty() + { + return string.IsNullOrEmpty(model) || string.IsNullOrWhiteSpace(model); + } } } diff --git a/Editor/ChatGPTSettingsEditor.cs b/Editor/ChatGPTSettingsEditor.cs new file mode 100644 index 0000000..354fcf3 --- /dev/null +++ b/Editor/ChatGPTSettingsEditor.cs @@ -0,0 +1,31 @@ +using System; +using UnityEditor; +using UnityEngine; + +namespace BKK.ChatGPTEditor +{ + [CustomEditor(typeof(ChatGPTSettings))] + public class ChatGPTSettingsEditor : Editor + { + private ChatGPTSettings chatGptSettings; + private SerializedProperty m_OpenAiApiKey; + private SerializedProperty m_Model; + private SerializedProperty m_CreateAssetPath; + + private void OnEnable() + { + chatGptSettings = target as ChatGPTSettings; + + m_OpenAiApiKey = serializedObject.FindProperty("openAiApiKey"); + m_Model = serializedObject.FindProperty("model"); + m_CreateAssetPath = serializedObject.FindProperty("createAssetPath"); + } + + public override void OnInspectorGUI() + { + EditorGUILayout.PropertyField(m_OpenAiApiKey); + EditorGUILayout.PropertyField(m_Model, new GUIContent("Model( Current text-davinci-003 Only )")); + EditorGUILayout.PropertyField(m_CreateAssetPath); + } + } +} diff --git a/Editor/ChatGPTSettingsEditor.cs.meta b/Editor/ChatGPTSettingsEditor.cs.meta new file mode 100644 index 0000000..8c0a5c0 --- /dev/null +++ b/Editor/ChatGPTSettingsEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b3bebe872b493db4bacb9f6de417b8e9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Resources/ChatGPTSettings.asset b/Editor/Resources/ChatGPTSettings.asset index 7bf87c1..61a45d3 100644 --- a/Editor/Resources/ChatGPTSettings.asset +++ b/Editor/Resources/ChatGPTSettings.asset @@ -13,4 +13,5 @@ MonoBehaviour: m_Name: ChatGPTSettings m_EditorClassIdentifier: openAiApiKey: + model: text-davinci-003 createAssetPath: Assets/Editor/ChatGPTAnswers diff --git a/package.json b/package.json index d238a69..02efc01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.bkk.chatgptscriptgenerator", - "version": "1.0.0", + "version": "1.0.1", "displayName": "ChatGPT Script Generator", "description": "ChatGPT Script Generator provides question ask to ChatGPT and script save in asset folder.", "unity": "2020.3",