pydantic-ai-slim 0.2.0__tar.gz → 0.2.1__tar.gz

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.

Potentially problematic release.


This version of pydantic-ai-slim might be problematic. Click here for more details.

Files changed (53) hide show
  1. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/PKG-INFO +3 -3
  2. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/_cli.py +10 -2
  3. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/agent.py +23 -7
  4. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/messages.py +4 -0
  5. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/anthropic.py +3 -2
  6. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/providers/bedrock.py +8 -2
  7. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/.gitignore +0 -0
  8. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/README.md +0 -0
  9. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/__init__.py +0 -0
  10. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/__main__.py +0 -0
  11. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/_agent_graph.py +0 -0
  12. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/_griffe.py +0 -0
  13. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/_output.py +0 -0
  14. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/_parts_manager.py +0 -0
  15. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/_pydantic.py +0 -0
  16. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/_system_prompt.py +0 -0
  17. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/_utils.py +0 -0
  18. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/common_tools/__init__.py +0 -0
  19. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/common_tools/duckduckgo.py +0 -0
  20. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/common_tools/tavily.py +0 -0
  21. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/exceptions.py +0 -0
  22. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/format_as_xml.py +0 -0
  23. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/format_prompt.py +0 -0
  24. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/mcp.py +0 -0
  25. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/__init__.py +0 -0
  26. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/_json_schema.py +0 -0
  27. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/bedrock.py +0 -0
  28. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/cohere.py +0 -0
  29. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/fallback.py +0 -0
  30. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/function.py +0 -0
  31. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/gemini.py +0 -0
  32. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/groq.py +0 -0
  33. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/instrumented.py +0 -0
  34. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/mistral.py +0 -0
  35. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/openai.py +0 -0
  36. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/test.py +0 -0
  37. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/models/wrapper.py +0 -0
  38. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/providers/__init__.py +0 -0
  39. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/providers/anthropic.py +0 -0
  40. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/providers/azure.py +0 -0
  41. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/providers/cohere.py +0 -0
  42. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/providers/deepseek.py +0 -0
  43. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/providers/google_gla.py +0 -0
  44. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/providers/google_vertex.py +0 -0
  45. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/providers/groq.py +0 -0
  46. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/providers/mistral.py +0 -0
  47. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/providers/openai.py +0 -0
  48. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/py.typed +0 -0
  49. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/result.py +0 -0
  50. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/settings.py +0 -0
  51. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/tools.py +0 -0
  52. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pydantic_ai/usage.py +0 -0
  53. {pydantic_ai_slim-0.2.0 → pydantic_ai_slim-0.2.1}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pydantic-ai-slim
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Agent Framework / shim to use Pydantic with LLMs, slim package
5
5
  Author-email: Samuel Colvin <samuel@pydantic.dev>, Marcelo Trylesinski <marcelotryle@gmail.com>, David Montague <david@pydantic.dev>, Alex Hall <alex@pydantic.dev>
6
6
  License-Expression: MIT
@@ -29,7 +29,7 @@ Requires-Dist: exceptiongroup; python_version < '3.11'
29
29
  Requires-Dist: griffe>=1.3.2
30
30
  Requires-Dist: httpx>=0.27
31
31
  Requires-Dist: opentelemetry-api>=1.28.0
32
- Requires-Dist: pydantic-graph==0.2.0
32
+ Requires-Dist: pydantic-graph==0.2.1
33
33
  Requires-Dist: pydantic>=2.10
34
34
  Requires-Dist: typing-inspection>=0.4.0
35
35
  Provides-Extra: anthropic
@@ -45,7 +45,7 @@ Requires-Dist: cohere>=5.13.11; (platform_system != 'Emscripten') and extra == '
45
45
  Provides-Extra: duckduckgo
46
46
  Requires-Dist: duckduckgo-search>=7.0.0; extra == 'duckduckgo'
47
47
  Provides-Extra: evals
48
- Requires-Dist: pydantic-evals==0.2.0; extra == 'evals'
48
+ Requires-Dist: pydantic-evals==0.2.1; extra == 'evals'
49
49
  Provides-Extra: groq
50
50
  Requires-Dist: groq>=0.15.0; extra == 'groq'
51
51
  Provides-Extra: logfire
@@ -42,6 +42,15 @@ except ImportError as _import_error:
42
42
  __all__ = 'cli', 'cli_exit'
43
43
 
44
44
 
45
+ PYDANTIC_AI_HOME = Path.home() / '.pydantic-ai'
46
+ """The home directory for PydanticAI CLI.
47
+
48
+ This folder is used to store the prompt history and configuration.
49
+ """
50
+
51
+ PROMPT_HISTORY_PATH = PYDANTIC_AI_HOME / 'prompt-history.txt'
52
+
53
+
45
54
  class SimpleCodeBlock(CodeBlock):
46
55
  """Customised code blocks in markdown.
47
56
 
@@ -167,9 +176,8 @@ Special prompts:
167
176
  pass
168
177
  return 0
169
178
 
170
- history = Path.home() / f'.{prog_name}-prompt-history.txt'
171
179
  # doing this instead of `PromptSession[Any](history=` allows mocking of PromptSession in tests
172
- session: PromptSession[Any] = PromptSession(history=FileHistory(str(history)))
180
+ session: PromptSession[Any] = PromptSession(history=FileHistory(str(PROMPT_HISTORY_PATH)))
173
181
  try:
174
182
  return asyncio.run(run_chat(session, stream, cli_agent, console, code_theme, prog_name))
175
183
  except KeyboardInterrupt: # pragma: no cover
@@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, Any, Callable, ClassVar, Generic, cast, final,
12
12
 
13
13
  from opentelemetry.trace import NoOpTracer, use_span
14
14
  from pydantic.json_schema import GenerateJsonSchema
15
- from typing_extensions import Literal, Never, TypeGuard, TypeVar, deprecated
15
+ from typing_extensions import Literal, Never, TypeIs, TypeVar, deprecated
16
16
 
17
17
  from pydantic_graph import End, Graph, GraphRun, GraphRunContext
18
18
  from pydantic_graph._utils import get_event_loop
@@ -459,7 +459,7 @@ class Agent(Generic[AgentDepsT, OutputDataT]):
459
459
  self,
460
460
  user_prompt: str | Sequence[_messages.UserContent] | None,
461
461
  *,
462
- output_type: type[RunOutputDataT] | ToolOutput[RunOutputDataT] | None = None,
462
+ output_type: None = None,
463
463
  message_history: list[_messages.ModelMessage] | None = None,
464
464
  model: models.Model | models.KnownModelName | str | None = None,
465
465
  deps: AgentDepsT = None,
@@ -468,7 +468,23 @@ class Agent(Generic[AgentDepsT, OutputDataT]):
468
468
  usage: _usage.Usage | None = None,
469
469
  infer_name: bool = True,
470
470
  **_deprecated_kwargs: Never,
471
- ) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, Any]]: ...
471
+ ) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, OutputDataT]]: ...
472
+
473
+ @overload
474
+ def iter(
475
+ self,
476
+ user_prompt: str | Sequence[_messages.UserContent] | None,
477
+ *,
478
+ output_type: type[RunOutputDataT] | ToolOutput[RunOutputDataT],
479
+ message_history: list[_messages.ModelMessage] | None = None,
480
+ model: models.Model | models.KnownModelName | str | None = None,
481
+ deps: AgentDepsT = None,
482
+ model_settings: ModelSettings | None = None,
483
+ usage_limits: _usage.UsageLimits | None = None,
484
+ usage: _usage.Usage | None = None,
485
+ infer_name: bool = True,
486
+ **_deprecated_kwargs: Never,
487
+ ) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, RunOutputDataT]]: ...
472
488
 
473
489
  @overload
474
490
  @deprecated('`result_type` is deprecated, use `output_type` instead.')
@@ -1621,7 +1637,7 @@ class Agent(Generic[AgentDepsT, OutputDataT]):
1621
1637
  @staticmethod
1622
1638
  def is_model_request_node(
1623
1639
  node: _agent_graph.AgentNode[T, S] | End[result.FinalResult[S]],
1624
- ) -> TypeGuard[_agent_graph.ModelRequestNode[T, S]]:
1640
+ ) -> TypeIs[_agent_graph.ModelRequestNode[T, S]]:
1625
1641
  """Check if the node is a `ModelRequestNode`, narrowing the type if it is.
1626
1642
 
1627
1643
  This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
@@ -1631,7 +1647,7 @@ class Agent(Generic[AgentDepsT, OutputDataT]):
1631
1647
  @staticmethod
1632
1648
  def is_call_tools_node(
1633
1649
  node: _agent_graph.AgentNode[T, S] | End[result.FinalResult[S]],
1634
- ) -> TypeGuard[_agent_graph.CallToolsNode[T, S]]:
1650
+ ) -> TypeIs[_agent_graph.CallToolsNode[T, S]]:
1635
1651
  """Check if the node is a `CallToolsNode`, narrowing the type if it is.
1636
1652
 
1637
1653
  This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
@@ -1641,7 +1657,7 @@ class Agent(Generic[AgentDepsT, OutputDataT]):
1641
1657
  @staticmethod
1642
1658
  def is_user_prompt_node(
1643
1659
  node: _agent_graph.AgentNode[T, S] | End[result.FinalResult[S]],
1644
- ) -> TypeGuard[_agent_graph.UserPromptNode[T, S]]:
1660
+ ) -> TypeIs[_agent_graph.UserPromptNode[T, S]]:
1645
1661
  """Check if the node is a `UserPromptNode`, narrowing the type if it is.
1646
1662
 
1647
1663
  This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
@@ -1651,7 +1667,7 @@ class Agent(Generic[AgentDepsT, OutputDataT]):
1651
1667
  @staticmethod
1652
1668
  def is_end_node(
1653
1669
  node: _agent_graph.AgentNode[T, S] | End[result.FinalResult[S]],
1654
- ) -> TypeGuard[End[result.FinalResult[S]]]:
1670
+ ) -> TypeIs[End[result.FinalResult[S]]]:
1655
1671
  """Check if the node is a `End`, narrowing the type if it is.
1656
1672
 
1657
1673
  This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations as _annotations
2
2
 
3
+ import base64
3
4
  import uuid
4
5
  from collections.abc import Sequence
5
6
  from dataclasses import dataclass, field, replace
@@ -341,6 +342,9 @@ class UserPromptPart:
341
342
  content.append(part)
342
343
  elif isinstance(part, (ImageUrl, AudioUrl, DocumentUrl, VideoUrl)):
343
344
  content.append({'kind': part.kind, 'url': part.url})
345
+ elif isinstance(part, BinaryContent):
346
+ base64_data = base64.b64encode(part.data).decode()
347
+ content.append({'kind': part.kind, 'content': base64_data, 'media_type': part.media_type})
344
348
  else:
345
349
  content.append({'kind': part.kind})
346
350
  return Event('gen_ai.user.message', body={'content': content, 'role': 'user'})
@@ -284,7 +284,7 @@ class AnthropicModel(Model):
284
284
 
285
285
  async def _map_message(self, messages: list[ModelMessage]) -> tuple[str, list[MessageParam]]:
286
286
  """Just maps a `pydantic_ai.Message` to a `anthropic.types.MessageParam`."""
287
- system_prompt: str = ''
287
+ system_prompt_parts: list[str] = []
288
288
  anthropic_messages: list[MessageParam] = []
289
289
  for m in messages:
290
290
  if isinstance(m, ModelRequest):
@@ -293,7 +293,7 @@ class AnthropicModel(Model):
293
293
  ] = []
294
294
  for request_part in m.parts:
295
295
  if isinstance(request_part, SystemPromptPart):
296
- system_prompt += request_part.content
296
+ system_prompt_parts.append(request_part.content)
297
297
  elif isinstance(request_part, UserPromptPart):
298
298
  async for content in self._map_user_prompt(request_part):
299
299
  user_content_params.append(content)
@@ -333,6 +333,7 @@ class AnthropicModel(Model):
333
333
  anthropic_messages.append(MessageParam(role='assistant', content=assistant_content_params))
334
334
  else:
335
335
  assert_never(m)
336
+ system_prompt = '\n\n'.join(system_prompt_parts)
336
337
  if instructions := self._get_instructions(messages):
337
338
  system_prompt = f'{instructions}\n\n{system_prompt}'
338
339
  return system_prompt, anthropic_messages
@@ -44,6 +44,7 @@ class BedrockProvider(Provider[BaseClient]):
44
44
  aws_access_key_id: str | None = None,
45
45
  aws_secret_access_key: str | None = None,
46
46
  aws_session_token: str | None = None,
47
+ profile_name: str | None = None,
47
48
  aws_read_timeout: float | None = None,
48
49
  aws_connect_timeout: float | None = None,
49
50
  ) -> None: ...
@@ -56,6 +57,7 @@ class BedrockProvider(Provider[BaseClient]):
56
57
  aws_access_key_id: str | None = None,
57
58
  aws_secret_access_key: str | None = None,
58
59
  aws_session_token: str | None = None,
60
+ profile_name: str | None = None,
59
61
  aws_read_timeout: float | None = None,
60
62
  aws_connect_timeout: float | None = None,
61
63
  ) -> None:
@@ -67,6 +69,7 @@ class BedrockProvider(Provider[BaseClient]):
67
69
  aws_access_key_id: The AWS access key ID.
68
70
  aws_secret_access_key: The AWS secret access key.
69
71
  aws_session_token: The AWS session token.
72
+ profile_name: The AWS profile name.
70
73
  aws_read_timeout: The read timeout for Bedrock client.
71
74
  aws_connect_timeout: The connect timeout for Bedrock client.
72
75
  """
@@ -76,12 +79,15 @@ class BedrockProvider(Provider[BaseClient]):
76
79
  try:
77
80
  read_timeout = aws_read_timeout or float(os.getenv('AWS_READ_TIMEOUT', 300))
78
81
  connect_timeout = aws_connect_timeout or float(os.getenv('AWS_CONNECT_TIMEOUT', 60))
79
- self._client = boto3.client( # type: ignore[reportUnknownMemberType]
80
- 'bedrock-runtime',
82
+ session = boto3.Session(
81
83
  aws_access_key_id=aws_access_key_id,
82
84
  aws_secret_access_key=aws_secret_access_key,
83
85
  aws_session_token=aws_session_token,
84
86
  region_name=region_name,
87
+ profile_name=profile_name,
88
+ )
89
+ self._client = session.client( # type: ignore[reportUnknownMemberType]
90
+ 'bedrock-runtime',
85
91
  config=Config(read_timeout=read_timeout, connect_timeout=connect_timeout),
86
92
  )
87
93
  except NoRegionError as exc: # pragma: no cover