Spaces:
Runtime error
Runtime error
context to string
Browse files
app.py
CHANGED
|
@@ -377,8 +377,8 @@ class PerplexityR1Model:
|
|
| 377 |
"""Call the model with the prompt."""
|
| 378 |
# Determine message format and count tokens
|
| 379 |
if isinstance(prompt, list):
|
| 380 |
-
#
|
| 381 |
-
combined_prompt = " ".join(msg.get("content", "") for msg in prompt)
|
| 382 |
self.last_input_token_count = len(combined_prompt.split())
|
| 383 |
messages = prompt # Already in message format
|
| 384 |
elif isinstance(prompt, str):
|
|
@@ -406,13 +406,11 @@ class PerplexityR1Model:
|
|
| 406 |
# For context length errors, try simple truncation
|
| 407 |
if "context length" in str(e).lower() or "token limit" in str(e).lower():
|
| 408 |
print("Context length error with R1-1776 - truncating prompt and retrying")
|
| 409 |
-
# Simple truncation - take the last ~80K characters which should be under the limit
|
| 410 |
if isinstance(prompt, str):
|
| 411 |
truncated_prompt = prompt[-80000:] if len(prompt) > 80000 else prompt
|
| 412 |
messages = [{"role": "user", "content": truncated_prompt}]
|
| 413 |
else:
|
| 414 |
-
|
| 415 |
-
combined_prompt = " ".join(msg.get("content", "") for msg in prompt)
|
| 416 |
truncated_prompt = combined_prompt[-80000:] if len(combined_prompt) > 80000 else combined_prompt
|
| 417 |
messages = [{"role": "user", "content": truncated_prompt}]
|
| 418 |
|
|
|
|
| 377 |
"""Call the model with the prompt."""
|
| 378 |
# Determine message format and count tokens
|
| 379 |
if isinstance(prompt, list):
|
| 380 |
+
# Convert each message's content to a string to avoid nested lists
|
| 381 |
+
combined_prompt = " ".join(str(msg.get("content", "")) for msg in prompt)
|
| 382 |
self.last_input_token_count = len(combined_prompt.split())
|
| 383 |
messages = prompt # Already in message format
|
| 384 |
elif isinstance(prompt, str):
|
|
|
|
| 406 |
# For context length errors, try simple truncation
|
| 407 |
if "context length" in str(e).lower() or "token limit" in str(e).lower():
|
| 408 |
print("Context length error with R1-1776 - truncating prompt and retrying")
|
|
|
|
| 409 |
if isinstance(prompt, str):
|
| 410 |
truncated_prompt = prompt[-80000:] if len(prompt) > 80000 else prompt
|
| 411 |
messages = [{"role": "user", "content": truncated_prompt}]
|
| 412 |
else:
|
| 413 |
+
combined_prompt = " ".join(str(msg.get("content", "")) for msg in prompt)
|
|
|
|
| 414 |
truncated_prompt = combined_prompt[-80000:] if len(combined_prompt) > 80000 else combined_prompt
|
| 415 |
messages = [{"role": "user", "content": truncated_prompt}]
|
| 416 |
|