-
Notifications
You must be signed in to change notification settings - Fork 16
Fix pyright type errors #137
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |||||
| """ | ||||||
|
|
||||||
| import math | ||||||
| from typing import Any, Callable, Dict, List, Optional, Union | ||||||
| from typing import Any, Callable, Dict, List, Optional, Union, cast | ||||||
|
|
||||||
| from ..models import EvaluateResult, Message, MetricResult | ||||||
| from ..typed_interface import reward_function | ||||||
|
|
@@ -77,12 +77,25 @@ def cosine_scaled_accuracy_length_reward( | |||||
| ) | ||||||
| }, | ||||||
| ) | ||||||
| text: str = response.content | ||||||
| # Coerce response content to string | ||||||
| text: str | ||||||
| if isinstance(response.content, str): | ||||||
| text = response.content | ||||||
| elif isinstance(response.content, list) and response.content: | ||||||
| # Join text parts if provided as structured content | ||||||
| try: | ||||||
| text = " ".join(part.text for part in response.content) # type: ignore[union-attr] | ||||||
| except Exception: | ||||||
| text = "" | ||||||
| else: | ||||||
| text = "" | ||||||
|
|
||||||
| # Step 1: Evaluate accuracy | ||||||
| accuracy_eval_result = accuracy_reward( | ||||||
| messages=messages, # Pass the full messages list | ||||||
| ground_truth=ground_truth, # Pass the ground_truth list | ||||||
| # Ensure ground_truth is a list if provided; default to [] for compatibility | ||||||
| gt_for_accuracy = ground_truth if ground_truth is not None else [] | ||||||
| accuracy_eval_result = cast(Any, accuracy_reward)( | ||||||
|
||||||
| accuracy_eval_result = cast(Any, accuracy_reward)( | |
| accuracy_eval_result = accuracy_reward( |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |||
| from typing import Any, Dict, List, Optional, Tuple, Union | ||||
|
|
||||
| # Import the base policy and types for proper recording functionality | ||||
| from openai.types import CompletionUsage | ||||
| from typing import Optional as _Optional | ||||
|
||||
| from typing import Optional as _Optional |
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.
The type ignore comment suggests uncertainty about the structure. Consider adding a more specific type check or explicit attribute validation before accessing
.textto make the code more robust.