lionagi 0.12.2__py3-none-any.whl → 0.12.4__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 (86) hide show
  1. lionagi/config.py +123 -0
  2. lionagi/fields/file.py +1 -1
  3. lionagi/fields/reason.py +1 -1
  4. lionagi/libs/file/concat.py +1 -6
  5. lionagi/libs/file/concat_files.py +1 -5
  6. lionagi/libs/file/save.py +1 -1
  7. lionagi/libs/package/imports.py +8 -177
  8. lionagi/libs/parse.py +30 -0
  9. lionagi/libs/schema/load_pydantic_model_from_schema.py +259 -0
  10. lionagi/libs/token_transform/perplexity.py +2 -4
  11. lionagi/libs/token_transform/synthlang_/resources/frameworks/framework_options.json +46 -46
  12. lionagi/libs/token_transform/synthlang_/translate_to_synthlang.py +1 -1
  13. lionagi/operations/chat/chat.py +2 -2
  14. lionagi/operations/communicate/communicate.py +20 -5
  15. lionagi/operations/parse/parse.py +131 -43
  16. lionagi/protocols/generic/log.py +1 -2
  17. lionagi/protocols/generic/pile.py +18 -4
  18. lionagi/protocols/messages/assistant_response.py +20 -1
  19. lionagi/protocols/messages/templates/README.md +6 -10
  20. lionagi/service/connections/__init__.py +15 -0
  21. lionagi/service/connections/api_calling.py +230 -0
  22. lionagi/service/connections/endpoint.py +410 -0
  23. lionagi/service/connections/endpoint_config.py +137 -0
  24. lionagi/service/connections/header_factory.py +56 -0
  25. lionagi/service/connections/match_endpoint.py +49 -0
  26. lionagi/service/connections/providers/__init__.py +3 -0
  27. lionagi/service/connections/providers/anthropic_.py +87 -0
  28. lionagi/service/connections/providers/exa_.py +33 -0
  29. lionagi/service/connections/providers/oai_.py +166 -0
  30. lionagi/service/connections/providers/ollama_.py +122 -0
  31. lionagi/service/connections/providers/perplexity_.py +29 -0
  32. lionagi/service/imodel.py +36 -144
  33. lionagi/service/manager.py +1 -7
  34. lionagi/service/{endpoints/rate_limited_processor.py → rate_limited_processor.py} +4 -2
  35. lionagi/service/resilience.py +545 -0
  36. lionagi/service/third_party/README.md +71 -0
  37. lionagi/service/third_party/__init__.py +0 -0
  38. lionagi/service/third_party/anthropic_models.py +159 -0
  39. lionagi/service/third_party/exa_models.py +165 -0
  40. lionagi/service/third_party/openai_models.py +18241 -0
  41. lionagi/service/third_party/pplx_models.py +156 -0
  42. lionagi/service/types.py +5 -4
  43. lionagi/session/branch.py +12 -7
  44. lionagi/tools/file/reader.py +1 -1
  45. lionagi/tools/memory/tools.py +497 -0
  46. lionagi/utils.py +921 -123
  47. lionagi/version.py +1 -1
  48. {lionagi-0.12.2.dist-info → lionagi-0.12.4.dist-info}/METADATA +33 -16
  49. {lionagi-0.12.2.dist-info → lionagi-0.12.4.dist-info}/RECORD +53 -63
  50. lionagi/libs/file/create_path.py +0 -80
  51. lionagi/libs/file/file_util.py +0 -358
  52. lionagi/libs/parse/__init__.py +0 -3
  53. lionagi/libs/parse/fuzzy_parse_json.py +0 -117
  54. lionagi/libs/parse/to_dict.py +0 -336
  55. lionagi/libs/parse/to_json.py +0 -61
  56. lionagi/libs/parse/to_num.py +0 -378
  57. lionagi/libs/parse/to_xml.py +0 -57
  58. lionagi/libs/parse/xml_parser.py +0 -148
  59. lionagi/libs/schema/breakdown_pydantic_annotation.py +0 -48
  60. lionagi/service/endpoints/__init__.py +0 -3
  61. lionagi/service/endpoints/base.py +0 -706
  62. lionagi/service/endpoints/chat_completion.py +0 -116
  63. lionagi/service/endpoints/match_endpoint.py +0 -72
  64. lionagi/service/providers/__init__.py +0 -3
  65. lionagi/service/providers/anthropic_/__init__.py +0 -3
  66. lionagi/service/providers/anthropic_/messages.py +0 -99
  67. lionagi/service/providers/exa_/models.py +0 -3
  68. lionagi/service/providers/exa_/search.py +0 -80
  69. lionagi/service/providers/exa_/types.py +0 -7
  70. lionagi/service/providers/groq_/__init__.py +0 -3
  71. lionagi/service/providers/groq_/chat_completions.py +0 -56
  72. lionagi/service/providers/ollama_/__init__.py +0 -3
  73. lionagi/service/providers/ollama_/chat_completions.py +0 -134
  74. lionagi/service/providers/openai_/__init__.py +0 -3
  75. lionagi/service/providers/openai_/chat_completions.py +0 -101
  76. lionagi/service/providers/openai_/spec.py +0 -14
  77. lionagi/service/providers/openrouter_/__init__.py +0 -3
  78. lionagi/service/providers/openrouter_/chat_completions.py +0 -62
  79. lionagi/service/providers/perplexity_/__init__.py +0 -3
  80. lionagi/service/providers/perplexity_/chat_completions.py +0 -44
  81. lionagi/service/providers/perplexity_/models.py +0 -5
  82. lionagi/service/providers/types.py +0 -17
  83. /lionagi/{service/providers/exa_/__init__.py → py.typed} +0 -0
  84. /lionagi/service/{endpoints/token_calculator.py → token_calculator.py} +0 -0
  85. {lionagi-0.12.2.dist-info → lionagi-0.12.4.dist-info}/WHEEL +0 -0
  86. {lionagi-0.12.2.dist-info → lionagi-0.12.4.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,156 @@
1
+ from enum import Enum
2
+ from typing import Any, Literal
3
+
4
+ from pydantic import BaseModel, Field
5
+
6
+
7
+ class PerplexityModels(str, Enum):
8
+ """
9
+ Models available in Perplexity's API.
10
+
11
+ sonar: Lightweight, cost-effective search model designed for quick, grounded
12
+ answers
13
+ sonar-pro: Advanced search model optimized for complex queries and deeper content
14
+ understanding.
15
+ sonar-reasoning: Quick problem-solving and reasoning model, ideal for evaluating
16
+ complex queries.
17
+ sonar-deep-research: Best suited for exhaustive research, generating detailed
18
+ reports and in-depth insights.
19
+ """
20
+
21
+ SONAR = "sonar"
22
+ SONAR_PRO = "sonar-pro"
23
+ SONAR_REASONING = "sonar-reasoning"
24
+ SONAR_DEEP_RESEARCH = "sonar-deep-research"
25
+
26
+
27
+ class PerplexityMessage(BaseModel):
28
+ """A single message in the conversation."""
29
+
30
+ role: Literal["system", "user", "assistant"] = Field(
31
+ ...,
32
+ description="The role of the speaker. Must be system, user, or assistant.",
33
+ )
34
+ content: str = Field(
35
+ ...,
36
+ description="The contents of the message in this turn of conversation",
37
+ )
38
+
39
+
40
+ class WebSearchOptions(BaseModel):
41
+ search_context_size: Literal["low", "medium", "high"] = Field(
42
+ default="low",
43
+ description="Determines how much search context is retrieved for the model. "
44
+ "Options are: low (minimizes context for cost savings but less comprehensive "
45
+ "answers), medium (balanced approach suitable for most queries), and high "
46
+ "(maximizes context for comprehensive answers but at higher cost).",
47
+ )
48
+
49
+
50
+ class PerplexityChatRequest(BaseModel):
51
+ """
52
+ Represents the request body for Perplexity's Chat Completions endpoint.
53
+ Endpoint: POST https://api.perplexity.ai/chat/completions
54
+ """
55
+
56
+ model: PerplexityModels = Field(
57
+ PerplexityModels.SONAR,
58
+ description="The model name, e.g. 'sonar', (the only model available at the "
59
+ "time when this request model was updated, check doc for latest info).",
60
+ )
61
+ messages: list[PerplexityMessage] = Field(
62
+ ..., description="A list of messages forming the conversation so far."
63
+ )
64
+
65
+ # Optional parameters
66
+ frequency_penalty: float | None = Field(
67
+ default=1,
68
+ ge=0,
69
+ le=2.0,
70
+ description=(
71
+ "Decreases likelihood of repetition based on prior frequency. Applies a "
72
+ "penalty to tokens based on how frequently they've appeared in the text "
73
+ "so far. Values typically range from 0 (no penalty) to 2.0 (strong "
74
+ "penalty). Higher values (e.g., 1.5) reduce repetition of the same words"
75
+ " and phrases. Useful for preventing the model from getting stuck in loops"
76
+ ),
77
+ )
78
+ presence_penalty: float | None = Field(
79
+ default=None,
80
+ ge=0,
81
+ le=2.0,
82
+ description=(
83
+ "Positive values increase the likelihood of discussing new topics. Applies "
84
+ "a penalty to tokens that have already appeared in the text, encouraging "
85
+ "the model to talk about new concepts. Values typically range from 0 (no"
86
+ " penalty) to 2.0 (strong penalty). Higher values reduce repetition but "
87
+ "may lead to more off-topic text."
88
+ ),
89
+ )
90
+ max_tokens: int | None = Field(
91
+ default=None,
92
+ description=(
93
+ "The maximum number of completion tokens returned by the API. Controls the "
94
+ "length of the model's response. If the response would exceed this limit, "
95
+ "it will be truncated. "
96
+ ),
97
+ )
98
+ return_related_questions: bool | None = Field(
99
+ default=False,
100
+ description="Determines whether related questions should be returned.",
101
+ )
102
+ search_domain_filter: list[Any] | None = Field(
103
+ default=None,
104
+ description="A list of domains to limit search results to. Currently limited "
105
+ "to 10 domains for Allowlisting and Denylisting. For Denylisting, add a - at "
106
+ "the beginning of the domain string. for more info, "
107
+ "see: https://docs.perplexity.ai/guides/search-domain-filters",
108
+ examples=[
109
+ "nasa.gov",
110
+ "wikipedia.org",
111
+ "-example.com",
112
+ "-facebook.com",
113
+ ],
114
+ )
115
+ search_recency_filter: str | None = Field(
116
+ default=None,
117
+ description=(
118
+ "Returns search results within a specified time interval: 'month', 'week', "
119
+ "'day', or 'hour'."
120
+ ),
121
+ )
122
+ temperature: float | None = Field(
123
+ default=None,
124
+ ge=0.0,
125
+ lt=2.0,
126
+ description=(
127
+ "The amount of randomness in the response, valued between 0 and 2. Lower "
128
+ "values (e.g., 0.1) make the output more focused, deterministic, and less "
129
+ "creative. Higher values (e.g., 1.5) make the output more random and "
130
+ "creative. Use lower values for factual/information retrieval tasks and "
131
+ "higher values for creative applications."
132
+ ),
133
+ )
134
+ top_k: int | None = Field(
135
+ default=None,
136
+ ge=0,
137
+ le=2048,
138
+ description=(
139
+ "Top-K filtering. 0 disables top-k filtering. If set, only the top K "
140
+ "tokens are considered. We recommend altering either top_k or top_p, "
141
+ "but not both."
142
+ ),
143
+ )
144
+ top_p: float | None = Field(
145
+ default=None,
146
+ ge=0.0,
147
+ le=1.0,
148
+ description=(
149
+ "The nucleus sampling threshold, valued between 0 and 1. Controls the "
150
+ "diversity of generated text by considering only the tokens whose "
151
+ "cumulative probability exceeds the top_p value. Lower values (e.g., 0.5) "
152
+ "make the output more focused and deterministic, while higher values "
153
+ "(e.g., 0.95) allow for more diverse outputs. Often used as an alternative"
154
+ " to temperature."
155
+ ),
156
+ )
lionagi/service/types.py CHANGED
@@ -2,15 +2,16 @@
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
- from .endpoints.base import APICalling, EndPoint
6
- from .endpoints.rate_limited_processor import RateLimitedAPIExecutor
7
- from .endpoints.token_calculator import TokenCalculator
5
+ from .connections.api_calling import APICalling
6
+ from .connections.endpoint import Endpoint
8
7
  from .imodel import iModel
9
8
  from .manager import iModelManager
9
+ from .rate_limited_processor import RateLimitedAPIExecutor
10
+ from .token_calculator import TokenCalculator
10
11
 
11
12
  __all__ = (
12
13
  "APICalling",
13
- "EndPoint",
14
+ "Endpoint",
14
15
  "RateLimitedAPIExecutor",
15
16
  "TokenCalculator",
16
17
  "iModel",
lionagi/session/branch.py CHANGED
@@ -10,6 +10,7 @@ import pandas as pd
10
10
  from jinja2 import Template
11
11
  from pydantic import BaseModel, Field, JsonValue, PrivateAttr
12
12
 
13
+ from lionagi.config import settings
13
14
  from lionagi.fields import Instruct
14
15
  from lionagi.libs.schema.as_readable import as_readable
15
16
  from lionagi.models.field_model import FieldModel
@@ -42,7 +43,7 @@ from lionagi.protocols.types import (
42
43
  SenderRecipient,
43
44
  System,
44
45
  )
45
- from lionagi.service.endpoints.base import EndPoint
46
+ from lionagi.service.connections.endpoint import Endpoint
46
47
  from lionagi.service.types import iModel, iModelManager
47
48
  from lionagi.settings import Settings
48
49
  from lionagi.tools.base import LionTool
@@ -200,9 +201,15 @@ class Branch(Element, Communicatable, Relational):
200
201
 
201
202
  chat_model = chat_model or imodel
202
203
  if not chat_model:
203
- chat_model = iModel(**Settings.iModel.CHAT)
204
+ chat_model = iModel(
205
+ provider=settings.LIONAGI_CHAT_PROVIDER,
206
+ model=settings.LIONAGI_CHAT_MODEL,
207
+ )
204
208
  if not parse_model:
205
- parse_model = iModel(**Settings.iModel.PARSE)
209
+ parse_model = iModel(
210
+ provider=settings.LIONAGI_CHAT_PROVIDER,
211
+ model="gpt-4o-mini", # Default parse model
212
+ )
206
213
 
207
214
  if isinstance(chat_model, dict):
208
215
  chat_model = iModel.from_dict(chat_model)
@@ -571,7 +578,7 @@ class Branch(Element, Communicatable, Relational):
571
578
  self,
572
579
  provider: str = None,
573
580
  base_url: str = None,
574
- endpoint: str | EndPoint = "chat",
581
+ endpoint: str | Endpoint = "chat",
575
582
  endpoint_params: list[str] | None = None,
576
583
  api_key: str = None,
577
584
  queue_capacity: int = 100,
@@ -799,9 +806,7 @@ class Branch(Element, Communicatable, Relational):
799
806
  request_fields=request_fields,
800
807
  response_format=response_format,
801
808
  progression=progression,
802
- chat_model=kwargs.pop("chat_model", None)
803
- or imodel
804
- or self.chat_model,
809
+ imodel=imodel or kwargs.pop("chat_model", None) or self.chat_model,
805
810
  tool_schemas=tool_schemas,
806
811
  images=images,
807
812
  image_detail=image_detail,
@@ -8,7 +8,7 @@ from enum import Enum
8
8
  from pydantic import BaseModel, Field, model_validator
9
9
 
10
10
  from lionagi.protocols.action.tool import Tool
11
- from lionagi.service.endpoints.token_calculator import TokenCalculator
11
+ from lionagi.service.token_calculator import TokenCalculator
12
12
  from lionagi.utils import to_num
13
13
 
14
14
  from ..base import LionTool