Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions src/client/content/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/client/mcp/rag/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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.

Expand All @@ -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"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/mcp/rag/rag_base_optimizer_config_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions tests/client/content/config/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down