Amm1rr / WebAI-to-API

Claude, Gemini to API : ) (Don't need API KEY)
MIT License
194 stars 39 forks source link

Bug: streaming process waiting problem #30

Closed linkedlist771 closed 2 months ago

linkedlist771 commented 2 months ago

in the [claude.py](https://github.com/Amm1rr/WebAI-to-API/blob/master/src/claude.pyline 239:

    answer = ""
    with httpx.stream("POST", url, headers=headers, data=payload) as r:
      for text in r.iter_text():
        response_parse_text = await parse_text(text)

        text_res = ""
        if response_parse_text:
            for text in response_parse_text:
                text_res += text

        answer = ''.join(text_res)
        print(answer)

        yield answer

I was testing the streaming output results and found that you need to add a async method right behind the yeild in the async function. for example:

yield answer
await asyncio.sleep(0)

Otherwise the function will be blocked until all the streaming data are received. There are two ways to solve it:

I have no idea make this happen, if you figure it out what is happening, catch me later.

Amm1rr commented 2 months ago

Thank you, I have fixed that.