ibm-watsonx-gov 1.3.3__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (353) hide show
  1. ibm_watsonx_gov/__init__.py +8 -0
  2. ibm_watsonx_gov/agent_catalog/__init__.py +8 -0
  3. ibm_watsonx_gov/agent_catalog/clients/__init__.py +14 -0
  4. ibm_watsonx_gov/agent_catalog/clients/ai_agent_client.py +333 -0
  5. ibm_watsonx_gov/agent_catalog/core/__init__.py +8 -0
  6. ibm_watsonx_gov/agent_catalog/core/agent_loader.py +202 -0
  7. ibm_watsonx_gov/agent_catalog/core/agents.py +134 -0
  8. ibm_watsonx_gov/agent_catalog/entities/__init__.py +8 -0
  9. ibm_watsonx_gov/agent_catalog/entities/ai_agent.py +599 -0
  10. ibm_watsonx_gov/agent_catalog/utils/__init__.py +8 -0
  11. ibm_watsonx_gov/agent_catalog/utils/constants.py +36 -0
  12. ibm_watsonx_gov/agent_catalog/utils/notebook_utils.py +70 -0
  13. ibm_watsonx_gov/ai_experiments/__init__.py +8 -0
  14. ibm_watsonx_gov/ai_experiments/ai_experiments_client.py +980 -0
  15. ibm_watsonx_gov/ai_experiments/utils/__init__.py +8 -0
  16. ibm_watsonx_gov/ai_experiments/utils/ai_experiment_utils.py +139 -0
  17. ibm_watsonx_gov/clients/__init__.py +0 -0
  18. ibm_watsonx_gov/clients/api_client.py +99 -0
  19. ibm_watsonx_gov/clients/segment_client.py +46 -0
  20. ibm_watsonx_gov/clients/usage_client.cp313-win_amd64.pyd +0 -0
  21. ibm_watsonx_gov/clients/wx_ai_client.py +87 -0
  22. ibm_watsonx_gov/config/__init__.py +14 -0
  23. ibm_watsonx_gov/config/agentic_ai_configuration.py +225 -0
  24. ibm_watsonx_gov/config/gen_ai_configuration.py +129 -0
  25. ibm_watsonx_gov/config/model_risk_configuration.py +173 -0
  26. ibm_watsonx_gov/config/predictive_ai_configuration.py +20 -0
  27. ibm_watsonx_gov/entities/__init__.py +8 -0
  28. ibm_watsonx_gov/entities/agentic_app.py +209 -0
  29. ibm_watsonx_gov/entities/agentic_evaluation_result.py +185 -0
  30. ibm_watsonx_gov/entities/ai_evaluation.py +290 -0
  31. ibm_watsonx_gov/entities/ai_experiment.py +419 -0
  32. ibm_watsonx_gov/entities/base_classes.py +134 -0
  33. ibm_watsonx_gov/entities/container.py +54 -0
  34. ibm_watsonx_gov/entities/credentials.py +633 -0
  35. ibm_watsonx_gov/entities/criteria.py +508 -0
  36. ibm_watsonx_gov/entities/enums.py +274 -0
  37. ibm_watsonx_gov/entities/evaluation_result.py +444 -0
  38. ibm_watsonx_gov/entities/foundation_model.py +490 -0
  39. ibm_watsonx_gov/entities/llm_judge.py +44 -0
  40. ibm_watsonx_gov/entities/locale.py +17 -0
  41. ibm_watsonx_gov/entities/mapping.py +49 -0
  42. ibm_watsonx_gov/entities/metric.py +211 -0
  43. ibm_watsonx_gov/entities/metric_threshold.py +36 -0
  44. ibm_watsonx_gov/entities/model_provider.py +329 -0
  45. ibm_watsonx_gov/entities/model_risk_result.py +43 -0
  46. ibm_watsonx_gov/entities/monitor.py +71 -0
  47. ibm_watsonx_gov/entities/prompt_setup.py +40 -0
  48. ibm_watsonx_gov/entities/state.py +22 -0
  49. ibm_watsonx_gov/entities/utils.py +99 -0
  50. ibm_watsonx_gov/evaluators/__init__.py +26 -0
  51. ibm_watsonx_gov/evaluators/agentic_evaluator.py +2725 -0
  52. ibm_watsonx_gov/evaluators/agentic_traces_evaluator.py +115 -0
  53. ibm_watsonx_gov/evaluators/base_evaluator.py +22 -0
  54. ibm_watsonx_gov/evaluators/impl/__init__.py +0 -0
  55. ibm_watsonx_gov/evaluators/impl/evaluate_metrics_impl.cp313-win_amd64.pyd +0 -0
  56. ibm_watsonx_gov/evaluators/impl/evaluate_model_risk_impl.cp313-win_amd64.pyd +0 -0
  57. ibm_watsonx_gov/evaluators/metrics_evaluator.py +187 -0
  58. ibm_watsonx_gov/evaluators/model_risk_evaluator.py +89 -0
  59. ibm_watsonx_gov/evaluators/traces_evaluator.py +93 -0
  60. ibm_watsonx_gov/metric_groups/answer_quality/answer_quality_decorator.py +66 -0
  61. ibm_watsonx_gov/metric_groups/content_safety/content_safety_decorator.py +76 -0
  62. ibm_watsonx_gov/metric_groups/readability/readability_decorator.py +59 -0
  63. ibm_watsonx_gov/metric_groups/retrieval_quality/retrieval_quality_decorator.py +63 -0
  64. ibm_watsonx_gov/metric_groups/usage/usage_decorator.py +58 -0
  65. ibm_watsonx_gov/metrics/__init__.py +74 -0
  66. ibm_watsonx_gov/metrics/answer_relevance/__init__.py +8 -0
  67. ibm_watsonx_gov/metrics/answer_relevance/answer_relevance_decorator.py +63 -0
  68. ibm_watsonx_gov/metrics/answer_relevance/answer_relevance_metric.py +260 -0
  69. ibm_watsonx_gov/metrics/answer_similarity/__init__.py +0 -0
  70. ibm_watsonx_gov/metrics/answer_similarity/answer_similarity_decorator.py +66 -0
  71. ibm_watsonx_gov/metrics/answer_similarity/answer_similarity_metric.py +219 -0
  72. ibm_watsonx_gov/metrics/average_precision/__init__.py +0 -0
  73. ibm_watsonx_gov/metrics/average_precision/average_precision_decorator.py +62 -0
  74. ibm_watsonx_gov/metrics/average_precision/average_precision_metric.py +174 -0
  75. ibm_watsonx_gov/metrics/base_metric_decorator.py +193 -0
  76. ibm_watsonx_gov/metrics/context_relevance/__init__.py +8 -0
  77. ibm_watsonx_gov/metrics/context_relevance/context_relevance_decorator.py +60 -0
  78. ibm_watsonx_gov/metrics/context_relevance/context_relevance_metric.py +414 -0
  79. ibm_watsonx_gov/metrics/cost/__init__.py +8 -0
  80. ibm_watsonx_gov/metrics/cost/cost_decorator.py +58 -0
  81. ibm_watsonx_gov/metrics/cost/cost_metric.py +155 -0
  82. ibm_watsonx_gov/metrics/duration/__init__.py +8 -0
  83. ibm_watsonx_gov/metrics/duration/duration_decorator.py +59 -0
  84. ibm_watsonx_gov/metrics/duration/duration_metric.py +111 -0
  85. ibm_watsonx_gov/metrics/evasiveness/__init__.py +8 -0
  86. ibm_watsonx_gov/metrics/evasiveness/evasiveness_decorator.py +61 -0
  87. ibm_watsonx_gov/metrics/evasiveness/evasiveness_metric.py +103 -0
  88. ibm_watsonx_gov/metrics/faithfulness/__init__.py +8 -0
  89. ibm_watsonx_gov/metrics/faithfulness/faithfulness_decorator.py +65 -0
  90. ibm_watsonx_gov/metrics/faithfulness/faithfulness_metric.py +254 -0
  91. ibm_watsonx_gov/metrics/hap/__init__.py +16 -0
  92. ibm_watsonx_gov/metrics/hap/hap_decorator.py +58 -0
  93. ibm_watsonx_gov/metrics/hap/hap_metric.py +98 -0
  94. ibm_watsonx_gov/metrics/hap/input_hap_metric.py +104 -0
  95. ibm_watsonx_gov/metrics/hap/output_hap_metric.py +110 -0
  96. ibm_watsonx_gov/metrics/harm/__init__.py +8 -0
  97. ibm_watsonx_gov/metrics/harm/harm_decorator.py +60 -0
  98. ibm_watsonx_gov/metrics/harm/harm_metric.py +103 -0
  99. ibm_watsonx_gov/metrics/harm_engagement/__init__.py +8 -0
  100. ibm_watsonx_gov/metrics/harm_engagement/harm_engagement_decorator.py +61 -0
  101. ibm_watsonx_gov/metrics/harm_engagement/harm_engagement_metric.py +103 -0
  102. ibm_watsonx_gov/metrics/hit_rate/__init__.py +0 -0
  103. ibm_watsonx_gov/metrics/hit_rate/hit_rate_decorator.py +59 -0
  104. ibm_watsonx_gov/metrics/hit_rate/hit_rate_metric.py +167 -0
  105. ibm_watsonx_gov/metrics/input_token_count/__init__.py +8 -0
  106. ibm_watsonx_gov/metrics/input_token_count/input_token_count_decorator.py +58 -0
  107. ibm_watsonx_gov/metrics/input_token_count/input_token_count_metric.py +112 -0
  108. ibm_watsonx_gov/metrics/jailbreak/__init__.py +8 -0
  109. ibm_watsonx_gov/metrics/jailbreak/jailbreak_decorator.py +60 -0
  110. ibm_watsonx_gov/metrics/jailbreak/jailbreak_metric.py +103 -0
  111. ibm_watsonx_gov/metrics/keyword_detection/keyword_detection_decorator.py +58 -0
  112. ibm_watsonx_gov/metrics/keyword_detection/keyword_detection_metric.py +111 -0
  113. ibm_watsonx_gov/metrics/llm_validation/__init__.py +8 -0
  114. ibm_watsonx_gov/metrics/llm_validation/evaluation_criteria.py +84 -0
  115. ibm_watsonx_gov/metrics/llm_validation/llm_validation_constants.py +24 -0
  116. ibm_watsonx_gov/metrics/llm_validation/llm_validation_decorator.py +54 -0
  117. ibm_watsonx_gov/metrics/llm_validation/llm_validation_impl.py +525 -0
  118. ibm_watsonx_gov/metrics/llm_validation/llm_validation_metric.py +258 -0
  119. ibm_watsonx_gov/metrics/llm_validation/llm_validation_prompts.py +106 -0
  120. ibm_watsonx_gov/metrics/llmaj/__init__.py +0 -0
  121. ibm_watsonx_gov/metrics/llmaj/llmaj_metric.py +298 -0
  122. ibm_watsonx_gov/metrics/ndcg/__init__.py +0 -0
  123. ibm_watsonx_gov/metrics/ndcg/ndcg_decorator.py +61 -0
  124. ibm_watsonx_gov/metrics/ndcg/ndcg_metric.py +166 -0
  125. ibm_watsonx_gov/metrics/output_token_count/__init__.py +8 -0
  126. ibm_watsonx_gov/metrics/output_token_count/output_token_count_decorator.py +58 -0
  127. ibm_watsonx_gov/metrics/output_token_count/output_token_count_metric.py +112 -0
  128. ibm_watsonx_gov/metrics/pii/__init__.py +16 -0
  129. ibm_watsonx_gov/metrics/pii/input_pii_metric.py +102 -0
  130. ibm_watsonx_gov/metrics/pii/output_pii_metric.py +107 -0
  131. ibm_watsonx_gov/metrics/pii/pii_decorator.py +59 -0
  132. ibm_watsonx_gov/metrics/pii/pii_metric.py +96 -0
  133. ibm_watsonx_gov/metrics/profanity/__init__.py +8 -0
  134. ibm_watsonx_gov/metrics/profanity/profanity_decorator.py +60 -0
  135. ibm_watsonx_gov/metrics/profanity/profanity_metric.py +103 -0
  136. ibm_watsonx_gov/metrics/prompt_safety_risk/__init__.py +8 -0
  137. ibm_watsonx_gov/metrics/prompt_safety_risk/prompt_safety_risk_decorator.py +57 -0
  138. ibm_watsonx_gov/metrics/prompt_safety_risk/prompt_safety_risk_metric.py +128 -0
  139. ibm_watsonx_gov/metrics/reciprocal_rank/__init__.py +0 -0
  140. ibm_watsonx_gov/metrics/reciprocal_rank/reciprocal_rank_decorator.py +62 -0
  141. ibm_watsonx_gov/metrics/reciprocal_rank/reciprocal_rank_metric.py +162 -0
  142. ibm_watsonx_gov/metrics/regex_detection/regex_detection_decorator.py +58 -0
  143. ibm_watsonx_gov/metrics/regex_detection/regex_detection_metric.py +106 -0
  144. ibm_watsonx_gov/metrics/retrieval_precision/__init__.py +0 -0
  145. ibm_watsonx_gov/metrics/retrieval_precision/retrieval_precision_decorator.py +62 -0
  146. ibm_watsonx_gov/metrics/retrieval_precision/retrieval_precision_metric.py +170 -0
  147. ibm_watsonx_gov/metrics/sexual_content/__init__.py +8 -0
  148. ibm_watsonx_gov/metrics/sexual_content/sexual_content_decorator.py +61 -0
  149. ibm_watsonx_gov/metrics/sexual_content/sexual_content_metric.py +103 -0
  150. ibm_watsonx_gov/metrics/social_bias/__init__.py +8 -0
  151. ibm_watsonx_gov/metrics/social_bias/social_bias_decorator.py +62 -0
  152. ibm_watsonx_gov/metrics/social_bias/social_bias_metric.py +103 -0
  153. ibm_watsonx_gov/metrics/status/__init__.py +0 -0
  154. ibm_watsonx_gov/metrics/status/status_metric.py +113 -0
  155. ibm_watsonx_gov/metrics/text_grade_level/__init__.py +8 -0
  156. ibm_watsonx_gov/metrics/text_grade_level/text_grade_level_decorator.py +59 -0
  157. ibm_watsonx_gov/metrics/text_grade_level/text_grade_level_metric.py +127 -0
  158. ibm_watsonx_gov/metrics/text_reading_ease/__init__.py +8 -0
  159. ibm_watsonx_gov/metrics/text_reading_ease/text_reading_ease_decorator.py +59 -0
  160. ibm_watsonx_gov/metrics/text_reading_ease/text_reading_ease_metric.py +123 -0
  161. ibm_watsonx_gov/metrics/tool_call_accuracy/__init__.py +0 -0
  162. ibm_watsonx_gov/metrics/tool_call_accuracy/tool_call_accuracy_decorator.py +67 -0
  163. ibm_watsonx_gov/metrics/tool_call_accuracy/tool_call_accuracy_metric.py +162 -0
  164. ibm_watsonx_gov/metrics/tool_call_parameter_accuracy/__init__.py +0 -0
  165. ibm_watsonx_gov/metrics/tool_call_parameter_accuracy/tool_call_parameter_accuracy_decorator.py +68 -0
  166. ibm_watsonx_gov/metrics/tool_call_parameter_accuracy/tool_call_parameter_accuracy_metric.py +151 -0
  167. ibm_watsonx_gov/metrics/tool_call_relevance/__init__.py +0 -0
  168. ibm_watsonx_gov/metrics/tool_call_relevance/tool_call_relevance_decorator.py +71 -0
  169. ibm_watsonx_gov/metrics/tool_call_relevance/tool_call_relevance_metric.py +166 -0
  170. ibm_watsonx_gov/metrics/tool_call_syntactic_accuracy/__init__.py +0 -0
  171. ibm_watsonx_gov/metrics/tool_call_syntactic_accuracy/tool_call_syntactic_accuracy_decorator.py +66 -0
  172. ibm_watsonx_gov/metrics/tool_call_syntactic_accuracy/tool_call_syntactic_accuracy_metric.py +121 -0
  173. ibm_watsonx_gov/metrics/topic_relevance/__init__.py +8 -0
  174. ibm_watsonx_gov/metrics/topic_relevance/topic_relevance_decorator.py +57 -0
  175. ibm_watsonx_gov/metrics/topic_relevance/topic_relevance_metric.py +106 -0
  176. ibm_watsonx_gov/metrics/unethical_behavior/__init__.py +8 -0
  177. ibm_watsonx_gov/metrics/unethical_behavior/unethical_behavior_decorator.py +61 -0
  178. ibm_watsonx_gov/metrics/unethical_behavior/unethical_behavior_metric.py +103 -0
  179. ibm_watsonx_gov/metrics/unsuccessful_requests/__init__.py +0 -0
  180. ibm_watsonx_gov/metrics/unsuccessful_requests/unsuccessful_requests_decorator.py +66 -0
  181. ibm_watsonx_gov/metrics/unsuccessful_requests/unsuccessful_requests_metric.py +128 -0
  182. ibm_watsonx_gov/metrics/user_id/__init__.py +0 -0
  183. ibm_watsonx_gov/metrics/user_id/user_id_metric.py +111 -0
  184. ibm_watsonx_gov/metrics/utils.py +440 -0
  185. ibm_watsonx_gov/metrics/violence/__init__.py +8 -0
  186. ibm_watsonx_gov/metrics/violence/violence_decorator.py +60 -0
  187. ibm_watsonx_gov/metrics/violence/violence_metric.py +103 -0
  188. ibm_watsonx_gov/prompt_evaluator/__init__.py +9 -0
  189. ibm_watsonx_gov/prompt_evaluator/impl/__init__.py +8 -0
  190. ibm_watsonx_gov/prompt_evaluator/impl/prompt_evaluator_impl.py +554 -0
  191. ibm_watsonx_gov/prompt_evaluator/impl/pta_lifecycle_evaluator.py +2332 -0
  192. ibm_watsonx_gov/prompt_evaluator/prompt_evaluator.py +262 -0
  193. ibm_watsonx_gov/providers/__init__.py +8 -0
  194. ibm_watsonx_gov/providers/detectors_provider.cp313-win_amd64.pyd +0 -0
  195. ibm_watsonx_gov/providers/detectors_provider.py +415 -0
  196. ibm_watsonx_gov/providers/eval_assist_provider.cp313-win_amd64.pyd +0 -0
  197. ibm_watsonx_gov/providers/eval_assist_provider.py +266 -0
  198. ibm_watsonx_gov/providers/inference_engines/__init__.py +0 -0
  199. ibm_watsonx_gov/providers/inference_engines/custom_inference_engine.py +165 -0
  200. ibm_watsonx_gov/providers/inference_engines/portkey_inference_engine.py +57 -0
  201. ibm_watsonx_gov/providers/llmevalkit/__init__.py +0 -0
  202. ibm_watsonx_gov/providers/llmevalkit/ciso_agent/main.py +516 -0
  203. ibm_watsonx_gov/providers/llmevalkit/ciso_agent/preprocess_log.py +111 -0
  204. ibm_watsonx_gov/providers/llmevalkit/ciso_agent/utils.py +186 -0
  205. ibm_watsonx_gov/providers/llmevalkit/function_calling/README.md +411 -0
  206. ibm_watsonx_gov/providers/llmevalkit/function_calling/__init__.py +27 -0
  207. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/README.md +306 -0
  208. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/__init__.py +89 -0
  209. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/__init__.py +30 -0
  210. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/base.py +411 -0
  211. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/code_agent.py +1254 -0
  212. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/exact_match.py +134 -0
  213. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/fuzzy_string.py +104 -0
  214. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/hybrid.py +516 -0
  215. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/llm_judge.py +1882 -0
  216. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/pipeline.py +387 -0
  217. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/types.py +178 -0
  218. ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/utils.py +298 -0
  219. ibm_watsonx_gov/providers/llmevalkit/function_calling/consts.py +33 -0
  220. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/__init__.py +31 -0
  221. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/base.py +26 -0
  222. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_call/__init__.py +4 -0
  223. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_call/general.py +46 -0
  224. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_call/general_metrics.json +783 -0
  225. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_call/general_metrics_runtime.json +580 -0
  226. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_selection/__init__.py +6 -0
  227. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_selection/function_selection.py +28 -0
  228. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_selection/function_selection_metrics.json +599 -0
  229. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_selection/function_selection_metrics_runtime.json +477 -0
  230. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/loader.py +259 -0
  231. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/parameter/__init__.py +7 -0
  232. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/parameter/parameter.py +52 -0
  233. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/parameter/parameter_metrics.json +613 -0
  234. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/parameter/parameter_metrics_runtime.json +489 -0
  235. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/trajectory/__init__.py +7 -0
  236. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/trajectory/trajectory.py +43 -0
  237. ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/trajectory/trajectory_metrics.json +161 -0
  238. ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/__init__.py +0 -0
  239. ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/adapters.py +102 -0
  240. ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/pipeline.py +355 -0
  241. ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/semantic_checker.py +816 -0
  242. ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/static_checker.py +297 -0
  243. ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/transformation_prompts.py +509 -0
  244. ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/types.py +596 -0
  245. ibm_watsonx_gov/providers/llmevalkit/llm/README.md +375 -0
  246. ibm_watsonx_gov/providers/llmevalkit/llm/__init__.py +137 -0
  247. ibm_watsonx_gov/providers/llmevalkit/llm/base.py +426 -0
  248. ibm_watsonx_gov/providers/llmevalkit/llm/output_parser.py +364 -0
  249. ibm_watsonx_gov/providers/llmevalkit/llm/providers/__init__.py +0 -0
  250. ibm_watsonx_gov/providers/llmevalkit/llm/providers/consts.py +7 -0
  251. ibm_watsonx_gov/providers/llmevalkit/llm/providers/ibm_watsonx_ai/__init__.py +0 -0
  252. ibm_watsonx_gov/providers/llmevalkit/llm/providers/ibm_watsonx_ai/ibm_watsonx_ai.py +656 -0
  253. ibm_watsonx_gov/providers/llmevalkit/llm/providers/litellm/__init__.py +0 -0
  254. ibm_watsonx_gov/providers/llmevalkit/llm/providers/litellm/litellm.py +509 -0
  255. ibm_watsonx_gov/providers/llmevalkit/llm/providers/litellm/rits.py +224 -0
  256. ibm_watsonx_gov/providers/llmevalkit/llm/providers/litellm/watsonx.py +60 -0
  257. ibm_watsonx_gov/providers/llmevalkit/llm/providers/mock_llm_client.py +75 -0
  258. ibm_watsonx_gov/providers/llmevalkit/llm/providers/openai/__init__.py +0 -0
  259. ibm_watsonx_gov/providers/llmevalkit/llm/providers/openai/openai.py +639 -0
  260. ibm_watsonx_gov/providers/llmevalkit/llm/providers/wxo_ai_gateway/__init__.py +0 -0
  261. ibm_watsonx_gov/providers/llmevalkit/llm/providers/wxo_ai_gateway/wxo_ai_gateway.py +134 -0
  262. ibm_watsonx_gov/providers/llmevalkit/llm/providers/wxo_ai_gateway/wxo_ai_gateway_inference.py +214 -0
  263. ibm_watsonx_gov/providers/llmevalkit/llm/types.py +136 -0
  264. ibm_watsonx_gov/providers/llmevalkit/metrics/__init__.py +4 -0
  265. ibm_watsonx_gov/providers/llmevalkit/metrics/field.py +255 -0
  266. ibm_watsonx_gov/providers/llmevalkit/metrics/metric.py +332 -0
  267. ibm_watsonx_gov/providers/llmevalkit/metrics/metrics_runner.py +188 -0
  268. ibm_watsonx_gov/providers/llmevalkit/metrics/prompt.py +403 -0
  269. ibm_watsonx_gov/providers/llmevalkit/metrics/utils.py +46 -0
  270. ibm_watsonx_gov/providers/llmevalkit/prompt/__init__.py +0 -0
  271. ibm_watsonx_gov/providers/llmevalkit/prompt/runner.py +144 -0
  272. ibm_watsonx_gov/providers/tool_call_metric_provider.py +455 -0
  273. ibm_watsonx_gov/providers/unitxt_provider.cp313-win_amd64.pyd +0 -0
  274. ibm_watsonx_gov/tools/__init__.py +10 -0
  275. ibm_watsonx_gov/tools/clients/__init__.py +11 -0
  276. ibm_watsonx_gov/tools/clients/ai_tool_client.py +405 -0
  277. ibm_watsonx_gov/tools/clients/detector_client.py +82 -0
  278. ibm_watsonx_gov/tools/core/__init__.py +8 -0
  279. ibm_watsonx_gov/tools/core/tool_loader.py +237 -0
  280. ibm_watsonx_gov/tools/entities/__init__.py +8 -0
  281. ibm_watsonx_gov/tools/entities/ai_tools.py +435 -0
  282. ibm_watsonx_gov/tools/onboarding/create/answer_relevance_detector.json +57 -0
  283. ibm_watsonx_gov/tools/onboarding/create/chromadb_retrieval_tool.json +63 -0
  284. ibm_watsonx_gov/tools/onboarding/create/context_relevance_detector.json +57 -0
  285. ibm_watsonx_gov/tools/onboarding/create/duduckgo_search_tool.json +53 -0
  286. ibm_watsonx_gov/tools/onboarding/create/google_search_tool.json +62 -0
  287. ibm_watsonx_gov/tools/onboarding/create/hap_detector.json +70 -0
  288. ibm_watsonx_gov/tools/onboarding/create/jailbreak_detector.json +70 -0
  289. ibm_watsonx_gov/tools/onboarding/create/pii_detector.json +36 -0
  290. ibm_watsonx_gov/tools/onboarding/create/prompt_safety_risk_detector.json +69 -0
  291. ibm_watsonx_gov/tools/onboarding/create/topic_relevance_detector.json +57 -0
  292. ibm_watsonx_gov/tools/onboarding/create/weather_tool.json +39 -0
  293. ibm_watsonx_gov/tools/onboarding/create/webcrawler_tool.json +34 -0
  294. ibm_watsonx_gov/tools/onboarding/create/wikipedia_search_tool.json +53 -0
  295. ibm_watsonx_gov/tools/onboarding/delete/delete_tools.json +4 -0
  296. ibm_watsonx_gov/tools/onboarding/update/google_search_tool.json +38 -0
  297. ibm_watsonx_gov/tools/ootb/__init__.py +8 -0
  298. ibm_watsonx_gov/tools/ootb/detectors/__init__.py +8 -0
  299. ibm_watsonx_gov/tools/ootb/detectors/hap_detector_tool.py +109 -0
  300. ibm_watsonx_gov/tools/ootb/detectors/jailbreak_detector_tool.py +104 -0
  301. ibm_watsonx_gov/tools/ootb/detectors/pii_detector_tool.py +83 -0
  302. ibm_watsonx_gov/tools/ootb/detectors/prompt_safety_risk_detector_tool.py +111 -0
  303. ibm_watsonx_gov/tools/ootb/detectors/topic_relevance_detector_tool.py +101 -0
  304. ibm_watsonx_gov/tools/ootb/rag/__init__.py +8 -0
  305. ibm_watsonx_gov/tools/ootb/rag/answer_relevance_detector_tool.py +119 -0
  306. ibm_watsonx_gov/tools/ootb/rag/context_relevance_detector_tool.py +118 -0
  307. ibm_watsonx_gov/tools/ootb/search/__init__.py +8 -0
  308. ibm_watsonx_gov/tools/ootb/search/duckduckgo_search_tool.py +62 -0
  309. ibm_watsonx_gov/tools/ootb/search/google_search_tool.py +105 -0
  310. ibm_watsonx_gov/tools/ootb/search/weather_tool.py +95 -0
  311. ibm_watsonx_gov/tools/ootb/search/web_crawler_tool.py +69 -0
  312. ibm_watsonx_gov/tools/ootb/search/wikipedia_search_tool.py +63 -0
  313. ibm_watsonx_gov/tools/ootb/vectordb/__init__.py +8 -0
  314. ibm_watsonx_gov/tools/ootb/vectordb/chromadb_retriever_tool.py +111 -0
  315. ibm_watsonx_gov/tools/rest_api/__init__.py +10 -0
  316. ibm_watsonx_gov/tools/rest_api/restapi_tool.py +72 -0
  317. ibm_watsonx_gov/tools/schemas/__init__.py +10 -0
  318. ibm_watsonx_gov/tools/schemas/search_tool_schema.py +46 -0
  319. ibm_watsonx_gov/tools/schemas/vectordb_retrieval_schema.py +55 -0
  320. ibm_watsonx_gov/tools/utils/__init__.py +14 -0
  321. ibm_watsonx_gov/tools/utils/constants.py +69 -0
  322. ibm_watsonx_gov/tools/utils/display_utils.py +38 -0
  323. ibm_watsonx_gov/tools/utils/environment.py +108 -0
  324. ibm_watsonx_gov/tools/utils/package_utils.py +40 -0
  325. ibm_watsonx_gov/tools/utils/platform_url_mapping.cp313-win_amd64.pyd +0 -0
  326. ibm_watsonx_gov/tools/utils/python_utils.py +68 -0
  327. ibm_watsonx_gov/tools/utils/tool_utils.py +206 -0
  328. ibm_watsonx_gov/traces/__init__.py +8 -0
  329. ibm_watsonx_gov/traces/span_exporter.py +195 -0
  330. ibm_watsonx_gov/traces/span_node.py +251 -0
  331. ibm_watsonx_gov/traces/span_util.py +153 -0
  332. ibm_watsonx_gov/traces/trace_utils.py +1074 -0
  333. ibm_watsonx_gov/utils/__init__.py +8 -0
  334. ibm_watsonx_gov/utils/aggregation_util.py +346 -0
  335. ibm_watsonx_gov/utils/async_util.py +62 -0
  336. ibm_watsonx_gov/utils/authenticator.py +144 -0
  337. ibm_watsonx_gov/utils/constants.py +15 -0
  338. ibm_watsonx_gov/utils/errors.py +40 -0
  339. ibm_watsonx_gov/utils/gov_sdk_logger.py +39 -0
  340. ibm_watsonx_gov/utils/insights_generator.py +1285 -0
  341. ibm_watsonx_gov/utils/python_utils.py +425 -0
  342. ibm_watsonx_gov/utils/rest_util.py +73 -0
  343. ibm_watsonx_gov/utils/segment_batch_manager.py +162 -0
  344. ibm_watsonx_gov/utils/singleton_meta.py +25 -0
  345. ibm_watsonx_gov/utils/url_mapping.cp313-win_amd64.pyd +0 -0
  346. ibm_watsonx_gov/utils/validation_util.py +126 -0
  347. ibm_watsonx_gov/visualizations/__init__.py +13 -0
  348. ibm_watsonx_gov/visualizations/metric_descriptions.py +57 -0
  349. ibm_watsonx_gov/visualizations/model_insights.py +1304 -0
  350. ibm_watsonx_gov/visualizations/visualization_utils.py +75 -0
  351. ibm_watsonx_gov-1.3.3.dist-info/METADATA +93 -0
  352. ibm_watsonx_gov-1.3.3.dist-info/RECORD +353 -0
  353. ibm_watsonx_gov-1.3.3.dist-info/WHEEL +4 -0
@@ -0,0 +1,633 @@
1
+ # ----------------------------------------------------------------------------------------------------
2
+ # IBM Confidential
3
+ # Licensed Materials - Property of IBM
4
+ # 5737-H76, 5900-A3Q
5
+ # © Copyright IBM Corp. 2025 All Rights Reserved.
6
+ # US Government Users Restricted Rights - Use, duplication or disclosure restricted by
7
+ # GSA ADPSchedule Contract with IBM Corp.
8
+ # ----------------------------------------------------------------------------------------------------
9
+
10
+ import os
11
+ from typing import Annotated, Literal
12
+
13
+ from ibm_watsonx_gov.entities.enums import Region
14
+ from ibm_watsonx_gov.utils.python_utils import get_environment_variable_value
15
+ from ibm_watsonx_gov.utils.url_mapping import (WATSONX_REGION_URLS,
16
+ WOS_URL_MAPPING)
17
+ from pydantic import BaseModel, Field, model_validator
18
+
19
+
20
+ class Credentials(BaseModel):
21
+ api_key: Annotated[str | None, Field(title="Api Key",
22
+ description="The user api key. Required for using watsonx as a service and one of api_key or password is required for using watsonx on-prem software.",
23
+ strip_whitespace=True,
24
+ default=None)]
25
+ region: Annotated[str | None,
26
+ Field(title="Region",
27
+ description="The watsonx cloud region. By default us-south region is used.",
28
+ default=Region.US_SOUTH.value)]
29
+ url: Annotated[str, Field(title="watsonx url",
30
+ description="The watsonx url. Required for using watsonx on-prem software.",
31
+ default=None)]
32
+ service_instance_id: Annotated[str | None, Field(title="Service instance id",
33
+ description="The watsonx.governance service instance id.",
34
+ default=None)]
35
+ username: Annotated[str | None, Field(title="User name",
36
+ description="The user name. Required for using watsonx on-prem software.",
37
+ default=None)]
38
+ password: Annotated[str | None, Field(title="Password",
39
+ description="The user password. One of api_key or password is required for using watsonx on-prem software.",
40
+ default=None)]
41
+ token: Annotated[str | None, Field(title="Token",
42
+ description="The bearer token.",
43
+ default=None)]
44
+ version: Annotated[str | None, Field(title="Version",
45
+ description="The watsonx on-prem software version. Required for using watsonx on-prem software.",
46
+ default=None,
47
+ examples=["5.2"])]
48
+ disable_ssl: Annotated[bool, Field(title="Disable ssl",
49
+ description="The flag to disable ssl.",
50
+ default=False)]
51
+ scope_id: Annotated[str | None, Field(title="Scope ID",
52
+ description="The scope identifier.",
53
+ default=None)]
54
+ scope_collection_type: Annotated[Literal["accounts", "subscriptions", "services", "products", "externalservices"] | None, Field(title="Scope Collection Type",
55
+ description="Scope collection type of item(s).",
56
+ default=None)]
57
+
58
+ @model_validator(mode="after")
59
+ def validate_credentials(self):
60
+ if self.version: # on-prem
61
+ if not self.url:
62
+ raise ValueError("The url value is required.")
63
+ if not self.username and not self.token:
64
+ raise ValueError("The username value is required.")
65
+ if not (self.api_key or self.password) and not self.token:
66
+ raise ValueError(
67
+ "One of api_key or password value is required.")
68
+ else:
69
+ if not (self.api_key or self.token):
70
+ raise ValueError("One of api_key or token value is required.")
71
+ if self.url:
72
+ url_map = WOS_URL_MAPPING.get(self.url)
73
+ if not url_map:
74
+ raise ValueError(
75
+ f"The url {self.url} is invalid. Please provide a valid watsonx.governance service url.")
76
+ self.region = url_map.region
77
+ else:
78
+ url_map = WATSONX_REGION_URLS.get(self.region)
79
+ if not url_map:
80
+ raise ValueError(
81
+ f"The region {self.region} is invalid. Please provide a valid watsonx.governance region. Supported regions are {Region.values()}")
82
+ self.url = url_map.wxg_url
83
+ if self.region == Region.AP_SOUTH.value:
84
+ if not self.scope_id:
85
+ raise ValueError(
86
+ "The scope_id is required when using ap-south region. Please provide a valid value.")
87
+ if not self.scope_collection_type:
88
+ raise ValueError(
89
+ "The scope_collection_type is required when using ap-south region. Please provide a valid value.")
90
+
91
+ return self
92
+
93
+ @classmethod
94
+ def create_from_env(cls):
95
+ region = get_environment_variable_value(
96
+ ["WATSONX_REGION"])
97
+ # possible API key environment variable names
98
+ api_key = get_environment_variable_value(
99
+ ["WXG_API_KEY", "WATSONX_APIKEY"])
100
+ username = get_environment_variable_value(
101
+ ["WXG_USERNAME", "WATSONX_USERNAME"])
102
+ password = get_environment_variable_value(["WATSONX_PASSWORD"])
103
+ version = get_environment_variable_value(
104
+ ["WXG_VERSION", "WATSONX_VERSION"])
105
+ token = get_environment_variable_value(["WATSONX_TOKEN"])
106
+
107
+ if version: # on-prem
108
+ url = get_environment_variable_value(["WATSONX_URL"])
109
+ if not url:
110
+ raise ValueError(
111
+ "The watsonx url is required and should be set using WATSONX_URL environment variable.")
112
+ if not (token or (username and (api_key or password))):
113
+ raise ValueError(
114
+ "One of token or username api key or password combination is required. These can be set using WATSONX_TOKEN, WATSONX_USERNAME, WATSONX_APIKEY, WATSONX_PASSWORD environment variables"
115
+ )
116
+ if not token:
117
+ if not username:
118
+ raise ValueError(
119
+ "The username is required and should be set using WATSONX_USERNAME environment variable.")
120
+ if not (api_key or password):
121
+ raise ValueError(
122
+ "One of api_key or password is required and should be set using WATSONX_APIKEY or WATSONX_PASSWORD environment variable.")
123
+ else:
124
+ url = os.getenv("WXG_URL")
125
+
126
+ if url:
127
+ url_map = WOS_URL_MAPPING.get(url)
128
+ if not url_map:
129
+ raise ValueError(
130
+ f"The url {url} is invalid. Please provide a valid watsonx.governance service url.")
131
+ region = url_map.region
132
+ else:
133
+ if not region:
134
+ region = Region.US_SOUTH.value
135
+
136
+ url_map = WATSONX_REGION_URLS.get(region)
137
+ if not url_map:
138
+ raise ValueError(
139
+ f"The region {region} is invalid. Supported regions are {Region.values()}. Please provide a valid watsonx.governance region in WATSONX_REGION environment varaible.")
140
+
141
+ url = url_map.wxg_url
142
+
143
+ if not (api_key or token):
144
+ raise ValueError(
145
+ "The api_key or token is required and should be set using WATSONX_APIKEY or WATSONX_TOKEN environment variable.")
146
+
147
+ disable_ssl = os.getenv("WATSONX_DISABLE_SSL", False)
148
+
149
+ return Credentials(
150
+ region=region,
151
+ api_key=api_key,
152
+ url=url,
153
+ service_instance_id=os.getenv("WXG_SERVICE_INSTANCE_ID"),
154
+ username=username,
155
+ password=password,
156
+ token=token,
157
+ version=version,
158
+ disable_ssl=disable_ssl
159
+ )
160
+
161
+
162
+ class WxAICredentials(BaseModel):
163
+ """
164
+ Defines the WxAICredentials class to specify the watsonx.ai server details.
165
+
166
+ Examples:
167
+ 1. Create WxAICredentials with default parameters. By default Dallas region is used.
168
+ .. code-block:: python
169
+
170
+ wxai_credentials = WxAICredentials(api_key="...")
171
+
172
+ 2. Create WxAICredentials by specifying region url.
173
+ .. code-block:: python
174
+
175
+ wxai_credentials = WxAICredentials(api_key="...",
176
+ url="https://au-syd.ml.cloud.ibm.com")
177
+
178
+ 3. Create WxAICredentials by reading from environment variables.
179
+ .. code-block:: python
180
+
181
+ os.environ["WATSONX_APIKEY"] = "..."
182
+ # [Optional] Specify watsonx region specific url. Default is https://us-south.ml.cloud.ibm.com .
183
+ os.environ["WATSONX_URL"] = "https://eu-gb.ml.cloud.ibm.com"
184
+ wxai_credentials = WxAICredentials.create_from_env()
185
+
186
+ 4. Create WxAICredentials for on-prem.
187
+ .. code-block:: python
188
+
189
+ wxai_credentials = WxAICredentials(url="https://<hostname>",
190
+ username="..."
191
+ api_key="...",
192
+ version="5.2")
193
+
194
+ 5. Create WxAICredentials by reading from environment variables for on-prem.
195
+ .. code-block:: python
196
+
197
+ os.environ["WATSONX_URL"] = "https://<hostname>"
198
+ os.environ["WATSONX_VERSION"] = "5.2"
199
+ os.environ["WATSONX_USERNAME"] = "..."
200
+ os.environ["WATSONX_APIKEY"] = "..."
201
+ # Only one of api_key or password is needed
202
+ #os.environ["WATSONX_PASSWORD"] = "..."
203
+ wxai_credentials = WxAICredentials.create_from_env()
204
+ """
205
+ url: Annotated[str, Field(
206
+ title="watsonx.ai url",
207
+ description="The url for watsonx ai service",
208
+ default="https://us-south.ml.cloud.ibm.com",
209
+ examples=[
210
+ "https://us-south.ml.cloud.ibm.com",
211
+ "https://eu-de.ml.cloud.ibm.com",
212
+ "https://eu-gb.ml.cloud.ibm.com",
213
+ "https://jp-tok.ml.cloud.ibm.com",
214
+ "https://au-syd.ml.cloud.ibm.com",
215
+ ]
216
+ )]
217
+ api_key: Annotated[str | None, Field(title="Api Key",
218
+ description="The user api key. Required for using watsonx as a service and one of api_key or password is required for using watsonx on-prem software.",
219
+ strip_whitespace=True,
220
+ default=None)]
221
+ version: Annotated[str | None, Field(title="Version",
222
+ description="The watsonx on-prem software version. Required for using watsonx on-prem software.",
223
+ default=None)]
224
+ username: Annotated[str | None, Field(title="User name",
225
+ description="The user name. Required for using watsonx on-prem software.",
226
+ default=None)]
227
+ password: Annotated[str | None, Field(title="Password",
228
+ description="The user password. One of api_key or password is required for using watsonx on-prem software.",
229
+ default=None)]
230
+ instance_id: Annotated[str | None, Field(title="Instance id",
231
+ description="The watsonx.ai instance id. Default value is openshift.",
232
+ default="openshift")]
233
+
234
+ @classmethod
235
+ def create_from_env(cls):
236
+ # possible API key environment variable names
237
+ api_key = get_environment_variable_value(
238
+ ["WXAI_API_KEY", "WATSONX_APIKEY", "WXG_API_KEY"])
239
+
240
+ username = get_environment_variable_value(
241
+ ["WXAI_USERNAME", "WATSONX_USERNAME", "WXG_USERNAME"])
242
+
243
+ version = get_environment_variable_value(
244
+ ["WXAI_VERSION", "WATSONX_VERSION", "WXG_VERSION"])
245
+
246
+ url = get_environment_variable_value(
247
+ ["WXAI_URL", "WATSONX_URL"])
248
+
249
+ password = get_environment_variable_value(["WATSONX_PASSWORD"])
250
+
251
+ instance_id = get_environment_variable_value(
252
+ ["WATSONX_INSTANCE_ID"], "openshift")
253
+
254
+ if version: # on-prem
255
+ url = get_environment_variable_value(["WATSONX_URL"])
256
+ if not url:
257
+ raise ValueError(
258
+ "The watsonx url is required and should be set using WATSONX_URL environment variable.")
259
+ if not username:
260
+ raise ValueError(
261
+ "The username is required and should be set using WATSONX_USERNAME environment variable.")
262
+ if not (api_key or password):
263
+ raise ValueError(
264
+ "One of api_key or password is required and should be set using WATSONX_APIKEY or WATSONX_PASSWORD environment variable.")
265
+ else:
266
+ # Check the url & update it
267
+ if url in WOS_URL_MAPPING.keys():
268
+ url = WOS_URL_MAPPING.get(url).wml_url
269
+
270
+ # If the url environment variable is not found, use the default
271
+ if not url:
272
+ url = "https://us-south.ml.cloud.ibm.com"
273
+
274
+ if not api_key:
275
+ raise ValueError(
276
+ "The api_key is required and should be set using WATSONX_APIKEY environment variable.")
277
+
278
+ credentials = {
279
+ "url": url,
280
+ "api_key": api_key,
281
+ "version": version,
282
+ "username": username,
283
+ "password": password,
284
+ "instance_id": instance_id
285
+ }
286
+
287
+ return WxAICredentials(
288
+ **credentials
289
+ )
290
+
291
+
292
+ class WxGovConsoleCredentials(BaseModel):
293
+ """
294
+ This class holds the authentication credentials required to connect to the watsonx Governance Console.
295
+
296
+ Examples:
297
+ 1. Create credentials manually:
298
+ .. code-block:: python
299
+
300
+ credentials = WxGovConsoleCredentials(
301
+ url="https://governance-console.example.com",
302
+ username="admin",
303
+ password="securepassword",
304
+ api_key="optional-api-key"
305
+ )
306
+
307
+ 2. Create credentials using environment variables:
308
+ .. code-block:: python
309
+
310
+ import os
311
+
312
+ os.environ['WXGC_URL'] = "https://governance-console.example.com"
313
+ os.environ['WXGC_USERNAME'] = "admin"
314
+ os.environ['WXGC_PASSWORD'] = "securepassword"
315
+ os.environ['WXGC_API_KEY'] = "optional-api-key" # Optional
316
+
317
+ credentials = WxGovConsoleCredentials.create_from_env()
318
+ """
319
+ url: str = Field(
320
+ description="The base URL of the watsonx Governance Console.")
321
+ username: str = Field(description="The username used for authentication.")
322
+ password: str = Field(description="The password used for authentication.")
323
+ api_key: str | None = Field(
324
+ default=None, description="Optional API key for token-based authentication.")
325
+
326
+ @classmethod
327
+ def create_from_env(cls):
328
+ return WxGovConsoleCredentials(
329
+ url=os.getenv("WXGC_URL"),
330
+ username=os.getenv("WXGC_USERNAME"),
331
+ password=os.getenv("WXGC_PASSWORD"),
332
+ api_key=os.getenv("WXGC_API_KEY"),
333
+ )
334
+
335
+
336
+ class RITSCredentials(BaseModel):
337
+ hostname: Annotated[
338
+ str | None,
339
+ Field(description="The rits hostname",
340
+ default="https://inference-3scale-apicast-production.apps.rits.fmaas.res.ibm.com"),
341
+ ]
342
+ api_key: str
343
+
344
+ @classmethod
345
+ def create_from_env(cls):
346
+ api_key = os.getenv("RITS_API_KEY")
347
+ rits_host = os.getenv(
348
+ "RITS_HOST", "https://inference-3scale-apicast-production.apps.rits.fmaas.res.ibm.com")
349
+
350
+ return RITSCredentials(
351
+ hostname=rits_host,
352
+ api_key=api_key,
353
+ )
354
+
355
+
356
+ class OpenAICredentials(BaseModel):
357
+ """
358
+ Defines the OpenAICredentials class to specify the OpenAI server details.
359
+
360
+ Examples:
361
+ 1. Create OpenAICredentials with default parameters. By default Dallas region is used.
362
+ .. code-block:: python
363
+
364
+ openai_credentials = OpenAICredentials(api_key=api_key,
365
+ url=openai_url)
366
+
367
+ 2. Create OpenAICredentials by reading from environment variables.
368
+ .. code-block:: python
369
+
370
+ os.environ["OPENAI_API_KEY"] = "..."
371
+ os.environ["OPENAI_URL"] = "..."
372
+ openai_credentials = OpenAICredentials.create_from_env()
373
+ """
374
+ url: str | None
375
+ api_key: str | None
376
+
377
+ @classmethod
378
+ def create_from_env(cls):
379
+ return OpenAICredentials(
380
+ url=os.getenv("OPENAI_URL"),
381
+ api_key=os.getenv("OPENAI_API_KEY"),
382
+ )
383
+
384
+
385
+ class PortKeyCredentials(BaseModel):
386
+ """
387
+ Defines the PortKeyCredentials class to specify the PortKey Gateway details.
388
+
389
+ Examples:
390
+ 1. Create PortKeyCredentials with default parameters.
391
+ .. code-block:: python
392
+
393
+ portkey_credentials = PortKeyCredentials(api_key=api_key,
394
+ url=portkey_url,
395
+ provider_api_key=provider_api_key,
396
+ provider=provider_name)
397
+
398
+ 2. Create PortKeyCredentials by reading from environment variables.
399
+ .. code-block:: python
400
+
401
+ os.environ["PORTKEY_API_KEY"] = "..."
402
+ os.environ["PORTKEY_URL"] = "..."
403
+ os.environ["PORTKEY_PROVIDER_API_KEY"] = "..."
404
+ os.environ["PORTKEY_PROVIDER_NAME"] = "..."
405
+ portkey_credentials = PortKeyCredentials.create_from_env()
406
+ """
407
+ url: Annotated[str | None, Field(
408
+ description="PortKey url. This attribute can be read from `PORTKEY_URL` environment variable.")]
409
+ api_key: Annotated[str | None, Field(
410
+ description="API key for PortKey. This attribute can be read from `PORTKEY_API_KEY` environment variable.")]
411
+ provider_api_key: Annotated[str | None, Field(
412
+ description="API key for the provider. This attribute can be read from `PORTKEY_PROVIDER_API_KEY` environment variable.")]
413
+ provider: Annotated[str | None, Field(
414
+ description="The provider name. This attribute can be read from `PORTKEY_PROVIDER_NAME` environment variable.")]
415
+
416
+ @classmethod
417
+ def create_from_env(cls):
418
+ return PortKeyCredentials(
419
+ url=os.getenv("PORTKEY_URL"),
420
+ api_key=os.getenv("PORTKEY_API_KEY"),
421
+ provider_api_key=os.getenv("PORTKEY_PROVIDER_API_KEY"),
422
+ provider=os.getenv("PORTKEY_PROVIDER_NAME")
423
+ )
424
+
425
+
426
+ class AzureOpenAICredentials(BaseModel):
427
+ url: Annotated[str | None, Field(
428
+ description="Azure OpenAI url. This attribute can be read from `AZURE_OPENAI_HOST` environment variable.",
429
+ serialization_alias="azure_openai_host")]
430
+ api_key: Annotated[str | None, Field(
431
+ description="API key for Azure OpenAI. This attribute can be read from `AZURE_OPENAI_API_KEY` environment variable.")]
432
+ api_version: Annotated[str | None, Field(
433
+ description="The model API version from Azure OpenAI. This attribute can be read from `AZURE_OPENAI_API_VERSION` environment variable.")]
434
+
435
+ @classmethod
436
+ def create_from_env(cls):
437
+ return AzureOpenAICredentials(
438
+ url=os.getenv("AZURE_OPENAI_HOST"),
439
+ api_key=os.getenv("AZURE_OPENAI_API_KEY"),
440
+ api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
441
+ )
442
+
443
+
444
+ class GoogleAIStudioCredentials(BaseModel):
445
+ """
446
+ Defines the GoogleAIStudioCredentials class for accessing Google AI Studio using an API key.
447
+
448
+ Examples:
449
+ 1. Create credentials manually:
450
+ .. code-block:: python
451
+
452
+ google_credentials = GoogleAIStudioCredentials(api_key="your-api-key")
453
+
454
+ 2. Create credentials from environment:
455
+ .. code-block:: python
456
+
457
+ os.environ["GOOGLE_API_KEY"] = "your-api-key"
458
+ google_credentials = GoogleAIStudioCredentials.create_from_env()
459
+ """
460
+ api_key: Annotated[str, Field(
461
+ title="Api Key",
462
+ description="The Google AI Studio key. This attribute can be read from GOOGLE_API_KEY environment variable when creating GoogleAIStudioCredentials from environment.")]
463
+
464
+ @classmethod
465
+ def create_from_env(cls):
466
+ return cls(api_key=os.getenv("GOOGLE_API_KEY") or os.getenv("GEMINI_API_KEY"))
467
+
468
+ @model_validator(mode="after")
469
+ def validate_credentials(self):
470
+ if not self.api_key or not self.api_key.strip():
471
+ raise ValueError(
472
+ "The api_key is missing or empty. Please provide a valid value")
473
+ return self
474
+
475
+
476
+ class VertexAICredentials(BaseModel):
477
+ """
478
+ Defines the VertexAICredentials class for accessing Vertex AI using service account credentials.
479
+
480
+ Examples:
481
+ 1. Create credentials manually:
482
+ .. code-block:: python
483
+
484
+ vertex_credentials = VertexAICredentials(
485
+ credentials_path="path/to/service_account.json",
486
+ project_id="my-gcp-project",
487
+ location="us-central1"
488
+ )
489
+
490
+ 2. Create credentials from environment:
491
+ .. code-block:: python
492
+
493
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/service_account.json"
494
+ os.environ["GOOGLE_CLOUD_PROJECT"] = "my-gcp-project"
495
+ os.environ["GOOGLE_CLOUD_LOCATION"] = "us-central1"
496
+
497
+ vertex_ai_credentials = VertexAICredentials.create_from_env()
498
+ """
499
+ credentials_path: Annotated[str, Field(
500
+ title="Credentials Path",
501
+ description="Path to service-account JSON. This attribute can be read from GOOGLE_APPLICATION_CREDENTIALS environment variable when creating VertexAICredentials from environment.")]
502
+ project_id: Annotated[str, Field(
503
+ title="Project ID",
504
+ description="The Google Cloud project id. This attribute can be read from GOOGLE_CLOUD_PROJECT or GCLOUD_PROJECT environment variable when creating VertexAICredentials from environment.")]
505
+ location: Annotated[str, Field(
506
+ title="Location",
507
+ default="us-central1",
508
+ description="Vertex AI region. This attribute can be read from GOOGLE_CLOUD_LOCATION environment variable when creating VertexAICredentials from environment. By default us-central1 location is used.",
509
+ examples=["us-central1", "europe-west4"])]
510
+
511
+ @classmethod
512
+ def create_from_env(cls):
513
+ return cls(
514
+ credentials_path=os.getenv("GOOGLE_APPLICATION_CREDENTIALS"),
515
+ project_id=os.getenv("GOOGLE_CLOUD_PROJECT") or os.getenv(
516
+ "GCLOUD_PROJECT"),
517
+ location=os.getenv("GOOGLE_CLOUD_LOCATION", "us-central1"),
518
+ )
519
+
520
+ @model_validator(mode="after")
521
+ def validate_credentials(self):
522
+ missing_fields = []
523
+ if not self.credentials_path:
524
+ missing_fields.append("credentials_path")
525
+ if not self.project_id:
526
+ missing_fields.append("project_id")
527
+
528
+ if missing_fields:
529
+ raise ValueError(
530
+ f"Missing required Vertex AI fields: {', '.join(missing_fields)}, Please provide the missing fields ")
531
+ return self
532
+
533
+
534
+ class AWSBedrockCredentials(BaseModel):
535
+ """
536
+ Defines the AWSBedrockCredentials class for accessing AWS Bedrock using environment variables or manual input.
537
+
538
+ Examples:
539
+ 1. Create credentials manually:
540
+ .. code-block:: python
541
+
542
+ credentials = AWSBedrockCredentials(
543
+ aws_access_key_id="your-access-key-id",
544
+ aws_secret_access_key="your-secret-access-key",
545
+ aws_region_name="us-east-1",
546
+ aws_session_token="optional-session-token"
547
+ )
548
+
549
+ 2. Create credentials from environment:
550
+ .. code-block:: python
551
+
552
+ os.environ["AWS_ACCESS_KEY_ID"] = "your-access-key-id"
553
+ os.environ["AWS_DEFAULT_REGION"] = "us-east-1"
554
+ os.environ["AWS_SECRET_ACCESS_KEY"] = "your-secret-access-key"
555
+
556
+ credentials = AWSBedrockCredentials.create_from_env()
557
+ """
558
+
559
+ aws_access_key_id: Annotated[str | None, Field(
560
+ title="AWS Access Key ID",
561
+ description="The AWS access key id. This attribute value will be read from AWS_ACCESS_KEY_ID environment variable when creating AWSBedrockCredentials from environment."
562
+ )]
563
+ aws_secret_access_key: Annotated[str | None, Field(
564
+ title="AWS Secret Access Key",
565
+ description="The AWS secret access key. This attribute value will be read from AWS_SECRET_ACCESS_KEY environment variable when creating AWSBedrockCredentials from environment."
566
+ )]
567
+ aws_region_name: Annotated[str, Field(
568
+ title="AWS Region",
569
+ default="us-east-1",
570
+ description="AWS region. This attribute value will be read from AWS_DEFAULT_REGION environment variable when creating AWSBedrockCredentials from environment.",
571
+ examples=["us-east-1", "eu-west-1"]
572
+ )]
573
+ aws_session_token: Annotated[str | None, Field(
574
+ title="AWS Session Token",
575
+ description="Optional AWS session token for temporary credentials."
576
+ )]
577
+
578
+ @classmethod
579
+ def create_from_env(cls):
580
+ return cls(
581
+ aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
582
+ aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
583
+ aws_region_name=os.getenv("AWS_DEFAULT_REGION", "us-east-1"),
584
+ aws_session_token=os.getenv("AWS_SESSION_TOKEN")
585
+ )
586
+
587
+ @model_validator(mode="after")
588
+ def validate_credentials(self):
589
+ missing_fields = []
590
+ if not self.aws_access_key_id:
591
+ missing_fields.append("aws_access_key_id")
592
+ if not self.aws_secret_access_key:
593
+ missing_fields.append("aws_secret_access_key")
594
+
595
+ if missing_fields:
596
+ raise ValueError(
597
+ f"Missing required AWS credentials: {', '.join(missing_fields)}. "
598
+ f"Please provide the missing fields or set them via environment variables."
599
+ )
600
+
601
+
602
+ class WxoAIGatewayCredentials(BaseModel):
603
+ """
604
+ Defines the WxoAIGatewayCredentials class to specify the WXO AI Gateway details.
605
+
606
+ Examples:
607
+ 1. Create WxoAIGatewayCredentials with default parameters.
608
+ .. code-block:: python
609
+
610
+ wxo_gateway_credentials = WxoAIGatewayCredentials(api_key=api_key,
611
+ url=url)
612
+
613
+ 2. Create WxoAIGatewayCredentials by reading from environment variables.
614
+ .. code-block:: python
615
+
616
+ os.environ["WATSONX_APIKEY"] = "..."
617
+ os.environ["WXO_AI_GATEWAY_URL"] = "..."
618
+ wxo_gateway_credentials = WxoAIGatewayCredentials.create_from_env()
619
+ """
620
+ url: Annotated[str | None, Field(
621
+ description="WXO AI Gateway url. This attribute can be read from `WXO_AI_GATEWAY_URL` environment variable.")]
622
+ api_key: Annotated[str | None, Field(
623
+ description="IBM Cloud API key. This attribute can be obtained from the `WXAI_API_KEY`, `WATSONX_APIKEY`, or `WXG_API_KEY` environment variable")]
624
+
625
+ @classmethod
626
+ def create_from_env(cls):
627
+ api_key = get_environment_variable_value(
628
+ ["WXAI_API_KEY", "WATSONX_APIKEY", "WXG_API_KEY"])
629
+ url = os.getenv("WXO_AI_GATEWAY_URL")
630
+ return WxoAIGatewayCredentials(
631
+ url=url,
632
+ api_key=api_key
633
+ )