Skip to content

Conversation

narengogi
Copy link
Collaborator

  • tested with cached streaming responses

@narengogi narengogi requested review from VisargD and b4s36t4 August 19, 2025 12:51
Copy link
Contributor

Code Quality type: bug fix

Description

Summary By MatterAI MatterAI logo

🔄 What Changed

The created timestamp in the streamChunkTemplate for OpenAI chat completions is now generated as a Unix timestamp in seconds instead of milliseconds. This involves dividing Date.now() by 1000 and flooring the result.

🔍 Impact of the Change

This change standardizes the created timestamp format, ensuring consistency with common API practices that often expect Unix timestamps in seconds. It improves data compatibility and reduces potential parsing issues for consumers of this data.

📁 Total Files Changed

  • src/providers/openai/chatComplete.ts: Modified the created field calculation from Date.now() to Math.floor(Date.now() / 1000).

🧪 Test Added

N/A

🔒Security Vulnerabilities

N/A

Motivation

To align the created timestamp format with standard Unix timestamps (in seconds) for better compatibility and consistency across systems.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing
    N/A

Screenshots (if applicable)

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

.

Tip

Quality Recommendations

  1. Ensure all timestamp fields across the application consistently use Unix timestamps in seconds to maintain data integrity and simplify integrations.

Tanka Poem ♫

Time's flow, once too swift,
Now seconds mark the passing,
Precision's new grace.
Data streams, aligned and true,
Epoch's beat, a steady pulse. ⏱️

Sequence Diagram

sequenceDiagram
    participant P as Provider
    participant CCF as chatComplete Function
    participant SCT as StreamChunkTemplate

    P->>CCF: initiateChatCompletion(model, ...)
    activate CCF
    Note over CCF: Generate unique ID
    CCF->>CCF: Calculate timestamp (Date.now() / 1000)
    CCF->>SCT: Construct streamChunkTemplate(id, object, created, model, ...)
    Note over SCT: created: Unix timestamp in seconds
    CCF-->>P: Return streamChunkTemplate
    deactivate CCF
Loading

Copy link
Contributor

✅ Clean implementation converting timestamp from milliseconds to seconds for Unix timestamp compatibility.

@VisargD VisargD merged commit 0cc63ac into Portkey-AI:main Aug 27, 2025
1 check passed
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.

2 participants