str.strip
str.strip(...)Description
Documentation for str.strip.
Real-World Examples
Practical code examples showing how str.strip is used in real projects.
# 提取子主题
sub_topics = []
sub_topics_text = self._extract_tag(extracted_responses[self.BASIC_QUERY_INDEX], "sub_topics")
if sub_topics_text:
sub_topics = [topic.strip() for topic in sub_topics_text.split(",")]
# 提取语言
language = self._extract_tag(extracted_responses[self.BASIC_QUERY_INDEX], "language")
# 提取最低星标数
min_stars = 0
min_stars_text = self._extract_tag(extracted_responses[self.BASIC_QUERY_INDEX], "min_stars")
if min_stars_text and min_stars_text.isdigit():
min_stars = int(min_stars_text)
# 解析GitHub搜索参数 - 英文
english_github_query = self._extract_tag(extracted_responses[self.GITHUB_QUERY_INDEX], "query")
# 解析GitHub搜索参数 - 中文
chinese_github_query = self._extract_tag(extracted_responses[2], "query")
# 构建GitHub参数
github_params = {
"query": english_github_query,
try:
response = self.llm.invoke(prompt)
# Handle different response formats (string or object with content attribute)
if hasattr(response, "content"):
optimized_query = response.content.strip()
else:
# Handle string responses
optimized_query = str(response).strip()
# Validate the optimized query
if optimized_query and len(optimized_query) > 0:
logger.info(
f"LLM optimized query from '{query}' to '{optimized_query}'"
)
return optimized_query
else:
logger.warning("LLM returned empty query, using original")
return query
except Exception:
logger.exception("Error optimizing query with LLM")
return query
def _search_github(self, query: str) -> List[Dict[str, Any]]: