Streamline interactions with large language models (LLMs) like Claude via OpenRouter by processing natural language inputs into structured, pattern-matched outputs. routerflu ensures consistent, extractable responses for programming, data querying, or content creation tasks.
✅ Pattern-Matched Outputs – Forces LLM responses to follow strict regex patterns for reliability.
✅ Flexible LLM Integration – Works with LLM7 (default), OpenAI, Anthropic, Google, or any BaseChatModel.
✅ Environment-Aware – Uses LLM7_API_KEY from env vars or accepts direct API keys.
✅ Minimal Dependencies – Built on langchain and llmatch_messages.
pip install routerflufromrouterfluimportrouterfluresponse=routerflu(
user_input="Write a Python function to reverse a string."
)
print(response) # Structured output matching predefined patternsfromlangchain_openaiimportChatOpenAIfromrouterfluimportrouterflullm=ChatOpenAI()
response=routerflu(user_input="Explain how REST APIs work.", llm=llm)fromlangchain_anthropicimportChatAnthropicfromrouterfluimportrouterflullm=ChatAnthropic()
response=routerflu(user_input="Debug this SQL query.", llm=llm)fromlangchain_google_genaiimportChatGoogleGenerativeAIfromrouterfluimportrouterflullm=ChatGoogleGenerativeAI()
response=routerflu(user_input="Summarize this document.", llm=llm)- Default: Uses
LLM7_API_KEYfrom environment variables. - Manual Override:
routerflu(user_input="...", api_key="your_llm7_api_key")
- Get a Free Key:LLM7 Token Registration
- LLM7 Free Tier: Sufficient for most use cases.
- Upgrade: Use a custom API key or switch to a paid plan.
langchain-core(forBaseChatModel)llmatch_messages(for pattern extraction)langchain_llm7(default LLM provider)
routerflu(
user_input: str,
api_key: Optional[str] =None,
llm: Optional[BaseChatModel] =None
) ->List[str]user_input(str): Natural language prompt for the LLM.api_key(Optional[str]): LLM7 API key (falls back to env varLLM7_API_KEY).llm(Optional[BaseChatModel]): Custom LLM (e.g.,ChatOpenAI,ChatAnthropic).
- System Prompt: Guides the LLM to format responses strictly.
- Pattern Matching: Uses regex to extract structured data from responses.
- Error Handling: Raises
RuntimeErrorif LLM fails to comply.
MIT
- GitHub Issues:routerflu GitHub
- Author:Eugene Evstafev
- GitHub:@chigwell