Conversation
WalkthroughThis PR refactors LLM factory and authentication handling by casting configuration parameters to strings, simplifying RootFlo authentication validation to require only base_url, making api_token optional with fallback handling, and expanding the stream method signature with kwargs support. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
flo_ai/flo_ai/helpers/llm_factory.py (2)
141-146: Avoid convertingNoneVertexAI base_url into the string"None"For VertexAI,
base_urlis optional. If it’s omitted,base_urlwill beNone, andstr(base_url)will turn that into the literal"None", which is likely not a valid URL and may regress existing configurations that relied on the default behavior when no base_url is provided.Consider guarding the cast:
- return VertexAI( - model=model_name, - project=project, - location=location, - base_url=str(base_url), - ) + return VertexAI( + model=model_name, + project=project, + location=location, + base_url=str(base_url) if base_url is not None else None, + )
167-179: PassNonetoOpenAIVLLMwhenapi_keyis not provided instead of stringifying itWhen
api_keyis not provided,str(None)converts it to the string"None", which theAsyncOpenAIclient treats as an actual API key rather than a missing value. This prevents the client from falling back to theOPENAI_API_KEYenvironment variable and instead attempts authentication with the literal string"None", causing authentication failures.Pass
Nonedirectly when the key is absent:return OpenAIVLLM( model=model_name, base_url=str(base_url), - api_key=str(api_key), + api_key=str(api_key) if api_key is not None else None, temperature=temperature, )flo_ai/flo_ai/llm/base_llm.py (1)
28-35: OllamaLLM.stream() missing**kwargs—add it to match abstract signatureThe abstract
streammethod now accepts**kwargs, butOllamaLLM.stream()does not include this parameter. Its signature only hasmessagesandfunctions, which means any polymorphic call to aBaseLLMinstance with extra kwargs will raiseTypeErrorif it's anOllamaLLM.Update
OllamaLLM.stream()inflo_ai/flo_ai/llm/ollama_llm.py(line 73) to accept**kwargs: Anyto match the abstract method signature. All other subclasses (OpenAI, Gemini, Anthropic, RootFloLLM) already have this parameter.flo_ai/flo_ai/llm/rootflo_llm.py (1)
175-196: Add validation for JWT required fields before token generationJWT generation at lines 179–191 assumes
_issuerand_audienceare present, but both are Optional[str] with None defaults (lines 37–38). The payload is built without validation, resulting in'iss': Noneand'aud': Nonewhen these fields are not provided. Add a check before generating JWT:- elif self._app_key and self._app_secret: + elif self._app_key and self._app_secret and self._issuer and self._audience:Replace
'no_token'sentinel withNonefor missing API keysLines 225, 234, 243, and 254 use
api_token or 'no_token'. The'no_token'string sends a literalAuthorization: Bearer no_tokenheader, which differs from the SDK's expected behavior when api_key isNone. WithNone, OpenAI and Anthropic SDKs properly fall back to environment variables or internal handling. To preserve correct SDK semantics:- api_key=api_token or 'no_token', + api_key=api_token,Apply this change for OpenAI, Anthropic, Gemini, and OpenAIVLLM instantiations. (Note: This may require adjusting your Istio mesh configuration if
'no_token'was relied upon as a workaround for request routing.)
🧹 Nitpick comments (1)
flo_ai/flo_ai/llm/rootflo_llm.py (1)
98-105: Optionalapi_tokenand conditionalAuthorizationheader align with mesh-based auth; update docstringMaking
api_tokenoptional and only adding theAuthorizationheader when it’s present is exactly what you want for Istio/service‑mesh scenarios where auth is injected.Minor nit: the docstring for
api_tokenstill reads as if it’s always supplied (“The JWT token for authorization”). Consider clarifying that it’s optional and that when omitted, no Authorization header is sent.Also applies to: 120-128
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
flo_ai/flo_ai/helpers/llm_factory.py(3 hunks)flo_ai/flo_ai/llm/base_llm.py(1 hunks)flo_ai/flo_ai/llm/rootflo_llm.py(7 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
flo_ai/flo_ai/helpers/llm_factory.py (1)
flo_ai/flo_ai/llm/rootflo_llm.py (1)
RootFloLLM(25-307)
🔇 Additional comments (2)
flo_ai/flo_ai/helpers/llm_factory.py (1)
192-219: RootFlo base_url validation looks good; string cast is safe hereThe new RootFlo block now only requires
base_url(from kwargs, model_config, orROOTFLO_BASE_URL), which aligns with the intent to support Istio/mesh‑based auth. The error message is clear and centralizes validation.Because of the preceding
if not base_url: raise ValueError,base_url=str(base_url)in theRootFloLLMctor is safe and should not suffer from the"None"issue mentioned for VertexAI.flo_ai/flo_ai/llm/rootflo_llm.py (1)
278-284:RootFloLLM.streamnow cleanly matches the extended interfaceThe
streammethod here now accepts**kwargsand passes them through to the underlying_llm.stream, which keeps RootFloLLM in sync with the updatedBaseLLM.streamand allows extra streaming options without further changes.
Summary by CodeRabbit
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.