Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /GRID-INTELLIGENCE_GRID /src /grid /skills /context_refine.py
| from __future__ import annotations | |
| import re | |
| from collections.abc import Mapping | |
| from typing import Any | |
| from .base import SimpleSkill | |
| _PRONOUNS = re.compile( | |
| r"\b(i|me|my|mine|we|us|our|ours|you|your|yours|he|him|his|she|her|hers|they|them|their|theirs|it|its|this|that|these|those)\b", | |
| re.IGNORECASE, | |
| ) | |
| def _refine(args: Mapping[str, Any]) -> dict[str, Any]: | |
| text = args.get("text") or args.get("input") | |
| if text is None: | |
| return { | |
| "skill": "context.refine", | |
| "status": "error", | |
| "error": "Missing required parameter: 'text'", | |
| } | |
| text = str(text) | |
| use_llm = bool(args.get("use_llm") or args.get("useLLM")) | |
| if use_llm: | |
| try: | |
| import importlib | |
| rag_config_module = importlib.import_module("tools.rag.config") | |
| rag_llm_module = importlib.import_module("tools.rag.llm.factory") | |
| RAGConfig = rag_config_module.RAGConfig | |
| get_llm_provider = rag_llm_module.get_llm_provider | |
| config = RAGConfig.from_env() | |
| config.ensure_local_only() | |
| llm = get_llm_provider(config=config) | |
| prompt = ( | |
| "Rewrite the text into a refined structured form with minimal noise.\n" | |
| "Rules:\n" | |
| "- Avoid pronouns. Replace pronouns with explicit nouns where possible.\n" | |
| "- Prefer bullet points and short sentences.\n" | |
| "- Preserve technical meaning.\n" | |
| "- Output sections: Facts, Assumptions, Goals, Constraints, Next actions.\n\n" | |
| f"TEXT:\n{text}\n" | |
| ) | |
| out = llm.generate(prompt=prompt, temperature=0.2) | |
| return { | |
| "skill": "context.refine", | |
| "status": "success", | |
| "output": out.strip(), | |
| } | |
| except Exception as e: | |
| return { | |
| "skill": "context.refine", | |
| "status": "error", | |
| "error": str(e), | |
| } | |
| # Heuristic fallback: remove pronouns + normalize whitespace | |
| cleaned = _PRONOUNS.sub("", text) | |
| cleaned = re.sub(r"\s+", " ", cleaned).strip() | |
| return { | |
| "skill": "context.refine", | |
| "status": "success", | |
| "output": cleaned, | |
| "note": "Heuristic mode used. Enable use_llm for higher-quality rewriting.", | |
| } | |
| context_refine = SimpleSkill( | |
| id="context.refine", | |
| name="Context Refine", | |
| description="Refine context into structured, pronoun-minimized text for clarity", | |
| handler=_refine, | |
| ) | |
Xet Storage Details
- Size:
- 2.57 kB
- Xet hash:
- d7865e7e5c3efce178bdc739cbe4de627e7682b35b60730bca2225c6d5a91eb2
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.