Problem with proxy and streaming
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- networking
Research direction
Start with the provided AsyncClient configuration and run the example with and without proxy="http://localhost:8080" and verify=False. Compare when streamed chunks become available, then trace the proxy and streaming entry points involved. Done means the reported configuration preserves incremental streaming, with the behavior verified against the no-proxy case.
Written by the indexing model from the issue text.
Description
Originally opened by
@markowangaon 2024-02-13 01:54:52 in encode/httpx
I try to process streaming (return customer in chat). I need to use proxy. I have problem that response does not streaming when using proxy (all responses returned after all processed, no effect of writing text)
import asyncio
from typing import Optional
from httpx import AsyncClient
from openai import AsyncStream, AsyncOpenAI
from openai.types.chat import ChatCompletionChunk
async def get_openai_stream_agenerator() -> AsyncStream[ChatCompletionChunk]:
client = AsyncOpenAI(
http_client=AsyncClient(
# when I comment these two lines streaming is ok
proxy="http://localhost:8080", # I'm using mitmproxy with basic configuration
verify=False,
)
)
messages = [
{"role": "system", "content": "Return details about asking person"},
{"role": "user", "content": "Iga Świątek"},
]
response: AsyncStream[ChatCompletionChunk] = await client.chat.completions.create(
model='gpt-4-0613',
messages=messages,
stream=True,
) # type: ignore
return response
def get_delta_argument(chunk: ChatCompletionChunk) -> Optional[str]:
if len(chunk.choices) > 0:
return chunk.dict()['choices'][0]['delta']['content']
else:
return None
async def get_response_generator() -> None:
async for it in await get_openai_stream_agenerator():
value = get_delta_argument(it)
if value:
print(value, end="")
print()
if __name__ == '__main__':
asyncio.run(get_response_generator())
OS: macOS
Python version: Python v3.11.7
Library version: openai 1.12.0, httpx 0.26.0
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 103
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 25
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pydantic/httpx2
-
Please revert aiter_bytes signature to AsyncIteratorMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pydantic/httpx2#1158 · 2 comments ·
Maintainers usually reply within 1 day
-
Export AutoBackendMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
pydantic/httpx2#1131 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Mention header name error message for invalid header encodingsMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pydantic/httpx2#864 · 3 comments ·
Maintainers usually reply within 1 day
-
Support DigestAuth with "x-www-authenticate" in first response headerPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dbt-labs/spark-utils#51 ·
-
bug pydanty:is-working
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
pydantic/pydantic-ai#13444 ·
Maintainers usually reply within 1 day
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
good first issue help wanted
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
changelog investigate
Difficulty 1/5 Under an hour Newbie friendliness 68/100
ramnes/notion-sdk-py#502 ·