Update script to handle streaming properly.
If a response was set to streaming, the sub agent will return unusable data.
This commit is contained in:
parent
7fd6363421
commit
446a33c3a4
@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
title: Multi Agent Collaboration System for Open WebUI
|
title: Multi Agent Collaboration System for Open WebUI
|
||||||
Description: Allows for Multiple Models to act as Agents in collaboration
|
Description: Allows for Multiple Models to act as Agents in collaboration
|
||||||
version: 0.5.6
|
version: 0.7.6
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
@ -72,9 +72,16 @@ class Pipe:
|
|||||||
agents = __user__["valves"].agent_list
|
agents = __user__["valves"].agent_list
|
||||||
operator_model = __user__["valves"].operator_model
|
operator_model = __user__["valves"].operator_model
|
||||||
number_of_agents = len(agents)
|
number_of_agents = len(agents)
|
||||||
|
if "### Task:" in body["messages"][0]["content"]:
|
||||||
|
body["model"] = operator_model
|
||||||
|
print("Internal Request")
|
||||||
|
return await generate_chat_completion(__request__, body, user)
|
||||||
|
# Capture Stream Setting
|
||||||
|
original_stream = body["stream"]
|
||||||
if number_of_agents > 0:
|
if number_of_agents > 0:
|
||||||
# Process through each agent in the list
|
# Process through each agent in the list
|
||||||
for agent_model in agents:
|
for agent_model in agents:
|
||||||
|
body["stream"] = False
|
||||||
# Temporarily change the model to the agent model
|
# Temporarily change the model to the agent model
|
||||||
body["model"] = agent_model
|
body["model"] = agent_model
|
||||||
print(f"Model being use: {agent_model}")
|
print(f"Model being use: {agent_model}")
|
||||||
@ -83,6 +90,8 @@ class Pipe:
|
|||||||
description=message, status="agent_processing", done=True
|
description=message, status="agent_processing", done=True
|
||||||
)
|
)
|
||||||
response = await generate_chat_completion(__request__, body, user)
|
response = await generate_chat_completion(__request__, body, user)
|
||||||
|
content = response["choices"][0]["message"]["content"]
|
||||||
|
print(f"This is the content from {agent_model}: {content}")
|
||||||
# Add Agent response as context
|
# Add Agent response as context
|
||||||
body["messages"].append(
|
body["messages"].append(
|
||||||
{
|
{
|
||||||
@ -90,11 +99,9 @@ class Pipe:
|
|||||||
"content": f"{response} \n (Provided by Agent: {agent_model})",
|
"content": f"{response} \n (Provided by Agent: {agent_model})",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
# set Operator for final processing
|
body["model"] = operator_model
|
||||||
body["model"] = operator_model
|
body["stream"] = original_stream
|
||||||
print(f"Model being use: {operator_model}")
|
print(f"Model being use: {operator_model}")
|
||||||
message = f"Final Response from {operator_model}"
|
message = f"Final Response from {operator_model}"
|
||||||
await emitter.emit(
|
await emitter.emit(description=message, status="final_processing", done=True)
|
||||||
description=message, status="final_processing", done=True
|
|
||||||
)
|
|
||||||
return await generate_chat_completion(__request__, body, user)
|
return await generate_chat_completion(__request__, body, user)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user