Easy Ollama Plugin and Samples for Unity
EasyLocalLLM now includes a command set for configuring and managing session-specific system prompts.
This lets you use a global system prompt while applying a different prompt for specific sessions.
SetSessionSystemPrompt(string sessionId, string systemPrompt)Sets the system prompt for a specific session.
Parameters:
sessionId: Session IDsystemPrompt: The system prompt to setExample:
var client = LLMClientFactory.CreateOllamaClient(config);
// Programming prompt for session A
client.SetSessionSystemPrompt("session-a",
"You are a programming expert. Help with code-related questions.");
// Translation prompt for session B
client.SetSessionSystemPrompt("session-b",
"You are a translation expert. Translate accurately between languages.");
GetSessionSystemPrompt(string sessionId)Gets the system prompt for a specific session.
Returns: The system prompt, or null if the session does not exist.
Example:
string prompt = client.GetSessionSystemPrompt("session-a");
Debug.Log($"Session A prompt: {prompt}");
ResetSessionSystemPrompt(string sessionId)Resets the system prompt for a specific session. After reset, the global system prompt is used.
Example:
// Reset session A prompt to the global setting
client.ResetSessionSystemPrompt("session-a");
SetSystemPromptForMultipleSessions(IEnumerable<string> sessionIds, string systemPrompt)Sets the same system prompt for multiple sessions at once.
Parameters:
sessionIds: List of session IDssystemPrompt: The system prompt to setExample:
// Apply the same prompt to multiple sessions
var sessionIds = new[] { "session-1", "session-2", "session-3" };
client.SetSystemPromptForMultipleSessions(sessionIds,
"You are a helpful customer service assistant.");
ResetAllSessionSystemPrompts()Resets the system prompts for all sessions.
Example:
// Reset all sessions to the global prompt
client.ResetAllSessionSystemPrompts();
ClearSessionWithPrompt(string sessionId)Clears both the session history and the session prompt.
Example:
// Fully reset session A
client.ClearSessionWithPrompt("session-a");
// Translation session
client.SetSessionSystemPrompt("translator",
"You are a professional translator. Translate accurately and naturally.");
// Programming help session
client.SetSessionSystemPrompt("programmer",
"You are a senior software engineer. Provide code examples and explanations.");
// Teaching session
client.SetSessionSystemPrompt("teacher",
"You are an educational tutor. Explain concepts clearly with examples.");
// Independent conversation per session
StartCoroutine(client.SendMessageAsync(
"Translate 'Hello' to Japanese",
response => Debug.Log(response.Content),
error => { },
new ChatRequestOptions { SessionId = "translator" }
));
// Japanese session
client.SetSessionSystemPrompt("ja",
"You are a helpful assistant. Always respond in Japanese.");
// English session
client.SetSessionSystemPrompt("en",
"You are a helpful assistant. Always respond in English.");
// French session
client.SetSessionSystemPrompt("fr",
"You are a helpful assistant. Always respond in French.");
// Project A session
client.SetSessionSystemPrompt("project-a",
"Context: You are helping with an educational game project. " +
"Focus on interactive and engaging explanations.");
// Project B session
client.SetSessionSystemPrompt("project-b",
"Context: You are helping with a business analytics project. " +
"Focus on data-driven insights and technical accuracy.");
GlobalSystemPrompt property
SetSessionSystemPrompt() method
ChatRequestOptions.SystemPrompt
Priority order:
Request level > Session level > Global level
If OllamaConfig.DebugMode = true, the following actions are logged:
[Ollama] Session 'session-a' system prompt updated: You are a programming expert...
[Ollama] Session 'session-a' system prompt reset to global
[Ollama] System prompt set for 3 sessions
[Ollama] Session 'session-a' cleared with prompt reset
Five tests were added to NonStreamingTests.cs:
| Test | Description |
|---|---|
| Test_SessionSystemPrompt_SetAndRetrieve | Set and retrieve prompt |
| Test_SessionSystemPrompt_Reset | Reset prompt |
| Test_SetSystemPromptForMultipleSessions | Bulk set prompts |
| Test_ResetAllSessionSystemPrompts | Reset all prompts |
| Test_ClearSessionWithPrompt | Clear history and prompt |
How to run:
Unity Test Runner -> PlayMode -> Run NonStreamingTests
All new methods are defined in IChatLLMClient:
OllamaClientMockChatLLMClient (for testing)Use meaningful session IDs to improve readability:
// Good
client.SetSessionSystemPrompt("translator-en-ja", "...");
client.SetSessionSystemPrompt("user-support-session-123", "...");
// Avoid
client.SetSessionSystemPrompt("session1", "...");
client.SetSessionSystemPrompt("temp", "...");
Set session prompts when the session is created:
// Recommended
var options = new ChatRequestOptions
{
SessionId = "programmer",
SystemPrompt = "You are a programming expert."
};
// Or
client.SetSessionSystemPrompt("programmer", "You are a programming expert.");
// Do not specify SystemPrompt on subsequent messages
StartCoroutine(client.SendMessageAsync("Write a function", callback,
new ChatRequestOptions { SessionId = "programmer" }));
Clear sessions to reduce memory usage:
// On session end
client.ClearSessionWithPrompt("session-id");
// Or individually
client.ClearMessages("session-id");
client.ResetSessionSystemPrompt("session-id");
Session system prompt commands allow you to: