Spaces:
Running
Running
Commit ·
a09c97b
1
Parent(s): 206a534
feat: add chat history support to AI strategist assist
Browse filesFiles changed (2)
21 unmodified lines222324252627282930313233343536373821 unmodified lines public string Goal { get; set; } = string.Empty; }
public class AIChatMessageDto { public string Role { get; set; } = string.Empty; // "user" or "model" public string Text { get; set; } = string.Empty; }
public class AICanvasAssistRequestDto { public Guid GraphId { get; set; } public string UserPrompt { get; set; } = string.Empty; public List<AIChatMessageDto> History { get; set; } = new(); }
public class AICanvasAssistResponseDto113 unmodified lines11411511611711811912012112212312412512617 unmodified lines144145146140141142147148149298 unmodified lines448449450451452453454455456457458459460461462463464465466467468469470471472473474475447476477478479113 unmodified lines }
private async Task<string> CallGeminiApiAsync(string prompt, string? systemInstruction = null, string? responseSchemaJson = null) { var parts = new[] { new { text = prompt } }; var contents = new[] { new { parts = parts } }; return await CallGeminiApiAsync(contents, systemInstruction, responseSchemaJson); }
private async Task<string> CallGeminiApiAsync(object[] contents, string? systemInstruction = null, string? responseSchemaJson = null) { var apiKey = _config["Gemini:ApiKey"] ?? Environment.GetEnvironmentVariable("GEMINI_API_KEY"); if (string.IsNullOrEmpty(apiKey))17 unmodified lines } var url = $"https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent?key={apiKey}";
var parts = new List<object> { new { text = prompt } }; var contents = new[] { new { parts = parts } }; object? generationConfig = null; if (responseSchemaJson != null) {298 unmodified lines "3. В поле 'explanation' напиши естественный, живой и дружелюбный ответ пользователю. Общайся напрямую как человек-наставник (без фраз вроде 'Пользовательский запрос...', 'В соответствии со своей ролью я не могу...'). Ответь на его вопрос, прокомментируй граф или дружелюбно объясни, какие изменения ты внес.";
var systemInstruction = "You are a friendly, highly professional Roadmap Strategist AI Agent. You interact with the user, answer their questions, and help them design, extend, or analyze their roadmaps. You converse naturally, warmly, and directly (in the user's language). If changes are needed, you return the new nodes and edges, breaking down complex tasks into hierarchical subtasks. To model sequential subtasks, you connect the parent to the first subtask using relationship 'subgoal', and then chain the subtasks sequentially using relationship 'sequential', and avoiding habits (relationship: habit) unless specifically requested."; var contentsList = new List<object>(); if (request.History != null) { foreach (var msg in request.History) { var role = msg.Role == "user" ? "user" : "model"; if (!string.IsNullOrWhiteSpace(msg.Text)) { contentsList.Add(new { role = role, parts = new[] { new { text = msg.Text } } }); } } }
// Add the current user prompt (contains graph context + query) contentsList.Add(new { role = "user", parts = new[] { new { text = prompt } } });
var responseJson = await CallGeminiApiAsync(prompt, systemInstruction, AssistResponseSchema); var responseJson = await CallGeminiApiAsync(contentsList.ToArray(), systemInstruction, AssistResponseSchema); responseJson = CleanJson(responseJson);
// 3. Deserialize Gemini responseFlowAPI.Application/DTOs/AI/AIDtos.cs+7
FlowAPI.Application/Services/AIService.cs+33-4