Spaces:
Running
Running
ming
commited on
Commit
Β·
e8ab865
1
Parent(s):
33cd483
Fix Outlines import - use correct API for installed version
Browse files- Try multiple import patterns to handle different Outlines versions
- Use outlines.generate.json directly instead of outlines.generate.json wrapper
- Fixes 'cannot import name generate' error
app/services/structured_summarizer.py
CHANGED
|
@@ -54,10 +54,27 @@ from pydantic import BaseModel
|
|
| 54 |
# Try to import Outlines for JSON schema enforcement
|
| 55 |
OUTLINES_AVAILABLE = False
|
| 56 |
outlines_models = None
|
| 57 |
-
|
| 58 |
|
| 59 |
try:
|
| 60 |
-
from outlines import models as outlines_models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
OUTLINES_AVAILABLE = True
|
| 62 |
logger.info("β
Outlines library imported successfully")
|
| 63 |
except ImportError as e:
|
|
@@ -231,7 +248,7 @@ class StructuredSummarizer:
|
|
| 231 |
# Also warm up Outlines JSON generation
|
| 232 |
if OUTLINES_AVAILABLE and self.outlines_model is not None:
|
| 233 |
try:
|
| 234 |
-
dummy_gen =
|
| 235 |
_ = dummy_gen("Warmup text for Outlines structured summary.")
|
| 236 |
logger.info("β
V4 Outlines JSON warmup successful")
|
| 237 |
except Exception as e:
|
|
@@ -939,7 +956,7 @@ Rules:
|
|
| 939 |
return
|
| 940 |
|
| 941 |
# Create an Outlines generator bound to the StructuredSummary schema
|
| 942 |
-
json_generator =
|
| 943 |
|
| 944 |
start_time = time.time()
|
| 945 |
|
|
|
|
| 54 |
# Try to import Outlines for JSON schema enforcement
|
| 55 |
OUTLINES_AVAILABLE = False
|
| 56 |
outlines_models = None
|
| 57 |
+
outlines_generate_json = None
|
| 58 |
|
| 59 |
try:
|
| 60 |
+
from outlines import models as outlines_models
|
| 61 |
+
# Try different import patterns based on Outlines version
|
| 62 |
+
try:
|
| 63 |
+
# Pattern 1: Direct import (some versions)
|
| 64 |
+
from outlines import generate
|
| 65 |
+
outlines_generate_json = generate.json
|
| 66 |
+
except ImportError:
|
| 67 |
+
try:
|
| 68 |
+
# Pattern 2: Submodule import (newer versions)
|
| 69 |
+
from outlines.generate import json as outlines_generate_json
|
| 70 |
+
except ImportError:
|
| 71 |
+
# Pattern 3: Check if it's a method on the module
|
| 72 |
+
import outlines
|
| 73 |
+
if hasattr(outlines, 'generate') and hasattr(outlines.generate, 'json'):
|
| 74 |
+
outlines_generate_json = outlines.generate.json
|
| 75 |
+
else:
|
| 76 |
+
raise ImportError("Could not find outlines.generate.json")
|
| 77 |
+
|
| 78 |
OUTLINES_AVAILABLE = True
|
| 79 |
logger.info("β
Outlines library imported successfully")
|
| 80 |
except ImportError as e:
|
|
|
|
| 248 |
# Also warm up Outlines JSON generation
|
| 249 |
if OUTLINES_AVAILABLE and self.outlines_model is not None:
|
| 250 |
try:
|
| 251 |
+
dummy_gen = outlines_generate_json(self.outlines_model, StructuredSummary)
|
| 252 |
_ = dummy_gen("Warmup text for Outlines structured summary.")
|
| 253 |
logger.info("β
V4 Outlines JSON warmup successful")
|
| 254 |
except Exception as e:
|
|
|
|
| 956 |
return
|
| 957 |
|
| 958 |
# Create an Outlines generator bound to the StructuredSummary schema
|
| 959 |
+
json_generator = outlines_generate_json(self.outlines_model, StructuredSummary)
|
| 960 |
|
| 961 |
start_time = time.time()
|
| 962 |
|