feat: pplx channel - #1998
Conversation
WalkthroughIntroduces Perplexity as a channel across backend and web UI, delegates Perplexity adaptor request/response handling to the OpenAI adaptor, expands Perplexity model list, and extends dto.GeneralOpenAIRequest with new search-related fields. Updates UI constants and icon mapping to surface Perplexity and enable model fetching. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant PerplexityAdaptor as Perplexity Adaptor
participant OpenAIAdaptor as OpenAI Adaptor
participant Downstream as Provider API
rect rgb(240,248,255)
note over Client,PerplexityAdaptor: Request conversion (Claude-style -> OpenAI-style)
Client->>PerplexityAdaptor: ConvertClaudeRequest(req, info, c)
PerplexityAdaptor->>OpenAIAdaptor: ConvertClaudeRequest(req, info, c)
OpenAIAdaptor-->>PerplexityAdaptor: Converted OpenAI request
PerplexityAdaptor-->>Client: Converted request
end
rect rgb(245,255,245)
note over Client,PerplexityAdaptor: Response handling (stream/non-stream)
Client->>PerplexityAdaptor: DoResponse(req, info, respWriter)
PerplexityAdaptor->>OpenAIAdaptor: DoResponse(req, info, respWriter)
OpenAIAdaptor->>Downstream: Send/stream request
Downstream-->>OpenAIAdaptor: Response/stream
OpenAIAdaptor-->>PerplexityAdaptor: Processed response
PerplexityAdaptor-->>Client: Final response/stream
end
sequenceDiagram
autonumber
participant Inbound as Inbound Perplexity Request
participant Relay as relay-perplexity
participant DTO as GeneralOpenAIRequest
Inbound->>Relay: Build request
Relay->>DTO: Set core fields
Relay->>DTO: Set search fields: SearchDomainFilter, SearchRecencyFilter, SearchMode
Relay->>DTO: Set flags: ReturnImages, ReturnRelatedQuestions
Relay-->>Inbound: DTO ready
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
relay/channel/perplexity/adaptor.go (1)
25-28: Consider caching the OpenAI adaptor instance (optional optimization).The delegation to
openai.Adaptoris clean and appropriate if Perplexity's API is OpenAI-compatible. However, creating a new adaptor instance on each call could be optimized by caching it as a field in the Perplexity Adaptor struct.Optional optimization:
type Adaptor struct { + openaiAdaptor openai.Adaptor } -func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayInfo, req *dto.ClaudeRequest) (any, error) { - adaptor := openai.Adaptor{} - return adaptor.ConvertClaudeRequest(c, info, req) +func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayInfo, req *dto.ClaudeRequest) (any, error) { + return a.openaiAdaptor.ConvertClaudeRequest(c, info, req) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
dto/openai_request.go(1 hunks)relay/channel/perplexity/adaptor.go(2 hunks)relay/channel/perplexity/constants.go(1 hunks)relay/channel/perplexity/relay-perplexity.go(1 hunks)web/src/components/table/channels/modals/EditChannelModal.jsx(1 hunks)web/src/constants/channel.constants.js(1 hunks)web/src/helpers/render.jsx(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
relay/channel/perplexity/adaptor.go (3)
relay/channel/openai/adaptor.go (1)
Adaptor(32-35)relay/common/relay_info.go (1)
RelayInfo(74-121)dto/claude.go (1)
ClaudeRequest(187-207)
🔇 Additional comments (8)
relay/channel/perplexity/constants.go (1)
5-5: LGTM! Clean addition of new Perplexity models.The three new model names ("sonar", "sonar-pro", "sonar-reasoning") are added cleanly to the existing ModelList slice, following the established pattern.
web/src/constants/channel.constants.js (1)
91-95: LGTM! Perplexity channel option added correctly.The new channel entry follows the established structure and is consistent with other channel definitions. The placement between values 26 and 24 appears intentional, possibly grouping by provider type or functionality.
web/src/helpers/render.jsx (2)
57-57: LGTM! Perplexity icon import added correctly.The import is properly added to the existing @lobehub/icons imports list.
313-314: LGTM! Perplexity icon case added consistently.The case statement for channel type 27 follows the same pattern as other channels, using
Perplexity.Colorwith the standardiconSizeof 14.relay/channel/perplexity/relay-perplexity.go (1)
14-27: LGTM! Request mapping extended cleanly with Perplexity-specific fields.The function now populates additional search-related fields (SearchDomainFilter, SearchRecencyFilter, ReturnImages, ReturnRelatedQuestions, SearchMode) from the input request. The implementation is straightforward and follows the existing pattern for field mappings.
web/src/components/table/channels/modals/EditChannelModal.jsx (1)
94-94: LGTM! Perplexity channel enabled for model fetching.Adding 27 to MODEL_FETCHABLE_TYPES allows the Perplexity channel to fetch its model list, consistent with other supported channels.
relay/channel/perplexity/adaptor.go (1)
82-84: DoResponse delegation is correct.The delegation to
openai.Adaptor.DoResponseis implemented cleanly and follows the same pattern asConvertClaudeRequest. See the suggestion in the previous comment about optionally caching the adaptor instance.dto/openai_request.go (1)
90-95: LGTM! Perplexity search parameters added cleanly.The five new fields for Perplexity search functionality are well-typed and appropriately use
omitemptytags. The use ofjson.RawMessageforSearchDomainFilterprovides flexibility for complex filter structures.Note: There's no validation for these fields, which may be intentional if the upstream Perplexity API handles validation.
feat: pplx channel
Summary by CodeRabbit
New Features
UI