opik 0.2.2__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.
Files changed (256) hide show
  1. opik-0.2.2/PKG-INFO +230 -0
  2. opik-0.2.2/README.md +3 -0
  3. opik-0.2.2/pyproject.toml +6 -0
  4. opik-0.2.2/setup.cfg +4 -0
  5. opik-0.2.2/setup.py +70 -0
  6. opik-0.2.2/src/opik/__init__.py +28 -0
  7. opik-0.2.2/src/opik/_logging.py +58 -0
  8. opik-0.2.2/src/opik/api_objects/__init__.py +0 -0
  9. opik-0.2.2/src/opik/api_objects/constants.py +6 -0
  10. opik-0.2.2/src/opik/api_objects/dataset/__init__.py +4 -0
  11. opik-0.2.2/src/opik/api_objects/dataset/converters.py +85 -0
  12. opik-0.2.2/src/opik/api_objects/dataset/dataset.py +308 -0
  13. opik-0.2.2/src/opik/api_objects/dataset/dataset_item.py +37 -0
  14. opik-0.2.2/src/opik/api_objects/dataset/utils.py +24 -0
  15. opik-0.2.2/src/opik/api_objects/experiment/__init__.py +3 -0
  16. opik-0.2.2/src/opik/api_objects/experiment/experiment.py +45 -0
  17. opik-0.2.2/src/opik/api_objects/experiment/experiment_item.py +10 -0
  18. opik-0.2.2/src/opik/api_objects/helpers.py +24 -0
  19. opik-0.2.2/src/opik/api_objects/opik_client.py +529 -0
  20. opik-0.2.2/src/opik/api_objects/span.py +267 -0
  21. opik-0.2.2/src/opik/api_objects/trace.py +237 -0
  22. opik-0.2.2/src/opik/api_objects/validation_helpers.py +42 -0
  23. opik-0.2.2/src/opik/cli.py +50 -0
  24. opik-0.2.2/src/opik/config.py +185 -0
  25. opik-0.2.2/src/opik/configurator/__init__.py +0 -0
  26. opik-0.2.2/src/opik/configurator/configure.py +493 -0
  27. opik-0.2.2/src/opik/configurator/interactive_helpers.py +97 -0
  28. opik-0.2.2/src/opik/context_storage.py +78 -0
  29. opik-0.2.2/src/opik/datetime_helpers.py +10 -0
  30. opik-0.2.2/src/opik/decorator/__init__.py +0 -0
  31. opik-0.2.2/src/opik/decorator/arguments_helpers.py +45 -0
  32. opik-0.2.2/src/opik/decorator/base_track_decorator.py +560 -0
  33. opik-0.2.2/src/opik/decorator/generator_wrappers.py +89 -0
  34. opik-0.2.2/src/opik/decorator/inspect_helpers.py +37 -0
  35. opik-0.2.2/src/opik/decorator/tracker.py +71 -0
  36. opik-0.2.2/src/opik/dict_utils.py +47 -0
  37. opik-0.2.2/src/opik/evaluation/__init__.py +3 -0
  38. opik-0.2.2/src/opik/evaluation/evaluation_result.py +12 -0
  39. opik-0.2.2/src/opik/evaluation/evaluator.py +98 -0
  40. opik-0.2.2/src/opik/evaluation/metrics/__init__.py +30 -0
  41. opik-0.2.2/src/opik/evaluation/metrics/arguments_helpers.py +31 -0
  42. opik-0.2.2/src/opik/evaluation/metrics/base_metric.py +50 -0
  43. opik-0.2.2/src/opik/evaluation/metrics/exceptions.py +4 -0
  44. opik-0.2.2/src/opik/evaluation/metrics/heuristics/__init__.py +0 -0
  45. opik-0.2.2/src/opik/evaluation/metrics/heuristics/contains.py +58 -0
  46. opik-0.2.2/src/opik/evaluation/metrics/heuristics/equals.py +57 -0
  47. opik-0.2.2/src/opik/evaluation/metrics/heuristics/is_json.py +47 -0
  48. opik-0.2.2/src/opik/evaluation/metrics/heuristics/levenshtein_ratio.py +61 -0
  49. opik-0.2.2/src/opik/evaluation/metrics/heuristics/regex_match.py +55 -0
  50. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/__init__.py +0 -0
  51. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/answer_relevance/__init__.py +0 -0
  52. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/answer_relevance/metric.py +121 -0
  53. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/answer_relevance/template.py +136 -0
  54. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/context_precision/__init__.py +0 -0
  55. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/context_precision/metric.py +143 -0
  56. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/context_precision/template.py +127 -0
  57. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/context_recall/__init__.py +0 -0
  58. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/context_recall/metric.py +141 -0
  59. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/context_recall/template.py +144 -0
  60. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/factuality/__init__.py +0 -0
  61. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/factuality/metric.py +135 -0
  62. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/factuality/template.py +128 -0
  63. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/hallucination/__init__.py +0 -0
  64. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/hallucination/metric.py +124 -0
  65. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/hallucination/template.py +73 -0
  66. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/moderation/__init__.py +0 -0
  67. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/moderation/metric.py +114 -0
  68. opik-0.2.2/src/opik/evaluation/metrics/llm_judges/moderation/template.py +83 -0
  69. opik-0.2.2/src/opik/evaluation/metrics/models.py +8 -0
  70. opik-0.2.2/src/opik/evaluation/metrics/score_result.py +11 -0
  71. opik-0.2.2/src/opik/evaluation/models/__init__.py +0 -0
  72. opik-0.2.2/src/opik/evaluation/models/base_model.py +21 -0
  73. opik-0.2.2/src/opik/evaluation/models/langchain_chat_model.py +23 -0
  74. opik-0.2.2/src/opik/evaluation/models/models_factory.py +13 -0
  75. opik-0.2.2/src/opik/evaluation/report.py +94 -0
  76. opik-0.2.2/src/opik/evaluation/scores_logger.py +26 -0
  77. opik-0.2.2/src/opik/evaluation/task_output.py +15 -0
  78. opik-0.2.2/src/opik/evaluation/tasks_scorer.py +137 -0
  79. opik-0.2.2/src/opik/evaluation/test_case.py +9 -0
  80. opik-0.2.2/src/opik/evaluation/test_result.py +12 -0
  81. opik-0.2.2/src/opik/evaluation/types.py +4 -0
  82. opik-0.2.2/src/opik/exceptions.py +18 -0
  83. opik-0.2.2/src/opik/hooks.py +5 -0
  84. opik-0.2.2/src/opik/httpx_client.py +29 -0
  85. opik-0.2.2/src/opik/integrations/__init__.py +0 -0
  86. opik-0.2.2/src/opik/integrations/langchain/__init__.py +3 -0
  87. opik-0.2.2/src/opik/integrations/langchain/openai_run_helpers.py +50 -0
  88. opik-0.2.2/src/opik/integrations/langchain/opik_encoder_extension.py +13 -0
  89. opik-0.2.2/src/opik/integrations/langchain/opik_tracer.py +280 -0
  90. opik-0.2.2/src/opik/integrations/llama_index/__init__.py +3 -0
  91. opik-0.2.2/src/opik/integrations/llama_index/callback.py +169 -0
  92. opik-0.2.2/src/opik/integrations/llama_index/event_parsing_utils.py +111 -0
  93. opik-0.2.2/src/opik/integrations/openai/__init__.py +3 -0
  94. opik-0.2.2/src/opik/integrations/openai/chunks_aggregator.py +64 -0
  95. opik-0.2.2/src/opik/integrations/openai/openai_decorator.py +167 -0
  96. opik-0.2.2/src/opik/integrations/openai/opik_tracker.py +35 -0
  97. opik-0.2.2/src/opik/integrations/openai/stream_wrappers.py +60 -0
  98. opik-0.2.2/src/opik/jsonable_encoder.py +70 -0
  99. opik-0.2.2/src/opik/logging_messages.py +44 -0
  100. opik-0.2.2/src/opik/message_processing/__init__.py +0 -0
  101. opik-0.2.2/src/opik/message_processing/api.py +0 -0
  102. opik-0.2.2/src/opik/message_processing/batching/__init__.py +0 -0
  103. opik-0.2.2/src/opik/message_processing/batching/base_batcher.py +49 -0
  104. opik-0.2.2/src/opik/message_processing/batching/batch_manager.py +41 -0
  105. opik-0.2.2/src/opik/message_processing/batching/batch_manager_constuctors.py +29 -0
  106. opik-0.2.2/src/opik/message_processing/batching/create_span_message_batcher.py +9 -0
  107. opik-0.2.2/src/opik/message_processing/batching/flushing_thread.py +30 -0
  108. opik-0.2.2/src/opik/message_processing/message_processors.py +196 -0
  109. opik-0.2.2/src/opik/message_processing/messages.py +95 -0
  110. opik-0.2.2/src/opik/message_processing/queue_consumer.py +48 -0
  111. opik-0.2.2/src/opik/message_processing/streamer.py +83 -0
  112. opik-0.2.2/src/opik/message_processing/streamer_constructors.py +47 -0
  113. opik-0.2.2/src/opik/opik_context.py +123 -0
  114. opik-0.2.2/src/opik/package_version.py +11 -0
  115. opik-0.2.2/src/opik/plugins/__init__.py +0 -0
  116. opik-0.2.2/src/opik/plugins/pytest/__init__.py +0 -0
  117. opik-0.2.2/src/opik/plugins/pytest/decorator.py +128 -0
  118. opik-0.2.2/src/opik/plugins/pytest/experiment_runner.py +80 -0
  119. opik-0.2.2/src/opik/plugins/pytest/hooks.py +94 -0
  120. opik-0.2.2/src/opik/plugins/pytest/summary.py +41 -0
  121. opik-0.2.2/src/opik/plugins/pytest/test_run_content.py +13 -0
  122. opik-0.2.2/src/opik/plugins/pytest/test_runs_storage.py +16 -0
  123. opik-0.2.2/src/opik/rest_api/__init__.py +221 -0
  124. opik-0.2.2/src/opik/rest_api/client.py +243 -0
  125. opik-0.2.2/src/opik/rest_api/core/__init__.py +30 -0
  126. opik-0.2.2/src/opik/rest_api/core/api_error.py +17 -0
  127. opik-0.2.2/src/opik/rest_api/core/client_wrapper.py +57 -0
  128. opik-0.2.2/src/opik/rest_api/core/datetime_utils.py +30 -0
  129. opik-0.2.2/src/opik/rest_api/core/file.py +43 -0
  130. opik-0.2.2/src/opik/rest_api/core/http_client.py +545 -0
  131. opik-0.2.2/src/opik/rest_api/core/jsonable_encoder.py +105 -0
  132. opik-0.2.2/src/opik/rest_api/core/pydantic_utilities.py +28 -0
  133. opik-0.2.2/src/opik/rest_api/core/query_encoder.py +39 -0
  134. opik-0.2.2/src/opik/rest_api/core/remove_none_from_dict.py +11 -0
  135. opik-0.2.2/src/opik/rest_api/core/request_options.py +32 -0
  136. opik-0.2.2/src/opik/rest_api/datasets/__init__.py +1 -0
  137. opik-0.2.2/src/opik/rest_api/datasets/client.py +1407 -0
  138. opik-0.2.2/src/opik/rest_api/environment.py +7 -0
  139. opik-0.2.2/src/opik/rest_api/errors/__init__.py +15 -0
  140. opik-0.2.2/src/opik/rest_api/errors/bad_request_error.py +9 -0
  141. opik-0.2.2/src/opik/rest_api/errors/conflict_error.py +9 -0
  142. opik-0.2.2/src/opik/rest_api/errors/not_found_error.py +10 -0
  143. opik-0.2.2/src/opik/rest_api/errors/not_implemented_error.py +10 -0
  144. opik-0.2.2/src/opik/rest_api/errors/unprocessable_entity_error.py +9 -0
  145. opik-0.2.2/src/opik/rest_api/experiments/__init__.py +1 -0
  146. opik-0.2.2/src/opik/rest_api/experiments/client.py +789 -0
  147. opik-0.2.2/src/opik/rest_api/feedback_definitions/__init__.py +5 -0
  148. opik-0.2.2/src/opik/rest_api/feedback_definitions/client.py +542 -0
  149. opik-0.2.2/src/opik/rest_api/feedback_definitions/types/__init__.py +5 -0
  150. opik-0.2.2/src/opik/rest_api/feedback_definitions/types/find_feedback_definitions_request_type.py +7 -0
  151. opik-0.2.2/src/opik/rest_api/projects/__init__.py +1 -0
  152. opik-0.2.2/src/opik/rest_api/projects/client.py +557 -0
  153. opik-0.2.2/src/opik/rest_api/spans/__init__.py +5 -0
  154. opik-0.2.2/src/opik/rest_api/spans/client.py +1283 -0
  155. opik-0.2.2/src/opik/rest_api/spans/types/__init__.py +5 -0
  156. opik-0.2.2/src/opik/rest_api/spans/types/get_spans_by_project_request_type.py +7 -0
  157. opik-0.2.2/src/opik/rest_api/system_usage/__init__.py +1 -0
  158. opik-0.2.2/src/opik/rest_api/system_usage/client.py +100 -0
  159. opik-0.2.2/src/opik/rest_api/traces/__init__.py +1 -0
  160. opik-0.2.2/src/opik/rest_api/traces/client.py +1269 -0
  161. opik-0.2.2/src/opik/rest_api/types/__init__.py +191 -0
  162. opik-0.2.2/src/opik/rest_api/types/categorical_feedback_definition.py +47 -0
  163. opik-0.2.2/src/opik/rest_api/types/categorical_feedback_definition_create.py +43 -0
  164. opik-0.2.2/src/opik/rest_api/types/categorical_feedback_definition_public.py +47 -0
  165. opik-0.2.2/src/opik/rest_api/types/categorical_feedback_definition_update.py +43 -0
  166. opik-0.2.2/src/opik/rest_api/types/categorical_feedback_detail.py +42 -0
  167. opik-0.2.2/src/opik/rest_api/types/categorical_feedback_detail_create.py +42 -0
  168. opik-0.2.2/src/opik/rest_api/types/categorical_feedback_detail_public.py +42 -0
  169. opik-0.2.2/src/opik/rest_api/types/categorical_feedback_detail_update.py +42 -0
  170. opik-0.2.2/src/opik/rest_api/types/chunked_output_json_node.py +44 -0
  171. opik-0.2.2/src/opik/rest_api/types/chunked_output_json_node_type.py +44 -0
  172. opik-0.2.2/src/opik/rest_api/types/dataset.py +50 -0
  173. opik-0.2.2/src/opik/rest_api/types/dataset_item.py +56 -0
  174. opik-0.2.2/src/opik/rest_api/types/dataset_item_batch.py +53 -0
  175. opik-0.2.2/src/opik/rest_api/types/dataset_item_compare.py +56 -0
  176. opik-0.2.2/src/opik/rest_api/types/dataset_item_compare_source.py +7 -0
  177. opik-0.2.2/src/opik/rest_api/types/dataset_item_page_compare.py +46 -0
  178. opik-0.2.2/src/opik/rest_api/types/dataset_item_page_public.py +46 -0
  179. opik-0.2.2/src/opik/rest_api/types/dataset_item_public.py +56 -0
  180. opik-0.2.2/src/opik/rest_api/types/dataset_item_public_source.py +7 -0
  181. opik-0.2.2/src/opik/rest_api/types/dataset_item_source.py +7 -0
  182. opik-0.2.2/src/opik/rest_api/types/dataset_item_write.py +50 -0
  183. opik-0.2.2/src/opik/rest_api/types/dataset_item_write_source.py +7 -0
  184. opik-0.2.2/src/opik/rest_api/types/dataset_page_public.py +46 -0
  185. opik-0.2.2/src/opik/rest_api/types/dataset_public.py +50 -0
  186. opik-0.2.2/src/opik/rest_api/types/delete_feedback_score.py +42 -0
  187. opik-0.2.2/src/opik/rest_api/types/error_message.py +42 -0
  188. opik-0.2.2/src/opik/rest_api/types/error_message_public.py +44 -0
  189. opik-0.2.2/src/opik/rest_api/types/experiment.py +54 -0
  190. opik-0.2.2/src/opik/rest_api/types/experiment_item.py +54 -0
  191. opik-0.2.2/src/opik/rest_api/types/experiment_item_compare.py +54 -0
  192. opik-0.2.2/src/opik/rest_api/types/experiment_item_public.py +49 -0
  193. opik-0.2.2/src/opik/rest_api/types/experiment_page_public.py +46 -0
  194. opik-0.2.2/src/opik/rest_api/types/experiment_public.py +54 -0
  195. opik-0.2.2/src/opik/rest_api/types/feedback.py +149 -0
  196. opik-0.2.2/src/opik/rest_api/types/feedback_create.py +127 -0
  197. opik-0.2.2/src/opik/rest_api/types/feedback_definition_page_public.py +46 -0
  198. opik-0.2.2/src/opik/rest_api/types/feedback_object_public.py +151 -0
  199. opik-0.2.2/src/opik/rest_api/types/feedback_public.py +149 -0
  200. opik-0.2.2/src/opik/rest_api/types/feedback_score.py +51 -0
  201. opik-0.2.2/src/opik/rest_api/types/feedback_score_average.py +43 -0
  202. opik-0.2.2/src/opik/rest_api/types/feedback_score_average_public.py +43 -0
  203. opik-0.2.2/src/opik/rest_api/types/feedback_score_batch.py +43 -0
  204. opik-0.2.2/src/opik/rest_api/types/feedback_score_batch_item.py +53 -0
  205. opik-0.2.2/src/opik/rest_api/types/feedback_score_batch_item_source.py +5 -0
  206. opik-0.2.2/src/opik/rest_api/types/feedback_score_compare.py +51 -0
  207. opik-0.2.2/src/opik/rest_api/types/feedback_score_compare_source.py +5 -0
  208. opik-0.2.2/src/opik/rest_api/types/feedback_score_public.py +51 -0
  209. opik-0.2.2/src/opik/rest_api/types/feedback_score_public_source.py +5 -0
  210. opik-0.2.2/src/opik/rest_api/types/feedback_score_source.py +5 -0
  211. opik-0.2.2/src/opik/rest_api/types/feedback_update.py +127 -0
  212. opik-0.2.2/src/opik/rest_api/types/json_node.py +5 -0
  213. opik-0.2.2/src/opik/rest_api/types/json_node_compare.py +5 -0
  214. opik-0.2.2/src/opik/rest_api/types/json_node_public.py +5 -0
  215. opik-0.2.2/src/opik/rest_api/types/json_node_write.py +5 -0
  216. opik-0.2.2/src/opik/rest_api/types/numerical_feedback_definition.py +47 -0
  217. opik-0.2.2/src/opik/rest_api/types/numerical_feedback_definition_create.py +43 -0
  218. opik-0.2.2/src/opik/rest_api/types/numerical_feedback_definition_public.py +47 -0
  219. opik-0.2.2/src/opik/rest_api/types/numerical_feedback_definition_update.py +43 -0
  220. opik-0.2.2/src/opik/rest_api/types/numerical_feedback_detail.py +43 -0
  221. opik-0.2.2/src/opik/rest_api/types/numerical_feedback_detail_create.py +43 -0
  222. opik-0.2.2/src/opik/rest_api/types/numerical_feedback_detail_public.py +43 -0
  223. opik-0.2.2/src/opik/rest_api/types/numerical_feedback_detail_update.py +43 -0
  224. opik-0.2.2/src/opik/rest_api/types/project.py +48 -0
  225. opik-0.2.2/src/opik/rest_api/types/project_page_public.py +46 -0
  226. opik-0.2.2/src/opik/rest_api/types/project_public.py +48 -0
  227. opik-0.2.2/src/opik/rest_api/types/span.py +67 -0
  228. opik-0.2.2/src/opik/rest_api/types/span_batch.py +43 -0
  229. opik-0.2.2/src/opik/rest_api/types/span_page_public.py +46 -0
  230. opik-0.2.2/src/opik/rest_api/types/span_public.py +62 -0
  231. opik-0.2.2/src/opik/rest_api/types/span_public_type.py +5 -0
  232. opik-0.2.2/src/opik/rest_api/types/span_type.py +5 -0
  233. opik-0.2.2/src/opik/rest_api/types/span_write.py +60 -0
  234. opik-0.2.2/src/opik/rest_api/types/span_write_type.py +5 -0
  235. opik-0.2.2/src/opik/rest_api/types/trace.py +62 -0
  236. opik-0.2.2/src/opik/rest_api/types/trace_batch.py +43 -0
  237. opik-0.2.2/src/opik/rest_api/types/trace_count_response.py +43 -0
  238. opik-0.2.2/src/opik/rest_api/types/trace_page_public.py +46 -0
  239. opik-0.2.2/src/opik/rest_api/types/trace_public.py +57 -0
  240. opik-0.2.2/src/opik/rest_api/types/trace_write.py +55 -0
  241. opik-0.2.2/src/opik/rest_api/types/workspace_trace_count.py +43 -0
  242. opik-0.2.2/src/opik/synchronization.py +66 -0
  243. opik-0.2.2/src/opik/types.py +63 -0
  244. opik-0.2.2/src/opik/url_helpers.py +28 -0
  245. opik-0.2.2/src/opik/validation/__init__.py +0 -0
  246. opik-0.2.2/src/opik/validation/feedback_score.py +47 -0
  247. opik-0.2.2/src/opik/validation/result.py +28 -0
  248. opik-0.2.2/src/opik/validation/usage.py +79 -0
  249. opik-0.2.2/src/opik/validation/validator.py +9 -0
  250. opik-0.2.2/src/opik.egg-info/PKG-INFO +230 -0
  251. opik-0.2.2/src/opik.egg-info/SOURCES.txt +254 -0
  252. opik-0.2.2/src/opik.egg-info/dependency_links.txt +1 -0
  253. opik-0.2.2/src/opik.egg-info/entry_points.txt +5 -0
  254. opik-0.2.2/src/opik.egg-info/not-zip-safe +1 -0
  255. opik-0.2.2/src/opik.egg-info/requires.txt +14 -0
  256. opik-0.2.2/src/opik.egg-info/top_level.txt +1 -0
opik-0.2.2/PKG-INFO ADDED
@@ -0,0 +1,230 @@
1
+ Metadata-Version: 2.1
2
+ Name: opik
3
+ Version: 0.2.2
4
+ Summary: Comet tool for logging and evaluating LLM traces
5
+ Home-page: https://www.comet.com
6
+ Author: Comet ML Inc.
7
+ Author-email: mail@comet.com
8
+ License: Apache 2.0 License
9
+ Project-URL: Source code, https://github.com/comet-ml/opik
10
+ Keywords: opik
11
+ Classifier: Development Status :: 2 - Pre-Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Natural Language :: English
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Requires-Python: >=3.8
23
+ Description-Content-Type: text/markdown
24
+ Requires-Dist: click
25
+ Requires-Dist: httpx<1.0.0
26
+ Requires-Dist: langchain_community<1.0.0
27
+ Requires-Dist: langchain_openai<1.0.0
28
+ Requires-Dist: levenshtein~=0.25.1
29
+ Requires-Dist: openai<2.0.0
30
+ Requires-Dist: pandas<3.0.0,>=2.0.0
31
+ Requires-Dist: pydantic-settings<3.0.0,>=2.0.0
32
+ Requires-Dist: pydantic<3.0.0,>=2.0.0
33
+ Requires-Dist: pytest
34
+ Requires-Dist: rich
35
+ Requires-Dist: tqdm
36
+ Requires-Dist: questionary
37
+ Requires-Dist: uuid7<1.0.0
38
+
39
+ <h1 align="center" style="border-bottom: none">
40
+ <div>
41
+ <a href="https://www.comet.com/site/products/opik?from=llm&utm_source=opik&utm_medium=github&utm_content=header_img&utm_campaign=opik"><picture>
42
+ <source media="(prefers-color-scheme: dark)" srcset="/apps/opik-documentation/documentation/static/img/logo-dark-mode.svg">
43
+ <source media="(prefers-color-scheme: light)" srcset="/apps/opik-documentation/documentation/static/img/opik-logo.svg">
44
+ <img alt="Comet Opik logo" src="/apps/opik-documentation/documentation/static/img/opik-logo.svg" width="200" />
45
+ </picture></a>
46
+ <br>
47
+ Opik
48
+ </div>
49
+ Open-source end-to-end LLM Development Platform<br>
50
+ </h1>
51
+
52
+ <p align="center">
53
+ Confidently evaluate, test and monitor LLM applications. 
54
+ </p>
55
+
56
+ <div align="center">
57
+
58
+ [![Python SDK](https://img.shields.io/pypi/v/opik)](https://pypi.org/project/opik/)
59
+ [![License](https://img.shields.io/github/license/comet-ml/opik)](https://github.com/comet-ml/opik/blob/main/LICENSE)
60
+ [![Build](https://github.com/comet-ml/opik/actions/workflows/build_apps.yml/badge.svg)](https://github.com/comet-ml/opik/actions/workflows/build_apps.yml)
61
+ <a target="_blank" href="https://colab.research.google.com/github/comet-ml/opik/blob/master/apps/opik-documentation/documentation/docs/cookbook/opik_quickstart.ipynb">
62
+ <!-- <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open Quickstart In Colab"/> -->
63
+ </a>
64
+
65
+ </div>
66
+
67
+ <p align="center">
68
+ <a href="https://www.comet.com/site/products/opik?from=llm&utm_source=opik&utm_medium=github&utm_content=website_button&utm_campaign=opik"><b>Website</b></a> •
69
+ <a href="https://chat.comet.com"><b>Slack community</b></a> •
70
+ <a href="https://x.com/Cometml"><b>Twitter</b></a> •
71
+ <a href="https://www.comet.com/docs/opik/?from=llm&utm_source=opik&utm_medium=github&utm_content=docs_button&utm_campaign=opik"><b>Documentation</b></a>
72
+ </p>
73
+
74
+ ![Opik thumbnail](readme-thumbnail.png)
75
+
76
+ ## 🚀 What is Opik?
77
+
78
+ Opik is an open-source platform for evaluating, testing and monitoring LLM applications. Built by [Comet](https://www.comet.com?from=llm&utm_source=opik&utm_medium=github&utm_content=what_is_opik_link&utm_campaign=opik).
79
+
80
+ <br>
81
+
82
+ You can use Opik for:
83
+ * **Development:**
84
+ * **Tracing:** Track all LLM calls and traces during development and production ([Quickstart](https://www.comet.com/docs/opik/quickstart/?from=llm&utm_source=opik&utm_medium=github&utm_content=quickstart_link&utm_campaign=opik), [Integrations](https://www.comet.com/docs/opik/tracing/integrations/overview/?from=llm&utm_source=opik&utm_medium=github&utm_content=integrations_link&utm_campaign=opik)
85
+ * **Annotations:** Annotate your LLM calls by logging feedback scores using the [Python SDK](https://www.comet.com/docs/opik/tracing/annotate_traces/#annotating-traces-and-spans-using-the-sdk?from=llm&utm_source=opik&utm_medium=github&utm_content=sdk_link&utm_campaign=opik) or the [UI](https://www.comet.com/docs/opik/tracing/annotate_traces/#annotating-traces-through-the-ui?from=llm&utm_source=opik&utm_medium=github&utm_content=ui_link&utm_campaign=opik).
86
+
87
+ * **Evaluation**: Automate the evaluation process of your LLM application:
88
+
89
+ * **Datasets and Experiments**: Store test cases and run experiments ([Datasets](https://www.comet.com/docs/opik/evaluation/manage_datasets/?from=llm&utm_source=opik&utm_medium=github&utm_content=datasets_link&utm_campaign=opik), [Evaluate your LLM Application](https://www.comet.com/docs/opik/evaluation/evaluate_your_llm/?from=llm&utm_source=opik&utm_medium=github&utm_content=eval_link&utm_campaign=opik))
90
+
91
+ * **LLM as a judge metrics**: Use Opik's LLM as a judge metric for complex issues like [hallucination detection](https://www.comet.com/docs/opik/evaluation/metrics/hallucination/?from=llm&utm_source=opik&utm_medium=github&utm_content=hallucination_link&utm_campaign=opik), [moderation](https://www.comet.com/docs/opik/evaluation/metrics/moderation/?from=llm&utm_source=opik&utm_medium=github&utm_content=moderation_link&utm_campaign=opik) and RAG evaluation ([Answer Relevance](https://www.comet.com/docs/opik/evaluation/metrics/answer_relevance/?from=llm&utm_source=opik&utm_medium=github&utm_content=alex_link&utm_campaign=opik), [Context Precision](https://www.comet.com/docs/opik/evaluation/metrics/context_precision/?from=llm&utm_source=opik&utm_medium=github&utm_content=context_link&utm_campaign=opik)
92
+
93
+ * **CI/CD integration**: Run evaluations as part of your CI/CD pipeline using our [PyTest integration](https://www.comet.com/docs/opik/testing/pytest_integration/?from=llm&utm_source=opik&utm_medium=github&utm_content=pytest_link&utm_campaign=opik)
94
+
95
+ * **Production Monitoring**: Monitor your LLM application in production and easily close the feedback loop by adding error traces to your evaluation datasets.
96
+
97
+ <br>
98
+
99
+ ## 🛠️ Installation
100
+ Opik is available as a fully open source local installation or using Comet.com as a hosted solution.
101
+ The easiest way to get started with Opik is by creating a free Comet account at [comet.com](https://www.comet.com/signup?from=llm&utm_source=opik&utm_medium=github&utm_content=install&utm_campaign=opik).
102
+
103
+ If you'd like to self-host Opik, you can do so by cloning the repository and starting the platform using Docker Compose:
104
+
105
+ ```bash
106
+ # Clone the Opik repository
107
+ git clone https://github.com/comet-ml/opik.git
108
+
109
+ # Navigate to the opik/deployment/docker-compose directory
110
+ cd opik/deployment/docker-compose
111
+
112
+ # Start the Opik platform
113
+ docker compose up --detach
114
+
115
+ # You can now visit http://localhost:5173 on your browser!
116
+ ```
117
+
118
+ Opik reports *anonymous* usage reports to the Opik team to help with the development of new features. No private information is collected, there reports are fully anonymous.
119
+
120
+ You can opt-out of usage reporting by setting the `OPIK_USAGE_REPORT_ENABLED` environment variable to `false` before running Opik locally:
121
+
122
+ ```bash
123
+ # Start the Opik platform
124
+ export OPIK_USAGE_REPORT_ENABLED=false
125
+
126
+ docker compose up --detach
127
+ ```
128
+ All usage reports can be found here: [Usage Reports](https://github.com/comet-ml/opik/blob/main/apps/opik-backend/src/main/java/com/comet/opik/infrastructure/bi/InstallationReportService.java#L101)
129
+
130
+ For more information about the different deployment options, please see our deployment guides:
131
+
132
+ | Installation methods | Docs link |
133
+ | ------------------- | --------- |
134
+ | Local instance | [![Local Deployment](https://img.shields.io/badge/Local%20Deployments-%232496ED?style=flat&logo=docker&logoColor=white)](https://www.comet.com/docs/opik/self-host/local_deployment?from=llm&utm_source=opik&utm_medium=github&utm_content=self_host_link&utm_campaign=opik)
135
+ | Kubernetes | [![Kubernetes](https://img.shields.io/badge/Kubernetes-%23326ce5.svg?&logo=kubernetes&logoColor=white)](https://www.comet.com/docs/opik/self-host/kubernetes/#kubernetes-installation?from=llm&utm_source=opik&utm_medium=github&utm_content=kubernetes_link&utm_campaign=opik)
136
+
137
+
138
+ ## 🏁 Get Started
139
+
140
+ To get started, you will need to first install the Python SDK:
141
+
142
+ ```bash
143
+ pip install opik
144
+ ```
145
+
146
+ Once the SDK is installed, you can configure it by running the `opik configure` command:
147
+
148
+ ```bash
149
+ opik configure
150
+ ```
151
+ This will allow you to configure Opik locally by setting the correct local server address or if you're using the Cloud platform by setting the API Key
152
+
153
+
154
+ > [!TIP]
155
+ > You can also call the `opik.configure(use_local=True)` method from your Python code to configure the SDK to run on the local installation.
156
+
157
+
158
+ You are now ready to start logging traces using the [Python SDK](https://www.comet.com/docs/opik/python-sdk-reference/?from=llm&utm_source=opik&utm_medium=github&utm_content=sdk_link2&utm_campaign=opik).
159
+
160
+ ### 📝 Logging Traces
161
+
162
+ The easiest way to get started is to use one of our integrations. Opik supports:
163
+
164
+ | Integration | Description | Documentation | Try in Colab |
165
+ | ----------- | ----------- | ------------- | ------------ |
166
+ | OpenAI | Log traces for all OpenAI LLM calls | [Documentation](https://www.comet.com/docs/opik/tracing/integrations/openai/?utm_source=opik&utm_medium=github&utm_content=openai_link&utm_campaign=opik) | [![Open Quickstart In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/comet-ml/opik/blob/master/apps/opik-documentation/documentation/docs/cookbook/openai.ipynb) |
167
+ | LiteLLM | Call any LLM model using the OpenAI format | [Documentation](/tracing/integrations/litellm.md) | [![Open Quickstart In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/comet-ml/opik/blob/master/apps/opik-documentation/documentation/docs/cookbook/litellm.ipynb) |
168
+ | LangChain | Log traces for all LangChain LLM calls | [Documentation](https://www.comet.com/docs/opik/tracing/integrations/langchain/?utm_source=opik&utm_medium=github&utm_content=langchain_link&utm_campaign=opik) | [![Open Quickstart In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/comet-ml/opik/blob/master/apps/opik-documentation/documentation/docs/cookbook/langchain.ipynb) |
169
+ | LangGraph | Log traces for all LangGraph executions | [Documentation](https://www.comet.com/docs/opik/tracing/integrations/langgraph/?utm_source=opik&utm_medium=github&utm_content=langchain_link&utm_campaign=opik) | [![Open Quickstart In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/comet-ml/opik/blob/master/apps/opik-documentation/documentation/docs/cookbook/langgraph.ipynb) |
170
+ | LlamaIndex | Log traces for all LlamaIndex LLM calls | [Documentation](https://www.comet.com/docs/opik/tracing/integrations/llama_index?utm_source=opik&utm_medium=github&utm_content=llama_index_link&utm_campaign=opik) | [![Open Quickstart In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/comet-ml/opik/blob/master/apps/opik-documentation/documentation/docs/cookbook/llama-index.ipynb) |
171
+ | Ollama | Log traces for all Ollama LLM calls | [Documentation](https://www.comet.com/docs/opik/tracing/integrations/ollama?utm_source=opik&utm_medium=github&utm_content=ollama_link&utm_campaign=opik) | [![Open Quickstart In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/comet-ml/opik/blob/master/apps/opik-documentation/documentation/docs/cookbook/ollama.ipynb) |
172
+ | Predibase | Fine-tune and serve open-source Large Language Models | [Documentation](https://www.comet.com/docs/opik/tracing/integrations/predibase?utm_source=opik&utm_medium=github&utm_content=predibase_link&utm_campaign=opik) | [![Open Quickstart In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/comet-ml/opik/blob/master/apps/opik-documentation/documentation/docs/cookbook/predibase.ipynb) |
173
+ | Ragas | Evaluation framework for your Retrieval Augmented Generation (RAG) pipelines | [Documentation](https://www.comet.com/docs/opik/tracing/integrations/ragas?utm_source=opik&utm_medium=github&utm_content=ragas_link&utm_campaign=opik) | [![Open Quickstart In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/comet-ml/opik/blob/master/apps/opik-documentation/documentation/docs/cookbook/ragas.ipynb) |
174
+
175
+ > [!TIP]
176
+ > If the framework you are using is not listed above, feel free to [open an issue](https://github.com/comet-ml/opik/issues) or submit a PR with the integration.
177
+
178
+ If you are not using any of the frameworks above, you can also using the `track` function decorator to [log traces](https://www.comet.com/docs/opik/tracing/log_traces/?from=llm&utm_source=opik&utm_medium=github&utm_content=traces_link&utm_campaign=opik):
179
+
180
+ ```python
181
+ import opik
182
+
183
+ opik.configure(use_local=True) # Run locally
184
+
185
+ @opik.track
186
+ def my_llm_function(user_question: str) -> str:
187
+ # Your LLM code here
188
+
189
+ return "Hello"
190
+ ```
191
+
192
+ > [!TIP]
193
+ > The track decorator can be used in conjunction with any of our integrations and can also be used to track nested function calls.
194
+
195
+ ### 🧑‍⚖️ LLM as a Judge metrics
196
+
197
+ The Python Opik SDK includes a number of LLM as a judge metrics to help you evaluate your LLM application. Learn more about it in the [metrics documentation](https://www.comet.com/docs/opik/evaluation/metrics/overview/?from=llm&utm_source=opik&utm_medium=github&utm_content=metrics_2_link&utm_campaign=opik).
198
+
199
+ To use them, simply import the relevant metric and use the `score` function:
200
+
201
+ ```python
202
+ from opik.evaluation.metrics import Hallucination
203
+
204
+ metric = Hallucination()
205
+ score = metric.score(
206
+ input="What is the capital of France?",
207
+ output="Paris",
208
+ context=["France is a country in Europe."]
209
+ )
210
+ print(score)
211
+ ```
212
+
213
+ Opik also includes a number of pre-built heuristic metrics as well as the ability to create your own. Learn more about it in the [metrics documentation](https://www.comet.com/docs/opik/evaluation/metrics/overview?from=llm&utm_source=opik&utm_medium=github&utm_content=metrics_3_link&utm_campaign=opik).
214
+
215
+ ### 🔍 Evaluating your LLM Application
216
+
217
+ Opik allows you to evaluate your LLM application during development through [Datasets](https://www.comet.com/docs/opik/evaluation/manage_datasets/?from=llm&utm_source=opik&utm_medium=github&utm_content=datasets_2_link&utm_campaign=opik) and [Experiments](https://www.comet.com/docs/opik/evaluation/evaluate_your_llm/?from=llm&utm_source=opik&utm_medium=github&utm_content=experiments_link&utm_campaign=opik).
218
+
219
+ You can also run evaluations as part of your CI/CD pipeline using our [PyTest integration](https://www.comet.com/docs/opik/testing/pytest_integration/?from=llm&utm_source=opik&utm_medium=github&utm_content=pytest_2_link&utm_campaign=opik).
220
+
221
+ ## 🤝 Contributing
222
+
223
+ There are many ways to contribute to Opik:
224
+
225
+ * Submit [bug reports](https://github.com/comet-ml/opik/issues) and [feature requests](https://github.com/comet-ml/opik/issues)
226
+ * Review the documentation and submit [Pull Requests](https://github.com/comet-ml/opik/pulls) to improve it
227
+ * Speaking or writing about Opik and [letting us know](https://chat.comet.com)
228
+ * Upvoting [popular feature requests](https://github.com/comet-ml/opik/issues?q=is%3Aissue+is%3Aopen+label%3A%22enhancement%22) to show your support
229
+
230
+ To learn more about how to contribute to Opik, please see our [contributing guidelines](CONTRIBUTING.md).
opik-0.2.2/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Opik Python SDK
2
+
3
+ If you would like to contribute to the Opik python SDK, please refer to the [Contribution guide](./CONTRIBUTING.md).
@@ -0,0 +1,6 @@
1
+ [tool.mypy]
2
+ follow_imports = "skip"
3
+ ignore_missing_imports = true
4
+ disallow_untyped_defs = true
5
+ disallow_untyped_calls = true
6
+ check_untyped_defs = true
opik-0.2.2/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
opik-0.2.2/setup.py ADDED
@@ -0,0 +1,70 @@
1
+ from setuptools import find_packages, setup
2
+ import os
3
+
4
+ project_urls = {"Source code": "https://github.com/comet-ml/opik"}
5
+
6
+ HERE = os.path.abspath(os.path.dirname(__file__))
7
+ version = os.environ.get("VERSION")
8
+ if version is None:
9
+ version_file = os.path.join(HERE, "..", "..", "version.txt")
10
+ if os.path.exists(version_file):
11
+ with open(version_file) as fp:
12
+ version = fp.read().strip()
13
+ else:
14
+ version = "0.0.1"
15
+
16
+ setup(
17
+ author="Comet ML Inc.",
18
+ author_email="mail@comet.com",
19
+ python_requires=">=3.8",
20
+ classifiers=[
21
+ "Development Status :: 2 - Pre-Alpha",
22
+ "Intended Audience :: Developers",
23
+ "License :: OSI Approved :: Apache Software License",
24
+ "Natural Language :: English",
25
+ "Programming Language :: Python :: 3 :: Only",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3.8",
28
+ "Programming Language :: Python :: 3.9",
29
+ "Programming Language :: Python :: 3.10",
30
+ "Programming Language :: Python :: 3.11",
31
+ "Programming Language :: Python :: 3.12",
32
+ ],
33
+ description="Comet tool for logging and evaluating LLM traces",
34
+ long_description=open(
35
+ os.path.join(HERE, "..", "..", "README.md"), encoding="utf-8"
36
+ ).read(),
37
+ long_description_content_type="text/markdown",
38
+ install_requires=[
39
+ "click",
40
+ "httpx<1.0.0",
41
+ "langchain_community<1.0.0",
42
+ "langchain_openai<1.0.0",
43
+ "levenshtein~=0.25.1",
44
+ "openai<2.0.0",
45
+ "pandas>=2.0.0,<3.0.0",
46
+ "pydantic-settings>=2.0.0,<3.0.0",
47
+ "pydantic>=2.0.0,<3.0.0",
48
+ "pytest",
49
+ "rich",
50
+ "tqdm",
51
+ "questionary",
52
+ "uuid7<1.0.0",
53
+ ],
54
+ entry_points={
55
+ "pytest11": [
56
+ "opik = opik.plugins.pytest.hooks",
57
+ ],
58
+ "console_scripts": ["opik = opik.cli:cli"],
59
+ },
60
+ include_package_data=True,
61
+ keywords="opik",
62
+ name="opik",
63
+ packages=find_packages("src"),
64
+ package_dir={"": "src"},
65
+ url="https://www.comet.com",
66
+ project_urls=project_urls,
67
+ version=version,
68
+ zip_safe=False,
69
+ license="Apache 2.0 License",
70
+ )
@@ -0,0 +1,28 @@
1
+ from .decorator.tracker import track, flush_tracker
2
+ from .api_objects.opik_client import Opik
3
+ from .api_objects.trace import Trace
4
+ from .api_objects.span import Span
5
+ from .api_objects.dataset.dataset_item import DatasetItem
6
+ from .api_objects.dataset import Dataset
7
+ from . import _logging
8
+ from .configurator.configure import configure
9
+ from . import package_version
10
+ from .plugins.pytest.decorator import llm_unit
11
+ from .evaluation import evaluate
12
+
13
+ _logging.setup()
14
+
15
+ __version__ = package_version.VERSION
16
+ __all__ = [
17
+ "__version__",
18
+ "evaluate",
19
+ "track",
20
+ "flush_tracker",
21
+ "Opik",
22
+ "Trace",
23
+ "Span",
24
+ "DatasetItem",
25
+ "Dataset",
26
+ "llm_unit",
27
+ "configure",
28
+ ]
@@ -0,0 +1,58 @@
1
+ from typing import Callable, Any
2
+ import functools
3
+ import logging
4
+
5
+
6
+ from . import config
7
+
8
+ CONSOLE_MSG_FORMAT = "OPIK: %(message)s"
9
+
10
+ FILE_MSG_FORMAT = "%(asctime)s OPIK %(levelname)s: %(message)s"
11
+
12
+
13
+ def setup() -> None:
14
+ opik_root_logger = logging.getLogger("opik")
15
+ opik_root_logger.propagate = False
16
+
17
+ config_ = config.OpikConfig()
18
+
19
+ console_handler = logging.StreamHandler()
20
+ console_level = config_.console_logging_level
21
+ console_handler.setLevel(console_level)
22
+ console_handler.setFormatter(logging.Formatter(CONSOLE_MSG_FORMAT))
23
+
24
+ opik_root_logger.addHandler(console_handler)
25
+
26
+ root_level = console_handler.level
27
+
28
+ if config_.file_logging_level is not None:
29
+ file_handler = logging.FileHandler(config_.logging_file)
30
+ file_level = config_.file_logging_level
31
+ file_handler.setLevel(file_level)
32
+ file_handler.setFormatter(logging.Formatter(FILE_MSG_FORMAT))
33
+ opik_root_logger.addHandler(file_handler)
34
+
35
+ root_level = min(root_level, file_handler.level)
36
+
37
+ opik_root_logger.setLevel(level=root_level)
38
+
39
+
40
+ def convert_exception_to_log_message(
41
+ message: str,
42
+ logger: logging.Logger,
43
+ return_on_exception: Any = None,
44
+ logging_level: int = logging.ERROR,
45
+ **log_kwargs: Any,
46
+ ) -> Callable:
47
+ def decorator(function: Callable) -> Any:
48
+ @functools.wraps(function)
49
+ def wrapper(*args: Any, **kwargs: Any) -> Any:
50
+ try:
51
+ return function(*args, **kwargs)
52
+ except Exception:
53
+ logger.log(logging_level, message, **log_kwargs)
54
+ return return_on_exception
55
+
56
+ return wrapper
57
+
58
+ return decorator
File without changes
@@ -0,0 +1,6 @@
1
+ FEEDBACK_SCORE_SOURCE_SDK = "sdk"
2
+ DATASET_SOURCE_SDK = "sdk"
3
+
4
+ FEEDBACK_SCORES_MAX_BATCH_SIZE = 1000
5
+ EXPERIMENT_ITEMS_MAX_BATCH_SIZE = 1000
6
+ DATASET_ITEMS_MAX_BATCH_SIZE = 1000
@@ -0,0 +1,4 @@
1
+ from .dataset import Dataset
2
+
3
+
4
+ __all__ = ["Dataset"]
@@ -0,0 +1,85 @@
1
+ import pandas as pd
2
+ import json
3
+
4
+ from typing import List, Callable, Any, Dict
5
+
6
+ from . import dataset_item
7
+
8
+ ItemConstructor = Callable[[Any], dataset_item.DatasetItem]
9
+
10
+
11
+ def to_pandas(
12
+ items: List[dataset_item.DatasetItem], keys_mapping: Dict[str, str]
13
+ ) -> pd.DataFrame:
14
+ new_item_dicts = []
15
+
16
+ for item in items:
17
+ new_item_dict = {
18
+ keys_mapping.get(key, key): value for key, value in item.__dict__.items()
19
+ }
20
+ new_item_dicts.append(new_item_dict)
21
+
22
+ return pd.DataFrame(new_item_dicts)
23
+
24
+
25
+ def from_jsonl_file(
26
+ file_path: str, keys_mapping: Dict[str, str], ignore_keys: List[str]
27
+ ) -> List[dataset_item.DatasetItem]:
28
+ items = []
29
+ with open(file_path, "r", encoding="utf-8") as file:
30
+ for line in file:
31
+ json_object = line.strip()
32
+ if json_object: # Skip empty lines
33
+ items.append(json.loads(json_object))
34
+
35
+ json_str = json.dumps(items)
36
+ return from_json(json_str, keys_mapping, ignore_keys)
37
+
38
+
39
+ def from_pandas(
40
+ dataframe: pd.DataFrame,
41
+ keys_mapping: Dict[str, str],
42
+ ignore_keys: List[str],
43
+ ) -> List[dataset_item.DatasetItem]:
44
+ result = []
45
+ ignore_keys = [] if ignore_keys is None else ignore_keys
46
+ for _, row in dataframe.iterrows():
47
+ item_kwargs = {
48
+ keys_mapping.get(key, key): value
49
+ for key, value in row.items()
50
+ if key not in ignore_keys
51
+ }
52
+ result.append(dataset_item.DatasetItem(**item_kwargs))
53
+
54
+ return result
55
+
56
+
57
+ def to_json(items: List[dataset_item.DatasetItem], keys_mapping: Dict[str, str]) -> str:
58
+ new_item_dicts = []
59
+
60
+ for item in items:
61
+ item_dict = item.__dict__
62
+ new_item_dict = {
63
+ keys_mapping.get(key, key): value for key, value in item_dict.items()
64
+ }
65
+ new_item_dicts.append(new_item_dict)
66
+
67
+ result: str = json.dumps(new_item_dicts, indent=2)
68
+ return result
69
+
70
+
71
+ def from_json(
72
+ value: str, keys_mapping: Dict[str, str], ignore_keys: List[str]
73
+ ) -> List[dataset_item.DatasetItem]:
74
+ result = []
75
+ item_dicts: List[Dict[str, Any]] = json.loads(value)
76
+
77
+ for item_dict in item_dicts:
78
+ item_kwargs = {
79
+ keys_mapping.get(key, key): value
80
+ for key, value in item_dict.items()
81
+ if key not in ignore_keys
82
+ }
83
+ result.append(dataset_item.DatasetItem(**item_kwargs))
84
+
85
+ return result