Update gemini_client/core.py
Browse files- gemini_client/core.py +1 -33
gemini_client/core.py
CHANGED
|
@@ -696,13 +696,7 @@ class AsyncChatbot:
|
|
| 696 |
media_mime_type = "image/jpeg"
|
| 697 |
|
| 698 |
# Pass proxy and impersonate settings to upload_file
|
| 699 |
-
|
| 700 |
-
media_upload_id = await upload_file(
|
| 701 |
-
media_file,
|
| 702 |
-
proxy=self.proxies_dict,
|
| 703 |
-
impersonate=self.impersonate,
|
| 704 |
-
timeout=600
|
| 705 |
-
)
|
| 706 |
console.log(f"{media_type.capitalize()} uploaded successfully. ID: {media_upload_id}")
|
| 707 |
except Exception as e:
|
| 708 |
console.log(f"[red]Error uploading {media_type}: {e}[/red]")
|
|
@@ -878,20 +872,6 @@ class AsyncChatbot:
|
|
| 878 |
break
|
| 879 |
except json.JSONDecodeError:
|
| 880 |
continue
|
| 881 |
-
|
| 882 |
-
# Check for error response "e" type
|
| 883 |
-
if line.startswith('[["e",'):
|
| 884 |
-
try:
|
| 885 |
-
error_json = json.loads(line)
|
| 886 |
-
if isinstance(error_json, list) and len(error_json) > 0 and isinstance(error_json[0], list):
|
| 887 |
-
# Usually nested like [["e", 5, ...]]
|
| 888 |
-
error_data = error_json[0]
|
| 889 |
-
if error_data[0] == "e":
|
| 890 |
-
error_code = error_data[1] if len(error_data) > 1 else "Unknown"
|
| 891 |
-
console.log(f"[red]Gemini returned error code: {error_code}[/red]")
|
| 892 |
-
return {"content": f"Gemini API Error: {error_code}", "error": True}
|
| 893 |
-
except Exception as e:
|
| 894 |
-
console.log(f"[red]Error parsing error response: {e}[/red]")
|
| 895 |
|
| 896 |
if not body:
|
| 897 |
# Attempt fallback: Deep search for content in all_parsed_parts
|
|
@@ -939,21 +919,9 @@ class AsyncChatbot:
|
|
| 939 |
"choices": [{"id": "fallback", "content": content_candidate}]
|
| 940 |
}
|
| 941 |
|
| 942 |
-
# Save full response to debug file
|
| 943 |
-
try:
|
| 944 |
-
debug_path = "last_gemini_response_debug.txt"
|
| 945 |
-
with open(debug_path, "w", encoding="utf-8") as f:
|
| 946 |
-
f.write(resp.text)
|
| 947 |
-
console.log(f"[red]Full response saved to {debug_path}[/red]")
|
| 948 |
-
except Exception as e:
|
| 949 |
-
console.log(f"[red]Failed to save debug file: {e}[/red]")
|
| 950 |
-
|
| 951 |
error_details = f"Failed to parse response body. No valid data found.\nStatus: {resp.status_code}\nResponse snippet: {resp.text[:2000]}..."
|
| 952 |
console.log(f"[red]{error_details}[/red]")
|
| 953 |
|
| 954 |
-
# FORCE PRINT FULL RESPONSE TO CONSOLE FOR HF SPACES DEBUGGING
|
| 955 |
-
console.log(f"[yellow]FULL RESPONSE (for debugging):[/yellow]\n{resp.text}")
|
| 956 |
-
|
| 957 |
# Debug: Dump all_parsed_parts keys or summary
|
| 958 |
console.log(f"[red]Parsed parts count: {len(all_parsed_parts)}[/red]")
|
| 959 |
|
|
|
|
| 696 |
media_mime_type = "image/jpeg"
|
| 697 |
|
| 698 |
# Pass proxy and impersonate settings to upload_file
|
| 699 |
+
media_upload_id = await upload_file(media_file, proxy=self.proxies_dict, impersonate=self.impersonate)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 700 |
console.log(f"{media_type.capitalize()} uploaded successfully. ID: {media_upload_id}")
|
| 701 |
except Exception as e:
|
| 702 |
console.log(f"[red]Error uploading {media_type}: {e}[/red]")
|
|
|
|
| 872 |
break
|
| 873 |
except json.JSONDecodeError:
|
| 874 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 875 |
|
| 876 |
if not body:
|
| 877 |
# Attempt fallback: Deep search for content in all_parsed_parts
|
|
|
|
| 919 |
"choices": [{"id": "fallback", "content": content_candidate}]
|
| 920 |
}
|
| 921 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 922 |
error_details = f"Failed to parse response body. No valid data found.\nStatus: {resp.status_code}\nResponse snippet: {resp.text[:2000]}..."
|
| 923 |
console.log(f"[red]{error_details}[/red]")
|
| 924 |
|
|
|
|
|
|
|
|
|
|
| 925 |
# Debug: Dump all_parsed_parts keys or summary
|
| 926 |
console.log(f"[red]Parsed parts count: {len(all_parsed_parts)}[/red]")
|
| 927 |
|