Nymbo commited on
Commit
4853dce
·
verified ·
1 Parent(s): 19a37f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -15,7 +15,7 @@ import sys
15
  import os
16
  import random
17
  from io import StringIO
18
- from typing import List, Dict, Tuple, Annotated, Literal
19
 
20
  import gradio as gr
21
  import requests
@@ -1104,11 +1104,11 @@ kokoro_interface = gr.Interface(
1104
 
1105
  def Memory_Tool(
1106
  action: Annotated[Literal["save","list","search","delete"], "Action to perform: save | list | search | delete"],
1107
- text: Annotated[str, "Text content (used when action=save)"] = "",
1108
- tags: Annotated[str, "Comma-separated tags (used when action=save)"] = "",
1109
- query: Annotated[str, "Search query terms (used when action=search)"] = "",
1110
  limit: Annotated[int, "Max results for list/search (1–200)"] = 20,
1111
- memory_id: Annotated[str, "Full UUID or unique prefix (used when action=delete)"] = "",
1112
  include_tags: Annotated[bool, "Include tags in list/search output"] = True,
1113
  ) -> str:
1114
  """Manage lightweight local JSON “memories” (save | list | search | delete) in one MCP tool.
@@ -1159,13 +1159,26 @@ def Memory_Tool(
1159
  Plaintext JSON; do not store secrets, credentials, or regulated personal data.
1160
  """
1161
  act = (action or "").lower().strip()
 
 
 
 
 
 
 
1162
  if act == "save":
 
 
1163
  return _mem_save(text=text, tags=tags)
1164
  if act == "list":
1165
  return _mem_list(limit=limit, include_tags=include_tags)
1166
  if act == "search":
 
 
1167
  return _mem_search(query=query, limit=limit)
1168
  if act == "delete":
 
 
1169
  return _mem_delete(memory_id=memory_id)
1170
  return "Error: invalid action (use save|list|search|delete)."
1171
 
 
15
  import os
16
  import random
17
  from io import StringIO
18
+ from typing import List, Dict, Tuple, Annotated, Literal, Optional
19
 
20
  import gradio as gr
21
  import requests
 
1104
 
1105
  def Memory_Tool(
1106
  action: Annotated[Literal["save","list","search","delete"], "Action to perform: save | list | search | delete"],
1107
+ text: Annotated[Optional[str], "Text content (used when action=save)"] = None,
1108
+ tags: Annotated[Optional[str], "Comma-separated tags (used when action=save)"] = None,
1109
+ query: Annotated[Optional[str], "Search query terms (used when action=search)"] = None,
1110
  limit: Annotated[int, "Max results for list/search (1–200)"] = 20,
1111
+ memory_id: Annotated[Optional[str], "Full UUID or unique prefix (used when action=delete)"] = None,
1112
  include_tags: Annotated[bool, "Include tags in list/search output"] = True,
1113
  ) -> str:
1114
  """Manage lightweight local JSON “memories” (save | list | search | delete) in one MCP tool.
 
1159
  Plaintext JSON; do not store secrets, credentials, or regulated personal data.
1160
  """
1161
  act = (action or "").lower().strip()
1162
+
1163
+ # Normalize None -> "" for internal helpers
1164
+ text = text or ""
1165
+ tags = tags or ""
1166
+ query = query or ""
1167
+ memory_id = memory_id or ""
1168
+
1169
  if act == "save":
1170
+ if not text.strip():
1171
+ return "Error: 'text' is required when action=save."
1172
  return _mem_save(text=text, tags=tags)
1173
  if act == "list":
1174
  return _mem_list(limit=limit, include_tags=include_tags)
1175
  if act == "search":
1176
+ if not query.strip():
1177
+ return "Error: 'query' is required when action=search."
1178
  return _mem_search(query=query, limit=limit)
1179
  if act == "delete":
1180
+ if not memory_id.strip():
1181
+ return "Error: 'memory_id' is required when action=delete."
1182
  return _mem_delete(memory_id=memory_id)
1183
  return "Error: invalid action (use save|list|search|delete)."
1184