Spaces:
Sleeping
Sleeping
Auto commit at 25-2025-08 14:37:20
Browse files
lily_llm_api/services/generation_service.py
CHANGED
|
@@ -283,8 +283,8 @@ def generate_sync(prompt: str, image_data_list: Optional[List[bytes]], max_lengt
|
|
| 283 |
per_image_tokens = [3000] * len(all_pixel_values)
|
| 284 |
|
| 285 |
# 2) ํ
์คํธ ๊ธธ์ด ์ธก์ (์ด๋ฏธ์ง ํ ํฐ ์ ์ธํ ํ๋กฌํํธ)
|
| 286 |
-
# ๋ฉํฐ๋ชจ๋ฌ์์๋ RAG
|
| 287 |
-
base_text_prompt = f"Human: {
|
| 288 |
text_inputs = tokenizer(
|
| 289 |
base_text_prompt,
|
| 290 |
return_tensors="pt",
|
|
@@ -411,10 +411,11 @@ def generate_sync(prompt: str, image_data_list: Optional[List[bytes]], max_lengt
|
|
| 411 |
# ๐ ๊ณต์ Kanana ํ์: ์ด๋ฏธ์ง ๊ฐ์์ ๋ง๊ฒ <image> ํ ํฐ ์์ฑ
|
| 412 |
num_images = len(all_pixel_values)
|
| 413 |
image_tokens = "<image>" * num_images # ์ด๋ฏธ์ง ๊ฐ์๋งํผ <image> ํ ํฐ ์์ฑ
|
| 414 |
-
#
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
|
|
|
| 418 |
print(f"๐ [DEBUG] ๋ฉํฐ๋ชจ๋ฌ ํ๋กฌํํธ ๊ตฌ์ฑ (๊ณต์ ํ์): {formatted_prompt}")
|
| 419 |
print(f"๐ [DEBUG] ์ด๋ฏธ์ง ํ ํฐ ์์ฑ: {num_images}๊ฐ ์ด๋ฏธ์ง -> {image_tokens}")
|
| 420 |
image_processed = True
|
|
@@ -603,13 +604,17 @@ def generate_sync(prompt: str, image_data_list: Optional[List[bytes]], max_lengt
|
|
| 603 |
except Exception:
|
| 604 |
neg_exists = False
|
| 605 |
if not neg_exists and len(all_pixel_values) > 0:
|
| 606 |
-
print("โ ๏ธ [DEBUG] -1 ํ ํฐ ์์ โ
|
| 607 |
for limit in [128, 64, 0]:
|
| 608 |
try:
|
| 609 |
base_snippet = (context_prompt or "")[:limit]
|
| 610 |
-
if base_snippet
|
| 611 |
-
|
| 612 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 613 |
print(f"๐ [DEBUG] ์ฌ์๋ limit={limit}: {base_prompt_retry}")
|
| 614 |
inputs_retry = tokenizer.encode_prompt(
|
| 615 |
prompt=base_prompt_retry,
|
|
|
|
| 283 |
per_image_tokens = [3000] * len(all_pixel_values)
|
| 284 |
|
| 285 |
# 2) ํ
์คํธ ๊ธธ์ด ์ธก์ (์ด๋ฏธ์ง ํ ํฐ ์ ์ธํ ํ๋กฌํํธ)
|
| 286 |
+
# ๋ฉํฐ๋ชจ๋ฌ์์๋ RAG ์ค๋ํซ์ ์ปจํ
์คํธ ๋ธ๋ก์ผ๋ก ๋ถ๋ฆฌํ์ฌ ํ
์คํธ ๊ธธ์ด๋ฅผ ์ฐ์
|
| 287 |
+
base_text_prompt = f"{('[CONTEXT]\n'+rag_snippet_short+'[/CONTEXT]\n') if rag_snippet_short else ''}Human: {prompt}\nAssistant:"
|
| 288 |
text_inputs = tokenizer(
|
| 289 |
base_text_prompt,
|
| 290 |
return_tensors="pt",
|
|
|
|
| 411 |
# ๐ ๊ณต์ Kanana ํ์: ์ด๋ฏธ์ง ๊ฐ์์ ๋ง๊ฒ <image> ํ ํฐ ์์ฑ
|
| 412 |
num_images = len(all_pixel_values)
|
| 413 |
image_tokens = "<image>" * num_images # ์ด๋ฏธ์ง ๊ฐ์๋งํผ <image> ํ ํฐ ์์ฑ
|
| 414 |
+
# RAG ์ค๋ํซ์ ๋ณ๋ ์ปจํ
์คํธ ๋ธ๋ก์ผ๋ก ๋ถ๋ฆฌํ์ฌ ์์ฝ ๋ฐฉ์ง
|
| 415 |
+
context_block = f"[CONTEXT]\n{rag_snippet_short}[/CONTEXT]\n" if rag_snippet_short else ""
|
| 416 |
+
# ์ฌ์ฉ์ ๋ฐํ๋ ์์ ์ง๋ฌธ๋ง ์ ์ง
|
| 417 |
+
mm_text = prompt
|
| 418 |
+
formatted_prompt = f"{context_block}Human: {image_tokens}{mm_text}\nAssistant:"
|
| 419 |
print(f"๐ [DEBUG] ๋ฉํฐ๋ชจ๋ฌ ํ๋กฌํํธ ๊ตฌ์ฑ (๊ณต์ ํ์): {formatted_prompt}")
|
| 420 |
print(f"๐ [DEBUG] ์ด๋ฏธ์ง ํ ํฐ ์์ฑ: {num_images}๊ฐ ์ด๋ฏธ์ง -> {image_tokens}")
|
| 421 |
image_processed = True
|
|
|
|
| 604 |
except Exception:
|
| 605 |
neg_exists = False
|
| 606 |
if not neg_exists and len(all_pixel_values) > 0:
|
| 607 |
+
print("โ ๏ธ [DEBUG] -1 ํ ํฐ ์์ โ ์ปจํ
์คํธ ๋ธ๋ก ๊ธธ์ด ์ค์ฌ ์ฌ์๋")
|
| 608 |
for limit in [128, 64, 0]:
|
| 609 |
try:
|
| 610 |
base_snippet = (context_prompt or "")[:limit]
|
| 611 |
+
if base_snippet:
|
| 612 |
+
if not base_snippet.endswith("\n"):
|
| 613 |
+
base_snippet += "\n"
|
| 614 |
+
context_block = f"[CONTEXT]\n{base_snippet}[/CONTEXT]\n"
|
| 615 |
+
else:
|
| 616 |
+
context_block = ""
|
| 617 |
+
base_prompt_retry = f"{context_block}Human: {'<image>' * len(all_pixel_values)}{prompt}\nAssistant:"
|
| 618 |
print(f"๐ [DEBUG] ์ฌ์๋ limit={limit}: {base_prompt_retry}")
|
| 619 |
inputs_retry = tokenizer.encode_prompt(
|
| 620 |
prompt=base_prompt_retry,
|