XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

Improve followups

8c4c4408
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +9 -7
Modified g4f/Provider/PollinationsAI.py +9 -7
@@ -59,7 +59,7 @@ FOLLOWUPS_TOOLS = [{
59 59
60 60 FOLLOWUPS_DEVELOPER_MESSAGE = [{
61 61 "role": "developer",
62 "content": "Prefix conversation title with one or more emojies. Suggested 4 Followups"
62 "content": "Prefix conversation title with one or more emojies. Suggested 4 Followups (User messages only).",
63 63 }]
64 64
65 65 class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
@@ -509,6 +509,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
509 509 elif response.headers["content-type"].startswith("text/event-stream"):
510 510 reasoning = False
511 511 model_returned = False
512 full_content = ""
512 513 async for result in see_stream(response.content):
513 514 if "error" in result:
514 515 raise ResponseError(result["error"].get("message", result["error"]))
@@ -522,6 +523,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
522 523 content = choice.get("delta", {}).get("content")
523 524 if content:
524 525 yield content
526 full_content += content
525 527 tool_calls = choice.get("delta", {}).get("tool_calls")
526 528 if tool_calls:
527 529 yield ToolCalls(choice["delta"]["tool_calls"])
@@ -535,20 +537,21 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
535 537 if reasoning:
536 538 yield Reasoning(status="")
537 539 if kwargs.get("action") == "next":
538 safe_messages = []
540 tool_messages = []
539 541 for message in messages:
540 542 if message.get("role") == "user":
541 543 if isinstance(message.get("content"), str):
542 safe_messages.append({"role": "user", "content": message.get("content")})
544 tool_messages.append({"role": "user", "content": message.get("content")})
543 545 elif isinstance(message.get("content"), list):
544 546 next_value = message.get("content").pop()
545 547 if isinstance(next_value, dict):
546 548 next_value = next_value.get("text")
547 549 if next_value:
548 safe_messages.append({"role": "user", "content": next_value})
550 tool_messages.append({"role": "user", "content": next_value})
551 tool_messages.append({"role": "assistant", "content": full_content})
549 552 data = {
550 553 "model": "openai",
551 "messages": safe_messages + FOLLOWUPS_DEVELOPER_MESSAGE,
554 "messages": tool_messages + FOLLOWUPS_DEVELOPER_MESSAGE,
552 555 "tool_choice": "required",
553 556 "tools": FOLLOWUPS_TOOLS
554 557 }
@@ -563,8 +566,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
563 566 if arguments.get("followups"):
564 567 yield SuggestedFollowups(arguments.get("followups"))
565 568 except Exception as e:
566 debug.error("Error generating title and followups")
567 debug.error(e)
569 debug.error("Error generating title and followups:", e)
568 570 elif response.headers["content-type"].startswith("application/json"):
569 571 prompt = format_media_prompt(messages)
570 572 result = await response.json()