diff --git a/src/client/content/config/settings.py b/src/client/content/config/settings.py index 28c148ea..d4402f05 100644 --- a/src/client/content/config/settings.py +++ b/src/client/content/config/settings.py @@ -228,6 +228,36 @@ def spring_ai_zip(provider, ll_config, embed_config): zip_buffer.seek(0) return zip_buffer +def langchain_mcp_zip(settings): + """Create LangChain MCP Zip File""" + + # Source directory that you want to copy + src_dir = Path(__file__).resolve().parents[2] / "mcp/rag" + + # Using TemporaryDirectory + with tempfile.TemporaryDirectory() as temp_dir: + dst_dir = os.path.join(temp_dir, "langchain_mcp") + logger.info("Starting langchain mcp zip processing: %s", dst_dir) + + shutil.copytree(src_dir, dst_dir) + + data=save_settings(settings) + settings_path = os.path.join(dst_dir, "optimizer_settings.json") + with open(settings_path, "w") as f: + f.write(data) + + zip_buffer = io.BytesIO() + with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zip_file: + for foldername, _, filenames in os.walk(dst_dir): + for filename in filenames: + file_path = os.path.join(foldername, filename) + + arc_name = os.path.relpath(file_path, dst_dir) # Make the path relative + zip_file.write(file_path, arc_name) + zip_buffer.seek(0) + return zip_buffer + + ##################################################### # MAIN @@ -284,7 +314,7 @@ def main(): else: st.info("Please upload a Settings file.") - st.header("SpringAI Settings", divider="red") + st.header("Export source code templates", divider="red") # Merge the User Settings into the Model Config model_lookup = st_common.state_configs_lookup("model_configs", "id") try: @@ -307,13 +337,23 @@ def main(): - Embedding Model: **{embed_config.get("model", "Unset")}** """) else: - st.download_button( + col_left, col_centre, _ = st.columns([3, 4, 3]) + with col_left: + st.download_button( label="Download SpringAI", data=spring_ai_zip(spring_ai_conf, ll_config, embed_config), # Generate zip on the fly file_name="spring_ai.zip", # Zip file name mime="application/zip", # Mime type for zip file disabled=spring_ai_conf == "hybrid", ) + with col_centre: + st.download_button( + label="Download LangchainMCP", + data=langchain_mcp_zip(settings), # Generate zip on the fly + file_name="langchain_mcp.zip", # Zip file name + mime="application/zip", # Mime type for zip file + disabled=spring_ai_conf == "hybrid", + ) if __name__ == "__main__" or "page.py" in inspect.stack()[1].filename: diff --git a/src/client/mcp/rag/README.md b/src/client/mcp/rag/README.md index 37061b7a..be28b8e8 100644 --- a/src/client/mcp/rag/README.md +++ b/src/client/mcp/rag/README.md @@ -120,7 +120,7 @@ rag.set_optimizer_settings_path("/Users/cdebari/Documents/GitHub/ai-optimizer-mc * Substitute `Local` with `Remote client` line: ```python -#mcp = FastMCP("rag", port=8001) #Remote client +#mcp = FastMCP("rag", port=9001) #Remote client mcp = FastMCP("rag") #Local ``` @@ -148,7 +148,7 @@ npx @modelcontextprotocol/inspector * set the Transport Type to `SSE` -* set the `URL` to `http://localhost:8001/sse` +* set the `URL` to `http://localhost:9001/sse` * test the tool developed. @@ -166,7 +166,7 @@ If you have already installed Node.js v20.17.0+, it should work: "command": "npx", "args": [ "mcp-remote", - "http://127.0.0.1:8001/sse" + "http://127.0.0.1:9001/sse" ] } } diff --git a/src/client/mcp/rag/rag_base_optimizer_config_mcp.py b/src/client/mcp/rag/rag_base_optimizer_config_mcp.py index d6d767ef..48239b04 100644 --- a/src/client/mcp/rag/rag_base_optimizer_config_mcp.py +++ b/src/client/mcp/rag/rag_base_optimizer_config_mcp.py @@ -24,7 +24,7 @@ data = {} # Initialize FastMCP server -#mcp = FastMCP("rag", port=8001) #Remote client +#mcp = FastMCP("rag", port=9001) #Remote client mcp = FastMCP("rag") #Local diff --git a/tests/client/content/config/test_settings.py b/tests/client/content/config/test_settings.py index a22c940b..17479ac2 100644 --- a/tests/client/content/config/test_settings.py +++ b/tests/client/content/config/test_settings.py @@ -55,7 +55,7 @@ def test_spring_ai_section_exists(self, app_server, app_test): assert app_server is not None at = app_test(self.ST_FILE).run() - # Check for SpringAI across all text elements - could be in title, header, markdown, etc. + # Check for Export source code templates across all text elements - could be in title, header, markdown, etc. page_text = [] # Check in markdown elements @@ -85,8 +85,8 @@ def test_spring_ai_section_exists(self, app_server, app_test): if hasattr(div, "label"): page_text.append(div.label) - # Assert that SpringAI is mentioned somewhere in the page - assert any("SpringAI" in text for text in page_text), "SpringAI section not found in page" + # Assert that Export source code templates is mentioned somewhere in the page + assert any("Export source code templates" in text for text in page_text), "Export source code templates section not found in page" def test_compare_with_uploaded_json(self, app_server, app_test): """Test the compare_with_uploaded_json function for finding differences in settings"""