mirascope 2.0.0a1__py3-none-any.whl → 2.0.0a3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mirascope/__init__.py +2 -2
- mirascope/api/__init__.py +6 -0
- mirascope/api/_generated/README.md +207 -0
- mirascope/api/_generated/__init__.py +85 -0
- mirascope/api/_generated/client.py +155 -0
- mirascope/api/_generated/core/__init__.py +52 -0
- mirascope/api/_generated/core/api_error.py +23 -0
- mirascope/api/_generated/core/client_wrapper.py +58 -0
- mirascope/api/_generated/core/datetime_utils.py +30 -0
- mirascope/api/_generated/core/file.py +70 -0
- mirascope/api/_generated/core/force_multipart.py +16 -0
- mirascope/api/_generated/core/http_client.py +619 -0
- mirascope/api/_generated/core/http_response.py +55 -0
- mirascope/api/_generated/core/jsonable_encoder.py +102 -0
- mirascope/api/_generated/core/pydantic_utilities.py +310 -0
- mirascope/api/_generated/core/query_encoder.py +60 -0
- mirascope/api/_generated/core/remove_none_from_dict.py +11 -0
- mirascope/api/_generated/core/request_options.py +35 -0
- mirascope/api/_generated/core/serialization.py +282 -0
- mirascope/api/_generated/docs/__init__.py +4 -0
- mirascope/api/_generated/docs/client.py +95 -0
- mirascope/api/_generated/docs/raw_client.py +132 -0
- mirascope/api/_generated/environment.py +9 -0
- mirascope/api/_generated/errors/__init__.py +7 -0
- mirascope/api/_generated/errors/bad_request_error.py +15 -0
- mirascope/api/_generated/health/__init__.py +7 -0
- mirascope/api/_generated/health/client.py +96 -0
- mirascope/api/_generated/health/raw_client.py +129 -0
- mirascope/api/_generated/health/types/__init__.py +8 -0
- mirascope/api/_generated/health/types/health_check_response.py +24 -0
- mirascope/api/_generated/health/types/health_check_response_status.py +5 -0
- mirascope/api/_generated/reference.md +167 -0
- mirascope/api/_generated/traces/__init__.py +55 -0
- mirascope/api/_generated/traces/client.py +162 -0
- mirascope/api/_generated/traces/raw_client.py +168 -0
- mirascope/api/_generated/traces/types/__init__.py +95 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item.py +36 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource.py +31 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item.py +25 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value.py +54 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_array_value.py +23 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value.py +28 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value_values_item.py +24 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item.py +35 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope.py +35 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item.py +27 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value.py +54 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_array_value.py +23 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value.py +28 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value_values_item.py +24 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item.py +60 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item.py +29 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value.py +54 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_array_value.py +23 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value.py +28 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value_values_item.py +24 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_status.py +24 -0
- mirascope/api/_generated/traces/types/traces_create_response.py +27 -0
- mirascope/api/_generated/traces/types/traces_create_response_partial_success.py +28 -0
- mirascope/api/_generated/types/__init__.py +21 -0
- mirascope/api/_generated/types/http_api_decode_error.py +31 -0
- mirascope/api/_generated/types/http_api_decode_error_tag.py +5 -0
- mirascope/api/_generated/types/issue.py +44 -0
- mirascope/api/_generated/types/issue_tag.py +17 -0
- mirascope/api/_generated/types/property_key.py +7 -0
- mirascope/api/_generated/types/property_key_tag.py +29 -0
- mirascope/api/_generated/types/property_key_tag_tag.py +5 -0
- mirascope/api/client.py +255 -0
- mirascope/api/settings.py +81 -0
- mirascope/llm/__init__.py +41 -11
- mirascope/llm/calls/calls.py +81 -57
- mirascope/llm/calls/decorator.py +121 -115
- mirascope/llm/content/__init__.py +3 -2
- mirascope/llm/context/_utils.py +19 -6
- mirascope/llm/exceptions.py +30 -16
- mirascope/llm/formatting/_utils.py +9 -5
- mirascope/llm/formatting/format.py +2 -2
- mirascope/llm/formatting/from_call_args.py +2 -2
- mirascope/llm/messages/message.py +13 -5
- mirascope/llm/models/__init__.py +2 -2
- mirascope/llm/models/models.py +189 -81
- mirascope/llm/prompts/__init__.py +13 -12
- mirascope/llm/prompts/_utils.py +27 -24
- mirascope/llm/prompts/decorator.py +133 -204
- mirascope/llm/prompts/prompts.py +424 -0
- mirascope/llm/prompts/protocols.py +25 -59
- mirascope/llm/providers/__init__.py +38 -0
- mirascope/llm/{clients → providers}/_missing_import_stubs.py +8 -6
- mirascope/llm/providers/anthropic/__init__.py +24 -0
- mirascope/llm/{clients → providers}/anthropic/_utils/decode.py +5 -4
- mirascope/llm/{clients → providers}/anthropic/_utils/encode.py +31 -10
- mirascope/llm/providers/anthropic/model_id.py +40 -0
- mirascope/llm/{clients/anthropic/clients.py → providers/anthropic/provider.py} +33 -418
- mirascope/llm/{clients → providers}/base/__init__.py +3 -3
- mirascope/llm/{clients → providers}/base/_utils.py +10 -7
- mirascope/llm/{clients/base/client.py → providers/base/base_provider.py} +255 -126
- mirascope/llm/providers/google/__init__.py +21 -0
- mirascope/llm/{clients → providers}/google/_utils/decode.py +6 -4
- mirascope/llm/{clients → providers}/google/_utils/encode.py +30 -24
- mirascope/llm/providers/google/model_id.py +28 -0
- mirascope/llm/providers/google/provider.py +438 -0
- mirascope/llm/providers/load_provider.py +48 -0
- mirascope/llm/providers/mlx/__init__.py +24 -0
- mirascope/llm/providers/mlx/_utils.py +107 -0
- mirascope/llm/providers/mlx/encoding/__init__.py +8 -0
- mirascope/llm/providers/mlx/encoding/base.py +69 -0
- mirascope/llm/providers/mlx/encoding/transformers.py +131 -0
- mirascope/llm/providers/mlx/mlx.py +237 -0
- mirascope/llm/providers/mlx/model_id.py +17 -0
- mirascope/llm/providers/mlx/provider.py +411 -0
- mirascope/llm/providers/model_id.py +16 -0
- mirascope/llm/providers/openai/__init__.py +6 -0
- mirascope/llm/providers/openai/completions/__init__.py +20 -0
- mirascope/llm/{clients/openai/responses → providers/openai/completions}/_utils/__init__.py +2 -0
- mirascope/llm/{clients → providers}/openai/completions/_utils/decode.py +5 -3
- mirascope/llm/{clients → providers}/openai/completions/_utils/encode.py +33 -23
- mirascope/llm/providers/openai/completions/provider.py +456 -0
- mirascope/llm/providers/openai/model_id.py +31 -0
- mirascope/llm/providers/openai/model_info.py +246 -0
- mirascope/llm/providers/openai/provider.py +386 -0
- mirascope/llm/providers/openai/responses/__init__.py +21 -0
- mirascope/llm/{clients → providers}/openai/responses/_utils/decode.py +5 -3
- mirascope/llm/{clients → providers}/openai/responses/_utils/encode.py +28 -17
- mirascope/llm/providers/openai/responses/provider.py +470 -0
- mirascope/llm/{clients → providers}/openai/shared/_utils.py +7 -3
- mirascope/llm/providers/provider_id.py +13 -0
- mirascope/llm/providers/provider_registry.py +167 -0
- mirascope/llm/responses/base_response.py +10 -5
- mirascope/llm/responses/base_stream_response.py +10 -5
- mirascope/llm/responses/response.py +24 -13
- mirascope/llm/responses/root_response.py +7 -12
- mirascope/llm/responses/stream_response.py +35 -23
- mirascope/llm/tools/__init__.py +9 -2
- mirascope/llm/tools/_utils.py +12 -3
- mirascope/llm/tools/decorator.py +10 -10
- mirascope/llm/tools/protocols.py +4 -4
- mirascope/llm/tools/tool_schema.py +44 -9
- mirascope/llm/tools/tools.py +12 -11
- mirascope/ops/__init__.py +156 -0
- mirascope/ops/_internal/__init__.py +5 -0
- mirascope/ops/_internal/closure.py +1118 -0
- mirascope/ops/_internal/configuration.py +126 -0
- mirascope/ops/_internal/context.py +76 -0
- mirascope/ops/_internal/exporters/__init__.py +26 -0
- mirascope/ops/_internal/exporters/exporters.py +342 -0
- mirascope/ops/_internal/exporters/processors.py +104 -0
- mirascope/ops/_internal/exporters/types.py +165 -0
- mirascope/ops/_internal/exporters/utils.py +29 -0
- mirascope/ops/_internal/instrumentation/__init__.py +8 -0
- mirascope/ops/_internal/instrumentation/llm/__init__.py +8 -0
- mirascope/ops/_internal/instrumentation/llm/encode.py +238 -0
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/__init__.py +38 -0
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_input_messages.py +31 -0
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_output_messages.py +38 -0
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_system_instructions.py +18 -0
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/shared.py +100 -0
- mirascope/ops/_internal/instrumentation/llm/llm.py +1288 -0
- mirascope/ops/_internal/propagation.py +198 -0
- mirascope/ops/_internal/protocols.py +51 -0
- mirascope/ops/_internal/session.py +139 -0
- mirascope/ops/_internal/spans.py +232 -0
- mirascope/ops/_internal/traced_calls.py +371 -0
- mirascope/ops/_internal/traced_functions.py +394 -0
- mirascope/ops/_internal/tracing.py +276 -0
- mirascope/ops/_internal/types.py +13 -0
- mirascope/ops/_internal/utils.py +75 -0
- mirascope/ops/_internal/versioned_calls.py +512 -0
- mirascope/ops/_internal/versioned_functions.py +346 -0
- mirascope/ops/_internal/versioning.py +303 -0
- mirascope/ops/exceptions.py +21 -0
- {mirascope-2.0.0a1.dist-info → mirascope-2.0.0a3.dist-info}/METADATA +77 -1
- mirascope-2.0.0a3.dist-info/RECORD +206 -0
- {mirascope-2.0.0a1.dist-info → mirascope-2.0.0a3.dist-info}/WHEEL +1 -1
- mirascope/graphs/__init__.py +0 -22
- mirascope/graphs/finite_state_machine.py +0 -625
- mirascope/llm/agents/__init__.py +0 -15
- mirascope/llm/agents/agent.py +0 -97
- mirascope/llm/agents/agent_template.py +0 -45
- mirascope/llm/agents/decorator.py +0 -176
- mirascope/llm/calls/base_call.py +0 -33
- mirascope/llm/clients/__init__.py +0 -34
- mirascope/llm/clients/anthropic/__init__.py +0 -25
- mirascope/llm/clients/anthropic/model_ids.py +0 -8
- mirascope/llm/clients/google/__init__.py +0 -20
- mirascope/llm/clients/google/clients.py +0 -853
- mirascope/llm/clients/google/model_ids.py +0 -15
- mirascope/llm/clients/openai/__init__.py +0 -25
- mirascope/llm/clients/openai/completions/__init__.py +0 -28
- mirascope/llm/clients/openai/completions/_utils/model_features.py +0 -81
- mirascope/llm/clients/openai/completions/clients.py +0 -833
- mirascope/llm/clients/openai/completions/model_ids.py +0 -8
- mirascope/llm/clients/openai/responses/__init__.py +0 -26
- mirascope/llm/clients/openai/responses/_utils/model_features.py +0 -87
- mirascope/llm/clients/openai/responses/clients.py +0 -832
- mirascope/llm/clients/openai/responses/model_ids.py +0 -8
- mirascope/llm/clients/providers.py +0 -175
- mirascope-2.0.0a1.dist-info/RECORD +0 -102
- /mirascope/llm/{clients → providers}/anthropic/_utils/__init__.py +0 -0
- /mirascope/llm/{clients → providers}/base/kwargs.py +0 -0
- /mirascope/llm/{clients → providers}/base/params.py +0 -0
- /mirascope/llm/{clients → providers}/google/_utils/__init__.py +0 -0
- /mirascope/llm/{clients → providers}/google/message.py +0 -0
- /mirascope/llm/{clients/openai/completions → providers/openai/responses}/_utils/__init__.py +0 -0
- /mirascope/llm/{clients → providers}/openai/shared/__init__.py +0 -0
- {mirascope-2.0.0a1.dist-info → mirascope-2.0.0a3.dist-info}/licenses/LICENSE +0 -0
mirascope/llm/agents/agent.py
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"""The `Agent` class for LLM agents."""
|
|
2
|
-
|
|
3
|
-
from abc import ABC
|
|
4
|
-
from collections.abc import Sequence
|
|
5
|
-
from dataclasses import dataclass
|
|
6
|
-
from typing import Generic
|
|
7
|
-
|
|
8
|
-
from ..context import Context, DepsT
|
|
9
|
-
from ..formatting import FormattableT
|
|
10
|
-
from ..messages import UserContent
|
|
11
|
-
from ..models import Model
|
|
12
|
-
from ..responses import AsyncResponse, AsyncStreamResponse, Response, StreamResponse
|
|
13
|
-
from ..tools import AsyncContextTool, AsyncTool, ContextTool, Tool
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@dataclass
|
|
17
|
-
class BaseAgent(Generic[DepsT, FormattableT], ABC):
|
|
18
|
-
"""Agent class for generating responses using LLMs with tools."""
|
|
19
|
-
|
|
20
|
-
ctx: Context[DepsT]
|
|
21
|
-
"""The context for the agent, such as the history of messages."""
|
|
22
|
-
|
|
23
|
-
format: type[FormattableT] | None
|
|
24
|
-
"""The response format for the generated response."""
|
|
25
|
-
|
|
26
|
-
model: Model
|
|
27
|
-
"""The default model the agent will use if not specified through context."""
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@dataclass
|
|
31
|
-
class Agent(BaseAgent[DepsT, FormattableT]):
|
|
32
|
-
"""Agent class for generating responses using LLMs with tools."""
|
|
33
|
-
|
|
34
|
-
tools: Sequence[Tool | ContextTool[DepsT]] | None
|
|
35
|
-
"""The tools available to the agent, if any."""
|
|
36
|
-
|
|
37
|
-
def __call__(
|
|
38
|
-
self,
|
|
39
|
-
content: UserContent,
|
|
40
|
-
*,
|
|
41
|
-
ctx: Context[DepsT] | None = None,
|
|
42
|
-
) -> Response[FormattableT]:
|
|
43
|
-
"""Generates a response by running the agent loop."""
|
|
44
|
-
raise NotImplementedError()
|
|
45
|
-
|
|
46
|
-
def call(
|
|
47
|
-
self,
|
|
48
|
-
content: UserContent,
|
|
49
|
-
*,
|
|
50
|
-
ctx: Context[DepsT] | None = None,
|
|
51
|
-
) -> Response[FormattableT]:
|
|
52
|
-
"""Generates a response by running the agent loop."""
|
|
53
|
-
raise NotImplementedError()
|
|
54
|
-
|
|
55
|
-
def stream(
|
|
56
|
-
self,
|
|
57
|
-
content: UserContent,
|
|
58
|
-
*,
|
|
59
|
-
ctx: Context[DepsT] | None = None,
|
|
60
|
-
) -> StreamResponse[FormattableT]:
|
|
61
|
-
"""Streams the response generated by running the agent loop."""
|
|
62
|
-
raise NotImplementedError()
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
@dataclass
|
|
66
|
-
class AsyncAgent(BaseAgent[DepsT, FormattableT]):
|
|
67
|
-
"""Asynchronous agent class for generating responses using LLMs with tools."""
|
|
68
|
-
|
|
69
|
-
tools: Sequence[AsyncTool | AsyncContextTool[DepsT]] | None
|
|
70
|
-
"""The tools available to the agent, if any."""
|
|
71
|
-
|
|
72
|
-
async def __call__(
|
|
73
|
-
self,
|
|
74
|
-
content: UserContent,
|
|
75
|
-
*,
|
|
76
|
-
ctx: Context[DepsT] | None = None,
|
|
77
|
-
) -> AsyncResponse[FormattableT]:
|
|
78
|
-
"""Generates a response by running the agent loop asynchronously."""
|
|
79
|
-
raise NotImplementedError()
|
|
80
|
-
|
|
81
|
-
async def call(
|
|
82
|
-
self,
|
|
83
|
-
content: UserContent,
|
|
84
|
-
*,
|
|
85
|
-
ctx: Context[DepsT] | None = None,
|
|
86
|
-
) -> AsyncResponse[FormattableT]:
|
|
87
|
-
"""Generates a response by running the agent loop asynchronously."""
|
|
88
|
-
raise NotImplementedError()
|
|
89
|
-
|
|
90
|
-
async def stream(
|
|
91
|
-
self,
|
|
92
|
-
content: UserContent,
|
|
93
|
-
*,
|
|
94
|
-
ctx: Context[DepsT] | None = None,
|
|
95
|
-
) -> AsyncStreamResponse[FormattableT]:
|
|
96
|
-
"""Streams the response generated by running the agent loop asynchronously."""
|
|
97
|
-
raise NotImplementedError()
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
from typing import Generic, overload
|
|
2
|
-
|
|
3
|
-
from ..context import DepsT
|
|
4
|
-
from ..formatting import FormattableT
|
|
5
|
-
from .agent import Agent, AsyncAgent
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class AgentTemplate(Generic[DepsT, FormattableT]):
|
|
9
|
-
@overload
|
|
10
|
-
def __call__(
|
|
11
|
-
self: "AgentTemplate[None, FormattableT]",
|
|
12
|
-
) -> Agent[None, FormattableT]:
|
|
13
|
-
"""Create an Agent with no deps"""
|
|
14
|
-
|
|
15
|
-
@overload
|
|
16
|
-
def __call__(
|
|
17
|
-
self: "AgentTemplate[DepsT, FormattableT]", deps: DepsT
|
|
18
|
-
) -> Agent[DepsT, FormattableT]:
|
|
19
|
-
"""Create an Agent with deps"""
|
|
20
|
-
|
|
21
|
-
def __call__(
|
|
22
|
-
self: "AgentTemplate[None, FormattableT] | AgentTemplate[DepsT, FormattableT]",
|
|
23
|
-
deps: DepsT | None = None,
|
|
24
|
-
) -> Agent[None, FormattableT] | Agent[DepsT, FormattableT]:
|
|
25
|
-
raise NotImplementedError()
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class AsyncAgentTemplate(Generic[DepsT, FormattableT]):
|
|
29
|
-
@overload
|
|
30
|
-
async def __call__(
|
|
31
|
-
self: "AsyncAgentTemplate[None, FormattableT]",
|
|
32
|
-
) -> AsyncAgent[None, FormattableT]:
|
|
33
|
-
"""Create an AsyncAgent with no deps"""
|
|
34
|
-
|
|
35
|
-
@overload
|
|
36
|
-
async def __call__(
|
|
37
|
-
self: "AsyncAgentTemplate[DepsT, FormattableT]", deps: DepsT
|
|
38
|
-
) -> AsyncAgent[DepsT, FormattableT]:
|
|
39
|
-
"""Create an AsyncAgent with deps"""
|
|
40
|
-
|
|
41
|
-
async def __call__(
|
|
42
|
-
self: "AsyncAgentTemplate[None, FormattableT] | AsyncAgentTemplate[DepsT, FormattableT]",
|
|
43
|
-
deps: DepsT | None = None,
|
|
44
|
-
) -> AsyncAgent[None, FormattableT] | AsyncAgent[DepsT, FormattableT]:
|
|
45
|
-
raise NotImplementedError()
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
"""The `llm.agent` decorator for turning a function into an agent."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from typing import TYPE_CHECKING, Any, Literal, Protocol, overload
|
|
6
|
-
from typing_extensions import TypeVar, Unpack
|
|
7
|
-
|
|
8
|
-
from ..tools import AsyncContextTool, AsyncTool, ContextTool, Tool
|
|
9
|
-
from .agent_template import AgentTemplate, AsyncAgentTemplate
|
|
10
|
-
|
|
11
|
-
if TYPE_CHECKING:
|
|
12
|
-
from ..clients import (
|
|
13
|
-
AnthropicClient,
|
|
14
|
-
AnthropicModelId,
|
|
15
|
-
BaseClient,
|
|
16
|
-
GoogleClient,
|
|
17
|
-
GoogleModelId,
|
|
18
|
-
ModelId,
|
|
19
|
-
OpenAICompletionsClient,
|
|
20
|
-
OpenAICompletionsModelId,
|
|
21
|
-
Params,
|
|
22
|
-
Provider,
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
from ..context import Context, DepsT
|
|
26
|
-
from ..formatting import FormattableT
|
|
27
|
-
from ..types import P
|
|
28
|
-
|
|
29
|
-
AgentToolT = TypeVar(
|
|
30
|
-
"AgentToolT",
|
|
31
|
-
bound="Tool | AsyncTool | ContextTool[Any] | AsyncContextTool[Any] | None",
|
|
32
|
-
covariant=True,
|
|
33
|
-
default=None,
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class SystemPrompt(Protocol[P]):
|
|
38
|
-
"""Protocol for a prompt template function that returns a system prompt as a string (no context)."""
|
|
39
|
-
|
|
40
|
-
def __call__(self) -> str: ...
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
class ContextSystemPrompt(Protocol[P, DepsT]):
|
|
44
|
-
"""Protocol for a prompt template function that returns a system prompt as a string (with context)."""
|
|
45
|
-
|
|
46
|
-
def __call__(self, ctx: Context[DepsT]) -> str: ...
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
class AsyncSystemPrompt(Protocol[P]):
|
|
50
|
-
"""Protocol for an async prompt template function that returns a system prompt as a string (no context)."""
|
|
51
|
-
|
|
52
|
-
async def __call__(self) -> str: ...
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
class AsyncContextSystemPrompt(Protocol[P, DepsT]):
|
|
56
|
-
"""Protocol for an async prompt template function that returns a system prompt as a string (with context)."""
|
|
57
|
-
|
|
58
|
-
async def __call__(self, ctx: Context[DepsT]) -> str: ...
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
class AgentDecorator(Protocol[P, AgentToolT, FormattableT]):
|
|
62
|
-
"""Protocol for the `agent` decorator."""
|
|
63
|
-
|
|
64
|
-
@overload
|
|
65
|
-
def __call__(
|
|
66
|
-
self: AgentDecorator[
|
|
67
|
-
P,
|
|
68
|
-
None | Tool | ContextTool[DepsT],
|
|
69
|
-
FormattableT,
|
|
70
|
-
],
|
|
71
|
-
fn: SystemPrompt[P] | ContextSystemPrompt[P, DepsT],
|
|
72
|
-
) -> AgentTemplate[DepsT, FormattableT]:
|
|
73
|
-
"""Decorator for creating a sync agent."""
|
|
74
|
-
...
|
|
75
|
-
|
|
76
|
-
@overload
|
|
77
|
-
def __call__(
|
|
78
|
-
self: AgentDecorator[
|
|
79
|
-
P,
|
|
80
|
-
None | AsyncTool | AsyncContextTool[DepsT],
|
|
81
|
-
FormattableT,
|
|
82
|
-
],
|
|
83
|
-
fn: AsyncSystemPrompt[P] | AsyncContextSystemPrompt[P, DepsT],
|
|
84
|
-
) -> AsyncAgentTemplate[DepsT, FormattableT]:
|
|
85
|
-
"""Decorator for creating an async agent."""
|
|
86
|
-
...
|
|
87
|
-
|
|
88
|
-
def __call__(
|
|
89
|
-
self,
|
|
90
|
-
fn: SystemPrompt[P]
|
|
91
|
-
| ContextSystemPrompt[P, DepsT]
|
|
92
|
-
| AsyncSystemPrompt[P]
|
|
93
|
-
| AsyncContextSystemPrompt[P, DepsT],
|
|
94
|
-
) -> AgentTemplate[DepsT, FormattableT] | AsyncAgentTemplate[DepsT, FormattableT]:
|
|
95
|
-
"""Decorator for creating an agent."""
|
|
96
|
-
raise NotImplementedError()
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
@overload
|
|
100
|
-
def agent(
|
|
101
|
-
*,
|
|
102
|
-
provider: Literal["anthropic"],
|
|
103
|
-
model_id: AnthropicModelId,
|
|
104
|
-
tools: list[AgentToolT] | None = None,
|
|
105
|
-
format: type[FormattableT] | None = None,
|
|
106
|
-
client: AnthropicClient | None = None,
|
|
107
|
-
**params: Unpack[Params],
|
|
108
|
-
) -> AgentDecorator[..., AgentToolT, FormattableT]:
|
|
109
|
-
"""Decorator for creating an Anthropic agent."""
|
|
110
|
-
...
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
@overload
|
|
114
|
-
def agent(
|
|
115
|
-
*,
|
|
116
|
-
provider: Literal["google"],
|
|
117
|
-
model_id: GoogleModelId,
|
|
118
|
-
tools: list[AgentToolT] | None = None,
|
|
119
|
-
format: type[FormattableT] | None = None,
|
|
120
|
-
client: GoogleClient | None = None,
|
|
121
|
-
**params: Unpack[Params],
|
|
122
|
-
) -> AgentDecorator[..., AgentToolT, FormattableT]:
|
|
123
|
-
"""Decorator for creating a Google agent."""
|
|
124
|
-
...
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
@overload
|
|
128
|
-
def agent(
|
|
129
|
-
*,
|
|
130
|
-
provider: Literal["openai:completions"],
|
|
131
|
-
model_id: OpenAICompletionsModelId,
|
|
132
|
-
tools: list[AgentToolT] | None = None,
|
|
133
|
-
format: type[FormattableT] | None = None,
|
|
134
|
-
client: OpenAICompletionsClient | None = None,
|
|
135
|
-
**params: Unpack[Params],
|
|
136
|
-
) -> AgentDecorator[..., AgentToolT, FormattableT]:
|
|
137
|
-
"""Decorator for creating an OpenAI agent."""
|
|
138
|
-
...
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
@overload
|
|
142
|
-
def agent(
|
|
143
|
-
*,
|
|
144
|
-
provider: Provider,
|
|
145
|
-
model_id: ModelId,
|
|
146
|
-
tools: list[AgentToolT] | None = None,
|
|
147
|
-
format: type[FormattableT] | None = None,
|
|
148
|
-
client: None = None,
|
|
149
|
-
**params: Unpack[Params],
|
|
150
|
-
) -> AgentDecorator[..., AgentToolT, FormattableT]:
|
|
151
|
-
"""Decorator for creating an agent using any registered model."""
|
|
152
|
-
...
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
def agent(
|
|
156
|
-
*,
|
|
157
|
-
provider: Provider,
|
|
158
|
-
model_id: ModelId,
|
|
159
|
-
tools: list[AgentToolT] | None = None,
|
|
160
|
-
format: type[FormattableT] | None = None,
|
|
161
|
-
client: BaseClient | None = None,
|
|
162
|
-
**params: Unpack[Params],
|
|
163
|
-
) -> AgentDecorator[..., AgentToolT, FormattableT]:
|
|
164
|
-
"""Decorator for creating an agent or structured agent.
|
|
165
|
-
|
|
166
|
-
Args:
|
|
167
|
-
model_id: The model to use for the agent.
|
|
168
|
-
tools: The tools available to the agent.
|
|
169
|
-
format: The response format type for the agent.
|
|
170
|
-
client: The client to use for the agent.
|
|
171
|
-
**params: Additional parameters for the model.
|
|
172
|
-
|
|
173
|
-
Returns:
|
|
174
|
-
An of `AgentDecorator`.
|
|
175
|
-
"""
|
|
176
|
-
raise NotImplementedError()
|
mirascope/llm/calls/base_call.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"""The `BaseCall` class for LLM calls."""
|
|
2
|
-
|
|
3
|
-
from abc import ABC
|
|
4
|
-
from dataclasses import dataclass
|
|
5
|
-
from typing import Generic
|
|
6
|
-
|
|
7
|
-
from ..formatting import Format, FormattableT
|
|
8
|
-
from ..models import Model, get_model_from_context
|
|
9
|
-
from ..prompts import PromptT
|
|
10
|
-
from ..tools import ToolkitT
|
|
11
|
-
from ..types import P
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@dataclass
|
|
15
|
-
class BaseCall(Generic[P, PromptT, ToolkitT, FormattableT], ABC):
|
|
16
|
-
"""A base class for generating responses using LLMs."""
|
|
17
|
-
|
|
18
|
-
default_model: Model
|
|
19
|
-
"""The default model that will be used if no model is set in context."""
|
|
20
|
-
|
|
21
|
-
toolkit: ToolkitT
|
|
22
|
-
"""The toolkit containing this call's tools."""
|
|
23
|
-
|
|
24
|
-
format: type[FormattableT] | Format[FormattableT] | None
|
|
25
|
-
"""The response format for the generated response."""
|
|
26
|
-
|
|
27
|
-
fn: PromptT
|
|
28
|
-
"""The Prompt function that generates the Prompt."""
|
|
29
|
-
|
|
30
|
-
@property
|
|
31
|
-
def model(self) -> Model:
|
|
32
|
-
"""The model used for generating responses. May be overwritten via `with llm.model(...)."""
|
|
33
|
-
return get_model_from_context() or self.default_model
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"""Client interfaces for LLM providers."""
|
|
2
|
-
|
|
3
|
-
from .anthropic import (
|
|
4
|
-
AnthropicClient,
|
|
5
|
-
AnthropicModelId,
|
|
6
|
-
)
|
|
7
|
-
from .base import BaseClient, ClientT, Params
|
|
8
|
-
from .google import GoogleClient, GoogleModelId
|
|
9
|
-
from .openai import (
|
|
10
|
-
OpenAICompletionsClient,
|
|
11
|
-
OpenAICompletionsModelId,
|
|
12
|
-
OpenAIResponsesClient,
|
|
13
|
-
OpenAIResponsesModelId,
|
|
14
|
-
)
|
|
15
|
-
from .providers import PROVIDERS, ModelId, Provider, client, get_client
|
|
16
|
-
|
|
17
|
-
__all__ = [
|
|
18
|
-
"PROVIDERS",
|
|
19
|
-
"AnthropicClient",
|
|
20
|
-
"AnthropicModelId",
|
|
21
|
-
"BaseClient",
|
|
22
|
-
"ClientT",
|
|
23
|
-
"GoogleClient",
|
|
24
|
-
"GoogleModelId",
|
|
25
|
-
"ModelId",
|
|
26
|
-
"OpenAICompletionsClient",
|
|
27
|
-
"OpenAICompletionsModelId",
|
|
28
|
-
"OpenAIResponsesClient",
|
|
29
|
-
"OpenAIResponsesModelId",
|
|
30
|
-
"Params",
|
|
31
|
-
"Provider",
|
|
32
|
-
"client",
|
|
33
|
-
"get_client",
|
|
34
|
-
]
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"""Anthropic client implementation."""
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING, Any
|
|
4
|
-
|
|
5
|
-
if TYPE_CHECKING:
|
|
6
|
-
from .clients import AnthropicClient, client, get_client
|
|
7
|
-
from .model_ids import AnthropicModelId
|
|
8
|
-
else:
|
|
9
|
-
try:
|
|
10
|
-
from .clients import AnthropicClient, client, get_client
|
|
11
|
-
from .model_ids import AnthropicModelId
|
|
12
|
-
except ImportError: # pragma: no cover
|
|
13
|
-
from .._missing_import_stubs import create_client_stub, create_import_error_stub
|
|
14
|
-
|
|
15
|
-
AnthropicClient = create_client_stub("anthropic", "AnthropicClient")
|
|
16
|
-
AnthropicModelId = str
|
|
17
|
-
client = create_import_error_stub("anthropic", "AnthropicClient")
|
|
18
|
-
get_client = create_import_error_stub("anthropic", "AnthropicClient")
|
|
19
|
-
|
|
20
|
-
__all__ = [
|
|
21
|
-
"AnthropicClient",
|
|
22
|
-
"AnthropicModelId",
|
|
23
|
-
"client",
|
|
24
|
-
"get_client",
|
|
25
|
-
]
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"""Google client implementation."""
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
4
|
-
|
|
5
|
-
if TYPE_CHECKING:
|
|
6
|
-
from .clients import GoogleClient, client, get_client
|
|
7
|
-
from .model_ids import GoogleModelId
|
|
8
|
-
else:
|
|
9
|
-
try:
|
|
10
|
-
from .clients import GoogleClient, client, get_client
|
|
11
|
-
from .model_ids import GoogleModelId
|
|
12
|
-
except ImportError: # pragma: no cover
|
|
13
|
-
from .._missing_import_stubs import create_client_stub, create_import_error_stub
|
|
14
|
-
|
|
15
|
-
GoogleClient = create_client_stub("google", "GoogleClient")
|
|
16
|
-
GoogleModelId = str
|
|
17
|
-
client = create_import_error_stub("google", "GoogleClient")
|
|
18
|
-
get_client = create_import_error_stub("google", "GoogleClient")
|
|
19
|
-
|
|
20
|
-
__all__ = ["GoogleClient", "GoogleModelId", "client", "get_client"]
|