|
@@ -17,6 +17,7 @@ namespace LLM.Editor.Client
|
|
private class CommandResponse { public List<Data.CommandData> commands; }
|
|
private class CommandResponse { public List<Data.CommandData> commands; }
|
|
|
|
|
|
private static Settings.MCPSettings _settings;
|
|
private static Settings.MCPSettings _settings;
|
|
|
|
+ private static string _systemPrompt;
|
|
|
|
|
|
private static bool LoadSettings()
|
|
private static bool LoadSettings()
|
|
{
|
|
{
|
|
@@ -32,6 +33,21 @@ namespace LLM.Editor.Client
|
|
_settings = AssetDatabase.LoadAssetAtPath<Settings.MCPSettings>(path);
|
|
_settings = AssetDatabase.LoadAssetAtPath<Settings.MCPSettings>(path);
|
|
return _settings;
|
|
return _settings;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private static bool LoadSystemPrompt()
|
|
|
|
+ {
|
|
|
|
+ if (!string.IsNullOrEmpty(_systemPrompt)) return true;
|
|
|
|
+
|
|
|
|
+ var guids = AssetDatabase.FindAssets("MCP_SystemPrompt");
|
|
|
|
+ if (guids.Length == 0)
|
|
|
|
+ {
|
|
|
|
+ Debug.LogError("[GeminiApiClient] Could not find 'MCP_SystemPrompt.txt'. Please create this text file in your project and enter the system prompt into it.");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ var path = AssetDatabase.GUIDToAssetPath(guids[0]);
|
|
|
|
+ _systemPrompt = System.IO.File.ReadAllText(path);
|
|
|
|
+ return !string.IsNullOrEmpty(_systemPrompt);
|
|
|
|
+ }
|
|
|
|
|
|
private static string GetAuthToken()
|
|
private static string GetAuthToken()
|
|
{
|
|
{
|
|
@@ -68,48 +84,9 @@ namespace LLM.Editor.Client
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private static string GetSystemPrompt()
|
|
|
|
- {
|
|
|
|
- return @"You are an expert Unity development assistant. Your goal is to help the user by breaking down their request into a sequence of commands.
|
|
|
|
-You MUST ONLY respond with a single JSON object containing a 'commands' array. Do not use markdown or any other formatting. The jsonData option of each command MUST be a valid JSON string.
|
|
|
|
-
|
|
|
|
-Some commands act on the 'subject' from the previous command.
|
|
|
|
-Here are the available commands and the exact `jsonData` format you must use for each:
|
|
|
|
-
|
|
|
|
-1. **DisplayMessage**: Shows a text message to the user.
|
|
|
|
- `""""jsonData"""": """"{\""""message\"""":\""""Your message here.\""""}""""`
|
|
|
|
-
|
|
|
|
-2. **CreateScript**: Creates a new C# script. This sets the new script as the subject.
|
|
|
|
- `""""jsonData"""": """"{\""""scriptName\"""":\""""MyNewScript\"""",\""""scriptContent\"""":\""""using UnityEngine;\\npublic class MyNewScript : MonoBehaviour { }\""""}""""`
|
|
|
|
-
|
|
|
|
-3. **CreatePrefab**: Asks the user for a save location, then creates a prefab. This sets the new prefab as the subject.
|
|
|
|
- `""""jsonData"""": """"{\""""sourceObjectQuery\"""":\""""MyModel t:Model\"""",\""""defaultName\"""":\""""MyModel.prefab\""""}""""`
|
|
|
|
-
|
|
|
|
-4. **AddComponentToAsset**: Attaches a script to the prefab currently set as the subject.
|
|
|
|
- `""""jsonData"""": """"{\""""scriptName\"""":\""""MyNewScript\""""}""""`
|
|
|
|
-
|
|
|
|
-5. **InstantiatePrefab**: Creates an instance of the prefab currently set as the subject. This sets the new scene object as the subject.
|
|
|
|
- `""""jsonData"""": """"{}""""`
|
|
|
|
-
|
|
|
|
-6. **RequestClarification**: Asks the user a follow-up question.
|
|
|
|
- `""""jsonData"""": """"{\""""prompt\"""":\""""Which object do you mean?\"""",\""""options\"""":[\""""ObjectA\"""",\""""ObjectB\""""]}""""`
|
|
|
|
-
|
|
|
|
-Your entire response must be a single, valid JSON object.
|
|
|
|
-
|
|
|
|
-Example of a valid response:
|
|
|
|
-{
|
|
|
|
- ""commands"": [
|
|
|
|
- {
|
|
|
|
- ""commandName"": ""DisplayMessage"",
|
|
|
|
- ""jsonData"": ""{\""message\"":\""Hello! How can I help?""\}""
|
|
|
|
- }
|
|
|
|
- ]
|
|
|
|
-}";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public static async Task SendPrompt(string prompt)
|
|
public static async Task SendPrompt(string prompt)
|
|
{
|
|
{
|
|
- if (!LoadSettings()) return;
|
|
|
|
|
|
+ if (!LoadSettings() || !LoadSystemPrompt()) return;
|
|
|
|
|
|
Debug.Log($"[GeminiApiClient] Getting auth token...");
|
|
Debug.Log($"[GeminiApiClient] Getting auth token...");
|
|
var authToken = GetAuthToken();
|
|
var authToken = GetAuthToken();
|
|
@@ -132,7 +109,7 @@ Example of a valid response:
|
|
{
|
|
{
|
|
system_instruction = new Api.SystemInstruction
|
|
system_instruction = new Api.SystemInstruction
|
|
{
|
|
{
|
|
- parts = new List<Api.Part> { new() { text = GetSystemPrompt() } }
|
|
|
|
|
|
+ parts = new List<Api.Part> { new() { text = _systemPrompt } }
|
|
},
|
|
},
|
|
contents = chatHistory.Select(entry => new Api.Content
|
|
contents = chatHistory.Select(entry => new Api.Content
|
|
{
|
|
{
|