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.
- ibm_watsonx_gov/__init__.py +8 -0
- ibm_watsonx_gov/agent_catalog/__init__.py +8 -0
- ibm_watsonx_gov/agent_catalog/clients/__init__.py +14 -0
- ibm_watsonx_gov/agent_catalog/clients/ai_agent_client.py +333 -0
- ibm_watsonx_gov/agent_catalog/core/__init__.py +8 -0
- ibm_watsonx_gov/agent_catalog/core/agent_loader.py +202 -0
- ibm_watsonx_gov/agent_catalog/core/agents.py +134 -0
- ibm_watsonx_gov/agent_catalog/entities/__init__.py +8 -0
- ibm_watsonx_gov/agent_catalog/entities/ai_agent.py +599 -0
- ibm_watsonx_gov/agent_catalog/utils/__init__.py +8 -0
- ibm_watsonx_gov/agent_catalog/utils/constants.py +36 -0
- ibm_watsonx_gov/agent_catalog/utils/notebook_utils.py +70 -0
- ibm_watsonx_gov/ai_experiments/__init__.py +8 -0
- ibm_watsonx_gov/ai_experiments/ai_experiments_client.py +980 -0
- ibm_watsonx_gov/ai_experiments/utils/__init__.py +8 -0
- ibm_watsonx_gov/ai_experiments/utils/ai_experiment_utils.py +139 -0
- ibm_watsonx_gov/clients/__init__.py +0 -0
- ibm_watsonx_gov/clients/api_client.py +99 -0
- ibm_watsonx_gov/clients/segment_client.py +46 -0
- ibm_watsonx_gov/clients/usage_client.cp313-win_amd64.pyd +0 -0
- ibm_watsonx_gov/clients/wx_ai_client.py +87 -0
- ibm_watsonx_gov/config/__init__.py +14 -0
- ibm_watsonx_gov/config/agentic_ai_configuration.py +225 -0
- ibm_watsonx_gov/config/gen_ai_configuration.py +129 -0
- ibm_watsonx_gov/config/model_risk_configuration.py +173 -0
- ibm_watsonx_gov/config/predictive_ai_configuration.py +20 -0
- ibm_watsonx_gov/entities/__init__.py +8 -0
- ibm_watsonx_gov/entities/agentic_app.py +209 -0
- ibm_watsonx_gov/entities/agentic_evaluation_result.py +185 -0
- ibm_watsonx_gov/entities/ai_evaluation.py +290 -0
- ibm_watsonx_gov/entities/ai_experiment.py +419 -0
- ibm_watsonx_gov/entities/base_classes.py +134 -0
- ibm_watsonx_gov/entities/container.py +54 -0
- ibm_watsonx_gov/entities/credentials.py +633 -0
- ibm_watsonx_gov/entities/criteria.py +508 -0
- ibm_watsonx_gov/entities/enums.py +274 -0
- ibm_watsonx_gov/entities/evaluation_result.py +444 -0
- ibm_watsonx_gov/entities/foundation_model.py +490 -0
- ibm_watsonx_gov/entities/llm_judge.py +44 -0
- ibm_watsonx_gov/entities/locale.py +17 -0
- ibm_watsonx_gov/entities/mapping.py +49 -0
- ibm_watsonx_gov/entities/metric.py +211 -0
- ibm_watsonx_gov/entities/metric_threshold.py +36 -0
- ibm_watsonx_gov/entities/model_provider.py +329 -0
- ibm_watsonx_gov/entities/model_risk_result.py +43 -0
- ibm_watsonx_gov/entities/monitor.py +71 -0
- ibm_watsonx_gov/entities/prompt_setup.py +40 -0
- ibm_watsonx_gov/entities/state.py +22 -0
- ibm_watsonx_gov/entities/utils.py +99 -0
- ibm_watsonx_gov/evaluators/__init__.py +26 -0
- ibm_watsonx_gov/evaluators/agentic_evaluator.py +2725 -0
- ibm_watsonx_gov/evaluators/agentic_traces_evaluator.py +115 -0
- ibm_watsonx_gov/evaluators/base_evaluator.py +22 -0
- ibm_watsonx_gov/evaluators/impl/__init__.py +0 -0
- ibm_watsonx_gov/evaluators/impl/evaluate_metrics_impl.cp313-win_amd64.pyd +0 -0
- ibm_watsonx_gov/evaluators/impl/evaluate_model_risk_impl.cp313-win_amd64.pyd +0 -0
- ibm_watsonx_gov/evaluators/metrics_evaluator.py +187 -0
- ibm_watsonx_gov/evaluators/model_risk_evaluator.py +89 -0
- ibm_watsonx_gov/evaluators/traces_evaluator.py +93 -0
- ibm_watsonx_gov/metric_groups/answer_quality/answer_quality_decorator.py +66 -0
- ibm_watsonx_gov/metric_groups/content_safety/content_safety_decorator.py +76 -0
- ibm_watsonx_gov/metric_groups/readability/readability_decorator.py +59 -0
- ibm_watsonx_gov/metric_groups/retrieval_quality/retrieval_quality_decorator.py +63 -0
- ibm_watsonx_gov/metric_groups/usage/usage_decorator.py +58 -0
- ibm_watsonx_gov/metrics/__init__.py +74 -0
- ibm_watsonx_gov/metrics/answer_relevance/__init__.py +8 -0
- ibm_watsonx_gov/metrics/answer_relevance/answer_relevance_decorator.py +63 -0
- ibm_watsonx_gov/metrics/answer_relevance/answer_relevance_metric.py +260 -0
- ibm_watsonx_gov/metrics/answer_similarity/__init__.py +0 -0
- ibm_watsonx_gov/metrics/answer_similarity/answer_similarity_decorator.py +66 -0
- ibm_watsonx_gov/metrics/answer_similarity/answer_similarity_metric.py +219 -0
- ibm_watsonx_gov/metrics/average_precision/__init__.py +0 -0
- ibm_watsonx_gov/metrics/average_precision/average_precision_decorator.py +62 -0
- ibm_watsonx_gov/metrics/average_precision/average_precision_metric.py +174 -0
- ibm_watsonx_gov/metrics/base_metric_decorator.py +193 -0
- ibm_watsonx_gov/metrics/context_relevance/__init__.py +8 -0
- ibm_watsonx_gov/metrics/context_relevance/context_relevance_decorator.py +60 -0
- ibm_watsonx_gov/metrics/context_relevance/context_relevance_metric.py +414 -0
- ibm_watsonx_gov/metrics/cost/__init__.py +8 -0
- ibm_watsonx_gov/metrics/cost/cost_decorator.py +58 -0
- ibm_watsonx_gov/metrics/cost/cost_metric.py +155 -0
- ibm_watsonx_gov/metrics/duration/__init__.py +8 -0
- ibm_watsonx_gov/metrics/duration/duration_decorator.py +59 -0
- ibm_watsonx_gov/metrics/duration/duration_metric.py +111 -0
- ibm_watsonx_gov/metrics/evasiveness/__init__.py +8 -0
- ibm_watsonx_gov/metrics/evasiveness/evasiveness_decorator.py +61 -0
- ibm_watsonx_gov/metrics/evasiveness/evasiveness_metric.py +103 -0
- ibm_watsonx_gov/metrics/faithfulness/__init__.py +8 -0
- ibm_watsonx_gov/metrics/faithfulness/faithfulness_decorator.py +65 -0
- ibm_watsonx_gov/metrics/faithfulness/faithfulness_metric.py +254 -0
- ibm_watsonx_gov/metrics/hap/__init__.py +16 -0
- ibm_watsonx_gov/metrics/hap/hap_decorator.py +58 -0
- ibm_watsonx_gov/metrics/hap/hap_metric.py +98 -0
- ibm_watsonx_gov/metrics/hap/input_hap_metric.py +104 -0
- ibm_watsonx_gov/metrics/hap/output_hap_metric.py +110 -0
- ibm_watsonx_gov/metrics/harm/__init__.py +8 -0
- ibm_watsonx_gov/metrics/harm/harm_decorator.py +60 -0
- ibm_watsonx_gov/metrics/harm/harm_metric.py +103 -0
- ibm_watsonx_gov/metrics/harm_engagement/__init__.py +8 -0
- ibm_watsonx_gov/metrics/harm_engagement/harm_engagement_decorator.py +61 -0
- ibm_watsonx_gov/metrics/harm_engagement/harm_engagement_metric.py +103 -0
- ibm_watsonx_gov/metrics/hit_rate/__init__.py +0 -0
- ibm_watsonx_gov/metrics/hit_rate/hit_rate_decorator.py +59 -0
- ibm_watsonx_gov/metrics/hit_rate/hit_rate_metric.py +167 -0
- ibm_watsonx_gov/metrics/input_token_count/__init__.py +8 -0
- ibm_watsonx_gov/metrics/input_token_count/input_token_count_decorator.py +58 -0
- ibm_watsonx_gov/metrics/input_token_count/input_token_count_metric.py +112 -0
- ibm_watsonx_gov/metrics/jailbreak/__init__.py +8 -0
- ibm_watsonx_gov/metrics/jailbreak/jailbreak_decorator.py +60 -0
- ibm_watsonx_gov/metrics/jailbreak/jailbreak_metric.py +103 -0
- ibm_watsonx_gov/metrics/keyword_detection/keyword_detection_decorator.py +58 -0
- ibm_watsonx_gov/metrics/keyword_detection/keyword_detection_metric.py +111 -0
- ibm_watsonx_gov/metrics/llm_validation/__init__.py +8 -0
- ibm_watsonx_gov/metrics/llm_validation/evaluation_criteria.py +84 -0
- ibm_watsonx_gov/metrics/llm_validation/llm_validation_constants.py +24 -0
- ibm_watsonx_gov/metrics/llm_validation/llm_validation_decorator.py +54 -0
- ibm_watsonx_gov/metrics/llm_validation/llm_validation_impl.py +525 -0
- ibm_watsonx_gov/metrics/llm_validation/llm_validation_metric.py +258 -0
- ibm_watsonx_gov/metrics/llm_validation/llm_validation_prompts.py +106 -0
- ibm_watsonx_gov/metrics/llmaj/__init__.py +0 -0
- ibm_watsonx_gov/metrics/llmaj/llmaj_metric.py +298 -0
- ibm_watsonx_gov/metrics/ndcg/__init__.py +0 -0
- ibm_watsonx_gov/metrics/ndcg/ndcg_decorator.py +61 -0
- ibm_watsonx_gov/metrics/ndcg/ndcg_metric.py +166 -0
- ibm_watsonx_gov/metrics/output_token_count/__init__.py +8 -0
- ibm_watsonx_gov/metrics/output_token_count/output_token_count_decorator.py +58 -0
- ibm_watsonx_gov/metrics/output_token_count/output_token_count_metric.py +112 -0
- ibm_watsonx_gov/metrics/pii/__init__.py +16 -0
- ibm_watsonx_gov/metrics/pii/input_pii_metric.py +102 -0
- ibm_watsonx_gov/metrics/pii/output_pii_metric.py +107 -0
- ibm_watsonx_gov/metrics/pii/pii_decorator.py +59 -0
- ibm_watsonx_gov/metrics/pii/pii_metric.py +96 -0
- ibm_watsonx_gov/metrics/profanity/__init__.py +8 -0
- ibm_watsonx_gov/metrics/profanity/profanity_decorator.py +60 -0
- ibm_watsonx_gov/metrics/profanity/profanity_metric.py +103 -0
- ibm_watsonx_gov/metrics/prompt_safety_risk/__init__.py +8 -0
- ibm_watsonx_gov/metrics/prompt_safety_risk/prompt_safety_risk_decorator.py +57 -0
- ibm_watsonx_gov/metrics/prompt_safety_risk/prompt_safety_risk_metric.py +128 -0
- ibm_watsonx_gov/metrics/reciprocal_rank/__init__.py +0 -0
- ibm_watsonx_gov/metrics/reciprocal_rank/reciprocal_rank_decorator.py +62 -0
- ibm_watsonx_gov/metrics/reciprocal_rank/reciprocal_rank_metric.py +162 -0
- ibm_watsonx_gov/metrics/regex_detection/regex_detection_decorator.py +58 -0
- ibm_watsonx_gov/metrics/regex_detection/regex_detection_metric.py +106 -0
- ibm_watsonx_gov/metrics/retrieval_precision/__init__.py +0 -0
- ibm_watsonx_gov/metrics/retrieval_precision/retrieval_precision_decorator.py +62 -0
- ibm_watsonx_gov/metrics/retrieval_precision/retrieval_precision_metric.py +170 -0
- ibm_watsonx_gov/metrics/sexual_content/__init__.py +8 -0
- ibm_watsonx_gov/metrics/sexual_content/sexual_content_decorator.py +61 -0
- ibm_watsonx_gov/metrics/sexual_content/sexual_content_metric.py +103 -0
- ibm_watsonx_gov/metrics/social_bias/__init__.py +8 -0
- ibm_watsonx_gov/metrics/social_bias/social_bias_decorator.py +62 -0
- ibm_watsonx_gov/metrics/social_bias/social_bias_metric.py +103 -0
- ibm_watsonx_gov/metrics/status/__init__.py +0 -0
- ibm_watsonx_gov/metrics/status/status_metric.py +113 -0
- ibm_watsonx_gov/metrics/text_grade_level/__init__.py +8 -0
- ibm_watsonx_gov/metrics/text_grade_level/text_grade_level_decorator.py +59 -0
- ibm_watsonx_gov/metrics/text_grade_level/text_grade_level_metric.py +127 -0
- ibm_watsonx_gov/metrics/text_reading_ease/__init__.py +8 -0
- ibm_watsonx_gov/metrics/text_reading_ease/text_reading_ease_decorator.py +59 -0
- ibm_watsonx_gov/metrics/text_reading_ease/text_reading_ease_metric.py +123 -0
- ibm_watsonx_gov/metrics/tool_call_accuracy/__init__.py +0 -0
- ibm_watsonx_gov/metrics/tool_call_accuracy/tool_call_accuracy_decorator.py +67 -0
- ibm_watsonx_gov/metrics/tool_call_accuracy/tool_call_accuracy_metric.py +162 -0
- ibm_watsonx_gov/metrics/tool_call_parameter_accuracy/__init__.py +0 -0
- ibm_watsonx_gov/metrics/tool_call_parameter_accuracy/tool_call_parameter_accuracy_decorator.py +68 -0
- ibm_watsonx_gov/metrics/tool_call_parameter_accuracy/tool_call_parameter_accuracy_metric.py +151 -0
- ibm_watsonx_gov/metrics/tool_call_relevance/__init__.py +0 -0
- ibm_watsonx_gov/metrics/tool_call_relevance/tool_call_relevance_decorator.py +71 -0
- ibm_watsonx_gov/metrics/tool_call_relevance/tool_call_relevance_metric.py +166 -0
- ibm_watsonx_gov/metrics/tool_call_syntactic_accuracy/__init__.py +0 -0
- ibm_watsonx_gov/metrics/tool_call_syntactic_accuracy/tool_call_syntactic_accuracy_decorator.py +66 -0
- ibm_watsonx_gov/metrics/tool_call_syntactic_accuracy/tool_call_syntactic_accuracy_metric.py +121 -0
- ibm_watsonx_gov/metrics/topic_relevance/__init__.py +8 -0
- ibm_watsonx_gov/metrics/topic_relevance/topic_relevance_decorator.py +57 -0
- ibm_watsonx_gov/metrics/topic_relevance/topic_relevance_metric.py +106 -0
- ibm_watsonx_gov/metrics/unethical_behavior/__init__.py +8 -0
- ibm_watsonx_gov/metrics/unethical_behavior/unethical_behavior_decorator.py +61 -0
- ibm_watsonx_gov/metrics/unethical_behavior/unethical_behavior_metric.py +103 -0
- ibm_watsonx_gov/metrics/unsuccessful_requests/__init__.py +0 -0
- ibm_watsonx_gov/metrics/unsuccessful_requests/unsuccessful_requests_decorator.py +66 -0
- ibm_watsonx_gov/metrics/unsuccessful_requests/unsuccessful_requests_metric.py +128 -0
- ibm_watsonx_gov/metrics/user_id/__init__.py +0 -0
- ibm_watsonx_gov/metrics/user_id/user_id_metric.py +111 -0
- ibm_watsonx_gov/metrics/utils.py +440 -0
- ibm_watsonx_gov/metrics/violence/__init__.py +8 -0
- ibm_watsonx_gov/metrics/violence/violence_decorator.py +60 -0
- ibm_watsonx_gov/metrics/violence/violence_metric.py +103 -0
- ibm_watsonx_gov/prompt_evaluator/__init__.py +9 -0
- ibm_watsonx_gov/prompt_evaluator/impl/__init__.py +8 -0
- ibm_watsonx_gov/prompt_evaluator/impl/prompt_evaluator_impl.py +554 -0
- ibm_watsonx_gov/prompt_evaluator/impl/pta_lifecycle_evaluator.py +2332 -0
- ibm_watsonx_gov/prompt_evaluator/prompt_evaluator.py +262 -0
- ibm_watsonx_gov/providers/__init__.py +8 -0
- ibm_watsonx_gov/providers/detectors_provider.cp313-win_amd64.pyd +0 -0
- ibm_watsonx_gov/providers/detectors_provider.py +415 -0
- ibm_watsonx_gov/providers/eval_assist_provider.cp313-win_amd64.pyd +0 -0
- ibm_watsonx_gov/providers/eval_assist_provider.py +266 -0
- ibm_watsonx_gov/providers/inference_engines/__init__.py +0 -0
- ibm_watsonx_gov/providers/inference_engines/custom_inference_engine.py +165 -0
- ibm_watsonx_gov/providers/inference_engines/portkey_inference_engine.py +57 -0
- ibm_watsonx_gov/providers/llmevalkit/__init__.py +0 -0
- ibm_watsonx_gov/providers/llmevalkit/ciso_agent/main.py +516 -0
- ibm_watsonx_gov/providers/llmevalkit/ciso_agent/preprocess_log.py +111 -0
- ibm_watsonx_gov/providers/llmevalkit/ciso_agent/utils.py +186 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/README.md +411 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/__init__.py +27 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/README.md +306 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/__init__.py +89 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/__init__.py +30 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/base.py +411 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/code_agent.py +1254 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/exact_match.py +134 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/fuzzy_string.py +104 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/hybrid.py +516 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/comparators/llm_judge.py +1882 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/pipeline.py +387 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/types.py +178 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/comparison/utils.py +298 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/consts.py +33 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/__init__.py +31 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/base.py +26 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_call/__init__.py +4 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_call/general.py +46 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_call/general_metrics.json +783 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_call/general_metrics_runtime.json +580 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_selection/__init__.py +6 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_selection/function_selection.py +28 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_selection/function_selection_metrics.json +599 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/function_selection/function_selection_metrics_runtime.json +477 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/loader.py +259 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/parameter/__init__.py +7 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/parameter/parameter.py +52 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/parameter/parameter_metrics.json +613 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/parameter/parameter_metrics_runtime.json +489 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/trajectory/__init__.py +7 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/trajectory/trajectory.py +43 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/metrics/trajectory/trajectory_metrics.json +161 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/__init__.py +0 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/adapters.py +102 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/pipeline.py +355 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/semantic_checker.py +816 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/static_checker.py +297 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/transformation_prompts.py +509 -0
- ibm_watsonx_gov/providers/llmevalkit/function_calling/pipeline/types.py +596 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/README.md +375 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/__init__.py +137 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/base.py +426 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/output_parser.py +364 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/__init__.py +0 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/consts.py +7 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/ibm_watsonx_ai/__init__.py +0 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/ibm_watsonx_ai/ibm_watsonx_ai.py +656 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/litellm/__init__.py +0 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/litellm/litellm.py +509 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/litellm/rits.py +224 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/litellm/watsonx.py +60 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/mock_llm_client.py +75 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/openai/__init__.py +0 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/openai/openai.py +639 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/wxo_ai_gateway/__init__.py +0 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/wxo_ai_gateway/wxo_ai_gateway.py +134 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/providers/wxo_ai_gateway/wxo_ai_gateway_inference.py +214 -0
- ibm_watsonx_gov/providers/llmevalkit/llm/types.py +136 -0
- ibm_watsonx_gov/providers/llmevalkit/metrics/__init__.py +4 -0
- ibm_watsonx_gov/providers/llmevalkit/metrics/field.py +255 -0
- ibm_watsonx_gov/providers/llmevalkit/metrics/metric.py +332 -0
- ibm_watsonx_gov/providers/llmevalkit/metrics/metrics_runner.py +188 -0
- ibm_watsonx_gov/providers/llmevalkit/metrics/prompt.py +403 -0
- ibm_watsonx_gov/providers/llmevalkit/metrics/utils.py +46 -0
- ibm_watsonx_gov/providers/llmevalkit/prompt/__init__.py +0 -0
- ibm_watsonx_gov/providers/llmevalkit/prompt/runner.py +144 -0
- ibm_watsonx_gov/providers/tool_call_metric_provider.py +455 -0
- ibm_watsonx_gov/providers/unitxt_provider.cp313-win_amd64.pyd +0 -0
- ibm_watsonx_gov/tools/__init__.py +10 -0
- ibm_watsonx_gov/tools/clients/__init__.py +11 -0
- ibm_watsonx_gov/tools/clients/ai_tool_client.py +405 -0
- ibm_watsonx_gov/tools/clients/detector_client.py +82 -0
- ibm_watsonx_gov/tools/core/__init__.py +8 -0
- ibm_watsonx_gov/tools/core/tool_loader.py +237 -0
- ibm_watsonx_gov/tools/entities/__init__.py +8 -0
- ibm_watsonx_gov/tools/entities/ai_tools.py +435 -0
- ibm_watsonx_gov/tools/onboarding/create/answer_relevance_detector.json +57 -0
- ibm_watsonx_gov/tools/onboarding/create/chromadb_retrieval_tool.json +63 -0
- ibm_watsonx_gov/tools/onboarding/create/context_relevance_detector.json +57 -0
- ibm_watsonx_gov/tools/onboarding/create/duduckgo_search_tool.json +53 -0
- ibm_watsonx_gov/tools/onboarding/create/google_search_tool.json +62 -0
- ibm_watsonx_gov/tools/onboarding/create/hap_detector.json +70 -0
- ibm_watsonx_gov/tools/onboarding/create/jailbreak_detector.json +70 -0
- ibm_watsonx_gov/tools/onboarding/create/pii_detector.json +36 -0
- ibm_watsonx_gov/tools/onboarding/create/prompt_safety_risk_detector.json +69 -0
- ibm_watsonx_gov/tools/onboarding/create/topic_relevance_detector.json +57 -0
- ibm_watsonx_gov/tools/onboarding/create/weather_tool.json +39 -0
- ibm_watsonx_gov/tools/onboarding/create/webcrawler_tool.json +34 -0
- ibm_watsonx_gov/tools/onboarding/create/wikipedia_search_tool.json +53 -0
- ibm_watsonx_gov/tools/onboarding/delete/delete_tools.json +4 -0
- ibm_watsonx_gov/tools/onboarding/update/google_search_tool.json +38 -0
- ibm_watsonx_gov/tools/ootb/__init__.py +8 -0
- ibm_watsonx_gov/tools/ootb/detectors/__init__.py +8 -0
- ibm_watsonx_gov/tools/ootb/detectors/hap_detector_tool.py +109 -0
- ibm_watsonx_gov/tools/ootb/detectors/jailbreak_detector_tool.py +104 -0
- ibm_watsonx_gov/tools/ootb/detectors/pii_detector_tool.py +83 -0
- ibm_watsonx_gov/tools/ootb/detectors/prompt_safety_risk_detector_tool.py +111 -0
- ibm_watsonx_gov/tools/ootb/detectors/topic_relevance_detector_tool.py +101 -0
- ibm_watsonx_gov/tools/ootb/rag/__init__.py +8 -0
- ibm_watsonx_gov/tools/ootb/rag/answer_relevance_detector_tool.py +119 -0
- ibm_watsonx_gov/tools/ootb/rag/context_relevance_detector_tool.py +118 -0
- ibm_watsonx_gov/tools/ootb/search/__init__.py +8 -0
- ibm_watsonx_gov/tools/ootb/search/duckduckgo_search_tool.py +62 -0
- ibm_watsonx_gov/tools/ootb/search/google_search_tool.py +105 -0
- ibm_watsonx_gov/tools/ootb/search/weather_tool.py +95 -0
- ibm_watsonx_gov/tools/ootb/search/web_crawler_tool.py +69 -0
- ibm_watsonx_gov/tools/ootb/search/wikipedia_search_tool.py +63 -0
- ibm_watsonx_gov/tools/ootb/vectordb/__init__.py +8 -0
- ibm_watsonx_gov/tools/ootb/vectordb/chromadb_retriever_tool.py +111 -0
- ibm_watsonx_gov/tools/rest_api/__init__.py +10 -0
- ibm_watsonx_gov/tools/rest_api/restapi_tool.py +72 -0
- ibm_watsonx_gov/tools/schemas/__init__.py +10 -0
- ibm_watsonx_gov/tools/schemas/search_tool_schema.py +46 -0
- ibm_watsonx_gov/tools/schemas/vectordb_retrieval_schema.py +55 -0
- ibm_watsonx_gov/tools/utils/__init__.py +14 -0
- ibm_watsonx_gov/tools/utils/constants.py +69 -0
- ibm_watsonx_gov/tools/utils/display_utils.py +38 -0
- ibm_watsonx_gov/tools/utils/environment.py +108 -0
- ibm_watsonx_gov/tools/utils/package_utils.py +40 -0
- ibm_watsonx_gov/tools/utils/platform_url_mapping.cp313-win_amd64.pyd +0 -0
- ibm_watsonx_gov/tools/utils/python_utils.py +68 -0
- ibm_watsonx_gov/tools/utils/tool_utils.py +206 -0
- ibm_watsonx_gov/traces/__init__.py +8 -0
- ibm_watsonx_gov/traces/span_exporter.py +195 -0
- ibm_watsonx_gov/traces/span_node.py +251 -0
- ibm_watsonx_gov/traces/span_util.py +153 -0
- ibm_watsonx_gov/traces/trace_utils.py +1074 -0
- ibm_watsonx_gov/utils/__init__.py +8 -0
- ibm_watsonx_gov/utils/aggregation_util.py +346 -0
- ibm_watsonx_gov/utils/async_util.py +62 -0
- ibm_watsonx_gov/utils/authenticator.py +144 -0
- ibm_watsonx_gov/utils/constants.py +15 -0
- ibm_watsonx_gov/utils/errors.py +40 -0
- ibm_watsonx_gov/utils/gov_sdk_logger.py +39 -0
- ibm_watsonx_gov/utils/insights_generator.py +1285 -0
- ibm_watsonx_gov/utils/python_utils.py +425 -0
- ibm_watsonx_gov/utils/rest_util.py +73 -0
- ibm_watsonx_gov/utils/segment_batch_manager.py +162 -0
- ibm_watsonx_gov/utils/singleton_meta.py +25 -0
- ibm_watsonx_gov/utils/url_mapping.cp313-win_amd64.pyd +0 -0
- ibm_watsonx_gov/utils/validation_util.py +126 -0
- ibm_watsonx_gov/visualizations/__init__.py +13 -0
- ibm_watsonx_gov/visualizations/metric_descriptions.py +57 -0
- ibm_watsonx_gov/visualizations/model_insights.py +1304 -0
- ibm_watsonx_gov/visualizations/visualization_utils.py +75 -0
- ibm_watsonx_gov-1.3.3.dist-info/METADATA +93 -0
- ibm_watsonx_gov-1.3.3.dist-info/RECORD +353 -0
- ibm_watsonx_gov-1.3.3.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
# LLM Client Library
|
|
2
|
+
|
|
3
|
+
This directory contains a flexible, extensible framework for working with any large-language-model (LLM) provider in a uniform way, including:
|
|
4
|
+
|
|
5
|
+
- **Unified interface** for multiple LLM providers (OpenAI, Azure OpenAI, IBM WatsonX, LiteLLM, RITS)
|
|
6
|
+
- **Tool calling support** across all providers with standardized response format
|
|
7
|
+
- **Structured output validation** with JSON Schema and Pydantic models
|
|
8
|
+
- **Optional dependencies** for each provider to keep installations lean
|
|
9
|
+
- **Robust error handling** and retry logic
|
|
10
|
+
- **Sync and async support** throughout
|
|
11
|
+
- **Observability hooks** for monitoring and debugging
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
llm/
|
|
15
|
+
├── __init__.py # Main imports and provider registration
|
|
16
|
+
├── base.py # Core LLMClient abstract base class
|
|
17
|
+
├── output_parser.py # ValidatingLLMClient with schema enforcement
|
|
18
|
+
├── README.md # This documentation
|
|
19
|
+
├── providers/
|
|
20
|
+
│ ├── openai/
|
|
21
|
+
│ │ └── openai.py # OpenAI provider with structured output support
|
|
22
|
+
│ ├── ibm_watsonx_ai/
|
|
23
|
+
│ │ └── ibm_watsonx_ai.py # IBM WatsonX provider with structured output
|
|
24
|
+
│ └── litellm/
|
|
25
|
+
│ ├── litellm.py # LiteLLM base provider
|
|
26
|
+
│ ├── rits.py # RITS-hosted models via LiteLLM
|
|
27
|
+
│ └── watsonx.py # WatsonX-hosted models via LiteLLM
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Install the core library:
|
|
35
|
+
```bash
|
|
36
|
+
pip install llmevalkit
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Install with specific provider dependencies:
|
|
40
|
+
```bash
|
|
41
|
+
# OpenAI support
|
|
42
|
+
pip install llmevalkit[openai]
|
|
43
|
+
|
|
44
|
+
# LiteLLM support
|
|
45
|
+
pip install llmevalkit[litellm]
|
|
46
|
+
|
|
47
|
+
# IBM WatsonX support
|
|
48
|
+
pip install llmevalkit[ibm_watsonx_ai]
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from llmevalkit.llm import get_llm
|
|
57
|
+
|
|
58
|
+
# Get any provider
|
|
59
|
+
WatsonXLiteLLMClient = get_llm("litellm.watsonx")
|
|
60
|
+
|
|
61
|
+
client = WatsonXLiteLLMClient(
|
|
62
|
+
model_name="meta-llama/llama-3-3-70b-instruct"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# Generate text
|
|
66
|
+
response = client.generate("Explain quantum computing")
|
|
67
|
+
print(response)
|
|
68
|
+
|
|
69
|
+
# Use structured output
|
|
70
|
+
WatsonXLiteLLMClientOutputVal = get_llm("litellm.watsonx.output_val")
|
|
71
|
+
structured_client = WatsonXLiteLLMClientOutputVal(
|
|
72
|
+
model_name="meta-llama/llama-3-3-70b-instruct",
|
|
73
|
+
include_schema_in_system_prompt=True, # Whether to add the Json Schema to the system prompt, or not
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
from pydantic import BaseModel
|
|
77
|
+
class Person(BaseModel):
|
|
78
|
+
name: str
|
|
79
|
+
age: int
|
|
80
|
+
|
|
81
|
+
person = structured_client.generate(
|
|
82
|
+
"Extract: John Doe, 30 years old",
|
|
83
|
+
schema=Person,
|
|
84
|
+
max_retries=2
|
|
85
|
+
)
|
|
86
|
+
print(f"Name: {person.name}, Age: {person.age}")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
You can list all available registered llm clients with:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from llmevalkit.llm import list_available_llms
|
|
93
|
+
|
|
94
|
+
print(f"Available LiteLLM providers: {list_available_llms()}")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Example output:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
"Available LiteLLM providers: ['litellm', 'litellm.output_val', 'litellm.rits', 'litellm.rits.output_val', 'litellm.watsonx', 'litellm.watsonx.output_val', 'openai.sync', 'openai.async', 'openai.sync.output_val', 'openai.async.output_val', 'azure_openai.sync', 'azure_openai.async', 'azure_openai.sync.output_val', 'azure_openai.async.output_val', 'watsonx', 'watsonx.output_val']"
|
|
101
|
+
```
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Examples
|
|
105
|
+
|
|
106
|
+
Comprehensive examples for each client are available in the `examples/llm` directory:
|
|
107
|
+
|
|
108
|
+
- **`azure_openai.py`** - Azure OpenAI client examples with Azure-specific configurations
|
|
109
|
+
- **`litellm_rits.py`** - LiteLLM RITS client examples with hosted models
|
|
110
|
+
- **`litellm_watsonx.py`** - LiteLLM WatsonX client examples with Granite models
|
|
111
|
+
- **`ibm_watsonx_ai.py`** - IBM WatsonX AI client examples with native IBM SDK
|
|
112
|
+
|
|
113
|
+
Each example file demonstrates:
|
|
114
|
+
- Basic text generation (with and without output validation)
|
|
115
|
+
- Tool calling functionality
|
|
116
|
+
- Async and sync usage patterns
|
|
117
|
+
- Error handling and observability hooks
|
|
118
|
+
- Structured output with Pydantic models and JSON schemas
|
|
119
|
+
|
|
120
|
+
To run an example:
|
|
121
|
+
```bash
|
|
122
|
+
python llmevalkit/examples/llm/azure_openai_example.py
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Core Components
|
|
128
|
+
|
|
129
|
+
### `base.py`
|
|
130
|
+
|
|
131
|
+
- **`LLMClient`**
|
|
132
|
+
The abstract foundation for any provider.
|
|
133
|
+
- Manages a registry of implementations (`register_llm`, `get_llm`).
|
|
134
|
+
- Handles initialization of the underlying SDK client.
|
|
135
|
+
- Exposes four main methods:
|
|
136
|
+
- `generate` (sync single)
|
|
137
|
+
- `generate_async` (async single)
|
|
138
|
+
- Emits observability hooks around every call (`before_generate`, `after_generate`, `error`).
|
|
139
|
+
- Requires subclasses to register their own `MethodConfig` entries (mapping "chat", "text", etc., to real SDK methods) and to implement a `_parse_llm_response(raw)` method to extract plain-text from the provider's raw response.
|
|
140
|
+
|
|
141
|
+
### `output_parser.py`
|
|
142
|
+
|
|
143
|
+
- **`ValidatingLLMClient`**
|
|
144
|
+
An extension of `LLMClient` that adds:
|
|
145
|
+
1. **Output enforcement** against a schema (JSON Schema dict, Pydantic model, or basic Python type).
|
|
146
|
+
2. Automatic **prompt injection** of system-level instructions ("Only output JSON matching this schema").
|
|
147
|
+
3. **Cleaning** of raw responses (stripping Markdown, extracting fenced JSON).
|
|
148
|
+
4. **Retries** for malformed outputs—only the bad items are retried.
|
|
149
|
+
5. Methods mirror `LLMClient` but return fully-parsed Python objects (or Pydantic instances) instead of raw text.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Available Providers
|
|
154
|
+
|
|
155
|
+
All provider adapters live under `providers/`. They subclass either `LLMClient` (plain) or `ValidatingLLMClient` (with output validation), and register themselves with a name you can pass to `get_llm(...)`.
|
|
156
|
+
|
|
157
|
+
### OpenAI Adapter
|
|
158
|
+
**Path:** `providers/openai/openai.py`
|
|
159
|
+
**Registered names:**
|
|
160
|
+
- `openai.sync` -> synchronous client
|
|
161
|
+
- `openai.async` -> asynchronous client
|
|
162
|
+
- `openai.sync.output_val` -> synchronous client with output validation
|
|
163
|
+
- `openai.async.output_val` -> asynchronous client with output validation
|
|
164
|
+
|
|
165
|
+
**Features:**
|
|
166
|
+
- Wraps `openai.OpenAI` SDK.
|
|
167
|
+
- Supports text & chat, sync & async.
|
|
168
|
+
- Tool calling support with structured responses.
|
|
169
|
+
- Streaming support.
|
|
170
|
+
|
|
171
|
+
**Environment:**
|
|
172
|
+
Set `OPENAI_API_KEY` in your environment, or pass it to the constructor.
|
|
173
|
+
|
|
174
|
+
**Example:**
|
|
175
|
+
```python
|
|
176
|
+
from llmevalkit.llm import get_llm
|
|
177
|
+
|
|
178
|
+
# Basic usage
|
|
179
|
+
client = get_llm("openai.sync")(api_key="your-key")
|
|
180
|
+
response = client.generate("Hello, world!", model="gpt-4o")
|
|
181
|
+
|
|
182
|
+
# With output validation
|
|
183
|
+
client = get_llm("openai.sync.output_val")(api_key="your-key")
|
|
184
|
+
from pydantic import BaseModel
|
|
185
|
+
class Person(BaseModel):
|
|
186
|
+
name: str
|
|
187
|
+
age: int
|
|
188
|
+
|
|
189
|
+
person = client.generate(
|
|
190
|
+
"Create a person",
|
|
191
|
+
model="gpt-4o",
|
|
192
|
+
schema=Person,
|
|
193
|
+
include_schema_in_system_prompt=True, # Whether to add the Json Schema to the system prompt, or not
|
|
194
|
+
)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Azure OpenAI Adapter
|
|
198
|
+
**Path:** `providers/openai/openai.py`
|
|
199
|
+
**Registered names:**
|
|
200
|
+
- `azure_openai.sync` -> synchronous client
|
|
201
|
+
- `azure_openai.async` -> asynchronous client
|
|
202
|
+
- `azure_openai.sync.output_val` -> synchronous client with output validation
|
|
203
|
+
- `azure_openai.async.output_val` -> asynchronous client with output validation
|
|
204
|
+
|
|
205
|
+
**Features:**
|
|
206
|
+
- Wraps `openai.AzureOpenAI` SDK.
|
|
207
|
+
- Supports Azure-specific configurations (endpoint, API version, deployment).
|
|
208
|
+
- Tool calling support with structured responses.
|
|
209
|
+
- Streaming support.
|
|
210
|
+
|
|
211
|
+
**Example:**
|
|
212
|
+
```python
|
|
213
|
+
from llmevalkit.llm import get_llm
|
|
214
|
+
|
|
215
|
+
client = get_llm("azure_openai.sync")(
|
|
216
|
+
api_key="your-key",
|
|
217
|
+
azure_endpoint="https://your-resource.openai.azure.com/",
|
|
218
|
+
api_version="2024-08-01-preview"
|
|
219
|
+
)
|
|
220
|
+
response = client.generate("Hello, world!", model="gpt-4o-2024-08-06")
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### LiteLLM Adapter
|
|
224
|
+
**Path:** `providers/litellm/litellm.py`
|
|
225
|
+
**Registered names:**
|
|
226
|
+
- `litellm` -> plain text adapter
|
|
227
|
+
- `litellm.output_val` -> validating adapter
|
|
228
|
+
|
|
229
|
+
**Features:**
|
|
230
|
+
- Wraps any model served by the `litellm` SDK.
|
|
231
|
+
- Supports chat, text APIs, both sync & async.
|
|
232
|
+
- The **plain** adapter returns raw strings; the **output-val** adapter enforces JSON schemas, Pydantic models, or basic types with retries.
|
|
233
|
+
- Streaming support.
|
|
234
|
+
|
|
235
|
+
### RITS-Hosted LiteLLM Adapter
|
|
236
|
+
**Path:** `providers/litellm/rits.py`
|
|
237
|
+
**Registered names:**
|
|
238
|
+
- `litellm.rits` -> plain text adapter
|
|
239
|
+
- `litellm.rits.output_val` -> validating adapter
|
|
240
|
+
|
|
241
|
+
**Features:**
|
|
242
|
+
- Subclasses the **validating** LiteLLM adapter.
|
|
243
|
+
- Automatically sets:
|
|
244
|
+
- `model_name="hosted_vllm/{model_name}"`
|
|
245
|
+
- `api_base="{RITS_API_URL}/{model_url}/v1"`
|
|
246
|
+
- `headers` with your `RITS_API_KEY`
|
|
247
|
+
- `guided_decoding_backend=XGRAMMAR`
|
|
248
|
+
|
|
249
|
+
**Environment variables:**
|
|
250
|
+
- `RITS_API_KEY` (your API key)
|
|
251
|
+
- `RITS_API_URL` (RITS API url)
|
|
252
|
+
|
|
253
|
+
**Example:**
|
|
254
|
+
```python
|
|
255
|
+
from llmevalkit.llm import get_llm
|
|
256
|
+
|
|
257
|
+
client = get_llm("litellm.rits.output_val")(
|
|
258
|
+
model_name="ibm-granite/granite-3.1-8b-instruct"
|
|
259
|
+
model_url="granite-3-1-8b-instruct" # The short model name that is added to the url (if not given - uses rits api to get this name)
|
|
260
|
+
include_schema_in_system_prompt=True, # Whether to add the Json Schema to the system prompt, or not (recommended in RITS - as the response_format in LiteLLM parameter is not working well with RITS)
|
|
261
|
+
)
|
|
262
|
+
result: int = client.generate("Compute 2+2", schema=int, max_retries=1)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Watsonx-Hosted LiteLLM Adapter
|
|
266
|
+
**Path:** `providers/litellm/watsonx.py`
|
|
267
|
+
**Registered names:**
|
|
268
|
+
- `litellm.watsonx` -> plain text adapter
|
|
269
|
+
- `litellm.watsonx.output_val` -> validating adapter
|
|
270
|
+
|
|
271
|
+
**Features:**
|
|
272
|
+
- Like RITS, but for IBM Watsonx.
|
|
273
|
+
- Automatically prefixes `model_name="watsonx/{model_name}"`.
|
|
274
|
+
- Inherits all the validation and retry logic from the validating LiteLLM base class.
|
|
275
|
+
|
|
276
|
+
**Environment variables:**
|
|
277
|
+
- `WX_API_KEY`
|
|
278
|
+
- `WX_PROJECT_ID`
|
|
279
|
+
- `WX_URL`
|
|
280
|
+
|
|
281
|
+
**Example:**
|
|
282
|
+
```python
|
|
283
|
+
from llmevalkit.llm import get_llm
|
|
284
|
+
|
|
285
|
+
client = get_llm("litellm.watsonx.output_val")(
|
|
286
|
+
model_name="meta-llama/llama-3-3-70b-instruct"
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
class Weather(BaseModel):
|
|
290
|
+
city: str
|
|
291
|
+
temperature_c: float
|
|
292
|
+
condition: str
|
|
293
|
+
|
|
294
|
+
weather = client.generate(
|
|
295
|
+
"Return weather for Rome with 25C and sunny condition.",
|
|
296
|
+
schema=Weather,
|
|
297
|
+
max_retries=2,
|
|
298
|
+
include_schema_in_system_prompt=True, # Whether to add the Json Schema to the system prompt, or not
|
|
299
|
+
)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### IBM WatsonX AI Adapter
|
|
303
|
+
**Path:** `providers/ibm_watsonx_ai/ibm_watsonx_ai.py`
|
|
304
|
+
**Registered names:**
|
|
305
|
+
- `watsonx` -> plain text adapter
|
|
306
|
+
- `watsonx.output_val` -> validating adapter
|
|
307
|
+
|
|
308
|
+
**Features:**
|
|
309
|
+
- Wraps the native IBM WatsonX AI SDK.
|
|
310
|
+
- Advanced generation parameters (temperature, etc.).
|
|
311
|
+
|
|
312
|
+
**Example:**
|
|
313
|
+
```python
|
|
314
|
+
from llmevalkit.llm import get_llm
|
|
315
|
+
|
|
316
|
+
client = get_llm("watsonx")(
|
|
317
|
+
model_id="meta-llama/llama-3-3-70b-instruct",
|
|
318
|
+
api_key=WATSONX_API_KEY,
|
|
319
|
+
project_id=WATSONX_PROJECT_ID,
|
|
320
|
+
url=WATSONX_URL,
|
|
321
|
+
)
|
|
322
|
+
response = client.generate("Explain quantum computing")
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## Adding Your Own Provider
|
|
328
|
+
|
|
329
|
+
1. **Subclass** either `LLMClient` (for plain text) or `ValidatingLLMClient` (if you need schema enforcement).
|
|
330
|
+
2. **Implement**
|
|
331
|
+
- `@classmethod provider_class() -> your SDK client class`
|
|
332
|
+
- `_register_methods()` to map `"chat"`, `"chat_async"`, (if available `"text"`, `"text_async"`).
|
|
333
|
+
- `_parse_llm_response(raw)` to pull a single string out of the provider's raw response.
|
|
334
|
+
|
|
335
|
+
3. **Register** your class:
|
|
336
|
+
```python
|
|
337
|
+
@register_llm("myprovider")
|
|
338
|
+
class MyClient(LLMClient):
|
|
339
|
+
...
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
4. **Use** it via the registry:
|
|
343
|
+
```python
|
|
344
|
+
from llmevalkit.llm import get_llm
|
|
345
|
+
|
|
346
|
+
Client = get_llm("myprovider")
|
|
347
|
+
client = Client(api_key="…", other_args=…)
|
|
348
|
+
text = client.generate("Hello world")
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## Tips & Best Practices
|
|
354
|
+
|
|
355
|
+
- **Hooks** let you tap into every call for logging, tracing, or metrics:
|
|
356
|
+
```python
|
|
357
|
+
client = MyClient(..., hooks=[lambda ev, data: print(ev, data)])
|
|
358
|
+
```
|
|
359
|
+
- **Retries** in validating mode help you guard against model hallucinations in structured outputs—set `max_retries=1` or `2` for quick corrections.
|
|
360
|
+
- **Keep schemas small**: only require the fields you care about to avoid brittle failures when the model adds extra metadata.
|
|
361
|
+
- **Tool calling** works consistently across all providers with the same interface.
|
|
362
|
+
- **Environment variables** can be used for API keys and configuration to keep secrets out of code.
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
## Supported Features by Provider
|
|
367
|
+
|
|
368
|
+
| Feature | OpenAI | Azure OpenAI | LiteLLM | LiteLLM RITS | LiteLLM WatsonX | IBM WatsonX AI |
|
|
369
|
+
|---------|---------|--------------|---------|--------------|-----------------|----------------|
|
|
370
|
+
| Basic Generation | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
371
|
+
| Async Generation | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
372
|
+
| Tool Calling | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
373
|
+
| Structured Output | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
374
|
+
| Observability Hooks | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
375
|
+
| Retry Logic | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LLM Client Library
|
|
3
|
+
|
|
4
|
+
A flexible, extensible framework for working with any large-language-model (LLM)
|
|
5
|
+
provider in a uniform way. Supports OpenAI, IBM Watson, LiteLLM, and more.
|
|
6
|
+
|
|
7
|
+
Key Features:
|
|
8
|
+
- Unified interface for multiple LLM providers
|
|
9
|
+
- Output validation with JSON Schema and Pydantic models
|
|
10
|
+
- Sync and async support
|
|
11
|
+
- Retry logic with validation
|
|
12
|
+
- Tool calling support
|
|
13
|
+
- Observability hooks
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from typing import Dict, Type
|
|
17
|
+
|
|
18
|
+
# Global registry for LLM clients - initialize once
|
|
19
|
+
_REGISTRY: Dict[str, Type["LLMClient"]] = {}
|
|
20
|
+
|
|
21
|
+
# Core imports
|
|
22
|
+
from .base import (
|
|
23
|
+
LLMClient,
|
|
24
|
+
get_llm,
|
|
25
|
+
register_llm,
|
|
26
|
+
list_available_llms,
|
|
27
|
+
Hook,
|
|
28
|
+
MethodConfig,
|
|
29
|
+
)
|
|
30
|
+
from .output_parser import OutputValidationError, ValidatingLLMClient
|
|
31
|
+
from .types import GenerationMode, LLMResponse
|
|
32
|
+
|
|
33
|
+
# Export core components
|
|
34
|
+
__all__ = [
|
|
35
|
+
"LLMClient",
|
|
36
|
+
"ValidatingLLMClient",
|
|
37
|
+
"get_llm",
|
|
38
|
+
"register_llm",
|
|
39
|
+
"list_available_llms",
|
|
40
|
+
"Hook",
|
|
41
|
+
"MethodConfig",
|
|
42
|
+
"OutputValidationError",
|
|
43
|
+
"GenerationMode",
|
|
44
|
+
"LLMResponse",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Conditional imports for providers
|
|
49
|
+
def _import_providers():
|
|
50
|
+
"""Import providers with optional dependencies"""
|
|
51
|
+
|
|
52
|
+
# Import mock (should not raise any error)
|
|
53
|
+
from .providers.mock_llm_client import MockLLMClient
|
|
54
|
+
|
|
55
|
+
# LiteLLM providers
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
import litellm
|
|
59
|
+
|
|
60
|
+
from .providers.litellm.litellm import (LiteLLMClient,
|
|
61
|
+
LiteLLMClientOutputVal)
|
|
62
|
+
from .providers.litellm.rits import (RITSLiteLLMClient,
|
|
63
|
+
RITSLiteLLMClientOutputVal)
|
|
64
|
+
from .providers.litellm.watsonx import (WatsonxLiteLLMClient,
|
|
65
|
+
WatsonxLiteLLMClientOutputVal)
|
|
66
|
+
|
|
67
|
+
__all__.extend(
|
|
68
|
+
[
|
|
69
|
+
"LiteLLMClient",
|
|
70
|
+
"LiteLLMClientOutputVal",
|
|
71
|
+
"RITSLiteLLMClient",
|
|
72
|
+
"RITSLiteLLMClientOutputVal",
|
|
73
|
+
"WatsonxLiteLLMClient",
|
|
74
|
+
"WatsonxLiteLLMClientOutputVal",
|
|
75
|
+
"MockLLMClient",
|
|
76
|
+
]
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
except ImportError:
|
|
80
|
+
pass
|
|
81
|
+
|
|
82
|
+
# OpenAI providers
|
|
83
|
+
try:
|
|
84
|
+
import openai
|
|
85
|
+
|
|
86
|
+
from .providers.openai.openai import (AsyncAzureOpenAIClient,
|
|
87
|
+
AsyncAzureOpenAIClientOutputVal,
|
|
88
|
+
AsyncOpenAIClient,
|
|
89
|
+
AsyncOpenAIClientOutputVal,
|
|
90
|
+
SyncAzureOpenAIClient,
|
|
91
|
+
SyncAzureOpenAIClientOutputVal,
|
|
92
|
+
SyncOpenAIClient,
|
|
93
|
+
SyncOpenAIClientOutputVal)
|
|
94
|
+
|
|
95
|
+
__all__.extend(
|
|
96
|
+
[
|
|
97
|
+
"SyncOpenAIClient",
|
|
98
|
+
"AsyncOpenAIClient",
|
|
99
|
+
"SyncOpenAIClientOutputVal",
|
|
100
|
+
"AsyncOpenAIClientOutputVal",
|
|
101
|
+
"SyncAzureOpenAIClient",
|
|
102
|
+
"AsyncAzureOpenAIClient",
|
|
103
|
+
"SyncAzureOpenAIClientOutputVal",
|
|
104
|
+
"AsyncAzureOpenAIClientOutputVal",
|
|
105
|
+
]
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
except ImportError:
|
|
109
|
+
pass
|
|
110
|
+
|
|
111
|
+
# IBM Watson providers
|
|
112
|
+
try:
|
|
113
|
+
import ibm_watsonx_ai
|
|
114
|
+
|
|
115
|
+
from .providers.ibm_watsonx_ai.ibm_watsonx_ai import (
|
|
116
|
+
WatsonxLLMClient, WatsonxLLMClientOutputVal)
|
|
117
|
+
|
|
118
|
+
__all__.extend(["WatsonxLLMClient", "WatsonxLLMClientOutputVal"])
|
|
119
|
+
|
|
120
|
+
except ImportError as e:
|
|
121
|
+
print(f"Optional dependency for IBM Watson not found: {e}")
|
|
122
|
+
pass
|
|
123
|
+
|
|
124
|
+
# WXO AI Gateway providers
|
|
125
|
+
try:
|
|
126
|
+
from .providers.wxo_ai_gateway.wxo_ai_gateway import \
|
|
127
|
+
WxoAIGatewayClientOutputVal
|
|
128
|
+
|
|
129
|
+
__all__.extend(["WxoAIGatewayClientOutputVal"])
|
|
130
|
+
|
|
131
|
+
except ImportError as e:
|
|
132
|
+
print(f"Failed with error: {e}")
|
|
133
|
+
pass
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# Initialize providers on import
|
|
137
|
+
_import_providers()
|