MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / get_latest_user_text

Function get_latest_user_text

api_utils/utils_ext/string_utils.py:24–50  ·  view source on GitHub ↗

Extract the text content of the most recent user message (concatenating multiple text segments).

(messages: List[Message])

Source from the content-addressed store, hash-verified

22
23
24def get_latest_user_text(messages: List[Message]) -> str:
25 """Extract the text content of the most recent user message (concatenating multiple text segments)."""
26 for msg in reversed(messages):
27 if msg.role == "user":
28 content = msg.content
29 if isinstance(content, str):
30 return content
31 elif isinstance(content, list):
32 parts: List[str] = []
33 for it in content:
34 if isinstance(it, dict):
35 if it.get("type") == "text":
36 text_raw = it.get("text", "")
37 if isinstance(text_raw, str):
38 parts.append(text_raw)
39 else:
40 parts.append(str(text_raw))
41 elif hasattr(it, "type") and it.type == "text":
42 text_attr = getattr(it, "text", "")
43 if isinstance(text_attr, str):
44 parts.append(text_attr)
45 else:
46 parts.append(str(text_attr))
47 return "\n".join(p for p in parts if p)
48 else:
49 return ""
50 return ""

Callers 1

maybe_execute_toolsFunction · 0.90

Calls 1

getMethod · 0.45

Tested by

no test coverage detected