Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add completion start time timestamp to relevant generators #8728

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

vblagoje
Copy link
Member

@vblagoje vblagoje commented Jan 16, 2025

Why:

Enhances Langfuse integration to track the time-to-first-token (TTFT) in streaming responses. The new entry in chat message metadata completion_start_time enables TTFT tracking in Langfuse. We'll separately update all other relevant generators in https://github.com/deepset-ai/haystack-core-integrations/

What:

  • Added completion_start_time metadata in the Hugging Face API and OpenAI chat and non-chat generators to record the TTFT.
  • Modified test cases to validate the inclusion of the completion_start_time and its format correctness.

How can it be used:

This change allows developers to track the exact start time of streaming completions, aiding in performance diagnostics

How did you test it:

Included updated unit tests for both Hugging Face API and OpenAI chat and non-chat generators to ensure the presence and correct ISO format of completion_start_time metadata. These tests verify that the timestamps are recorded and formatted correctly during streaming responses.

Notes for the reviewer:

Ensure close attention to the new metadata handling and its correctness across different components. Testing has validated the format, but real integration checks are recommended for full assurance.

@github-actions github-actions bot added topic:tests type:documentation Improvements on the docs labels Jan 16, 2025
@coveralls
Copy link
Collaborator

coveralls commented Jan 16, 2025

Pull Request Test Coverage Report for Build 12810835892

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 13 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.009%) to 91.301%

Files with Coverage Reduction New Missed Lines %
components/generators/hugging_face_api.py 2 96.3%
components/generators/chat/hugging_face_api.py 3 96.46%
components/generators/chat/openai.py 4 96.3%
components/generators/openai.py 4 95.65%
Totals Coverage Status
Change from base Build 12794162077: 0.009%
Covered Lines: 8848
Relevant Lines: 9691

💛 - Coveralls

@vblagoje vblagoje marked this pull request as ready for review January 16, 2025 12:50
@vblagoje vblagoje requested review from a team as code owners January 16, 2025 12:50
@vblagoje vblagoje requested review from dfokina and anakin87 and removed request for a team January 16, 2025 12:50
@vblagoje vblagoje changed the title feat: Add completion start time timestamp to relevant chat generators feat: Add completion start time timestamp to relevant generators Jan 16, 2025
Comment on lines +278 to +285
meta = {
"finish_reason": finish_reason if finish_reason else None,
"received_at": datetime.now().isoformat(),
}
chunks_meta.append(meta)

if first_chunk_time is None:
first_chunk_time = meta["received_at"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
meta = {
"finish_reason": finish_reason if finish_reason else None,
"received_at": datetime.now().isoformat(),
}
chunks_meta.append(meta)
if first_chunk_time is None:
first_chunk_time = meta["received_at"]
meta = {}
if finish_reason:
meta["finish_reason"] = finish_reason
if first_chunk_time is None:
first_chunk_time = datetime.now().isoformat()

Do you see any problems with this simpler approach?

Comment on lines +228 to +236
chunk_metadata = {
**asdict(token),
**(asdict(chunk.details) if chunk.details else {}),
"received_at": datetime.now().isoformat(),
}

if first_chunk_time is None:
first_chunk_time = chunk_metadata["received_at"]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above - could we simplify it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:tests type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants