lionagi 0.6.1__tar.gz → 0.7.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. {lionagi-0.6.1 → lionagi-0.7.0}/PKG-INFO +1 -1
  2. lionagi-0.7.0/lionagi/libs/token_transform/llmlingua.py +1 -0
  3. lionagi-0.7.0/lionagi/libs/token_transform/perplexity.py +439 -0
  4. lionagi-0.7.0/lionagi/libs/token_transform/synthlang.py +409 -0
  5. lionagi-0.7.0/lionagi/operations/ReAct/ReAct.py +126 -0
  6. lionagi-0.7.0/lionagi/operations/ReAct/utils.py +28 -0
  7. lionagi-0.7.0/lionagi/operations/__init__.py +5 -0
  8. lionagi-0.7.0/lionagi/operations/_act/act.py +73 -0
  9. lionagi-0.7.0/lionagi/operations/chat/chat.py +173 -0
  10. lionagi-0.7.0/lionagi/operations/communicate/communicate.py +167 -0
  11. lionagi-0.7.0/lionagi/operations/instruct/instruct.py +29 -0
  12. lionagi-0.7.0/lionagi/operations/interpret/interpret.py +40 -0
  13. lionagi-0.7.0/lionagi/operations/operate/operate.py +189 -0
  14. lionagi-0.7.0/lionagi/operations/parse/parse.py +125 -0
  15. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operations/select/select.py +11 -30
  16. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operations/select/utils.py +13 -2
  17. lionagi-0.7.0/lionagi/operations/translate/__init__.py +0 -0
  18. lionagi-0.7.0/lionagi/operations/translate/translate.py +47 -0
  19. lionagi-0.7.0/lionagi/operations/types.py +29 -0
  20. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/action/manager.py +20 -21
  21. lionagi-0.7.0/lionagi/protocols/adapters/__init__.py +0 -0
  22. lionagi-0.7.0/lionagi/protocols/adapters/pandas_/__init__.py +0 -0
  23. lionagi-0.7.0/lionagi/service/providers/__init__.py +3 -0
  24. lionagi-0.7.0/lionagi/service/providers/anthropic_/__init__.py +3 -0
  25. lionagi-0.7.0/lionagi/service/providers/groq_/__init__.py +3 -0
  26. lionagi-0.7.0/lionagi/service/providers/openai_/__init__.py +3 -0
  27. lionagi-0.7.0/lionagi/service/providers/openrouter_/__init__.py +3 -0
  28. lionagi-0.7.0/lionagi/service/providers/perplexity_/__init__.py +3 -0
  29. lionagi-0.7.0/lionagi/session/__init__.py +3 -0
  30. lionagi-0.7.0/lionagi/session/branch.py +1456 -0
  31. lionagi-0.7.0/lionagi/version.py +1 -0
  32. {lionagi-0.6.1 → lionagi-0.7.0}/pyproject.toml +6 -1
  33. {lionagi-0.6.1 → lionagi-0.7.0}/uv.lock +1 -1
  34. lionagi-0.6.1/lionagi/libs/compress/models.py +0 -66
  35. lionagi-0.6.1/lionagi/libs/compress/utils.py +0 -69
  36. lionagi-0.6.1/lionagi/operations/__init__.py +0 -13
  37. lionagi-0.6.1/lionagi/operations/select/__init__.py +0 -7
  38. lionagi-0.6.1/lionagi/operations/select/prompt.py +0 -5
  39. lionagi-0.6.1/lionagi/operations/types.py +0 -13
  40. lionagi-0.6.1/lionagi/session/branch.py +0 -1287
  41. lionagi-0.6.1/lionagi/version.py +0 -1
  42. {lionagi-0.6.1 → lionagi-0.7.0}/.env.example +0 -0
  43. {lionagi-0.6.1 → lionagi-0.7.0}/.github/FUNDING.yml +0 -0
  44. {lionagi-0.6.1 → lionagi-0.7.0}/.github/dependabot.yml +0 -0
  45. {lionagi-0.6.1 → lionagi-0.7.0}/.github/workflows/ci.yml +0 -0
  46. {lionagi-0.6.1 → lionagi-0.7.0}/.github/workflows/codeql.yml +0 -0
  47. {lionagi-0.6.1 → lionagi-0.7.0}/.github/workflows/docs.yml +0 -0
  48. {lionagi-0.6.1 → lionagi-0.7.0}/.github/workflows/release.yml +0 -0
  49. {lionagi-0.6.1 → lionagi-0.7.0}/.gitignore +0 -0
  50. {lionagi-0.6.1 → lionagi-0.7.0}/.pre-commit-config.yaml +0 -0
  51. {lionagi-0.6.1 → lionagi-0.7.0}/.python-version +0 -0
  52. {lionagi-0.6.1 → lionagi-0.7.0}/CODE_OF_CONDUCT.md +0 -0
  53. {lionagi-0.6.1 → lionagi-0.7.0}/CONTRIBUTING.md +0 -0
  54. {lionagi-0.6.1 → lionagi-0.7.0}/LICENSE +0 -0
  55. {lionagi-0.6.1 → lionagi-0.7.0}/README.md +0 -0
  56. {lionagi-0.6.1 → lionagi-0.7.0}/dev_tools/count_code_base_lines.py +0 -0
  57. {lionagi-0.6.1 → lionagi-0.7.0}/docs/Makefile +0 -0
  58. {lionagi-0.6.1 → lionagi-0.7.0}/docs/_static/custom.css +0 -0
  59. {lionagi-0.6.1 → lionagi-0.7.0}/docs/_templates/layout.html +0 -0
  60. {lionagi-0.6.1 → lionagi-0.7.0}/docs/conf.py +0 -0
  61. {lionagi-0.6.1 → lionagi-0.7.0}/docs/index.rst +0 -0
  62. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/action.rst +0 -0
  63. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/adapter.rst +0 -0
  64. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/branch.rst +0 -0
  65. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/concepts.rst +0 -0
  66. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/event.rst +0 -0
  67. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/form.rst +0 -0
  68. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/graph.rst +0 -0
  69. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/index.rst +0 -0
  70. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/instruct.rst +0 -0
  71. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/lib_file.rst +0 -0
  72. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/lib_nested.rst +0 -0
  73. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/lib_package.rst +0 -0
  74. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/lib_schema.rst +0 -0
  75. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/lib_validate.rst +0 -0
  76. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/mail.rst +0 -0
  77. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/message.rst +0 -0
  78. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/models.rst +0 -0
  79. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/operations.rst +0 -0
  80. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/operative_step.rst +0 -0
  81. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/pile_progression.rst +0 -0
  82. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/service.rst +0 -0
  83. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/session.rst +0 -0
  84. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/strategies.rst +0 -0
  85. {lionagi-0.6.1 → lionagi-0.7.0}/docs/modules/utils.rst +0 -0
  86. {lionagi-0.6.1 → lionagi-0.7.0}/docs/operations/core_operations.rst +0 -0
  87. {lionagi-0.6.1 → lionagi-0.7.0}/docs/operations/index.rst +0 -0
  88. {lionagi-0.6.1 → lionagi-0.7.0}/docs/operations/strategies.rst +0 -0
  89. {lionagi-0.6.1 → lionagi-0.7.0}/docs/tutorials/get_started.rst +0 -0
  90. {lionagi-0.6.1 → lionagi-0.7.0}/docs/tutorials/get_started_pt2.rst +0 -0
  91. {lionagi-0.6.1 → lionagi-0.7.0}/docs/tutorials/get_started_pt3.rst +0 -0
  92. {lionagi-0.6.1 → lionagi-0.7.0}/docs/tutorials/index.rst +0 -0
  93. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/__init__.py +0 -0
  94. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/_class_registry.py +0 -0
  95. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/_errors.py +0 -0
  96. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/__init__.py +0 -0
  97. {lionagi-0.6.1/lionagi/libs/compress → lionagi-0.7.0/lionagi/libs/file}/__init__.py +0 -0
  98. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/file/chunk.py +0 -0
  99. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/file/file_ops.py +0 -0
  100. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/file/params.py +0 -0
  101. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/file/process.py +0 -0
  102. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/file/save.py +0 -0
  103. {lionagi-0.6.1/lionagi/libs/file → lionagi-0.7.0/lionagi/libs/nested}/__init__.py +0 -0
  104. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/nested/flatten.py +0 -0
  105. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/nested/nfilter.py +0 -0
  106. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/nested/nget.py +0 -0
  107. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/nested/ninsert.py +0 -0
  108. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/nested/nmerge.py +0 -0
  109. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/nested/npop.py +0 -0
  110. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/nested/nset.py +0 -0
  111. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/nested/unflatten.py +0 -0
  112. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/nested/utils.py +0 -0
  113. {lionagi-0.6.1/lionagi/libs/nested → lionagi-0.7.0/lionagi/libs/package}/__init__.py +0 -0
  114. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/package/imports.py +0 -0
  115. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/package/management.py +0 -0
  116. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/package/params.py +0 -0
  117. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/package/system.py +0 -0
  118. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/parse.py +0 -0
  119. {lionagi-0.6.1/lionagi/libs/package → lionagi-0.7.0/lionagi/libs/schema}/__init__.py +0 -0
  120. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/schema/as_readable.py +0 -0
  121. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/schema/extract_code_block.py +0 -0
  122. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/schema/extract_docstring.py +0 -0
  123. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/schema/function_to_schema.py +0 -0
  124. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/schema/json_schema.py +0 -0
  125. {lionagi-0.6.1/lionagi/protocols/adapters → lionagi-0.7.0/lionagi/libs/token_transform}/__init__.py +0 -0
  126. {lionagi-0.6.1/lionagi/libs/schema → lionagi-0.7.0/lionagi/libs/validate}/__init__.py +0 -0
  127. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/validate/common_field_validators.py +0 -0
  128. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/validate/fuzzy_match_keys.py +0 -0
  129. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/validate/fuzzy_validate_mapping.py +0 -0
  130. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/validate/string_similarity.py +0 -0
  131. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/libs/validate/validate_boolean.py +0 -0
  132. {lionagi-0.6.1/lionagi/libs/validate → lionagi-0.7.0/lionagi/operations/ReAct}/__init__.py +0 -0
  133. {lionagi-0.6.1/lionagi/operations/brainstorm → lionagi-0.7.0/lionagi/operations/_act}/__init__.py +0 -0
  134. {lionagi-0.6.1/lionagi/operations/strategies → lionagi-0.7.0/lionagi/operations/brainstorm}/__init__.py +0 -0
  135. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operations/brainstorm/brainstorm.py +0 -0
  136. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operations/brainstorm/prompt.py +0 -0
  137. {lionagi-0.6.1/lionagi/operatives → lionagi-0.7.0/lionagi/operations/chat}/__init__.py +0 -0
  138. {lionagi-0.6.1/lionagi/protocols/adapters/pandas_ → lionagi-0.7.0/lionagi/operations/communicate}/__init__.py +0 -0
  139. {lionagi-0.6.1/lionagi/operatives/action → lionagi-0.7.0/lionagi/operations/instruct}/__init__.py +0 -0
  140. {lionagi-0.6.1/lionagi/operatives/forms → lionagi-0.7.0/lionagi/operations/interpret}/__init__.py +0 -0
  141. {lionagi-0.6.1/lionagi/operatives/instruct → lionagi-0.7.0/lionagi/operations/operate}/__init__.py +0 -0
  142. {lionagi-0.6.1/lionagi/operatives/models → lionagi-0.7.0/lionagi/operations/parse}/__init__.py +0 -0
  143. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operations/plan/__init__.py +0 -0
  144. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operations/plan/plan.py +0 -0
  145. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operations/plan/prompt.py +0 -0
  146. {lionagi-0.6.1/lionagi/protocols → lionagi-0.7.0/lionagi/operations/select}/__init__.py +0 -0
  147. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operations/utils.py +0 -0
  148. {lionagi-0.6.1/lionagi/protocols/generic → lionagi-0.7.0/lionagi/operatives}/__init__.py +0 -0
  149. {lionagi-0.6.1/lionagi/protocols/graph → lionagi-0.7.0/lionagi/operatives/action}/__init__.py +0 -0
  150. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/action/function_calling.py +0 -0
  151. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/action/request_response_model.py +0 -0
  152. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/action/tool.py +0 -0
  153. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/action/utils.py +0 -0
  154. {lionagi-0.6.1/lionagi/protocols/mail → lionagi-0.7.0/lionagi/operatives/forms}/__init__.py +0 -0
  155. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/forms/base.py +0 -0
  156. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/forms/form.py +0 -0
  157. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/forms/report.py +0 -0
  158. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/forms/utils.py +0 -0
  159. {lionagi-0.6.1/lionagi/protocols/messages → lionagi-0.7.0/lionagi/operatives/instruct}/__init__.py +0 -0
  160. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/instruct/base.py +0 -0
  161. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/instruct/instruct.py +0 -0
  162. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/instruct/instruct_collection.py +0 -0
  163. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/instruct/node.py +0 -0
  164. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/instruct/prompts.py +0 -0
  165. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/instruct/reason.py +0 -0
  166. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/manager.py +0 -0
  167. {lionagi-0.6.1/lionagi/service/endpoints → lionagi-0.7.0/lionagi/operatives/models}/__init__.py +0 -0
  168. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/models/field_model.py +0 -0
  169. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/models/model_params.py +0 -0
  170. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/models/note.py +0 -0
  171. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/models/operable_model.py +0 -0
  172. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/models/schema_model.py +0 -0
  173. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/operative.py +0 -0
  174. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/step.py +0 -0
  175. {lionagi-0.6.1/lionagi/service/providers → lionagi-0.7.0/lionagi/operatives/strategies}/__init__.py +0 -0
  176. {lionagi-0.6.1/lionagi/operations → lionagi-0.7.0/lionagi/operatives}/strategies/base.py +0 -0
  177. {lionagi-0.6.1/lionagi/operations → lionagi-0.7.0/lionagi/operatives}/strategies/concurrent.py +0 -0
  178. {lionagi-0.6.1/lionagi/operations → lionagi-0.7.0/lionagi/operatives}/strategies/concurrent_chunk.py +0 -0
  179. {lionagi-0.6.1/lionagi/operations → lionagi-0.7.0/lionagi/operatives}/strategies/concurrent_sequential_chunk.py +0 -0
  180. {lionagi-0.6.1/lionagi/operations → lionagi-0.7.0/lionagi/operatives}/strategies/params.py +0 -0
  181. {lionagi-0.6.1/lionagi/operations → lionagi-0.7.0/lionagi/operatives}/strategies/sequential.py +0 -0
  182. {lionagi-0.6.1/lionagi/operations → lionagi-0.7.0/lionagi/operatives}/strategies/sequential_chunk.py +0 -0
  183. {lionagi-0.6.1/lionagi/operations → lionagi-0.7.0/lionagi/operatives}/strategies/sequential_concurrent_chunk.py +0 -0
  184. {lionagi-0.6.1/lionagi/operations → lionagi-0.7.0/lionagi/operatives}/strategies/utils.py +0 -0
  185. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/operatives/types.py +0 -0
  186. {lionagi-0.6.1/lionagi/service/providers/anthropic_ → lionagi-0.7.0/lionagi/protocols}/__init__.py +0 -0
  187. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/_concepts.py +0 -0
  188. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/adapters/adapter.py +0 -0
  189. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/adapters/json_adapter.py +0 -0
  190. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/adapters/pandas_/csv_adapter.py +0 -0
  191. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/adapters/pandas_/excel_adapter.py +0 -0
  192. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/adapters/pandas_/pd_dataframe_adapter.py +0 -0
  193. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/adapters/pandas_/pd_series_adapter.py +0 -0
  194. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/adapters/types.py +0 -0
  195. {lionagi-0.6.1/lionagi/service/providers/groq_ → lionagi-0.7.0/lionagi/protocols/generic}/__init__.py +0 -0
  196. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/generic/element.py +0 -0
  197. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/generic/event.py +0 -0
  198. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/generic/log.py +0 -0
  199. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/generic/pile.py +0 -0
  200. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/generic/processor.py +0 -0
  201. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/generic/progression.py +0 -0
  202. {lionagi-0.6.1/lionagi/service/providers/openai_ → lionagi-0.7.0/lionagi/protocols/graph}/__init__.py +0 -0
  203. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/graph/edge.py +0 -0
  204. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/graph/graph.py +0 -0
  205. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/graph/node.py +0 -0
  206. {lionagi-0.6.1/lionagi/service/providers/openrouter_ → lionagi-0.7.0/lionagi/protocols/mail}/__init__.py +0 -0
  207. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/mail/exchange.py +0 -0
  208. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/mail/mail.py +0 -0
  209. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/mail/mailbox.py +0 -0
  210. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/mail/manager.py +0 -0
  211. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/mail/package.py +0 -0
  212. {lionagi-0.6.1/lionagi/service/providers/perplexity_ → lionagi-0.7.0/lionagi/protocols/messages}/__init__.py +0 -0
  213. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/action_request.py +0 -0
  214. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/action_response.py +0 -0
  215. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/assistant_response.py +0 -0
  216. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/base.py +0 -0
  217. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/instruction.py +0 -0
  218. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/manager.py +0 -0
  219. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/message.py +0 -0
  220. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/system.py +0 -0
  221. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/templates/README.md +0 -0
  222. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/templates/action_request.jinja2 +0 -0
  223. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/templates/action_response.jinja2 +0 -0
  224. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/templates/assistant_response.jinja2 +0 -0
  225. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/templates/instruction_message.jinja2 +0 -0
  226. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/templates/system_message.jinja2 +0 -0
  227. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/messages/templates/tool_schemas.jinja2 +0 -0
  228. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/protocols/types.py +0 -0
  229. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/__init__.py +0 -0
  230. {lionagi-0.6.1/lionagi/session → lionagi-0.7.0/lionagi/service/endpoints}/__init__.py +0 -0
  231. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/endpoints/base.py +0 -0
  232. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/endpoints/chat_completion.py +0 -0
  233. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/endpoints/match_endpoint.py +0 -0
  234. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/endpoints/rate_limited_processor.py +0 -0
  235. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/endpoints/token_calculator.py +0 -0
  236. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/imodel.py +0 -0
  237. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/manager.py +0 -0
  238. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/providers/anthropic_/messages.py +0 -0
  239. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/providers/groq_/chat_completions.py +0 -0
  240. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/providers/openai_/chat_completions.py +0 -0
  241. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/providers/openrouter_/chat_completions.py +0 -0
  242. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/providers/perplexity_/chat_completions.py +0 -0
  243. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/service/types.py +0 -0
  244. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/session/session.py +0 -0
  245. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/settings.py +0 -0
  246. {lionagi-0.6.1 → lionagi-0.7.0}/lionagi/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lionagi
3
- Version: 0.6.1
3
+ Version: 0.7.0
4
4
  Summary: An AGentic Intelligence Operating System.
5
5
  Author-email: HaiyangLi <quantocean.li@gmail.com>
6
6
  License: Apache License
@@ -0,0 +1,439 @@
1
+ import asyncio
2
+ from dataclasses import dataclass
3
+ from timeit import default_timer as timer
4
+
5
+ import numpy as np
6
+ from pydantic import BaseModel
7
+
8
+ from lionagi.protocols.generic.event import EventStatus
9
+ from lionagi.protocols.generic.log import Log
10
+ from lionagi.service.endpoints.base import APICalling
11
+ from lionagi.service.imodel import iModel
12
+ from lionagi.utils import alcall, lcall, to_dict, to_list
13
+
14
+
15
+ @dataclass
16
+ class PerplexityScores:
17
+ """
18
+ Stores logprobs, tokens, and derived perplexity from a completion response.
19
+ """
20
+
21
+ completion_response: BaseModel | dict
22
+ original_tokens: list[str]
23
+ n_samples: int
24
+
25
+ @property
26
+ def logprobs(self) -> list[float]:
27
+ """Return list of logprobs extracted from the model response."""
28
+ return [i["logprob"] for i in self.perplexity_scores]
29
+
30
+ @property
31
+ def perplexity(self) -> float:
32
+ """
33
+ e^(mean logprob), if logprobs exist. Fallback to 1.0 if empty.
34
+ """
35
+ if not self.logprobs:
36
+ return 1.0
37
+ return np.exp(np.mean(self.logprobs))
38
+
39
+ @property
40
+ def perplexity_scores(self) -> list[dict]:
41
+ """
42
+ Return [{'token': ..., 'logprob': ...}, ...].
43
+ Handles two possible logprob structures:
44
+ - "tokens" + "token_logprobs"
45
+ - "content" (older style)
46
+ """
47
+ outs = []
48
+ try:
49
+ if isinstance(self.completion_response, dict):
50
+ log_prob = self.completion_response["choices"][0]["logprobs"]
51
+ else:
52
+ # Pydantic or other object
53
+ log_prob = self.completion_response.choices[0].logprobs
54
+ except Exception:
55
+ return outs
56
+
57
+ if not log_prob:
58
+ return outs
59
+
60
+ if "tokens" in log_prob and "token_logprobs" in log_prob:
61
+ # OpenAI style logprobs
62
+ for token, lp in zip(
63
+ log_prob["tokens"], log_prob["token_logprobs"]
64
+ ):
65
+ outs.append({"token": token, "logprob": lp})
66
+ elif "content" in log_prob:
67
+ # Old style logprobs
68
+ for item in log_prob["content"]:
69
+ outs.append(
70
+ {"token": item["token"], "logprob": item["logprob"]}
71
+ )
72
+ return outs
73
+
74
+ def to_dict(self) -> dict:
75
+ """
76
+ Construct a dictionary representation, including perplexity, usage, etc.
77
+ """
78
+ # usage info
79
+ usage = {}
80
+ if isinstance(self.completion_response, dict):
81
+ usage = self.completion_response.get("usage", {})
82
+ else:
83
+ usage = to_dict(self.completion_response.usage)
84
+
85
+ return {
86
+ "perplexity": self.perplexity,
87
+ "original_tokens": self.original_tokens,
88
+ "prompt_tokens": usage.get("prompt_tokens", 0),
89
+ "completion_tokens": usage.get("completion_tokens", 0),
90
+ "total_tokens": usage.get("total_tokens", 0),
91
+ }
92
+
93
+ def to_log(self) -> Log:
94
+ """
95
+ Return a Log object for convenience.
96
+ """
97
+ return Log(content=self.to_dict())
98
+
99
+
100
+ async def compute_perplexity(
101
+ chat_model: iModel,
102
+ initial_context: str = None,
103
+ tokens: list[str] = None,
104
+ system_msg: str = None,
105
+ n_samples: int = 1,
106
+ use_residue: bool = True,
107
+ **kwargs,
108
+ ) -> list[PerplexityScores]:
109
+ """
110
+ Splits tokens into n_samples chunks, calls the model with logprobs=True,
111
+ and returns PerplexityScores for each chunk.
112
+ """
113
+ context = initial_context or ""
114
+ n_samples = n_samples or len(tokens)
115
+
116
+ sample_token_len, residue = divmod(len(tokens), n_samples)
117
+ if n_samples == 1:
118
+ samples = [tokens]
119
+ else:
120
+ samples = [
121
+ tokens[: (i + 1) * sample_token_len] for i in range(n_samples)
122
+ ]
123
+ if use_residue and residue != 0:
124
+ samples.append(tokens[-residue:])
125
+
126
+ # Build text for each chunk
127
+ sampless = [context + " " + " ".join(s) for s in samples]
128
+ kwargs["logprobs"] = True
129
+
130
+ async def _inner(api_call: APICalling):
131
+ await api_call.invoke()
132
+ elapsed = 0
133
+ while (
134
+ api_call.status not in [EventStatus.COMPLETED, EventStatus.FAILED]
135
+ and elapsed < 5
136
+ ):
137
+ await asyncio.sleep(0.1)
138
+ elapsed += 0.1
139
+ return api_call.response
140
+
141
+ # Create and schedule calls
142
+ api_calls = []
143
+ for sample_txt in sampless:
144
+ messages = []
145
+ if system_msg:
146
+ if not chat_model.sequential_exchange:
147
+ messages.append({"role": "system", "content": system_msg})
148
+ messages.append({"role": "user", "content": sample_txt})
149
+ else:
150
+ messages.append({"role": "user", "content": sample_txt})
151
+
152
+ api_calls.append(
153
+ chat_model.create_api_calling(messages=messages, **kwargs)
154
+ )
155
+
156
+ results = await alcall(api_calls, _inner, max_concurrent=50)
157
+
158
+ def _pplx_score(input_):
159
+ idx, resp = input_
160
+ return PerplexityScores(resp, samples[idx], n_samples)
161
+
162
+ return lcall(enumerate(results), _pplx_score)
163
+
164
+
165
+ class LLMCompressor:
166
+ """
167
+ Compress text by selecting segments with highest perplexity tokens
168
+ (or in practice, rank segments by logprob).
169
+ """
170
+
171
+ def __init__(
172
+ self,
173
+ chat_model: iModel,
174
+ system_msg=None,
175
+ tokenizer=None,
176
+ splitter=None,
177
+ target_ratio=0.2,
178
+ n_samples=5,
179
+ chunk_size=64,
180
+ max_tokens_per_sample=80,
181
+ min_pplx=0,
182
+ split_overlap=0,
183
+ split_threshold=0,
184
+ verbose=True,
185
+ ):
186
+ # Must have "logprobs" support
187
+ if "logprobs" not in chat_model.endpoint.acceptable_kwargs:
188
+ raise ValueError(
189
+ f"Model {chat_model.model_name} does not support logprobs. "
190
+ "Please use a model that supports logprobs."
191
+ )
192
+
193
+ self.chat_model = chat_model
194
+ self.tokenizer = tokenizer
195
+ self.splitter = splitter
196
+ self.system_msg = (
197
+ system_msg or "Concisely summarize content for storage:"
198
+ )
199
+ self.target_ratio = target_ratio
200
+ self.n_samples = n_samples
201
+ self.chunk_size = chunk_size
202
+ self.max_tokens_per_sample = max_tokens_per_sample
203
+ self.min_pplx = min_pplx
204
+ self.verbose = verbose
205
+ self.split_overlap = split_overlap
206
+ self.split_threshold = split_threshold
207
+
208
+ def tokenize(self, text: str, **kwargs) -> list[str]:
209
+ """
210
+ Tokenize text. If no custom tokenizer, use the default from lionagi.
211
+ """
212
+ if not self.tokenizer:
213
+ from lionagi.service.endpoints.token_calculator import (
214
+ TokenCalculator,
215
+ )
216
+
217
+ return TokenCalculator.tokenize(
218
+ text,
219
+ encoding_name=self.chat_model.model_name,
220
+ return_tokens=True,
221
+ )
222
+ if hasattr(self.tokenizer, "tokenize"):
223
+ return self.tokenizer.tokenize(text, **kwargs)
224
+ return self.tokenizer(text, **kwargs)
225
+
226
+ def split(
227
+ self,
228
+ text: str,
229
+ chunk_size=None,
230
+ overlap=None,
231
+ threshold=None,
232
+ by_chars=False,
233
+ return_tokens=False,
234
+ **kwargs,
235
+ ) -> list:
236
+ """
237
+ Split text into segments. If no custom splitter, default to chunk_content from lionagi.
238
+ """
239
+ if not self.splitter:
240
+ from lionagi.libs.file.chunk import chunk_content
241
+
242
+ contents = chunk_content(
243
+ content=text,
244
+ chunk_size=chunk_size or self.chunk_size,
245
+ overlap=overlap or self.split_overlap,
246
+ threshold=threshold or self.split_threshold,
247
+ return_tokens=return_tokens,
248
+ chunk_by="chars" if by_chars else "tokens",
249
+ )
250
+ return [i["chunk_content"] for i in contents]
251
+
252
+ # If user provided an object with .split or .chunk or .segment
253
+ for meth in ["split", "chunk", "segment"]:
254
+ if hasattr(self.splitter, meth):
255
+ return getattr(self.splitter, meth)(text, **kwargs)
256
+ raise ValueError(
257
+ "No valid method found in splitter: must have .split/.chunk/.segment"
258
+ )
259
+
260
+ async def rank_by_pplex(
261
+ self,
262
+ items: list,
263
+ initial_text=None,
264
+ cumulative=False,
265
+ n_samples=None,
266
+ use_residue=True,
267
+ **kwargs,
268
+ ) -> list:
269
+ """
270
+ Rank items (token lists or strings) by perplexity descending.
271
+ If cumulative=True, each item is appended to the context.
272
+ """
273
+
274
+ async def _get_item_perplexity(item):
275
+ # Ensure item is a list of tokens
276
+ item_toks = item if isinstance(item, list) else [item]
277
+ if len(item_toks) > self.max_tokens_per_sample:
278
+ item_toks = item_toks[: self.max_tokens_per_sample]
279
+ pplex_scores = await compute_perplexity(
280
+ chat_model=self.chat_model,
281
+ initial_context=initial_text,
282
+ tokens=item_toks,
283
+ n_samples=n_samples or self.n_samples,
284
+ system_msg=self.system_msg,
285
+ use_residue=use_residue,
286
+ **kwargs,
287
+ )
288
+ # Usually we only look at pplex_scores[0], as there's one chunk
289
+ return pplex_scores
290
+
291
+ # If user passed a single string, tokenize it
292
+ if isinstance(items, str):
293
+ items = self.tokenize(items)
294
+
295
+ if len(items) == 1:
296
+ single_scores = await _get_item_perplexity(items[0])
297
+ return [(items[0], single_scores[0])]
298
+
299
+ segments = []
300
+ if cumulative:
301
+ ctx = initial_text or ""
302
+ for i in items:
303
+ seg_toks = i if isinstance(i, list) else [i]
304
+ joined = " ".join(seg_toks)
305
+ ctx += " " + joined
306
+ segments.append(ctx)
307
+ else:
308
+ for i in items:
309
+ seg_toks = i if isinstance(i, list) else [i]
310
+ segments.append(" ".join(seg_toks))
311
+
312
+ tasks = [
313
+ asyncio.create_task(_get_item_perplexity(seg)) for seg in segments
314
+ ]
315
+ results = await asyncio.gather(*tasks)
316
+ # Pair each item with the first pplex (p[0]) if multiple were returned
317
+ pairs = [(itm, pplex[0]) for itm, pplex in zip(items, results)]
318
+
319
+ # Sort descending by perplexity
320
+ return sorted(pairs, key=lambda x: x[1].perplexity, reverse=True)
321
+
322
+ async def compress(
323
+ self,
324
+ text: str,
325
+ compression_ratio=None,
326
+ initial_text=None,
327
+ cumulative=False,
328
+ split_kwargs=None,
329
+ min_pplx=None,
330
+ **kwargs,
331
+ ) -> str:
332
+ """
333
+ Main method to compress text:
334
+ 1) Split text
335
+ 2) Rank by perplexity
336
+ 3) Select best segments until reaching target ratio
337
+ """
338
+ start = timer()
339
+ if split_kwargs is None:
340
+ split_kwargs = {
341
+ "chunk_size": self.max_tokens_per_sample,
342
+ "overlap": self.split_overlap,
343
+ "threshold": self.split_threshold,
344
+ "return_tokens": True,
345
+ }
346
+
347
+ # Tokenize once to get total length
348
+ all_tokens = self.tokenize(text)
349
+ original_len = len(all_tokens)
350
+
351
+ # Split text
352
+ items = self.split(text, **split_kwargs)
353
+ # items -> list of token-lists
354
+
355
+ # Rank
356
+ ranked = await self.rank_by_pplex(
357
+ items=items,
358
+ initial_text=initial_text,
359
+ cumulative=cumulative,
360
+ **kwargs,
361
+ )
362
+
363
+ # Select
364
+ selected = self.select_by_pplex(
365
+ ranked_items=ranked,
366
+ target_compression_ratio=compression_ratio or self.target_ratio,
367
+ original_length=original_len,
368
+ min_pplx=min_pplx or self.min_pplx,
369
+ )
370
+
371
+ if self.verbose:
372
+ compressed_len = sum(
373
+ len(to_list(self.tokenize(x), dropna=True, flatten=True))
374
+ for x in selected
375
+ )
376
+ ratio = compressed_len / original_len if original_len else 1
377
+ print(
378
+ f"Original tokens: {original_len}\n"
379
+ f"Selected tokens: {compressed_len}\n"
380
+ f"Compression ratio: {ratio:.3f}\n"
381
+ f"Time: {timer() - start:.3f}s\n"
382
+ )
383
+
384
+ # Join final
385
+ out_str = " ".join(selected)
386
+ return out_str.strip()
387
+
388
+ def select_by_pplex(
389
+ self,
390
+ ranked_items: list,
391
+ target_compression_ratio: float,
392
+ original_length: int,
393
+ min_pplx=0,
394
+ ) -> list[str]:
395
+ """
396
+ From highest perplexity to lowest, pick items until we reach the desired ratio.
397
+ Items below min_pplx are skipped.
398
+ """
399
+ desired_len = int(original_length * target_compression_ratio)
400
+
401
+ chosen = []
402
+ current_len = 0
403
+ for item, info in ranked_items:
404
+ if info.perplexity > min_pplx:
405
+ if isinstance(item, list):
406
+ item_toks = to_list(item, dropna=True, flatten=True)
407
+ else:
408
+ item_toks = self.tokenize(item)
409
+ if current_len + len(item_toks) > desired_len:
410
+ break
411
+ chosen.append(" ".join(item_toks))
412
+ current_len += len(item_toks)
413
+
414
+ return chosen
415
+
416
+
417
+ # Helper function to quickly compress text using perplexity
418
+ # (If you don't want to manually create LLMCompressor instance everywhere)
419
+ async def compress_text(
420
+ text: str,
421
+ chat_model: iModel,
422
+ system_msg: str = None,
423
+ target_ratio: float = 0.2,
424
+ n_samples: int = 5,
425
+ max_tokens_per_sample=80,
426
+ verbose=True,
427
+ ) -> str:
428
+ """
429
+ Convenience function that instantiates LLMCompressor and compresses text.
430
+ """
431
+ compressor = LLMCompressor(
432
+ chat_model=chat_model,
433
+ system_msg=system_msg,
434
+ target_ratio=target_ratio,
435
+ n_samples=n_samples,
436
+ max_tokens_per_sample=max_tokens_per_sample,
437
+ verbose=verbose,
438
+ )
439
+ return await compressor.compress(text)