Spaces:
Sleeping
Sleeping
Ali Hmaou commited on
Commit ·
c4472ea
1
Parent(s): 462be19
Version 1.5RC
Browse files- src/mcp_server/server.py +7 -10
src/mcp_server/server.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
import json
|
|
|
|
| 5 |
|
| 6 |
# Ajout du répertoire racine au path pour permettre les imports absolus 'src.xxx'
|
| 7 |
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
|
@@ -31,7 +32,7 @@ PROVIDER_MODELS = {
|
|
| 31 |
# --- Wrappers pour Gradio UI (Exposed as MCP Tools) ---
|
| 32 |
# Ces wrappers permettent d'avoir une UI conviviale tout en exposant les fonctions via MCP avec des noms explicites pour les agents.
|
| 33 |
|
| 34 |
-
def step_1_initialisation_and_proposal(project_name, description,
|
| 35 |
"""
|
| 36 |
STEP 1: Starts a new tool project and uses AI to propose code.
|
| 37 |
|
|
@@ -40,12 +41,11 @@ def step_1_initialisation_and_proposal(project_name, description, type, model_id
|
|
| 40 |
Args:
|
| 41 |
project_name: The technical name of the tool (e.g., 'weather-fetcher').
|
| 42 |
description: A natural language description of what the tool should do, or a raw Swagger/OpenAPI JSON specification.
|
| 43 |
-
type: The type of tool pattern (e.g., 'adhoc' for custom logic, 'api_wrapper' for REST clients).
|
| 44 |
model_id: The LLM model to use for code generation (default: Qwen/Qwen2.5-Coder-32B-Instruct).
|
| 45 |
provider_id: The inference provider to use. Options: 'together', 'fal-ai', 'replicate', 'sambanova', 'hyperbolic', or None (auto).
|
| 46 |
"""
|
| 47 |
-
# 1. Initialisation du projet
|
| 48 |
-
init_result = tools.init_project(project_name, description, type)
|
| 49 |
draft_id = init_result.get("draft_id", "")
|
| 50 |
|
| 51 |
# 2. Génération de la proposition par LLM
|
|
@@ -70,7 +70,7 @@ def step_1_initialisation_and_proposal(project_name, description, type, model_id
|
|
| 70 |
out_comp # output_component_ui (Dropdown)
|
| 71 |
)
|
| 72 |
|
| 73 |
-
def step_2_logic_definition(draft_id, python_code, inputs, output_desc, requirements, output_component):
|
| 74 |
"""
|
| 75 |
STEP 2: Validates and saves the tool code.
|
| 76 |
|
|
@@ -289,9 +289,6 @@ with gr.Blocks(title="Meta-MCP Fractal") as demo:
|
|
| 289 |
placeholder="Décrivez ce que doit faire l'outil, ou collez ici le contenu d'un fichier swagger.json pour générer un client API automatiquement."
|
| 290 |
)
|
| 291 |
|
| 292 |
-
with gr.Row():
|
| 293 |
-
project_type = gr.Dropdown(choices=["adhoc", "api_wrapper"], value="adhoc", label="Type")
|
| 294 |
-
|
| 295 |
with gr.Accordion("Paramètres IA (Avancé)", open=False):
|
| 296 |
provider_id = gr.Dropdown(
|
| 297 |
label="Provider d'Inférence",
|
|
@@ -413,8 +410,8 @@ with gr.Blocks(title="Meta-MCP Fractal") as demo:
|
|
| 413 |
# 1. Init -> Remplissage auto de l'onglet 2 (Logic) et copie de l'ID vers onglet 3 (Deploy)
|
| 414 |
btn_init.click(
|
| 415 |
step_1_initialisation_and_proposal,
|
| 416 |
-
inputs=[project_name, project_desc,
|
| 417 |
-
outputs=[out_init, draft_id_logic, python_code, inputs_dict, output_desc, requirements_box
|
| 418 |
api_name="step_1_initialisation_and_proposal"
|
| 419 |
).then(
|
| 420 |
fn=lambda x: x,
|
|
|
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
import json
|
| 5 |
+
from typing import List, Dict, Any
|
| 6 |
|
| 7 |
# Ajout du répertoire racine au path pour permettre les imports absolus 'src.xxx'
|
| 8 |
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
|
|
|
| 32 |
# --- Wrappers pour Gradio UI (Exposed as MCP Tools) ---
|
| 33 |
# Ces wrappers permettent d'avoir une UI conviviale tout en exposant les fonctions via MCP avec des noms explicites pour les agents.
|
| 34 |
|
| 35 |
+
def step_1_initialisation_and_proposal(project_name, description, model_id, provider_id):
|
| 36 |
"""
|
| 37 |
STEP 1: Starts a new tool project and uses AI to propose code.
|
| 38 |
|
|
|
|
| 41 |
Args:
|
| 42 |
project_name: The technical name of the tool (e.g., 'weather-fetcher').
|
| 43 |
description: A natural language description of what the tool should do, or a raw Swagger/OpenAPI JSON specification.
|
|
|
|
| 44 |
model_id: The LLM model to use for code generation (default: Qwen/Qwen2.5-Coder-32B-Instruct).
|
| 45 |
provider_id: The inference provider to use. Options: 'together', 'fal-ai', 'replicate', 'sambanova', 'hyperbolic', or None (auto).
|
| 46 |
"""
|
| 47 |
+
# 1. Initialisation du projet (type 'adhoc' par défaut)
|
| 48 |
+
init_result = tools.init_project(project_name, description, type="adhoc")
|
| 49 |
draft_id = init_result.get("draft_id", "")
|
| 50 |
|
| 51 |
# 2. Génération de la proposition par LLM
|
|
|
|
| 70 |
out_comp # output_component_ui (Dropdown)
|
| 71 |
)
|
| 72 |
|
| 73 |
+
def step_2_logic_definition(draft_id: str, python_code: str, inputs: Dict[str, Any], output_desc: str, requirements: List[str], output_component: str = "text"):
|
| 74 |
"""
|
| 75 |
STEP 2: Validates and saves the tool code.
|
| 76 |
|
|
|
|
| 289 |
placeholder="Décrivez ce que doit faire l'outil, ou collez ici le contenu d'un fichier swagger.json pour générer un client API automatiquement."
|
| 290 |
)
|
| 291 |
|
|
|
|
|
|
|
|
|
|
| 292 |
with gr.Accordion("Paramètres IA (Avancé)", open=False):
|
| 293 |
provider_id = gr.Dropdown(
|
| 294 |
label="Provider d'Inférence",
|
|
|
|
| 410 |
# 1. Init -> Remplissage auto de l'onglet 2 (Logic) et copie de l'ID vers onglet 3 (Deploy)
|
| 411 |
btn_init.click(
|
| 412 |
step_1_initialisation_and_proposal,
|
| 413 |
+
inputs=[project_name, project_desc, model_id, provider_id],
|
| 414 |
+
outputs=[out_init, draft_id_logic, python_code, inputs_dict, output_desc, requirements_box],
|
| 415 |
api_name="step_1_initialisation_and_proposal"
|
| 416 |
).then(
|
| 417 |
fn=lambda x: x,
|