MCPcopy
hub / github.com/algorithmicsuperintelligence/optillm / _extract_content

Method _extract_content

optillm/leap.py:31–44  ·  view source on GitHub ↗

Validate a provider response and return its message content. Guards against the empty / None / length-truncated responses that would otherwise raise IndexError/TypeError downstream (e.g. when the content is fed to extract_output or split). Mirrors the response-validation

(self, response, context: str)

Source from the content-addressed store, hash-verified

29 return match.group(1).strip() if match else ""
30
31 def _extract_content(self, response, context: str) -> str:
32 """Validate a provider response and return its message content.
33
34 Guards against the empty / None / length-truncated responses that would
35 otherwise raise IndexError/TypeError downstream (e.g. when the content
36 is fed to extract_output or split). Mirrors the response-validation
37 idiom already used in moa/bon/plansearch.
38 """
39 if (response is None or
40 not response.choices or
41 response.choices[0].message.content is None or
42 response.choices[0].finish_reason == "length"):
43 raise Exception(f"LEAP: provider returned an empty, None, or truncated response while {context}")
44 return response.choices[0].message.content
45
46 def extract_examples_from_query(self, initial_query: str) -> List[Tuple[str, str]]:
47 logger.info("Extracting examples from initial query")

Calls

no outgoing calls

Tested by

no test coverage detected