Skip to content

Commit 64b7a3e

Browse files
committed
fix(v2): address PR review comments
- Remove debug logging blocks in retry.py that wrote to hardcoded local path - Fix GENAI_STRUCTURED_OUTPUTS enum value to avoid alias collision - Fix sync retry to extract stream parameter from kwargs like async version
1 parent d0a96e2 commit 64b7a3e

File tree

2 files changed

+5
-60
lines changed

2 files changed

+5
-60
lines changed

instructor/mode.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class Mode(enum.Enum):
5151
GEMINI_TOOLS = "gemini_tools"
5252
GENAI_TOOLS = "genai_tools"
5353
GENAI_JSON = "genai_json"
54-
GENAI_STRUCTURED_OUTPUTS = "genai_json" # Backwards compatibility alias
54+
GENAI_STRUCTURED_OUTPUTS = (
55+
"genai_structured_outputs" # Backwards compatibility alias
56+
)
5557

5658
# Cohere modes
5759
COHERE_TOOLS = "cohere_tools"

instructor/v2/core/retry.py

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from __future__ import annotations
88

99
import logging
10-
import json
11-
import time
1210
from typing import TYPE_CHECKING, Any, TypeVar
1311

1412
from pydantic import BaseModel, ValidationError
@@ -110,12 +108,13 @@ def retry_sync_v2(
110108

111109
# Parse response using registry
112110
try:
111+
stream = kwargs.get("stream", False)
113112
parsed = handlers.response_parser(
114113
response=response,
115114
response_model=response_model,
116115
validation_context=context,
117116
strict=strict,
118-
stream=False,
117+
stream=stream,
119118
is_async=False,
120119
)
121120
logger.debug(
@@ -266,34 +265,6 @@ async def retry_async_v2(
266265
if inspect.isclass(response_model) and issubclass(
267266
response_model, (IterableBase, PartialBase)
268267
):
269-
# region agent log
270-
with open(
271-
"/Users/jasonliu/dev/instructor/.cursor/debug.log", "a"
272-
) as _log:
273-
_log.write(
274-
json.dumps(
275-
{
276-
"sessionId": "debug-session",
277-
"runId": "streaming-pre",
278-
"hypothesisId": "H3",
279-
"location": "instructor/v2/core/retry.py:retry_async_v2",
280-
"message": "retry_async_streaming_short_circuit",
281-
"data": {
282-
"provider": str(provider),
283-
"mode": str(mode),
284-
"response_model": getattr(
285-
response_model,
286-
"__name__",
287-
str(response_model),
288-
),
289-
"stream": bool(stream),
290-
},
291-
"timestamp": int(time.time() * 1000),
292-
}
293-
)
294-
+ "\n"
295-
)
296-
# endregion agent log
297268
# Map mode for streaming: Anthropic TOOLS mode needs ANTHROPIC_TOOLS
298269
# for extract_json to work correctly (checks for Mode.ANTHROPIC_TOOLS)
299270
streaming_mode = mode
@@ -309,34 +280,6 @@ async def retry_async_v2(
309280

310281
# Parse response using registry
311282
try:
312-
# region agent log
313-
with open(
314-
"/Users/jasonliu/dev/instructor/.cursor/debug.log", "a"
315-
) as _log:
316-
_log.write(
317-
json.dumps(
318-
{
319-
"sessionId": "debug-session",
320-
"runId": "streaming-pre",
321-
"hypothesisId": "H4",
322-
"location": "instructor/v2/core/retry.py:retry_async_v2",
323-
"message": "retry_async_parse_response",
324-
"data": {
325-
"provider": str(provider),
326-
"mode": str(mode),
327-
"response_model": getattr(
328-
response_model,
329-
"__name__",
330-
str(response_model),
331-
),
332-
"stream": bool(stream),
333-
},
334-
"timestamp": int(time.time() * 1000),
335-
}
336-
)
337-
+ "\n"
338-
)
339-
# endregion agent log
340283
parsed = handlers.response_parser(
341284
response=response,
342285
response_model=response_model,

0 commit comments

Comments
 (0)