reflex-examples icon indicating copy to clipboard operation
reflex-examples copied to clipboard

Add orcarouter_chat example

Open zhenjunchen-png opened this issue 6 months ago • 1 comments

Adds an orcarouter_chat example: a minimal Reflex chat app that calls OrcaRouter, an OpenAI-compatible LLM gateway, and lets you switch the model from a dropdown populated at startup from OrcaRouter's public pricing catalog, with a curated fallback list when that endpoint is unreachable.

Disclosure: I'm an engineer on the OrcaRouter team.

zhenjunchen-png avatar May 30 '26 07:05 zhenjunchen-png

Greptile Summary

This PR adds a new orcarouter_chat example: a minimal Reflex streaming chat app that uses OrcaRouter as an OpenAI-compatible LLM gateway, with a runtime-populated model dropdown and optional fallback routing.

  • State architecture: ConfigState (model picker, catalog fetch) and ChatState (streaming, messages) are deliberately split to avoid re-rendering the model picker on every streamed token — a sound Reflex pattern.
  • Catalog loading: load_models correctly uses @rx.event(background=True) and snapshots state before the 10-second HTTP call, though the get_state(ConfigState) call inside the async with self: block in submit (line 243) still holds ChatState's lock while acquiring ConfigState's lock, which was flagged in a previous review thread and remains unaddressed.
  • Resilience: graceful fallback to a curated model list, temperature-retry logic for reasoning models, and user-visible error callouts are all well-handled.

Confidence Score: 3/5

The main app file has a concurrency issue in the submit path that should be resolved before this example ships.

In submit, await self.get_state(ConfigState) is called on line 243 while ChatState's state lock is still held (the async with self: block opened on line 231 has not yet exited). This means every message send holds ChatState's lock while waiting to acquire ConfigState's lock — any concurrent event that needs ChatState (e.g. the user typing the next message) is blocked for the entire duration. The issue was flagged in a prior review round and is still present in the current code.

orcarouter_chat/orcarouter_chat/orcarouter_chat.py — specifically the submit background handler around lines 231–246.

Important Files Changed

Filename Overview
orcarouter_chat/orcarouter_chat/orcarouter_chat.py Core app file with ConfigState/ChatState split, background streaming, and live model catalog fetch. Contains an unresolved cross-state lock hold: get_state(ConfigState) is awaited on line 243 while ChatState's lock is still held from async with self: on line 231, blocking any concurrent state mutation (e.g., typing) until ConfigState's lock is also free.
orcarouter_chat/rxconfig.py Minimal Reflex config; correctly points env_file to .env so the API key is loaded at startup.
orcarouter_chat/requirements.txt Four dependencies with appropriate minimum versions; all are used directly by the app.
orcarouter_chat/README.md Clear setup guide covering key acquisition, env file, and reflex run; accurately describes what the example demonstrates.
orcarouter_chat/.env.example Single-line placeholder for the API key; correct and minimal.
orcarouter_chat/.gitignore Standard Reflex gitignore entries including .env and .venv/; no concerns.
orcarouter_chat/orcarouter_chat/init.py Empty init file; expected for a Reflex app package.

Reviews (3): Last reviewed commit: "Guard against Clear during streaming" | Re-trigger Greptile

greptile-apps avatar May 30 '26 07:05 greptile-apps

👋 Friendly nudge — I don't think CI has triggered here yet. Anything needed from my side, or does it require a maintainer to approve the run? Thanks!

jinhaosong-source avatar Jul 09 '26 03:07 jinhaosong-source