Skip to content

Commit

Permalink
Fixing a bug with Reasoning in the (g4f/Provider/Blackbox.py) provider
Browse files Browse the repository at this point in the history
  • Loading branch information
kqlio67 committed Jan 30, 2025
1 parent 8d1cfcd commit 3030ae5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions g4f/Provider/Blackbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ async def create_async_generator(
await raise_for_status(response)
response_text = await response.text()
parts = response_text.split('$~~~$')
print(parts)
text_to_yield = parts[2] if len(parts) >= 3 else response_text

if not text_to_yield or text_to_yield.isspace():
Expand All @@ -311,9 +312,17 @@ async def create_async_generator(
prompt = messages[-1]["content"]
yield ImageResponse(images=[image_url], alt=prompt)
else:
if "<think>" in text_to_yield and "</think>" in text_to_yield:
pre_think, rest = text_to_yield.split('<think>', 1)
think_content, post_think = rest.split('</think>', 1)
if "\n\n\n" in text_to_yield:
think_split = text_to_yield.split("\n\n\n", 1)
if len(think_split) > 1:
think_content, answer = think_split[0].strip(), think_split[1].strip()
yield Reasoning(status=think_content)
yield answer
full_response = f"{think_content}\n\n{answer}"
else:
yield text_to_yield
full_response = text_to_yield
elif "<think>" in text_to_yield:

pre_think = pre_think.strip()
think_content = think_content.strip()
Expand Down

0 comments on commit 3030ae5

Please sign in to comment.