update
This commit is contained in:
49
main.py
Normal file
49
main.py
Normal file
@@ -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)
|
||||
39
ui.py
Normal file
39
ui.py
Normal file
@@ -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("Введите описание задачи")
|
||||
Reference in New Issue
Block a user