Spaces:
Running
Running
Commit ·
ab6ad9a
1
Parent(s): e4a761a
Refine strategist prompts for conversational tone, adaptive sizes, and correct chronological chaining
Browse files187 unmodified lines18818919019119219346 unmodified lines24024124224324424558 unmodified lines3043053063073083092 unmodified lines31231331431531631731831932032132232332432532632732832933033133233333433533633733833934089 unmodified lines43043143243343443518 unmodified lines454455456457458459460461462463464465466467468469470471472473474475476477478479480481482421 unmodified lines904905906907908187 unmodified lines}using var httpClient = new HttpClient();var jsonPayload = JsonSerializer.Serialize(requestBody);HttpResponseMessage? response = null;46 unmodified lines{throw new Exception("Graph not found.");}var failedNode = graph.Nodes.FirstOrDefault(n => n.Id == request.FailedNodeId);if (failedNode == null)58 unmodified linespublic async Task<FullGraphResponseDto> GenerateGoalGraphAsync(GenerateGoalGraphRequestDto request){if (string.IsNullOrWhiteSpace(request.Goal)){throw new ArgumentException("Goal description cannot be empty.");2 unmodified lines// 1. Build prompt for Geminivar prompt = $"������������ ����� ������� ��������� ����: \"{request.Goal}\". " +"������� ��������� ������������� �������� �����.\n" +"������� ���������� ������ � ��������� (������������� � �����������):\n" +"- � ��� ���� ��� ���� ������:\n" +" 1. 'relationship': 'sequential' � ���������������� ���� / ����. ������������ ��� �������� ��������� � ��������� ����� ������� ������ ������ ����������, � ����� ��� ���������� ����� ������ ������� ������������ ���� � ������.\n" +" 2. 'relationship': 'subgoal' � ������������ � �������. ������������ ��� ���������� ������� ���� �� ������ ������ �����.\n" +"- ������� ����������� ������������ (����������):\n" +" * ����� ���� �� ����� ������ ����� ���� ���������������! ���� ������� ���� �� ���� �������, �� ������ ������� � �� � ����������� ������� (subgoals) � ���������������� ����.\n" +" * �� ������������� ����� ������� ��������. ������� �������� ������ (��������: ������� ���� -> ������� A -> ������� A.1 -> ������� A.1.1) � ��� ��������� � ��������������.\n" +" * ������: ������� ���� '������������� �����' ����� ������� '����� �����'. ������� '����� �����' ����� ���� ����������� ������� '���������� �����' � '��������� �������' (��������� ����� 'subgoal' � '����� �����'). '��������� �������' ����� ����� ���� '���������� �����' -> '�������� ������' (��������� ����� 'sequential' ����� �����).\n" +"- ��� ��������� ������� ������������ � �������:\n" +" * ������������ �������: ���� � ������������ ���� ���� ��������� ����������� ��� ������������ �����������, ��������� �� ��� �������� � �������� ����� ����� 'subgoal' (������� �����������).\n" +" * ���������������� �������: ���� ���� ������ ������� ������ ����������� ������ ���� �� ������, �� �������� �������� ����� 'subgoal' ������ � ������ ����� �������, � ��������� ���� ������ ���� ������� �������� ��������������� ����� 'sequential'.\n" +" * ��������� ���������: �� ������ �������� ������������� ��� ������� �� ����� ������� �����������.\n" +"- �� ��������� ������������ �������� ��� ���������������� �����. ������� �� ����������������� ������ / ������. ������� ��������� / ����������� ������ �������� ������������.\n" +"- �������� ����� ������ ���� ����������� ��������� � ������. �� ����� �� �� 2-3 ���! ���� ���� ������� (��� ������� �����, �������� ����������������), ���������� ����������� ����� �� 8-15+ �����, ������������ ��� ������ ���� � �� ���������.\n" +"- ������� ��� ����� ����� (����������):\n" +" * 'sketch' � ����������� ���/���� (��������� � 99% �������). ����� ������� �������� ���, ���� ���� �� �������� ��������, ����� �������� (��������, '�������� 30 �����', '��������� 1 ���') ��� �������� ��������, ������ ����� ��� 'sketch'!\n" +" * 'habit' (��������) � ��������� ������ ������ ���� ������������ ����� ������ ���������� ����������, ���������/����������� ������������� �������� ��� ������������ �������� (��������, '������ ���� ���� ����'). ������� �� ��������� ��� ��� ������� ����� ��������!\n" +" * 'condition' (�������) � ��������� ������ ������ ��� ����� ���������� ���������, �������� � ������ (��������, '���� X, �� Y, ����� Z'). ������� �� ��������� ��� ��� ������� ����� � ���������� ����������, ���� ��� ��������� ����!\n" +"������� ���� ��� �������� �������� �������� (label) � ��������� �������� (description).\n" +"� ���� 'explanation' ������ �����, ����������� � ������������� ����� �� ���� ����������� ������-��������, ������� ������ ������������ ����� � ��� ������ ������.";// 2. Call Gemini APIvar systemInstruction = "You are a friendly, highly professional Roadmap Strategist AI Agent. You design detailed, clean, and logical roadmaps represented as graphs (nodes and edges). You break down complex goals into hierarchical, deeply nested subgoals (recursive subgoals, where subgoals can have their own subgoals). You can connect a parent to multiple parallel subgoals using 'subgoal' relationship, or connect a parent to the first subgoal in a sequence using 'subgoal' and chain the remaining subgoals using 'sequential' relationship. Node types MUST follow these rules: 'sketch' for 99% of regular tasks (including tasks with durations/wait times); 'habit' ONLY for repeating daily/weekly actions meant to form a routine, if explicitly requested; 'condition' ONLY for logical forks/branches with conditions. You write warm, direct, and conversational explanations in the 'explanation' field.";var responseJson = await CallGeminiApiAsync(prompt, systemInstruction, GoalResponseSchema);responseJson = CleanJson(responseJson);89 unmodified lines{throw new Exception("Graph not found.");}// 1. Serialize existing nodes and edges for Gemini contextvar existingNodesText = new StringBuilder();18 unmodified lines"���� ������:\n" +"1. ���� ������ ������������ ������� ���������� ����� ���������, ����������� ��� ���������� �����: ���������� ����� ���� (NewNodes) � ����� ����� (NewEdges). ��� ���� ������ ������ �������� ���������� ������:\n" +" - � ��� ���� ��� ���� ������:\n" +" * 'relationship': 'sequential' � ���������������� ���� / ����. ������������ ��� �������� ��������� � ��������� ����� ������� ������ ������ ����������, � ����� ��� ���������� ����� ������ ������� ������������ ���� � ������.\n" +" * 'relationship': 'subgoal' � ������������ � �������. ������������ ��� ���������� ������� ���� �� ������ ������ �����.\n" +" - ������� ����������� ������������ (����������):\n" +" * ����� ���� �� ����� ������ ����� ���� ���������������! ���� ������� ���� �� ���� �������, �� ������ ������� � �� � ����������� ������� (subgoals) � ���������������� ����.\n" +" * �� ������������� ����� ������� ��������. ������� �������� ������ (��������: ������� ���� -> ������� A -> ������� A.1 -> ������� A.1.1) � ��� ��������� � ��������������.\n" +" - ��� ��������� ������� ������������ � �������:\n" +" * ������������ �������: ���� � ������������ ���� ���� ��������� ����������� ��� ������������ �����������, ��������� �� ��� �������� � �������� ����� ����� 'subgoal' (������� �����������).\n" +" * ���������������� �������: ���� ���� ������ ������� ������ ����������� ������ ���� �� ������, �� �������� �������� ����� 'subgoal' ������ � ������ ����� �������, � ��������� ���� ������ ���� ������� �������� ��������������� ����� 'sequential'.\n" +" * ��������� ���������: �� ������ �������� ������������� ��� ������� �� ����� ������� �����������.\n" +" - ���� ������������ ������ �������� ������� (������������) ��� ����� ��� ������������ ����:\n" +" * ���� ��������������� ������������ ���� ��� �� �����, ������� ������ ������������ ���� (��������, '������������' / 'Configuration') � ����� ��� ��������������� � ���������� ������ ����� 'relationship': 'sequential'.\n" +" * ����� ������������ ���� � ��������� (��������� ������� ����������� ��� ������������ ����� ��� ���������������� ������� ��� ��������� �����, ��� ������� ����).\n" +" * �� ��������� ������������ �������� ��� ���������������� �����. ������� �� ����������������� ������ / ������. ������� ��������� / ����������� ������ �������� ������������.\n" +" - ����������� ���� ����������� �����. �� ��������� 1-2 ����, ���� ������������ ������ ��������� ��� ��������� �����; ������ �����������, ������� � ��������� ���� �� 5-12 �����.\n" +" - ������� ��� ����� ����� (����������):\n" +" * 'sketch' � ����������� ���/���� (��������� � 99% �������). ����� ������� �������� ���, ���� ���� �� �������� ��������, ����� �������� (��������, '�������� 30 �����', '��������� 1 ���') ��� �������� ��������, ������ ����� ��� 'sketch'!\n" +" * 'habit' (��������) � ��������� ������ ������ ���� ������������ ����� ������ ���������� ����������, ���������/����������� ������������� �������� ��� ������������ �������� (��������, '������ ���� ���� ����'). ������� �� ��������� ��� ��� ������� ����� ��������!\n" +" * 'condition' (�������) � ��������� ������ ������ ��� ����� ���������� ���������, �������� � ������ (��������, '���� X, �� Y, ����� Z'). ������� �� ��������� ��� ��� ������� ����� � ���������� ����������, ���� ��� ��������� ����!\n" +" - �������� ����� ���� � ������������� ��� ���� � ������ � ������� ���������� ��������� ID (��������, new_step_1).\n" +"2. ���� ������ ������������ �� ������� ���������� ���������: ������ ������ 'NewNodes' � 'NewEdges' ������� ( [] ).\n" +"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. If changes are needed, you return the new nodes and edges, breaking down complex tasks into hierarchical, deeply nested subgoals (recursive subgoals, where subgoals can have their own subgoals). You can connect a parent to multiple parallel subgoals using 'subgoal' relationship, or connect a parent to the first subgoal in a sequence using 'subgoal' and chain the remaining subgoals using 'sequential' relationship. Node types MUST follow these rules: 'sketch' for 99% of regular tasks (including tasks with durations/wait times); 'habit' ONLY for repeating daily/weekly actions meant to form a routine, if explicitly requested; 'condition' ONLY for logical forks/branches with conditions. You never connect subgoals directly to unrelated nodes without a parent node.";var contentsList = new List<object>();if (request.History != null){421 unmodified linesreturn textResponse;}}}187 unmodified lines18818919019119219319446 unmodified lines24124224324424524624758 unmodified lines3063073083093103113123132 unmodified lines31631731831932032132232332432532632732832933033133233333433533633733833934034134234334489 unmodified lines43443543643743843944018 unmodified lines459460461462463464465466467468469470471472473474475476477478479480481482483484485421 unmodified lines907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940187 unmodified lines}using var httpClient = new HttpClient();httpClient.Timeout = TimeSpan.FromSeconds(5);var jsonPayload = JsonSerializer.Serialize(requestBody);HttpResponseMessage? response = null;46 unmodified lines{throw new Exception("Graph not found.");}await CheckAndIncrementAiGenerationsLimitAsync(graph.UserId);var failedNode = graph.Nodes.FirstOrDefault(n => n.Id == request.FailedNodeId);if (failedNode == null)58 unmodified linespublic async Task<FullGraphResponseDto> GenerateGoalGraphAsync(GenerateGoalGraphRequestDto request){await CheckAndIncrementAiGenerationsLimitAsync(request.UserId);if (string.IsNullOrWhiteSpace(request.Goal)){throw new ArgumentException("Goal description cannot be empty.");2 unmodified lines// 1. Build prompt for Geminivar prompt = $"������������ ����� ������� ��������� ����: \"{request.Goal}\". " +"������� ��������� ������������� �������� �����.\n" +"������� ���������� ������ � ��������� (�������������, ����������� � ������������������):\n" +"- � ��� ���� ��� ���� ������:\n" +" 1. 'relationship': 'sequential' � ���������������� ���� / ����. ������������ ��� �������� ���������, ��������� ����� ������� ������ ������ ����������, � ����� ��� ���������� ����� ������ ������� ������������ ���� � ������. ��������� ���� ��� ��� �����, ������� ������ �������������� ������� ���� �� ����� (��������: ����������� ���� -> �������� ����� -> ������ ����).\n" +" 2. 'relationship': 'subgoal' � ������������ � �������. ������������ ��� ���������� ������� ���� �� ������ ������ �����.\n" +"- ������� ����������� ������������:\n" +" * ����� ������� ���� �� ����� ������ ����� ���� ���������������. ���� ������� �������, ������ � �� � ����������� ������� (subgoals) � ���������������� ����.\n" +" * �� ������������� ����� ������� ��������. ������� �������� ������ (��������: ������� ���� -> ������� A -> ������� A.1 -> ������� A.1.1) � ��� ��������� � ��������������.\n" +"- ��� ��������� ������� ������������ � ��������-������������ ����� (����������):\n" +" * �� ����� ��� ��������� �������������! ���� ���� ������ ������� ������ ����������� ������ ���� �� ������ (���� ��������������� �����������), �� ������ ������� ������������ ���� ������ 'subgoal' ������ � ����� ������ ����� �������. ��� ����������� ���� ���� ������� �������� ��������������� ���� � ������ ����� 'sequential'.\n" +" * ��������� ��������� ����� �������� � �������� ����� 'subgoal' (�����������) ������ ���� ��� ������ ���������� ���� �� ����� � �� ����� ������ ������������ ��� � ����� ������� (��������: ���� ingredients � ���������� ������).\n" +" * �� ��������� ������������ �������� ��� ���������������� �����. ������� �� ����������������� ������ / ������. ������� ��������� / ����������� ������ �������� ������������.\n" +"- ���������� ������ �������� �����:\n" +" * ���� ���� ������� (��������, �������� ���, ������ ������), ������� ���������� ����� �� 3-5 �����.\n" +" * ���� ���� ������� (������� �����, �������� ����������������), ���������� ����������� ����� �� 8-15+ �����, ������������ ��� ������ ���� � �� ���������.\n" +"- ������� ��� ����� ����� (����������):\n" +" * 'sketch' � ����������� ���/���� (��������� � 99% �������). ����� ������� �������� ���, ���� ���� �� �������� ��������, ����� �������� (��������, '�������� 30 �����', '��������� 1 ���') ��� �������� ��������, ������ ����� ��� 'sketch'!\n" +" * 'habit' (��������) � ��������� ������ ������ ���� ������������ ����� ������ ���������� ����������, ���������/����������� ������������� �������� ��� ������������ �������� (��������, '������ ���� ���� ����'). ������� �� ��������� ��� ��� ������� ����� ��������!\n" +" * 'condition' (�������) � ��������� ������ ������ ��� ����� ���������� ���������, �������� � ������ (��������, '���� X, �� Y, ����� Z'). ������� �� ��������� ��� ��� ������� ����� � ���������� ����������, ���� ��� ��������� ����!\n" +"������� ���� ��� �������� �������� �������� (label) � ��������� �������� (description).\n" +"� ���� 'explanation' ������ �����, ������, ����������� � ������������� ����� �� ���� ����������� ������-��������. ������� � ������������� �� ������� ������������ �����, ��� ���������� ���������. ������� ����� ������ ������������ �����, ������ ������������ ����� ����������� �����������, � ������ ���������������, � ��� ������ ������������ ������ �� ���������� ����.";// 2. Call Gemini APIvar systemInstruction = "You are a warm, friendly, and highly professional Roadmap Strategist AI Agent. You design roadmaps represented as graphs (nodes and edges). You break down complex goals into hierarchical, deeply nested subgoals (recursive subgoals, where subgoals can have their own subgoals). You connect a parent to multiple parallel subgoals using 'subgoal' relationship ONLY if they can be done in parallel or in any order. If subgoals have chronological dependencies, connect the parent to the first subgoal in the sequence using 'subgoal' and chain the remaining subgoals using 'sequential' relationship. Node types MUST follow these rules: 'sketch' for 99% of regular tasks (including tasks with durations/wait times); 'habit' ONLY for repeating daily/weekly actions meant to form a routine, if explicitly requested; 'condition' ONLY for logical forks/branches with conditions. You adapt the graph size: 3-5 nodes for simple goals, 8-15+ nodes for complex goals. In the 'explanation' field, you write in a warm, direct, and conversational human tone, explaining the plan's logic and giving practical advice.";var responseJson = await CallGeminiApiAsync(prompt, systemInstruction, GoalResponseSchema);responseJson = CleanJson(responseJson);89 unmodified lines{throw new Exception("Graph not found.");}await CheckAndIncrementAiGenerationsLimitAsync(graph.UserId);// 1. Serialize existing nodes and edges for Gemini contextvar existingNodesText = new StringBuilder();18 unmodified lines"���� ������:\n" +"1. ���� ������ ������������ ������� ���������� ����� ���������, ����������� ��� ���������� �����: ���������� ����� ���� (NewNodes) � ����� ����� (NewEdges). ��� ���� ������ ������ �������� ���������� ������:\n" +" - � ��� ���� ��� ���� ������:\n" +" * 'relationship': 'sequential' � ���������������� ���� / ����. ������������ ��� �������� ���������, ��������� ����� ������� ������ ������ ����������, � ����� ��� ���������� ����� ������ ������� ������������ ���� � ������. ��������� ���� ��� ��� �����, ������� ������ �������������� ������� ���� �� ����� (��������: ����������� ���� -> �������� ����� -> ������ ����).\n" +" * 'relationship': 'subgoal' � ������������ � �������. ������������ ��� ���������� ������� ���� �� ������ ������ �����.\n" +" - ������� ����������� ������������:\n" +" * ����� ���� �� ����� ������ ����� ���� ���������������! ���� ������� ���� �� ���� �������, �� ������ ������� � �� � ����������� ������� (subgoals) � ���������������� ����.\n" +" * �� ������������� ����� ������� ��������. ������� �������� ������ (��������: ������� ���� -> ������� A -> ������� A.1 -> ������� A.1.1) � ��� ��������� � ��������������.\n" +" - ��� ��������� ������� ������������ � ��������-������������ ����� (����������):\n" +" * �� ����� ��� ��������� �������������! ���� ���� ������ ������� ������ ����������� ������ ���� �� ������ (���� ��������������� �����������), �� ������ ������� ������������ ���� ������ 'subgoal' ������ � ����� ������ ����� �������. ��� ����������� ���� ���� ������� �������� ��������������� ���� � ������ ����� 'sequential'.\n" +" * ��������� ��������� ����� �������� � �������� ����� 'subgoal' (�����������) ������ ���� ��� ������ ���������� ���� �� ����� � �� ����� ������ ������������ ��� � ����� �������.\n" +" * �� ��������� ������������ �������� ��� ���������������� �����. ������� �� ����������������� ������ / ������. ������� ��������� / ����������� ������ �������� ������������.\n" +" - ���������� ������ ����������:\n" +" * ���� ������������ ������ �������� ������� �������� ��� ������ ���������, ������ 1-3 ����.\n" +" * ���� ������������ ������ ��������� ��� ��������� ������� ����, ������ �����������, ������� � ��������� ���� �� 5-12 �����.\n" +" - ������� ��� ����� ����� (����������):\n" +" * 'sketch' � ����������� ���/���� (��������� � 99% �������). ����� ������� �������� ���, ���� ���� �� �������� ��������, ����� �������� (��������, '�������� 30 �����', '��������� 1 ���') ��� �������� ��������, ������ ����� ��� 'sketch'!\n" +" * 'habit' (��������) � ��������� ������ ������ ���� ������������ ����� ������ ���������� ����������, ���������/����������� ������������� �������� ��� ������������ �������� (��������, '������ ���� ���� ����'). ������� �� ��������� ��� ��� ������� ����� ��������!\n" +" * 'condition' (�������) � ��������� ������ ������ ��� ����� ���������� ���������, �������� � ������ (��������, '���� X, �� Y, ����� Z'). ������� �� ��������� ��� ��� ������� ����� � ���������� ����������, ���� ��� ��������� ����!\n" +" - �������� ����� ���� � ������������� ��� ���� � ������ � ������� ���������� ��������� ID (��������, new_step_1).\n" +"2. ���� ������ ������������ �� ������� ���������� ���������: ������ ������ 'NewNodes' � 'NewEdges' ������� ( [] ).\n" +"3. � ���� 'explanation' ������ ������������, ������, ����� � ����������� ����� �� ���� ��������-����������. ������ �� ������� ������������, ����� ������ ��������� ��������� ��� ������� ������ ������������ ����� �� ������� ������������ �����.";var systemInstruction = "You are a warm, friendly, and highly professional Roadmap Strategist AI Agent. You interact with the user, answer their questions, and help them design, extend, or analyze their roadmaps. If changes are needed, you return the new nodes and edges, breaking down complex tasks into hierarchical, deeply nested subgoals (recursive subgoals, where subgoals can have their own subgoals). You connect a parent to multiple parallel subgoals using 'subgoal' relationship ONLY if they can be done in parallel or in any order. If subgoals have chronological dependencies, connect the parent to the first subgoal in the sequence using 'subgoal' and chain the remaining subgoals using 'sequential' relationship. Node types MUST follow these rules: 'sketch' for 99% of regular tasks (including tasks with durations/wait times); 'habit' ONLY for repeating daily/weekly actions meant to form a routine, if explicitly requested; 'condition' ONLY for logical forks/branches with conditions. You never connect subgoals directly to unrelated nodes without a parent node. In the 'explanation' field, you write in a warm, direct, and conversational human tone, explaining your changes or answering user questions.";var contentsList = new List<object>();if (request.History != null){421 unmodified linesreturn textResponse;}private async Task CheckAndIncrementAiGenerationsLimitAsync(Guid userId){var user = await _userRepo.GetByIdAsync(userId);if (user == null) throw new Exception("User not found.");var today = DateTime.UtcNow.Date;if (user.LastAiGenerationDate.Date != today){user.DailyAiGenerationsCount = 0;user.LastAiGenerationDate = DateTime.UtcNow;}int limit = user.SubscriptionTier switch{"Free" => 3,"Pro" => 200,"Ultra" => int.MaxValue,_ => 3};if (user.DailyAiGenerationsCount >= limit){throw new InvalidOperationException($"Daily AI generation limit reached for your tier ({limit} generations per day).");}user.DailyAiGenerationsCount++;await _userRepo.UpdateAsync(user);}}}
FlowAPI.Application/Services/AIService.cs+57-25