lionagi 0.6.1__py3-none-any.whl → 0.7.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. lionagi/libs/token_transform/__init__.py +0 -0
  2. lionagi/libs/token_transform/llmlingua.py +1 -0
  3. lionagi/libs/token_transform/perplexity.py +439 -0
  4. lionagi/libs/token_transform/synthlang.py +409 -0
  5. lionagi/operations/ReAct/ReAct.py +126 -0
  6. lionagi/operations/ReAct/utils.py +28 -0
  7. lionagi/operations/__init__.py +1 -9
  8. lionagi/operations/_act/act.py +73 -0
  9. lionagi/operations/chat/__init__.py +3 -0
  10. lionagi/operations/chat/chat.py +173 -0
  11. lionagi/operations/communicate/__init__.py +0 -0
  12. lionagi/operations/communicate/communicate.py +167 -0
  13. lionagi/operations/instruct/__init__.py +3 -0
  14. lionagi/operations/instruct/instruct.py +29 -0
  15. lionagi/operations/interpret/__init__.py +3 -0
  16. lionagi/operations/interpret/interpret.py +40 -0
  17. lionagi/operations/operate/__init__.py +3 -0
  18. lionagi/operations/operate/operate.py +189 -0
  19. lionagi/operations/parse/__init__.py +3 -0
  20. lionagi/operations/parse/parse.py +125 -0
  21. lionagi/operations/select/__init__.py +0 -4
  22. lionagi/operations/select/select.py +11 -30
  23. lionagi/operations/select/utils.py +13 -2
  24. lionagi/operations/translate/__init__.py +0 -0
  25. lionagi/operations/translate/translate.py +47 -0
  26. lionagi/operations/types.py +16 -0
  27. lionagi/operatives/action/manager.py +20 -21
  28. lionagi/operatives/strategies/__init__.py +3 -0
  29. lionagi/session/branch.py +1098 -929
  30. lionagi/version.py +1 -1
  31. {lionagi-0.6.1.dist-info → lionagi-0.7.0.dist-info}/METADATA +1 -1
  32. {lionagi-0.6.1.dist-info → lionagi-0.7.0.dist-info}/RECORD +45 -26
  33. lionagi/libs/compress/models.py +0 -66
  34. lionagi/libs/compress/utils.py +0 -69
  35. lionagi/operations/select/prompt.py +0 -5
  36. /lionagi/{libs/compress → operations/ReAct}/__init__.py +0 -0
  37. /lionagi/operations/{strategies → _act}/__init__.py +0 -0
  38. /lionagi/{operations → operatives}/strategies/base.py +0 -0
  39. /lionagi/{operations → operatives}/strategies/concurrent.py +0 -0
  40. /lionagi/{operations → operatives}/strategies/concurrent_chunk.py +0 -0
  41. /lionagi/{operations → operatives}/strategies/concurrent_sequential_chunk.py +0 -0
  42. /lionagi/{operations → operatives}/strategies/params.py +0 -0
  43. /lionagi/{operations → operatives}/strategies/sequential.py +0 -0
  44. /lionagi/{operations → operatives}/strategies/sequential_chunk.py +0 -0
  45. /lionagi/{operations → operatives}/strategies/sequential_concurrent_chunk.py +0 -0
  46. /lionagi/{operations → operatives}/strategies/utils.py +0 -0
  47. {lionagi-0.6.1.dist-info → lionagi-0.7.0.dist-info}/WHEEL +0 -0
  48. {lionagi-0.6.1.dist-info → lionagi-0.7.0.dist-info}/licenses/LICENSE +0 -0
lionagi/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.6.1"
1
+ __version__ = "0.7.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
@@ -3,12 +3,9 @@ lionagi/_class_registry.py,sha256=dutMsw-FQNqVV5gGH-NEIv90uBkSr8fERJ_x3swbb-s,31
3
3
  lionagi/_errors.py,sha256=wNKdnVQvE_CHEstK7htrrj334RA_vbGcIds-3pUiRkc,455
4
4
  lionagi/settings.py,sha256=k9zRJXv57TveyfHO3Vr9VGiKrSwlRUUVKt5zf6v9RU4,1627
5
5
  lionagi/utils.py,sha256=hBlGmi8Px_ng3v4_D_k8xNpW3X93u01930lkZIHUQ-Y,73019
6
- lionagi/version.py,sha256=baAcEjLSYFIeNZF51tOMmA_zAMhN8HvKael-UU-Ruec,22
6
+ lionagi/version.py,sha256=RaANGbRu5e-vehwXI1-Qe2ggPPfs1TQaZj072JdbLk4,22
7
7
  lionagi/libs/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
8
8
  lionagi/libs/parse.py,sha256=tpEbmIRGuHhLCJlUlm6fjmqm_Z6XJLAXGNFHNuk422I,1011
9
- lionagi/libs/compress/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
10
- lionagi/libs/compress/models.py,sha256=MJ5hmRjzlWIyKbkFpkUXjgi8kvGXPUoIvgdVZXUnUZ8,1906
11
- lionagi/libs/compress/utils.py,sha256=QZQWB-lJiarqlr0fiRN6yUdOddGsqK89qvPWT2YsMM0,1802
12
9
  lionagi/libs/file/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
13
10
  lionagi/libs/file/chunk.py,sha256=YS1EZXQFnYlFLKMveLXHKWZGk43vtLjuYb8D663T4IA,8835
14
11
  lionagi/libs/file/file_ops.py,sha256=_h30SBV-Es4-X7c5iPoRE3oQFu_V7OIxWQVU7c5UQvw,3430
@@ -36,35 +33,47 @@ lionagi/libs/schema/extract_code_block.py,sha256=ZfOFh6psjYyS9nm7zJoMMUYBkFPh9-J
36
33
  lionagi/libs/schema/extract_docstring.py,sha256=VbxB4ZDsaZAMc0r8hphdvSsqXSyJ2w80zloAUirGFts,5729
37
34
  lionagi/libs/schema/function_to_schema.py,sha256=_wuuZOxohCDdJCPnUi8_YobJ47XRVI5HjrwnWO_3xeQ,3393
38
35
  lionagi/libs/schema/json_schema.py,sha256=Z45azAI_7lr5BWj-X6VQwUhuvuqXibciXgla8wi4gPY,7670
36
+ lionagi/libs/token_transform/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
+ lionagi/libs/token_transform/llmlingua.py,sha256=DkeLUlrb7rGx3nZ04aADU9HXXu5mZTf_DBwT0xhzIv4,7
38
+ lionagi/libs/token_transform/perplexity.py,sha256=XX-RoqGbeVYSl7fG1T_hF3I2pCAJ0A1LSKkrUpqsbeI,14091
39
+ lionagi/libs/token_transform/synthlang.py,sha256=dD2JD0WCB0xLMF2PG8nJluJXEQ6VSTyqmTnmrFm9IgU,12709
39
40
  lionagi/libs/validate/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
40
41
  lionagi/libs/validate/common_field_validators.py,sha256=5pu3kH13dVy1Nq-AQcHx0bIPusOnhvvCwUmaBX5l8bw,4778
41
42
  lionagi/libs/validate/fuzzy_match_keys.py,sha256=S7kzJnh-aKDMFbecmtMjFHNk2h-xMJqtQygMnq839lY,6255
42
43
  lionagi/libs/validate/fuzzy_validate_mapping.py,sha256=SQqyxgrAgJ5zBKxIAnulWsZXb-PAzLBEF2NhV6G0x-E,4935
43
44
  lionagi/libs/validate/string_similarity.py,sha256=7x8D4LZCMNJGz2ZCeKmct7Nc4i8m_ORoHIeGvkeMZOA,8733
44
45
  lionagi/libs/validate/validate_boolean.py,sha256=h3d7Dn7asJokBozWaKxaV_3Y6vUWBc0-zfNJjTQ9Bo8,3614
45
- lionagi/operations/__init__.py,sha256=_TvmWRotAQILyE3JWls7uY1luV7GAwwddtVdKnvjgIk,280
46
- lionagi/operations/types.py,sha256=_TvmWRotAQILyE3JWls7uY1luV7GAwwddtVdKnvjgIk,280
46
+ lionagi/operations/__init__.py,sha256=O7nV0tedpUe7_OlUWmCcduGPFtqtzWZcR_SIOnjLsro,134
47
+ lionagi/operations/types.py,sha256=LIa68xcyKLVafof-DSFwKtSkneuYPFqrtGyClohYI6o,704
47
48
  lionagi/operations/utils.py,sha256=Twy6L_UFt9JqJFRYuKKTKVZIXsePidNl5ipcYcCbesI,1220
49
+ lionagi/operations/ReAct/ReAct.py,sha256=NH8P2urJRk7WJrL7QbRB1J7PafQOb6Ef5b-k4w0JQbs,3945
50
+ lionagi/operations/ReAct/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
51
+ lionagi/operations/ReAct/utils.py,sha256=0OhZhoc8QsTsMFo2Jmys1mgpnMwHsldKuLVSbev9uZM,994
52
+ lionagi/operations/_act/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
53
+ lionagi/operations/_act/act.py,sha256=YTJzdDtp8JzwOx4SG8rafWSseUrHsOVDhmCoNnuOxs8,2213
48
54
  lionagi/operations/brainstorm/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
49
55
  lionagi/operations/brainstorm/brainstorm.py,sha256=88Cq2IBrUs5du9q_8rf_VmhLYBfGKJv4rCeDTcJ07_g,17196
50
56
  lionagi/operations/brainstorm/prompt.py,sha256=f-Eh6pO606dT2TrX9BFv_einRDpYwFi6Gep9Strd1cM,610
57
+ lionagi/operations/chat/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
58
+ lionagi/operations/chat/chat.py,sha256=ug3bFTByNVwa5Rlb1qWY1vf1cCMDpX8sX1tGR6ElYIs,5356
59
+ lionagi/operations/communicate/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
+ lionagi/operations/communicate/communicate.py,sha256=ZOW-jrPXb8Tt2NCy53yYMmndNZxhY1vruebQB7_wV5E,5660
61
+ lionagi/operations/instruct/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
62
+ lionagi/operations/instruct/instruct.py,sha256=CYICzWvmgALtSPIetfF3csx6WDsCuiu4NRRPL56UA2g,795
63
+ lionagi/operations/interpret/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
64
+ lionagi/operations/interpret/interpret.py,sha256=3VrPe01RnZhsdtQlhG8xNno2jojOq1O9ZfJwyIH2FWk,1118
65
+ lionagi/operations/operate/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
66
+ lionagi/operations/operate/operate.py,sha256=4Z6rQmaylI_ZeNPIviz5fsDD-NFlmbcK5nqQ8z2Sasg,6670
67
+ lionagi/operations/parse/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
68
+ lionagi/operations/parse/parse.py,sha256=-MGdQTV8N0KQsj_ec08P0kd_55ubpOaH_v5VlSHse54,4575
51
69
  lionagi/operations/plan/__init__.py,sha256=AFkAmOJBTqPlYuqFRRn7rCvIw3CGh9XXH_22cNWbfig,156
52
70
  lionagi/operations/plan/plan.py,sha256=Uxysob3evbjhXWS_wseO3Mb_A90p1wk3ralJ17rHFCk,15333
53
71
  lionagi/operations/plan/prompt.py,sha256=ig4JjJR5gV-lXPRVbiaJuL9qeoahM_afYvWphpY1lWA,993
54
- lionagi/operations/select/__init__.py,sha256=an28I5IbKj0waICk5SjYnz3WmkQLpIARO0yNUu9VWNE,162
55
- lionagi/operations/select/prompt.py,sha256=2OJQE8EKPj9nubP_drp6BYyF7J8RiDs1BEkv0D-HLn8,299
56
- lionagi/operations/select/select.py,sha256=B_XZcdmW9mmVGFZGnfCn89TxZvAMlS27YcD9RQ96f40,3166
57
- lionagi/operations/select/utils.py,sha256=hYOSGx7vMvjGHibcFOUuCfTXFO2IzzIUwQy82PQtluQ,3251
58
- lionagi/operations/strategies/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
59
- lionagi/operations/strategies/base.py,sha256=cfZXUZYPypW-hFZJj7HDtTPc-x99XB6dO_S5os1srTk,1820
60
- lionagi/operations/strategies/concurrent.py,sha256=bLLL90LYywkxGlMY8XXGsZ1GRZrtB_8lsfkqspLgQ6o,2721
61
- lionagi/operations/strategies/concurrent_chunk.py,sha256=9qwYoqO0LO1BMIyxU-tc_9ppBK0J94cnWs3e7wx7PR0,1678
62
- lionagi/operations/strategies/concurrent_sequential_chunk.py,sha256=5Zw9fO1YWSj81w6IjOdEPzHE-4TxIdui-ljjrAsbEEI,3658
63
- lionagi/operations/strategies/params.py,sha256=XNCD8sQJCm7xk0yGFKSQ14FuUNV1f8wLfNNJg_NYsn8,5407
64
- lionagi/operations/strategies/sequential.py,sha256=nSMtYy10P4W8U2SoARfKCBDN6y8_WoubKjoORUnewjY,949
65
- lionagi/operations/strategies/sequential_chunk.py,sha256=bs_0zZJjJpYdmEEWx3mwh3it5ErQYfZr-ImahyKEy8Y,3161
66
- lionagi/operations/strategies/sequential_concurrent_chunk.py,sha256=GJurnTuu6U7FOPR9mZxkjoJMIiQbgvRGt5iZZtmB2mY,3559
67
- lionagi/operations/strategies/utils.py,sha256=plZg84Yqba5GAmNPvsiUjbAavdDmCfwZkKnK_c_aORw,1414
72
+ lionagi/operations/select/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
73
+ lionagi/operations/select/select.py,sha256=qCxgsqNSDQVmtINHTee2973UU6VuBuAsO7fdhQ0VYjQ,2492
74
+ lionagi/operations/select/utils.py,sha256=uFnpTTGg05D3nzB8h81caIhwZa5-m9xrd-GJmlnU41s,3713
75
+ lionagi/operations/translate/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
76
+ lionagi/operations/translate/translate.py,sha256=6eBVoQRarGEJ8Tfcl6Z__PLHQTTIbM5MaPVYNeKHRIs,1397
68
77
  lionagi/operatives/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
69
78
  lionagi/operatives/manager.py,sha256=pFGKSOIkXayHfDHCMJJwZXBhx3O02UlYK5mZ_-53AVg,190
70
79
  lionagi/operatives/operative.py,sha256=WZeg1XHS8iuzs4I3-va9FS9tOWu0XZ7xnOVzHthvEUQ,6724
@@ -72,7 +81,7 @@ lionagi/operatives/step.py,sha256=DevwisZc2q88ynUiiSu7VBEY2A_G4Q5iRLrVgVLHNJU,98
72
81
  lionagi/operatives/types.py,sha256=8krpGIeJL2GkO580ePOuAZfGc7vUVPIanemoA77tbVY,1697
73
82
  lionagi/operatives/action/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
74
83
  lionagi/operatives/action/function_calling.py,sha256=VHUq8qebCAAdaWcPJQCZNI-P6zC_P1kp9o-d7nhZf_0,4602
75
- lionagi/operatives/action/manager.py,sha256=H50L9fv6kpQ87vW4nEIfP1JHZ5gX4fQs0uPDeRpEYEw,7929
84
+ lionagi/operatives/action/manager.py,sha256=N0M4pUuxh51yelNzad1YuDcsNPgVmgLMD0JaWvNlIHI,7840
76
85
  lionagi/operatives/action/request_response_model.py,sha256=7X_ZkcgmQ0D77qyP8_39RdEAKASCjEPWH4ey83jIUKc,2326
77
86
  lionagi/operatives/action/tool.py,sha256=fUwlzmi6kuuwHU6xA8Soo_bWOgD-I7TBLtJ-WJ1OBLk,4277
78
87
  lionagi/operatives/action/utils.py,sha256=vUe7Aysuzbg16rAfe2Ttp5QUz5_L6mMedBVAWzGAHwk,4330
@@ -94,6 +103,16 @@ lionagi/operatives/models/model_params.py,sha256=yElYJ0el2CFykdVlBHhpVG77PO_q6Zq
94
103
  lionagi/operatives/models/note.py,sha256=8TS0Zi0eSo1fmVoqBMWB6ChSrXKb36ozAM70o7P4kTU,9495
95
104
  lionagi/operatives/models/operable_model.py,sha256=mnTIAXJHJecXjqKNZWSch5w6x3U3Fl_9mUK4RudnM64,15573
96
105
  lionagi/operatives/models/schema_model.py,sha256=-BeCwW_1Rle--w-f7MajbOYH7t_8SPWw0_qK0fpTsRg,666
106
+ lionagi/operatives/strategies/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
107
+ lionagi/operatives/strategies/base.py,sha256=cfZXUZYPypW-hFZJj7HDtTPc-x99XB6dO_S5os1srTk,1820
108
+ lionagi/operatives/strategies/concurrent.py,sha256=bLLL90LYywkxGlMY8XXGsZ1GRZrtB_8lsfkqspLgQ6o,2721
109
+ lionagi/operatives/strategies/concurrent_chunk.py,sha256=9qwYoqO0LO1BMIyxU-tc_9ppBK0J94cnWs3e7wx7PR0,1678
110
+ lionagi/operatives/strategies/concurrent_sequential_chunk.py,sha256=5Zw9fO1YWSj81w6IjOdEPzHE-4TxIdui-ljjrAsbEEI,3658
111
+ lionagi/operatives/strategies/params.py,sha256=XNCD8sQJCm7xk0yGFKSQ14FuUNV1f8wLfNNJg_NYsn8,5407
112
+ lionagi/operatives/strategies/sequential.py,sha256=nSMtYy10P4W8U2SoARfKCBDN6y8_WoubKjoORUnewjY,949
113
+ lionagi/operatives/strategies/sequential_chunk.py,sha256=bs_0zZJjJpYdmEEWx3mwh3it5ErQYfZr-ImahyKEy8Y,3161
114
+ lionagi/operatives/strategies/sequential_concurrent_chunk.py,sha256=GJurnTuu6U7FOPR9mZxkjoJMIiQbgvRGt5iZZtmB2mY,3559
115
+ lionagi/operatives/strategies/utils.py,sha256=plZg84Yqba5GAmNPvsiUjbAavdDmCfwZkKnK_c_aORw,1414
97
116
  lionagi/protocols/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
98
117
  lionagi/protocols/_concepts.py,sha256=aIV3cIuKxRcEFdROemlFR6mMAwqiYv-rjkZQ4rHBfXo,1554
99
118
  lionagi/protocols/types.py,sha256=M-cWgRGl8vaU776MuX-QSQVmaI1rbXmzyW9tfPHzGYc,2065
@@ -161,9 +180,9 @@ lionagi/service/providers/openrouter_/chat_completions.py,sha256=MRf4ZbMCgzNIL4g
161
180
  lionagi/service/providers/perplexity_/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
162
181
  lionagi/service/providers/perplexity_/chat_completions.py,sha256=SsDbrtXwQsR4Yu2VMU43KfeS86QWI8UTNhDth5lNWNs,1055
163
182
  lionagi/session/__init__.py,sha256=v8vNyJVIVj8_Oz9RJdVe6ZKUQMYTgDh1VQpnr1KdLaw,112
164
- lionagi/session/branch.py,sha256=-lu63-Eua1pgo9RVoiS54G4_JtmNC__ZEaegRtKFPro,47448
183
+ lionagi/session/branch.py,sha256=Fhuv_JM4glBw8BEiOksQmehHPAyxe4beQ2QBIJduypA,57727
165
184
  lionagi/session/session.py,sha256=A2PCG1BD1noMLtCJD3C_H7r-0GUQ_ru2szOhF1pOCtY,8976
166
- lionagi-0.6.1.dist-info/METADATA,sha256=_KZh-djuuzJ-mwnUvpVUJ7TGmw_ghQnj0_QvqG8nkFY,22776
167
- lionagi-0.6.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
168
- lionagi-0.6.1.dist-info/licenses/LICENSE,sha256=VXFWsdoN5AAknBCgFqQNgPWYx7OPp-PFEP961zGdOjc,11288
169
- lionagi-0.6.1.dist-info/RECORD,,
185
+ lionagi-0.7.0.dist-info/METADATA,sha256=GScf641-hvSkJb8TJTrZgPYDhFs012qBnJhfTItnGbo,22776
186
+ lionagi-0.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
187
+ lionagi-0.7.0.dist-info/licenses/LICENSE,sha256=VXFWsdoN5AAknBCgFqQNgPWYx7OPp-PFEP961zGdOjc,11288
188
+ lionagi-0.7.0.dist-info/RECORD,,
@@ -1,66 +0,0 @@
1
- # Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
-
5
- import numpy as np
6
- from pydantic import BaseModel
7
-
8
- from lionagi.operatives.models.note import Note
9
- from lionagi.protocols.generic.log import Log
10
-
11
-
12
- class PerplexityTokenScore(BaseModel):
13
- token: str
14
- logprob: float
15
-
16
-
17
- class PerplexityScores(BaseModel):
18
-
19
- completion_response: BaseModel
20
- original_tokens: list[str]
21
- n_samples: int
22
-
23
- @property
24
- def logprobs(self) -> list[float]:
25
- return [i.logprob for i in self.perplexity_scores]
26
-
27
- @property
28
- def predicted_tokens(self) -> list[str]:
29
- return [i.token for i in self.perplexity_scores]
30
-
31
- @property
32
- def perplexity(self) -> float:
33
- return np.exp(np.mean(self.logprobs))
34
-
35
- @property
36
- def perplexity_scores(self) -> list[PerplexityTokenScore]:
37
- outs = []
38
- log_prob = self.completion_response.choices[0].logprobs
39
- n = Note.from_dict(log_prob)
40
- for j in range(len(n[["content"]])):
41
- p_ = ["content", j]
42
- p_token = p_ + ["token"]
43
- p_logprob = p_ + ["logprob"]
44
- p_score = PerplexityTokenScore(
45
- token=n[p_token], logprob=n[p_logprob]
46
- )
47
- outs.append(p_score)
48
- return outs
49
-
50
- @property
51
- def prompt_tokens(self) -> int:
52
- return self.completion_response.usage.prompt_tokens
53
-
54
- @property
55
- def completion_tokens(self) -> int:
56
- return self.completion_response.usage.completion_tokens
57
-
58
- def to_log(self) -> Log:
59
- dict_ = self.model_dump()
60
- info = dict_.pop("completion_response")
61
- dict_["perplexity"] = self.perplexity
62
- dict_["prompt_tokens"] = self.prompt_tokens
63
- dict_["completion_tokens"] = self.completion_tokens
64
- dict_["perplexity_scores"] = self.perplexity_scores
65
-
66
- return Log(content=dict_, info=info)
@@ -1,69 +0,0 @@
1
- # Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
-
5
- import asyncio
6
-
7
- from lionagi.service.imodel import iModel
8
-
9
- from .models import PerplexityScores
10
-
11
-
12
- async def compute_perplexity(
13
- imodel: iModel,
14
- initial_context: str = None,
15
- tokens: list[str] = None,
16
- system_msg: str = None,
17
- n_samples: int = 1, # number of samples used for the computation
18
- use_residue: bool = True, # whether to use residue for the last sample
19
- **kwargs,
20
- ) -> list[PerplexityScores]:
21
- tasks = []
22
- context = initial_context or ""
23
-
24
- n_samples = n_samples or len(tokens)
25
- sample_token_len, residue = divmod(len(tokens), n_samples)
26
- samples = []
27
-
28
- if n_samples == 1:
29
- samples = [tokens]
30
- else:
31
- samples = [
32
- tokens[: (i + 1) * sample_token_len] for i in range(n_samples)
33
- ]
34
-
35
- if use_residue and residue != 0:
36
- samples.append(tokens[-residue:])
37
-
38
- sampless = [context + " ".join(sample) for sample in samples]
39
-
40
- for sample in sampless:
41
- messages = (
42
- [{"role": "system", "content": system_msg}] if system_msg else []
43
- )
44
- messages.append(
45
- {"role": "user", "content": sample},
46
- )
47
- task = asyncio.create_task(
48
- imodel.invoke(
49
- messages=messages,
50
- logprobs=True,
51
- max_tokens=sample_token_len,
52
- **kwargs,
53
- )
54
- )
55
- tasks.append(task)
56
-
57
- results = await asyncio.gather(*tasks)
58
-
59
- outs = []
60
-
61
- for idx, item in enumerate(results):
62
- p = PerplexityScores(
63
- completion_response=item,
64
- original_tokens=samples[idx],
65
- n_samples=n_samples,
66
- )
67
- outs.append(p)
68
-
69
- return outs
@@ -1,5 +0,0 @@
1
- # Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
-
5
- PROMPT = "Please select up to {max_num_selections} items from the following list {choices}. Provide the selection(s) into appropriate field in format required, and no comments from you"
File without changes
File without changes
File without changes
File without changes
File without changes