From d9d34433fc8814f445f83db559b824f2a2104ba2 Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Mon, 13 Jan 2025 20:06:49 -0800 Subject: [PATCH] Update spec --- docs/resources/llama-stack-spec.html | 82 +++++++++++++++---- docs/resources/llama-stack-spec.yaml | 55 ++++++++++--- llama_stack/apis/agents/event_logger.py | 2 +- .../agents/meta_reference/agent_instance.py | 4 +- .../inference/meta_reference/inference.py | 4 +- .../remote/inference/groq/groq_utils.py | 2 +- .../remote/inference/nvidia/openai_utils.py | 2 +- .../tests/inference/test_text_inference.py | 2 +- .../utils/inference/openai_compat.py | 4 +- 9 files changed, 118 insertions(+), 39 deletions(-) diff --git a/docs/resources/llama-stack-spec.html b/docs/resources/llama-stack-spec.html index 0ce216479..5ed8701a4 100644 --- a/docs/resources/llama-stack-spec.html +++ b/docs/resources/llama-stack-spec.html @@ -3843,8 +3843,8 @@ "properties": { "role": { "type": "string", - "const": "ipython", - "default": "ipython" + "const": "tool", + "default": "tool" }, "call_id": { "type": "string" @@ -4185,14 +4185,7 @@ "$ref": "#/components/schemas/ChatCompletionResponseEventType" }, "delta": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/components/schemas/ToolCallDelta" - } - ] + "$ref": "#/components/schemas/ContentDelta" }, "logprobs": { "type": "array", @@ -4232,6 +4225,50 @@ ], "title": "SSE-stream of these events." }, + "ContentDelta": { + "oneOf": [ + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "text", + "default": "text" + }, + "text": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "type", + "text" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "image", + "default": "image" + }, + "data": { + "type": "string", + "contentEncoding": "base64" + } + }, + "additionalProperties": false, + "required": [ + "type", + "data" + ] + }, + { + "$ref": "#/components/schemas/ToolCallDelta" + } + ] + }, "TokenLogProbs": { "type": "object", "properties": { @@ -4250,6 +4287,11 @@ "ToolCallDelta": { "type": "object", "properties": { + "type": { + "type": "string", + "const": "tool_call", + "default": "tool_call" + }, "content": { "oneOf": [ { @@ -4266,6 +4308,7 @@ }, "additionalProperties": false, "required": [ + "type", "content", "parse_status" ] @@ -4275,8 +4318,8 @@ "enum": [ "started", "in_progress", - "failure", - "success" + "failed", + "succeeded" ] }, "CompletionRequest": { @@ -4777,18 +4820,16 @@ "step_id": { "type": "string" }, - "text_delta": { - "type": "string" - }, - "tool_call_delta": { - "$ref": "#/components/schemas/ToolCallDelta" + "delta": { + "$ref": "#/components/schemas/ContentDelta" } }, "additionalProperties": false, "required": [ "event_type", "step_type", - "step_id" + "step_id", + "delta" ] }, "AgentTurnResponseStepStartPayload": { @@ -8758,6 +8799,10 @@ "name": "CompletionResponseStreamChunk", "description": "streamed completion response.\n\n" }, + { + "name": "ContentDelta", + "description": "" + }, { "name": "CreateAgentRequest", "description": "" @@ -9392,6 +9437,7 @@ "CompletionRequest", "CompletionResponse", "CompletionResponseStreamChunk", + "ContentDelta", "CreateAgentRequest", "CreateAgentSessionRequest", "CreateAgentTurnRequest", diff --git a/docs/resources/llama-stack-spec.yaml b/docs/resources/llama-stack-spec.yaml index 031178ce9..2a573959f 100644 --- a/docs/resources/llama-stack-spec.yaml +++ b/docs/resources/llama-stack-spec.yaml @@ -150,6 +150,8 @@ components: AgentTurnResponseStepProgressPayload: additionalProperties: false properties: + delta: + $ref: '#/components/schemas/ContentDelta' event_type: const: step_progress default: step_progress @@ -163,14 +165,11 @@ components: - shield_call - memory_retrieval type: string - text_delta: - type: string - tool_call_delta: - $ref: '#/components/schemas/ToolCallDelta' required: - event_type - step_type - step_id + - delta type: object AgentTurnResponseStepStartPayload: additionalProperties: false @@ -462,9 +461,7 @@ components: additionalProperties: false properties: delta: - oneOf: - - type: string - - $ref: '#/components/schemas/ToolCallDelta' + $ref: '#/components/schemas/ContentDelta' event_type: $ref: '#/components/schemas/ChatCompletionResponseEventType' logprobs: @@ -571,6 +568,34 @@ components: - delta title: streamed completion response. type: object + ContentDelta: + oneOf: + - additionalProperties: false + properties: + text: + type: string + type: + const: text + default: text + type: string + required: + - type + - text + type: object + - additionalProperties: false + properties: + data: + contentEncoding: base64 + type: string + type: + const: image + default: image + type: string + required: + - type + - data + type: object + - $ref: '#/components/schemas/ToolCallDelta' CreateAgentRequest: additionalProperties: false properties: @@ -2664,7 +2689,12 @@ components: - $ref: '#/components/schemas/ToolCall' parse_status: $ref: '#/components/schemas/ToolCallParseStatus' + type: + const: tool_call + default: tool_call + type: string required: + - type - content - parse_status type: object @@ -2672,8 +2702,8 @@ components: enum: - started - in_progress - - failure - - success + - failed + - succeeded type: string ToolChoice: enum: @@ -2888,8 +2918,8 @@ components: content: $ref: '#/components/schemas/InterleavedContent' role: - const: ipython - default: ipython + const: tool + default: tool type: string tool_name: oneOf: @@ -5500,6 +5530,8 @@ tags: ' name: CompletionResponseStreamChunk +- description: + name: ContentDelta - description: name: CreateAgentRequest @@ -5939,6 +5971,7 @@ x-tagGroups: - CompletionRequest - CompletionResponse - CompletionResponseStreamChunk + - ContentDelta - CreateAgentRequest - CreateAgentSessionRequest - CreateAgentTurnRequest diff --git a/llama_stack/apis/agents/event_logger.py b/llama_stack/apis/agents/event_logger.py index 41004ccb0..9e2f14805 100644 --- a/llama_stack/apis/agents/event_logger.py +++ b/llama_stack/apis/agents/event_logger.py @@ -132,7 +132,7 @@ class EventLogger: delta = event.payload.delta if delta.type == "tool_call": - if delta.parse_status == ToolCallParseStatus.success: + if delta.parse_status == ToolCallParseStatus.succeeded: yield ( event, LogEvent( diff --git a/llama_stack/providers/inline/agents/meta_reference/agent_instance.py b/llama_stack/providers/inline/agents/meta_reference/agent_instance.py index be33d75c3..2299e80d1 100644 --- a/llama_stack/providers/inline/agents/meta_reference/agent_instance.py +++ b/llama_stack/providers/inline/agents/meta_reference/agent_instance.py @@ -415,7 +415,7 @@ class ChatAgent(ShieldRunnerMixin): step_type=StepType.tool_execution.value, step_id=step_id, delta=ToolCallDelta( - parse_status=ToolCallParseStatus.success, + parse_status=ToolCallParseStatus.succeeded, content=ToolCall( call_id="", tool_name=MEMORY_QUERY_TOOL, @@ -511,7 +511,7 @@ class ChatAgent(ShieldRunnerMixin): delta = event.delta if delta.type == "tool_call": - if delta.parse_status == ToolCallParseStatus.success: + if delta.parse_status == ToolCallParseStatus.succeeded: tool_calls.append(delta.content) if stream: yield AgentTurnResponseStreamChunk( diff --git a/llama_stack/providers/inline/inference/meta_reference/inference.py b/llama_stack/providers/inline/inference/meta_reference/inference.py index e099580af..d64d32f03 100644 --- a/llama_stack/providers/inline/inference/meta_reference/inference.py +++ b/llama_stack/providers/inline/inference/meta_reference/inference.py @@ -431,7 +431,7 @@ class MetaReferenceInferenceImpl( event_type=ChatCompletionResponseEventType.progress, delta=ToolCallDelta( content="", - parse_status=ToolCallParseStatus.failure, + parse_status=ToolCallParseStatus.failed, ), stop_reason=stop_reason, ) @@ -443,7 +443,7 @@ class MetaReferenceInferenceImpl( event_type=ChatCompletionResponseEventType.progress, delta=ToolCallDelta( content=tool_call, - parse_status=ToolCallParseStatus.success, + parse_status=ToolCallParseStatus.succeeded, ), stop_reason=stop_reason, ) diff --git a/llama_stack/providers/remote/inference/groq/groq_utils.py b/llama_stack/providers/remote/inference/groq/groq_utils.py index b87c0c94c..11f684847 100644 --- a/llama_stack/providers/remote/inference/groq/groq_utils.py +++ b/llama_stack/providers/remote/inference/groq/groq_utils.py @@ -215,7 +215,7 @@ async def convert_chat_completion_response_stream( event_type=event_type, delta=ToolCallDelta( content=tool_call, - parse_status=ToolCallParseStatus.success, + parse_status=ToolCallParseStatus.succeeded, ), ) ) diff --git a/llama_stack/providers/remote/inference/nvidia/openai_utils.py b/llama_stack/providers/remote/inference/nvidia/openai_utils.py index 955b65aa5..975812844 100644 --- a/llama_stack/providers/remote/inference/nvidia/openai_utils.py +++ b/llama_stack/providers/remote/inference/nvidia/openai_utils.py @@ -501,7 +501,7 @@ async def convert_openai_chat_completion_stream( event_type=next(event_type), delta=ToolCallDelta( content=_convert_openai_tool_calls(choice.delta.tool_calls)[0], - parse_status=ToolCallParseStatus.success, + parse_status=ToolCallParseStatus.succeeded, ), logprobs=_convert_openai_logprobs(choice.logprobs), ) diff --git a/llama_stack/providers/tests/inference/test_text_inference.py b/llama_stack/providers/tests/inference/test_text_inference.py index 24093cb59..932ae36e6 100644 --- a/llama_stack/providers/tests/inference/test_text_inference.py +++ b/llama_stack/providers/tests/inference/test_text_inference.py @@ -475,7 +475,7 @@ class TestInference: last = grouped[ChatCompletionResponseEventType.progress][-1] # assert last.event.stop_reason == expected_stop_reason - assert last.event.delta.parse_status == ToolCallParseStatus.success + assert last.event.delta.parse_status == ToolCallParseStatus.succeeded assert last.event.delta.content.type == "tool_call" call = last.event.delta.content diff --git a/llama_stack/providers/utils/inference/openai_compat.py b/llama_stack/providers/utils/inference/openai_compat.py index e70ad4033..82e01c364 100644 --- a/llama_stack/providers/utils/inference/openai_compat.py +++ b/llama_stack/providers/utils/inference/openai_compat.py @@ -245,7 +245,7 @@ async def process_chat_completion_stream_response( event_type=ChatCompletionResponseEventType.progress, delta=ToolCallDelta( content="", - parse_status=ToolCallParseStatus.failure, + parse_status=ToolCallParseStatus.failed, ), stop_reason=stop_reason, ) @@ -257,7 +257,7 @@ async def process_chat_completion_stream_response( event_type=ChatCompletionResponseEventType.progress, delta=ToolCallDelta( content=tool_call, - parse_status=ToolCallParseStatus.success, + parse_status=ToolCallParseStatus.succeeded, ), stop_reason=stop_reason, )