-
Notifications
You must be signed in to change notification settings - Fork 87
feat: observe decorators #633
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
base: staging
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @abhishekg999, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly extends the tracing capabilities by enabling the observation of Python generators, both synchronous and asynchronous. This feature ensures that the execution flow of generators, including individual yielded items and any exceptions, is properly captured and integrated into the tracing system. The changes also include improvements to context management within decorators and robust error handling, alongside dedicated tests to verify the new functionality. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with π and π on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a significant feature: support for observing synchronous and asynchronous generators within the tracer. This is implemented by wrapping generator objects and creating child spans for each yielded item, which is a solid approach. The PR also includes comprehensive tests for this new functionality, covering various scenarios like context preservation and exception handling. Additionally, there are several good refactorings, such as simplifying the agent decorator's context creation and improving type hints.
My review includes a few suggestions:
- A potential bug in
_ObservedAsyncGeneratorwhere context propagation might be lost. - A simplification for creating child span names within the generator wrappers.
- A recommendation to remove an unnecessary
type: ignorecomment. - Suggestions to strengthen a couple of tests in
test_tracer.pythat were weakened during refactoring.
Overall, this is a great contribution that enhances the tracing capabilities.
| super().__init__(config, trainable_model, tracer, project_name) | ||
| if client is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[CriticalError]
This FireworksTrainer creates its own SpanStore and InMemorySpanExporter. However, the spans generated by @self.tracer.observe within this class will be processed by the exporter configured in the tracer instance passed during initialization, not this new, local one.
As a result, self.span_store will remain empty, and _extract_message_history_from_spans will fail to retrieve any trace data, likely breaking the training logic that depends on it.
To fix this, the trainer should either receive the SpanStore as a constructor argument or have a mechanism to access the SpanStore from the provided tracer instance.
Context for Agents
[**CriticalError**]
This `FireworksTrainer` creates its own `SpanStore` and `InMemorySpanExporter`. However, the spans generated by `@self.tracer.observe` within this class will be processed by the exporter configured in the `tracer` instance passed during initialization, not this new, local one.
As a result, `self.span_store` will remain empty, and `_extract_message_history_from_spans` will fail to retrieve any trace data, likely breaking the training logic that depends on it.
To fix this, the trainer should either receive the `SpanStore` as a constructor argument or have a mechanism to access the `SpanStore` from the provided `tracer` instance.
File: src/judgeval/v1/trainers/fireworks_trainer.py
Line: 48| config: TrainerConfig, | ||
| trainable_model: TrainableModel, | ||
| tracer: Tracer, | ||
| project_name: Optional[str] = None, | ||
| client: Optional["JudgmentSyncClient"] = None, | ||
| client: Optional[JudgmentSyncClient] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[BestPractice]
The type hint for the client parameter is Optional[JudgmentSyncClient] = None, but the implementation raises a ValueError if it's None. This makes the parameter mandatory in practice. The type hint should be updated to reflect this requirement to avoid confusion for developers using this class.
Suggested Change
| config: TrainerConfig, | |
| trainable_model: TrainableModel, | |
| tracer: Tracer, | |
| project_name: Optional[str] = None, | |
| client: Optional["JudgmentSyncClient"] = None, | |
| client: Optional[JudgmentSyncClient] = None, | |
| config: TrainerConfig, | |
| trainable_model: TrainableModel, | |
| tracer: Tracer, | |
| project_name: Optional[str] = None, | |
| client: JudgmentSyncClient, |
β‘ Committable suggestion
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
Context for Agents
[**BestPractice**]
The type hint for the `client` parameter is `Optional[JudgmentSyncClient] = None`, but the implementation raises a `ValueError` if it's `None`. This makes the parameter mandatory in practice. The type hint should be updated to reflect this requirement to avoid confusion for developers using this class.
<details>
<summary>Suggested Change</summary>
```suggestion
config: TrainerConfig,
trainable_model: TrainableModel,
tracer: Tracer,
project_name: Optional[str] = None,
client: JudgmentSyncClient,
```
β‘ **Committable suggestion**
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
</details>
File: src/judgeval/v1/trainers/fireworks_trainer.py
Line: 45
alanzhang25
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice! just the two comments
|
βοΈ Propel has finished reviewing this change. |
π Summary
β Checklist