lionagi 0.12.3__py3-none-any.whl → 0.12.5__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.
Files changed (74) hide show
  1. lionagi/config.py +123 -0
  2. lionagi/libs/schema/load_pydantic_model_from_schema.py +259 -0
  3. lionagi/libs/token_transform/perplexity.py +2 -4
  4. lionagi/libs/token_transform/synthlang_/translate_to_synthlang.py +1 -1
  5. lionagi/operations/chat/chat.py +2 -2
  6. lionagi/operations/communicate/communicate.py +20 -5
  7. lionagi/operations/parse/parse.py +131 -43
  8. lionagi/protocols/generic/pile.py +94 -33
  9. lionagi/protocols/graph/node.py +25 -19
  10. lionagi/protocols/messages/assistant_response.py +20 -1
  11. lionagi/service/connections/__init__.py +15 -0
  12. lionagi/service/connections/api_calling.py +230 -0
  13. lionagi/service/connections/endpoint.py +410 -0
  14. lionagi/service/connections/endpoint_config.py +137 -0
  15. lionagi/service/connections/header_factory.py +56 -0
  16. lionagi/service/connections/match_endpoint.py +49 -0
  17. lionagi/service/connections/providers/__init__.py +3 -0
  18. lionagi/service/connections/providers/anthropic_.py +87 -0
  19. lionagi/service/connections/providers/exa_.py +33 -0
  20. lionagi/service/connections/providers/oai_.py +166 -0
  21. lionagi/service/connections/providers/ollama_.py +122 -0
  22. lionagi/service/connections/providers/perplexity_.py +29 -0
  23. lionagi/service/imodel.py +36 -144
  24. lionagi/service/manager.py +1 -7
  25. lionagi/service/{endpoints/rate_limited_processor.py → rate_limited_processor.py} +4 -2
  26. lionagi/service/resilience.py +545 -0
  27. lionagi/service/third_party/README.md +71 -0
  28. lionagi/service/third_party/anthropic_models.py +159 -0
  29. lionagi/service/{providers/exa_/models.py → third_party/exa_models.py} +18 -13
  30. lionagi/service/third_party/openai_models.py +18241 -0
  31. lionagi/service/third_party/pplx_models.py +156 -0
  32. lionagi/service/types.py +5 -4
  33. lionagi/session/branch.py +12 -7
  34. lionagi/tools/file/reader.py +1 -1
  35. lionagi/tools/memory/tools.py +497 -0
  36. lionagi/version.py +1 -1
  37. {lionagi-0.12.3.dist-info → lionagi-0.12.5.dist-info}/METADATA +17 -19
  38. {lionagi-0.12.3.dist-info → lionagi-0.12.5.dist-info}/RECORD +43 -54
  39. lionagi/adapters/__init__.py +0 -1
  40. lionagi/adapters/adapter.py +0 -120
  41. lionagi/adapters/json_adapter.py +0 -181
  42. lionagi/adapters/pandas_/csv_adapter.py +0 -94
  43. lionagi/adapters/pandas_/excel_adapter.py +0 -94
  44. lionagi/adapters/pandas_/pd_dataframe_adapter.py +0 -81
  45. lionagi/adapters/pandas_/pd_series_adapter.py +0 -57
  46. lionagi/adapters/toml_adapter.py +0 -204
  47. lionagi/adapters/types.py +0 -21
  48. lionagi/service/endpoints/__init__.py +0 -3
  49. lionagi/service/endpoints/base.py +0 -706
  50. lionagi/service/endpoints/chat_completion.py +0 -116
  51. lionagi/service/endpoints/match_endpoint.py +0 -72
  52. lionagi/service/providers/__init__.py +0 -3
  53. lionagi/service/providers/anthropic_/__init__.py +0 -3
  54. lionagi/service/providers/anthropic_/messages.py +0 -99
  55. lionagi/service/providers/exa_/search.py +0 -80
  56. lionagi/service/providers/exa_/types.py +0 -7
  57. lionagi/service/providers/groq_/__init__.py +0 -3
  58. lionagi/service/providers/groq_/chat_completions.py +0 -56
  59. lionagi/service/providers/ollama_/__init__.py +0 -3
  60. lionagi/service/providers/ollama_/chat_completions.py +0 -134
  61. lionagi/service/providers/openai_/__init__.py +0 -3
  62. lionagi/service/providers/openai_/chat_completions.py +0 -101
  63. lionagi/service/providers/openai_/spec.py +0 -14
  64. lionagi/service/providers/openrouter_/__init__.py +0 -3
  65. lionagi/service/providers/openrouter_/chat_completions.py +0 -62
  66. lionagi/service/providers/perplexity_/__init__.py +0 -3
  67. lionagi/service/providers/perplexity_/chat_completions.py +0 -44
  68. lionagi/service/providers/perplexity_/models.py +0 -144
  69. lionagi/service/providers/types.py +0 -17
  70. /lionagi/{adapters/pandas_/__init__.py → py.typed} +0 -0
  71. /lionagi/service/{providers/exa_ → third_party}/__init__.py +0 -0
  72. /lionagi/service/{endpoints/token_calculator.py → token_calculator.py} +0 -0
  73. {lionagi-0.12.3.dist-info → lionagi-0.12.5.dist-info}/WHEEL +0 -0
  74. {lionagi-0.12.3.dist-info → lionagi-0.12.5.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,159 @@
1
+ # Copyright (c) 2025, HaiyangLi <quantocean.li at gmail dot com>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ """Anthropic API models for request/response validation."""
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Literal, Optional, Union
10
+
11
+ from pydantic import BaseModel, Field, field_validator
12
+
13
+
14
+ class TextContentBlock(BaseModel):
15
+ type: Literal["text"] = "text"
16
+ text: str
17
+ cache_control: dict | None = None
18
+
19
+
20
+ class ImageSource(BaseModel):
21
+ type: Literal["base64"] = "base64"
22
+ media_type: Literal["image/jpeg", "image/png", "image/gif", "image/webp"]
23
+ data: str
24
+
25
+
26
+ class ImageContentBlock(BaseModel):
27
+ type: Literal["image"] = "image"
28
+ source: ImageSource
29
+
30
+
31
+ ContentBlock = Union[TextContentBlock, ImageContentBlock]
32
+
33
+
34
+ class Message(BaseModel):
35
+ role: Literal["user", "assistant"]
36
+ content: str | list[str | ContentBlock]
37
+
38
+ @field_validator("content", mode="before")
39
+ def validate_content(cls, v):
40
+ """Convert string content to proper format."""
41
+ if isinstance(v, str):
42
+ return v
43
+ if isinstance(v, list):
44
+ # Ensure all items are either strings or proper content blocks
45
+ result = []
46
+ for item in v:
47
+ if isinstance(item, str):
48
+ result.append({"type": "text", "text": item})
49
+ else:
50
+ result.append(item)
51
+ return result
52
+ return v
53
+
54
+
55
+ class ToolDefinition(BaseModel):
56
+ name: str = Field(
57
+ ..., min_length=1, max_length=64, pattern="^[a-zA-Z0-9_-]+$"
58
+ )
59
+ description: str | None = None
60
+ input_schema: dict
61
+
62
+
63
+ class ToolChoice(BaseModel):
64
+ type: Literal["auto", "any", "tool"]
65
+ name: str | None = None
66
+
67
+
68
+ class CreateMessageRequest(BaseModel):
69
+ """Request model for Anthropic messages API."""
70
+
71
+ model: str = Field(..., min_length=1, max_length=256)
72
+ messages: list[Message]
73
+ max_tokens: int = Field(..., ge=1)
74
+
75
+ # Optional fields
76
+ system: str | list[ContentBlock] | None = None
77
+ temperature: float | None = Field(None, ge=0, le=1)
78
+ top_p: float | None = Field(None, ge=0, le=1)
79
+ top_k: int | None = Field(None, ge=0)
80
+ stop_sequences: list[str] | None = None
81
+ stream: bool | None = False
82
+ metadata: dict | None = None
83
+ tools: list[ToolDefinition] | None = None
84
+ tool_choice: ToolChoice | dict | None = None
85
+
86
+ class Config:
87
+ extra = "forbid"
88
+
89
+
90
+ class Usage(BaseModel):
91
+ """Token usage information."""
92
+
93
+ input_tokens: int
94
+ output_tokens: int
95
+
96
+
97
+ class ContentBlockResponse(BaseModel):
98
+ """Response content block."""
99
+
100
+ type: Literal["text"]
101
+ text: str
102
+
103
+
104
+ class CreateMessageResponse(BaseModel):
105
+ """Response model for Anthropic messages API."""
106
+
107
+ id: str
108
+ type: Literal["message"] = "message"
109
+ role: Literal["assistant"] = "assistant"
110
+ content: list[ContentBlockResponse]
111
+ model: str
112
+ stop_reason: None | (
113
+ Literal["end_turn", "max_tokens", "stop_sequence", "tool_use"]
114
+ ) = None
115
+ stop_sequence: str | None = None
116
+ usage: Usage
117
+
118
+
119
+ # Streaming response models
120
+ class MessageStartEvent(BaseModel):
121
+ type: Literal["message_start"] = "message_start"
122
+ message: CreateMessageResponse
123
+
124
+
125
+ class ContentBlockStartEvent(BaseModel):
126
+ type: Literal["content_block_start"] = "content_block_start"
127
+ index: int
128
+ content_block: ContentBlockResponse
129
+
130
+
131
+ class ContentBlockDeltaEvent(BaseModel):
132
+ type: Literal["content_block_delta"] = "content_block_delta"
133
+ index: int
134
+ delta: dict
135
+
136
+
137
+ class ContentBlockStopEvent(BaseModel):
138
+ type: Literal["content_block_stop"] = "content_block_stop"
139
+ index: int
140
+
141
+
142
+ class MessageDeltaEvent(BaseModel):
143
+ type: Literal["message_delta"] = "message_delta"
144
+ delta: dict
145
+ usage: Usage | None = None
146
+
147
+
148
+ class MessageStopEvent(BaseModel):
149
+ type: Literal["message_stop"] = "message_stop"
150
+
151
+
152
+ StreamEvent = Union[
153
+ MessageStartEvent,
154
+ ContentBlockStartEvent,
155
+ ContentBlockDeltaEvent,
156
+ ContentBlockStopEvent,
157
+ MessageDeltaEvent,
158
+ MessageStopEvent,
159
+ ]
@@ -3,7 +3,7 @@ from enum import Enum
3
3
  from pydantic import BaseModel, Field
4
4
 
5
5
 
6
- class CategoryEnum(str, Enum):
6
+ class SearchCategory(str, Enum):
7
7
  company = "company"
8
8
  research_paper = "research paper"
9
9
  news = "news"
@@ -15,13 +15,13 @@ class CategoryEnum(str, Enum):
15
15
  financial_report = "financial report"
16
16
 
17
17
 
18
- class LivecrawlEnum(str, Enum):
18
+ class LivecrawlType(str, Enum):
19
19
  never = "never"
20
20
  fallback = "fallback"
21
21
  always = "always"
22
22
 
23
23
 
24
- class SearchTypeEnum(str, Enum):
24
+ class SearchType(str, Enum):
25
25
  keyword = "keyword"
26
26
  neural = "neural"
27
27
  auto = "auto"
@@ -30,11 +30,12 @@ class SearchTypeEnum(str, Enum):
30
30
  class ContentsText(BaseModel):
31
31
  includeHtmlTags: bool | None = Field(
32
32
  default=False,
33
- description="Whether to include HTML tags in the text. Set to True if you want to retain HTML structure for the LLM to interpret.",
33
+ description="Whether to include HTML tags in the text. Set to True if you want"
34
+ " to retain HTML structure for the LLM to interpret.",
34
35
  )
35
36
  maxCharacters: int | None = Field(
36
37
  default=None,
37
- description="The maximum number of characters to return from the webpage text.",
38
+ description="The maximum number of characters to return from the webpage text",
38
39
  )
39
40
 
40
41
 
@@ -72,7 +73,8 @@ class ContentsExtras(BaseModel):
72
73
  class Contents(BaseModel):
73
74
  text: None | ContentsText = Field(
74
75
  default=None,
75
- description="Return full or partial text for each page, with optional HTML structure or size limit.",
76
+ description="Return full or partial text for each page, with optional HTML "
77
+ "structure or size limit.",
76
78
  )
77
79
  highlights: None | ContentsHighlights = Field(
78
80
  default=None, description="Return snippet highlights for each page."
@@ -80,8 +82,8 @@ class Contents(BaseModel):
80
82
  summary: None | ContentsSummary = Field(
81
83
  default=None, description="Return a short summary of each page."
82
84
  )
83
- livecrawl: None | LivecrawlEnum = Field(
84
- default=LivecrawlEnum.never,
85
+ livecrawl: None | LivecrawlType = Field(
86
+ default=LivecrawlType.never,
85
87
  description="Livecrawling setting for each page. Options: never, fallback, always.",
86
88
  )
87
89
  livecrawlTimeout: int | None = Field(
@@ -107,11 +109,11 @@ class ExaSearchRequest(BaseModel):
107
109
  ...,
108
110
  description="The main query string describing what you're looking for.",
109
111
  )
110
- category: None | CategoryEnum = Field(
112
+ category: None | SearchCategory = Field(
111
113
  default=None,
112
114
  description="A data category to focus on, such as 'company', 'research paper', 'news', etc.",
113
115
  )
114
- type: None | SearchTypeEnum = Field(
116
+ type: None | SearchType = Field(
115
117
  default=None,
116
118
  description="The type of search to run. Can be 'auto', 'keyword', or 'neural'.",
117
119
  )
@@ -148,13 +150,16 @@ class ExaSearchRequest(BaseModel):
148
150
  )
149
151
  includeText: None | list[str] = Field(
150
152
  default=None,
151
- description="Strings that must appear in the webpage text. Only a single string up to 5 words is currently supported.",
153
+ description="Strings that must appear in the webpage text. Only a single string up to "
154
+ "5 words is currently supported.",
152
155
  )
153
156
  excludeText: None | list[str] = Field(
154
157
  default=None,
155
- description="Strings that must NOT appear in the webpage text. Only a single string up to 5 words is currently supported.",
158
+ description="Strings that must NOT appear in the webpage text. Only a single string up to "
159
+ "5 words is currently supported.",
156
160
  )
157
161
  contents: None | Contents = Field(
158
162
  default=None,
159
- description="Dict defining the different ways you want to retrieve webpage contents, including text, highlights, or summaries.",
163
+ description="Dict defining the different ways you want to retrieve webpage contents, "
164
+ "including text, highlights, or summaries.",
160
165
  )