Update app.py
Browse files
app.py
CHANGED
|
@@ -476,8 +476,13 @@ async def generate_and_edit(source_text, target_start, target_end, response_prom
|
|
| 476 |
if "error" in response:
|
| 477 |
return "Error: Failed to generate response", ""
|
| 478 |
response_text = response["content"]
|
| 479 |
-
|
| 480 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 481 |
|
| 482 |
# Step 4: Paste response into the target hole
|
| 483 |
paste_result = api.editor.paste(chunk_id, target_start)
|
|
|
|
| 476 |
if "error" in response:
|
| 477 |
return "Error: Failed to generate response", ""
|
| 478 |
response_text = response["content"]
|
| 479 |
+
# Extract only the response part after "Response for [TARGET]:" if present
|
| 480 |
+
response_match = re.search(r"Response for \[TARGET\]:\s*(.+)", response_text, re.DOTALL)
|
| 481 |
+
if response_match:
|
| 482 |
+
api.editor.clipboard = response_match.group(1).strip()
|
| 483 |
+
else:
|
| 484 |
+
api.editor.clipboard = response_text.strip() # Fallback to full response if no match
|
| 485 |
+
logger.info(f"Generated and set response to clipboard: {api.editor.clipboard}")
|
| 486 |
|
| 487 |
# Step 4: Paste response into the target hole
|
| 488 |
paste_result = api.editor.paste(chunk_id, target_start)
|