Skip to content

refactor: log params and channel params - #1338

Closed
xyfacai wants to merge 1 commit into
alphafrom
refactor/log-params
Closed

refactor: log params and channel params#1338
xyfacai wants to merge 1 commit into
alphafrom
refactor/log-params

Conversation

@xyfacai

@xyfacai xyfacai commented Jul 7, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added structured channel settings with explicit fields for force format, thinking-to-content, and proxy options.
    • Introduced new utility functions for flexible context value retrieval and JSON string conversion.
  • Improvements

    • Enhanced type safety and clarity by replacing generic maps with strongly typed channel settings throughout the system.
    • Added validation for channel settings during channel creation and update.
    • Standardized and simplified proxy configuration handling.
  • Refactor

    • Refactored logging and quota recording to use structured parameters instead of multiple positional arguments, improving maintainability and readability.

@coderabbitai

coderabbitai Bot commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces strong typing for channel settings by defining a new ChannelSettings struct and refactoring code to use this type instead of generic maps. It adds validation for channel settings, standardizes context key access, and refactors consumption log recording to use a structured parameter object. Several internal APIs and function signatures are updated accordingly.

Changes

File(s) Change Summary
common/gin.go Added generic function GetContextKeyType[T any] for type-safe Gin context value retrieval.
common/str.go Added GetJsonString(data any) string utility for marshaling data to JSON string.
controller/channel.go Added validation of channel settings in AddChannel and UpdateChannel.
controller/channel-test.go Refactored RecordConsumeLog call to use RecordConsumeLogParams struct.
dto/channel_settings.go Introduced new ChannelSettings struct with fields for channel configuration.
main.go Moved logger setup to after environment initialization in InitResources().
middleware/distributor.go Standardized Gin context key setting using common.SetContextKey and constants.
model/channel.go Added ValidateSettings() method; refactored settings handling to use ChannelSettings struct.
model/log.go Refactored RecordConsumeLog to accept a RecordConsumeLogParams struct; added the struct definition.
relay/common/relay_info.go Changed RelayInfo.ChannelSetting from map to ChannelSettings type; updated context retrieval accordingly.
relay/channel/api_request.go
relay/channel/coze/relay-coze.go
relay/channel/vertex/service_account.go
Refactored proxy handling to use ChannelSettings.Proxy field instead of map lookups.
relay/channel/openai/adaptor.go
relay/channel/openai/relay-openai.go
Refactored feature flag checks to use boolean fields on ChannelSettings instead of map assertions.
relay/relay-mj.go
relay/relay-text.go
relay/relay_task.go
service/quota.go
Refactored all RecordConsumeLog calls to use RecordConsumeLogParams struct.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GinContext
    participant Controller
    participant Model
    participant DTO

    Client->>Controller: AddChannel/UpdateChannel (JSON)
    Controller->>DTO: Bind JSON to ChannelSettings
    Controller->>Model: channel.ValidateSettings()
    alt Validation fails
        Controller->>Client: Return error JSON
    else Validation succeeds
        Controller->>Model: Proceed with DB operations
    end
Loading
sequenceDiagram
    participant Service
    participant Model

    Service->>Model: RecordConsumeLog(userId, RecordConsumeLogParams)
    Model->>Model: LogQuotaData using params
    Model-->>Service: (async) Logging complete
Loading

Possibly related PRs

Poem

In the warren of code, a new type is born,
Channel settings now tidy, no longer forlorn.
Logs are recorded with structured delight,
Context keys typed, everything’s right!
🐇✨
Strong types and new flows—
This bunny approves how the garden now grows!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 265c7d9 and c5243f5.

📒 Files selected for processing (19)
  • common/gin.go (1 hunks)
  • common/str.go (1 hunks)
  • controller/channel-test.go (1 hunks)
  • controller/channel.go (2 hunks)
  • dto/channel_settings.go (1 hunks)
  • main.go (1 hunks)
  • middleware/distributor.go (2 hunks)
  • model/channel.go (3 hunks)
  • model/log.go (3 hunks)
  • relay/channel/api_request.go (1 hunks)
  • relay/channel/coze/relay-coze.go (1 hunks)
  • relay/channel/openai/adaptor.go (1 hunks)
  • relay/channel/openai/relay-openai.go (2 hunks)
  • relay/channel/vertex/service_account.go (1 hunks)
  • relay/common/relay_info.go (3 hunks)
  • relay/relay-mj.go (5 hunks)
  • relay/relay-text.go (1 hunks)
  • relay/relay_task.go (1 hunks)
  • service/quota.go (3 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@xyfacai xyfacai closed this Jul 7, 2025
@xyfacai
xyfacai deleted the refactor/log-params branch July 7, 2025 04:55
jiutubaba pushed a commit to jiutubaba/fx-api that referenced this pull request May 17, 2026
…elect

fix(admin): fix Safari system log select height
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant