mirror of
https://github.com/microsoft/autogen.git
synced 2025-11-07 21:34:00 +00:00
Use structured output for m1 orchestrator (#6540)
Use structured output when available in m1 orchestrator Co-authored-by: Victor Dibia <victordibia@microsoft.com>
This commit is contained in:
parent
cd49d71f2a
commit
b0c800255a
@ -47,6 +47,7 @@ from ._prompts import (
|
|||||||
ORCHESTRATOR_TASK_LEDGER_FULL_PROMPT,
|
ORCHESTRATOR_TASK_LEDGER_FULL_PROMPT,
|
||||||
ORCHESTRATOR_TASK_LEDGER_PLAN_PROMPT,
|
ORCHESTRATOR_TASK_LEDGER_PLAN_PROMPT,
|
||||||
ORCHESTRATOR_TASK_LEDGER_PLAN_UPDATE_PROMPT,
|
ORCHESTRATOR_TASK_LEDGER_PLAN_UPDATE_PROMPT,
|
||||||
|
LedgerEntry,
|
||||||
)
|
)
|
||||||
|
|
||||||
trace_logger = logging.getLogger(TRACE_LOGGER_NAME)
|
trace_logger = logging.getLogger(TRACE_LOGGER_NAME)
|
||||||
@ -309,7 +310,18 @@ class MagenticOneOrchestrator(BaseGroupChatManager):
|
|||||||
assert self._max_json_retries > 0
|
assert self._max_json_retries > 0
|
||||||
key_error: bool = False
|
key_error: bool = False
|
||||||
for _ in range(self._max_json_retries):
|
for _ in range(self._max_json_retries):
|
||||||
response = await self._model_client.create(self._get_compatible_context(context), json_output=True)
|
if self._model_client.model_info.get("structured_output", False):
|
||||||
|
response = await self._model_client.create(
|
||||||
|
self._get_compatible_context(context), json_output=LedgerEntry
|
||||||
|
)
|
||||||
|
elif self._model_client.model_info.get("json_output", False):
|
||||||
|
response = await self._model_client.create(
|
||||||
|
self._get_compatible_context(context), cancellation_token=cancellation_token, json_output=True
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
response = await self._model_client.create(
|
||||||
|
self._get_compatible_context(context), cancellation_token=cancellation_token
|
||||||
|
)
|
||||||
ledger_str = response.content
|
ledger_str = response.content
|
||||||
try:
|
try:
|
||||||
assert isinstance(ledger_str, str)
|
assert isinstance(ledger_str, str)
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
ORCHESTRATOR_SYSTEM_MESSAGE = ""
|
ORCHESTRATOR_SYSTEM_MESSAGE = ""
|
||||||
|
|
||||||
|
|
||||||
@ -98,6 +100,24 @@ Please output an answer in pure JSON format according to the following schema. T
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class LedgerEntryBooleanAnswer(BaseModel):
|
||||||
|
reason: str
|
||||||
|
answer: bool
|
||||||
|
|
||||||
|
|
||||||
|
class LedgerEntryStringAnswer(BaseModel):
|
||||||
|
reason: str
|
||||||
|
answer: str
|
||||||
|
|
||||||
|
|
||||||
|
class LedgerEntry(BaseModel):
|
||||||
|
is_request_satisfied: LedgerEntryBooleanAnswer
|
||||||
|
is_in_loop: LedgerEntryBooleanAnswer
|
||||||
|
is_progress_being_made: LedgerEntryBooleanAnswer
|
||||||
|
next_speaker: LedgerEntryStringAnswer
|
||||||
|
instruction_or_question: LedgerEntryStringAnswer
|
||||||
|
|
||||||
|
|
||||||
ORCHESTRATOR_TASK_LEDGER_FACTS_UPDATE_PROMPT = """As a reminder, we are working to solve the following task:
|
ORCHESTRATOR_TASK_LEDGER_FACTS_UPDATE_PROMPT = """As a reminder, we are working to solve the following task:
|
||||||
|
|
||||||
{task}
|
{task}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user