rasa-pro 3.13.1a18__py3-none-any.whl → 3.13.3__py3-none-any.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.
Potentially problematic release.
This version of rasa-pro might be problematic. Click here for more details.
- rasa/cli/project_templates/defaults.py +25 -3
- rasa/cli/scaffold.py +3 -22
- rasa/core/actions/action.py +2 -4
- rasa/core/channels/studio_chat.py +10 -34
- rasa/core/channels/voice_stream/asr/asr_engine.py +5 -1
- rasa/core/channels/voice_stream/asr/deepgram.py +5 -0
- rasa/core/channels/voice_stream/audiocodes.py +9 -4
- rasa/core/channels/voice_stream/jambonz.py +1 -1
- rasa/core/channels/voice_stream/voice_channel.py +7 -0
- rasa/core/nlg/callback.py +1 -1
- rasa/core/policies/enterprise_search_policy.py +9 -8
- rasa/core/policies/flows/flow_executor.py +1 -8
- rasa/dialogue_understanding/commands/correct_slots_command.py +0 -10
- rasa/dialogue_understanding/generator/command_generator.py +5 -5
- rasa/dialogue_understanding/generator/flow_retrieval.py +9 -10
- rasa/dialogue_understanding/processor/command_processor.py +6 -1
- rasa/model_manager/model_api.py +3 -2
- rasa/model_manager/runner_service.py +1 -1
- rasa/model_manager/trainer_service.py +9 -12
- rasa/model_manager/utils.py +29 -1
- rasa/shared/core/domain.py +15 -62
- rasa/shared/core/flows/flow_step.py +1 -7
- rasa/shared/core/flows/yaml_flows_io.py +8 -16
- rasa/shared/core/slots.py +0 -4
- rasa/shared/importers/importer.py +0 -6
- rasa/shared/importers/utils.py +1 -77
- rasa/studio/upload.py +45 -10
- rasa/telemetry.py +1 -2
- rasa/utils/io.py +9 -27
- rasa/utils/json_utils.py +1 -6
- rasa/utils/log_utils.py +1 -5
- rasa/utils/plotting.py +1 -1
- rasa/validator.py +3 -7
- rasa/version.py +1 -1
- {rasa_pro-3.13.1a18.dist-info → rasa_pro-3.13.3.dist-info}/METADATA +8 -9
- {rasa_pro-3.13.1a18.dist-info → rasa_pro-3.13.3.dist-info}/RECORD +39 -261
- rasa/builder/README.md +0 -120
- rasa/builder/__init__.py +0 -0
- rasa/builder/config.py +0 -79
- rasa/builder/create_openai_vector_store.py +0 -228
- rasa/builder/exceptions.py +0 -55
- rasa/builder/inkeep-rag-response-schema.json +0 -64
- rasa/builder/inkeep_document_retrieval.py +0 -212
- rasa/builder/llm-helper-schema.json +0 -69
- rasa/builder/llm_context.py +0 -81
- rasa/builder/llm_helper_prompt.jinja2 +0 -245
- rasa/builder/llm_service.py +0 -317
- rasa/builder/logging_utils.py +0 -51
- rasa/builder/main.py +0 -147
- rasa/builder/models.py +0 -225
- rasa/builder/project_generator.py +0 -282
- rasa/builder/scrape_rasa_docs.py +0 -97
- rasa/builder/service.py +0 -742
- rasa/builder/skill_to_bot_prompt.jinja2 +0 -164
- rasa/builder/training_service.py +0 -132
- rasa/builder/validation_service.py +0 -93
- rasa/cli/project_templates/finance/actions/__init__.py +0 -0
- rasa/cli/project_templates/finance/actions/action_add_payee.py +0 -47
- rasa/cli/project_templates/finance/actions/action_ask_account.py +0 -50
- rasa/cli/project_templates/finance/actions/action_ask_account_from.py +0 -50
- rasa/cli/project_templates/finance/actions/action_ask_card.py +0 -47
- rasa/cli/project_templates/finance/actions/action_check_balance.py +0 -40
- rasa/cli/project_templates/finance/actions/action_check_card_existence.py +0 -35
- rasa/cli/project_templates/finance/actions/action_check_payee_existence.py +0 -40
- rasa/cli/project_templates/finance/actions/action_check_sufficient_funds.py +0 -41
- rasa/cli/project_templates/finance/actions/action_list_payees.py +0 -45
- rasa/cli/project_templates/finance/actions/action_process_immediate_payment.py +0 -18
- rasa/cli/project_templates/finance/actions/action_remove_payee.py +0 -49
- rasa/cli/project_templates/finance/actions/action_schedule_payment.py +0 -19
- rasa/cli/project_templates/finance/actions/action_session_start.py +0 -69
- rasa/cli/project_templates/finance/actions/action_update_card_status.py +0 -45
- rasa/cli/project_templates/finance/actions/action_validate_payment_date.py +0 -36
- rasa/cli/project_templates/finance/actions/database.py +0 -276
- rasa/cli/project_templates/finance/config.yml +0 -32
- rasa/cli/project_templates/finance/credentials.yml +0 -33
- rasa/cli/project_templates/finance/csvs/accounts.csv +0 -8
- rasa/cli/project_templates/finance/csvs/advisors.csv +0 -7
- rasa/cli/project_templates/finance/csvs/appointments.csv +0 -211
- rasa/cli/project_templates/finance/csvs/branches.csv +0 -10
- rasa/cli/project_templates/finance/csvs/cards.csv +0 -11
- rasa/cli/project_templates/finance/csvs/payees.csv +0 -10
- rasa/cli/project_templates/finance/csvs/transactions.csv +0 -71
- rasa/cli/project_templates/finance/csvs/users.csv +0 -4
- rasa/cli/project_templates/finance/data/flows/add_payee.yml +0 -29
- rasa/cli/project_templates/finance/data/flows/block_card.yml +0 -66
- rasa/cli/project_templates/finance/data/flows/check_balance.yml +0 -9
- rasa/cli/project_templates/finance/data/flows/list_payees.yml +0 -5
- rasa/cli/project_templates/finance/data/flows/remove_payee.yml +0 -21
- rasa/cli/project_templates/finance/data/flows/select_card.yml +0 -12
- rasa/cli/project_templates/finance/data/flows/transfer_money.yml +0 -67
- rasa/cli/project_templates/finance/data/flows/welcome.yml +0 -14
- rasa/cli/project_templates/finance/data/nlu.yml +0 -29
- rasa/cli/project_templates/finance/data/patterns/pattern_chitchat.yml +0 -7
- rasa/cli/project_templates/finance/data/patterns/pattern_completed.yml +0 -6
- rasa/cli/project_templates/finance/data/patterns/pattern_search.yml +0 -5
- rasa/cli/project_templates/finance/data/patterns/pattern_session_start.yml +0 -9
- rasa/cli/project_templates/finance/data/source/accounts.json +0 -51
- rasa/cli/project_templates/finance/data/source/advisors.json +0 -44
- rasa/cli/project_templates/finance/data/source/appointments.json +0 -1474
- rasa/cli/project_templates/finance/data/source/branches.json +0 -47
- rasa/cli/project_templates/finance/data/source/cards.json +0 -72
- rasa/cli/project_templates/finance/data/source/payees.json +0 -74
- rasa/cli/project_templates/finance/data/source/transactions.json +0 -492
- rasa/cli/project_templates/finance/data/source/users.json +0 -29
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/consequences_of_blocking_card.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/reasons_to_block_card.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/recovering_from_card_fraud.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/tips_for_card_security.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/block_card/what_to_do_if_card_is_lost.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/account_balance_security.txt +0 -7
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/common_balance_inquiries.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/methods_to_check_balance.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/understanding_balance_updates.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/check_balance/what_to_do_if_balance_is_incorrect.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/benefits_of_authorised_payees.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/common_issues_with_payees.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/general_payee_information.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/payee_management_tips.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/manage_payees/understanding_payee_types.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/common_transfer_errors.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/fees_for_transfers.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/general_transfer_information.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/security_tips_for_transfers.txt +0 -8
- rasa/cli/project_templates/finance/docs/bank_of_rasa_faq/transfer_money/transfer_processing_times.txt +0 -8
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part1.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part10.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part11.txt +0 -48
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part12.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part13.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part14.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part15.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part16.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part17.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part18.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part19.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part2.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part20.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part21.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part22.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part23.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part24.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part25.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part26.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part27.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part28.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part29.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part3.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part30.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part31.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part32.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part33.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part34.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part35.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part36.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part37.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part38.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part39.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part4.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part40.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part41.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part42.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part43.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part44.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part45.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part46.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part47.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part48.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part49.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part5.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part50.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part51.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part52.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part53.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part54.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part55.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part56.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part57.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part58.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part59.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part6.txt +0 -47
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part60.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part61.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part7.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part8.txt +0 -50
- rasa/cli/project_templates/finance/docs/huggingface_alpaca_dataset/questions_part9.txt +0 -47
- rasa/cli/project_templates/finance/domain/add_payee.yml +0 -47
- rasa/cli/project_templates/finance/domain/block_card.yml +0 -101
- rasa/cli/project_templates/finance/domain/check_balance.yml +0 -9
- rasa/cli/project_templates/finance/domain/default_actions.yml +0 -16
- rasa/cli/project_templates/finance/domain/default_flows.yml +0 -33
- rasa/cli/project_templates/finance/domain/list_payees.yml +0 -4
- rasa/cli/project_templates/finance/domain/remove_payee.yml +0 -16
- rasa/cli/project_templates/finance/domain/select_card.yml +0 -12
- rasa/cli/project_templates/finance/domain/transfer_money.yml +0 -79
- rasa/cli/project_templates/finance/endpoints.yml +0 -62
- rasa/cli/project_templates/finance/prompts/command-generator.jinja2 +0 -57
- rasa/cli/project_templates/finance/prompts/rephraser_demo_personality_prompt.jinja2 +0 -19
- rasa/cli/project_templates/finance/tests/conversation_repair/cancellations.yml +0 -12
- rasa/cli/project_templates/finance/tests/conversation_repair/cannot_handle.yml +0 -7
- rasa/cli/project_templates/finance/tests/conversation_repair/chitchat.yml +0 -7
- rasa/cli/project_templates/finance/tests/conversation_repair/clarification.yml +0 -9
- rasa/cli/project_templates/finance/tests/conversation_repair/completion.yml +0 -18
- rasa/cli/project_templates/finance/tests/conversation_repair/corrections.yml +0 -17
- rasa/cli/project_templates/finance/tests/conversation_repair/digressions.yml +0 -32
- rasa/cli/project_templates/finance/tests/conversation_repair/human_handoff.yml +0 -21
- rasa/cli/project_templates/finance/tests/conversation_repair/skipping_collect_steps.yml +0 -16
- rasa/cli/project_templates/finance/tests/demo_scripts/main.yml +0 -16
- rasa/cli/project_templates/finance/tests/happy_paths/balance_verification.yml +0 -15
- rasa/cli/project_templates/finance/tests/happy_paths/banking_questions.yml +0 -12
- rasa/cli/project_templates/finance/tests/happy_paths/card_blocking.yml +0 -52
- rasa/cli/project_templates/finance/tests/happy_paths/money_transfer.yml +0 -136
- rasa/cli/project_templates/finance/tests/happy_paths/payee_management.yml +0 -27
- rasa/cli/project_templates/finance/tests/happy_paths/user_greeted.yml +0 -5
- rasa/cli/project_templates/plain/actions/__init__.py +0 -0
- rasa/cli/project_templates/plain/config.yml +0 -17
- rasa/cli/project_templates/plain/credentials.yml +0 -33
- rasa/cli/project_templates/plain/data/patterns/pattern_session_start.yml +0 -7
- rasa/cli/project_templates/plain/domain.yml +0 -5
- rasa/cli/project_templates/plain/endpoints.yml +0 -58
- rasa/cli/project_templates/telco/actions/__init__.py +0 -0
- rasa/cli/project_templates/telco/actions/actions_billing.py +0 -197
- rasa/cli/project_templates/telco/actions/actions_get_data_from_db.py +0 -43
- rasa/cli/project_templates/telco/actions/actions_run_diagnostics.py +0 -23
- rasa/cli/project_templates/telco/actions/actions_session_start.py +0 -13
- rasa/cli/project_templates/telco/config.yml +0 -25
- rasa/cli/project_templates/telco/credentials.yml +0 -33
- rasa/cli/project_templates/telco/csvs/billing.csv +0 -10
- rasa/cli/project_templates/telco/csvs/customers.csv +0 -5
- rasa/cli/project_templates/telco/data/flows/flow_global.yml +0 -5
- rasa/cli/project_templates/telco/data/flows/flow_reboot_router.yml +0 -8
- rasa/cli/project_templates/telco/data/flows/flow_reset_router.yml +0 -7
- rasa/cli/project_templates/telco/data/flows/flow_solve_internet_issue.yml +0 -73
- rasa/cli/project_templates/telco/data/flows/flow_undertand_bill.yml +0 -45
- rasa/cli/project_templates/telco/data/patterns/pattern_completed.yml +0 -7
- rasa/cli/project_templates/telco/data/patterns/pattern_human_handoff.yml +0 -6
- rasa/cli/project_templates/telco/data/patterns/pattern_search.yml +0 -7
- rasa/cli/project_templates/telco/data/patterns/pattern_session_start.yml +0 -9
- rasa/cli/project_templates/telco/docs/reset_vs_rboot_router.txt +0 -1
- rasa/cli/project_templates/telco/docs/restart_router.txt +0 -6
- rasa/cli/project_templates/telco/docs/run_speed_test.txt +0 -6
- rasa/cli/project_templates/telco/domain/domain_global.yml +0 -29
- rasa/cli/project_templates/telco/domain/domain_patterns.yml +0 -17
- rasa/cli/project_templates/telco/domain/domain_reboot_router.yml +0 -20
- rasa/cli/project_templates/telco/domain/domain_reset_router.yml +0 -11
- rasa/cli/project_templates/telco/domain/domain_run_speed_test.yml +0 -24
- rasa/cli/project_templates/telco/domain/domain_solve_internet_issue.yml +0 -74
- rasa/cli/project_templates/telco/domain/domain_undertand_bill.yml +0 -102
- rasa/cli/project_templates/telco/endpoints.yml +0 -60
- rasa/cli/project_templates/telco/prompts/command-generator.jinja2 +0 -57
- rasa/cli/project_templates/telco/tests/e2e_results_failed.yml +0 -62
- rasa/cli/project_templates/telco/tests/e2e_results_passed.yml +0 -130
- rasa/cli/project_templates/telco/tests/e2e_test_cases/billing_test_cases.yml +0 -68
- rasa/cli/project_templates/telco/tests/e2e_test_cases/global_test_cases.yml +0 -13
- rasa/cli/project_templates/telco/tests/e2e_test_cases/internet_slow_test_case.yml +0 -47
- rasa/cli/project_templates/telco/tests/e2e_test_cases/out_of_scope_test_case.yml +0 -21
- rasa/cli/project_templates/telco/tests/e2e_test_cases/patterns_test_cases.yml +0 -15
- rasa/shared/importers/static.py +0 -63
- rasa/utils/openapi.py +0 -144
- {rasa_pro-3.13.1a18.dist-info → rasa_pro-3.13.3.dist-info}/NOTICE +0 -0
- {rasa_pro-3.13.1a18.dist-info → rasa_pro-3.13.3.dist-info}/WHEEL +0 -0
- {rasa_pro-3.13.1a18.dist-info → rasa_pro-3.13.3.dist-info}/entry_points.txt +0 -0
rasa/builder/config.py
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"""Configuration module for the prompt-to-bot service."""
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
from typing import Any, Dict
|
|
5
|
-
|
|
6
|
-
import importlib_resources
|
|
7
|
-
|
|
8
|
-
from rasa.constants import PACKAGE_NAME
|
|
9
|
-
from rasa.shared.utils.yaml import read_yaml, read_yaml_file
|
|
10
|
-
|
|
11
|
-
# OpenAI Configuration
|
|
12
|
-
OPENAI_MODEL = os.getenv("OPENAI_MODEL", "gpt-4.1-2025-04-14")
|
|
13
|
-
OPENAI_TEMPERATURE = float(os.getenv("OPENAI_TEMPERATURE", "0.7"))
|
|
14
|
-
OPENAI_VECTOR_STORE_ID = os.getenv(
|
|
15
|
-
"OPENAI_VECTOR_STORE_ID", "vs_685123376e288191a005b6b144d3026f"
|
|
16
|
-
)
|
|
17
|
-
OPENAI_MAX_VECTOR_RESULTS = int(os.getenv("OPENAI_MAX_VECTOR_RESULTS", "10"))
|
|
18
|
-
OPENAI_TIMEOUT = int(os.getenv("OPENAI_TIMEOUT", "30"))
|
|
19
|
-
|
|
20
|
-
# Server Configuration
|
|
21
|
-
BUILDER_SERVER_HOST = os.getenv("SERVER_HOST", "0.0.0.0")
|
|
22
|
-
BUILDER_SERVER_PORT = int(os.getenv("SERVER_PORT", "5050"))
|
|
23
|
-
MAX_RETRIES = int(os.getenv("MAX_RETRIES", "5"))
|
|
24
|
-
MAX_LOG_ENTRIES = int(os.getenv("MAX_LOG_ENTRIES", "30"))
|
|
25
|
-
|
|
26
|
-
# CORS Configuration
|
|
27
|
-
_cors_origins_env = os.getenv("CORS_ORIGINS", "*")
|
|
28
|
-
CORS_ORIGINS = _cors_origins_env.split(",") if _cors_origins_env != "*" else ["*"]
|
|
29
|
-
|
|
30
|
-
# Validation Configuration
|
|
31
|
-
VALIDATION_FAIL_ON_WARNINGS = (
|
|
32
|
-
os.getenv("VALIDATION_FAIL_ON_WARNINGS", "false").lower() == "true"
|
|
33
|
-
)
|
|
34
|
-
VALIDATION_MAX_HISTORY = None # Could be configured if needed
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def get_default_config(assistant_id: str) -> Dict[str, Any]:
|
|
38
|
-
"""Get default Rasa configuration."""
|
|
39
|
-
base_config = read_yaml_file(
|
|
40
|
-
str(
|
|
41
|
-
importlib_resources.files(PACKAGE_NAME).joinpath(
|
|
42
|
-
"cli/project_templates/default/config.yml"
|
|
43
|
-
)
|
|
44
|
-
)
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
if not isinstance(base_config, dict):
|
|
48
|
-
raise ValueError("Base config is not a dictionary")
|
|
49
|
-
|
|
50
|
-
base_config["assistant_id"] = assistant_id
|
|
51
|
-
|
|
52
|
-
return base_config
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def get_default_endpoints() -> Dict[str, Any]:
|
|
56
|
-
"""Get default endpoints configuration."""
|
|
57
|
-
endpoints_config = read_yaml_file(
|
|
58
|
-
str(
|
|
59
|
-
importlib_resources.files(PACKAGE_NAME).joinpath(
|
|
60
|
-
"cli/project_templates/default/endpoints.yml"
|
|
61
|
-
)
|
|
62
|
-
)
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
if not isinstance(endpoints_config, dict):
|
|
66
|
-
raise ValueError("Endpoints config is not a dictionary")
|
|
67
|
-
|
|
68
|
-
return endpoints_config
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def get_default_credentials() -> Dict[str, Any]:
|
|
72
|
-
"""Get default credentials configuration."""
|
|
73
|
-
default_credentials_yaml = """
|
|
74
|
-
studio_chat:
|
|
75
|
-
user_message_evt: "user_message"
|
|
76
|
-
bot_message_evt: "bot_message"
|
|
77
|
-
session_persistence: true
|
|
78
|
-
"""
|
|
79
|
-
return read_yaml(default_credentials_yaml)
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Script to create and populate OpenAI vector store with Rasa documentation."""
|
|
3
|
-
|
|
4
|
-
import json
|
|
5
|
-
import sys
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
from typing import Dict, List
|
|
8
|
-
|
|
9
|
-
import openai
|
|
10
|
-
import structlog
|
|
11
|
-
|
|
12
|
-
structlogger = structlog.get_logger()
|
|
13
|
-
|
|
14
|
-
# Configuration
|
|
15
|
-
DOCS_DIR = "rasa_docs_md"
|
|
16
|
-
FILE_IDS_FILE = "file_ids.json"
|
|
17
|
-
MARKDOWN_TO_URL_FILE = "markdown_to_url.json"
|
|
18
|
-
ASSISTANT_NAME = "Rasa Docs Assistant"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def load_url_mapping() -> Dict[str, str]:
|
|
22
|
-
"""Load the markdown filename to URL mapping."""
|
|
23
|
-
markdown_to_url_file = Path(MARKDOWN_TO_URL_FILE)
|
|
24
|
-
|
|
25
|
-
if not markdown_to_url_file.exists():
|
|
26
|
-
raise FileNotFoundError(
|
|
27
|
-
f"URL mapping file {markdown_to_url_file} not found. "
|
|
28
|
-
"Please run scrape_rasa_docs.py first."
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
with open(markdown_to_url_file, "r") as f:
|
|
32
|
-
return json.load(f)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def get_markdown_files(docs_dir: str = DOCS_DIR) -> List[Path]:
|
|
36
|
-
"""Get all markdown files in the docs directory."""
|
|
37
|
-
docs_path = Path(docs_dir)
|
|
38
|
-
|
|
39
|
-
if not docs_path.exists():
|
|
40
|
-
raise FileNotFoundError(f"Documentation directory {docs_dir} not found")
|
|
41
|
-
|
|
42
|
-
md_files = list(docs_path.glob("*.md"))
|
|
43
|
-
if not md_files:
|
|
44
|
-
raise FileNotFoundError(f"No markdown files found in {docs_dir}")
|
|
45
|
-
|
|
46
|
-
structlogger.info("vector_store.found_files", count=len(md_files))
|
|
47
|
-
return md_files
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def load_or_upload_files(client: openai.OpenAI) -> List[Dict[str, str]]:
|
|
51
|
-
"""Load existing file IDs or upload files to OpenAI."""
|
|
52
|
-
file_ids_file = Path(FILE_IDS_FILE)
|
|
53
|
-
|
|
54
|
-
if file_ids_file.exists():
|
|
55
|
-
structlogger.info("vector_store.loading_existing_files")
|
|
56
|
-
with open(file_ids_file, "r") as f:
|
|
57
|
-
return json.load(f)
|
|
58
|
-
|
|
59
|
-
return upload_files(client)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def upload_files(client: openai.OpenAI) -> List[Dict[str, str]]:
|
|
63
|
-
"""Upload markdown files to OpenAI."""
|
|
64
|
-
structlogger.info("vector_store.uploading_files")
|
|
65
|
-
|
|
66
|
-
md_files = get_markdown_files()
|
|
67
|
-
uploaded_files = []
|
|
68
|
-
|
|
69
|
-
for md_file in md_files:
|
|
70
|
-
try:
|
|
71
|
-
with open(md_file, "rb") as f:
|
|
72
|
-
uploaded = client.files.create(file=f, purpose="assistants")
|
|
73
|
-
|
|
74
|
-
file_info = {"file_id": uploaded.id, "file_name": md_file.name}
|
|
75
|
-
uploaded_files.append(file_info)
|
|
76
|
-
|
|
77
|
-
structlogger.info(
|
|
78
|
-
"vector_store.file_uploaded",
|
|
79
|
-
file_name=md_file.name,
|
|
80
|
-
file_id=uploaded.id,
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
except Exception as e:
|
|
84
|
-
structlogger.error(
|
|
85
|
-
"vector_store.upload_failed", file_name=md_file.name, error=str(e)
|
|
86
|
-
)
|
|
87
|
-
raise
|
|
88
|
-
|
|
89
|
-
# Save file IDs for future use
|
|
90
|
-
with open(FILE_IDS_FILE, "w") as f:
|
|
91
|
-
json.dump(uploaded_files, f, indent=2)
|
|
92
|
-
|
|
93
|
-
structlogger.info("vector_store.upload_complete", count=len(uploaded_files))
|
|
94
|
-
return uploaded_files
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def prepare_files_with_metadata(files: List[Dict[str, str]]) -> List[Dict[str, str]]:
|
|
98
|
-
"""Prepare files with URL metadata."""
|
|
99
|
-
url_mapping = load_url_mapping()
|
|
100
|
-
|
|
101
|
-
files_with_metadata = []
|
|
102
|
-
for file_info in files:
|
|
103
|
-
file_name = file_info["file_name"]
|
|
104
|
-
url = url_mapping.get(file_name, "")
|
|
105
|
-
|
|
106
|
-
if not url:
|
|
107
|
-
structlogger.warning("vector_store.missing_url", file_name=file_name)
|
|
108
|
-
|
|
109
|
-
files_with_metadata.append(
|
|
110
|
-
{"file_id": file_info["file_id"], "file_name": file_name, "url": url}
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
return files_with_metadata
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def create_vector_store(
|
|
117
|
-
client: openai.OpenAI, files_with_metadata: List[Dict[str, str]]
|
|
118
|
-
) -> str:
|
|
119
|
-
"""Create vector store and add files."""
|
|
120
|
-
try:
|
|
121
|
-
# Create vector store
|
|
122
|
-
structlogger.info("vector_store.creating")
|
|
123
|
-
vector_store = client.vector_stores.create(name=ASSISTANT_NAME)
|
|
124
|
-
|
|
125
|
-
# Add files to vector store
|
|
126
|
-
for file_meta in files_with_metadata:
|
|
127
|
-
try:
|
|
128
|
-
client.vector_stores.files.create(
|
|
129
|
-
vector_store_id=vector_store.id,
|
|
130
|
-
file_id=file_meta["file_id"],
|
|
131
|
-
attributes={"url": file_meta["url"]},
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
structlogger.info(
|
|
135
|
-
"vector_store.file_added",
|
|
136
|
-
file_name=file_meta["file_name"],
|
|
137
|
-
url=file_meta["url"],
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
except Exception as e:
|
|
141
|
-
structlogger.error(
|
|
142
|
-
"vector_store.file_add_failed",
|
|
143
|
-
file_name=file_meta["file_name"],
|
|
144
|
-
error=str(e),
|
|
145
|
-
)
|
|
146
|
-
# Continue with other files
|
|
147
|
-
|
|
148
|
-
structlogger.info(
|
|
149
|
-
"vector_store.created",
|
|
150
|
-
vector_store_id=vector_store.id,
|
|
151
|
-
files_count=len(files_with_metadata),
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
return vector_store.id
|
|
155
|
-
|
|
156
|
-
except Exception as e:
|
|
157
|
-
structlogger.error("vector_store.creation_failed", error=str(e))
|
|
158
|
-
raise
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
def run_vector_store_creation() -> str:
|
|
162
|
-
"""Run the complete vector store creation process."""
|
|
163
|
-
client = openai.OpenAI()
|
|
164
|
-
|
|
165
|
-
try:
|
|
166
|
-
# Load or upload files
|
|
167
|
-
files = load_or_upload_files(client)
|
|
168
|
-
|
|
169
|
-
# Prepare files with metadata
|
|
170
|
-
files_with_metadata = prepare_files_with_metadata(files)
|
|
171
|
-
|
|
172
|
-
# Create vector store
|
|
173
|
-
vector_store_id = create_vector_store(client, files_with_metadata)
|
|
174
|
-
|
|
175
|
-
print("\n🎉 Vector store created successfully!")
|
|
176
|
-
print(f"Vector store ID: {vector_store_id}")
|
|
177
|
-
print(f"Files processed: {len(files_with_metadata)}")
|
|
178
|
-
|
|
179
|
-
return vector_store_id
|
|
180
|
-
|
|
181
|
-
except Exception as e:
|
|
182
|
-
structlogger.error("vector_store.process_failed", error=str(e))
|
|
183
|
-
print(f"\n❌ Vector store creation failed: {e}")
|
|
184
|
-
raise
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
def setup_logging():
|
|
188
|
-
"""Setup basic logging."""
|
|
189
|
-
import logging.config
|
|
190
|
-
|
|
191
|
-
logging_config = {
|
|
192
|
-
"version": 1,
|
|
193
|
-
"disable_existing_loggers": False,
|
|
194
|
-
"formatters": {
|
|
195
|
-
"standard": {"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"},
|
|
196
|
-
},
|
|
197
|
-
"handlers": {
|
|
198
|
-
"default": {
|
|
199
|
-
"level": "INFO",
|
|
200
|
-
"formatter": "standard",
|
|
201
|
-
"class": "logging.StreamHandler",
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
"loggers": {"": {"handlers": ["default"], "level": "INFO", "propagate": False}},
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
logging.config.dictConfig(logging_config)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
def main():
|
|
211
|
-
"""Main entry point for the script."""
|
|
212
|
-
setup_logging()
|
|
213
|
-
|
|
214
|
-
try:
|
|
215
|
-
run_vector_store_creation()
|
|
216
|
-
return 0
|
|
217
|
-
|
|
218
|
-
except KeyboardInterrupt:
|
|
219
|
-
print("\n⏹️ Process interrupted by user")
|
|
220
|
-
return 1
|
|
221
|
-
|
|
222
|
-
except Exception as e:
|
|
223
|
-
print(f"\n💥 Unexpected error: {e}")
|
|
224
|
-
return 1
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if __name__ == "__main__":
|
|
228
|
-
sys.exit(main())
|
rasa/builder/exceptions.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"""Custom exceptions for the prompt-to-bot service."""
|
|
2
|
-
|
|
3
|
-
from typing import Any, Optional
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class PromptToBotError(Exception):
|
|
7
|
-
"""Base exception for prompt-to-bot service."""
|
|
8
|
-
|
|
9
|
-
pass
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class ValidationError(PromptToBotError):
|
|
13
|
-
"""Raised when Rasa project validation fails."""
|
|
14
|
-
|
|
15
|
-
def __init__(self, message: str, validation_logs: Optional[Any] = None):
|
|
16
|
-
super().__init__(message)
|
|
17
|
-
self.validation_logs = validation_logs
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class TrainingError(PromptToBotError):
|
|
21
|
-
"""Raised when model training fails."""
|
|
22
|
-
|
|
23
|
-
pass
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class LLMGenerationError(PromptToBotError):
|
|
27
|
-
"""Raised when LLM generation fails."""
|
|
28
|
-
|
|
29
|
-
pass
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class DocumentRetrievalError(PromptToBotError):
|
|
33
|
-
"""Raised when document retrieval fails."""
|
|
34
|
-
|
|
35
|
-
pass
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
class SchemaValidationError(PromptToBotError):
|
|
39
|
-
"""Raised when schema validation fails."""
|
|
40
|
-
|
|
41
|
-
pass
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
class AgentLoadError(PromptToBotError):
|
|
45
|
-
"""Raised when agent loading fails."""
|
|
46
|
-
|
|
47
|
-
pass
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class ProjectGenerationError(PromptToBotError):
|
|
51
|
-
"""Raised when project generation fails after retries."""
|
|
52
|
-
|
|
53
|
-
def __init__(self, message: str, attempts: int):
|
|
54
|
-
super().__init__(f"{message} (failed after {attempts} attempts)")
|
|
55
|
-
self.attempts = attempts
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
-
"type": "object",
|
|
4
|
-
"properties": {
|
|
5
|
-
"content": {
|
|
6
|
-
"type": "array",
|
|
7
|
-
"items": {
|
|
8
|
-
"type": "object",
|
|
9
|
-
"properties": {
|
|
10
|
-
"type": {
|
|
11
|
-
"type": "string"
|
|
12
|
-
},
|
|
13
|
-
"source": {
|
|
14
|
-
"type": "object",
|
|
15
|
-
"properties": {
|
|
16
|
-
"content": {
|
|
17
|
-
"type": "array",
|
|
18
|
-
"items": {
|
|
19
|
-
"type": "object",
|
|
20
|
-
"properties": {
|
|
21
|
-
"type": {
|
|
22
|
-
"type": "string"
|
|
23
|
-
},
|
|
24
|
-
"media_type": {
|
|
25
|
-
"type": "string"
|
|
26
|
-
},
|
|
27
|
-
"text": {
|
|
28
|
-
"type": "string"
|
|
29
|
-
},
|
|
30
|
-
"data": {
|
|
31
|
-
"type": "string"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
"type": {
|
|
37
|
-
"type": "string"
|
|
38
|
-
},
|
|
39
|
-
"media_type": {
|
|
40
|
-
"type": "string"
|
|
41
|
-
},
|
|
42
|
-
"data": {
|
|
43
|
-
"type": "string"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"title": {
|
|
48
|
-
"type": "string"
|
|
49
|
-
},
|
|
50
|
-
"context": {
|
|
51
|
-
"type": "string"
|
|
52
|
-
},
|
|
53
|
-
"record_type": {
|
|
54
|
-
"type": "string"
|
|
55
|
-
},
|
|
56
|
-
"url": {
|
|
57
|
-
"type": "string"
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"required": ["content"]
|
|
64
|
-
}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import json
|
|
3
|
-
import os
|
|
4
|
-
from contextlib import asynccontextmanager
|
|
5
|
-
from typing import List, Optional
|
|
6
|
-
|
|
7
|
-
import importlib_resources
|
|
8
|
-
import openai
|
|
9
|
-
import structlog
|
|
10
|
-
from openai.types.chat import ChatCompletion
|
|
11
|
-
|
|
12
|
-
from rasa.builder.exceptions import DocumentRetrievalError
|
|
13
|
-
from rasa.builder.models import Document
|
|
14
|
-
from rasa.constants import PACKAGE_NAME
|
|
15
|
-
from rasa.shared.utils.io import read_json_file
|
|
16
|
-
|
|
17
|
-
INKEEP_API_KEY_ENV_VAR = "INKEEP_API_KEY"
|
|
18
|
-
INKEEP_RAG_RESPONSE_SCHEMA_PATH = str(
|
|
19
|
-
importlib_resources.files(PACKAGE_NAME).joinpath(
|
|
20
|
-
"builder/inkeep-rag-response-schema.json"
|
|
21
|
-
)
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
INKEEP_DOCUMENT_RETRIEVAL_MODEL = "inkeep-rag"
|
|
25
|
-
INKEEP_BASE_URL = "https://api.inkeep.com/v1/"
|
|
26
|
-
|
|
27
|
-
structlogger = structlog.get_logger()
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class InKeepDocumentRetrieval:
|
|
31
|
-
"""Handles the document retrieval from InKeep AI."""
|
|
32
|
-
|
|
33
|
-
def __init__(
|
|
34
|
-
self,
|
|
35
|
-
api_key: Optional[str] = None,
|
|
36
|
-
):
|
|
37
|
-
self._client: Optional[openai.AsyncOpenAI] = None
|
|
38
|
-
self._rag_schema = read_json_file(INKEEP_RAG_RESPONSE_SCHEMA_PATH)
|
|
39
|
-
self._api_key = api_key or os.getenv(INKEEP_API_KEY_ENV_VAR)
|
|
40
|
-
|
|
41
|
-
async def retrieve_documents(
|
|
42
|
-
self, query: str, temperature: float = 0.0, timeout: float = 30.0
|
|
43
|
-
) -> List[Document]:
|
|
44
|
-
"""Retrieve relevant documents using InKeep AI based on the given query.
|
|
45
|
-
|
|
46
|
-
Args:
|
|
47
|
-
query: The search query
|
|
48
|
-
temperature: Controls randomness in generation (0.0 for deterministic)
|
|
49
|
-
timeout: Timeout for the API call
|
|
50
|
-
|
|
51
|
-
Returns:
|
|
52
|
-
List of Document objects containing retrieved content
|
|
53
|
-
|
|
54
|
-
Raises:
|
|
55
|
-
LLMGenerationError: If the API call fails or returns invalid response
|
|
56
|
-
"""
|
|
57
|
-
response = await self._call_inkeep_rag_api(
|
|
58
|
-
query=query,
|
|
59
|
-
temperature=temperature,
|
|
60
|
-
timeout=timeout,
|
|
61
|
-
)
|
|
62
|
-
documents = self._parse_documents_from_response(response)
|
|
63
|
-
return documents
|
|
64
|
-
|
|
65
|
-
async def _call_inkeep_rag_api(
|
|
66
|
-
self, query: str, temperature: float, timeout: float
|
|
67
|
-
) -> ChatCompletion:
|
|
68
|
-
"""Call InKeep AI RAG's API endpoint and return the response content.
|
|
69
|
-
|
|
70
|
-
Args:
|
|
71
|
-
query: The search query to send to InKeep
|
|
72
|
-
temperature: Controls randomness in generation (0.0 for deterministic)
|
|
73
|
-
timeout: Timeout for the API call
|
|
74
|
-
|
|
75
|
-
Returns:
|
|
76
|
-
The response content from InKeep AI. The response is made of the retrieved
|
|
77
|
-
documents.
|
|
78
|
-
|
|
79
|
-
Raises:
|
|
80
|
-
LLMGenerationError: If the API call fails or returns invalid response
|
|
81
|
-
"""
|
|
82
|
-
request_params = {
|
|
83
|
-
"model": INKEEP_DOCUMENT_RETRIEVAL_MODEL,
|
|
84
|
-
"messages": [{"role": "user", "content": query}],
|
|
85
|
-
"temperature": temperature,
|
|
86
|
-
"timeout": timeout,
|
|
87
|
-
"response_format": {
|
|
88
|
-
"type": "json_schema",
|
|
89
|
-
"json_schema": self._rag_schema,
|
|
90
|
-
},
|
|
91
|
-
}
|
|
92
|
-
try:
|
|
93
|
-
async with self._get_client() as client:
|
|
94
|
-
response = await client.chat.completions.create(**request_params)
|
|
95
|
-
|
|
96
|
-
if not response.choices[0].message.content:
|
|
97
|
-
structlogger.warning(
|
|
98
|
-
"inkeep_document_retrieval.empty_response",
|
|
99
|
-
event_info="InKeep AI returned an empty response. ",
|
|
100
|
-
request_params=request_params,
|
|
101
|
-
response_content=response.choices[0].message.content,
|
|
102
|
-
)
|
|
103
|
-
raise DocumentRetrievalError(
|
|
104
|
-
"InKeep Document Retrieval: Empty response"
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
return response
|
|
108
|
-
|
|
109
|
-
except openai.OpenAIError as e:
|
|
110
|
-
structlogger.error(
|
|
111
|
-
"inkeep_document_retrieval.api_error",
|
|
112
|
-
event_info="InKeep Document Retrieval: API error",
|
|
113
|
-
request_params=request_params,
|
|
114
|
-
error=e,
|
|
115
|
-
)
|
|
116
|
-
raise DocumentRetrievalError(f"InKeep Document Retrieval: API error: {e}")
|
|
117
|
-
except asyncio.TimeoutError as e:
|
|
118
|
-
structlogger.error(
|
|
119
|
-
"inkeep_document_retrieval.timeout_error",
|
|
120
|
-
event_info="InKeep Document Retrieval: Timeout error",
|
|
121
|
-
request_params=request_params,
|
|
122
|
-
error=e,
|
|
123
|
-
)
|
|
124
|
-
raise DocumentRetrievalError(f"InKeep AI request timed out: {e}")
|
|
125
|
-
except Exception as e:
|
|
126
|
-
structlogger.error(
|
|
127
|
-
"inkeep_document_retrieval.error",
|
|
128
|
-
event_info="InKeep Document Retrieval: Error",
|
|
129
|
-
request_params=request_params,
|
|
130
|
-
error=e,
|
|
131
|
-
)
|
|
132
|
-
raise DocumentRetrievalError(
|
|
133
|
-
f"InKeep Document Retrieval: Unexpected error: {e}"
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
@asynccontextmanager
|
|
137
|
-
async def _get_client(self):
|
|
138
|
-
"""Get or create client that handles the API calls to InKeep AI."""
|
|
139
|
-
if self._client is None:
|
|
140
|
-
self._client = openai.AsyncOpenAI(
|
|
141
|
-
api_key=self._api_key,
|
|
142
|
-
base_url=INKEEP_BASE_URL,
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
try:
|
|
146
|
-
yield self._client
|
|
147
|
-
except Exception as e:
|
|
148
|
-
structlogger.error(
|
|
149
|
-
"inkeep_document_retrieval.client_error",
|
|
150
|
-
event_info="InKeep Document Retrieval: Client error",
|
|
151
|
-
error=str(e),
|
|
152
|
-
)
|
|
153
|
-
raise
|
|
154
|
-
|
|
155
|
-
def _parse_documents_from_response(
|
|
156
|
-
self, response: ChatCompletion
|
|
157
|
-
) -> List[Document]:
|
|
158
|
-
"""Parse the InKeep AI response into Document objects.
|
|
159
|
-
|
|
160
|
-
Args:
|
|
161
|
-
response: ChatCompletion response from InKeep AI's RAG model.
|
|
162
|
-
|
|
163
|
-
Returns:
|
|
164
|
-
List of Document objects
|
|
165
|
-
"""
|
|
166
|
-
try:
|
|
167
|
-
content = response.choices[0].message.content
|
|
168
|
-
if not content:
|
|
169
|
-
return []
|
|
170
|
-
|
|
171
|
-
response_data = json.loads(content)
|
|
172
|
-
documents = []
|
|
173
|
-
|
|
174
|
-
for item in response_data.get("content", []):
|
|
175
|
-
try:
|
|
176
|
-
document = Document.from_inkeep_rag_response(item)
|
|
177
|
-
documents.append(document)
|
|
178
|
-
except Exception as e:
|
|
179
|
-
structlogger.warning(
|
|
180
|
-
"inkeep_document_retrieval.invalid_document_skipped",
|
|
181
|
-
event_info=(
|
|
182
|
-
"InKeep Document Retrieval: Invalid document structure "
|
|
183
|
-
"skipped. Returning empty list for this item."
|
|
184
|
-
),
|
|
185
|
-
error=str(e),
|
|
186
|
-
item=item,
|
|
187
|
-
)
|
|
188
|
-
# Continue processing other items, skip this invalid one
|
|
189
|
-
continue
|
|
190
|
-
|
|
191
|
-
return documents
|
|
192
|
-
|
|
193
|
-
except json.JSONDecodeError as e:
|
|
194
|
-
structlogger.warning(
|
|
195
|
-
"inkeep_document_retrieval.parse_response_failed",
|
|
196
|
-
event_info=(
|
|
197
|
-
"InKeep Document Retrieval: Parse response failed. "
|
|
198
|
-
"Returning empty list.",
|
|
199
|
-
),
|
|
200
|
-
error=str(e),
|
|
201
|
-
)
|
|
202
|
-
return []
|
|
203
|
-
except Exception as e:
|
|
204
|
-
structlogger.error(
|
|
205
|
-
"inkeep_document_retrieval.parse_response_error",
|
|
206
|
-
event_info=(
|
|
207
|
-
"InKeep Document Retrieval: Parse response error. "
|
|
208
|
-
"Returning empty list.",
|
|
209
|
-
),
|
|
210
|
-
error=str(e),
|
|
211
|
-
)
|
|
212
|
-
return []
|