create_us.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import requests
  2. import urllib3
  3. import os
  4. urllib3.disable_warnings()
  5. TAIGA_USER = os.environ.get('TAIGA_USER', 'FrancoisLange')
  6. TAIGA_PASS = os.environ.get('TAIGA_PASS', 'your_db_password_here')
  7. base_url = 'https://192.168.130.161/taiga/api/v1'
  8. project_id = 21
  9. def main():
  10. print("Connecting to Taiga...")
  11. auth_resp = requests.post(f'{base_url}/auth', json={'type': 'normal', 'username': TAIGA_USER, 'password': TAIGA_PASS}, verify=False)
  12. if auth_resp.status_code != 200:
  13. print("Auth failed!")
  14. return
  15. auth = auth_resp.json()
  16. headers = {
  17. 'Authorization': f'Bearer {auth["auth_token"]}',
  18. 'Content-Type': 'application/json',
  19. 'x-disable-pagination': 'true'
  20. }
  21. # 1. Check if the User Story already exists
  22. existing_us = requests.get(f'{base_url}/userstories?project={project_id}', headers=headers, verify=False).json()
  23. target_us = None
  24. subject_text = "Customer requesting a bigger model, more focus on the subject"
  25. for u in existing_us:
  26. if u['subject'].strip().lower() == subject_text.lower():
  27. target_us = u
  28. break
  29. # 2. Get active milestones to find a sprint
  30. sprints = requests.get(f'{base_url}/milestones?project={project_id}', headers=headers, verify=False).json()
  31. milestone_id = None
  32. # Use "Sprint 7: Production Hardening & Handover" if found, or first sprint
  33. sprint_7 = next((s for s in sprints if "Sprint 7" in s['name']), None)
  34. if sprint_7:
  35. milestone_id = sprint_7['id']
  36. print(f"Target Sprint: {sprint_7['name']} (ID: {milestone_id})")
  37. elif sprints:
  38. milestone_id = sprints[0]['id']
  39. print(f"Target Sprint (fallback): {sprints[0]['name']} (ID: {milestone_id})")
  40. if not target_us:
  41. print(f"Creating User Story: '{subject_text}'...")
  42. us_payload = {
  43. "project": project_id,
  44. "subject": subject_text,
  45. "description": "The customer requested upgrading to a larger local LLM (e.g. Qwen2.5-7B) for more precise and focused nutritional reasoning, while keeping calculations structured internally using a scratchpad structure to avoid raw thinking cluttering frontend layouts.",
  46. "milestone": milestone_id
  47. }
  48. res = requests.post(f'{base_url}/userstories', json=us_payload, headers=headers, verify=False)
  49. if res.status_code == 201:
  50. target_us = res.json()
  51. print(f"Successfully created User Story ID {target_us['id']} [Ref: {target_us['ref']}]!")
  52. else:
  53. print(f"Failed to create User Story: {res.status_code} {res.text}")
  54. return
  55. else:
  56. print(f"User Story already exists with ID {target_us['id']} [Ref: {target_us['ref']}]")
  57. us_id = target_us['id']
  58. us_ref = target_us['ref']
  59. # 3. Create the three tasks
  60. tasks_to_add = [
  61. {
  62. "subject": "Task 1: Update local LLM to Qwen2.5 (7B)",
  63. "description": "Update the local LLM configuration via Ollama to remove llama3.2:3b/1b and implement qwen2.5 (7B), ensuring it fits securely within our CPU and 30 GB RAM limits without exceeding our tight disk space."
  64. },
  65. {
  66. "subject": "Task 2: Refactor backend prompts to utilize <scratchpad> CoT structure",
  67. "description": "Refactor the Python backend prompts (sys_prompt and task_prompt) to utilize a <scratchpad> XML tag structure for internal Chain of Thought (CoT) calculations, specifically forcing conversions to grams and calorie summation."
  68. },
  69. {
  70. "subject": "Task 3: Implement Python parsing function to strip <scratchpad> block",
  71. "description": "Implement a Python parsing function (using regex or string splitting) to intercept the LLM's response, strip out the entire <scratchpad> block, and return only the final 5-column Markdown table to the frontend."
  72. }
  73. ]
  74. # Fetch existing tasks under this user story
  75. existing_tasks = requests.get(f'{base_url}/tasks?user_story={us_id}', headers=headers, verify=False).json()
  76. existing_subjects = {t['subject'] for t in existing_tasks}
  77. for task in tasks_to_add:
  78. subject = task['subject']
  79. if subject in existing_subjects:
  80. print(f"Task '{subject}' already exists. Skipping.")
  81. continue
  82. print(f"Creating task '{subject}'...")
  83. task_payload = {
  84. "project": project_id,
  85. "user_story": us_id,
  86. "subject": subject,
  87. "description": task['description'],
  88. "milestone": milestone_id
  89. }
  90. resp = requests.post(f'{base_url}/tasks', json=task_payload, headers=headers, verify=False)
  91. if resp.status_code == 201:
  92. print(f"Successfully created task '{subject}' [Ref: {resp.json()['ref']}]!")
  93. else:
  94. print(f"Failed to create task '{subject}': {resp.status_code} {resp.text}")
  95. if __name__ == '__main__':
  96. main()