XFEstudio/gpt4free
Enhance DeepSeek streaming, uploads, and testing support (#3507)
* DeepSeek: SSE streaming, PoW uploads & tests Add full DeepSeek provider streaming and file upload support plus unit tests. Implement SSE parser (iter_deepseek_sse), robust stream state handling, resume/continue logic (iter_chat_stream), PoW challenge solving (create_pow_response), multipart uploads (upload_file) and poll-based parsing wait (wait_for_file_parsed). Improve header handling (_build_chat_headers/_build_upload_session_headers), fragment/status processing and diagnostic logging. Add unit tests covering chunk logging, streaming and upload flows (etc/unittest/test_deepseek_*.py). Also adjust image.detect_file_type signature to always return (extension, mime). * DeepSeek: modularize PoW/stream and improve handling Move DeepSeek PoW and SSE stream logic into g4f/Provider/needs_auth/deepseek (pow.py, stream.py) and add small init. Refactor DeepSeek.py to import and use these helpers, add _unwrap_biz_response, _build_completion_payload, _resolve_upload_metadata, and upload_files. Simplify delete_chat_session to the observed POST contract and return bool. Improve header/timezone handling, error checking for business envelope, file parsing failure statuses, and run PoW off the event loop (asyncio.to_thread). Update and extend unit tests to cover new behaviors. * Add deepseek chunk log helper and update test import Add ChunkJsonlWriter and helpers in etc/testing/deepseek_chunk_log.py to record provider response chunks to a durable JSONL journal (with reader and store_or_collect_chunk). Update unit test import in etc/unittest/test_deepseek_chunk_log.py to use the new helper path. Also remove stray trailing blank lines in deepseek package files (pow.py, stream.py, __init__.py). * DeepSeek: handle fragment kinds and empty resumes Enhance DeepSeek streaming: track fragment kinds and indices, properly handle indexed SET/APPEND and type/content patches, and emit reasoning/response chunks based on fragment types. Add _record_fragment_kind and _fragment_index_from_path, plus new state fields (fragment_kinds, next_fragment_index). Improve resume logic in DeepSeek provider to attempt a single resume for FINISHED streams with no response, track empty_response_resume_attempted, and raise ResponseError when appropriate. Update and extend unit tests to cover fragment indexing, resumed full messages, and empty-resume behaviors. * Update test_deepseek_stream.py * Fix DeepSeek PoW executor usage This change updates the DeepSeek upload flow to solve PoW challenges using the running event loop's executor instead of asyncio.to_thread. It keeps the async behavior consistent with the test environment and avoids the underlying issue seen in the upload path. The unit test was also updated to assert the executor call pattern and validate the expected PoW response handling.
f9e5becf