Skip to content

feat: specify reasong_effort to improve the time to generate a sentence#27

Merged
hmasdev merged 6 commits into
mainfrom
feature/specify-reasoning-effort-param
Nov 15, 2025
Merged

feat: specify reasong_effort to improve the time to generate a sentence#27
hmasdev merged 6 commits into
mainfrom
feature/specify-reasoning-effort-param

Conversation

@hmasdev

@hmasdev hmasdev commented Nov 15, 2025

Copy link
Copy Markdown
Owner

This pull request introduces a new utility for measuring and logging execution time, and integrates it into the sentence generation workflow for improved observability. The most significant changes are the addition of the stopwatch context manager and decorator, their usage in the OpenAI sentence generator, and comprehensive tests to ensure their reliability.

New stopwatch utility

  • Added stopwatch context manager and stopwatch_deco decorator in simple_typing_application/utils/stopwatch.py to measure and log execution time of code blocks and functions, with customizable log level, prefix, and postfix.

Integration with sentence generation

  • Wrapped the OpenAI agent invocation in generate method of openai_sentence_generator.py with the new stopwatch context manager to log execution time at DEBUG level.

Testing and validation

  • Added comprehensive tests for both the context manager and decorator in tests/utils/test_stopwatch.py, covering logging behavior, custom options, error handling, and decorator usage.

Minor improvements

  • Updated agent initialization in openai_sentence_generator.py to set reasoning_effort based on model type.

Check

For gpt-5-nano,

  • Before: DEBUG:simple_typing_application.sentence_generator.openai_sentence_generator:OpenAI agent invocation: 27.244881 seconds
  • After: DEBUG:simple_typing_application.sentence_generator.openai_sentence_generator:OpenAI agent invocation: 2.191623 seconds

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds a stopwatch utility for measuring execution time and integrates it into the OpenAI sentence generator to improve observability and performance. The key changes include setting reasoning_effort to "minimal" for GPT-5 models and adding comprehensive logging of execution time.

Key Changes:

  • Added stopwatch context manager and stopwatch_deco decorator for timing code execution with flexible logging options
  • Configured reasoning_effort="minimal" for GPT-5 models to reduce generation time from ~27s to ~2s
  • Integrated stopwatch into the OpenAI sentence generator's generate method to log execution time at DEBUG level

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
simple_typing_application/utils/stopwatch.py New utility providing context manager and decorator for measuring and logging execution time with customizable log levels and messages
simple_typing_application/sentence_generator/openai_sentence_generator.py Added reasoning_effort parameter for GPT-5 models and wrapped agent invocation with stopwatch for performance monitoring
tests/utils/test_stopwatch.py Comprehensive test coverage for stopwatch functionality including context manager, decorator, custom options, and error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread simple_typing_application/utils/stopwatch.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hmasdev hmasdev merged commit b82784b into main Nov 15, 2025
29 checks passed
@hmasdev hmasdev deleted the feature/specify-reasoning-effort-param branch November 15, 2025 16:55
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