From 74720327eac30023592a70101b2af61ea4606702 Mon Sep 17 00:00:00 2001 From: Zhonglin Han Date: Fri, 20 Dec 2024 11:04:33 -0800 Subject: [PATCH 1/2] Sync updates from stainless branch: hanzlfs/dev --- src/llama_stack_client/_client.py | 4 +++- .../types/inference_chat_completion_params.py | 10 ++++----- .../types/inference_completion_params.py | 10 ++++----- .../types/shared/agent_config.py | 21 +++++++++++++++++-- .../types/shared_params/agent_config.py | 21 +++++++++++++++++-- tests/api_resources/test_agents.py | 8 +++++++ tests/test_client.py | 2 +- 7 files changed, 60 insertions(+), 16 deletions(-) diff --git a/src/llama_stack_client/_client.py b/src/llama_stack_client/_client.py index f0d61be..708f30c 100644 --- a/src/llama_stack_client/_client.py +++ b/src/llama_stack_client/_client.py @@ -1,7 +1,7 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from __future__ import annotations import json +from __future__ import annotations import os from typing import Any, Union, Mapping @@ -126,6 +126,7 @@ def __init__( if default_headers is None: default_headers = {} default_headers["X-LlamaStack-ProviderData"] = json.dumps(provider_data) + super().__init__( version=__version__, base_url=base_url, @@ -316,6 +317,7 @@ def __init__( if default_headers is None: default_headers = {} default_headers["X-LlamaStack-ProviderData"] = json.dumps(provider_data) + super().__init__( version=__version__, base_url=base_url, diff --git a/src/llama_stack_client/types/inference_chat_completion_params.py b/src/llama_stack_client/types/inference_chat_completion_params.py index e4f263b..fb9b755 100644 --- a/src/llama_stack_client/types/inference_chat_completion_params.py +++ b/src/llama_stack_client/types/inference_chat_completion_params.py @@ -18,8 +18,8 @@ "Message", "Logprobs", "ResponseFormat", - "ResponseFormatJsonSchemaFormat", - "ResponseFormatGrammarFormat", + "ResponseFormatUnionMember0", + "ResponseFormatUnionMember1", "Tool", "InferenceChatCompletionParamsNonStreaming", "InferenceChatCompletionParamsStreaming", @@ -64,19 +64,19 @@ class Logprobs(TypedDict, total=False): top_k: int -class ResponseFormatJsonSchemaFormat(TypedDict, total=False): +class ResponseFormatUnionMember0(TypedDict, total=False): json_schema: Required[Dict[str, Union[bool, float, str, Iterable[object], object, None]]] type: Required[Literal["json_schema"]] -class ResponseFormatGrammarFormat(TypedDict, total=False): +class ResponseFormatUnionMember1(TypedDict, total=False): bnf: Required[Dict[str, Union[bool, float, str, Iterable[object], object, None]]] type: Required[Literal["grammar"]] -ResponseFormat: TypeAlias = Union[ResponseFormatJsonSchemaFormat, ResponseFormatGrammarFormat] +ResponseFormat: TypeAlias = Union[ResponseFormatUnionMember0, ResponseFormatUnionMember1] class Tool(TypedDict, total=False): diff --git a/src/llama_stack_client/types/inference_completion_params.py b/src/llama_stack_client/types/inference_completion_params.py index 85fae63..339687e 100644 --- a/src/llama_stack_client/types/inference_completion_params.py +++ b/src/llama_stack_client/types/inference_completion_params.py @@ -13,8 +13,8 @@ "InferenceCompletionParamsBase", "Logprobs", "ResponseFormat", - "ResponseFormatJsonSchemaFormat", - "ResponseFormatGrammarFormat", + "ResponseFormatUnionMember0", + "ResponseFormatUnionMember1", "InferenceCompletionParamsNonStreaming", "InferenceCompletionParamsStreaming", ] @@ -38,19 +38,19 @@ class Logprobs(TypedDict, total=False): top_k: int -class ResponseFormatJsonSchemaFormat(TypedDict, total=False): +class ResponseFormatUnionMember0(TypedDict, total=False): json_schema: Required[Dict[str, Union[bool, float, str, Iterable[object], object, None]]] type: Required[Literal["json_schema"]] -class ResponseFormatGrammarFormat(TypedDict, total=False): +class ResponseFormatUnionMember1(TypedDict, total=False): bnf: Required[Dict[str, Union[bool, float, str, Iterable[object], object, None]]] type: Required[Literal["grammar"]] -ResponseFormat: TypeAlias = Union[ResponseFormatJsonSchemaFormat, ResponseFormatGrammarFormat] +ResponseFormat: TypeAlias = Union[ResponseFormatUnionMember0, ResponseFormatUnionMember1] class InferenceCompletionParamsNonStreaming(InferenceCompletionParamsBase, total=False): diff --git a/src/llama_stack_client/types/shared/agent_config.py b/src/llama_stack_client/types/shared/agent_config.py index 4236242..00d4096 100644 --- a/src/llama_stack_client/types/shared/agent_config.py +++ b/src/llama_stack_client/types/shared/agent_config.py @@ -1,6 +1,6 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Union, Optional +from typing import Dict, List, Union, Optional from typing_extensions import Literal, TypeAlias from ..._models import BaseModel @@ -12,7 +12,22 @@ from .wolfram_alpha_tool_definition import WolframAlphaToolDefinition from .code_interpreter_tool_definition import CodeInterpreterToolDefinition -__all__ = ["AgentConfig", "Tool"] +__all__ = ["AgentConfig", "ResponseFormat", "ResponseFormatUnionMember0", "ResponseFormatUnionMember1", "Tool"] + + +class ResponseFormatUnionMember0(BaseModel): + json_schema: Dict[str, Union[bool, float, str, List[object], object, None]] + + type: Literal["json_schema"] + + +class ResponseFormatUnionMember1(BaseModel): + bnf: Dict[str, Union[bool, float, str, List[object], object, None]] + + type: Literal["grammar"] + + +ResponseFormat: TypeAlias = Union[ResponseFormatUnionMember0, ResponseFormatUnionMember1] Tool: TypeAlias = Union[ SearchToolDefinition, @@ -37,6 +52,8 @@ class AgentConfig(BaseModel): output_shields: Optional[List[str]] = None + response_format: Optional[ResponseFormat] = None + sampling_params: Optional[SamplingParams] = None tool_choice: Optional[Literal["auto", "required"]] = None diff --git a/src/llama_stack_client/types/shared_params/agent_config.py b/src/llama_stack_client/types/shared_params/agent_config.py index f89de86..85b9004 100644 --- a/src/llama_stack_client/types/shared_params/agent_config.py +++ b/src/llama_stack_client/types/shared_params/agent_config.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import List, Union, Iterable +from typing import Dict, List, Union, Iterable from typing_extensions import Literal, Required, TypeAlias, TypedDict from .sampling_params import SamplingParams @@ -13,7 +13,22 @@ from .wolfram_alpha_tool_definition import WolframAlphaToolDefinition from .code_interpreter_tool_definition import CodeInterpreterToolDefinition -__all__ = ["AgentConfig", "Tool"] +__all__ = ["AgentConfig", "ResponseFormat", "ResponseFormatUnionMember0", "ResponseFormatUnionMember1", "Tool"] + + +class ResponseFormatUnionMember0(TypedDict, total=False): + json_schema: Required[Dict[str, Union[bool, float, str, Iterable[object], object, None]]] + + type: Required[Literal["json_schema"]] + + +class ResponseFormatUnionMember1(TypedDict, total=False): + bnf: Required[Dict[str, Union[bool, float, str, Iterable[object], object, None]]] + + type: Required[Literal["grammar"]] + + +ResponseFormat: TypeAlias = Union[ResponseFormatUnionMember0, ResponseFormatUnionMember1] Tool: TypeAlias = Union[ SearchToolDefinition, @@ -38,6 +53,8 @@ class AgentConfig(TypedDict, total=False): output_shields: List[str] + response_format: ResponseFormat + sampling_params: SamplingParams tool_choice: Literal["auto", "required"] diff --git a/tests/api_resources/test_agents.py b/tests/api_resources/test_agents.py index 92db1ff..9e50fa9 100644 --- a/tests/api_resources/test_agents.py +++ b/tests/api_resources/test_agents.py @@ -39,6 +39,10 @@ def test_method_create_with_all_params(self, client: LlamaStackClient) -> None: "model": "model", "input_shields": ["string"], "output_shields": ["string"], + "response_format": { + "json_schema": {"foo": True}, + "type": "json_schema", + }, "sampling_params": { "strategy": "greedy", "max_tokens": 0, @@ -169,6 +173,10 @@ async def test_method_create_with_all_params(self, async_client: AsyncLlamaStack "model": "model", "input_shields": ["string"], "output_shields": ["string"], + "response_format": { + "json_schema": {"foo": True}, + "type": "json_schema", + }, "sampling_params": { "strategy": "greedy", "max_tokens": 0, diff --git a/tests/test_client.py b/tests/test_client.py index 921151e..a52a26e 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1631,7 +1631,7 @@ def test_get_platform(self) -> None: import threading from llama_stack_client._utils import asyncify - from llama_stack_client._base_client import get_platform + from llama_stack_client._base_client import get_platform async def test_main() -> None: result = await asyncify(get_platform)() From 4744e32bf87a6597e7504b0f7b1e28fe322142ee Mon Sep 17 00:00:00 2001 From: Zhonglin Han Date: Fri, 20 Dec 2024 11:29:36 -0800 Subject: [PATCH 2/2] Update _client.py --- src/llama_stack_client/_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llama_stack_client/_client.py b/src/llama_stack_client/_client.py index 708f30c..dda78e4 100644 --- a/src/llama_stack_client/_client.py +++ b/src/llama_stack_client/_client.py @@ -1,7 +1,7 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import json from __future__ import annotations +import json import os from typing import Any, Union, Mapping