From 939b7c3b8c1000ee40a8f6947102af2d131dc1ba Mon Sep 17 00:00:00 2001 From: Damir Date: Tue, 7 Apr 2026 18:53:46 +0300 Subject: [PATCH] update --- main.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ ui.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 main.py create mode 100644 ui.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..8f823bd --- /dev/null +++ b/main.py @@ -0,0 +1,49 @@ +from fastapi import FastAPI, HTTPException +import requests +import yaml +from pydantic import BaseModel + +app = FastAPI() + +OLLAMA_URL = "http://10.10.10.136:11434/api/generate" + +class Prompt(BaseModel): + task_description: str + model: str = "codellama" + +def validate_yaml(content: str): + try: + yaml.safe_load(content) + return True, "Valid YAML" + except yaml.YAMLError as exc: + return False, str(exc) + +@app.post("/generate_config") +async def generate_config(data: Prompt): + payload = { + "model": data.model, + "prompt": f"Generate only a valid CI/CD YAML configuration for the following task: {data.task_description}. Return ONLY the code block.", + "stream": False + } + + try: + response = requests.post(OLLAMA_URL, json=payload) + response_data = response.json() + generated_text = response_data.get("response", "") + + # Очистка от markdown-тегов, если модель их добавила + config_content = generated_text.replace("```yaml", "").replace("```", "").strip() + + is_valid, message = validate_yaml(config_content) + + return { + "config": config_content, + "is_valid": is_valid, + "validation_message": message + } + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + +if __name__ == "__main__": + import uvicorn + uvicorn.run(app, host="0.0.0.0", port=8000) \ No newline at end of file diff --git a/ui.py b/ui.py new file mode 100644 index 0000000..07131d0 --- /dev/null +++ b/ui.py @@ -0,0 +1,39 @@ +import streamlit as st +import requests + +st.set_page_config(page_title="AI DevOps Assistant", layout="wide") + +st.title("🚀 CI/CD AI Generator & Validator") +st.subheader("Генерация и проверка конфигураций пайплайнов") + +backend_url = "http://localhost:8000/generate_config" + +with st.sidebar: + st.info("Настройки") + model_name = st.selectbox("Выберите модель Ollama", ["codellama", "llama3", "mistral"]) + +task = st.text_area("Опишите задачу (напр. 'Pipeline for Dockerized Node.js app with Jest tests'):") + +if st.button("Сгенерировать и проверить"): + if task: + with st.spinner("ИИ формирует конфигурацию..."): + res = requests.post(backend_url, json={"task_description": task, "model": model_name}) + if res.status_code == 200: + data = res.json() + + col1, col2 = st.columns(2) + + with col1: + st.markdown("### Сгенерированный YAML") + st.code(data["config"], language="yaml") + + with col2: + st.markdown("### Статус валидации") + if data["is_valid"]: + st.success("✅ Конфигурация синтаксически верна") + else: + st.error(f"❌ Ошибка в YAML: {data['validation_message']}") + else: + st.error("Ошибка связи с бекендом") + else: + st.warning("Введите описание задачи") \ No newline at end of file