44
55import os
66import warnings
7- from typing import Literal , overload
7+ from typing import Any , Literal , overload
88
99from context7 .errors import Context7Error , Context7ValidationError
10- from context7 .http import HttpClient
10+ from context7 .http import HttpClient , TxtResponseHeaders
1111from context7 .models import (
1212 CodeDocsResponse ,
1313 InfoDocsResponse ,
@@ -79,8 +79,8 @@ def _build_docs_request(
7979
8080
8181def _process_docs_response (
82- result : str | dict ,
83- headers : object | None ,
82+ result : str | dict [ str , Any ] ,
83+ headers : TxtResponseHeaders | None ,
8484 mode : Literal ["info" , "code" ],
8585 format : Literal ["json" , "txt" ], # pylint: disable=redefined-builtin
8686) -> TextDocsResponse | CodeDocsResponse | InfoDocsResponse :
@@ -93,8 +93,10 @@ def _process_docs_response(
9393 hasNext = headers .has_next if headers else False ,
9494 hasPrev = headers .has_prev if headers else False ,
9595 )
96+ # When format is "txt", result is always a string from the HTTP response
97+ content = result if isinstance (result , str ) else ""
9698 return TextDocsResponse (
97- content = result ,
99+ content = content ,
98100 pagination = pagination ,
99101 totalTokens = headers .total_tokens if headers else 0 ,
100102 )
0 commit comments