fix code
This commit is contained in:
@@ -600,10 +600,47 @@ class DictService:
|
||||
# 如果查询成功且返回了字典条目,直接将结果存入Redis缓存
|
||||
if success and dict_entry:
|
||||
try:
|
||||
uk_phone = dict_entry.uk_phone if dict_entry.uk_phone else None
|
||||
uk_phone = dict_entry.uk_phone if dict_entry.uk_phone else dict_entry.us_phone
|
||||
await DictService._cache_word_result(word, uk_phone)
|
||||
except Exception as e:
|
||||
logger.error(f"Error caching word {word} after successful lookup: {e}")
|
||||
# 若包含连字符,拆分为多个子词并额外触发查询
|
||||
if '-' in word:
|
||||
parts = [p.strip() for p in word.split('-') if p.strip()]
|
||||
for part in parts:
|
||||
try:
|
||||
part_success, part_entry = await youdao_word_api.lookup_and_process(
|
||||
word=part,
|
||||
category=category,
|
||||
dict_type=dict_type,
|
||||
)
|
||||
if part_success and part_entry:
|
||||
try:
|
||||
uk_phone_part = part_entry.uk_phone if part_entry.uk_phone else dict_entry.us_phone
|
||||
await DictService._cache_word_result(part, uk_phone_part)
|
||||
except Exception as ce:
|
||||
logger.error(f"Error caching sub-word {part} after successful lookup: {ce}")
|
||||
# 只要任一查询成功,则整体视为成功
|
||||
success = success or part_success
|
||||
except Exception as se:
|
||||
logger.error(f"Error looking up sub-word '{part}' for '{word}': {se}")
|
||||
|
||||
# 若原词未获得音标,尝试使用子词的音标拼接缓存到原词
|
||||
try:
|
||||
orig_has_phone = bool(getattr(dict_entry, 'us_phone', None) or getattr(dict_entry, 'uk_phone', None)) if dict_entry else False
|
||||
except Exception:
|
||||
orig_has_phone = False
|
||||
if not orig_has_phone:
|
||||
try:
|
||||
phonetics = []
|
||||
for part in parts:
|
||||
_, part_phone = await DictService._is_word_already_processed(part)
|
||||
phonetics.append(part_phone if part_phone else "*")
|
||||
composed_phone = " - ".join(phonetics) if phonetics else None
|
||||
if composed_phone:
|
||||
await DictService._cache_word_result(word, composed_phone)
|
||||
except Exception as ce2:
|
||||
logger.error(f"Error composing phonetics for hyphenated word '{word}': {ce2}")
|
||||
|
||||
return success
|
||||
except Exception as e:
|
||||
|
||||
@@ -18,10 +18,11 @@ class ProductService:
|
||||
@staticmethod
|
||||
async def init_products(items: List[dict] | None = None) -> int:
|
||||
default = [
|
||||
{"title": "500积分", "description": "仅限一次", "points": 500, "amount_cents": 100, "one_time": True},
|
||||
{"title": "100积分", "description": "充值100积分", "points": 100, "amount_cents": 100, "one_time": False},
|
||||
{"title": "500积分", "description": "充值500积分", "points": 500, "amount_cents": 500, "one_time": False},
|
||||
{"title": "100积分", "description": "测试100积分", "points": 100, "amount_cents": 1, "one_time": False},
|
||||
{"title": "+1000%", "description": "仅限一次", "points": 100, "amount_cents": 100, "one_time": True},
|
||||
{"title": "+100%", "description": "充值100积分", "points": 20, "amount_cents": 100, "one_time": False},
|
||||
{"title": "+200%", "description": "充值500积分", "points": 150, "amount_cents": 500, "one_time": False},
|
||||
{"title": "+500%", "description": "充值500积分", "points": 500, "amount_cents": 1000, "one_time": False},
|
||||
# {"title": "100积分", "description": "测试100积分", "points": 100, "amount_cents": 1, "one_time": False},
|
||||
]
|
||||
payload = items or default
|
||||
async with async_db_session.begin() as db:
|
||||
|
||||
@@ -62,14 +62,64 @@ class Qwen:
|
||||
# "Focus: primary/central/artificial objects."
|
||||
|
||||
# v2:
|
||||
"Vision-to-English-Chinese education module. Analyze and describe the image in three levels: "
|
||||
"LEVEL1 (simple vocabulary and basic grammar, ~10 words),"
|
||||
"LEVEL2 (detailed and complex vocabulary, 15-20 words),"
|
||||
"LEVEL3 (professional, uncommon words and complex grammar, ≤25 words)."
|
||||
"For each level, provide 6-8 English sentences and Chinese translations."
|
||||
"Output JSON: {LEVEL1: {desc_en:[], desc_zh:[]}, LEVEL2: {}, LEVEL3: {}}."
|
||||
"Ensure all description are unique - no repetition."
|
||||
# "Vision-to-English-Chinese education module. Analyze and describe the image in three levels: "
|
||||
# "LEVEL1 (simple vocabulary and basic grammar, ~10 words),"
|
||||
# "LEVEL2 (detailed and complex vocabulary, 15-20 words),"
|
||||
# "LEVEL3 (professional, uncommon words and complex grammar, ≤25 words)."
|
||||
# "For each level, provide 6-8 English sentences and Chinese translations."
|
||||
# "Output JSON: {LEVEL1: {desc_en:[], desc_zh:[]}, LEVEL2: {}, LEVEL3: {}}."
|
||||
# "Ensure all description are unique - no repetition."
|
||||
# "Focus: primary/central/artificial objects."
|
||||
|
||||
# v3
|
||||
"""
|
||||
Vision-to-English-Chinese education module (for image recognition). Follow these steps and rules strictly to generate descriptions:
|
||||
# Step 1: Image Pre-Analysis (Model Must Do First)
|
||||
Identify core subject: What is the main object/scene/person in the image?
|
||||
Extract key details: Color, shape, position, action, environment, quantity (as applicable).
|
||||
Confirm context: Is it a static scene/dynamic action/daily scene/professional scenario?
|
||||
|
||||
# Step 2: Three-Level Description Requirements (No Repetition Across Levels)
|
||||
level1: Basic Introduction
|
||||
Rules: Simple vocabulary + elementary grammar, ≤15 words per sentence.
|
||||
Quantity: 5-7 unique English sentences + corresponding Chinese translations.
|
||||
Focus: Only core subject (e.g., "A red cat sits on the chair" → 一只红色的猫坐在椅子上).
|
||||
|
||||
level2: Detailed Expansion
|
||||
Rules: Richer vocabulary + complex structures, 15-25 words per sentence.
|
||||
Quantity: 8-10 unique English sentences + corresponding Chinese translations.
|
||||
Focus: Add key details (color/action/environment) not mentioned in level1.
|
||||
|
||||
level3: Coherent Narrative
|
||||
Rules:
|
||||
Total words around 300, ≤30 words per sentence (strictly enforced).
|
||||
Logical continuity: Follow "overall scene → local details → implicit context" order.
|
||||
Use connecting words (e.g., however, besides, therefore) to link sentences.
|
||||
Quantity: A continuous article split into independent sentences (array elements).
|
||||
Output: English sentences + corresponding Chinese translations (no overlap with level1/2).
|
||||
|
||||
# Step 3: Output Format (Strictly Follow JSON Structure)
|
||||
{
|
||||
"level1": {
|
||||
"desc_en": ["sentence1 (≤10 words)", "sentence2 (≤10 words)", ...],
|
||||
"desc_zh": ["准确对应翻译 1", "准确对应翻译 2", ...]
|
||||
},
|
||||
"level2": {
|
||||
"desc_en": ["sentence1 (15-20 words)", "sentence2 (15-20 words)", ...],
|
||||
"desc_zh": ["准确对应翻译 1", "准确对应翻译 2", ...]
|
||||
},
|
||||
"level3": {
|
||||
"desc_en": ["sentence1 (≤25 words)", "sentence2 (≤25 words)", ...], //coherent article
|
||||
"desc_zh": ["准确对应翻译 1", "准确对应翻译 2", ...] //same logic as English
|
||||
}
|
||||
}
|
||||
Mandatory Rules (Model Must Obey)
|
||||
All English sentences and Chinese translations are 100% unique across three levels.
|
||||
LEVEL3 translations must maintain the same logical flow as English.
|
||||
No abbreviations, slang, or untranslated words; use standard English/Chinese.
|
||||
If image details are unclear, describe observable elements (avoid speculation).
|
||||
Strictly adhere to word/sentence quantity limits (no under/over).
|
||||
"""
|
||||
)
|
||||
|
||||
if exclude_words:
|
||||
|
||||
Reference in New Issue
Block a user