Skip to content

Commit 970f50e

Browse files
committed
Bump to llama-stack and llama-stack-client 0.3.0
1 parent d5ecd53 commit 970f50e

10 files changed

Lines changed: 70 additions & 59 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ dependencies = [
2828
# Used by authentication/k8s integration
2929
"kubernetes>=30.1.0",
3030
# Used to call Llama Stack APIs
31-
"llama-stack==0.2.22",
32-
"llama-stack-client==0.2.22",
31+
"llama-stack==0.3.0",
32+
"llama-stack-client==0.3.0",
3333
# Used by Logger
3434
"rich>=14.0.0",
3535
# Used by JWK token auth handler

src/app/endpoints/query.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
APIConnectionError,
1414
AsyncLlamaStackClient, # type: ignore
1515
)
16-
from llama_stack_client.lib.agents.event_logger import interleaved_content_as_str
1716
from llama_stack_client.types import Shield, UserMessage # type: ignore
18-
from llama_stack_client.types.agents.turn import Turn
19-
from llama_stack_client.types.agents.turn_create_params import (
17+
from llama_stack_client.types.alpha.agents.turn import Turn
18+
from llama_stack_client.types.alpha.agents.turn_create_params import (
2019
Toolgroup,
2120
ToolgroupAgentToolGroupWithArgs,
2221
Document,
2322
)
2423
from llama_stack_client.types.model_list_response import ModelListResponse
2524
from llama_stack_client.types.shared.interleaved_content_item import TextContentItem
26-
from llama_stack_client.types.tool_execution_step import ToolExecutionStep
25+
from llama_stack_client.types.alpha.tool_execution_step import ToolExecutionStep
2726

2827
import constants
2928
import metrics
@@ -62,7 +61,7 @@
6261
)
6362
from utils.mcp_headers import handle_mcp_headers_with_toolgroups, mcp_headers_dependency
6463
from utils.transcripts import store_transcript
65-
from utils.types import TurnSummary
64+
from utils.types import TurnSummary, content_to_str
6665
from utils.token_counter import extract_and_update_token_metrics, TokenCounter
6766

6867
logger = logging.getLogger("app.endpoints.handlers")
@@ -211,7 +210,7 @@ async def get_topic_summary(
211210
)
212211
response = cast(Turn, response)
213212
return (
214-
interleaved_content_as_str(response.output_message.content)
213+
content_to_str(response.output_message.content)
215214
if (
216215
getattr(response, "output_message", None) is not None
217216
and getattr(response.output_message, "content", None) is not None
@@ -778,7 +777,7 @@ async def retrieve_response( # pylint: disable=too-many-locals,too-many-branche
778777

779778
summary = TurnSummary(
780779
llm_response=(
781-
interleaved_content_as_str(response.output_message.content)
780+
content_to_str(response.output_message.content)
782781
if (
783782
getattr(response, "output_message", None) is not None
784783
and getattr(response.output_message, "content", None) is not None

src/app/endpoints/streaming_query.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
APIConnectionError,
1717
AsyncLlamaStackClient, # type: ignore
1818
)
19-
from llama_stack_client.lib.agents.event_logger import interleaved_content_as_str
2019
from llama_stack_client.types import UserMessage # type: ignore
21-
from llama_stack_client.types.agents.agent_turn_response_stream_chunk import (
20+
from llama_stack_client.types.alpha.agents.agent_turn_response_stream_chunk import (
2221
AgentTurnResponseStreamChunk,
2322
)
2423
from llama_stack_client.types.shared import ToolCall
2524
from llama_stack_client.types.shared.interleaved_content_item import TextContentItem
26-
from llama_stack_client.types.agents.turn_create_params import Document
25+
from llama_stack_client.types.alpha.agents.turn_create_params import Document
2726

2827
from app.endpoints.query import (
2928
get_rag_toolgroups,
@@ -65,7 +64,7 @@
6564
from utils.mcp_headers import handle_mcp_headers_with_toolgroups, mcp_headers_dependency
6665
from utils.token_counter import TokenCounter, extract_token_usage_from_turn
6766
from utils.transcripts import store_transcript
68-
from utils.types import TurnSummary
67+
from utils.types import TurnSummary, content_to_str
6968

7069

7170
logger = logging.getLogger("app.endpoints.handlers")
@@ -444,9 +443,7 @@ def _handle_turn_complete_event(
444443
str: SSE-formatted string containing the turn completion
445444
event and output message content.
446445
"""
447-
full_response = interleaved_content_as_str(
448-
chunk.event.payload.turn.output_message.content
449-
)
446+
full_response = content_to_str(chunk.event.payload.turn.output_message.content)
450447

451448
if media_type == MEDIA_TYPE_TEXT:
452449
yield (
@@ -615,7 +612,7 @@ def _handle_tool_execution_event(
615612

616613
for r in chunk.event.payload.step_details.tool_responses:
617614
if r.tool_name == "query_from_memory":
618-
inserted_context = interleaved_content_as_str(r.content)
615+
inserted_context = content_to_str(r.content)
619616
yield stream_event(
620617
data={
621618
"id": chunk_id,
@@ -666,7 +663,7 @@ def _handle_tool_execution_event(
666663
"id": chunk_id,
667664
"token": {
668665
"tool_name": r.tool_name,
669-
"response": interleaved_content_as_str(r.content),
666+
"response": content_to_str(r.content),
670667
},
671668
},
672669
event_type=LLM_TOOL_RESULT_EVENT,
@@ -749,9 +746,7 @@ async def response_generator(
749746
continue
750747
p = chunk.event.payload
751748
if p.event_type == "turn_complete":
752-
summary.llm_response = interleaved_content_as_str(
753-
p.turn.output_message.content
754-
)
749+
summary.llm_response = content_to_str(p.turn.output_message.content)
755750
latest_turn = p.turn
756751
system_prompt = get_system_prompt(context.query_request, configuration)
757752
try:

src/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Minimal and maximal supported Llama Stack version
44
MINIMAL_SUPPORTED_LLAMA_STACK_VERSION = "0.2.17"
5-
MAXIMAL_SUPPORTED_LLAMA_STACK_VERSION = "0.2.22"
5+
MAXIMAL_SUPPORTED_LLAMA_STACK_VERSION = "0.3.0"
66

77
UNABLE_TO_PROCESS_RESPONSE = "Unable to process this request"
88

src/metrics/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from llama_stack.models.llama.datatypes import RawMessage
66
from llama_stack.models.llama.llama3.chat_format import ChatFormat
77
from llama_stack.models.llama.llama3.tokenizer import Tokenizer
8-
from llama_stack_client.types.agents.turn import Turn
8+
from llama_stack_client.types.alpha.agents.turn import Turn
99

1010
import metrics
1111
from client import AsyncLlamaStackClientHolder

src/models/requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from enum import Enum
55

66
from pydantic import BaseModel, model_validator, field_validator, Field
7-
from llama_stack_client.types.agents.turn_create_params import Document
7+
from llama_stack_client.types.alpha.agents.turn_create_params import Document
88

99
from log import get_logger
1010
from utils import suid

src/utils/token_counter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from llama_stack.models.llama.datatypes import RawMessage
88
from llama_stack.models.llama.llama3.chat_format import ChatFormat
99
from llama_stack.models.llama.llama3.tokenizer import Tokenizer
10-
from llama_stack_client.types.agents.turn import Turn
10+
from llama_stack_client.types.alpha.agents.turn import Turn
1111

1212
import metrics
1313

src/utils/types.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,41 @@
22

33
from typing import Any, Optional
44
import json
5-
from llama_stack_client.lib.agents.event_logger import interleaved_content_as_str
65
from llama_stack_client.lib.agents.tool_parser import ToolParser
76
from llama_stack_client.types.shared.completion_message import CompletionMessage
87
from llama_stack_client.types.shared.tool_call import ToolCall
9-
from llama_stack_client.types.tool_execution_step import ToolExecutionStep
8+
from llama_stack_client.types.shared.interleaved_content_item import (
9+
TextContentItem,
10+
ImageContentItem,
11+
)
12+
from llama_stack_client.types.alpha.tool_execution_step import ToolExecutionStep
1013
from pydantic import BaseModel
1114
from models.responses import RAGChunk
1215
from constants import DEFAULT_RAG_TOOL
1316

1417

18+
def content_to_str(content: Any) -> str:
19+
"""Convert content (str, TextContentItem, ImageContentItem, or list) to string.
20+
21+
Args:
22+
content: Content to convert to string.
23+
24+
Returns:
25+
str: String representation of the content.
26+
"""
27+
if content is None:
28+
return ""
29+
if isinstance(content, str):
30+
return content
31+
if isinstance(content, TextContentItem):
32+
return content.text
33+
if isinstance(content, ImageContentItem):
34+
return "<image>"
35+
if isinstance(content, list):
36+
return " ".join(content_to_str(item) for item in content)
37+
return str(content)
38+
39+
1540
class Singleton(type):
1641
"""Metaclass for Singleton support."""
1742

@@ -99,9 +124,7 @@ def append_tool_calls_from_llama(self, tec: ToolExecutionStep) -> None:
99124
responses_by_id = {tc.call_id: tc for tc in tec.tool_responses}
100125
for call_id, tc in calls_by_id.items():
101126
resp = responses_by_id.get(call_id)
102-
response_content = (
103-
interleaved_content_as_str(resp.content) if resp else None
104-
)
127+
response_content = content_to_str(resp.content) if resp else None
105128

106129
self.tool_calls.append(
107130
ToolCallSummary(

tests/unit/app/endpoints/test_query.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
from llama_stack_client import APIConnectionError
1616
from llama_stack_client.types import UserMessage # type: ignore
17-
from llama_stack_client.types.agents.turn import Turn
17+
from llama_stack_client.types.alpha.agents.turn import Turn
1818
from llama_stack_client.types.shared.interleaved_content_item import TextContentItem
19-
from llama_stack_client.types.tool_execution_step import ToolExecutionStep
20-
from llama_stack_client.types.tool_response import ToolResponse
19+
from llama_stack_client.types.alpha.tool_execution_step import ToolExecutionStep
20+
from llama_stack_client.types.alpha.tool_response import ToolResponse
2121
from pydantic import AnyUrl
2222

2323
from tests.unit.conftest import AgentFixtures
@@ -1929,9 +1929,9 @@ async def test_get_topic_summary_successful_response(mocker: MockerFixture) -> N
19291929
# Mock the agent's create_turn method
19301930
mock_agent.create_turn.return_value = mock_response
19311931

1932-
# Mock the interleaved_content_as_str function
1932+
# Mock the content_to_str function
19331933
mocker.patch(
1934-
"app.endpoints.query.interleaved_content_as_str",
1934+
"app.endpoints.query.content_to_str",
19351935
return_value="This is a topic summary about OpenStack",
19361936
)
19371937

@@ -2062,9 +2062,9 @@ async def test_get_topic_summary_with_interleaved_content(
20622062
# Mock the agent's create_turn method
20632063
mock_agent.create_turn.return_value = mock_response
20642064

2065-
# Mock the interleaved_content_as_str function
2066-
mock_interleaved_content_as_str = mocker.patch(
2067-
"app.endpoints.query.interleaved_content_as_str", return_value="Topic summary"
2065+
# Mock the content_to_str function
2066+
mock_content_to_str = mocker.patch(
2067+
"app.endpoints.query.content_to_str", return_value="Topic summary"
20682068
)
20692069

20702070
# Mock the get_topic_summary_system_prompt function
@@ -2085,8 +2085,8 @@ async def test_get_topic_summary_with_interleaved_content(
20852085
# Assertions
20862086
assert result == "Topic summary"
20872087

2088-
# Verify interleaved_content_as_str was called with the content
2089-
mock_interleaved_content_as_str.assert_called_once_with(mock_content)
2088+
# Verify content_to_str was called with the content
2089+
mock_content_to_str.assert_called_once_with(mock_content)
20902090

20912091

20922092
@pytest.mark.asyncio
@@ -2107,10 +2107,8 @@ async def test_get_topic_summary_system_prompt_retrieval(mocker: MockerFixture)
21072107
# Mock the agent's create_turn method
21082108
mock_agent.create_turn.return_value = mock_response
21092109

2110-
# Mock the interleaved_content_as_str function
2111-
mocker.patch(
2112-
"app.endpoints.query.interleaved_content_as_str", return_value="Topic summary"
2113-
)
2110+
# Mock the content_to_str function
2111+
mocker.patch("app.endpoints.query.content_to_str", return_value="Topic summary")
21142112

21152113
# Mock the get_topic_summary_system_prompt function
21162114
mock_get_topic_summary_system_prompt = mocker.patch(
@@ -2183,10 +2181,8 @@ async def test_get_topic_summary_agent_creation_parameters(
21832181
# Mock the agent's create_turn method
21842182
mock_agent.create_turn.return_value = mock_response
21852183

2186-
# Mock the interleaved_content_as_str function
2187-
mocker.patch(
2188-
"app.endpoints.query.interleaved_content_as_str", return_value="Topic summary"
2189-
)
2184+
# Mock the content_to_str function
2185+
mocker.patch("app.endpoints.query.content_to_str", return_value="Topic summary")
21902186

21912187
# Mock the get_topic_summary_system_prompt function
21922188
mocker.patch(
@@ -2230,10 +2226,8 @@ async def test_get_topic_summary_create_turn_parameters(mocker: MockerFixture) -
22302226
# Mock the agent's create_turn method
22312227
mock_agent.create_turn.return_value = mock_response
22322228

2233-
# Mock the interleaved_content_as_str function
2234-
mocker.patch(
2235-
"app.endpoints.query.interleaved_content_as_str", return_value="Topic summary"
2236-
)
2229+
# Mock the content_to_str function
2230+
mocker.patch("app.endpoints.query.content_to_str", return_value="Topic summary")
22372231

22382232
# Mock the get_topic_summary_system_prompt function
22392233
mocker.patch(

tests/unit/app/endpoints/test_streaming_query.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@
1515

1616
from llama_stack_client import APIConnectionError
1717
from llama_stack_client.types import UserMessage # type: ignore
18-
from llama_stack_client.types.agents import Turn
18+
from llama_stack_client.types.alpha.agents.turn import Turn
1919
from llama_stack_client.types.shared.completion_message import CompletionMessage
2020
from llama_stack_client.types.shared.interleaved_content_item import TextContentItem
2121
from llama_stack_client.types.shared.safety_violation import SafetyViolation
22-
from llama_stack_client.types.shield_call_step import ShieldCallStep
22+
from llama_stack_client.types.alpha.shield_call_step import ShieldCallStep
2323
from llama_stack_client.types.shared.tool_call import ToolCall
2424
from llama_stack_client.types.shared.content_delta import TextDelta, ToolCallDelta
25-
from llama_stack_client.types.agents.turn_response_event import TurnResponseEvent
26-
from llama_stack_client.types.agents.agent_turn_response_stream_chunk import (
25+
from llama_stack_client.types.alpha.agents.turn_response_event import TurnResponseEvent
26+
from llama_stack_client.types.alpha.agents.agent_turn_response_stream_chunk import (
2727
AgentTurnResponseStreamChunk,
2828
)
29-
from llama_stack_client.types.agents.turn_response_event_payload import (
29+
from llama_stack_client.types.alpha.agents.turn_response_event_payload import (
3030
AgentTurnResponseStepProgressPayload,
3131
AgentTurnResponseStepCompletePayload,
3232
AgentTurnResponseTurnStartPayload,
3333
AgentTurnResponseTurnAwaitingInputPayload,
3434
AgentTurnResponseTurnCompletePayload,
3535
)
36-
from llama_stack_client.types.tool_execution_step import ToolExecutionStep
37-
from llama_stack_client.types.tool_response import ToolResponse
36+
from llama_stack_client.types.alpha.tool_execution_step import ToolExecutionStep
37+
from llama_stack_client.types.alpha.tool_response import ToolResponse
3838

3939
from configuration import AppConfig
4040
from app.endpoints.query import get_rag_toolgroups

0 commit comments

Comments
 (0)