diff --git a/.github/ISSUE_TEMPLATE/agent_scenario_request.yml b/.github/ISSUE_TEMPLATE/agent_scenario_request.yml new file mode 100644 index 00000000000..a76f4c31653 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/agent_scenario_request.yml @@ -0,0 +1,46 @@ +name: "❤️‍🔥ᴬᴳᴱᴺᵀ Agent scenario request" +description: Propose a agent scenario request for RAGFlow. +title: "[Agent Scenario Request]: " +labels: ["❤️‍🔥ᴬᴳᴱᴺᵀ agent scenario"] +body: + - type: checkboxes + attributes: + label: Self Checks + description: "Please check the following in order to be responded in time :)" + options: + - label: I have searched for existing issues [search for existing issues](https://github.com/infiniflow/ragflow/issues), including closed ones. + required: true + - label: I confirm that I am using English to submit this report ([Language Policy](https://github.com/infiniflow/ragflow/issues/5910)). + required: true + - label: Non-english title submitions will be closed directly ( 非英文标题的提交将会被直接关闭 ) ([Language Policy](https://github.com/infiniflow/ragflow/issues/5910)). + required: true + - label: "Please do not modify this template :) and fill in all the required fields." + required: true + - type: textarea + attributes: + label: Is your feature request related to a scenario? + description: | + A clear and concise description of what the scenario is. Ex. I'm always frustrated when [...] + render: Markdown + validations: + required: false + - type: textarea + attributes: + label: Describe the feature you'd like + description: A clear and concise description of what you want to happen. + validations: + required: true + - type: textarea + attributes: + label: Documentation, adoption, use case + description: If you can, explain some scenarios how users might use this, situations it would be helpful in. Any API designs, mockups, or diagrams are also helpful. + render: Markdown + validations: + required: false + - type: textarea + attributes: + label: Additional information + description: | + Add any other context or screenshots about the feature request here. + validations: + required: false \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 489daab3e74..cfdb3c15a97 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,52 +16,52 @@ concurrency: jobs: release: - runs-on: [ "self-hosted", "overseas" ] + runs-on: [ "self-hosted", "ragflow-test" ] steps: - name: Ensure workspace ownership - run: echo "chown -R $USER $GITHUB_WORKSPACE" && sudo chown -R $USER $GITHUB_WORKSPACE + run: echo "chown -R ${USER} ${GITHUB_WORKSPACE}" && sudo chown -R ${USER} ${GITHUB_WORKSPACE} # https://github.com/actions/checkout/blob/v3/README.md - name: Check out code uses: actions/checkout@v4 with: - token: ${{ secrets.MY_GITHUB_TOKEN }} # Use the secret as an environment variable + token: ${{ secrets.GITHUB_TOKEN }} # Use the secret as an environment variable fetch-depth: 0 fetch-tags: true - name: Prepare release body run: | - if [[ $GITHUB_EVENT_NAME == 'create' ]]; then + if [[ ${GITHUB_EVENT_NAME} == "create" ]]; then RELEASE_TAG=${GITHUB_REF#refs/tags/} - if [[ $RELEASE_TAG == 'nightly' ]]; then + if [[ ${RELEASE_TAG} == "nightly" ]]; then PRERELEASE=true else PRERELEASE=false fi - echo "Workflow triggered by create tag: $RELEASE_TAG" + echo "Workflow triggered by create tag: ${RELEASE_TAG}" else RELEASE_TAG=nightly PRERELEASE=true echo "Workflow triggered by schedule" fi - echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV - echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV + echo "RELEASE_TAG=${RELEASE_TAG}" >> ${GITHUB_ENV} + echo "PRERELEASE=${PRERELEASE}" >> ${GITHUB_ENV} RELEASE_DATETIME=$(date --rfc-3339=seconds) - echo Release $RELEASE_TAG created from $GITHUB_SHA at $RELEASE_DATETIME > release_body.md + echo Release ${RELEASE_TAG} created from ${GITHUB_SHA} at ${RELEASE_DATETIME} > release_body.md - name: Move the existing mutable tag # https://github.com/softprops/action-gh-release/issues/171 run: | git fetch --tags - if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then + if [[ ${GITHUB_EVENT_NAME} == "schedule" ]]; then # Determine if a given tag exists and matches a specific Git commit. # actions/checkout@v4 fetch-tags doesn't work when triggered by schedule - if [ "$(git rev-parse -q --verify "refs/tags/$RELEASE_TAG")" = "$GITHUB_SHA" ]; then - echo "mutable tag $RELEASE_TAG exists and matches $GITHUB_SHA" + if [ "$(git rev-parse -q --verify "refs/tags/${RELEASE_TAG}")" = "${GITHUB_SHA}" ]; then + echo "mutable tag ${RELEASE_TAG} exists and matches ${GITHUB_SHA}" else - git tag -f $RELEASE_TAG $GITHUB_SHA - git push -f origin $RELEASE_TAG:refs/tags/$RELEASE_TAG - echo "created/moved mutable tag $RELEASE_TAG to $GITHUB_SHA" + git tag -f ${RELEASE_TAG} ${GITHUB_SHA} + git push -f origin ${RELEASE_TAG}:refs/tags/${RELEASE_TAG} + echo "created/moved mutable tag ${RELEASE_TAG} to ${GITHUB_SHA}" fi fi @@ -69,50 +69,26 @@ jobs: # https://github.com/actions/upload-release-asset has been replaced by https://github.com/softprops/action-gh-release uses: softprops/action-gh-release@v2 with: - token: ${{ secrets.MY_GITHUB_TOKEN }} # Use the secret as an environment variable + token: ${{ secrets.GITHUB_TOKEN }} # Use the secret as an environment variable prerelease: ${{ env.PRERELEASE }} tag_name: ${{ env.RELEASE_TAG }} # The body field does not support environment variable substitution directly. body_path: release_body.md - # https://github.com/marketplace/actions/docker-login - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: infiniflow - password: ${{ secrets.DOCKERHUB_TOKEN }} - - # https://github.com/marketplace/actions/build-and-push-docker-images - - name: Build and push full image - uses: docker/build-push-action@v6 - with: - context: . - push: true - tags: infiniflow/ragflow:${{ env.RELEASE_TAG }} - file: Dockerfile - platforms: linux/amd64 - - # https://github.com/marketplace/actions/build-and-push-docker-images - - name: Build and push slim image - uses: docker/build-push-action@v6 - with: - context: . - push: true - tags: infiniflow/ragflow:${{ env.RELEASE_TAG }}-slim - file: Dockerfile - build-args: LIGHTEN=1 - platforms: linux/amd64 - - - name: Build ragflow-sdk + - name: Build and push ragflow-sdk if: startsWith(github.ref, 'refs/tags/v') run: | - cd sdk/python && \ - uv build + cd sdk/python && uv build && uv publish --token ${{ secrets.PYPI_API_TOKEN }} - - name: Publish package distributions to PyPI + - name: Build and push ragflow-cli if: startsWith(github.ref, 'refs/tags/v') - uses: pypa/gh-action-pypi-publish@release/v1 - with: - packages-dir: sdk/python/dist/ - password: ${{ secrets.PYPI_API_TOKEN }} - verbose: true + run: | + cd admin/client && uv build && uv publish --token ${{ secrets.PYPI_API_TOKEN }} + + - name: Build and push image + run: | + sudo docker login --username infiniflow --password-stdin <<< ${{ secrets.DOCKERHUB_TOKEN }} + sudo docker build --build-arg NEED_MIRROR=1 -t infiniflow/ragflow:${RELEASE_TAG} -f Dockerfile . + sudo docker tag infiniflow/ragflow:${RELEASE_TAG} infiniflow/ragflow:latest + sudo docker push infiniflow/ragflow:${RELEASE_TAG} + sudo docker push infiniflow/ragflow:latest diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b5ea772d5e2..4357bf98278 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,8 +9,11 @@ on: - 'docs/**' - '*.md' - '*.mdx' - pull_request: - types: [ opened, synchronize, reopened, labeled ] + # The only difference between pull_request and pull_request_target is the context in which the workflow runs: + # — pull_request_target workflows use the workflow files from the default branch, and secrets are available. + # — pull_request workflows use the workflow files from the pull request branch, and secrets are unavailable. + pull_request_target: + types: [ synchronize, ready_for_review ] paths-ignore: - 'docs/**' - '*.md' @@ -28,26 +31,63 @@ jobs: name: ragflow_tests # https://docs.github.com/en/actions/using-jobs/using-conditions-to-control-job-execution # https://github.com/orgs/community/discussions/26261 - if: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'ci') }} - runs-on: [ "self-hosted", "debug" ] + if: ${{ github.event_name != 'pull_request_target' || contains(github.event.pull_request.labels.*.name, 'ci') }} + runs-on: [ "self-hosted", "ragflow-test" ] steps: # https://github.com/hmarr/debug-action #- uses: hmarr/debug-action@v2 - - name: Show who triggered this workflow + - name: Ensure workspace ownership run: | echo "Workflow triggered by ${{ github.event_name }}" - - - name: Ensure workspace ownership - run: echo "chown -R $USER $GITHUB_WORKSPACE" && sudo chown -R $USER $GITHUB_WORKSPACE + echo "chown -R ${USER} ${GITHUB_WORKSPACE}" && sudo chown -R ${USER} ${GITHUB_WORKSPACE} # https://github.com/actions/checkout/issues/1781 - name: Check out code uses: actions/checkout@v4 with: + ref: ${{ (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && format('refs/pull/{0}/merge', github.event.pull_request.number) || github.sha }} fetch-depth: 0 fetch-tags: true + - name: Check workflow duplication + if: ${{ !cancelled() && !failure() }} + run: | + if [[ ${GITHUB_EVENT_NAME} != "pull_request_target" && ${GITHUB_EVENT_NAME} != "schedule" ]]; then + HEAD=$(git rev-parse HEAD) + # Find a PR that introduced a given commit + gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}" + PR_NUMBER=$(gh pr list --search ${HEAD} --state merged --json number --jq .[0].number) + echo "HEAD=${HEAD}" + echo "PR_NUMBER=${PR_NUMBER}" + if [[ -n "${PR_NUMBER}" ]]; then + PR_SHA_FP=${RUNNER_WORKSPACE_PREFIX}/artifacts/${GITHUB_REPOSITORY}/PR_${PR_NUMBER} + if [[ -f "${PR_SHA_FP}" ]]; then + read -r PR_SHA PR_RUN_ID < "${PR_SHA_FP}" + # Calculate the hash of the current workspace content + HEAD_SHA=$(git rev-parse HEAD^{tree}) + if [[ "${HEAD_SHA}" == "${PR_SHA}" ]]; then + echo "Cancel myself since the workspace content hash is the same with PR #${PR_NUMBER} merged. See ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${PR_RUN_ID} for details." + gh run cancel ${GITHUB_RUN_ID} + while true; do + status=$(gh run view ${GITHUB_RUN_ID} --json status -q .status) + [ "${status}" = "completed" ] && break + sleep 5 + done + exit 1 + fi + fi + fi + elif [[ ${GITHUB_EVENT_NAME} == "pull_request_target" ]]; then + PR_NUMBER=${{ github.event.pull_request.number }} + PR_SHA_FP=${RUNNER_WORKSPACE_PREFIX}/artifacts/${GITHUB_REPOSITORY}/PR_${PR_NUMBER} + # Calculate the hash of the current workspace content + PR_SHA=$(git rev-parse HEAD^{tree}) + echo "PR #${PR_NUMBER} workspace content hash: ${PR_SHA}" + mkdir -p ${RUNNER_WORKSPACE_PREFIX}/artifacts/${GITHUB_REPOSITORY} + echo "${PR_SHA} ${GITHUB_RUN_ID}" > ${PR_SHA_FP} + fi + # https://github.com/astral-sh/ruff-action - name: Static check with Ruff uses: astral-sh/ruff-action@v3 @@ -55,121 +95,145 @@ jobs: version: ">=0.11.x" args: "check" - - name: Build ragflow:nightly-slim - run: | - RUNNER_WORKSPACE_PREFIX=${RUNNER_WORKSPACE_PREFIX:-$HOME} - sudo docker pull ubuntu:22.04 - sudo docker build --progress=plain --build-arg LIGHTEN=1 --build-arg NEED_MIRROR=1 -f Dockerfile -t infiniflow/ragflow:nightly-slim . - - name: Build ragflow:nightly run: | - sudo docker build --progress=plain --build-arg NEED_MIRROR=1 -f Dockerfile -t infiniflow/ragflow:nightly . - - - name: Start ragflow:nightly-slim - run: | - echo -e "\nRAGFLOW_IMAGE=infiniflow/ragflow:nightly-slim" >> docker/.env - sudo docker compose -f docker/docker-compose.yml up -d - - - name: Stop ragflow:nightly-slim - if: always() # always run this step even if previous steps failed - run: | - sudo docker compose -f docker/docker-compose.yml down -v + RUNNER_WORKSPACE_PREFIX=${RUNNER_WORKSPACE_PREFIX:-${HOME}} + RAGFLOW_IMAGE=infiniflow/ragflow:${GITHUB_RUN_ID} + echo "RAGFLOW_IMAGE=${RAGFLOW_IMAGE}" >> ${GITHUB_ENV} + sudo docker pull ubuntu:22.04 + sudo DOCKER_BUILDKIT=1 docker build --build-arg NEED_MIRROR=1 -f Dockerfile -t ${RAGFLOW_IMAGE} . + if [[ ${GITHUB_EVENT_NAME} == "schedule" ]]; then + export HTTP_API_TEST_LEVEL=p3 + else + export HTTP_API_TEST_LEVEL=p2 + fi + echo "HTTP_API_TEST_LEVEL=${HTTP_API_TEST_LEVEL}" >> ${GITHUB_ENV} + echo "RAGFLOW_CONTAINER=${GITHUB_RUN_ID}-ragflow-cpu-1" >> ${GITHUB_ENV} - name: Start ragflow:nightly run: | - echo -e "\nRAGFLOW_IMAGE=infiniflow/ragflow:nightly" >> docker/.env - sudo docker compose -f docker/docker-compose.yml up -d + # Determine runner number (default to 1 if not found) + RUNNER_NUM=$(sudo docker inspect $(hostname) --format '{{index .Config.Labels "com.docker.compose.container-number"}}' 2>/dev/null || true) + RUNNER_NUM=${RUNNER_NUM:-1} + + # Compute port numbers using bash arithmetic + ES_PORT=$((1200 + RUNNER_NUM * 10)) + OS_PORT=$((1201 + RUNNER_NUM * 10)) + INFINITY_THRIFT_PORT=$((23817 + RUNNER_NUM * 10)) + INFINITY_HTTP_PORT=$((23820 + RUNNER_NUM * 10)) + INFINITY_PSQL_PORT=$((5432 + RUNNER_NUM * 10)) + MYSQL_PORT=$((5455 + RUNNER_NUM * 10)) + MINIO_PORT=$((9000 + RUNNER_NUM * 10)) + MINIO_CONSOLE_PORT=$((9001 + RUNNER_NUM * 10)) + REDIS_PORT=$((6379 + RUNNER_NUM * 10)) + TEI_PORT=$((6380 + RUNNER_NUM * 10)) + KIBANA_PORT=$((6601 + RUNNER_NUM * 10)) + SVR_HTTP_PORT=$((9380 + RUNNER_NUM * 10)) + ADMIN_SVR_HTTP_PORT=$((9381 + RUNNER_NUM * 10)) + SVR_MCP_PORT=$((9382 + RUNNER_NUM * 10)) + SANDBOX_EXECUTOR_MANAGER_PORT=$((9385 + RUNNER_NUM * 10)) + SVR_WEB_HTTP_PORT=$((80 + RUNNER_NUM * 10)) + SVR_WEB_HTTPS_PORT=$((443 + RUNNER_NUM * 10)) + + # Persist computed ports into docker/.env so docker-compose uses the correct host bindings + echo "" >> docker/.env + echo -e "ES_PORT=${ES_PORT}" >> docker/.env + echo -e "OS_PORT=${OS_PORT}" >> docker/.env + echo -e "INFINITY_THRIFT_PORT=${INFINITY_THRIFT_PORT}" >> docker/.env + echo -e "INFINITY_HTTP_PORT=${INFINITY_HTTP_PORT}" >> docker/.env + echo -e "INFINITY_PSQL_PORT=${INFINITY_PSQL_PORT}" >> docker/.env + echo -e "MYSQL_PORT=${MYSQL_PORT}" >> docker/.env + echo -e "MINIO_PORT=${MINIO_PORT}" >> docker/.env + echo -e "MINIO_CONSOLE_PORT=${MINIO_CONSOLE_PORT}" >> docker/.env + echo -e "REDIS_PORT=${REDIS_PORT}" >> docker/.env + echo -e "TEI_PORT=${TEI_PORT}" >> docker/.env + echo -e "KIBANA_PORT=${KIBANA_PORT}" >> docker/.env + echo -e "SVR_HTTP_PORT=${SVR_HTTP_PORT}" >> docker/.env + echo -e "ADMIN_SVR_HTTP_PORT=${ADMIN_SVR_HTTP_PORT}" >> docker/.env + echo -e "SVR_MCP_PORT=${SVR_MCP_PORT}" >> docker/.env + echo -e "SANDBOX_EXECUTOR_MANAGER_PORT=${SANDBOX_EXECUTOR_MANAGER_PORT}" >> docker/.env + echo -e "SVR_WEB_HTTP_PORT=${SVR_WEB_HTTP_PORT}" >> docker/.env + echo -e "SVR_WEB_HTTPS_PORT=${SVR_WEB_HTTPS_PORT}" >> docker/.env + + echo -e "COMPOSE_PROFILES=\${COMPOSE_PROFILES},tei-cpu" >> docker/.env + echo -e "TEI_MODEL=BAAI/bge-small-en-v1.5" >> docker/.env + echo -e "RAGFLOW_IMAGE=${RAGFLOW_IMAGE}" >> docker/.env + echo "HOST_ADDRESS=http://host.docker.internal:${SVR_HTTP_PORT}" >> ${GITHUB_ENV} + + sudo docker compose -f docker/docker-compose.yml -p ${GITHUB_RUN_ID} up -d + uv sync --python 3.10 --only-group test --no-default-groups --frozen && uv pip install sdk/python - name: Run sdk tests against Elasticsearch run: | export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY="" - export HOST_ADDRESS=http://host.docker.internal:9380 - until sudo docker exec ragflow-server curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do + until sudo docker exec ${RAGFLOW_CONTAINER} curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do echo "Waiting for service to be available..." sleep 5 done - if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then - export HTTP_API_TEST_LEVEL=p3 - else - export HTTP_API_TEST_LEVEL=p2 - fi - UV_LINK_MODE=copy uv sync --python 3.10 --only-group test --no-default-groups --frozen && uv pip install sdk/python && uv run --only-group test --no-default-groups pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_sdk_api + source .venv/bin/activate && pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_sdk_api - name: Run frontend api tests against Elasticsearch run: | export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY="" - export HOST_ADDRESS=http://host.docker.internal:9380 - until sudo docker exec ragflow-server curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do + until sudo docker exec ${RAGFLOW_CONTAINER} curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do echo "Waiting for service to be available..." sleep 5 done - cd sdk/python && UV_LINK_MODE=copy uv sync --python 3.10 --group test --frozen && source .venv/bin/activate && cd test/test_frontend_api && pytest -s --tb=short get_email.py test_dataset.py + source .venv/bin/activate && pytest -s --tb=short sdk/python/test/test_frontend_api/get_email.py sdk/python/test/test_frontend_api/test_dataset.py - name: Run http api tests against Elasticsearch run: | export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY="" - export HOST_ADDRESS=http://host.docker.internal:9380 - until sudo docker exec ragflow-server curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do + until sudo docker exec ${RAGFLOW_CONTAINER} curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do echo "Waiting for service to be available..." sleep 5 done - if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then - export HTTP_API_TEST_LEVEL=p3 - else - export HTTP_API_TEST_LEVEL=p2 - fi - UV_LINK_MODE=copy uv sync --python 3.10 --only-group test --no-default-groups --frozen && uv run --only-group test --no-default-groups pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_http_api + source .venv/bin/activate && pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_http_api - name: Stop ragflow:nightly if: always() # always run this step even if previous steps failed run: | - sudo docker compose -f docker/docker-compose.yml down -v + sudo docker compose -f docker/docker-compose.yml -p ${GITHUB_RUN_ID} down -v || true + sudo docker ps -a --filter "label=com.docker.compose.project=${GITHUB_RUN_ID}" -q | xargs -r sudo docker rm -f - name: Start ragflow:nightly run: | - sudo DOC_ENGINE=infinity docker compose -f docker/docker-compose.yml up -d + sed -i '1i DOC_ENGINE=infinity' docker/.env + sudo docker compose -f docker/docker-compose.yml -p ${GITHUB_RUN_ID} up -d - name: Run sdk tests against Infinity run: | export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY="" - export HOST_ADDRESS=http://host.docker.internal:9380 - until sudo docker exec ragflow-server curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do + until sudo docker exec ${RAGFLOW_CONTAINER} curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do echo "Waiting for service to be available..." sleep 5 done - if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then - export HTTP_API_TEST_LEVEL=p3 - else - export HTTP_API_TEST_LEVEL=p2 - fi - UV_LINK_MODE=copy uv sync --python 3.10 --only-group test --no-default-groups --frozen && uv pip install sdk/python && DOC_ENGINE=infinity uv run --only-group test --no-default-groups pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_sdk_api + source .venv/bin/activate && DOC_ENGINE=infinity pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_sdk_api - name: Run frontend api tests against Infinity run: | export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY="" - export HOST_ADDRESS=http://host.docker.internal:9380 - until sudo docker exec ragflow-server curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do + until sudo docker exec ${RAGFLOW_CONTAINER} curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do echo "Waiting for service to be available..." sleep 5 done - cd sdk/python && UV_LINK_MODE=copy uv sync --python 3.10 --group test --frozen && source .venv/bin/activate && cd test/test_frontend_api && pytest -s --tb=short get_email.py test_dataset.py + source .venv/bin/activate && DOC_ENGINE=infinity pytest -s --tb=short sdk/python/test/test_frontend_api/get_email.py sdk/python/test/test_frontend_api/test_dataset.py - name: Run http api tests against Infinity run: | export http_proxy=""; export https_proxy=""; export no_proxy=""; export HTTP_PROXY=""; export HTTPS_PROXY=""; export NO_PROXY="" - export HOST_ADDRESS=http://host.docker.internal:9380 - until sudo docker exec ragflow-server curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do + until sudo docker exec ${RAGFLOW_CONTAINER} curl -s --connect-timeout 5 ${HOST_ADDRESS} > /dev/null; do echo "Waiting for service to be available..." sleep 5 done - if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then - export HTTP_API_TEST_LEVEL=p3 - else - export HTTP_API_TEST_LEVEL=p2 - fi - UV_LINK_MODE=copy uv sync --python 3.10 --only-group test --no-default-groups --frozen && DOC_ENGINE=infinity uv run --only-group test --no-default-groups pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_http_api + source .venv/bin/activate && DOC_ENGINE=infinity pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_http_api - name: Stop ragflow:nightly if: always() # always run this step even if previous steps failed run: | - sudo DOC_ENGINE=infinity docker compose -f docker/docker-compose.yml down -v + # Sometimes `docker compose down` fail due to hang container, heavy load etc. Need to remove such containers to release resources(for example, listen ports). + sudo docker compose -f docker/docker-compose.yml -p ${GITHUB_RUN_ID} down -v || true + sudo docker ps -a --filter "label=com.docker.compose.project=${GITHUB_RUN_ID}" -q | xargs -r sudo docker rm -f + if [[ -n ${RAGFLOW_IMAGE} ]]; then + sudo docker rmi -f ${RAGFLOW_IMAGE} + fi diff --git a/.gitignore b/.gitignore index 52c53277043..fbf80b3aabd 100644 --- a/.gitignore +++ b/.gitignore @@ -149,7 +149,7 @@ out # Nuxt.js build / generate output .nuxt dist - +ragflow_cli.egg-info # Gatsby files .cache/ # Comment in the public line in if your project uses Gatsby and not Next.js @@ -193,3 +193,5 @@ dist # SvelteKit build / generate output .svelte-kit +# Default backup dir +backup diff --git a/.trivyignore b/.trivyignore new file mode 100644 index 00000000000..8f2725fe68d --- /dev/null +++ b/.trivyignore @@ -0,0 +1,15 @@ +**/*.md +**/*.min.js +**/*.min.css +**/*.svg +**/*.png +**/*.jpg +**/*.jpeg +**/*.gif +**/*.woff +**/*.woff2 +**/*.map +**/*.webp +**/*.ico +**/*.ttf +**/*.eot \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000000..7e5d43f9d68 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,116 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +RAGFlow is an open-source RAG (Retrieval-Augmented Generation) engine based on deep document understanding. It's a full-stack application with: +- Python backend (Flask-based API server) +- React/TypeScript frontend (built with UmiJS) +- Microservices architecture with Docker deployment +- Multiple data stores (MySQL, Elasticsearch/Infinity, Redis, MinIO) + +## Architecture + +### Backend (`/api/`) +- **Main Server**: `api/ragflow_server.py` - Flask application entry point +- **Apps**: Modular Flask blueprints in `api/apps/` for different functionalities: + - `kb_app.py` - Knowledge base management + - `dialog_app.py` - Chat/conversation handling + - `document_app.py` - Document processing + - `canvas_app.py` - Agent workflow canvas + - `file_app.py` - File upload/management +- **Services**: Business logic in `api/db/services/` +- **Models**: Database models in `api/db/db_models.py` + +### Core Processing (`/rag/`) +- **Document Processing**: `deepdoc/` - PDF parsing, OCR, layout analysis +- **LLM Integration**: `rag/llm/` - Model abstractions for chat, embedding, reranking +- **RAG Pipeline**: `rag/flow/` - Chunking, parsing, tokenization +- **Graph RAG**: `graphrag/` - Knowledge graph construction and querying + +### Agent System (`/agent/`) +- **Components**: Modular workflow components (LLM, retrieval, categorize, etc.) +- **Templates**: Pre-built agent workflows in `agent/templates/` +- **Tools**: External API integrations (Tavily, Wikipedia, SQL execution, etc.) + +### Frontend (`/web/`) +- React/TypeScript with UmiJS framework +- Ant Design + shadcn/ui components +- State management with Zustand +- Tailwind CSS for styling + +## Common Development Commands + +### Backend Development +```bash +# Install Python dependencies +uv sync --python 3.10 --all-extras +uv run download_deps.py +pre-commit install + +# Start dependent services +docker compose -f docker/docker-compose-base.yml up -d + +# Run backend (requires services to be running) +source .venv/bin/activate +export PYTHONPATH=$(pwd) +bash docker/launch_backend_service.sh + +# Run tests +uv run pytest + +# Linting +ruff check +ruff format +``` + +### Frontend Development +```bash +cd web +npm install +npm run dev # Development server +npm run build # Production build +npm run lint # ESLint +npm run test # Jest tests +``` + +### Docker Development +```bash +# Full stack with Docker +cd docker +docker compose -f docker-compose.yml up -d + +# Check server status +docker logs -f ragflow-server + +# Rebuild images +docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly . +``` + +## Key Configuration Files + +- `docker/.env` - Environment variables for Docker deployment +- `docker/service_conf.yaml.template` - Backend service configuration +- `pyproject.toml` - Python dependencies and project configuration +- `web/package.json` - Frontend dependencies and scripts + +## Testing + +- **Python**: pytest with markers (p1/p2/p3 priority levels) +- **Frontend**: Jest with React Testing Library +- **API Tests**: HTTP API and SDK tests in `test/` and `sdk/python/test/` + +## Database Engines + +RAGFlow supports switching between Elasticsearch (default) and Infinity: +- Set `DOC_ENGINE=infinity` in `docker/.env` to use Infinity +- Requires container restart: `docker compose down -v && docker compose up -d` + +## Development Environment Requirements + +- Python 3.10-3.12 +- Node.js >=18.20.4 +- Docker & Docker Compose +- uv package manager +- 16GB+ RAM, 50GB+ disk space \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 67fd2645682..b16a0d7d518 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,6 @@ USER root SHELL ["/bin/bash", "-c"] ARG NEED_MIRROR=0 -ARG LIGHTEN=0 -ENV LIGHTEN=${LIGHTEN} WORKDIR /ragflow @@ -17,13 +15,6 @@ RUN --mount=type=bind,from=infiniflow/ragflow_deps:latest,source=/huggingface.co /huggingface.co/InfiniFlow/text_concat_xgb_v1.0 \ /huggingface.co/InfiniFlow/deepdoc \ | tar -xf - --strip-components=3 -C /ragflow/rag/res/deepdoc -RUN --mount=type=bind,from=infiniflow/ragflow_deps:latest,source=/huggingface.co,target=/huggingface.co \ - if [ "$LIGHTEN" != "1" ]; then \ - (tar -cf - \ - /huggingface.co/BAAI/bge-large-zh-v1.5 \ - /huggingface.co/maidalun1020/bce-embedding-base_v1 \ - | tar -xf - --strip-components=2 -C /root/.ragflow) \ - fi # https://github.com/chrismattmann/tika-python # This is the only way to run python-tika without internet access. Without this set, the default is to check the tika version and pull latest every time from Apache. @@ -63,11 +54,11 @@ RUN --mount=type=cache,id=ragflow_apt,target=/var/cache/apt,sharing=locked \ apt install -y ghostscript RUN if [ "$NEED_MIRROR" == "1" ]; then \ - pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple && \ - pip3 config set global.trusted-host mirrors.aliyun.com; \ + pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \ + pip3 config set global.trusted-host pypi.tuna.tsinghua.edu.cn; \ mkdir -p /etc/uv && \ echo "[[index]]" > /etc/uv/uv.toml && \ - echo 'url = "https://mirrors.aliyun.com/pypi/simple"' >> /etc/uv/uv.toml && \ + echo 'url = "https://pypi.tuna.tsinghua.edu.cn/simple"' >> /etc/uv/uv.toml && \ echo "default = true" >> /etc/uv/uv.toml; \ fi; \ pipx install uv @@ -151,15 +142,11 @@ COPY pyproject.toml uv.lock ./ # uv records index url into uv.lock but doesn't failover among multiple indexes RUN --mount=type=cache,id=ragflow_uv,target=/root/.cache/uv,sharing=locked \ if [ "$NEED_MIRROR" == "1" ]; then \ - sed -i 's|pypi.org|mirrors.aliyun.com/pypi|g' uv.lock; \ + sed -i 's|pypi.org|pypi.tuna.tsinghua.edu.cn|g' uv.lock; \ else \ - sed -i 's|mirrors.aliyun.com/pypi|pypi.org|g' uv.lock; \ + sed -i 's|pypi.tuna.tsinghua.edu.cn|pypi.org|g' uv.lock; \ fi; \ - if [ "$LIGHTEN" == "1" ]; then \ - uv sync --python 3.10 --frozen; \ - else \ - uv sync --python 3.10 --frozen --all-extras; \ - fi + uv sync --python 3.10 --frozen COPY web web COPY docs docs @@ -169,11 +156,7 @@ RUN --mount=type=cache,id=ragflow_npm,target=/root/.npm,sharing=locked \ COPY .git /ragflow/.git RUN version_info=$(git describe --tags --match=v* --first-parent --always); \ - if [ "$LIGHTEN" == "1" ]; then \ - version_info="$version_info slim"; \ - else \ - version_info="$version_info full"; \ - fi; \ + version_info="$version_info"; \ echo "RAGFlow version: $version_info"; \ echo $version_info > /ragflow/VERSION @@ -191,6 +174,7 @@ ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" ENV PYTHONPATH=/ragflow/ COPY web web +COPY admin admin COPY api api COPY conf conf COPY deepdoc deepdoc @@ -201,6 +185,7 @@ COPY agentic_reasoning agentic_reasoning COPY pyproject.toml uv.lock ./ COPY mcp mcp COPY plugin plugin +COPY common common COPY docker/service_conf.yaml.template ./conf/service_conf.yaml.template COPY docker/entrypoint.sh ./ diff --git a/Dockerfile_tei b/Dockerfile_tei new file mode 100644 index 00000000000..539002359b8 --- /dev/null +++ b/Dockerfile_tei @@ -0,0 +1,14 @@ +FROM ghcr.io/huggingface/text-embeddings-inference:cpu-1.8 + +# uv tool install huggingface_hub +# hf download --local-dir tei_data/BAAI/bge-small-en-v1.5 BAAI/bge-small-en-v1.5 +# hf download --local-dir tei_data/BAAI/bge-m3 BAAI/bge-m3 +# hf download --local-dir tei_data/Qwen/Qwen3-Embedding-0.6B Qwen/Qwen3-Embedding-0.6B +COPY tei_data /data + +# curl -X POST http://localhost:6380/embed -H "Content-Type: application/json" -d '{"inputs": "Hello, world! This is a test sentence."}' +# curl -X POST http://tei:80/embed -H "Content-Type: application/json" -d '{"inputs": "Hello, world! This is a test sentence."}' +# [[-0.058816575,0.019564206,0.026697718,...]] + +# curl -X POST http://localhost:6380/v1/embeddings -H "Content-Type: application/json" -d '{"input": "Hello, world! This is a test sentence."}' +# {"object":"list","data":[{"object":"embedding","embedding":[-0.058816575,0.019564206,...],"index":0}],"model":"BAAI/bge-small-en-v1.5","usage":{"prompt_tokens":12,"total_tokens":12}} diff --git a/README.md b/README.md index c8e47cdbc92..299bd67fd0a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@
-ragflow logo +ragflow logo
@@ -22,7 +22,7 @@ Static Badge - docker pull infiniflow/ragflow:v0.19.1 + docker pull infiniflow/ragflow:v0.22.0 Latest Release @@ -43,7 +43,9 @@ Demo -# +
+ +
infiniflow%2Fragflow | Trendshift @@ -59,8 +61,7 @@ - 🔎 [System Architecture](#-system-architecture) - 🎬 [Get Started](#-get-started) - 🔧 [Configurations](#-configurations) -- 🔧 [Build a docker image without embedding models](#-build-a-docker-image-without-embedding-models) -- 🔧 [Build a docker image including embedding models](#-build-a-docker-image-including-embedding-models) +- 🔧 [Build a Docker image](#-build-a-docker-image) - 🔨 [Launch service from source for development](#-launch-service-from-source-for-development) - 📚 [Documentation](#-documentation) - 📜 [Roadmap](#-roadmap) @@ -71,26 +72,27 @@ ## 💡 What is RAGFlow? -[RAGFlow](https://ragflow.io/) is an open-source RAG (Retrieval-Augmented Generation) engine based on deep document -understanding. It offers a streamlined RAG workflow for businesses of any scale, combining LLM (Large Language Models) -to provide truthful question-answering capabilities, backed by well-founded citations from various complex formatted -data. +[RAGFlow](https://ragflow.io/) is a leading open-source Retrieval-Augmented Generation (RAG) engine that fuses cutting-edge RAG with Agent capabilities to create a superior context layer for LLMs. It offers a streamlined RAG workflow adaptable to enterprises of any scale. Powered by a converged context engine and pre-built agent templates, RAGFlow enables developers to transform complex data into high-fidelity, production-ready AI systems with exceptional efficiency and precision. ## 🎮 Demo Try our demo at [https://demo.ragflow.io](https://demo.ragflow.io).
- - + +
## 🔥 Latest Updates +- 2025-11-12 Supports data synchronization from Confluence, AWS S3, Discord, Google Drive. +- 2025-10-23 Supports MinerU & Docling as document parsing methods. +- 2025-10-15 Supports orchestrable ingestion pipeline. +- 2025-08-08 Supports OpenAI's latest GPT-5 series models. +- 2025-08-01 Supports agentic workflow and MCP. - 2025-05-23 Adds a Python/JavaScript code executor component to Agent. - 2025-05-05 Supports cross-language query. - 2025-03-19 Supports using a multi-modal model to make sense of images within PDF or DOCX files. -- 2025-02-28 Combined with Internet search (Tavily), supports reasoning like Deep Research for any LLMs. - 2024-12-18 Upgrades Document Layout Analysis model in DeepDoc. - 2024-08-22 Support text to SQL statements through RAG. @@ -135,7 +137,7 @@ releases! 🌟 ## 🔎 System Architecture
- +
## 🎬 Get Started @@ -174,41 +176,46 @@ releases! 🌟 > ```bash > vm.max_map_count=262144 > ``` - + > 2. Clone the repo: ```bash $ git clone https://github.com/infiniflow/ragflow.git ``` - 3. Start up the server using the pre-built Docker images: > [!CAUTION] > All Docker images are built for x86 platforms. We don't currently offer Docker images for ARM64. > If you are on an ARM64 platform, follow [this guide](https://ragflow.io/docs/dev/build_docker_image) to build a Docker image compatible with your system. - > The command below downloads the `v0.19.1-slim` edition of the RAGFlow Docker image. See the following table for descriptions of different RAGFlow editions. To download a RAGFlow edition different from `v0.19.1-slim`, update the `RAGFLOW_IMAGE` variable accordingly in **docker/.env** before using `docker compose` to start the server. For example: set `RAGFLOW_IMAGE=infiniflow/ragflow:v0.19.1` for the full edition `v0.19.1`. +> The command below downloads the `v0.22.0` edition of the RAGFlow Docker image. See the following table for descriptions of different RAGFlow editions. To download a RAGFlow edition different from `v0.22.0`, update the `RAGFLOW_IMAGE` variable accordingly in **docker/.env** before using `docker compose` to start the server. - ```bash +```bash $ cd ragflow/docker - # Use CPU for embedding and DeepDoc tasks: + + # Optional: use a stable tag (see releases: https://github.com/infiniflow/ragflow/releases), e.g.: git checkout v0.22.0 + + # Use CPU for DeepDoc tasks: $ docker compose -f docker-compose.yml up -d - # To use GPU to accelerate embedding and DeepDoc tasks: - # docker compose -f docker-compose-gpu.yml up -d - ``` + # To use GPU to accelerate DeepDoc tasks: + # sed -i '1i DEVICE=gpu' .env + # docker compose -f docker-compose.yml up -d +``` + +> Note: Prior to `v0.22.0`, we provided both images with embedding models and slim images without embedding models. Details as follows: - | RAGFlow image tag | Image size (GB) | Has embedding models? | Stable? | - |-------------------|-----------------|-----------------------|--------------------------| - | v0.19.1 | ≈9 | :heavy_check_mark: | Stable release | - | v0.19.1-slim | ≈2 | ❌ | Stable release | - | nightly | ≈9 | :heavy_check_mark: | _Unstable_ nightly build | - | nightly-slim | ≈2 | ❌ | _Unstable_ nightly build | +| RAGFlow image tag | Image size (GB) | Has embedding models? | Stable? | +| ----------------- | --------------- | --------------------- | ------------------------ | +| v0.21.1 | ≈9 | ✔️ | Stable release | +| v0.21.1-slim | ≈2 | ❌ | Stable release | + +> Starting with `v0.22.0`, we ship only the slim edition and no longer append the **-slim** suffix to the image tag. 4. Check the server status after having the server up and running: ```bash - $ docker logs -f ragflow-server + $ docker logs -f docker-ragflow-cpu-1 ``` _The following output confirms a successful launch of the system:_ @@ -226,14 +233,17 @@ releases! 🌟 > If you skip this confirmation step and directly log in to RAGFlow, your browser may prompt a `network anormal` > error because, at that moment, your RAGFlow may not be fully initialized. - + > 5. In your web browser, enter the IP address of your server and log in to RAGFlow. + > With the default settings, you only need to enter `http://IP_OF_YOUR_MACHINE` (**sans** port number) as the default > HTTP serving port `80` can be omitted when using the default configurations. + > 6. In [service_conf.yaml.template](./docker/service_conf.yaml.template), select the desired LLM factory in `user_default_llm` and update the `API_KEY` field with the corresponding API key. > See [llm_api_key_setup](https://ragflow.io/docs/dev/llm_api_key_setup) for more information. + > _The show is on!_ @@ -272,7 +282,6 @@ RAGFlow uses Elasticsearch by default for storing full text and vectors. To swit > `-v` will delete the docker container volumes, and the existing data will be cleared. 2. Set `DOC_ENGINE` in **docker/.env** to `infinity`. - 3. Start the containers: ```bash @@ -282,20 +291,10 @@ RAGFlow uses Elasticsearch by default for storing full text and vectors. To swit > [!WARNING] > Switching to Infinity on a Linux/arm64 machine is not yet officially supported. -## 🔧 Build a Docker image without embedding models +## 🔧 Build a Docker image This image is approximately 2 GB in size and relies on external LLM and embedding services. -```bash -git clone https://github.com/infiniflow/ragflow.git -cd ragflow/ -docker build --platform linux/amd64 --build-arg LIGHTEN=1 -f Dockerfile -t infiniflow/ragflow:nightly-slim . -``` - -## 🔧 Build a Docker image including embedding models - -This image is approximately 9 GB in size. As it includes embedding models, it relies on external LLM services only. - ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ @@ -304,22 +303,20 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly ## 🔨 Launch service from source for development -1. Install uv, or skip this step if it is already installed: +1. Install `uv` and `pre-commit`, or skip this step if they are already installed: ```bash pipx install uv pre-commit ``` - 2. Clone the source code and install Python dependencies: ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ - uv sync --python 3.10 --all-extras # install RAGFlow dependent python modules + uv sync --python 3.10 # install RAGFlow dependent python modules uv run download_deps.py pre-commit install ``` - 3. Launch the dependent services (MinIO, Elasticsearch, Redis, and MySQL) using Docker Compose: ```bash @@ -331,22 +328,23 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly ``` 127.0.0.1 es01 infinity mysql minio redis sandbox-executor-manager ``` - 4. If you cannot access HuggingFace, set the `HF_ENDPOINT` environment variable to use a mirror site: ```bash export HF_ENDPOINT=https://hf-mirror.com ``` - 5. If your operating system does not have jemalloc, please install it as follows: ```bash - # ubuntu + # Ubuntu sudo apt-get install libjemalloc-dev - # centos + # CentOS sudo yum install jemalloc + # OpenSUSE + sudo zypper install jemalloc + # macOS + sudo brew install jemalloc ``` - 6. Launch backend service: ```bash @@ -354,14 +352,12 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly export PYTHONPATH=$(pwd) bash docker/launch_backend_service.sh ``` - 7. Install frontend dependencies: ```bash cd web npm install ``` - 8. Launch frontend service: ```bash @@ -371,14 +367,12 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly _The following output confirms a successful launch of the system:_ ![](https://github.com/user-attachments/assets/0daf462c-a24d-4496-a66f-92533534e187) - 9. Stop RAGFlow front-end and back-end service after development is complete: ```bash pkill -f "ragflow_server.py|task_executor.py" ``` - ## 📚 Documentation - [Quickstart](https://ragflow.io/docs/dev/) diff --git a/README_id.md b/README_id.md index 50e00a9d5ed..c9017ddd126 100644 --- a/README_id.md +++ b/README_id.md @@ -1,6 +1,6 @@
-Logo ragflow +Logo ragflow
@@ -22,7 +22,7 @@ Lencana Daring - docker pull infiniflow/ragflow:v0.19.1 + docker pull infiniflow/ragflow:v0.22.0 Rilis Terbaru @@ -43,7 +43,13 @@ Demo -# +
+ +
+ +
+infiniflow%2Fragflow | Trendshift +
📕 Daftar Isi @@ -55,8 +61,7 @@ - 🔎 [Arsitektur Sistem](#-arsitektur-sistem) - 🎬 [Mulai](#-mulai) - 🔧 [Konfigurasi](#-konfigurasi) -- 🔧 [Membangun Image Docker tanpa Model Embedding](#-membangun-image-docker-tanpa-model-embedding) -- 🔧 [Membangun Image Docker dengan Model Embedding](#-membangun-image-docker-dengan-model-embedding) +- 🔧 [Membangun Image Docker](#-membangun-docker-image) - 🔨 [Meluncurkan aplikasi dari Sumber untuk Pengembangan](#-meluncurkan-aplikasi-dari-sumber-untuk-pengembangan) - 📚 [Dokumentasi](#-dokumentasi) - 📜 [Peta Jalan](#-peta-jalan) @@ -67,23 +72,27 @@ ## 💡 Apa Itu RAGFlow? -[RAGFlow](https://ragflow.io/) adalah mesin RAG (Retrieval-Augmented Generation) open-source berbasis pemahaman dokumen yang mendalam. Platform ini menyediakan alur kerja RAG yang efisien untuk bisnis dengan berbagai skala, menggabungkan LLM (Large Language Models) untuk menyediakan kemampuan tanya-jawab yang benar dan didukung oleh referensi dari data terstruktur kompleks. +[RAGFlow](https://ragflow.io/) adalah mesin RAG (Retrieval-Augmented Generation) open-source terkemuka yang mengintegrasikan teknologi RAG mutakhir dengan kemampuan Agent untuk menciptakan lapisan kontekstual superior bagi LLM. Menyediakan alur kerja RAG yang efisien dan dapat diadaptasi untuk perusahaan segala skala. Didukung oleh mesin konteks terkonvergensi dan template Agent yang telah dipra-bangun, RAGFlow memungkinkan pengembang mengubah data kompleks menjadi sistem AI kesetiaan-tinggi dan siap-produksi dengan efisiensi dan presisi yang luar biasa. ## 🎮 Demo Coba demo kami di [https://demo.ragflow.io](https://demo.ragflow.io).
- - + +
## 🔥 Pembaruan Terbaru +- 2025-11-12 Mendukung sinkronisasi data dari Confluence, AWS S3, Discord, Google Drive. +- 2025-10-23 Mendukung MinerU & Docling sebagai metode penguraian dokumen. +- 2025-10-15 Dukungan untuk jalur data yang terorkestrasi. +- 2025-08-08 Mendukung model seri GPT-5 terbaru dari OpenAI. +- 2025-08-01 Mendukung alur kerja agen dan MCP. - 2025-05-23 Menambahkan komponen pelaksana kode Python/JS ke Agen. - 2025-05-05 Mendukung kueri lintas bahasa. - 2025-03-19 Mendukung penggunaan model multi-modal untuk memahami gambar di dalam file PDF atau DOCX. -- 2025-02-28 dikombinasikan dengan pencarian Internet (TAVILY), mendukung penelitian mendalam untuk LLM apa pun. - 2024-12-18 Meningkatkan model Analisis Tata Letak Dokumen di DeepDoc. - 2024-08-22 Dukungan untuk teks ke pernyataan SQL melalui RAG. @@ -126,7 +135,7 @@ Coba demo kami di [https://demo.ragflow.io](https://demo.ragflow.io). ## 🔎 Arsitektur Sistem
- +
## 🎬 Mulai @@ -165,41 +174,46 @@ Coba demo kami di [https://demo.ragflow.io](https://demo.ragflow.io). > ```bash > vm.max_map_count=262144 > ``` - + > 2. Clone repositori: ```bash $ git clone https://github.com/infiniflow/ragflow.git ``` - 3. Bangun image Docker pre-built dan jalankan server: > [!CAUTION] > Semua gambar Docker dibangun untuk platform x86. Saat ini, kami tidak menawarkan gambar Docker untuk ARM64. > Jika Anda menggunakan platform ARM64, [silakan gunakan panduan ini untuk membangun gambar Docker yang kompatibel dengan sistem Anda](https://ragflow.io/docs/dev/build_docker_image). -> Perintah di bawah ini mengunduh edisi v0.19.1-slim dari gambar Docker RAGFlow. Silakan merujuk ke tabel berikut untuk deskripsi berbagai edisi RAGFlow. Untuk mengunduh edisi RAGFlow yang berbeda dari v0.19.1-slim, perbarui variabel RAGFLOW_IMAGE di docker/.env sebelum menggunakan docker compose untuk memulai server. Misalnya, atur RAGFLOW_IMAGE=infiniflow/ragflow:v0.19.1 untuk edisi lengkap v0.19.1. +> Perintah di bawah ini mengunduh edisi v0.22.0 dari gambar Docker RAGFlow. Silakan merujuk ke tabel berikut untuk deskripsi berbagai edisi RAGFlow. Untuk mengunduh edisi RAGFlow yang berbeda dari v0.22.0, perbarui variabel RAGFLOW_IMAGE di docker/.env sebelum menggunakan docker compose untuk memulai server. ```bash -$ cd ragflow/docker -# Use CPU for embedding and DeepDoc tasks: -$ docker compose -f docker-compose.yml up -d + $ cd ragflow/docker + + # Opsional: gunakan tag stabil (lihat releases: https://github.com/infiniflow/ragflow/releases), contoh: git checkout v0.22.0 + + # Use CPU for DeepDoc tasks: + $ docker compose -f docker-compose.yml up -d -# To use GPU to accelerate embedding and DeepDoc tasks: -# docker compose -f docker-compose-gpu.yml up -d + # To use GPU to accelerate DeepDoc tasks: + # sed -i '1i DEVICE=gpu' .env + # docker compose -f docker-compose.yml up -d ``` +> Catatan: Sebelum `v0.22.0`, kami menyediakan image dengan model embedding dan image slim tanpa model embedding. Detailnya sebagai berikut: + | RAGFlow image tag | Image size (GB) | Has embedding models? | Stable? | | ----------------- | --------------- | --------------------- | ------------------------ | -| v0.19.1 | ≈9 | :heavy_check_mark: | Stable release | -| v0.19.1-slim | ≈2 | ❌ | Stable release | -| nightly | ≈9 | :heavy_check_mark: | _Unstable_ nightly build | -| nightly-slim | ≈2 | ❌ | _Unstable_ nightly build | +| v0.21.1 | ≈9 | ✔️ | Stable release | +| v0.21.1-slim | ≈2 | ❌ | Stable release | + +> Mulai dari `v0.22.0`, kami hanya menyediakan edisi slim dan tidak lagi menambahkan akhiran **-slim** pada tag image. 1. Periksa status server setelah server aktif dan berjalan: ```bash - $ docker logs -f ragflow-server + $ docker logs -f docker-ragflow-cpu-1 ``` _Output berikut menandakan bahwa sistem berhasil diluncurkan:_ @@ -217,14 +231,17 @@ $ docker compose -f docker-compose.yml up -d > Jika Anda melewatkan langkah ini dan langsung login ke RAGFlow, browser Anda mungkin menampilkan error `network anormal` > karena RAGFlow mungkin belum sepenuhnya siap. - + > 2. Buka browser web Anda, masukkan alamat IP server Anda, dan login ke RAGFlow. + > Dengan pengaturan default, Anda hanya perlu memasukkan `http://IP_DEVICE_ANDA` (**tanpa** nomor port) karena > port HTTP default `80` bisa dihilangkan saat menggunakan konfigurasi default. + > 3. Dalam [service_conf.yaml.template](./docker/service_conf.yaml.template), pilih LLM factory yang diinginkan di `user_default_llm` dan perbarui bidang `API_KEY` dengan kunci API yang sesuai. > Lihat [llm_api_key_setup](https://ragflow.io/docs/dev/llm_api_key_setup) untuk informasi lebih lanjut. + > _Sistem telah siap digunakan!_ @@ -246,20 +263,10 @@ Pembaruan konfigurasi ini memerlukan reboot semua kontainer agar efektif: > $ docker compose -f docker-compose.yml up -d > ``` -## 🔧 Membangun Docker Image tanpa Model Embedding +## 🔧 Membangun Docker Image Image ini berukuran sekitar 2 GB dan bergantung pada aplikasi LLM eksternal dan embedding. -```bash -git clone https://github.com/infiniflow/ragflow.git -cd ragflow/ -docker build --platform linux/amd64 --build-arg LIGHTEN=1 -f Dockerfile -t infiniflow/ragflow:nightly-slim . -``` - -## 🔧 Membangun Docker Image Termasuk Model Embedding - -Image ini berukuran sekitar 9 GB. Karena sudah termasuk model embedding, ia hanya bergantung pada aplikasi LLM eksternal. - ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ @@ -268,22 +275,20 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly ## 🔨 Menjalankan Aplikasi dari untuk Pengembangan -1. Instal uv, atau lewati langkah ini jika sudah terinstal: +1. Instal `uv` dan `pre-commit`, atau lewati langkah ini jika sudah terinstal: ```bash pipx install uv pre-commit ``` - 2. Clone kode sumber dan instal dependensi Python: ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ - uv sync --python 3.10 --all-extras # install RAGFlow dependent python modules + uv sync --python 3.10 # install RAGFlow dependent python modules uv run download_deps.py pre-commit install ``` - 3. Jalankan aplikasi yang diperlukan (MinIO, Elasticsearch, Redis, dan MySQL) menggunakan Docker Compose: ```bash @@ -295,13 +300,11 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly ``` 127.0.0.1 es01 infinity mysql minio redis sandbox-executor-manager ``` - 4. Jika Anda tidak dapat mengakses HuggingFace, atur variabel lingkungan `HF_ENDPOINT` untuk menggunakan situs mirror: ```bash export HF_ENDPOINT=https://hf-mirror.com ``` - 5. Jika sistem operasi Anda tidak memiliki jemalloc, instal sebagai berikut: ```bash @@ -309,8 +312,9 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly sudo apt-get install libjemalloc-dev # centos sudo yum install jemalloc + # mac + sudo brew install jemalloc ``` - 6. Jalankan aplikasi backend: ```bash @@ -318,14 +322,12 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly export PYTHONPATH=$(pwd) bash docker/launch_backend_service.sh ``` - 7. Instal dependensi frontend: ```bash cd web npm install ``` - 8. Jalankan aplikasi frontend: ```bash @@ -335,15 +337,12 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly _Output berikut menandakan bahwa sistem berhasil diluncurkan:_ ![](https://github.com/user-attachments/assets/0daf462c-a24d-4496-a66f-92533534e187) - - 9. Hentikan layanan front-end dan back-end RAGFlow setelah pengembangan selesai: ```bash pkill -f "ragflow_server.py|task_executor.py" ``` - ## 📚 Dokumentasi - [Quickstart](https://ragflow.io/docs/dev/) diff --git a/README_ja.md b/README_ja.md index f0f153de060..24bce0874c3 100644 --- a/README_ja.md +++ b/README_ja.md @@ -1,6 +1,6 @@
-ragflow logo +ragflow logo
@@ -22,7 +22,7 @@ Static Badge - docker pull infiniflow/ragflow:v0.19.1 + docker pull infiniflow/ragflow:v0.22.0 Latest Release @@ -43,27 +43,37 @@ Demo -# +
+ +
+ +
+infiniflow%2Fragflow | Trendshift +
## 💡 RAGFlow とは? -[RAGFlow](https://ragflow.io/) は、深い文書理解に基づいたオープンソースの RAG (Retrieval-Augmented Generation) エンジンである。LLM(大規模言語モデル)を組み合わせることで、様々な複雑なフォーマットのデータから根拠のある引用に裏打ちされた、信頼できる質問応答機能を実現し、あらゆる規模のビジネスに適した RAG ワークフローを提供します。 +[RAGFlow](https://ragflow.io/) は、先進的なRAG(Retrieval-Augmented Generation)技術と Agent 機能を融合し、大規模言語モデル(LLM)に優れたコンテキスト層を構築する最先端のオープンソース RAG エンジンです。あらゆる規模の企業に対応可能な合理化された RAG ワークフローを提供し、統合型コンテキストエンジンと事前構築されたAgentテンプレートにより、開発者が複雑なデータを驚異的な効率性と精度で高精細なプロダクションレディAIシステムへ変換することを可能にします。 ## 🎮 Demo デモをお試しください:[https://demo.ragflow.io](https://demo.ragflow.io)。
- - + +
## 🔥 最新情報 +- 2025-11-12 Confluence、AWS S3、Discord、Google Drive からのデータ同期をサポートします。 +- 2025-10-23 ドキュメント解析方法として MinerU と Docling をサポートします。 +- 2025-10-15 オーケストレーションされたデータパイプラインのサポート。 +- 2025-08-08 OpenAI の最新 GPT-5 シリーズモデルをサポートします。 +- 2025-08-01 エージェントワークフローとMCPをサポート。 - 2025-05-23 エージェントに Python/JS コードエグゼキュータコンポーネントを追加しました。 - 2025-05-05 言語間クエリをサポートしました。 - 2025-03-19 PDFまたはDOCXファイル内の画像を理解するために、多モーダルモデルを使用することをサポートします。 -- 2025-02-28 インターネット検索 (TAVILY) と組み合わせて、あらゆる LLM の詳細な調査をサポートします。 - 2024-12-18 DeepDoc のドキュメント レイアウト分析モデルをアップグレードします。 - 2024-08-22 RAG を介して SQL ステートメントへのテキストをサポートします。 @@ -106,7 +116,7 @@ ## 🔎 システム構成
- +
## 🎬 初期設定 @@ -144,41 +154,46 @@ > ```bash > vm.max_map_count=262144 > ``` - + > 2. リポジトリをクローンする: ```bash $ git clone https://github.com/infiniflow/ragflow.git ``` - 3. ビルド済みの Docker イメージをビルドし、サーバーを起動する: > [!CAUTION] > 現在、公式に提供されているすべての Docker イメージは x86 アーキテクチャ向けにビルドされており、ARM64 用の Docker イメージは提供されていません。 > ARM64 アーキテクチャのオペレーティングシステムを使用している場合は、[このドキュメント](https://ragflow.io/docs/dev/build_docker_image)を参照して Docker イメージを自分でビルドしてください。 - > 以下のコマンドは、RAGFlow Docker イメージの v0.19.1-slim エディションをダウンロードします。異なる RAGFlow エディションの説明については、以下の表を参照してください。v0.19.1-slim とは異なるエディションをダウンロードするには、docker/.env ファイルの RAGFLOW_IMAGE 変数を適宜更新し、docker compose を使用してサーバーを起動してください。例えば、完全版 v0.19.1 をダウンロードするには、RAGFLOW_IMAGE=infiniflow/ragflow:v0.19.1 と設定します。 +> 以下のコマンドは、RAGFlow Docker イメージの v0.22.0 エディションをダウンロードします。異なる RAGFlow エディションの説明については、以下の表を参照してください。v0.22.0 とは異なるエディションをダウンロードするには、docker/.env ファイルの RAGFLOW_IMAGE 変数を適宜更新し、docker compose を使用してサーバーを起動してください。 - ```bash +```bash $ cd ragflow/docker - # Use CPU for embedding and DeepDoc tasks: + + # 任意: 安定版タグを利用 (一覧: https://github.com/infiniflow/ragflow/releases) 例: git checkout v0.22.0 + + # Use CPU for DeepDoc tasks: $ docker compose -f docker-compose.yml up -d - # To use GPU to accelerate embedding and DeepDoc tasks: - # docker compose -f docker-compose-gpu.yml up -d - ``` + # To use GPU to accelerate DeepDoc tasks: + # sed -i '1i DEVICE=gpu' .env + # docker compose -f docker-compose.yml up -d +``` + +> 注意:`v0.22.0` より前のバージョンでは、embedding モデルを含むイメージと、embedding モデルを含まない slim イメージの両方を提供していました。詳細は以下の通りです: - | RAGFlow image tag | Image size (GB) | Has embedding models? | Stable? | - | ----------------- | --------------- | --------------------- | ------------------------ | - | v0.19.1 | ≈9 | :heavy_check_mark: | Stable release | - | v0.19.1-slim | ≈2 | ❌ | Stable release | - | nightly | ≈9 | :heavy_check_mark: | _Unstable_ nightly build | - | nightly-slim | ≈2 | ❌ | _Unstable_ nightly build | +| RAGFlow image tag | Image size (GB) | Has embedding models? | Stable? | +| ----------------- | --------------- | --------------------- | ------------------------ | +| v0.21.1 | ≈9 | ✔️ | Stable release | +| v0.21.1-slim | ≈2 | ❌ | Stable release | -1. サーバーを立ち上げた後、サーバーの状態を確認する: +> `v0.22.0` 以降、当プロジェクトでは slim エディションのみを提供し、イメージタグに **-slim** サフィックスを付けなくなりました。 + 1. サーバーを立ち上げた後、サーバーの状態を確認する: + ```bash - $ docker logs -f ragflow-server + $ docker logs -f docker-ragflow-cpu-1 ``` _以下の出力は、システムが正常に起動したことを確認するものです:_ @@ -194,12 +209,15 @@ ``` > もし確認ステップをスキップして直接 RAGFlow にログインした場合、その時点で RAGFlow が完全に初期化されていない可能性があるため、ブラウザーがネットワーク異常エラーを表示するかもしれません。 - + > 2. ウェブブラウザで、プロンプトに従ってサーバーの IP アドレスを入力し、RAGFlow にログインします。 + > デフォルトの設定を使用する場合、デフォルトの HTTP サービングポート `80` は省略できるので、与えられたシナリオでは、`http://IP_OF_YOUR_MACHINE`(ポート番号は省略)だけを入力すればよい。 + > 3. [service_conf.yaml.template](./docker/service_conf.yaml.template) で、`user_default_llm` で希望の LLM ファクトリを選択し、`API_KEY` フィールドを対応する API キーで更新する。 > 詳しくは [llm_api_key_setup](https://ragflow.io/docs/dev/llm_api_key_setup) を参照してください。 + > _これで初期設定完了!ショーの開幕です!_ @@ -228,33 +246,27 @@ RAGFlow はデフォルトで Elasticsearch を使用して全文とベクトルを保存します。[Infinity]に切り替え(https://github.com/infiniflow/infinity/)、次の手順に従います。 1. 実行中のすべてのコンテナを停止するには: + ```bash $ docker compose -f docker/docker-compose.yml down -v ``` + Note: `-v` は docker コンテナのボリュームを削除し、既存のデータをクリアします。 2. **docker/.env** の「DOC \_ ENGINE」を「infinity」に設定します。 - 3. 起動コンテナ: + ```bash $ docker compose -f docker-compose.yml up -d ``` + > [!WARNING] > Linux/arm64 マシンでの Infinity への切り替えは正式にサポートされていません。 + > -## 🔧 ソースコードで Docker イメージを作成(埋め込みモデルなし) +## 🔧 ソースコードで Docker イメージを作成 この Docker イメージのサイズは約 1GB で、外部の大モデルと埋め込みサービスに依存しています。 -```bash -git clone https://github.com/infiniflow/ragflow.git -cd ragflow/ -docker build --platform linux/amd64 --build-arg LIGHTEN=1 -f Dockerfile -t infiniflow/ragflow:nightly-slim . -``` - -## 🔧 ソースコードをコンパイルした Docker イメージ(埋め込みモデルを含む) - -この Docker のサイズは約 9GB で、埋め込みモデルを含むため、外部の大モデルサービスのみが必要です。 - ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ @@ -263,22 +275,20 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly ## 🔨 ソースコードからサービスを起動する方法 -1. uv をインストールする。すでにインストールされている場合は、このステップをスキップしてください: +1. `uv` と `pre-commit` をインストールする。すでにインストールされている場合は、このステップをスキップしてください: ```bash pipx install uv pre-commit ``` - 2. ソースコードをクローンし、Python の依存関係をインストールする: ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ - uv sync --python 3.10 --all-extras # install RAGFlow dependent python modules + uv sync --python 3.10 # install RAGFlow dependent python modules uv run download_deps.py pre-commit install ``` - 3. Docker Compose を使用して依存サービス(MinIO、Elasticsearch、Redis、MySQL)を起動する: ```bash @@ -290,22 +300,21 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly ``` 127.0.0.1 es01 infinity mysql minio redis sandbox-executor-manager ``` - 4. HuggingFace にアクセスできない場合は、`HF_ENDPOINT` 環境変数を設定してミラーサイトを使用してください: ```bash export HF_ENDPOINT=https://hf-mirror.com ``` - 5. オペレーティングシステムにjemallocがない場合は、次のようにインストールします: - + ```bash # ubuntu sudo apt-get install libjemalloc-dev # centos sudo yum install jemalloc + # mac + sudo brew install jemalloc ``` - 6. バックエンドサービスを起動する: ```bash @@ -313,14 +322,12 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly export PYTHONPATH=$(pwd) bash docker/launch_backend_service.sh ``` - 7. フロントエンドの依存関係をインストールする: ```bash cd web npm install ``` - 8. フロントエンドサービスを起動する: ```bash @@ -330,14 +337,12 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly _以下の画面で、システムが正常に起動したことを示します:_ ![](https://github.com/user-attachments/assets/0daf462c-a24d-4496-a66f-92533534e187) - 9. 開発が完了したら、RAGFlow のフロントエンド サービスとバックエンド サービスを停止します: ```bash pkill -f "ragflow_server.py|task_executor.py" ``` - ## 📚 ドキュメンテーション - [Quickstart](https://ragflow.io/docs/dev/) diff --git a/README_ko.md b/README_ko.md index 322a32d20ed..bd5acf82d4d 100644 --- a/README_ko.md +++ b/README_ko.md @@ -1,6 +1,6 @@
-ragflow logo +ragflow logo
@@ -22,7 +22,7 @@ Static Badge - docker pull infiniflow/ragflow:v0.19.1 + docker pull infiniflow/ragflow:v0.22.0 Latest Release @@ -43,27 +43,38 @@ Demo -# +
+ +
+ +
+infiniflow%2Fragflow | Trendshift +
+ ## 💡 RAGFlow란? -[RAGFlow](https://ragflow.io/)는 심층 문서 이해에 기반한 오픈소스 RAG (Retrieval-Augmented Generation) 엔진입니다. 이 엔진은 대규모 언어 모델(LLM)과 결합하여 정확한 질문 응답 기능을 제공하며, 다양한 복잡한 형식의 데이터에서 신뢰할 수 있는 출처를 바탕으로 한 인용을 통해 이를 뒷받침합니다. RAGFlow는 규모에 상관없이 모든 기업에 최적화된 RAG 워크플로우를 제공합니다. +[RAGFlow](https://ragflow.io/) 는 최첨단 RAG(Retrieval-Augmented Generation)와 Agent 기능을 융합하여 대규모 언어 모델(LLM)을 위한 우수한 컨텍스트 계층을 생성하는 선도적인 오픈소스 RAG 엔진입니다. 모든 규모의 기업에 적용 가능한 효율적인 RAG 워크플로를 제공하며, 통합 컨텍스트 엔진과 사전 구축된 Agent 템플릿을 통해 개발자들이 복잡한 데이터를 예외적인 효율성과 정밀도로 고급 구현도의 프로덕션 준비 완료 AI 시스템으로 변환할 수 있도록 지원합니다. ## 🎮 데모 데모를 [https://demo.ragflow.io](https://demo.ragflow.io)에서 실행해 보세요.
- - + +
## 🔥 업데이트 +- 2025-11-12 Confluence, AWS S3, Discord, Google Drive에서 데이터 동기화를 지원합니다. +- 2025-10-23 문서 파싱 방법으로 MinerU 및 Docling을 지원합니다. +- 2025-10-15 조정된 데이터 파이프라인 지원. +- 2025-08-08 OpenAI의 최신 GPT-5 시리즈 모델을 지원합니다. +- 2025-08-01 에이전트 워크플로우와 MCP를 지원합니다. - 2025-05-23 Agent에 Python/JS 코드 실행기 구성 요소를 추가합니다. - 2025-05-05 언어 간 쿼리를 지원합니다. - 2025-03-19 PDF 또는 DOCX 파일 내의 이미지를 이해하기 위해 다중 모드 모델을 사용하는 것을 지원합니다. -- 2025-02-28 인터넷 검색(TAVILY)과 결합되어 모든 LLM에 대한 심층 연구를 지원합니다. - 2024-12-18 DeepDoc의 문서 레이아웃 분석 모델 업그레이드. - 2024-08-22 RAG를 통해 SQL 문에 텍스트를 지원합니다. @@ -106,7 +117,7 @@ ## 🔎 시스템 아키텍처
- +
## 🎬 시작하기 @@ -157,28 +168,34 @@ > 모든 Docker 이미지는 x86 플랫폼을 위해 빌드되었습니다. 우리는 현재 ARM64 플랫폼을 위한 Docker 이미지를 제공하지 않습니다. > ARM64 플랫폼을 사용 중이라면, [시스템과 호환되는 Docker 이미지를 빌드하려면 이 가이드를 사용해 주세요](https://ragflow.io/docs/dev/build_docker_image). - > 아래 명령어는 RAGFlow Docker 이미지의 v0.19.1-slim 버전을 다운로드합니다. 다양한 RAGFlow 버전에 대한 설명은 다음 표를 참조하십시오. v0.19.1-slim과 다른 RAGFlow 버전을 다운로드하려면, docker/.env 파일에서 RAGFLOW_IMAGE 변수를 적절히 업데이트한 후 docker compose를 사용하여 서버를 시작하십시오. 예를 들어, 전체 버전인 v0.19.1을 다운로드하려면 RAGFLOW_IMAGE=infiniflow/ragflow:v0.19.1로 설정합니다. + > 아래 명령어는 RAGFlow Docker 이미지의 v0.22.0 버전을 다운로드합니다. 다양한 RAGFlow 버전에 대한 설명은 다음 표를 참조하십시오. v0.22.0과 다른 RAGFlow 버전을 다운로드하려면, docker/.env 파일에서 RAGFLOW_IMAGE 변수를 적절히 업데이트한 후 docker compose를 사용하여 서버를 시작하십시오. ```bash $ cd ragflow/docker - # Use CPU for embedding and DeepDoc tasks: + + # Optional: use a stable tag (see releases: https://github.com/infiniflow/ragflow/releases), e.g.: git checkout v0.22.0 + + # Use CPU for DeepDoc tasks: $ docker compose -f docker-compose.yml up -d - # To use GPU to accelerate embedding and DeepDoc tasks: - # docker compose -f docker-compose-gpu.yml up -d - ``` + # To use GPU to accelerate DeepDoc tasks: + # sed -i '1i DEVICE=gpu' .env + # docker compose -f docker-compose.yml up -d +``` + +> 참고: `v0.22.0` 이전 버전에서는 embedding 모델이 포함된 이미지와 embedding 모델이 포함되지 않은 slim 이미지를 모두 제공했습니다. 자세한 내용은 다음과 같습니다: - | RAGFlow image tag | Image size (GB) | Has embedding models? | Stable? | - | ----------------- | --------------- | --------------------- | ------------------------ | - | v0.19.1 | ≈9 | :heavy_check_mark: | Stable release | - | v0.19.1-slim | ≈2 | ❌ | Stable release | - | nightly | ≈9 | :heavy_check_mark: | _Unstable_ nightly build | - | nightly-slim | ≈2 | ❌ | _Unstable_ nightly build | +| RAGFlow image tag | Image size (GB) | Has embedding models? | Stable? | +| ----------------- | --------------- | --------------------- | ------------------------ | +| v0.21.1 | ≈9 | ✔️ | Stable release | +| v0.21.1-slim | ≈2 | ❌ | Stable release | + +> `v0.22.0`부터는 slim 에디션만 배포하며 이미지 태그에 **-slim** 접미사를 더 이상 붙이지 않습니다. 1. 서버가 시작된 후 서버 상태를 확인하세요: ```bash - $ docker logs -f ragflow-server + $ docker logs -f docker-ragflow-cpu-1 ``` _다음 출력 결과로 시스템이 성공적으로 시작되었음을 확인합니다:_ @@ -240,20 +257,10 @@ RAGFlow 는 기본적으로 Elasticsearch 를 사용하여 전체 텍스트 및 > [!WARNING] > Linux/arm64 시스템에서 Infinity로 전환하는 것은 공식적으로 지원되지 않습니다. -## 🔧 소스 코드로 Docker 이미지를 컴파일합니다(임베딩 모델 포함하지 않음) +## 🔧 소스 코드로 Docker 이미지를 컴파일합니다 이 Docker 이미지의 크기는 약 1GB이며, 외부 대형 모델과 임베딩 서비스에 의존합니다. -```bash -git clone https://github.com/infiniflow/ragflow.git -cd ragflow/ -docker build --platform linux/amd64 --build-arg LIGHTEN=1 -f Dockerfile -t infiniflow/ragflow:nightly-slim . -``` - -## 🔧 소스 코드로 Docker 이미지를 컴파일합니다(임베딩 모델 포함) - -이 Docker의 크기는 약 9GB이며, 이미 임베딩 모델을 포함하고 있으므로 외부 대형 모델 서비스에만 의존하면 됩니다. - ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ @@ -262,7 +269,7 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly ## 🔨 소스 코드로 서비스를 시작합니다. -1. uv를 설치하거나 이미 설치된 경우 이 단계를 건너뜁니다: +1. `uv` 와 `pre-commit` 을 설치하거나, 이미 설치된 경우 이 단계를 건너뜁니다: ```bash pipx install uv pre-commit @@ -273,7 +280,7 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ - uv sync --python 3.10 --all-extras # install RAGFlow dependent python modules + uv sync --python 3.10 # install RAGFlow dependent python modules uv run download_deps.py pre-commit install ``` @@ -303,6 +310,8 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly sudo apt-get install libjemalloc-dev # centos sudo yum install jemalloc + # mac + sudo brew install jemalloc ``` 6. 백엔드 서비스를 시작합니다: @@ -336,7 +345,7 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly ```bash pkill -f "ragflow_server.py|task_executor.py" ``` - + ## 📚 문서 diff --git a/README_pt_br.md b/README_pt_br.md index 8154751ff31..0769ea5e5ae 100644 --- a/README_pt_br.md +++ b/README_pt_br.md @@ -1,6 +1,6 @@
-ragflow logo +ragflow logo
@@ -22,7 +22,7 @@ Badge Estático - docker pull infiniflow/ragflow:v0.19.1 + docker pull infiniflow/ragflow:v0.22.0 Última Versão @@ -43,7 +43,13 @@ Demo -# +
+ +
+ +
+infiniflow%2Fragflow | Trendshift +
📕 Índice @@ -67,23 +73,27 @@ ## 💡 O que é o RAGFlow? -[RAGFlow](https://ragflow.io/) é um mecanismo RAG (Geração Aumentada por Recuperação) de código aberto baseado em entendimento profundo de documentos. Ele oferece um fluxo de trabalho RAG simplificado para empresas de qualquer porte, combinando LLMs (Modelos de Linguagem de Grande Escala) para fornecer capacidades de perguntas e respostas verídicas, respaldadas por citações bem fundamentadas de diversos dados complexos formatados. +[RAGFlow](https://ragflow.io/) é um mecanismo de RAG (Retrieval-Augmented Generation) open-source líder que fusiona tecnologias RAG de ponta com funcionalidades Agent para criar uma camada contextual superior para LLMs. Oferece um fluxo de trabalho RAG otimizado adaptável a empresas de qualquer escala. Alimentado por um motor de contexto convergente e modelos Agent pré-construídos, o RAGFlow permite que desenvolvedores transformem dados complexos em sistemas de IA de alta fidelidade e pronto para produção com excepcional eficiência e precisão. ## 🎮 Demo Experimente nossa demo em [https://demo.ragflow.io](https://demo.ragflow.io).
- - + +
## 🔥 Últimas Atualizações +- 12-11-2025 Suporta a sincronização de dados do Confluence, AWS S3, Discord e Google Drive. +- 23-10-2025 Suporta MinerU e Docling como métodos de análise de documentos. +- 15-10-2025 Suporte para pipelines de dados orquestrados. +- 08-08-2025 Suporta a mais recente série GPT-5 da OpenAI. +- 01-08-2025 Suporta fluxo de trabalho agente e MCP. - 23-05-2025 Adicione o componente executor de código Python/JS ao Agente. - 05-05-2025 Suporte a consultas entre idiomas. - 19-03-2025 Suporta o uso de um modelo multi-modal para entender imagens dentro de arquivos PDF ou DOCX. -- 28-02-2025 combinado com a pesquisa na Internet (T AVI LY), suporta pesquisas profundas para qualquer LLM. - 18-12-2024 Atualiza o modelo de Análise de Layout de Documentos no DeepDoc. - 22-08-2024 Suporta conversão de texto para comandos SQL via RAG. @@ -126,7 +136,7 @@ Experimente nossa demo em [https://demo.ragflow.io](https://demo.ragflow.io). ## 🔎 Arquitetura do Sistema
- +
## 🎬 Primeiros Passos @@ -144,84 +154,90 @@ Experimente nossa demo em [https://demo.ragflow.io](https://demo.ragflow.io). ### 🚀 Iniciar o servidor -1. Certifique-se de que `vm.max_map_count` >= 262144: - - > Para verificar o valor de `vm.max_map_count`: - > - > ```bash - > $ sysctl vm.max_map_count - > ``` - > - > Se necessário, redefina `vm.max_map_count` para um valor de pelo menos 262144: - > - > ```bash - > # Neste caso, defina para 262144: - > $ sudo sysctl -w vm.max_map_count=262144 - > ``` - > - > Essa mudança será resetada após a reinicialização do sistema. Para garantir que a alteração permaneça permanente, adicione ou atualize o valor de `vm.max_map_count` em **/etc/sysctl.conf**: - > - > ```bash - > vm.max_map_count=262144 - > ``` - -2. Clone o repositório: - - ```bash - $ git clone https://github.com/infiniflow/ragflow.git - ``` - -3. Inicie o servidor usando as imagens Docker pré-compiladas: +1. Certifique-se de que `vm.max_map_count` >= 262144: + + > Para verificar o valor de `vm.max_map_count`: + > + > ```bash + > $ sysctl vm.max_map_count + > ``` + > + > Se necessário, redefina `vm.max_map_count` para um valor de pelo menos 262144: + > + > ```bash + > # Neste caso, defina para 262144: + > $ sudo sysctl -w vm.max_map_count=262144 + > ``` + > + > Essa mudança será resetada após a reinicialização do sistema. Para garantir que a alteração permaneça permanente, adicione ou atualize o valor de `vm.max_map_count` em **/etc/sysctl.conf**: + > + > ```bash + > vm.max_map_count=262144 + > ``` + > +2. Clone o repositório: + + ```bash + $ git clone https://github.com/infiniflow/ragflow.git + ``` +3. Inicie o servidor usando as imagens Docker pré-compiladas: > [!CAUTION] > Todas as imagens Docker são construídas para plataformas x86. Atualmente, não oferecemos imagens Docker para ARM64. > Se você estiver usando uma plataforma ARM64, por favor, utilize [este guia](https://ragflow.io/docs/dev/build_docker_image) para construir uma imagem Docker compatível com o seu sistema. - > O comando abaixo baixa a edição `v0.19.1-slim` da imagem Docker do RAGFlow. Consulte a tabela a seguir para descrições de diferentes edições do RAGFlow. Para baixar uma edição do RAGFlow diferente da `v0.19.1-slim`, atualize a variável `RAGFLOW_IMAGE` conforme necessário no **docker/.env** antes de usar `docker compose` para iniciar o servidor. Por exemplo: defina `RAGFLOW_IMAGE=infiniflow/ragflow:v0.19.1` para a edição completa `v0.19.1`. + > O comando abaixo baixa a edição`v0.22.0` da imagem Docker do RAGFlow. Consulte a tabela a seguir para descrições de diferentes edições do RAGFlow. Para baixar uma edição do RAGFlow diferente da `v0.22.0`, atualize a variável `RAGFLOW_IMAGE` conforme necessário no **docker/.env** antes de usar `docker compose` para iniciar o servidor. + +```bash + $ cd ragflow/docker + + # Opcional: use uma tag estável (veja releases: https://github.com/infiniflow/ragflow/releases), ex.: git checkout v0.22.0 - ```bash - $ cd ragflow/docker - # Use CPU for embedding and DeepDoc tasks: - $ docker compose -f docker-compose.yml up -d + # Use CPU for DeepDoc tasks: + $ docker compose -f docker-compose.yml up -d - # To use GPU to accelerate embedding and DeepDoc tasks: - # docker compose -f docker-compose-gpu.yml up -d - ``` + # To use GPU to accelerate DeepDoc tasks: + # sed -i '1i DEVICE=gpu' .env + # docker compose -f docker-compose.yml up -d +``` - | Tag da imagem RAGFlow | Tamanho da imagem (GB) | Possui modelos de incorporação? | Estável? | - | --------------------- | ---------------------- | ------------------------------- | ------------------------ | - | v0.19.1 | ~9 | :heavy_check_mark: | Lançamento estável | - | v0.19.1-slim | ~2 | ❌ | Lançamento estável | - | nightly | ~9 | :heavy_check_mark: | _Instável_ build noturno | - | nightly-slim | ~2 | ❌ | _Instável_ build noturno | +> Nota: Antes da `v0.22.0`, fornecíamos imagens com modelos de embedding e imagens slim sem modelos de embedding. Detalhes a seguir: -4. Verifique o status do servidor após tê-lo iniciado: +| RAGFlow image tag | Image size (GB) | Has embedding models? | Stable? | +| ----------------- | --------------- | --------------------- | ------------------------ | +| v0.21.1 | ≈9 | ✔️ | Stable release | +| v0.21.1-slim | ≈2 | ❌ | Stable release | - ```bash - $ docker logs -f ragflow-server - ``` +> A partir da `v0.22.0`, distribuímos apenas a edição slim e não adicionamos mais o sufixo **-slim** às tags das imagens. - _O seguinte resultado confirma o lançamento bem-sucedido do sistema:_ +4. Verifique o status do servidor após tê-lo iniciado: - ```bash - ____ ___ ______ ______ __ - / __ \ / | / ____// ____// /____ _ __ - / /_/ // /| | / / __ / /_ / // __ \| | /| / / - / _, _// ___ |/ /_/ // __/ / // /_/ /| |/ |/ / - /_/ |_|/_/ |_|\____//_/ /_/ \____/ |__/|__/ + ```bash + $ docker logs -f docker-ragflow-cpu-1 + ``` - * Rodando em todos os endereços (0.0.0.0) - ``` + _O seguinte resultado confirma o lançamento bem-sucedido do sistema:_ - > Se você pular essa etapa de confirmação e acessar diretamente o RAGFlow, seu navegador pode exibir um erro `network anormal`, pois, nesse momento, seu RAGFlow pode não estar totalmente inicializado. + ```bash + ____ ___ ______ ______ __ + / __ \ / | / ____// ____// /____ _ __ + / /_/ // /| | / / __ / /_ / // __ \| | /| / / + / _, _// ___ |/ /_/ // __/ / // /_/ /| |/ |/ / + /_/ |_|/_/ |_|\____//_/ /_/ \____/ |__/|__/ -5. No seu navegador, insira o endereço IP do seu servidor e faça login no RAGFlow. + * Rodando em todos os endereços (0.0.0.0) + ``` - > Com as configurações padrão, você só precisa digitar `http://IP_DO_SEU_MÁQUINA` (**sem** o número da porta), pois a porta HTTP padrão `80` pode ser omitida ao usar as configurações padrão. + > Se você pular essa etapa de confirmação e acessar diretamente o RAGFlow, seu navegador pode exibir um erro `network anormal`, pois, nesse momento, seu RAGFlow pode não estar totalmente inicializado. + > +5. No seu navegador, insira o endereço IP do seu servidor e faça login no RAGFlow. -6. Em [service_conf.yaml.template](./docker/service_conf.yaml.template), selecione a fábrica LLM desejada em `user_default_llm` e atualize o campo `API_KEY` com a chave de API correspondente. + > Com as configurações padrão, você só precisa digitar `http://IP_DO_SEU_MÁQUINA` (**sem** o número da porta), pois a porta HTTP padrão `80` pode ser omitida ao usar as configurações padrão. + > +6. Em [service_conf.yaml.template](./docker/service_conf.yaml.template), selecione a fábrica LLM desejada em `user_default_llm` e atualize o campo `API_KEY` com a chave de API correspondente. - > Consulte [llm_api_key_setup](https://ragflow.io/docs/dev/llm_api_key_setup) para mais informações. + > Consulte [llm_api_key_setup](https://ragflow.io/docs/dev/llm_api_key_setup) para mais informações. + > _O show está no ar!_ @@ -252,9 +268,9 @@ O RAGFlow usa o Elasticsearch por padrão para armazenar texto completo e vetore ```bash $ docker compose -f docker/docker-compose.yml down -v ``` + Note: `-v` irá deletar os volumes do contêiner, e os dados existentes serão apagados. 2. Defina `DOC_ENGINE` no **docker/.env** para `infinity`. - 3. Inicie os contêineres: ```bash @@ -262,22 +278,12 @@ O RAGFlow usa o Elasticsearch por padrão para armazenar texto completo e vetore ``` > [!ATENÇÃO] -> A mudança para o Infinity em uma máquina Linux/arm64 ainda não é oficialmente suportada. + > A mudança para o Infinity em uma máquina Linux/arm64 ainda não é oficialmente suportada. -## 🔧 Criar uma imagem Docker sem modelos de incorporação +## 🔧 Criar uma imagem Docker Esta imagem tem cerca de 2 GB de tamanho e depende de serviços externos de LLM e incorporação. -```bash -git clone https://github.com/infiniflow/ragflow.git -cd ragflow/ -docker build --platform linux/amd64 --build-arg LIGHTEN=1 -f Dockerfile -t infiniflow/ragflow:nightly-slim . -``` - -## 🔧 Criar uma imagem Docker incluindo modelos de incorporação - -Esta imagem tem cerca de 9 GB de tamanho. Como inclui modelos de incorporação, depende apenas de serviços externos de LLM. - ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ @@ -286,22 +292,20 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly ## 🔨 Lançar o serviço a partir do código-fonte para desenvolvimento -1. Instale o `uv`, ou pule esta etapa se ele já estiver instalado: +1. Instale o `uv` e o `pre-commit`, ou pule esta etapa se eles já estiverem instalados: ```bash pipx install uv pre-commit ``` - 2. Clone o código-fonte e instale as dependências Python: ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ - uv sync --python 3.10 --all-extras # instala os módulos Python dependentes do RAGFlow + uv sync --python 3.10 # instala os módulos Python dependentes do RAGFlow uv run download_deps.py pre-commit install ``` - 3. Inicie os serviços dependentes (MinIO, Elasticsearch, Redis e MySQL) usando Docker Compose: ```bash @@ -313,22 +317,21 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly ``` 127.0.0.1 es01 infinity mysql minio redis sandbox-executor-manager ``` - 4. Se não conseguir acessar o HuggingFace, defina a variável de ambiente `HF_ENDPOINT` para usar um site espelho: ```bash export HF_ENDPOINT=https://hf-mirror.com ``` - 5. Se o seu sistema operacional não tiver jemalloc, instale-o da seguinte maneira: - ```bash - # ubuntu - sudo apt-get install libjemalloc-dev - # centos - sudo yum instalar jemalloc - ``` - + ```bash + # ubuntu + sudo apt-get install libjemalloc-dev + # centos + sudo yum instalar jemalloc + # mac + sudo brew install jemalloc + ``` 6. Lance o serviço de back-end: ```bash @@ -336,14 +339,12 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly export PYTHONPATH=$(pwd) bash docker/launch_backend_service.sh ``` - 7. Instale as dependências do front-end: ```bash cd web npm install ``` - 8. Lance o serviço de front-end: ```bash @@ -353,13 +354,11 @@ docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly _O seguinte resultado confirma o lançamento bem-sucedido do sistema:_ ![](https://github.com/user-attachments/assets/0daf462c-a24d-4496-a66f-92533534e187) - 9. Pare os serviços de front-end e back-end do RAGFlow após a conclusão do desenvolvimento: - ```bash - pkill -f "ragflow_server.py|task_executor.py" - ``` - + ```bash + pkill -f "ragflow_server.py|task_executor.py" + ``` ## 📚 Documentação diff --git a/README_tzh.md b/README_tzh.md index e6010b0b640..a788964538f 100644 --- a/README_tzh.md +++ b/README_tzh.md @@ -1,6 +1,6 @@
-ragflow logo +ragflow logo
@@ -22,7 +22,7 @@ Static Badge - docker pull infiniflow/ragflow:v0.19.1 + docker pull infiniflow/ragflow:v0.22.0 Latest Release @@ -43,7 +43,9 @@ Demo -# +
+ +
infiniflow%2Fragflow | Trendshift @@ -70,23 +72,27 @@ ## 💡 RAGFlow 是什麼? -[RAGFlow](https://ragflow.io/) 是一款基於深度文件理解所建構的開源 RAG(Retrieval-Augmented Generation)引擎。 RAGFlow 可以為各種規模的企業及個人提供一套精簡的 RAG 工作流程,結合大語言模型(LLM)針對用戶各類不同的複雜格式數據提供可靠的問答以及有理有據的引用。 +[RAGFlow](https://ragflow.io/) 是一款領先的開源 RAG(Retrieval-Augmented Generation)引擎,通過融合前沿的 RAG 技術與 Agent 能力,為大型語言模型提供卓越的上下文層。它提供可適配任意規模企業的端到端 RAG 工作流,憑藉融合式上下文引擎與預置的 Agent 模板,助力開發者以極致效率與精度將複雜數據轉化為高可信、生產級的人工智能系統。 ## 🎮 Demo 試用 請登入網址 [https://demo.ragflow.io](https://demo.ragflow.io) 試用 demo。
- - + +
## 🔥 近期更新 +- 2025-11-12 支援從 Confluence、AWS S3、Discord、Google Drive 進行資料同步。 +- 2025-10-23 支援 MinerU 和 Docling 作為文件解析方法。 +- 2025-10-15 支援可編排的資料管道。 +- 2025-08-08 支援 OpenAI 最新的 GPT-5 系列模型。 +- 2025-08-01 支援 agentic workflow 和 MCP - 2025-05-23 為 Agent 新增 Python/JS 程式碼執行器元件。 - 2025-05-05 支援跨語言查詢。 - 2025-03-19 PDF和DOCX中的圖支持用多模態大模型去解析得到描述. -- 2025-02-28 結合網路搜尋(Tavily),對於任意大模型實現類似 Deep Research 的推理功能. - 2024-12-18 升級了 DeepDoc 的文檔佈局分析模型。 - 2024-08-22 支援用 RAG 技術實現從自然語言到 SQL 語句的轉換。 @@ -129,7 +135,7 @@ ## 🔎 系統架構
- +
## 🎬 快速開始 @@ -167,47 +173,52 @@ > ```bash > vm.max_map_count=262144 > ``` - + > 2. 克隆倉庫: ```bash $ git clone https://github.com/infiniflow/ragflow.git ``` - 3. 進入 **docker** 資料夾,利用事先編譯好的 Docker 映像啟動伺服器: > [!CAUTION] > 所有 Docker 映像檔都是為 x86 平台建置的。目前,我們不提供 ARM64 平台的 Docker 映像檔。 > 如果您使用的是 ARM64 平台,請使用 [這份指南](https://ragflow.io/docs/dev/build_docker_image) 來建置適合您系統的 Docker 映像檔。 - > 執行以下指令會自動下載 RAGFlow slim Docker 映像 `v0.19.1-slim`。請參考下表查看不同 Docker 發行版的說明。如需下載不同於 `v0.19.1-slim` 的 Docker 映像,請在執行 `docker compose` 啟動服務之前先更新 **docker/.env** 檔案內的 `RAGFLOW_IMAGE` 變數。例如,你可以透過設定 `RAGFLOW_IMAGE=infiniflow/ragflow:v0.19.1` 來下載 RAGFlow 鏡像的 `v0.19.1` 完整發行版。 +> 執行以下指令會自動下載 RAGFlow Docker 映像 `v0.22.0`。請參考下表查看不同 Docker 發行版的說明。如需下載不同於 `v0.22.0` 的 Docker 映像,請在執行 `docker compose` 啟動服務之前先更新 **docker/.env** 檔案內的 `RAGFLOW_IMAGE` 變數。 - ```bash +```bash $ cd ragflow/docker - # Use CPU for embedding and DeepDoc tasks: + + # 可選:使用穩定版標籤(查看發佈:https://github.com/infiniflow/ragflow/releases),例:git checkout v0.22.0 + + # Use CPU for DeepDoc tasks: $ docker compose -f docker-compose.yml up -d - # To use GPU to accelerate embedding and DeepDoc tasks: - # docker compose -f docker-compose-gpu.yml up -d - ``` + # To use GPU to accelerate DeepDoc tasks: + # sed -i '1i DEVICE=gpu' .env + # docker compose -f docker-compose.yml up -d +``` - | RAGFlow image tag | Image size (GB) | Has embedding models? | Stable? | - | ----------------- | --------------- | --------------------- | ------------------------ | - | v0.19.1 | ≈9 | :heavy_check_mark: | Stable release | - | v0.19.1-slim | ≈2 | ❌ | Stable release | - | nightly | ≈9 | :heavy_check_mark: | _Unstable_ nightly build | - | nightly-slim | ≈2 | ❌ | _Unstable_ nightly build | +> 注意:在 `v0.22.0` 之前的版本,我們會同時提供包含 embedding 模型的映像和不含 embedding 模型的 slim 映像。具體如下: - > [!TIP] - > 如果你遇到 Docker 映像檔拉不下來的問題,可以在 **docker/.env** 檔案內根據變數 `RAGFLOW_IMAGE` 的註解提示選擇華為雲或阿里雲的對應映像。 - > - > - 華為雲鏡像名:`swr.cn-north-4.myhuaweicloud.com/infiniflow/ragflow` - > - 阿里雲鏡像名:`registry.cn-hangzhou.aliyuncs.com/infiniflow/ragflow` +| RAGFlow image tag | Image size (GB) | Has embedding models? | Stable? | +| ----------------- | --------------- | --------------------- | ------------------------ | +| v0.21.1 | ≈9 | ✔️ | Stable release | +| v0.21.1-slim | ≈2 | ❌ | Stable release | + +> 從 `v0.22.0` 開始,我們只發佈 slim 版本,並且不再在映像標籤後附加 **-slim** 後綴。 + +> [!TIP] +> 如果你遇到 Docker 映像檔拉不下來的問題,可以在 **docker/.env** 檔案內根據變數 `RAGFLOW_IMAGE` 的註解提示選擇華為雲或阿里雲的對應映像。 +> +> - 華為雲鏡像名:`swr.cn-north-4.myhuaweicloud.com/infiniflow/ragflow` +> - 阿里雲鏡像名:`registry.cn-hangzhou.aliyuncs.com/infiniflow/ragflow` 4. 伺服器啟動成功後再次確認伺服器狀態: ```bash - $ docker logs -f ragflow-server + $ docker logs -f docker-ragflow-cpu-1 ``` _出現以下介面提示說明伺服器啟動成功:_ @@ -223,12 +234,15 @@ ``` > 如果您跳過這一步驟系統確認步驟就登入 RAGFlow,你的瀏覽器有可能會提示 `network anormal` 或 `網路異常`,因為 RAGFlow 可能並未完全啟動成功。 - + > 5. 在你的瀏覽器中輸入你的伺服器對應的 IP 位址並登入 RAGFlow。 + > 上面這個範例中,您只需輸入 http://IP_OF_YOUR_MACHINE 即可:未改動過設定則無需輸入連接埠(預設的 HTTP 服務連接埠 80)。 + > 6. 在 [service_conf.yaml.template](./docker/service_conf.yaml.template) 檔案的 `user_default_llm` 欄位設定 LLM factory,並在 `API_KEY` 欄填入和你選擇的大模型相對應的 API key。 > 詳見 [llm_api_key_setup](https://ragflow.io/docs/dev/llm_api_key_setup)。 + > _好戲開始,接著奏樂接著舞! _ @@ -246,7 +260,7 @@ > [./docker/README](./docker/README.md) 解釋了 [service_conf.yaml.template](./docker/service_conf.yaml.template) 用到的環境變數設定和服務配置。 -如需更新預設的 HTTP 服務連接埠(80), 可以在[docker-compose.yml](./docker/docker-compose.yml) 檔案中將配置`80:80` 改為`:80` 。 +如需更新預設的 HTTP 服務連接埠(80), 可以在[docker-compose.yml](./docker/docker-compose.yml) 檔案中將配置 `80:80` 改為 `:80` 。 > 所有系統配置都需要透過系統重新啟動生效: > @@ -263,10 +277,9 @@ RAGFlow 預設使用 Elasticsearch 儲存文字和向量資料. 如果要切換 ```bash $ docker compose -f docker/docker-compose.yml down -v ``` - Note: `-v` 將會刪除 docker 容器的 volumes,已有的資料會被清空。 + Note: `-v` 將會刪除 docker 容器的 volumes,已有的資料會被清空。 2. 設定 **docker/.env** 目錄中的 `DOC_ENGINE` 為 `infinity`. - 3. 啟動容器: ```bash @@ -276,45 +289,33 @@ RAGFlow 預設使用 Elasticsearch 儲存文字和向量資料. 如果要切換 > [!WARNING] > Infinity 目前官方並未正式支援在 Linux/arm64 架構下的機器上運行. -## 🔧 原始碼編譯 Docker 映像(不含 embedding 模型) +## 🔧 原始碼編譯 Docker 映像 本 Docker 映像大小約 2 GB 左右並且依賴外部的大模型和 embedding 服務。 ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ -docker build --platform linux/amd64 --build-arg LIGHTEN=1 --build-arg NEED_MIRROR=1 -f Dockerfile -t infiniflow/ragflow:nightly-slim . -``` - -## 🔧 原始碼編譯 Docker 映像(包含 embedding 模型) - -本 Docker 大小約 9 GB 左右。由於已包含 embedding 模型,所以只需依賴外部的大模型服務即可。 - -```bash -git clone https://github.com/infiniflow/ragflow.git -cd ragflow/ -docker build --platform linux/amd64 --build-arg NEED_MIRROR=1 -f Dockerfile -t infiniflow/ragflow:nightly . +docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly . ``` ## 🔨 以原始碼啟動服務 -1. 安裝 uv。如已安裝,可跳過此步驟: +1. 安裝 `uv` 和 `pre-commit`。如已安裝,可跳過此步驟: ```bash pipx install uv pre-commit export UV_INDEX=https://mirrors.aliyun.com/pypi/simple ``` - 2. 下載原始碼並安裝 Python 依賴: ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ - uv sync --python 3.10 --all-extras # install RAGFlow dependent python modules + uv sync --python 3.10 # install RAGFlow dependent python modules uv run download_deps.py pre-commit install ``` - 3. 透過 Docker Compose 啟動依賴的服務(MinIO, Elasticsearch, Redis, and MySQL): ```bash @@ -326,13 +327,11 @@ docker build --platform linux/amd64 --build-arg NEED_MIRROR=1 -f Dockerfile -t i ``` 127.0.0.1 es01 infinity mysql minio redis sandbox-executor-manager ``` - 4. 如果無法存取 HuggingFace,可以把環境變數 `HF_ENDPOINT` 設為對應的鏡像網站: ```bash export HF_ENDPOINT=https://hf-mirror.com ``` - 5. 如果你的操作系统没有 jemalloc,请按照如下方式安装: ```bash @@ -340,8 +339,9 @@ docker build --platform linux/amd64 --build-arg NEED_MIRROR=1 -f Dockerfile -t i sudo apt-get install libjemalloc-dev # centos sudo yum install jemalloc + # mac + sudo brew install jemalloc ``` - 6. 啟動後端服務: ```bash @@ -349,14 +349,12 @@ docker build --platform linux/amd64 --build-arg NEED_MIRROR=1 -f Dockerfile -t i export PYTHONPATH=$(pwd) bash docker/launch_backend_service.sh ``` - 7. 安裝前端依賴: ```bash cd web npm install ``` - 8. 啟動前端服務: ```bash @@ -366,15 +364,16 @@ docker build --platform linux/amd64 --build-arg NEED_MIRROR=1 -f Dockerfile -t i 以下界面說明系統已成功啟動:_ ![](https://github.com/user-attachments/assets/0daf462c-a24d-4496-a66f-92533534e187) + ``` + ``` 9. 開發完成後停止 RAGFlow 前端和後端服務: ```bash pkill -f "ragflow_server.py|task_executor.py" ``` - ## 📚 技術文檔 - [Quickstart](https://ragflow.io/docs/dev/) diff --git a/README_zh.md b/README_zh.md index 1669c68446c..c70073a3e0f 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1,6 +1,6 @@ @@ -22,7 +22,7 @@ Static Badge - docker pull infiniflow/ragflow:v0.19.1 + docker pull infiniflow/ragflow:v0.22.0 Latest Release @@ -43,7 +43,9 @@ Demo -# +
+ +
infiniflow%2Fragflow | Trendshift @@ -70,23 +72,27 @@ ## 💡 RAGFlow 是什么? -[RAGFlow](https://ragflow.io/) 是一款基于深度文档理解构建的开源 RAG(Retrieval-Augmented Generation)引擎。RAGFlow 可以为各种规模的企业及个人提供一套精简的 RAG 工作流程,结合大语言模型(LLM)针对用户各类不同的复杂格式数据提供可靠的问答以及有理有据的引用。 +[RAGFlow](https://ragflow.io/) 是一款领先的开源检索增强生成(RAG)引擎,通过融合前沿的 RAG 技术与 Agent 能力,为大型语言模型提供卓越的上下文层。它提供可适配任意规模企业的端到端 RAG 工作流,凭借融合式上下文引擎与预置的 Agent 模板,助力开发者以极致效率与精度将复杂数据转化为高可信、生产级的人工智能系统。 ## 🎮 Demo 试用 请登录网址 [https://demo.ragflow.io](https://demo.ragflow.io) 试用 demo。
- - + +
## 🔥 近期更新 +- 2025-11-12 支持从 Confluence、AWS S3、Discord、Google Drive 进行数据同步。 +- 2025-10-23 支持 MinerU 和 Docling 作为文档解析方法。 +- 2025-10-15 支持可编排的数据管道。 +- 2025-08-08 支持 OpenAI 最新的 GPT-5 系列模型。 +- 2025-08-01 支持 agentic workflow 和 MCP。 - 2025-05-23 Agent 新增 Python/JS 代码执行器组件。 - 2025-05-05 支持跨语言查询。 - 2025-03-19 PDF 和 DOCX 中的图支持用多模态大模型去解析得到描述. -- 2025-02-28 结合互联网搜索(Tavily),对于任意大模型实现类似 Deep Research 的推理功能. - 2024-12-18 升级了 DeepDoc 的文档布局分析模型。 - 2024-08-22 支持用 RAG 技术实现从自然语言到 SQL 语句的转换。 @@ -129,7 +135,7 @@ ## 🔎 系统架构
- +
## 🎬 快速开始 @@ -180,23 +186,29 @@ > 请注意,目前官方提供的所有 Docker 镜像均基于 x86 架构构建,并不提供基于 ARM64 的 Docker 镜像。 > 如果你的操作系统是 ARM64 架构,请参考[这篇文档](https://ragflow.io/docs/dev/build_docker_image)自行构建 Docker 镜像。 - > 运行以下命令会自动下载 RAGFlow slim Docker 镜像 `v0.19.1-slim`。请参考下表查看不同 Docker 发行版的描述。如需下载不同于 `v0.19.1-slim` 的 Docker 镜像,请在运行 `docker compose` 启动服务之前先更新 **docker/.env** 文件内的 `RAGFLOW_IMAGE` 变量。比如,你可以通过设置 `RAGFLOW_IMAGE=infiniflow/ragflow:v0.19.1` 来下载 RAGFlow 镜像的 `v0.19.1` 完整发行版。 + > 运行以下命令会自动下载 RAGFlow Docker 镜像 `v0.22.0`。请参考下表查看不同 Docker 发行版的描述。如需下载不同于 `v0.22.0` 的 Docker 镜像,请在运行 `docker compose` 启动服务之前先更新 **docker/.env** 文件内的 `RAGFLOW_IMAGE` 变量。 ```bash $ cd ragflow/docker - # Use CPU for embedding and DeepDoc tasks: + + # 可选:使用稳定版本标签(查看发布:https://github.com/infiniflow/ragflow/releases),例如:git checkout v0.22.0 + + # Use CPU for DeepDoc tasks: $ docker compose -f docker-compose.yml up -d - # To use GPU to accelerate embedding and DeepDoc tasks: - # docker compose -f docker-compose-gpu.yml up -d + # To use GPU to accelerate DeepDoc tasks: + # sed -i '1i DEVICE=gpu' .env + # docker compose -f docker-compose.yml up -d ``` + + > 注意:在 `v0.22.0` 之前的版本,我们会同时提供包含 embedding 模型的镜像和不含 embedding 模型的 slim 镜像。具体如下: | RAGFlow image tag | Image size (GB) | Has embedding models? | Stable? | | ----------------- | --------------- | --------------------- | ------------------------ | - | v0.19.1 | ≈9 | :heavy_check_mark: | Stable release | - | v0.19.1-slim | ≈2 | ❌ | Stable release | - | nightly | ≈9 | :heavy_check_mark: | _Unstable_ nightly build | - | nightly-slim | ≈2 | ❌ | _Unstable_ nightly build | + | v0.21.1 | ≈9 | ✔️ | Stable release | + | v0.21.1-slim | ≈2 | ❌ | Stable release | + + > 从 `v0.22.0` 开始,我们只发布 slim 版本,并且不再在镜像标签后附加 **-slim** 后缀。 > [!TIP] > 如果你遇到 Docker 镜像拉不下来的问题,可以在 **docker/.env** 文件内根据变量 `RAGFLOW_IMAGE` 的注释提示选择华为云或者阿里云的相应镜像。 @@ -207,7 +219,7 @@ 4. 服务器启动成功后再次确认服务器状态: ```bash - $ docker logs -f ragflow-server + $ docker logs -f docker-ragflow-cpu-1 ``` _出现以下界面提示说明服务器启动成功:_ @@ -276,29 +288,19 @@ RAGFlow 默认使用 Elasticsearch 存储文本和向量数据. 如果要切换 > [!WARNING] > Infinity 目前官方并未正式支持在 Linux/arm64 架构下的机器上运行. -## 🔧 源码编译 Docker 镜像(不含 embedding 模型) +## 🔧 源码编译 Docker 镜像 本 Docker 镜像大小约 2 GB 左右并且依赖外部的大模型和 embedding 服务。 ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ -docker build --platform linux/amd64 --build-arg LIGHTEN=1 --build-arg NEED_MIRROR=1 -f Dockerfile -t infiniflow/ragflow:nightly-slim . -``` - -## 🔧 源码编译 Docker 镜像(包含 embedding 模型) - -本 Docker 大小约 9 GB 左右。由于已包含 embedding 模型,所以只需依赖外部的大模型服务即可。 - -```bash -git clone https://github.com/infiniflow/ragflow.git -cd ragflow/ -docker build --platform linux/amd64 --build-arg NEED_MIRROR=1 -f Dockerfile -t infiniflow/ragflow:nightly . +docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly . ``` ## 🔨 以源代码启动服务 -1. 安装 uv。如已经安装,可跳过本步骤: +1. 安装 `uv` 和 `pre-commit`。如已经安装,可跳过本步骤: ```bash pipx install uv pre-commit @@ -310,7 +312,7 @@ docker build --platform linux/amd64 --build-arg NEED_MIRROR=1 -f Dockerfile -t i ```bash git clone https://github.com/infiniflow/ragflow.git cd ragflow/ - uv sync --python 3.10 --all-extras # install RAGFlow dependent python modules + uv sync --python 3.10 # install RAGFlow dependent python modules uv run download_deps.py pre-commit install ``` @@ -339,6 +341,8 @@ docker build --platform linux/amd64 --build-arg NEED_MIRROR=1 -f Dockerfile -t i sudo apt-get install libjemalloc-dev # centos sudo yum install jemalloc + # mac + sudo brew install jemalloc ``` 6. 启动后端服务: diff --git a/admin/build_cli_release.sh b/admin/build_cli_release.sh new file mode 100755 index 00000000000..c9fd6d9d909 --- /dev/null +++ b/admin/build_cli_release.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -e + +echo "🚀 Start building..." +echo "================================" + +PROJECT_NAME="ragflow-cli" + +RELEASE_DIR="release" +BUILD_DIR="dist" +SOURCE_DIR="src" +PACKAGE_DIR="ragflow_cli" + +echo "🧹 Clean old build folder..." +rm -rf release/ + +echo "📁 Prepare source code..." +mkdir release/$PROJECT_NAME/$SOURCE_DIR -p +cp pyproject.toml release/$PROJECT_NAME/pyproject.toml +cp README.md release/$PROJECT_NAME/README.md + +mkdir release/$PROJECT_NAME/$SOURCE_DIR/$PACKAGE_DIR -p +cp admin_client.py release/$PROJECT_NAME/$SOURCE_DIR/$PACKAGE_DIR/admin_client.py + +if [ -d "release/$PROJECT_NAME/$SOURCE_DIR" ]; then + echo "✅ source dir: release/$PROJECT_NAME/$SOURCE_DIR" +else + echo "❌ source dir not exist: release/$PROJECT_NAME/$SOURCE_DIR" + exit 1 +fi + +echo "🔨 Make build file..." +cd release/$PROJECT_NAME +export PYTHONPATH=$(pwd) +python -m build + +echo "✅ check build result..." +if [ -d "$BUILD_DIR" ]; then + echo "📦 Package generated:" + ls -la $BUILD_DIR/ +else + echo "❌ Build Failed: $BUILD_DIR not exist." + exit 1 +fi + +echo "🎉 Build finished successfully!" \ No newline at end of file diff --git a/admin/client/README.md b/admin/client/README.md new file mode 100644 index 00000000000..1964a41d40e --- /dev/null +++ b/admin/client/README.md @@ -0,0 +1,136 @@ +# RAGFlow Admin Service & CLI + +### Introduction + +Admin Service is a dedicated management component designed to monitor, maintain, and administrate the RAGFlow system. It provides comprehensive tools for ensuring system stability, performing operational tasks, and managing users and permissions efficiently. + +The service offers real-time monitoring of critical components, including the RAGFlow server, Task Executor processes, and dependent services such as MySQL, Elasticsearch, Redis, and MinIO. It automatically checks their health status, resource usage, and uptime, and performs restarts in case of failures to minimize downtime. + +For user and system management, it supports listing, creating, modifying, and deleting users and their associated resources like knowledge bases and Agents. + +Built with scalability and reliability in mind, the Admin Service ensures smooth system operation and simplifies maintenance workflows. + +It consists of a server-side Service and a command-line client (CLI), both implemented in Python. User commands are parsed using the Lark parsing toolkit. + +- **Admin Service**: A backend service that interfaces with the RAGFlow system to execute administrative operations and monitor its status. +- **Admin CLI**: A command-line interface that allows users to connect to the Admin Service and issue commands for system management. + + + +### Starting the Admin Service + +#### Launching from source code + +1. Before start Admin Service, please make sure RAGFlow system is already started. + +2. Launch from source code: + + ```bash + python admin/server/admin_server.py + ``` + The service will start and listen for incoming connections from the CLI on the configured port. + +#### Using docker image + +1. Before startup, please configure the `docker_compose.yml` file to enable admin server: + + ```bash + command: + - --enable-adminserver + ``` + +2. Start the containers, the service will start and listen for incoming connections from the CLI on the configured port. + + + +### Using the Admin CLI + +1. Ensure the Admin Service is running. +2. Install ragflow-cli. + ```bash + pip install ragflow-cli==0.22.0 + ``` +3. Launch the CLI client: + ```bash + ragflow-cli -h 127.0.0.1 -p 9381 + ``` + You will be prompted to enter the superuser's password to log in. + The default password is admin. + + **Parameters:** + + - -h: RAGFlow admin server host address + + - -p: RAGFlow admin server port + + + +## Supported Commands + +Commands are case-insensitive and must be terminated with a semicolon (`;`). + +### Service Management Commands + +- `LIST SERVICES;` + - Lists all available services within the RAGFlow system. +- `SHOW SERVICE ;` + - Shows detailed status information for the service identified by ``. + + +### User Management Commands + +- `LIST USERS;` + - Lists all users known to the system. +- `SHOW USER '';` + - Shows details and permissions for the specified user. The username must be enclosed in single or double quotes. + +- `CREATE USER ;` + - Create user by username and password. The username and password must be enclosed in single or double quotes. + +- `DROP USER '';` + - Removes the specified user from the system. Use with caution. +- `ALTER USER PASSWORD '' '';` + - Changes the password for the specified user. +- `ALTER USER ACTIVE ;` + - Changes the user to active or inactive. + + +### Data and Agent Commands + +- `LIST DATASETS OF '';` + - Lists the datasets associated with the specified user. +- `LIST AGENTS OF '';` + - Lists the agents associated with the specified user. + +### Meta-Commands + +Meta-commands are prefixed with a backslash (`\`). + +- `\?` or `\help` + - Shows help information for the available commands. +- `\q` or `\quit` + - Exits the CLI application. + +## Examples + +```commandline +admin> list users; ++-------------------------------+------------------------+-----------+-------------+ +| create_date | email | is_active | nickname | ++-------------------------------+------------------------+-----------+-------------+ +| Fri, 22 Nov 2024 16:03:41 GMT | jeffery@infiniflow.org | 1 | Jeffery | +| Fri, 22 Nov 2024 16:10:55 GMT | aya@infiniflow.org | 1 | Waterdancer | ++-------------------------------+------------------------+-----------+-------------+ + +admin> list services; ++-------------------------------------------------------------------------------------------+-----------+----+---------------+-------+----------------+ +| extra | host | id | name | port | service_type | ++-------------------------------------------------------------------------------------------+-----------+----+---------------+-------+----------------+ +| {} | 0.0.0.0 | 0 | ragflow_0 | 9380 | ragflow_server | +| {'meta_type': 'mysql', 'password': 'infini_rag_flow', 'username': 'root'} | localhost | 1 | mysql | 5455 | meta_data | +| {'password': 'infini_rag_flow', 'store_type': 'minio', 'user': 'rag_flow'} | localhost | 2 | minio | 9000 | file_store | +| {'password': 'infini_rag_flow', 'retrieval_type': 'elasticsearch', 'username': 'elastic'} | localhost | 3 | elasticsearch | 1200 | retrieval | +| {'db_name': 'default_db', 'retrieval_type': 'infinity'} | localhost | 4 | infinity | 23817 | retrieval | +| {'database': 1, 'mq_type': 'redis', 'password': 'infini_rag_flow'} | localhost | 5 | redis | 6379 | message_queue | ++-------------------------------------------------------------------------------------------+-----------+----+---------------+-------+----------------+ +``` diff --git a/admin/client/admin_client.py b/admin/client/admin_client.py new file mode 100644 index 00000000000..b52e6749454 --- /dev/null +++ b/admin/client/admin_client.py @@ -0,0 +1,975 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import argparse +import base64 +from cmd import Cmd + +from Cryptodome.PublicKey import RSA +from Cryptodome.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5 +from typing import Dict, List, Any +from lark import Lark, Transformer, Tree +import requests +import getpass + +GRAMMAR = r""" +start: command + +command: sql_command | meta_command + +sql_command: list_services + | show_service + | startup_service + | shutdown_service + | restart_service + | list_users + | show_user + | drop_user + | alter_user + | create_user + | activate_user + | list_datasets + | list_agents + | create_role + | drop_role + | alter_role + | list_roles + | show_role + | grant_permission + | revoke_permission + | alter_user_role + | show_user_permission + | show_version + +// meta command definition +meta_command: "\\" meta_command_name [meta_args] + +meta_command_name: /[a-zA-Z?]+/ +meta_args: (meta_arg)+ + +meta_arg: /[^\\s"']+/ | quoted_string + +// command definition + +LIST: "LIST"i +SERVICES: "SERVICES"i +SHOW: "SHOW"i +CREATE: "CREATE"i +SERVICE: "SERVICE"i +SHUTDOWN: "SHUTDOWN"i +STARTUP: "STARTUP"i +RESTART: "RESTART"i +USERS: "USERS"i +DROP: "DROP"i +USER: "USER"i +ALTER: "ALTER"i +ACTIVE: "ACTIVE"i +PASSWORD: "PASSWORD"i +DATASETS: "DATASETS"i +OF: "OF"i +AGENTS: "AGENTS"i +ROLE: "ROLE"i +ROLES: "ROLES"i +DESCRIPTION: "DESCRIPTION"i +GRANT: "GRANT"i +REVOKE: "REVOKE"i +ALL: "ALL"i +PERMISSION: "PERMISSION"i +TO: "TO"i +FROM: "FROM"i +FOR: "FOR"i +RESOURCES: "RESOURCES"i +ON: "ON"i +SET: "SET"i +VERSION: "VERSION"i + +list_services: LIST SERVICES ";" +show_service: SHOW SERVICE NUMBER ";" +startup_service: STARTUP SERVICE NUMBER ";" +shutdown_service: SHUTDOWN SERVICE NUMBER ";" +restart_service: RESTART SERVICE NUMBER ";" + +list_users: LIST USERS ";" +drop_user: DROP USER quoted_string ";" +alter_user: ALTER USER PASSWORD quoted_string quoted_string ";" +show_user: SHOW USER quoted_string ";" +create_user: CREATE USER quoted_string quoted_string ";" +activate_user: ALTER USER ACTIVE quoted_string status ";" + +list_datasets: LIST DATASETS OF quoted_string ";" +list_agents: LIST AGENTS OF quoted_string ";" + +create_role: CREATE ROLE identifier [DESCRIPTION quoted_string] ";" +drop_role: DROP ROLE identifier ";" +alter_role: ALTER ROLE identifier SET DESCRIPTION quoted_string ";" +list_roles: LIST ROLES ";" +show_role: SHOW ROLE identifier ";" + +grant_permission: GRANT action_list ON identifier TO ROLE identifier ";" +revoke_permission: REVOKE action_list ON identifier FROM ROLE identifier ";" +alter_user_role: ALTER USER quoted_string SET ROLE identifier ";" +show_user_permission: SHOW USER PERMISSION quoted_string ";" + +show_version: SHOW VERSION ";" + +action_list: identifier ("," identifier)* + +identifier: WORD +quoted_string: QUOTED_STRING +status: WORD + +QUOTED_STRING: /'[^']+'/ | /"[^"]+"/ +WORD: /[a-zA-Z0-9_\-\.]+/ +NUMBER: /[0-9]+/ + +%import common.WS +%ignore WS +""" + + +class AdminTransformer(Transformer): + + def start(self, items): + return items[0] + + def command(self, items): + return items[0] + + def list_services(self, items): + result = {'type': 'list_services'} + return result + + def show_service(self, items): + service_id = int(items[2]) + return {"type": "show_service", "number": service_id} + + def startup_service(self, items): + service_id = int(items[2]) + return {"type": "startup_service", "number": service_id} + + def shutdown_service(self, items): + service_id = int(items[2]) + return {"type": "shutdown_service", "number": service_id} + + def restart_service(self, items): + service_id = int(items[2]) + return {"type": "restart_service", "number": service_id} + + def list_users(self, items): + return {"type": "list_users"} + + def show_user(self, items): + user_name = items[2] + return {"type": "show_user", "user_name": user_name} + + def drop_user(self, items): + user_name = items[2] + return {"type": "drop_user", "user_name": user_name} + + def alter_user(self, items): + user_name = items[3] + new_password = items[4] + return {"type": "alter_user", "user_name": user_name, "password": new_password} + + def create_user(self, items): + user_name = items[2] + password = items[3] + return {"type": "create_user", "user_name": user_name, "password": password, "role": "user"} + + def activate_user(self, items): + user_name = items[3] + activate_status = items[4] + return {"type": "activate_user", "activate_status": activate_status, "user_name": user_name} + + def list_datasets(self, items): + user_name = items[3] + return {"type": "list_datasets", "user_name": user_name} + + def list_agents(self, items): + user_name = items[3] + return {"type": "list_agents", "user_name": user_name} + + def create_role(self, items): + role_name = items[2] + if len(items) > 4: + description = items[4] + return {"type": "create_role", "role_name": role_name, "description": description} + else: + return {"type": "create_role", "role_name": role_name} + + def drop_role(self, items): + role_name = items[2] + return {"type": "drop_role", "role_name": role_name} + + def alter_role(self, items): + role_name = items[2] + description = items[5] + return {"type": "alter_role", "role_name": role_name, "description": description} + + def list_roles(self, items): + return {"type": "list_roles"} + + def show_role(self, items): + role_name = items[2] + return {"type": "show_role", "role_name": role_name} + + def grant_permission(self, items): + action_list = items[1] + resource = items[3] + role_name = items[6] + return {"type": "grant_permission", "role_name": role_name, "resource": resource, "actions": action_list} + + def revoke_permission(self, items): + action_list = items[1] + resource = items[3] + role_name = items[6] + return { + "type": "revoke_permission", + "role_name": role_name, + "resource": resource, "actions": action_list + } + + def alter_user_role(self, items): + user_name = items[2] + role_name = items[5] + return {"type": "alter_user_role", "user_name": user_name, "role_name": role_name} + + def show_user_permission(self, items): + user_name = items[3] + return {"type": "show_user_permission", "user_name": user_name} + + def show_version(self, items): + return {"type": "show_version"} + + def action_list(self, items): + return items + + def meta_command(self, items): + command_name = str(items[0]).lower() + args = items[1:] if len(items) > 1 else [] + + # handle quoted parameter + parsed_args = [] + for arg in args: + if hasattr(arg, 'value'): + parsed_args.append(arg.value) + else: + parsed_args.append(str(arg)) + + return {'type': 'meta', 'command': command_name, 'args': parsed_args} + + def meta_command_name(self, items): + return items[0] + + def meta_args(self, items): + return items + + +def encrypt(input_string): + pub = '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArq9XTUSeYr2+N1h3Afl/z8Dse/2yD0ZGrKwx+EEEcdsBLca9Ynmx3nIB5obmLlSfmskLpBo0UACBmB5rEjBp2Q2f3AG3Hjd4B+gNCG6BDaawuDlgANIhGnaTLrIqWrrcm4EMzJOnAOI1fgzJRsOOUEfaS318Eq9OVO3apEyCCt0lOQK6PuksduOjVxtltDav+guVAA068NrPYmRNabVKRNLJpL8w4D44sfth5RvZ3q9t+6RTArpEtc5sh5ChzvqPOzKGMXW83C95TxmXqpbK6olN4RevSfVjEAgCydH6HN6OhtOQEcnrU97r9H0iZOWwbw3pVrZiUkuRD1R56Wzs2wIDAQAB\n-----END PUBLIC KEY-----' + pub_key = RSA.importKey(pub) + cipher = Cipher_pkcs1_v1_5.new(pub_key) + cipher_text = cipher.encrypt(base64.b64encode(input_string.encode('utf-8'))) + return base64.b64encode(cipher_text).decode("utf-8") + + +def encode_to_base64(input_string): + base64_encoded = base64.b64encode(input_string.encode('utf-8')) + return base64_encoded.decode('utf-8') + + +class AdminCLI(Cmd): + def __init__(self): + super().__init__() + self.parser = Lark(GRAMMAR, start='start', parser='lalr', transformer=AdminTransformer()) + self.command_history = [] + self.is_interactive = False + self.admin_account = "admin@ragflow.io" + self.admin_password: str = "admin" + self.session = requests.Session() + self.access_token: str = "" + self.host: str = "" + self.port: int = 0 + + intro = r"""Type "\h" for help.""" + prompt = "admin> " + + def onecmd(self, command: str) -> bool: + try: + result = self.parse_command(command) + + if isinstance(result, dict): + if 'type' in result and result.get('type') == 'empty': + return False + + self.execute_command(result) + + if isinstance(result, Tree): + return False + + if result.get('type') == 'meta' and result.get('command') in ['q', 'quit', 'exit']: + return True + + except KeyboardInterrupt: + print("\nUse '\\q' to quit") + except EOFError: + print("\nGoodbye!") + return True + return False + + def emptyline(self) -> bool: + return False + + def default(self, line: str) -> bool: + return self.onecmd(line) + + def parse_command(self, command_str: str) -> dict[str, str]: + if not command_str.strip(): + return {'type': 'empty'} + + self.command_history.append(command_str) + + try: + result = self.parser.parse(command_str) + return result + except Exception as e: + return {'type': 'error', 'message': f'Parse error: {str(e)}'} + + def verify_admin(self, arguments: dict, single_command: bool): + self.host = arguments['host'] + self.port = arguments['port'] + print(f"Attempt to access ip: {self.host}, port: {self.port}") + url = f"http://{self.host}:{self.port}/api/v1/admin/login" + + attempt_count = 3 + if single_command: + attempt_count = 1 + + try_count = 0 + while True: + try_count += 1 + if try_count > attempt_count: + return False + + if single_command: + admin_passwd = arguments['password'] + else: + admin_passwd = getpass.getpass(f"password for {self.admin_account}: ").strip() + try: + self.admin_password = encrypt(admin_passwd) + response = self.session.post(url, json={'email': self.admin_account, 'password': self.admin_password}) + if response.status_code == 200: + res_json = response.json() + error_code = res_json.get('code', -1) + if error_code == 0: + self.session.headers.update({ + 'Content-Type': 'application/json', + 'Authorization': response.headers['Authorization'], + 'User-Agent': 'RAGFlow-CLI/0.22.0' + }) + print("Authentication successful.") + return True + else: + error_message = res_json.get('message', 'Unknown error') + print(f"Authentication failed: {error_message}, try again") + continue + else: + print(f"Bad response,status: {response.status_code}, password is wrong") + except Exception as e: + print(str(e)) + print(f"Can't access {self.host}, port: {self.port}") + + def _format_service_detail_table(self, data): + if not any([isinstance(v, list) for v in data.values()]): + # normal table + return data + # handle task_executor heartbeats map, for example {'name': [{'done': 2, 'now': timestamp1}, {'done': 3, 'now': timestamp2}] + task_executor_list = [] + for k, v in data.items(): + # display latest status + heartbeats = sorted(v, key=lambda x: x["now"], reverse=True) + task_executor_list.append({ + "task_executor_name": k, + **heartbeats[0], + }) + return task_executor_list + + def _print_table_simple(self, data): + if not data: + print("No data to print") + return + if isinstance(data, dict): + # handle single row data + data = [data] + + columns = list(data[0].keys()) + col_widths = {} + + def get_string_width(text): + half_width_chars = ( + " !\"#$%&'()*+,-./0123456789:;<=>?@" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" + "abcdefghijklmnopqrstuvwxyz{|}~" + "\t\n\r" + ) + width = 0 + for char in text: + if char in half_width_chars: + width += 1 + else: + width += 2 + return width + + for col in columns: + max_width = get_string_width(str(col)) + for item in data: + value_len = get_string_width(str(item.get(col, ''))) + if value_len > max_width: + max_width = value_len + col_widths[col] = max(2, max_width) + + # Generate delimiter + separator = "+" + "+".join(["-" * (col_widths[col] + 2) for col in columns]) + "+" + + # Print header + print(separator) + header = "|" + "|".join([f" {col:<{col_widths[col]}} " for col in columns]) + "|" + print(header) + print(separator) + + # Print data + for item in data: + row = "|" + for col in columns: + value = str(item.get(col, '')) + if get_string_width(value) > col_widths[col]: + value = value[:col_widths[col] - 3] + "..." + row += f" {value:<{col_widths[col] - (get_string_width(value) - len(value))}} |" + print(row) + + print(separator) + + def run_interactive(self): + + self.is_interactive = True + print("RAGFlow Admin command line interface - Type '\\?' for help, '\\q' to quit") + + while True: + try: + command = input("admin> ").strip() + if not command: + continue + + print(f"command: {command}") + result = self.parse_command(command) + self.execute_command(result) + + if isinstance(result, Tree): + continue + + if result.get('type') == 'meta' and result.get('command') in ['q', 'quit', 'exit']: + break + + except KeyboardInterrupt: + print("\nUse '\\q' to quit") + except EOFError: + print("\nGoodbye!") + break + + def run_single_command(self, command: str): + result = self.parse_command(command) + self.execute_command(result) + + def parse_connection_args(self, args: List[str]) -> Dict[str, Any]: + parser = argparse.ArgumentParser(description='Admin CLI Client', add_help=False) + parser.add_argument('-h', '--host', default='localhost', help='Admin service host') + parser.add_argument('-p', '--port', type=int, default=9381, help='Admin service port') + parser.add_argument('-w', '--password', default='admin', type=str, help='Superuser password') + parser.add_argument('command', nargs='?', help='Single command') + try: + parsed_args, remaining_args = parser.parse_known_args(args) + if remaining_args: + command = remaining_args[0] + return { + 'host': parsed_args.host, + 'port': parsed_args.port, + 'password': parsed_args.password, + 'command': command + } + else: + return { + 'host': parsed_args.host, + 'port': parsed_args.port, + } + except SystemExit: + return {'error': 'Invalid connection arguments'} + + def execute_command(self, parsed_command: Dict[str, Any]): + + command_dict: dict + if isinstance(parsed_command, Tree): + command_dict = parsed_command.children[0] + else: + if parsed_command['type'] == 'error': + print(f"Error: {parsed_command['message']}") + return + else: + command_dict = parsed_command + + # print(f"Parsed command: {command_dict}") + + command_type = command_dict['type'] + + match command_type: + case 'list_services': + self._handle_list_services(command_dict) + case 'show_service': + self._handle_show_service(command_dict) + case 'restart_service': + self._handle_restart_service(command_dict) + case 'shutdown_service': + self._handle_shutdown_service(command_dict) + case 'startup_service': + self._handle_startup_service(command_dict) + case 'list_users': + self._handle_list_users(command_dict) + case 'show_user': + self._handle_show_user(command_dict) + case 'drop_user': + self._handle_drop_user(command_dict) + case 'alter_user': + self._handle_alter_user(command_dict) + case 'create_user': + self._handle_create_user(command_dict) + case 'activate_user': + self._handle_activate_user(command_dict) + case 'list_datasets': + self._handle_list_datasets(command_dict) + case 'list_agents': + self._handle_list_agents(command_dict) + case 'create_role': + self._create_role(command_dict) + case 'drop_role': + self._drop_role(command_dict) + case 'alter_role': + self._alter_role(command_dict) + case 'list_roles': + self._list_roles(command_dict) + case 'show_role': + self._show_role(command_dict) + case 'grant_permission': + self._grant_permission(command_dict) + case 'revoke_permission': + self._revoke_permission(command_dict) + case 'alter_user_role': + self._alter_user_role(command_dict) + case 'show_user_permission': + self._show_user_permission(command_dict) + case 'show_version': + self._show_version(command_dict) + case 'meta': + self._handle_meta_command(command_dict) + case _: + print(f"Command '{command_type}' would be executed with API") + + def _handle_list_services(self, command): + print("Listing all services") + + url = f'http://{self.host}:{self.port}/api/v1/admin/services' + response = self.session.get(url) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print(f"Fail to get all services, code: {res_json['code']}, message: {res_json['message']}") + + def _handle_show_service(self, command): + service_id: int = command['number'] + print(f"Showing service: {service_id}") + + url = f'http://{self.host}:{self.port}/api/v1/admin/services/{service_id}' + response = self.session.get(url) + res_json = response.json() + if response.status_code == 200: + res_data = res_json['data'] + if 'status' in res_data and res_data['status'] == 'alive': + print(f"Service {res_data['service_name']} is alive, ") + if isinstance(res_data['message'], str): + print(res_data['message']) + else: + data = self._format_service_detail_table(res_data['message']) + self._print_table_simple(data) + else: + print(f"Service {res_data['service_name']} is down, {res_data['message']}") + else: + print(f"Fail to show service, code: {res_json['code']}, message: {res_json['message']}") + + def _handle_restart_service(self, command): + service_id: int = command['number'] + print(f"Restart service {service_id}") + + def _handle_shutdown_service(self, command): + service_id: int = command['number'] + print(f"Shutdown service {service_id}") + + def _handle_startup_service(self, command): + service_id: int = command['number'] + print(f"Startup service {service_id}") + + def _handle_list_users(self, command): + print("Listing all users") + + url = f'http://{self.host}:{self.port}/api/v1/admin/users' + response = self.session.get(url) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print(f"Fail to get all users, code: {res_json['code']}, message: {res_json['message']}") + + def _handle_show_user(self, command): + username_tree: Tree = command['user_name'] + user_name: str = username_tree.children[0].strip("'\"") + print(f"Showing user: {user_name}") + url = f'http://{self.host}:{self.port}/api/v1/admin/users/{user_name}' + response = self.session.get(url) + res_json = response.json() + if response.status_code == 200: + table_data = res_json['data'] + table_data.pop('avatar') + self._print_table_simple(table_data) + else: + print(f"Fail to get user {user_name}, code: {res_json['code']}, message: {res_json['message']}") + + def _handle_drop_user(self, command): + username_tree: Tree = command['user_name'] + user_name: str = username_tree.children[0].strip("'\"") + print(f"Drop user: {user_name}") + url = f'http://{self.host}:{self.port}/api/v1/admin/users/{user_name}' + response = self.session.delete(url) + res_json = response.json() + if response.status_code == 200: + print(res_json["message"]) + else: + print(f"Fail to drop user, code: {res_json['code']}, message: {res_json['message']}") + + def _handle_alter_user(self, command): + user_name_tree: Tree = command['user_name'] + user_name: str = user_name_tree.children[0].strip("'\"") + password_tree: Tree = command['password'] + password: str = password_tree.children[0].strip("'\"") + print(f"Alter user: {user_name}, password: {password}") + url = f'http://{self.host}:{self.port}/api/v1/admin/users/{user_name}/password' + response = self.session.put(url, json={'new_password': encrypt(password)}) + res_json = response.json() + if response.status_code == 200: + print(res_json["message"]) + else: + print(f"Fail to alter password, code: {res_json['code']}, message: {res_json['message']}") + + def _handle_create_user(self, command): + user_name_tree: Tree = command['user_name'] + user_name: str = user_name_tree.children[0].strip("'\"") + password_tree: Tree = command['password'] + password: str = password_tree.children[0].strip("'\"") + role: str = command['role'] + print(f"Create user: {user_name}, password: {password}, role: {role}") + url = f'http://{self.host}:{self.port}/api/v1/admin/users' + response = self.session.post( + url, + json={'user_name': user_name, 'password': encrypt(password), 'role': role} + ) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print(f"Fail to create user {user_name}, code: {res_json['code']}, message: {res_json['message']}") + + def _handle_activate_user(self, command): + user_name_tree: Tree = command['user_name'] + user_name: str = user_name_tree.children[0].strip("'\"") + activate_tree: Tree = command['activate_status'] + activate_status: str = activate_tree.children[0].strip("'\"") + if activate_status.lower() in ['on', 'off']: + print(f"Alter user {user_name} activate status, turn {activate_status.lower()}.") + url = f'http://{self.host}:{self.port}/api/v1/admin/users/{user_name}/activate' + response = self.session.put(url, json={'activate_status': activate_status}) + res_json = response.json() + if response.status_code == 200: + print(res_json["message"]) + else: + print(f"Fail to alter activate status, code: {res_json['code']}, message: {res_json['message']}") + else: + print(f"Unknown activate status: {activate_status}.") + + def _handle_list_datasets(self, command): + username_tree: Tree = command['user_name'] + user_name: str = username_tree.children[0].strip("'\"") + print(f"Listing all datasets of user: {user_name}") + url = f'http://{self.host}:{self.port}/api/v1/admin/users/{user_name}/datasets' + response = self.session.get(url) + res_json = response.json() + if response.status_code == 200: + table_data = res_json['data'] + for t in table_data: + t.pop('avatar') + self._print_table_simple(table_data) + else: + print(f"Fail to get all datasets of {user_name}, code: {res_json['code']}, message: {res_json['message']}") + + def _handle_list_agents(self, command): + username_tree: Tree = command['user_name'] + user_name: str = username_tree.children[0].strip("'\"") + print(f"Listing all agents of user: {user_name}") + url = f'http://{self.host}:{self.port}/api/v1/admin/users/{user_name}/agents' + response = self.session.get(url) + res_json = response.json() + if response.status_code == 200: + table_data = res_json['data'] + for t in table_data: + t.pop('avatar') + self._print_table_simple(table_data) + else: + print(f"Fail to get all agents of {user_name}, code: {res_json['code']}, message: {res_json['message']}") + + def _create_role(self, command): + role_name_tree: Tree = command['role_name'] + role_name: str = role_name_tree.children[0].strip("'\"") + desc_str: str = '' + if 'description' in command: + desc_tree: Tree = command['description'] + desc_str = desc_tree.children[0].strip("'\"") + + print(f"create role name: {role_name}, description: {desc_str}") + url = f'http://{self.host}:{self.port}/api/v1/admin/roles' + response = self.session.post( + url, + json={'role_name': role_name, 'description': desc_str} + ) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print(f"Fail to create role {role_name}, code: {res_json['code']}, message: {res_json['message']}") + + def _drop_role(self, command): + role_name_tree: Tree = command['role_name'] + role_name: str = role_name_tree.children[0].strip("'\"") + print(f"drop role name: {role_name}") + url = f'http://{self.host}:{self.port}/api/v1/admin/roles/{role_name}' + response = self.session.delete(url) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print(f"Fail to drop role {role_name}, code: {res_json['code']}, message: {res_json['message']}") + + def _alter_role(self, command): + role_name_tree: Tree = command['role_name'] + role_name: str = role_name_tree.children[0].strip("'\"") + desc_tree: Tree = command['description'] + desc_str: str = desc_tree.children[0].strip("'\"") + + print(f"alter role name: {role_name}, description: {desc_str}") + url = f'http://{self.host}:{self.port}/api/v1/admin/roles/{role_name}' + response = self.session.put( + url, + json={'description': desc_str} + ) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print( + f"Fail to update role {role_name} with description: {desc_str}, code: {res_json['code']}, message: {res_json['message']}") + + def _list_roles(self, command): + print("Listing all roles") + url = f'http://{self.host}:{self.port}/api/v1/admin/roles' + response = self.session.get(url) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print(f"Fail to list roles, code: {res_json['code']}, message: {res_json['message']}") + + def _show_role(self, command): + role_name_tree: Tree = command['role_name'] + role_name: str = role_name_tree.children[0].strip("'\"") + print(f"show role: {role_name}") + url = f'http://{self.host}:{self.port}/api/v1/admin/roles/{role_name}/permission' + response = self.session.get(url) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print(f"Fail to list roles, code: {res_json['code']}, message: {res_json['message']}") + + def _grant_permission(self, command): + role_name_tree: Tree = command['role_name'] + role_name_str: str = role_name_tree.children[0].strip("'\"") + resource_tree: Tree = command['resource'] + resource_str: str = resource_tree.children[0].strip("'\"") + action_tree_list: list = command['actions'] + actions: list = [] + for action_tree in action_tree_list: + action_str: str = action_tree.children[0].strip("'\"") + actions.append(action_str) + print(f"grant role_name: {role_name_str}, resource: {resource_str}, actions: {actions}") + url = f'http://{self.host}:{self.port}/api/v1/admin/roles/{role_name_str}/permission' + response = self.session.post( + url, + json={'actions': actions, 'resource': resource_str} + ) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print( + f"Fail to grant role {role_name_str} with {actions} on {resource_str}, code: {res_json['code']}, message: {res_json['message']}") + + def _revoke_permission(self, command): + role_name_tree: Tree = command['role_name'] + role_name_str: str = role_name_tree.children[0].strip("'\"") + resource_tree: Tree = command['resource'] + resource_str: str = resource_tree.children[0].strip("'\"") + action_tree_list: list = command['actions'] + actions: list = [] + for action_tree in action_tree_list: + action_str: str = action_tree.children[0].strip("'\"") + actions.append(action_str) + print(f"revoke role_name: {role_name_str}, resource: {resource_str}, actions: {actions}") + url = f'http://{self.host}:{self.port}/api/v1/admin/roles/{role_name_str}/permission' + response = self.session.delete( + url, + json={'actions': actions, 'resource': resource_str} + ) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print( + f"Fail to revoke role {role_name_str} with {actions} on {resource_str}, code: {res_json['code']}, message: {res_json['message']}") + + def _alter_user_role(self, command): + role_name_tree: Tree = command['role_name'] + role_name_str: str = role_name_tree.children[0].strip("'\"") + user_name_tree: Tree = command['user_name'] + user_name_str: str = user_name_tree.children[0].strip("'\"") + print(f"alter_user_role user_name: {user_name_str}, role_name: {role_name_str}") + url = f'http://{self.host}:{self.port}/api/v1/admin/users/{user_name_str}/role' + response = self.session.put( + url, + json={'role_name': role_name_str} + ) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print( + f"Fail to alter user: {user_name_str} to role {role_name_str}, code: {res_json['code']}, message: {res_json['message']}") + + def _show_user_permission(self, command): + user_name_tree: Tree = command['user_name'] + user_name_str: str = user_name_tree.children[0].strip("'\"") + print(f"show_user_permission user_name: {user_name_str}") + url = f'http://{self.host}:{self.port}/api/v1/admin/users/{user_name_str}/permission' + response = self.session.get(url) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print( + f"Fail to show user: {user_name_str} permission, code: {res_json['code']}, message: {res_json['message']}") + + def _show_version(self, command): + print("show_version") + url = f'http://{self.host}:{self.port}/api/v1/admin/version' + response = self.session.get(url) + res_json = response.json() + if response.status_code == 200: + self._print_table_simple(res_json['data']) + else: + print(f"Fail to show version, code: {res_json['code']}, message: {res_json['message']}") + + def _handle_meta_command(self, command): + meta_command = command['command'] + args = command.get('args', []) + + if meta_command in ['?', 'h', 'help']: + self.show_help() + elif meta_command in ['q', 'quit', 'exit']: + print("Goodbye!") + else: + print(f"Meta command '{meta_command}' with args {args}") + + def show_help(self): + """Help info""" + help_text = """ +Commands: + LIST SERVICES + SHOW SERVICE + STARTUP SERVICE + SHUTDOWN SERVICE + RESTART SERVICE + LIST USERS + SHOW USER + DROP USER + CREATE USER + ALTER USER PASSWORD + ALTER USER ACTIVE + LIST DATASETS OF + LIST AGENTS OF + +Meta Commands: + \\?, \\h, \\help Show this help + \\q, \\quit, \\exit Quit the CLI + """ + print(help_text) + + +def main(): + import sys + + cli = AdminCLI() + + args = cli.parse_connection_args(sys.argv) + if 'error' in args: + print(f"Error: {args['error']}") + return + + if 'command' in args: + if 'password' not in args: + print("Error: password is missing") + return + if cli.verify_admin(args, single_command=True): + command: str = args['command'] + print(f"Run single command: {command}") + cli.run_single_command(command) + else: + if cli.verify_admin(args, single_command=False): + print(r""" + ____ ___ ______________ ___ __ _ + / __ \/ | / ____/ ____/ /___ _ __ / | ____/ /___ ___ (_)___ + / /_/ / /| |/ / __/ /_ / / __ \ | /| / / / /| |/ __ / __ `__ \/ / __ \ + / _, _/ ___ / /_/ / __/ / / /_/ / |/ |/ / / ___ / /_/ / / / / / / / / / / + /_/ |_/_/ |_\____/_/ /_/\____/|__/|__/ /_/ |_\__,_/_/ /_/ /_/_/_/ /_/ + """) + cli.cmdloop() + + +if __name__ == '__main__': + main() diff --git a/admin/client/pyproject.toml b/admin/client/pyproject.toml new file mode 100644 index 00000000000..6dad77a2b8a --- /dev/null +++ b/admin/client/pyproject.toml @@ -0,0 +1,24 @@ +[project] +name = "ragflow-cli" +version = "0.22.0" +description = "Admin Service's client of [RAGFlow](https://github.com/infiniflow/ragflow). The Admin Service provides user management and system monitoring. " +authors = [{ name = "Lynn", email = "lynn_inf@hotmail.com" }] +license = { text = "Apache License, Version 2.0" } +readme = "README.md" +requires-python = ">=3.10,<3.13" +dependencies = [ + "requests>=2.30.0,<3.0.0", + "beartype>=0.18.5,<0.19.0", + "pycryptodomex>=3.10.0", + "lark>=1.1.0", +] + +[dependency-groups] +test = [ + "pytest>=8.3.5", + "requests>=2.32.3", + "requests-toolbelt>=1.0.0", +] + +[project.scripts] +ragflow-cli = "admin_client:main" diff --git a/admin/server/admin_server.py b/admin/server/admin_server.py new file mode 100644 index 00000000000..cfc5c4bee55 --- /dev/null +++ b/admin/server/admin_server.py @@ -0,0 +1,79 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import signal +import logging +import time +import threading +import traceback +from werkzeug.serving import run_simple +from flask import Flask +from routes import admin_bp +from common.log_utils import init_root_logger +from common.constants import SERVICE_CONF +from common.config_utils import show_configs +from common import settings +from config import load_configurations, SERVICE_CONFIGS +from auth import init_default_admin, setup_auth +from flask_session import Session +from flask_login import LoginManager +from common.versions import get_ragflow_version + +stop_event = threading.Event() + +if __name__ == '__main__': + init_root_logger("admin_service") + logging.info(r""" + ____ ___ ______________ ___ __ _ + / __ \/ | / ____/ ____/ /___ _ __ / | ____/ /___ ___ (_)___ + / /_/ / /| |/ / __/ /_ / / __ \ | /| / / / /| |/ __ / __ `__ \/ / __ \ + / _, _/ ___ / /_/ / __/ / / /_/ / |/ |/ / / ___ / /_/ / / / / / / / / / / + /_/ |_/_/ |_\____/_/ /_/\____/|__/|__/ /_/ |_\__,_/_/ /_/ /_/_/_/ /_/ + """) + + app = Flask(__name__) + app.register_blueprint(admin_bp) + app.config["SESSION_PERMANENT"] = False + app.config["SESSION_TYPE"] = "filesystem" + app.config["MAX_CONTENT_LENGTH"] = int( + os.environ.get("MAX_CONTENT_LENGTH", 1024 * 1024 * 1024) + ) + Session(app) + logging.info(f'RAGFlow version: {get_ragflow_version()}') + show_configs() + login_manager = LoginManager() + login_manager.init_app(app) + settings.init_settings() + setup_auth(login_manager) + init_default_admin() + SERVICE_CONFIGS.configs = load_configurations(SERVICE_CONF) + + try: + logging.info("RAGFlow Admin service start...") + run_simple( + hostname="0.0.0.0", + port=9381, + application=app, + threaded=True, + use_reloader=False, + use_debugger=True, + ) + except Exception: + traceback.print_exc() + stop_event.set() + time.sleep(1) + os.kill(os.getpid(), signal.SIGKILL) diff --git a/admin/server/auth.py b/admin/server/auth.py new file mode 100644 index 00000000000..564c348e3f6 --- /dev/null +++ b/admin/server/auth.py @@ -0,0 +1,187 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +import logging +import uuid +from functools import wraps +from datetime import datetime +from flask import request, jsonify +from flask_login import current_user, login_user +from itsdangerous.url_safe import URLSafeTimedSerializer as Serializer + +from api.common.exceptions import AdminException, UserNotFoundError +from api.common.base64 import encode_to_base64 +from api.db.services import UserService +from common.constants import ActiveEnum, StatusEnum +from api.utils.crypt import decrypt +from common.misc_utils import get_uuid +from common.time_utils import current_timestamp, datetime_format, get_format_time +from common.connection_utils import construct_response +from common import settings + + +def setup_auth(login_manager): + @login_manager.request_loader + def load_user(web_request): + jwt = Serializer(secret_key=settings.SECRET_KEY) + authorization = web_request.headers.get("Authorization") + if authorization: + try: + access_token = str(jwt.loads(authorization)) + + if not access_token or not access_token.strip(): + logging.warning("Authentication attempt with empty access token") + return None + + # Access tokens should be UUIDs (32 hex characters) + if len(access_token.strip()) < 32: + logging.warning(f"Authentication attempt with invalid token format: {len(access_token)} chars") + return None + + user = UserService.query( + access_token=access_token, status=StatusEnum.VALID.value + ) + if user: + if not user[0].access_token or not user[0].access_token.strip(): + logging.warning(f"User {user[0].email} has empty access_token in database") + return None + return user[0] + else: + return None + except Exception as e: + logging.warning(f"load_user got exception {e}") + return None + else: + return None + + +def init_default_admin(): + # Verify that at least one active admin user exists. If not, create a default one. + users = UserService.query(is_superuser=True) + if not users: + default_admin = { + "id": uuid.uuid1().hex, + "password": encode_to_base64("admin"), + "nickname": "admin", + "is_superuser": True, + "email": "admin@ragflow.io", + "creator": "system", + "status": "1", + } + if not UserService.save(**default_admin): + raise AdminException("Can't init admin.", 500) + elif not any([u.is_active == ActiveEnum.ACTIVE.value for u in users]): + raise AdminException("No active admin. Please update 'is_active' in db manually.", 500) + + +def check_admin_auth(func): + @wraps(func) + def wrapper(*args, **kwargs): + user = UserService.filter_by_id(current_user.id) + if not user: + raise UserNotFoundError(current_user.email) + if not user.is_superuser: + raise AdminException("Not admin", 403) + if user.is_active == ActiveEnum.INACTIVE.value: + raise AdminException(f"User {current_user.email} inactive", 403) + + return func(*args, **kwargs) + + return wrapper + + +def login_admin(email: str, password: str): + """ + :param email: admin email + :param password: string before decrypt + """ + users = UserService.query(email=email) + if not users: + raise UserNotFoundError(email) + psw = decrypt(password) + user = UserService.query_user(email, psw) + if not user: + raise AdminException("Email and password do not match!") + if not user.is_superuser: + raise AdminException("Not admin", 403) + if user.is_active == ActiveEnum.INACTIVE.value: + raise AdminException(f"User {email} inactive", 403) + + resp = user.to_json() + user.access_token = get_uuid() + login_user(user) + user.update_time = (current_timestamp(),) + user.update_date = (datetime_format(datetime.now()),) + user.last_login_time = get_format_time() + user.save() + msg = "Welcome back!" + return construct_response(data=resp, auth=user.get_id(), message=msg) + + +def check_admin(username: str, password: str): + users = UserService.query(email=username) + if not users: + logging.info(f"Username: {username} is not registered!") + user_info = { + "id": uuid.uuid1().hex, + "password": encode_to_base64("admin"), + "nickname": "admin", + "is_superuser": True, + "email": "admin@ragflow.io", + "creator": "system", + "status": "1", + } + if not UserService.save(**user_info): + raise AdminException("Can't init admin.", 500) + + user = UserService.query_user(username, password) + if user: + return True + else: + return False + + +def login_verify(f): + @wraps(f) + def decorated(*args, **kwargs): + auth = request.authorization + if not auth or 'username' not in auth.parameters or 'password' not in auth.parameters: + return jsonify({ + "code": 401, + "message": "Authentication required", + "data": None + }), 200 + + username = auth.parameters['username'] + password = auth.parameters['password'] + try: + if check_admin(username, password) is False: + return jsonify({ + "code": 500, + "message": "Access denied", + "data": None + }), 200 + except Exception as e: + error_msg = str(e) + return jsonify({ + "code": 500, + "message": error_msg + }), 200 + + return f(*args, **kwargs) + + return decorated diff --git a/admin/server/config.py b/admin/server/config.py new file mode 100644 index 00000000000..e2c7d11ef90 --- /dev/null +++ b/admin/server/config.py @@ -0,0 +1,317 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +import logging +import threading +from enum import Enum + +from pydantic import BaseModel +from typing import Any +from common.config_utils import read_config +from urllib.parse import urlparse + + +class ServiceConfigs: + configs = dict + + def __init__(self): + self.configs = [] + self.lock = threading.Lock() + + +SERVICE_CONFIGS = ServiceConfigs + + +class ServiceType(Enum): + METADATA = "metadata" + RETRIEVAL = "retrieval" + MESSAGE_QUEUE = "message_queue" + RAGFLOW_SERVER = "ragflow_server" + TASK_EXECUTOR = "task_executor" + FILE_STORE = "file_store" + + +class BaseConfig(BaseModel): + id: int + name: str + host: str + port: int + service_type: str + detail_func_name: str + + def to_dict(self) -> dict[str, Any]: + return {'id': self.id, 'name': self.name, 'host': self.host, 'port': self.port, + 'service_type': self.service_type} + + +class MetaConfig(BaseConfig): + meta_type: str + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + extra_dict = result['extra'].copy() + extra_dict['meta_type'] = self.meta_type + result['extra'] = extra_dict + return result + + +class MySQLConfig(MetaConfig): + username: str + password: str + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + extra_dict = result['extra'].copy() + extra_dict['username'] = self.username + extra_dict['password'] = self.password + result['extra'] = extra_dict + return result + + +class PostgresConfig(MetaConfig): + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + return result + + +class RetrievalConfig(BaseConfig): + retrieval_type: str + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + extra_dict = result['extra'].copy() + extra_dict['retrieval_type'] = self.retrieval_type + result['extra'] = extra_dict + return result + + +class InfinityConfig(RetrievalConfig): + db_name: str + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + extra_dict = result['extra'].copy() + extra_dict['db_name'] = self.db_name + result['extra'] = extra_dict + return result + + +class ElasticsearchConfig(RetrievalConfig): + username: str + password: str + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + extra_dict = result['extra'].copy() + extra_dict['username'] = self.username + extra_dict['password'] = self.password + result['extra'] = extra_dict + return result + + +class MessageQueueConfig(BaseConfig): + mq_type: str + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + extra_dict = result['extra'].copy() + extra_dict['mq_type'] = self.mq_type + result['extra'] = extra_dict + return result + + +class RedisConfig(MessageQueueConfig): + database: int + password: str + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + extra_dict = result['extra'].copy() + extra_dict['database'] = self.database + extra_dict['password'] = self.password + result['extra'] = extra_dict + return result + + +class RabbitMQConfig(MessageQueueConfig): + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + return result + + +class RAGFlowServerConfig(BaseConfig): + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + return result + + +class TaskExecutorConfig(BaseConfig): + message_queue_type: str + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + result['extra']['message_queue_type'] = self.message_queue_type + return result + + +class FileStoreConfig(BaseConfig): + store_type: str + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + extra_dict = result['extra'].copy() + extra_dict['store_type'] = self.store_type + result['extra'] = extra_dict + return result + + +class MinioConfig(FileStoreConfig): + user: str + password: str + + def to_dict(self) -> dict[str, Any]: + result = super().to_dict() + if 'extra' not in result: + result['extra'] = dict() + extra_dict = result['extra'].copy() + extra_dict['user'] = self.user + extra_dict['password'] = self.password + result['extra'] = extra_dict + return result + + +def load_configurations(config_path: str) -> list[BaseConfig]: + raw_configs = read_config(config_path) + configurations = [] + ragflow_count = 0 + id_count = 0 + for k, v in raw_configs.items(): + match (k): + case "ragflow": + name: str = f'ragflow_{ragflow_count}' + host: str = v['host'] + http_port: int = v['http_port'] + config = RAGFlowServerConfig(id=id_count, name=name, host=host, port=http_port, + service_type="ragflow_server", + detail_func_name="check_ragflow_server_alive") + configurations.append(config) + id_count += 1 + case "es": + name: str = 'elasticsearch' + url = v['hosts'] + parsed = urlparse(url) + host: str = parsed.hostname + port: int = parsed.port + username: str = v.get('username') + password: str = v.get('password') + config = ElasticsearchConfig(id=id_count, name=name, host=host, port=port, service_type="retrieval", + retrieval_type="elasticsearch", + username=username, password=password, + detail_func_name="get_es_cluster_stats") + configurations.append(config) + id_count += 1 + + case "infinity": + name: str = 'infinity' + url = v['uri'] + parts = url.split(':', 1) + host = parts[0] + port = int(parts[1]) + database: str = v.get('db_name', 'default_db') + config = InfinityConfig(id=id_count, name=name, host=host, port=port, service_type="retrieval", + retrieval_type="infinity", + db_name=database, detail_func_name="get_infinity_status") + configurations.append(config) + id_count += 1 + case "minio": + name: str = 'minio' + url = v['host'] + parts = url.split(':', 1) + host = parts[0] + port = int(parts[1]) + user = v.get('user') + password = v.get('password') + config = MinioConfig(id=id_count, name=name, host=host, port=port, user=user, password=password, + service_type="file_store", + store_type="minio", detail_func_name="check_minio_alive") + configurations.append(config) + id_count += 1 + case "redis": + name: str = 'redis' + url = v['host'] + parts = url.split(':', 1) + host = parts[0] + port = int(parts[1]) + password = v.get('password') + db: int = v.get('db') + config = RedisConfig(id=id_count, name=name, host=host, port=port, password=password, database=db, + service_type="message_queue", mq_type="redis", detail_func_name="get_redis_info") + configurations.append(config) + id_count += 1 + case "mysql": + name: str = 'mysql' + host: str = v.get('host') + port: int = v.get('port') + username = v.get('user') + password = v.get('password') + config = MySQLConfig(id=id_count, name=name, host=host, port=port, username=username, password=password, + service_type="meta_data", meta_type="mysql", detail_func_name="get_mysql_status") + configurations.append(config) + id_count += 1 + case "admin": + pass + case "task_executor": + name: str = 'task_executor' + host: str = v.get('host', '') + port: int = v.get('port', 0) + message_queue_type: str = v.get('message_queue_type') + config = TaskExecutorConfig(id=id_count, name=name, host=host, port=port, message_queue_type=message_queue_type, + service_type="task_executor", detail_func_name="check_task_executor_alive") + configurations.append(config) + id_count += 1 + case _: + logging.warning(f"Unknown configuration key: {k}") + continue + + return configurations diff --git a/admin/server/exceptions.py b/admin/server/exceptions.py new file mode 100644 index 00000000000..5e3021b418a --- /dev/null +++ b/admin/server/exceptions.py @@ -0,0 +1,17 @@ +class AdminException(Exception): + def __init__(self, message, code=400): + super().__init__(message) + self.code = code + self.message = message + +class UserNotFoundError(AdminException): + def __init__(self, username): + super().__init__(f"User '{username}' not found", 404) + +class UserAlreadyExistsError(AdminException): + def __init__(self, username): + super().__init__(f"User '{username}' already exists", 409) + +class CannotDeleteAdminError(AdminException): + def __init__(self): + super().__init__("Cannot delete admin account", 403) \ No newline at end of file diff --git a/test/libs/__init__.py b/admin/server/models.py similarity index 100% rename from test/libs/__init__.py rename to admin/server/models.py diff --git a/admin/server/responses.py b/admin/server/responses.py new file mode 100644 index 00000000000..54f841a8307 --- /dev/null +++ b/admin/server/responses.py @@ -0,0 +1,34 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +from flask import jsonify + + +def success_response(data=None, message="Success", code=0): + return jsonify({ + "code": code, + "message": message, + "data": data + }), 200 + + +def error_response(message="Error", code=-1, data=None): + return jsonify({ + "code": code, + "message": message, + "data": data + }), 400 diff --git a/admin/server/roles.py b/admin/server/roles.py new file mode 100644 index 00000000000..ac04179f063 --- /dev/null +++ b/admin/server/roles.py @@ -0,0 +1,76 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging + +from typing import Dict, Any + +from api.common.exceptions import AdminException + + +class RoleMgr: + @staticmethod + def create_role(role_name: str, description: str): + error_msg = f"not implement: create role: {role_name}, description: {description}" + logging.error(error_msg) + raise AdminException(error_msg) + + @staticmethod + def update_role_description(role_name: str, description: str) -> Dict[str, Any]: + error_msg = f"not implement: update role: {role_name} with description: {description}" + logging.error(error_msg) + raise AdminException(error_msg) + + @staticmethod + def delete_role(role_name: str) -> Dict[str, Any]: + error_msg = f"not implement: drop role: {role_name}" + logging.error(error_msg) + raise AdminException(error_msg) + + @staticmethod + def list_roles() -> Dict[str, Any]: + error_msg = "not implement: list roles" + logging.error(error_msg) + raise AdminException(error_msg) + + @staticmethod + def get_role_permission(role_name: str) -> Dict[str, Any]: + error_msg = f"not implement: show role {role_name}" + logging.error(error_msg) + raise AdminException(error_msg) + + @staticmethod + def grant_role_permission(role_name: str, actions: list, resource: str) -> Dict[str, Any]: + error_msg = f"not implement: grant role {role_name} actions: {actions} on {resource}" + logging.error(error_msg) + raise AdminException(error_msg) + + @staticmethod + def revoke_role_permission(role_name: str, actions: list, resource: str) -> Dict[str, Any]: + error_msg = f"not implement: revoke role {role_name} actions: {actions} on {resource}" + logging.error(error_msg) + raise AdminException(error_msg) + + @staticmethod + def update_user_role(user_name: str, role_name: str) -> Dict[str, Any]: + error_msg = f"not implement: update user role: {user_name} to role {role_name}" + logging.error(error_msg) + raise AdminException(error_msg) + + @staticmethod + def get_user_permission(user_name: str) -> Dict[str, Any]: + error_msg = f"not implement: get user permission: {user_name}" + logging.error(error_msg) + raise AdminException(error_msg) diff --git a/admin/server/routes.py b/admin/server/routes.py new file mode 100644 index 00000000000..2c70fbd7af6 --- /dev/null +++ b/admin/server/routes.py @@ -0,0 +1,382 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import secrets + +from flask import Blueprint, request +from flask_login import current_user, logout_user, login_required + +from auth import login_verify, login_admin, check_admin_auth +from responses import success_response, error_response +from services import UserMgr, ServiceMgr, UserServiceMgr +from roles import RoleMgr +from api.common.exceptions import AdminException +from common.versions import get_ragflow_version + +admin_bp = Blueprint('admin', __name__, url_prefix='/api/v1/admin') + + +@admin_bp.route('/login', methods=['POST']) +def login(): + if not request.json: + return error_response('Authorize admin failed.' ,400) + try: + email = request.json.get("email", "") + password = request.json.get("password", "") + return login_admin(email, password) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/logout', methods=['GET']) +@login_required +def logout(): + try: + current_user.access_token = f"INVALID_{secrets.token_hex(16)}" + current_user.save() + logout_user() + return success_response(True) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/auth', methods=['GET']) +@login_verify +def auth_admin(): + try: + return success_response(None, "Admin is authorized", 0) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/users', methods=['GET']) +@login_required +@check_admin_auth +def list_users(): + try: + users = UserMgr.get_all_users() + return success_response(users, "Get all users", 0) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/users', methods=['POST']) +@login_required +@check_admin_auth +def create_user(): + try: + data = request.get_json() + if not data or 'username' not in data or 'password' not in data: + return error_response("Username and password are required", 400) + + username = data['username'] + password = data['password'] + role = data.get('role', 'user') + + res = UserMgr.create_user(username, password, role) + if res["success"]: + user_info = res["user_info"] + user_info.pop("password") # do not return password + return success_response(user_info, "User created successfully") + else: + return error_response("create user failed") + + except AdminException as e: + return error_response(e.message, e.code) + except Exception as e: + return error_response(str(e)) + + +@admin_bp.route('/users/', methods=['DELETE']) +@login_required +@check_admin_auth +def delete_user(username): + try: + res = UserMgr.delete_user(username) + if res["success"]: + return success_response(None, res["message"]) + else: + return error_response(res["message"]) + + except AdminException as e: + return error_response(e.message, e.code) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/users//password', methods=['PUT']) +@login_required +@check_admin_auth +def change_password(username): + try: + data = request.get_json() + if not data or 'new_password' not in data: + return error_response("New password is required", 400) + + new_password = data['new_password'] + msg = UserMgr.update_user_password(username, new_password) + return success_response(None, msg) + + except AdminException as e: + return error_response(e.message, e.code) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/users//activate', methods=['PUT']) +@login_required +@check_admin_auth +def alter_user_activate_status(username): + try: + data = request.get_json() + if not data or 'activate_status' not in data: + return error_response("Activation status is required", 400) + activate_status = data['activate_status'] + msg = UserMgr.update_user_activate_status(username, activate_status) + return success_response(None, msg) + except AdminException as e: + return error_response(e.message, e.code) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/users/', methods=['GET']) +@login_required +@check_admin_auth +def get_user_details(username): + try: + user_details = UserMgr.get_user_details(username) + return success_response(user_details) + + except AdminException as e: + return error_response(e.message, e.code) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/users//datasets', methods=['GET']) +@login_required +@check_admin_auth +def get_user_datasets(username): + try: + datasets_list = UserServiceMgr.get_user_datasets(username) + return success_response(datasets_list) + + except AdminException as e: + return error_response(e.message, e.code) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/users//agents', methods=['GET']) +@login_required +@check_admin_auth +def get_user_agents(username): + try: + agents_list = UserServiceMgr.get_user_agents(username) + return success_response(agents_list) + + except AdminException as e: + return error_response(e.message, e.code) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/services', methods=['GET']) +@login_required +@check_admin_auth +def get_services(): + try: + services = ServiceMgr.get_all_services() + return success_response(services, "Get all services", 0) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/service_types/', methods=['GET']) +@login_required +@check_admin_auth +def get_services_by_type(service_type_str): + try: + services = ServiceMgr.get_services_by_type(service_type_str) + return success_response(services) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/services/', methods=['GET']) +@login_required +@check_admin_auth +def get_service(service_id): + try: + services = ServiceMgr.get_service_details(service_id) + return success_response(services) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/services/', methods=['DELETE']) +@login_required +@check_admin_auth +def shutdown_service(service_id): + try: + services = ServiceMgr.shutdown_service(service_id) + return success_response(services) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/services/', methods=['PUT']) +@login_required +@check_admin_auth +def restart_service(service_id): + try: + services = ServiceMgr.restart_service(service_id) + return success_response(services) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/roles', methods=['POST']) +@login_required +@check_admin_auth +def create_role(): + try: + data = request.get_json() + if not data or 'role_name' not in data: + return error_response("Role name is required", 400) + role_name: str = data['role_name'] + description: str = data['description'] + res = RoleMgr.create_role(role_name, description) + return success_response(res) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/roles/', methods=['PUT']) +@login_required +@check_admin_auth +def update_role(role_name: str): + try: + data = request.get_json() + if not data or 'description' not in data: + return error_response("Role description is required", 400) + description: str = data['description'] + res = RoleMgr.update_role_description(role_name, description) + return success_response(res) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/roles/', methods=['DELETE']) +@login_required +@check_admin_auth +def delete_role(role_name: str): + try: + res = RoleMgr.delete_role(role_name) + return success_response(res) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/roles', methods=['GET']) +@login_required +@check_admin_auth +def list_roles(): + try: + res = RoleMgr.list_roles() + return success_response(res) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/roles//permission', methods=['GET']) +@login_required +@check_admin_auth +def get_role_permission(role_name: str): + try: + res = RoleMgr.get_role_permission(role_name) + return success_response(res) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/roles//permission', methods=['POST']) +@login_required +@check_admin_auth +def grant_role_permission(role_name: str): + try: + data = request.get_json() + if not data or 'actions' not in data or 'resource' not in data: + return error_response("Permission is required", 400) + actions: list = data['actions'] + resource: str = data['resource'] + res = RoleMgr.grant_role_permission(role_name, actions, resource) + return success_response(res) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/roles//permission', methods=['DELETE']) +@login_required +@check_admin_auth +def revoke_role_permission(role_name: str): + try: + data = request.get_json() + if not data or 'actions' not in data or 'resource' not in data: + return error_response("Permission is required", 400) + actions: list = data['actions'] + resource: str = data['resource'] + res = RoleMgr.revoke_role_permission(role_name, actions, resource) + return success_response(res) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/users//role', methods=['PUT']) +@login_required +@check_admin_auth +def update_user_role(user_name: str): + try: + data = request.get_json() + if not data or 'role_name' not in data: + return error_response("Role name is required", 400) + role_name: str = data['role_name'] + res = RoleMgr.update_user_role(user_name, role_name) + return success_response(res) + except Exception as e: + return error_response(str(e), 500) + + +@admin_bp.route('/users//permission', methods=['GET']) +@login_required +@check_admin_auth +def get_user_permission(user_name: str): + try: + res = RoleMgr.get_user_permission(user_name) + return success_response(res) + except Exception as e: + return error_response(str(e), 500) + +@admin_bp.route('/version', methods=['GET']) +@login_required +@check_admin_auth +def show_version(): + try: + res = {"version": get_ragflow_version()} + return success_response(res) + except Exception as e: + return error_response(str(e), 500) diff --git a/admin/server/services.py b/admin/server/services.py new file mode 100644 index 00000000000..e8cf4eb5d44 --- /dev/null +++ b/admin/server/services.py @@ -0,0 +1,231 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +import re +from werkzeug.security import check_password_hash +from common.constants import ActiveEnum +from api.db.services import UserService +from api.db.joint_services.user_account_service import create_new_user, delete_user_data +from api.db.services.canvas_service import UserCanvasService +from api.db.services.user_service import TenantService +from api.db.services.knowledgebase_service import KnowledgebaseService +from api.utils.crypt import decrypt +from api.utils import health_utils + +from api.common.exceptions import AdminException, UserAlreadyExistsError, UserNotFoundError +from config import SERVICE_CONFIGS + + +class UserMgr: + @staticmethod + def get_all_users(): + users = UserService.get_all_users() + result = [] + for user in users: + result.append({ + 'email': user.email, + 'nickname': user.nickname, + 'create_date': user.create_date, + 'is_active': user.is_active, + 'is_superuser': user.is_superuser, + }) + return result + + @staticmethod + def get_user_details(username): + # use email to query + users = UserService.query_user_by_email(username) + result = [] + for user in users: + result.append({ + 'avatar': user.avatar, + 'email': user.email, + 'language': user.language, + 'last_login_time': user.last_login_time, + 'is_active': user.is_active, + 'is_anonymous': user.is_anonymous, + 'login_channel': user.login_channel, + 'status': user.status, + 'is_superuser': user.is_superuser, + 'create_date': user.create_date, + 'update_date': user.update_date + }) + return result + + @staticmethod + def create_user(username, password, role="user") -> dict: + # Validate the email address + if not re.match(r"^[\w\._-]+@([\w_-]+\.)+[\w-]{2,}$", username): + raise AdminException(f"Invalid email address: {username}!") + # Check if the email address is already used + if UserService.query(email=username): + raise UserAlreadyExistsError(username) + # Construct user info data + user_info_dict = { + "email": username, + "nickname": "", # ask user to edit it manually in settings. + "password": decrypt(password), + "login_channel": "password", + "is_superuser": role == "admin", + } + return create_new_user(user_info_dict) + + @staticmethod + def delete_user(username): + # use email to delete + user_list = UserService.query_user_by_email(username) + if not user_list: + raise UserNotFoundError(username) + if len(user_list) > 1: + raise AdminException(f"Exist more than 1 user: {username}!") + usr = user_list[0] + return delete_user_data(usr.id) + + @staticmethod + def update_user_password(username, new_password) -> str: + # use email to find user. check exist and unique. + user_list = UserService.query_user_by_email(username) + if not user_list: + raise UserNotFoundError(username) + elif len(user_list) > 1: + raise AdminException(f"Exist more than 1 user: {username}!") + # check new_password different from old. + usr = user_list[0] + psw = decrypt(new_password) + if check_password_hash(usr.password, psw): + return "Same password, no need to update!" + # update password + UserService.update_user_password(usr.id, psw) + return "Password updated successfully!" + + @staticmethod + def update_user_activate_status(username, activate_status: str): + # use email to find user. check exist and unique. + user_list = UserService.query_user_by_email(username) + if not user_list: + raise UserNotFoundError(username) + elif len(user_list) > 1: + raise AdminException(f"Exist more than 1 user: {username}!") + # check activate status different from new + usr = user_list[0] + # format activate_status before handle + _activate_status = activate_status.lower() + target_status = { + 'on': ActiveEnum.ACTIVE.value, + 'off': ActiveEnum.INACTIVE.value, + }.get(_activate_status) + if not target_status: + raise AdminException(f"Invalid activate_status: {activate_status}") + if target_status == usr.is_active: + return f"User activate status is already {_activate_status}!" + # update is_active + UserService.update_user(usr.id, {"is_active": target_status}) + return f"Turn {_activate_status} user activate status successfully!" + + +class UserServiceMgr: + + @staticmethod + def get_user_datasets(username): + # use email to find user. + user_list = UserService.query_user_by_email(username) + if not user_list: + raise UserNotFoundError(username) + elif len(user_list) > 1: + raise AdminException(f"Exist more than 1 user: {username}!") + # find tenants + usr = user_list[0] + tenants = TenantService.get_joined_tenants_by_user_id(usr.id) + tenant_ids = [m["tenant_id"] for m in tenants] + # filter permitted kb and owned kb + return KnowledgebaseService.get_all_kb_by_tenant_ids(tenant_ids, usr.id) + + @staticmethod + def get_user_agents(username): + # use email to find user. + user_list = UserService.query_user_by_email(username) + if not user_list: + raise UserNotFoundError(username) + elif len(user_list) > 1: + raise AdminException(f"Exist more than 1 user: {username}!") + # find tenants + usr = user_list[0] + tenants = TenantService.get_joined_tenants_by_user_id(usr.id) + tenant_ids = [m["tenant_id"] for m in tenants] + # filter permitted agents and owned agents + res = UserCanvasService.get_all_agents_by_tenant_ids(tenant_ids, usr.id) + return [{ + 'title': r['title'], + 'permission': r['permission'], + 'canvas_category': r['canvas_category'].split('_')[0], + 'avatar': r['avatar'] + } for r in res] + + +class ServiceMgr: + + @staticmethod + def get_all_services(): + result = [] + configs = SERVICE_CONFIGS.configs + for service_id, config in enumerate(configs): + config_dict = config.to_dict() + try: + service_detail = ServiceMgr.get_service_details(service_id) + if "status" in service_detail: + config_dict['status'] = service_detail['status'] + else: + config_dict['status'] = 'timeout' + except Exception: + config_dict['status'] = 'timeout' + if not config_dict['host']: + config_dict['host'] = '-' + if not config_dict['port']: + config_dict['port'] = '-' + result.append(config_dict) + return result + + @staticmethod + def get_services_by_type(service_type_str: str): + raise AdminException("get_services_by_type: not implemented") + + @staticmethod + def get_service_details(service_id: int): + service_id = int(service_id) + configs = SERVICE_CONFIGS.configs + service_config_mapping = { + c.id: { + 'name': c.name, + 'detail_func_name': c.detail_func_name + } for c in configs + } + service_info = service_config_mapping.get(service_id, {}) + if not service_info: + raise AdminException(f"invalid service_id: {service_id}") + + detail_func = getattr(health_utils, service_info.get('detail_func_name')) + res = detail_func() + res.update({'service_name': service_info.get('name')}) + return res + + @staticmethod + def shutdown_service(service_id: int): + raise AdminException("shutdown_service: not implemented") + + @staticmethod + def restart_service(service_id: int): + raise AdminException("restart_service: not implemented") diff --git a/agent/README.md b/agent/README.md deleted file mode 100644 index 250149b84c2..00000000000 --- a/agent/README.md +++ /dev/null @@ -1,45 +0,0 @@ -English | [简体中文](./README_zh.md) - -# *Graph* - - -## Introduction - -*Graph* is a mathematical concept which is composed of nodes and edges. -It is used to compose a complex work flow or agent. -And this graph is beyond the DAG that we can use circles to describe our agent or work flow. -Under this folder, we propose a test tool ./test/client.py which can test the DSLs such as json files in folder ./test/dsl_examples. -Please use this client at the same folder you start RAGFlow. If it's run by Docker, please go into the container before running the client. -Otherwise, correct configurations in service_conf.yaml is essential. - -```bash -PYTHONPATH=path/to/ragflow python graph/test/client.py -h -usage: client.py [-h] -s DSL -t TENANT_ID -m - -options: - -h, --help show this help message and exit - -s DSL, --dsl DSL input dsl - -t TENANT_ID, --tenant_id TENANT_ID - Tenant ID - -m, --stream Stream output -``` -
- -
- - -## How to gain a TENANT_ID in command line? -
- -
-💡 We plan to display it here in the near future. -
- -
- - -## How to set 'kb_ids' for component 'Retrieval' in DSL? -
- -
- diff --git a/agent/README_zh.md b/agent/README_zh.md deleted file mode 100644 index 411e31e2bf7..00000000000 --- a/agent/README_zh.md +++ /dev/null @@ -1,46 +0,0 @@ -[English](./README.md) | 简体中文 - -# *Graph* - - -## 简介 - -"Graph"是一个由节点和边组成的数学概念。 -它被用来构建复杂的工作流或代理。 -这个图超越了有向无环图(DAG),我们可以使用循环来描述我们的代理或工作流。 -在这个文件夹下,我们提出了一个测试工具 ./test/client.py, -它可以测试像文件夹./test/dsl_examples下一样的DSL文件。 -请在启动 RAGFlow 的同一文件夹中使用此客户端。如果它是通过 Docker 运行的,请在运行客户端之前进入容器。 -否则,正确配置 service_conf.yaml 文件是必不可少的。 - -```bash -PYTHONPATH=path/to/ragflow python graph/test/client.py -h -usage: client.py [-h] -s DSL -t TENANT_ID -m - -options: - -h, --help show this help message and exit - -s DSL, --dsl DSL input dsl - -t TENANT_ID, --tenant_id TENANT_ID - Tenant ID - -m, --stream Stream output -``` -
- -
- - -## 命令行中的TENANT_ID如何获得? -
- -
-💡 后面会展示在这里: -
- -
- - -## DSL里面的Retrieval组件的kb_ids怎么填? -
- -
- diff --git a/agent/canvas.py b/agent/canvas.py index 4b859fbf356..bc7a45e3e60 100644 --- a/agent/canvas.py +++ b/agent/canvas.py @@ -13,89 +13,73 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import logging +import base64 import json +import logging +import re +import time +from concurrent.futures import ThreadPoolExecutor from copy import deepcopy from functools import partial -import pandas as pd +from typing import Any, Union, Tuple from agent.component import component_class from agent.component.base import ComponentBase - - -class Canvas: - """ - dsl = { - "components": { - "begin": { - "obj":{ - "component_name": "Begin", - "params": {}, - }, - "downstream": ["answer_0"], - "upstream": [], - }, - "answer_0": { - "obj": { - "component_name": "Answer", - "params": {} - }, - "downstream": ["retrieval_0"], - "upstream": ["begin", "generate_0"], - }, - "retrieval_0": { - "obj": { - "component_name": "Retrieval", - "params": {} - }, - "downstream": ["generate_0"], - "upstream": ["answer_0"], - }, - "generate_0": { - "obj": { - "component_name": "Generate", - "params": {} - }, - "downstream": ["answer_0"], - "upstream": ["retrieval_0"], - } - }, - "history": [], - "messages": [], - "reference": [], - "path": [["begin"]], - "answer": [] - } +from api.db.services.file_service import FileService +from api.db.services.task_service import has_canceled +from common.misc_utils import get_uuid, hash_str2int +from common.exceptions import TaskCanceledException +from rag.prompts.generator import chunks_format +from rag.utils.redis_conn import REDIS_CONN + +class Graph: """ - - def __init__(self, dsl: str, tenant_id=None): - self.path = [] - self.history = [] - self.messages = [] - self.answer = [] - self.components = {} - self.dsl = json.loads(dsl) if dsl else { + dsl = { "components": { "begin": { - "obj": { + "obj":{ "component_name": "Begin", - "params": { - "prologue": "Hi there!" - } + "params": {}, }, - "downstream": [], + "downstream": ["answer_0"], "upstream": [], - "parent_id": "" + }, + "retrieval_0": { + "obj": { + "component_name": "Retrieval", + "params": {} + }, + "downstream": ["generate_0"], + "upstream": ["answer_0"], + }, + "generate_0": { + "obj": { + "component_name": "Generate", + "params": {} + }, + "downstream": ["answer_0"], + "upstream": ["retrieval_0"], } }, "history": [], - "messages": [], - "reference": [], - "path": [], - "answer": [] + "path": ["begin"], + "retrieval": {"chunks": [], "doc_aggs": []}, + "globals": { + "sys.query": "", + "sys.user_id": tenant_id, + "sys.conversation_turns": 0, + "sys.files": [] + } } + """ + + def __init__(self, dsl: str, tenant_id=None, task_id=None): + self.path = [] + self.components = {} + self.error = "" + self.dsl = json.loads(dsl) self._tenant_id = tenant_id - self._embed_id = "" + self.task_id = task_id if task_id else get_uuid() self.load() def load(self): @@ -104,34 +88,22 @@ def load(self): for k, cpn in self.components.items(): cpn_nms.add(cpn["obj"]["component_name"]) - assert "Begin" in cpn_nms, "There have to be an 'Begin' component." - assert "Answer" in cpn_nms, "There have to be an 'Answer' component." - for k, cpn in self.components.items(): cpn_nms.add(cpn["obj"]["component_name"]) param = component_class(cpn["obj"]["component_name"] + "Param")() param.update(cpn["obj"]["params"]) - param.check() + try: + param.check() + except Exception as e: + raise ValueError(self.get_component_name(k) + f": {e}") + cpn["obj"] = component_class(cpn["obj"]["component_name"])(self, k, param) - if cpn["obj"].component_name == "Categorize": - for _, desc in param.category_description.items(): - if desc["to"] not in cpn["downstream"]: - cpn["downstream"].append(desc["to"]) self.path = self.dsl["path"] - self.history = self.dsl["history"] - self.messages = self.dsl["messages"] - self.answer = self.dsl["answer"] - self.reference = self.dsl["reference"] - self._embed_id = self.dsl.get("embed_id", "") def __str__(self): self.dsl["path"] = self.path - self.dsl["history"] = self.history - self.dsl["messages"] = self.messages - self.dsl["answer"] = self.answer - self.dsl["reference"] = self.reference - self.dsl["embed_id"] = self._embed_id + self.dsl["task_id"] = self.task_id dsl = { "components": {} } @@ -152,170 +124,406 @@ def __str__(self): def reset(self): self.path = [] - self.history = [] - self.messages = [] - self.answer = [] - self.reference = [] for k, cpn in self.components.items(): self.components[k]["obj"].reset() - self._embed_id = "" + try: + REDIS_CONN.delete(f"{self.task_id}-logs") + REDIS_CONN.delete(f"{self.task_id}-cancel") + except Exception as e: + logging.exception(e) def get_component_name(self, cid): - for n in self.dsl["graph"]["nodes"]: + for n in self.dsl.get("graph", {}).get("nodes", []): if cid == n["id"]: return n["data"]["name"] return "" - def run(self, running_hint_text = "is running...🕞", **kwargs): - if not running_hint_text or not isinstance(running_hint_text, str): - running_hint_text = "is running...🕞" - bypass_begin = bool(kwargs.get("bypass_begin", False)) + def run(self, **kwargs): + raise NotImplementedError() - if self.answer: - cpn_id = self.answer[0] - self.answer.pop(0) - try: - ans = self.components[cpn_id]["obj"].run(self.history, **kwargs) - except Exception as e: - ans = ComponentBase.be_output(str(e)) - self.path[-1].append(cpn_id) - if kwargs.get("stream"): - for an in ans(): - yield an + def get_component(self, cpn_id) -> Union[None, dict[str, Any]]: + return self.components.get(cpn_id) + + def get_component_obj(self, cpn_id) -> ComponentBase: + return self.components.get(cpn_id)["obj"] + + def get_component_type(self, cpn_id) -> str: + return self.components.get(cpn_id)["obj"].component_name + + def get_component_input_form(self, cpn_id) -> dict: + return self.components.get(cpn_id)["obj"].get_input_form() + + def get_tenant_id(self): + return self._tenant_id + + def get_value_with_variable(self,value: str) -> Any: + pat = re.compile(r"\{* *\{([a-zA-Z:0-9]+@[A-Za-z0-9_.]+|sys\.[A-Za-z0-9_.]+|env\.[A-Za-z0-9_.]+)\} *\}*") + out_parts = [] + last = 0 + + for m in pat.finditer(value): + out_parts.append(value[last:m.start()]) + key = m.group(1) + v = self.get_variable_value(key) + if v is None: + rep = "" + elif isinstance(v, partial): + buf = [] + for chunk in v(): + buf.append(chunk) + rep = "".join(buf) + elif isinstance(v, str): + rep = v else: - yield ans - return + rep = json.dumps(v, ensure_ascii=False) + + out_parts.append(rep) + last = m.end() + + out_parts.append(value[last:]) + return("".join(out_parts)) + + def get_variable_value(self, exp: str) -> Any: + exp = exp.strip("{").strip("}").strip(" ").strip("{").strip("}") + if exp.find("@") < 0: + return self.globals[exp] + cpn_id, var_nm = exp.split("@") + cpn = self.get_component(cpn_id) + if not cpn: + raise Exception(f"Can't find variable: '{cpn_id}@{var_nm}'") + parts = var_nm.split(".", 1) + root_key = parts[0] + rest = parts[1] if len(parts) > 1 else "" + root_val = cpn["obj"].output(root_key) + + if not rest: + return root_val + return self.get_variable_param_value(root_val,rest) + + def get_variable_param_value(self, obj: Any, path: str) -> Any: + cur = obj + if not path: + return cur + for key in path.split('.'): + if cur is None: + return None + if isinstance(cur, str): + try: + cur = json.loads(cur) + except Exception: + return None + if isinstance(cur, dict): + cur = cur.get(key) + else: + cur = getattr(cur, key, None) + return cur - if not self.path: - self.components["begin"]["obj"].run(self.history, **kwargs) - self.path.append(["begin"]) - if bypass_begin: - cpn = self.get_component("begin") - downstream = cpn["downstream"] - self.path.append(downstream) + def is_canceled(self) -> bool: + return has_canceled(self.task_id) + def cancel_task(self) -> bool: + try: + REDIS_CONN.set(f"{self.task_id}-cancel", "x") + except Exception as e: + logging.exception(e) + return False + return True - self.path.append([]) +class Canvas(Graph): - ran = -1 - waiting = [] - without_dependent_checking = [] + def __init__(self, dsl: str, tenant_id=None, task_id=None): + self.globals = { + "sys.query": "", + "sys.user_id": tenant_id, + "sys.conversation_turns": 0, + "sys.files": [] + } + super().__init__(dsl, tenant_id, task_id) - def prepare2run(cpns): - nonlocal ran, ans - for c in cpns: - if self.path[-1] and c == self.path[-1][-1]: - continue - cpn = self.components[c]["obj"] - if cpn.component_name == "Answer": - self.answer.append(c) + def load(self): + super().load() + self.history = self.dsl["history"] + if "globals" in self.dsl: + self.globals = self.dsl["globals"] + else: + self.globals = { + "sys.query": "", + "sys.user_id": "", + "sys.conversation_turns": 0, + "sys.files": [] + } + + self.retrieval = self.dsl["retrieval"] + self.memory = self.dsl.get("memory", []) + + def __str__(self): + self.dsl["history"] = self.history + self.dsl["retrieval"] = self.retrieval + self.dsl["memory"] = self.memory + return super().__str__() + + def reset(self, mem=False): + super().reset() + if not mem: + self.history = [] + self.retrieval = [] + self.memory = [] + for k in self.globals.keys(): + if k.startswith("sys."): + if isinstance(self.globals[k], str): + self.globals[k] = "" + elif isinstance(self.globals[k], int): + self.globals[k] = 0 + elif isinstance(self.globals[k], float): + self.globals[k] = 0 + elif isinstance(self.globals[k], list): + self.globals[k] = [] + elif isinstance(self.globals[k], dict): + self.globals[k] = {} else: - logging.debug(f"Canvas.prepare2run: {c}") - if c not in without_dependent_checking: - cpids = cpn.get_dependent_components() - if any([cc not in self.path[-1] for cc in cpids]): - if c not in waiting: - waiting.append(c) - continue - yield "*'{}'* {}".format(self.get_component_name(c), running_hint_text) - - if cpn.component_name.lower() == "iteration": - st_cpn = cpn.get_start() - assert st_cpn, "Start component not found for Iteration." - if not st_cpn["obj"].end(): - cpn = st_cpn["obj"] - c = cpn._id - - try: - ans = cpn.run(self.history, **kwargs) - except Exception as e: - logging.exception(f"Canvas.run got exception: {e}") - self.path[-1].append(c) - ran += 1 - raise e - self.path[-1].append(c) - - ran += 1 - - downstream = self.components[self.path[-2][-1]]["downstream"] - if not downstream and self.components[self.path[-2][-1]].get("parent_id"): - cid = self.path[-2][-1] - pid = self.components[cid]["parent_id"] - o, _ = self.components[cid]["obj"].output(allow_partial=False) - oo, _ = self.components[pid]["obj"].output(allow_partial=False) - self.components[pid]["obj"].set_output(pd.concat([oo, o], ignore_index=True).dropna()) - downstream = [pid] - - for m in prepare2run(downstream): - yield {"content": m, "running_status": True} - - while 0 <= ran < len(self.path[-1]): - logging.debug(f"Canvas.run: {ran} {self.path}") - cpn_id = self.path[-1][ran] - cpn = self.get_component(cpn_id) - if not any([cpn["downstream"], cpn.get("parent_id"), waiting]): - break + self.globals[k] = None - loop = self._find_loop() - if loop: - raise OverflowError(f"Too much loops: {loop}") + def run(self, **kwargs): + st = time.perf_counter() + self.message_id = get_uuid() + created_at = int(time.time()) + self.add_user_input(kwargs.get("query")) + for k, cpn in self.components.items(): + self.components[k]["obj"].reset(True) - downstream = [] - if cpn["obj"].component_name.lower() in ["switch", "categorize", "relevant"]: - switch_out = cpn["obj"].output()[1].iloc[0, 0] - assert switch_out in self.components, \ - "{}'s output: {} not valid.".format(cpn_id, switch_out) - downstream = [switch_out] - else: - downstream = cpn["downstream"] - - if not downstream and cpn.get("parent_id"): - pid = cpn["parent_id"] - _, o = cpn["obj"].output(allow_partial=False) - _, oo = self.components[pid]["obj"].output(allow_partial=False) - self.components[pid]["obj"].set_output(pd.concat([oo.dropna(axis=1), o.dropna(axis=1)], ignore_index=True).dropna()) - downstream = [pid] - - for m in prepare2run(downstream): - yield {"content": m, "running_status": True} - - if ran >= len(self.path[-1]) and waiting: - without_dependent_checking = waiting - waiting = [] - for m in prepare2run(without_dependent_checking): - yield {"content": m, "running_status": True} - without_dependent_checking = [] - ran -= 1 - - if self.answer: - cpn_id = self.answer[0] - self.answer.pop(0) - ans = self.components[cpn_id]["obj"].run(self.history, **kwargs) - self.path[-1].append(cpn_id) - if kwargs.get("stream"): - assert isinstance(ans, partial) - for an in ans(): - yield an - else: - yield ans + if kwargs.get("webhook_payload"): + for k, cpn in self.components.items(): + if self.components[k]["obj"].component_name.lower() == "webhook": + for kk, vv in kwargs["webhook_payload"].items(): + self.components[k]["obj"].set_output(kk, vv) - else: - raise Exception("The dialog flow has no way to interact with you. Please add an 'Interact' component to the end of the flow.") + self.components[k]["obj"].reset(True) - def get_component(self, cpn_id): - return self.components[cpn_id] + for k in kwargs.keys(): + if k in ["query", "user_id", "files"] and kwargs[k]: + if k == "files": + self.globals[f"sys.{k}"] = self.get_files(kwargs[k]) + else: + self.globals[f"sys.{k}"] = kwargs[k] + if not self.globals["sys.conversation_turns"] : + self.globals["sys.conversation_turns"] = 0 + self.globals["sys.conversation_turns"] += 1 + + def decorate(event, dt): + nonlocal created_at + return { + "event": event, + #"conversation_id": "f3cc152b-24b0-4258-a1a1-7d5e9fc8a115", + "message_id": self.message_id, + "created_at": created_at, + "task_id": self.task_id, + "data": dt + } - def get_tenant_id(self): - return self._tenant_id + if not self.path or self.path[-1].lower().find("userfillup") < 0: + self.path.append("begin") + self.retrieval.append({"chunks": [], "doc_aggs": []}) + + if self.is_canceled(): + msg = f"Task {self.task_id} has been canceled before starting." + logging.info(msg) + raise TaskCanceledException(msg) + + yield decorate("workflow_started", {"inputs": kwargs.get("inputs")}) + self.retrieval.append({"chunks": {}, "doc_aggs": {}}) + + def _run_batch(f, t): + if self.is_canceled(): + msg = f"Task {self.task_id} has been canceled during batch execution." + logging.info(msg) + raise TaskCanceledException(msg) + + with ThreadPoolExecutor(max_workers=5) as executor: + thr = [] + i = f + while i < t: + cpn = self.get_component_obj(self.path[i]) + if cpn.component_name.lower() in ["begin", "userfillup"]: + thr.append(executor.submit(cpn.invoke, inputs=kwargs.get("inputs", {}))) + i += 1 + else: + for _, ele in cpn.get_input_elements().items(): + if isinstance(ele, dict) and ele.get("_cpn_id") and ele.get("_cpn_id") not in self.path[:i] and self.path[0].lower().find("userfillup") < 0: + self.path.pop(i) + t -= 1 + break + else: + thr.append(executor.submit(cpn.invoke, **cpn.get_input())) + i += 1 + for t in thr: + t.result() + + def _node_finished(cpn_obj): + return decorate("node_finished",{ + "inputs": cpn_obj.get_input_values(), + "outputs": cpn_obj.output(), + "component_id": cpn_obj._id, + "component_name": self.get_component_name(cpn_obj._id), + "component_type": self.get_component_type(cpn_obj._id), + "error": cpn_obj.error(), + "elapsed_time": time.perf_counter() - cpn_obj.output("_created_time"), + "created_at": cpn_obj.output("_created_time"), + }) + + self.error = "" + idx = len(self.path) - 1 + partials = [] + while idx < len(self.path): + to = len(self.path) + for i in range(idx, to): + yield decorate("node_started", { + "inputs": None, "created_at": int(time.time()), + "component_id": self.path[i], + "component_name": self.get_component_name(self.path[i]), + "component_type": self.get_component_type(self.path[i]), + "thoughts": self.get_component_thoughts(self.path[i]) + }) + _run_batch(idx, to) + to = len(self.path) + # post processing of components invocation + for i in range(idx, to): + cpn = self.get_component(self.path[i]) + cpn_obj = self.get_component_obj(self.path[i]) + if cpn_obj.component_name.lower() == "message": + if isinstance(cpn_obj.output("content"), partial): + _m = "" + for m in cpn_obj.output("content")(): + if not m: + continue + if m == "": + yield decorate("message", {"content": "", "start_to_think": True}) + elif m == "": + yield decorate("message", {"content": "", "end_to_think": True}) + else: + yield decorate("message", {"content": m}) + _m += m + cpn_obj.set_output("content", _m) + cite = re.search(r"\[ID:[ 0-9]+\]", _m) + else: + yield decorate("message", {"content": cpn_obj.output("content")}) + cite = re.search(r"\[ID:[ 0-9]+\]", cpn_obj.output("content")) + yield decorate("message_end", {"reference": self.get_reference() if cite else None}) + + while partials: + _cpn_obj = self.get_component_obj(partials[0]) + if isinstance(_cpn_obj.output("content"), partial): + break + yield _node_finished(_cpn_obj) + partials.pop(0) + + other_branch = False + if cpn_obj.error(): + ex = cpn_obj.exception_handler() + if ex and ex["goto"]: + self.path.extend(ex["goto"]) + other_branch = True + elif ex and ex["default_value"]: + yield decorate("message", {"content": ex["default_value"]}) + yield decorate("message_end", {}) + else: + self.error = cpn_obj.error() + + if cpn_obj.component_name.lower() != "iteration": + if isinstance(cpn_obj.output("content"), partial): + if self.error: + cpn_obj.set_output("content", None) + yield _node_finished(cpn_obj) + else: + partials.append(self.path[i]) + else: + yield _node_finished(cpn_obj) + + def _append_path(cpn_id): + nonlocal other_branch + if other_branch: + return + if self.path[-1] == cpn_id: + return + self.path.append(cpn_id) + + def _extend_path(cpn_ids): + nonlocal other_branch + if other_branch: + return + for cpn_id in cpn_ids: + _append_path(cpn_id) + + if cpn_obj.component_name.lower() == "iterationitem" and cpn_obj.end(): + iter = cpn_obj.get_parent() + yield _node_finished(iter) + _extend_path(self.get_component(cpn["parent_id"])["downstream"]) + elif cpn_obj.component_name.lower() in ["categorize", "switch"]: + _extend_path(cpn_obj.output("_next")) + elif cpn_obj.component_name.lower() == "iteration": + _append_path(cpn_obj.get_start()) + elif not cpn["downstream"] and cpn_obj.get_parent(): + _append_path(cpn_obj.get_parent().get_start()) + else: + _extend_path(cpn["downstream"]) + + if self.error: + logging.error(f"Runtime Error: {self.error}") + break + idx = to + + if any([self.get_component_obj(c).component_name.lower() == "userfillup" for c in self.path[idx:]]): + path = [c for c in self.path[idx:] if self.get_component(c)["obj"].component_name.lower() == "userfillup"] + path.extend([c for c in self.path[idx:] if self.get_component(c)["obj"].component_name.lower() != "userfillup"]) + another_inputs = {} + tips = "" + for c in path: + o = self.get_component_obj(c) + if o.component_name.lower() == "userfillup": + o.invoke() + another_inputs.update(o.get_input_elements()) + if o.get_param("enable_tips"): + tips = o.output("tips") + self.path = path + yield decorate("user_inputs", {"inputs": another_inputs, "tips": tips}) + return + self.path = self.path[:idx] + if not self.error: + yield decorate("workflow_finished", + { + "inputs": kwargs.get("inputs"), + "outputs": self.get_component_obj(self.path[-1]).output(), + "elapsed_time": time.perf_counter() - st, + "created_at": st, + }) + self.history.append(("assistant", self.get_component_obj(self.path[-1]).output())) + elif "Task has been canceled" in self.error: + yield decorate("workflow_finished", + { + "inputs": kwargs.get("inputs"), + "outputs": "Task has been canceled", + "elapsed_time": time.perf_counter() - st, + "created_at": st, + }) + + def is_reff(self, exp: str) -> bool: + exp = exp.strip("{").strip("}") + if exp.find("@") < 0: + return exp in self.globals + arr = exp.split("@") + if len(arr) != 2: + return False + if self.get_component(arr[0]) is None: + return False + return True def get_history(self, window_size): convs = [] if window_size <= 0: return convs - for role, obj in self.history[window_size * -1:]: - if isinstance(obj, list) and obj and all([isinstance(o, dict) for o in obj]): - convs.append({"role": role, "content": '\n'.join([str(s.get("content", "")) for s in obj])}) + for role, obj in self.history[window_size * -2:]: + if isinstance(obj, dict): + convs.append({"role": role, "content": obj.get("content", "")}) else: convs.append({"role": role, "content": str(obj)}) return convs @@ -323,57 +531,86 @@ def get_history(self, window_size): def add_user_input(self, question): self.history.append(("user", question)) - def set_embedding_model(self, embed_id): - self._embed_id = embed_id - - def get_embedding_model(self): - return self._embed_id - - def _find_loop(self, max_loops=6): - path = self.path[-1][::-1] - if len(path) < 2: - return False - - for i in range(len(path)): - if path[i].lower().find("answer") == 0 or path[i].lower().find("iterationitem") == 0: - path = path[:i] - break - - if len(path) < 2: - return False - - for loc in range(2, len(path) // 2): - pat = ",".join(path[0:loc]) - path_str = ",".join(path) - if len(pat) >= len(path_str): - return False - loop = max_loops - while path_str.find(pat) == 0 and loop >= 0: - loop -= 1 - if len(pat)+1 >= len(path_str): - return False - path_str = path_str[len(pat)+1:] - if loop < 0: - pat = " => ".join([p.split(":")[0] for p in path[0:loc]]) - return pat + " => " + pat - - return False - def get_prologue(self): return self.components["begin"]["obj"]._param.prologue + def get_mode(self): + return self.components["begin"]["obj"]._param.mode + def set_global_param(self, **kwargs): - for k, v in kwargs.items(): - for q in self.components["begin"]["obj"]._param.query: - if k != q["key"]: - continue - q["value"] = v + self.globals.update(kwargs) def get_preset_param(self): - return self.components["begin"]["obj"]._param.query + return self.components["begin"]["obj"]._param.inputs def get_component_input_elements(self, cpnnm): return self.components[cpnnm]["obj"].get_input_elements() - - def set_component_infor(self, cpn_id, infor): - self.components[cpn_id]["obj"].set_infor(infor) + + def get_files(self, files: Union[None, list[dict]]) -> list[str]: + if not files: + return [] + def image_to_base64(file): + return "data:{};base64,{}".format(file["mime_type"], + base64.b64encode(FileService.get_blob(file["created_by"], file["id"])).decode("utf-8")) + exe = ThreadPoolExecutor(max_workers=5) + threads = [] + for file in files: + if file["mime_type"].find("image") >=0: + threads.append(exe.submit(image_to_base64, file)) + continue + threads.append(exe.submit(FileService.parse, file["name"], FileService.get_blob(file["created_by"], file["id"]), True, file["created_by"])) + return [th.result() for th in threads] + + def tool_use_callback(self, agent_id: str, func_name: str, params: dict, result: Any, elapsed_time=None): + agent_ids = agent_id.split("-->") + agent_name = self.get_component_name(agent_ids[0]) + path = agent_name if len(agent_ids) < 2 else agent_name+"-->"+"-->".join(agent_ids[1:]) + try: + bin = REDIS_CONN.get(f"{self.task_id}-{self.message_id}-logs") + if bin: + obj = json.loads(bin.encode("utf-8")) + if obj[-1]["component_id"] == agent_ids[0]: + obj[-1]["trace"].append({"path": path, "tool_name": func_name, "arguments": params, "result": result, "elapsed_time": elapsed_time}) + else: + obj.append({ + "component_id": agent_ids[0], + "trace": [{"path": path, "tool_name": func_name, "arguments": params, "result": result, "elapsed_time": elapsed_time}] + }) + else: + obj = [{ + "component_id": agent_ids[0], + "trace": [{"path": path, "tool_name": func_name, "arguments": params, "result": result, "elapsed_time": elapsed_time}] + }] + REDIS_CONN.set_obj(f"{self.task_id}-{self.message_id}-logs", obj, 60*10) + except Exception as e: + logging.exception(e) + + def add_reference(self, chunks: list[object], doc_infos: list[object]): + if not self.retrieval: + self.retrieval = [{"chunks": {}, "doc_aggs": {}}] + + r = self.retrieval[-1] + for ck in chunks_format({"chunks": chunks}): + cid = hash_str2int(ck["id"], 500) + # cid = uuid.uuid5(uuid.NAMESPACE_DNS, ck["id"]) + if cid not in r: + r["chunks"][cid] = ck + + for doc in doc_infos: + if doc["doc_name"] not in r: + r["doc_aggs"][doc["doc_name"]] = doc + + def get_reference(self): + if not self.retrieval: + return {"chunks": {}, "doc_aggs": {}} + return self.retrieval[-1] + + def add_memory(self, user:str, assist:str, summ: str): + self.memory.append((user, assist, summ)) + + def get_memory(self) -> list[Tuple]: + return self.memory + + def get_component_thoughts(self, cpn_id) -> str: + return self.components.get(cpn_id)["obj"].thoughts() + diff --git a/agent/component/__init__.py b/agent/component/__init__.py index b4681ac51fb..d4a481518ba 100644 --- a/agent/component/__init__.py +++ b/agent/component/__init__.py @@ -13,124 +13,46 @@ # See the License for the specific language governing permissions and # limitations under the License. # - +import os import importlib -from .begin import Begin, BeginParam -from .generate import Generate, GenerateParam -from .retrieval import Retrieval, RetrievalParam -from .answer import Answer, AnswerParam -from .categorize import Categorize, CategorizeParam -from .switch import Switch, SwitchParam -from .relevant import Relevant, RelevantParam -from .message import Message, MessageParam -from .rewrite import RewriteQuestion, RewriteQuestionParam -from .keyword import KeywordExtract, KeywordExtractParam -from .concentrator import Concentrator, ConcentratorParam -from .baidu import Baidu, BaiduParam -from .duckduckgo import DuckDuckGo, DuckDuckGoParam -from .wikipedia import Wikipedia, WikipediaParam -from .pubmed import PubMed, PubMedParam -from .arxiv import ArXiv, ArXivParam -from .google import Google, GoogleParam -from .bing import Bing, BingParam -from .googlescholar import GoogleScholar, GoogleScholarParam -from .deepl import DeepL, DeepLParam -from .github import GitHub, GitHubParam -from .baidufanyi import BaiduFanyi, BaiduFanyiParam -from .qweather import QWeather, QWeatherParam -from .exesql import ExeSQL, ExeSQLParam -from .yahoofinance import YahooFinance, YahooFinanceParam -from .wencai import WenCai, WenCaiParam -from .jin10 import Jin10, Jin10Param -from .tushare import TuShare, TuShareParam -from .akshare import AkShare, AkShareParam -from .crawler import Crawler, CrawlerParam -from .invoke import Invoke, InvokeParam -from .template import Template, TemplateParam -from .email import Email, EmailParam -from .iteration import Iteration, IterationParam -from .iterationitem import IterationItem, IterationItemParam -from .code import Code, CodeParam +import inspect +from types import ModuleType +from typing import Dict, Type +_package_path = os.path.dirname(__file__) +__all_classes: Dict[str, Type] = {} -def component_class(class_name): - m = importlib.import_module("agent.component") - c = getattr(m, class_name) - return c +def _import_submodules() -> None: + for filename in os.listdir(_package_path): # noqa: F821 + if filename.startswith("__") or not filename.endswith(".py") or filename.startswith("base"): + continue + module_name = filename[:-3] + + try: + module = importlib.import_module(f".{module_name}", package=__name__) + _extract_classes_from_module(module) # noqa: F821 + except ImportError as e: + print(f"Warning: Failed to import module {module_name}: {str(e)}") + +def _extract_classes_from_module(module: ModuleType) -> None: + for name, obj in inspect.getmembers(module): + if (inspect.isclass(obj) and + obj.__module__ == module.__name__ and not name.startswith("_")): + __all_classes[name] = obj + globals()[name] = obj +_import_submodules() -__all__ = [ - "Begin", - "BeginParam", - "Generate", - "GenerateParam", - "Retrieval", - "RetrievalParam", - "Answer", - "AnswerParam", - "Categorize", - "CategorizeParam", - "Switch", - "SwitchParam", - "Relevant", - "RelevantParam", - "Message", - "MessageParam", - "RewriteQuestion", - "RewriteQuestionParam", - "KeywordExtract", - "KeywordExtractParam", - "Concentrator", - "ConcentratorParam", - "Baidu", - "BaiduParam", - "DuckDuckGo", - "DuckDuckGoParam", - "Wikipedia", - "WikipediaParam", - "PubMed", - "PubMedParam", - "ArXiv", - "ArXivParam", - "Google", - "GoogleParam", - "Bing", - "BingParam", - "GoogleScholar", - "GoogleScholarParam", - "DeepL", - "DeepLParam", - "GitHub", - "GitHubParam", - "BaiduFanyi", - "BaiduFanyiParam", - "QWeather", - "QWeatherParam", - "ExeSQL", - "ExeSQLParam", - "YahooFinance", - "YahooFinanceParam", - "WenCai", - "WenCaiParam", - "Jin10", - "Jin10Param", - "TuShare", - "TuShareParam", - "AkShare", - "AkShareParam", - "Crawler", - "CrawlerParam", - "Invoke", - "InvokeParam", - "Iteration", - "IterationParam", - "IterationItem", - "IterationItemParam", - "Template", - "TemplateParam", - "Email", - "EmailParam", - "Code", - "CodeParam", - "component_class" -] +__all__ = list(__all_classes.keys()) + ["__all_classes"] + +del _package_path, _import_submodules, _extract_classes_from_module + + +def component_class(class_name): + for module_name in ["agent.component", "agent.tools", "rag.flow"]: + try: + return getattr(importlib.import_module(module_name), class_name) + except Exception: + # logging.warning(f"Can't import module: {module_name}, error: {e}") + pass + assert False, f"Can't import {class_name}" diff --git a/agent/component/agent_with_tools.py b/agent/component/agent_with_tools.py new file mode 100644 index 00000000000..98dfbc92fe8 --- /dev/null +++ b/agent/component/agent_with_tools.py @@ -0,0 +1,378 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import re +from concurrent.futures import ThreadPoolExecutor +from copy import deepcopy +from functools import partial +from typing import Any + +import json_repair +from timeit import default_timer as timer +from agent.tools.base import LLMToolPluginCallSession, ToolParamBase, ToolBase, ToolMeta +from api.db.services.llm_service import LLMBundle +from api.db.services.tenant_llm_service import TenantLLMService +from api.db.services.mcp_server_service import MCPServerService +from common.connection_utils import timeout +from rag.prompts.generator import next_step, COMPLETE_TASK, analyze_task, \ + citation_prompt, reflect, rank_memories, kb_prompt, citation_plus, full_question, message_fit_in +from rag.utils.mcp_tool_call_conn import MCPToolCallSession, mcp_tool_metadata_to_openai_tool +from agent.component.llm import LLMParam, LLM + + +class AgentParam(LLMParam, ToolParamBase): + """ + Define the Agent component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "agent", + "description": "This is an agent for a specific task.", + "parameters": { + "user_prompt": { + "type": "string", + "description": "This is the order you need to send to the agent.", + "default": "", + "required": True + }, + "reasoning": { + "type": "string", + "description": ( + "Supervisor's reasoning for choosing the this agent. " + "Explain why this agent is being invoked and what is expected of it." + ), + "required": True + }, + "context": { + "type": "string", + "description": ( + "All relevant background information, prior facts, decisions, " + "and state needed by the agent to solve the current query. " + "Should be as detailed and self-contained as possible." + ), + "required": True + }, + } + } + super().__init__() + self.function_name = "agent" + self.tools = [] + self.mcp = [] + self.max_rounds = 5 + self.description = "" + + +class Agent(LLM, ToolBase): + component_name = "Agent" + + def __init__(self, canvas, id, param: LLMParam): + LLM.__init__(self, canvas, id, param) + self.tools = {} + for cpn in self._param.tools: + cpn = self._load_tool_obj(cpn) + self.tools[cpn.get_meta()["function"]["name"]] = cpn + + self.chat_mdl = LLMBundle(self._canvas.get_tenant_id(), TenantLLMService.llm_id2llm_type(self._param.llm_id), self._param.llm_id, + max_retries=self._param.max_retries, + retry_interval=self._param.delay_after_error, + max_rounds=self._param.max_rounds, + verbose_tool_use=True + ) + self.tool_meta = [v.get_meta() for _,v in self.tools.items()] + + for mcp in self._param.mcp: + _, mcp_server = MCPServerService.get_by_id(mcp["mcp_id"]) + tool_call_session = MCPToolCallSession(mcp_server, mcp_server.variables) + for tnm, meta in mcp["tools"].items(): + self.tool_meta.append(mcp_tool_metadata_to_openai_tool(meta)) + self.tools[tnm] = tool_call_session + self.callback = partial(self._canvas.tool_use_callback, id) + self.toolcall_session = LLMToolPluginCallSession(self.tools, self.callback) + #self.chat_mdl.bind_tools(self.toolcall_session, self.tool_metas) + + def _load_tool_obj(self, cpn: dict) -> object: + from agent.component import component_class + param = component_class(cpn["component_name"] + "Param")() + param.update(cpn["params"]) + try: + param.check() + except Exception as e: + self.set_output("_ERROR", cpn["component_name"] + f" configuration error: {e}") + raise + cpn_id = f"{self._id}-->" + cpn.get("name", "").replace(" ", "_") + return component_class(cpn["component_name"])(self._canvas, cpn_id, param) + + def get_meta(self) -> dict[str, Any]: + self._param.function_name= self._id.split("-->")[-1] + m = super().get_meta() + if hasattr(self._param, "user_prompt") and self._param.user_prompt: + m["function"]["parameters"]["properties"]["user_prompt"] = self._param.user_prompt + return m + + def get_input_form(self) -> dict[str, dict]: + res = {} + for k, v in self.get_input_elements().items(): + res[k] = { + "type": "line", + "name": v["name"] + } + for cpn in self._param.tools: + if not isinstance(cpn, LLM): + continue + res.update(cpn.get_input_form()) + return res + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 20*60))) + def _invoke(self, **kwargs): + if self.check_if_canceled("Agent processing"): + return + + if kwargs.get("user_prompt"): + usr_pmt = "" + if kwargs.get("reasoning"): + usr_pmt += "\nREASONING:\n{}\n".format(kwargs["reasoning"]) + if kwargs.get("context"): + usr_pmt += "\nCONTEXT:\n{}\n".format(kwargs["context"]) + if usr_pmt: + usr_pmt += "\nQUERY:\n{}\n".format(str(kwargs["user_prompt"])) + else: + usr_pmt = str(kwargs["user_prompt"]) + self._param.prompts = [{"role": "user", "content": usr_pmt}] + + if not self.tools: + if self.check_if_canceled("Agent processing"): + return + return LLM._invoke(self, **kwargs) + + prompt, msg, user_defined_prompt = self._prepare_prompt_variables() + + downstreams = self._canvas.get_component(self._id)["downstream"] if self._canvas.get_component(self._id) else [] + ex = self.exception_handler() + output_structure=None + try: + output_structure=self._param.outputs['structured'] + except Exception: + pass + if any([self._canvas.get_component_obj(cid).component_name.lower()=="message" for cid in downstreams]) and not output_structure and not (ex and ex["goto"]): + self.set_output("content", partial(self.stream_output_with_tools, prompt, msg, user_defined_prompt)) + return + + _, msg = message_fit_in([{"role": "system", "content": prompt}, *msg], int(self.chat_mdl.max_length * 0.97)) + use_tools = [] + ans = "" + for delta_ans, tk in self._react_with_tools_streamly(prompt, msg, use_tools, user_defined_prompt): + if self.check_if_canceled("Agent processing"): + return + ans += delta_ans + + if ans.find("**ERROR**") >= 0: + logging.error(f"Agent._chat got error. response: {ans}") + if self.get_exception_default_value(): + self.set_output("content", self.get_exception_default_value()) + else: + self.set_output("_ERROR", ans) + return + + self.set_output("content", ans) + if use_tools: + self.set_output("use_tools", use_tools) + return ans + + def stream_output_with_tools(self, prompt, msg, user_defined_prompt={}): + _, msg = message_fit_in([{"role": "system", "content": prompt}, *msg], int(self.chat_mdl.max_length * 0.97)) + answer_without_toolcall = "" + use_tools = [] + for delta_ans,_ in self._react_with_tools_streamly(prompt, msg, use_tools, user_defined_prompt): + if self.check_if_canceled("Agent streaming"): + return + + if delta_ans.find("**ERROR**") >= 0: + if self.get_exception_default_value(): + self.set_output("content", self.get_exception_default_value()) + yield self.get_exception_default_value() + else: + self.set_output("_ERROR", delta_ans) + return + answer_without_toolcall += delta_ans + yield delta_ans + + self.set_output("content", answer_without_toolcall) + if use_tools: + self.set_output("use_tools", use_tools) + + def _gen_citations(self, text): + retrievals = self._canvas.get_reference() + retrievals = {"chunks": list(retrievals["chunks"].values()), "doc_aggs": list(retrievals["doc_aggs"].values())} + formated_refer = kb_prompt(retrievals, self.chat_mdl.max_length, True) + for delta_ans in self._generate_streamly([{"role": "system", "content": citation_plus("\n\n".join(formated_refer))}, + {"role": "user", "content": text} + ]): + yield delta_ans + + def _react_with_tools_streamly(self, prompt, history: list[dict], use_tools, user_defined_prompt={}): + token_count = 0 + tool_metas = self.tool_meta + hist = deepcopy(history) + last_calling = "" + if len(hist) > 3: + st = timer() + user_request = full_question(messages=history, chat_mdl=self.chat_mdl) + self.callback("Multi-turn conversation optimization", {}, user_request, elapsed_time=timer()-st) + else: + user_request = history[-1]["content"] + + def use_tool(name, args): + nonlocal hist, use_tools, token_count,last_calling,user_request + logging.info(f"{last_calling=} == {name=}") + # Summarize of function calling + #if all([ + # isinstance(self.toolcall_session.get_tool_obj(name), Agent), + # last_calling, + # last_calling != name + #]): + # self.toolcall_session.get_tool_obj(name).add2system_prompt(f"The chat history with other agents are as following: \n" + self.get_useful_memory(user_request, str(args["user_prompt"]),user_defined_prompt)) + last_calling = name + tool_response = self.toolcall_session.tool_call(name, args) + use_tools.append({ + "name": name, + "arguments": args, + "results": tool_response + }) + # self.callback("add_memory", {}, "...") + #self.add_memory(hist[-2]["content"], hist[-1]["content"], name, args, str(tool_response), user_defined_prompt) + + return name, tool_response + + def complete(): + nonlocal hist + need2cite = self._param.cite and self._canvas.get_reference()["chunks"] and self._id.find("-->") < 0 + cited = False + if hist[0]["role"] == "system" and need2cite: + if len(hist) < 7: + hist[0]["content"] += citation_prompt() + cited = True + yield "", token_count + + _hist = hist + if len(hist) > 12: + _hist = [hist[0], hist[1], *hist[-10:]] + entire_txt = "" + for delta_ans in self._generate_streamly(_hist): + if not need2cite or cited: + yield delta_ans, 0 + entire_txt += delta_ans + if not need2cite or cited: + return + + st = timer() + txt = "" + for delta_ans in self._gen_citations(entire_txt): + if self.check_if_canceled("Agent streaming"): + return + yield delta_ans, 0 + txt += delta_ans + + self.callback("gen_citations", {}, txt, elapsed_time=timer()-st) + + def append_user_content(hist, content): + if hist[-1]["role"] == "user": + hist[-1]["content"] += content + else: + hist.append({"role": "user", "content": content}) + + st = timer() + task_desc = analyze_task(self.chat_mdl, prompt, user_request, tool_metas, user_defined_prompt) + self.callback("analyze_task", {}, task_desc, elapsed_time=timer()-st) + for _ in range(self._param.max_rounds + 1): + if self.check_if_canceled("Agent streaming"): + return + response, tk = next_step(self.chat_mdl, hist, tool_metas, task_desc, user_defined_prompt) + # self.callback("next_step", {}, str(response)[:256]+"...") + token_count += tk + hist.append({"role": "assistant", "content": response}) + try: + functions = json_repair.loads(re.sub(r"```.*", "", response)) + if not isinstance(functions, list): + raise TypeError(f"List should be returned, but `{functions}`") + for f in functions: + if not isinstance(f, dict): + raise TypeError(f"An object type should be returned, but `{f}`") + with ThreadPoolExecutor(max_workers=5) as executor: + thr = [] + for func in functions: + name = func["name"] + args = func["arguments"] + if name == COMPLETE_TASK: + append_user_content(hist, f"Respond with a formal answer. FORGET(DO NOT mention) about `{COMPLETE_TASK}`. The language for the response MUST be as the same as the first user request.\n") + for txt, tkcnt in complete(): + yield txt, tkcnt + return + + thr.append(executor.submit(use_tool, name, args)) + + st = timer() + reflection = reflect(self.chat_mdl, hist, [th.result() for th in thr], user_defined_prompt) + append_user_content(hist, reflection) + self.callback("reflection", {}, str(reflection), elapsed_time=timer()-st) + + except Exception as e: + logging.exception(msg=f"Wrong JSON argument format in LLM ReAct response: {e}") + e = f"\nTool call error, please correct the input parameter of response format and call it again.\n *** Exception ***\n{e}" + append_user_content(hist, str(e)) + + logging.warning( f"Exceed max rounds: {self._param.max_rounds}") + final_instruction = f""" +{user_request} +IMPORTANT: You have reached the conversation limit. Based on ALL the information and research you have gathered so far, please provide a DIRECT and COMPREHENSIVE final answer to the original request. +Instructions: +1. SYNTHESIZE all information collected during this conversation +2. Provide a COMPLETE response using existing data - do not suggest additional research +3. Structure your response as a FINAL DELIVERABLE, not a plan +4. If information is incomplete, state what you found and provide the best analysis possible with available data +5. DO NOT mention conversation limits or suggest further steps +6. Focus on delivering VALUE with the information already gathered +Respond immediately with your final comprehensive answer. + """ + if self.check_if_canceled("Agent final instruction"): + return + append_user_content(hist, final_instruction) + + for txt, tkcnt in complete(): + yield txt, tkcnt + + def get_useful_memory(self, goal: str, sub_goal:str, topn=3, user_defined_prompt:dict={}) -> str: + # self.callback("get_useful_memory", {"topn": 3}, "...") + mems = self._canvas.get_memory() + rank = rank_memories(self.chat_mdl, goal, sub_goal, [summ for (user, assist, summ) in mems], user_defined_prompt) + try: + rank = json_repair.loads(re.sub(r"```.*", "", rank))[:topn] + mems = [mems[r] for r in rank] + return "\n\n".join([f"User: {u}\nAgent: {a}" for u, a,_ in mems]) + except Exception as e: + logging.exception(e) + + return "Error occurred." + + def reset(self, temp=False): + """ + Reset all tools if they have a reset method. This avoids errors for tools like MCPToolCallSession. + """ + for k, cpn in self.tools.items(): + if hasattr(cpn, "reset") and callable(cpn.reset): + cpn.reset() + diff --git a/agent/component/answer.py b/agent/component/answer.py deleted file mode 100644 index c8c3439c00b..00000000000 --- a/agent/component/answer.py +++ /dev/null @@ -1,92 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import random -from abc import ABC -from functools import partial -from typing import Tuple, Union - -import pandas as pd - -from agent.component.base import ComponentBase, ComponentParamBase - - -class AnswerParam(ComponentParamBase): - - """ - Define the Answer component parameters. - """ - def __init__(self): - super().__init__() - self.post_answers = [] - - def check(self): - return True - - -class Answer(ComponentBase, ABC): - component_name = "Answer" - - def _run(self, history, **kwargs): - if kwargs.get("stream"): - return partial(self.stream_output) - - ans = self.get_input() - if self._param.post_answers: - ans = pd.concat([ans, pd.DataFrame([{"content": random.choice(self._param.post_answers)}])], ignore_index=False) - return ans - - def stream_output(self): - res = None - if hasattr(self, "exception") and self.exception: - res = {"content": str(self.exception)} - self.exception = None - yield res - self.set_output(res) - return - - stream = self.get_stream_input() - if isinstance(stream, pd.DataFrame): - res = stream - answer = "" - for ii, row in stream.iterrows(): - answer += row.to_dict()["content"] - yield {"content": answer} - elif stream is not None: - for st in stream(): - res = st - yield st - if self._param.post_answers and res: - res["content"] += random.choice(self._param.post_answers) - yield res - - if res is None: - res = {"content": ""} - - self.set_output(res) - - def set_exception(self, e): - self.exception = e - - def output(self, allow_partial=True) -> Tuple[str, Union[pd.DataFrame, partial]]: - if allow_partial: - return super.output() - - for r, c in self._canvas.history[::-1]: - if r == "user": - return self._param.output_var_name, pd.DataFrame([{"content": c}]) - - self._param.output_var_name, pd.DataFrame([]) - diff --git a/agent/component/arxiv.py b/agent/component/arxiv.py deleted file mode 100644 index a7df3385cec..00000000000 --- a/agent/component/arxiv.py +++ /dev/null @@ -1,68 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -from abc import ABC -import arxiv -import pandas as pd -from agent.component.base import ComponentBase, ComponentParamBase - -class ArXivParam(ComponentParamBase): - """ - Define the ArXiv component parameters. - """ - - def __init__(self): - super().__init__() - self.top_n = 6 - self.sort_by = 'submittedDate' - - def check(self): - self.check_positive_integer(self.top_n, "Top N") - self.check_valid_value(self.sort_by, "ArXiv Search Sort_by", - ['submittedDate', 'lastUpdatedDate', 'relevance']) - - -class ArXiv(ComponentBase, ABC): - component_name = "ArXiv" - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = " - ".join(ans["content"]) if "content" in ans else "" - if not ans: - return ArXiv.be_output("") - - try: - sort_choices = {"relevance": arxiv.SortCriterion.Relevance, - "lastUpdatedDate": arxiv.SortCriterion.LastUpdatedDate, - 'submittedDate': arxiv.SortCriterion.SubmittedDate} - arxiv_client = arxiv.Client() - search = arxiv.Search( - query=ans, - max_results=self._param.top_n, - sort_by=sort_choices[self._param.sort_by] - ) - arxiv_res = [ - {"content": 'Title: ' + i.title + '\nPdf_Url: \nSummary: ' + i.summary} for - i in list(arxiv_client.results(search))] - except Exception as e: - return ArXiv.be_output("**ERROR**: " + str(e)) - - if not arxiv_res: - return ArXiv.be_output("") - - df = pd.DataFrame(arxiv_res) - logging.debug(f"df: {str(df)}") - return df diff --git a/agent/component/baidu.py b/agent/component/baidu.py deleted file mode 100644 index b75faa4a031..00000000000 --- a/agent/component/baidu.py +++ /dev/null @@ -1,79 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -from abc import ABC -import pandas as pd -import requests -from bs4 import BeautifulSoup -import re -from agent.component.base import ComponentBase, ComponentParamBase - - -class BaiduParam(ComponentParamBase): - """ - Define the Baidu component parameters. - """ - - def __init__(self): - super().__init__() - self.top_n = 10 - - def check(self): - self.check_positive_integer(self.top_n, "Top N") - - -class Baidu(ComponentBase, ABC): - component_name = "Baidu" - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = " - ".join(ans["content"]) if "content" in ans else "" - if not ans: - return Baidu.be_output("") - - try: - url = 'https://www.baidu.com/s?wd=' + ans + '&rn=' + str(self._param.top_n) - headers = { - 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', - 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', - 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', - 'Connection': 'keep-alive', - } - response = requests.get(url=url, headers=headers) - # check if request success - if response.status_code == 200: - soup = BeautifulSoup(response.text, 'html.parser') - url_res = [] - title_res = [] - body_res = [] - for item in soup.select('.result.c-container'): - # extract title - title_res.append(item.select_one('h3 a').get_text(strip=True)) - url_res.append(item.select_one('h3 a')['href']) - body_res.append(item.select_one('.c-abstract').get_text(strip=True) if item.select_one('.c-abstract') else '') - baidu_res = [{"content": re.sub('|', '', '' + title + ' ' + body)} for - url, title, body in zip(url_res, title_res, body_res)] - del body_res, url_res, title_res - except Exception as e: - return Baidu.be_output("**ERROR**: " + str(e)) - - if not baidu_res: - return Baidu.be_output("") - - df = pd.DataFrame(baidu_res) - logging.debug(f"df: {str(df)}") - return df - diff --git a/agent/component/baidufanyi.py b/agent/component/baidufanyi.py deleted file mode 100644 index f6eada60569..00000000000 --- a/agent/component/baidufanyi.py +++ /dev/null @@ -1,96 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import random -from abc import ABC -import requests -from agent.component.base import ComponentBase, ComponentParamBase -from hashlib import md5 - - -class BaiduFanyiParam(ComponentParamBase): - """ - Define the BaiduFanyi component parameters. - """ - - def __init__(self): - super().__init__() - self.appid = "xxx" - self.secret_key = "xxx" - self.trans_type = 'translate' - self.parameters = [] - self.source_lang = 'auto' - self.target_lang = 'auto' - self.domain = 'finance' - - def check(self): - self.check_empty(self.appid, "BaiduFanyi APPID") - self.check_empty(self.secret_key, "BaiduFanyi Secret Key") - self.check_valid_value(self.trans_type, "Translate type", ['translate', 'fieldtranslate']) - self.check_valid_value(self.source_lang, "Source language", - ['auto', 'zh', 'en', 'yue', 'wyw', 'jp', 'kor', 'fra', 'spa', 'th', 'ara', 'ru', 'pt', - 'de', 'it', 'el', 'nl', 'pl', 'bul', 'est', 'dan', 'fin', 'cs', 'rom', 'slo', 'swe', - 'hu', 'cht', 'vie']) - self.check_valid_value(self.target_lang, "Target language", - ['auto', 'zh', 'en', 'yue', 'wyw', 'jp', 'kor', 'fra', 'spa', 'th', 'ara', 'ru', 'pt', - 'de', 'it', 'el', 'nl', 'pl', 'bul', 'est', 'dan', 'fin', 'cs', 'rom', 'slo', 'swe', - 'hu', 'cht', 'vie']) - self.check_valid_value(self.domain, "Translate field", - ['it', 'finance', 'machinery', 'senimed', 'novel', 'academic', 'aerospace', 'wiki', - 'news', 'law', 'contract']) - - -class BaiduFanyi(ComponentBase, ABC): - component_name = "BaiduFanyi" - - def _run(self, history, **kwargs): - - ans = self.get_input() - ans = " - ".join(ans["content"]) if "content" in ans else "" - if not ans: - return BaiduFanyi.be_output("") - - try: - source_lang = self._param.source_lang - target_lang = self._param.target_lang - appid = self._param.appid - salt = random.randint(32768, 65536) - secret_key = self._param.secret_key - - if self._param.trans_type == 'translate': - sign = md5((appid + ans + salt + secret_key).encode('utf-8')).hexdigest() - url = 'http://api.fanyi.baidu.com/api/trans/vip/translate?' + 'q=' + ans + '&from=' + source_lang + '&to=' + target_lang + '&appid=' + appid + '&salt=' + salt + '&sign=' + sign - headers = {"Content-Type": "application/x-www-form-urlencoded"} - response = requests.post(url=url, headers=headers).json() - - if response.get('error_code'): - BaiduFanyi.be_output("**Error**:" + response['error_msg']) - - return BaiduFanyi.be_output(response['trans_result'][0]['dst']) - elif self._param.trans_type == 'fieldtranslate': - domain = self._param.domain - sign = md5((appid + ans + salt + domain + secret_key).encode('utf-8')).hexdigest() - url = 'http://api.fanyi.baidu.com/api/trans/vip/fieldtranslate?' + 'q=' + ans + '&from=' + source_lang + '&to=' + target_lang + '&appid=' + appid + '&salt=' + salt + '&domain=' + domain + '&sign=' + sign - headers = {"Content-Type": "application/x-www-form-urlencoded"} - response = requests.post(url=url, headers=headers).json() - - if response.get('error_code'): - BaiduFanyi.be_output("**Error**:" + response['error_msg']) - - return BaiduFanyi.be_output(response['trans_result'][0]['dst']) - - except Exception as e: - BaiduFanyi.be_output("**Error**:" + str(e)) - diff --git a/agent/component/base.py b/agent/component/base.py index e35a84e64e6..31ad46820b7 100644 --- a/agent/component/base.py +++ b/agent/component/base.py @@ -13,17 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # + +import re +import time +from abc import ABC import builtins import json -import logging import os -from abc import ABC -from functools import partial -from typing import Any, Tuple, Union - +import logging +from typing import Any, List, Union import pandas as pd - +import trio from agent import settings +from common.connection_utils import timeout + _FEEDED_DEPRECATED_PARAMS = "_feeded_deprecated_params" _DEPRECATED_PARAMS = "_deprecated_params" @@ -33,12 +36,16 @@ class ComponentParamBase(ABC): def __init__(self): - self.output_var_name = "output" - self.infor_var_name = "infor" - self.message_history_window_size = 22 - self.query = [] - self.inputs = [] - self.debug_inputs = [] + self.message_history_window_size = 13 + self.inputs = {} + self.outputs = {} + self.description = "" + self.max_retries = 0 + self.delay_after_error = 2.0 + self.exception_method = None + self.exception_default_value = None + self.exception_goto = None + self.debug_inputs = {} def set_name(self, name: str): self._name = name @@ -89,6 +96,14 @@ def __str__(self): def as_dict(self): def _recursive_convert_obj_to_dict(obj): ret_dict = {} + if isinstance(obj, dict): + for k,v in obj.items(): + if isinstance(v, dict) or (v and type(v).__name__ not in dir(builtins)): + ret_dict[k] = _recursive_convert_obj_to_dict(v) + else: + ret_dict[k] = v + return ret_dict + for attr_name in list(obj.__dict__): if attr_name in [_FEEDED_DEPRECATED_PARAMS, _DEPRECATED_PARAMS, _USER_FEEDED_PARAMS, _IS_RAW_CONF]: continue @@ -97,7 +112,7 @@ def _recursive_convert_obj_to_dict(obj): if isinstance(attr, pd.DataFrame): ret_dict[attr_name] = attr.to_dict() continue - if attr and type(attr).__name__ not in dir(builtins): + if isinstance(attr, dict) or (attr and type(attr).__name__ not in dir(builtins)): ret_dict[attr_name] = _recursive_convert_obj_to_dict(attr) else: ret_dict[attr_name] = attr @@ -110,11 +125,15 @@ def update(self, conf, allow_redundant=False): update_from_raw_conf = conf.get(_IS_RAW_CONF, True) if update_from_raw_conf: deprecated_params_set = self._get_or_init_deprecated_params_set() - feeded_deprecated_params_set = self._get_or_init_feeded_deprecated_params_set() + feeded_deprecated_params_set = ( + self._get_or_init_feeded_deprecated_params_set() + ) user_feeded_params_set = self._get_or_init_user_feeded_params_set() setattr(self, _IS_RAW_CONF, False) else: - feeded_deprecated_params_set = self._get_or_init_feeded_deprecated_params_set(conf) + feeded_deprecated_params_set = ( + self._get_or_init_feeded_deprecated_params_set(conf) + ) user_feeded_params_set = self._get_or_init_user_feeded_params_set(conf) def _recursive_update_param(param, config, depth, prefix): @@ -150,11 +169,15 @@ def _recursive_update_param(param, config, depth, prefix): else: # recursive set obj attr - sub_params = _recursive_update_param(attr, config_value, depth + 1, prefix=f"{prefix}{config_key}.") + sub_params = _recursive_update_param( + attr, config_value, depth + 1, prefix=f"{prefix}{config_key}." + ) setattr(param, config_key, sub_params) if not allow_redundant and redundant_attrs: - raise ValueError(f"cpn `{getattr(self, '_name', type(self))}` has redundant parameters: `{[redundant_attrs]}`") + raise ValueError( + f"cpn `{getattr(self, '_name', type(self))}` has redundant parameters: `{[redundant_attrs]}`" + ) return param @@ -185,7 +208,9 @@ def validate(self): param_validation_path_prefix = home_dir + "/param_validation/" param_name = type(self).__name__ - param_validation_path = "/".join([param_validation_path_prefix, param_name + ".json"]) + param_validation_path = "/".join( + [param_validation_path_prefix, param_name + ".json"] + ) validation_json = None @@ -218,7 +243,11 @@ def _validate_param(self, param_obj, validation_json): break if not value_legal: - raise ValueError("Plase check runtime conf, {} = {} does not match user-parameter restriction".format(variable, value)) + raise ValueError( + "Please check runtime conf, {} = {} does not match user-parameter restriction".format( + variable, value + ) + ) elif variable in validation_json: self._validate_param(attr, validation_json) @@ -226,63 +255,94 @@ def _validate_param(self, param_obj, validation_json): @staticmethod def check_string(param, descr): if type(param).__name__ not in ["str"]: - raise ValueError(descr + " {} not supported, should be string type".format(param)) + raise ValueError( + descr + " {} not supported, should be string type".format(param) + ) @staticmethod def check_empty(param, descr): if not param: - raise ValueError(descr + " does not support empty value.") + raise ValueError( + descr + " does not support empty value." + ) @staticmethod def check_positive_integer(param, descr): if type(param).__name__ not in ["int", "long"] or param <= 0: - raise ValueError(descr + " {} not supported, should be positive integer".format(param)) + raise ValueError( + descr + " {} not supported, should be positive integer".format(param) + ) @staticmethod def check_positive_number(param, descr): if type(param).__name__ not in ["float", "int", "long"] or param <= 0: - raise ValueError(descr + " {} not supported, should be positive numeric".format(param)) + raise ValueError( + descr + " {} not supported, should be positive numeric".format(param) + ) @staticmethod def check_nonnegative_number(param, descr): if type(param).__name__ not in ["float", "int", "long"] or param < 0: - raise ValueError(descr + " {} not supported, should be non-negative numeric".format(param)) + raise ValueError( + descr + + " {} not supported, should be non-negative numeric".format(param) + ) @staticmethod def check_decimal_float(param, descr): if type(param).__name__ not in ["float", "int"] or param < 0 or param > 1: - raise ValueError(descr + " {} not supported, should be a float number in range [0, 1]".format(param)) + raise ValueError( + descr + + " {} not supported, should be a float number in range [0, 1]".format( + param + ) + ) @staticmethod def check_boolean(param, descr): if type(param).__name__ != "bool": - raise ValueError(descr + " {} not supported, should be bool type".format(param)) + raise ValueError( + descr + " {} not supported, should be bool type".format(param) + ) @staticmethod def check_open_unit_interval(param, descr): if type(param).__name__ not in ["float"] or param <= 0 or param >= 1: - raise ValueError(descr + " should be a numeric number between 0 and 1 exclusively") + raise ValueError( + descr + " should be a numeric number between 0 and 1 exclusively" + ) @staticmethod def check_valid_value(param, descr, valid_values): if param not in valid_values: - raise ValueError(descr + " {} is not supported, it should be in {}".format(param, valid_values)) + raise ValueError( + descr + + " {} is not supported, it should be in {}".format(param, valid_values) + ) @staticmethod def check_defined_type(param, descr, types): if type(param).__name__ not in types: - raise ValueError(descr + " {} not supported, should be one of {}".format(param, types)) + raise ValueError( + descr + " {} not supported, should be one of {}".format(param, types) + ) @staticmethod def check_and_change_lower(param, valid_list, descr=""): if type(param).__name__ != "str": - raise ValueError(descr + " {} not supported, should be one of {}".format(param, valid_list)) + raise ValueError( + descr + + " {} not supported, should be one of {}".format(param, valid_list) + ) lower_param = param.lower() if lower_param in valid_list: return lower_param else: - raise ValueError(descr + " {} not supported, should be one of {}".format(param, valid_list)) + raise ValueError( + descr + + " {} not supported, should be one of {}".format(param, valid_list) + ) @staticmethod def _greater_equal_than(value, limit): @@ -296,7 +356,11 @@ def _less_equal_than(value, limit): def _range(value, ranges): in_range = False for left_limit, right_limit in ranges: - if left_limit - settings.FLOAT_ZERO <= value <= right_limit + settings.FLOAT_ZERO: + if ( + left_limit - settings.FLOAT_ZERO + <= value + <= right_limit + settings.FLOAT_ZERO + ): in_range = True break @@ -312,17 +376,24 @@ def _not_in(value, wrong_value_list): def _warn_deprecated_param(self, param_name, descr): if self._deprecated_params_set.get(param_name): - logging.warning(f"{descr} {param_name} is deprecated and ignored in this version.") + logging.warning( + f"{descr} {param_name} is deprecated and ignored in this version." + ) def _warn_to_deprecate_param(self, param_name, descr, new_param): if self._deprecated_params_set.get(param_name): - logging.warning(f"{descr} {param_name} will be deprecated in future release; please use {new_param} instead.") + logging.warning( + f"{descr} {param_name} will be deprecated in future release; " + f"please use {new_param} instead." + ) return True return False class ComponentBase(ABC): component_name: str + thread_limiter = trio.CapacityLimiter(int(os.environ.get('MAX_CONCURRENT_CHATS', 10))) + variable_ref_patt = r"\{* *\{([a-zA-Z:0-9]+@[A-Za-z0-9_.]+|sys\.[A-Za-z0-9_.]+|env\.[A-Za-z0-9_.]+)\} *\}*" def __str__(self): """ @@ -331,232 +402,178 @@ def __str__(self): "params": {} } """ - out = getattr(self._param, self._param.output_var_name) - if isinstance(out, pd.DataFrame) and "chunks" in out: - del out["chunks"] - setattr(self._param, self._param.output_var_name, out) - return """{{ "component_name": "{}", - "params": {}, - "output": {}, - "inputs": {} - }}""".format( - self.component_name, - self._param, - json.dumps(json.loads(str(self._param)).get("output", {}), ensure_ascii=False), - json.dumps(json.loads(str(self._param)).get("inputs", []), ensure_ascii=False), + "params": {} + }}""".format(self.component_name, + self._param ) def __init__(self, canvas, id, param: ComponentParamBase): - from agent.canvas import Canvas # Local import to avoid cyclic dependency - - assert isinstance(canvas, Canvas), "canvas must be an instance of Canvas" + from agent.canvas import Graph # Local import to avoid cyclic dependency + assert isinstance(canvas, Graph), "canvas must be an instance of Canvas" self._canvas = canvas self._id = id self._param = param self._param.check() - def get_dependent_components(self): - cpnts = set( - [ - para["component_id"].split("@")[0] - for para in self._param.query - if para.get("component_id") and para["component_id"].lower().find("answer") < 0 and para["component_id"].lower().find("begin") < 0 - ] - ) - return list(cpnts) + def is_canceled(self) -> bool: + return self._canvas.is_canceled() + + def check_if_canceled(self, message: str = "") -> bool: + if self.is_canceled(): + task_id = getattr(self._canvas, 'task_id', 'unknown') + log_message = f"Task {task_id} has been canceled" + if message: + log_message += f" during {message}" + logging.info(log_message) + self.set_output("_ERROR", "Task has been canceled") + return True + return False - def run(self, history, **kwargs): - logging.debug("{}, history: {}, kwargs: {}".format(self, json.dumps(history, ensure_ascii=False), json.dumps(kwargs, ensure_ascii=False))) - self._param.debug_inputs = [] + def invoke(self, **kwargs) -> dict[str, Any]: + self.set_output("_created_time", time.perf_counter()) try: - res = self._run(history, **kwargs) - self.set_output(res) + self._invoke(**kwargs) except Exception as e: - self.set_output(pd.DataFrame([{"content": str(e)}])) - raise e + if self.get_exception_default_value(): + self.set_exception_default_value() + else: + self.set_output("_ERROR", str(e)) + logging.exception(e) + self._param.debug_inputs = {} + self.set_output("_elapsed_time", time.perf_counter() - self.output("_created_time")) + return self.output() + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 10*60))) + def _invoke(self, **kwargs): + raise NotImplementedError() - return res + def output(self, var_nm: str=None) -> Union[dict[str, Any], Any]: + if var_nm: + return self._param.outputs.get(var_nm, {}).get("value", "") + return {k: o.get("value") for k,o in self._param.outputs.items()} - def _run(self, history, **kwargs): - raise NotImplementedError() + def set_output(self, key: str, value: Any): + if key not in self._param.outputs: + self._param.outputs[key] = {"value": None, "type": str(type(value))} + self._param.outputs[key]["value"] = value - def output(self, allow_partial=True) -> Tuple[str, Union[pd.DataFrame, partial]]: - o = getattr(self._param, self._param.output_var_name) - if not isinstance(o, partial): - if not isinstance(o, pd.DataFrame): - if isinstance(o, list): - return self._param.output_var_name, pd.DataFrame(o).dropna() - if o is None: - return self._param.output_var_name, pd.DataFrame() - return self._param.output_var_name, pd.DataFrame([{"content": str(o)}]) - return self._param.output_var_name, o - - if allow_partial or not isinstance(o, partial): - if not isinstance(o, partial) and not isinstance(o, pd.DataFrame): - return pd.DataFrame(o if isinstance(o, list) else [o]).dropna() - return self._param.output_var_name, o - - outs = None - for oo in o(): - if not isinstance(oo, pd.DataFrame): - outs = pd.DataFrame(oo if isinstance(oo, list) else [oo]).dropna() - else: - outs = oo.dropna() - return self._param.output_var_name, outs - - def reset(self): - setattr(self._param, self._param.output_var_name, None) - self._param.inputs = [] - - def set_output(self, v): - setattr(self._param, self._param.output_var_name, v) - - def set_infor(self, v): - setattr(self._param, self._param.infor_var_name, v) - - def _fetch_outputs_from(self, sources: list[dict[str, Any]]) -> list[pd.DataFrame]: - outs = [] - for q in sources: - if q.get("component_id"): - if "@" in q["component_id"] and q["component_id"].split("@")[0].lower().find("begin") >= 0: - cpn_id, key = q["component_id"].split("@") - for p in self._canvas.get_component(cpn_id)["obj"]._param.query: - if p["key"] == key: - outs.append(pd.DataFrame([{"content": p.get("value", "")}])) - break - else: - assert False, f"Can't find parameter '{key}' for {cpn_id}" - continue + def error(self): + return self._param.outputs.get("_ERROR", {}).get("value") - if q["component_id"].lower().find("answer") == 0: - txt = [] - for r, c in self._canvas.history[::-1][: self._param.message_history_window_size][::-1]: - txt.append(f"{r.upper()}:{c}") - txt = "\n".join(txt) - outs.append(pd.DataFrame([{"content": txt}])) - continue + def reset(self, only_output=False): + for k in self._param.outputs.keys(): + self._param.outputs[k]["value"] = None + if only_output: + return + for k in self._param.inputs.keys(): + self._param.inputs[k]["value"] = None + self._param.debug_inputs = {} + + def get_input(self, key: str=None) -> Union[Any, dict[str, Any]]: + if key: + return self._param.inputs.get(key, {}).get("value") + + res = {} + for var, o in self.get_input_elements().items(): + v = self.get_param(var) + if v is None: + continue + if isinstance(v, str) and self._canvas.is_reff(v): + self.set_input_value(var, self._canvas.get_variable_value(v)) + else: + self.set_input_value(var, v) + res[var] = self.get_input_value(var) + return res - outs.append(self._canvas.get_component(q["component_id"])["obj"].output(allow_partial=False)[1]) - elif q.get("value"): - outs.append(pd.DataFrame([{"content": q["value"]}])) - return outs - def get_input(self): + def get_input_values(self) -> Union[Any, dict[str, Any]]: if self._param.debug_inputs: - return pd.DataFrame([{"content": v["value"]} for v in self._param.debug_inputs if v.get("value")]) + return self._param.debug_inputs + + return {var: self.get_input_value(var) for var, o in self.get_input_elements().items()} + + def get_input_elements_from_text(self, txt: str) -> dict[str, dict[str, str]]: + res = {} + for r in re.finditer(self.variable_ref_patt, txt, flags=re.IGNORECASE|re.DOTALL): + exp = r.group(1) + cpn_id, var_nm = exp.split("@") if exp.find("@")>0 else ("", exp) + res[exp] = { + "name": (self._canvas.get_component_name(cpn_id) +f"@{var_nm}") if cpn_id else exp, + "value": self._canvas.get_variable_value(exp), + "_retrival": self._canvas.get_variable_value(f"{cpn_id}@_references") if cpn_id else None, + "_cpn_id": cpn_id + } + return res - reversed_cpnts = [] - if len(self._canvas.path) > 1: - reversed_cpnts.extend(self._canvas.path[-2]) - reversed_cpnts.extend(self._canvas.path[-1]) - up_cpns = self.get_upstream() - reversed_up_cpnts = [cpn for cpn in reversed_cpnts if cpn in up_cpns] + def get_input_elements(self) -> dict[str, Any]: + return self._param.inputs - if self._param.query: - self._param.inputs = [] - outs = self._fetch_outputs_from(self._param.query) + def get_input_form(self) -> dict[str, dict]: + return self._param.get_input_form() - for out in outs: - records = out.to_dict("records") - content: str + def set_input_value(self, key: str, value: Any) -> None: + if key not in self._param.inputs: + self._param.inputs[key] = {"value": None} + self._param.inputs[key]["value"] = value - if len(records) > 1: - content = "\n".join([str(d["content"]) for d in records]) - else: - content = records[0]["content"] + def get_input_value(self, key: str) -> Any: + if key not in self._param.inputs: + return None + return self._param.inputs[key].get("value") - self._param.inputs.append({"component_id": records[0].get("component_id"), "content": content}) + def get_component_name(self, cpn_id) -> str: + return self._canvas.get_component(cpn_id)["obj"].component_name.lower() - if outs: - df = pd.concat(outs, ignore_index=True) - if "content" in df: - df = df.drop_duplicates(subset=["content"]).reset_index(drop=True) - return df + def get_param(self, name): + if hasattr(self._param, name): + return getattr(self._param, name) + return None - upstream_outs = [] + def debug(self, **kwargs): + return self._invoke(**kwargs) - for u in reversed_up_cpnts[::-1]: - if self.get_component_name(u) in ["switch", "concentrator"]: - continue - if self.component_name.lower() == "generate" and self.get_component_name(u) == "retrieval": - o = self._canvas.get_component(u)["obj"].output(allow_partial=False)[1] - if o is not None: - o["component_id"] = u - upstream_outs.append(o) - continue - # if self.component_name.lower()!="answer" and u not in self._canvas.get_component(self._id)["upstream"]: continue - if self.component_name.lower().find("switch") < 0 and self.get_component_name(u) in ["relevant", "categorize"]: - continue - if u.lower().find("answer") >= 0: - for r, c in self._canvas.history[::-1]: - if r == "user": - upstream_outs.append(pd.DataFrame([{"content": c, "component_id": u}])) - break - break - if self.component_name.lower().find("answer") >= 0 and self.get_component_name(u) in ["relevant"]: - continue - o = self._canvas.get_component(u)["obj"].output(allow_partial=False)[1] - if o is not None: - o["component_id"] = u - upstream_outs.append(o) - break - - assert upstream_outs, "Can't inference the where the component input is. Please identify whose output is this component's input." - - df = pd.concat(upstream_outs, ignore_index=True) - if "content" in df: - df = df.drop_duplicates(subset=["content"]).reset_index(drop=True) - - self._param.inputs = [] - for _, r in df.iterrows(): - self._param.inputs.append({"component_id": r["component_id"], "content": r["content"]}) - - return df - - def get_input_elements(self): - assert self._param.query, "Please verify the input parameters first." - eles = [] - for q in self._param.query: - if q.get("component_id"): - cpn_id = q["component_id"] - if cpn_id.split("@")[0].lower().find("begin") >= 0: - cpn_id, key = cpn_id.split("@") - eles.extend(self._canvas.get_component(cpn_id)["obj"]._param.query) - continue + def get_parent(self) -> Union[object, None]: + pid = self._canvas.get_component(self._id).get("parent_id") + if not pid: + return None + return self._canvas.get_component(pid)["obj"] - eles.append({"name": self._canvas.get_component_name(cpn_id), "key": cpn_id}) - else: - eles.append({"key": q["value"], "name": q["value"], "value": q["value"]}) - return eles - - def get_stream_input(self): - reversed_cpnts = [] - if len(self._canvas.path) > 1: - reversed_cpnts.extend(self._canvas.path[-2]) - reversed_cpnts.extend(self._canvas.path[-1]) - up_cpns = self.get_upstream() - reversed_up_cpnts = [cpn for cpn in reversed_cpnts if cpn in up_cpns] - - for u in reversed_up_cpnts[::-1]: - if self.get_component_name(u) in ["switch", "answer"]: - continue - return self._canvas.get_component(u)["obj"].output()[1] + def get_upstream(self) -> List[str]: + cpn_nms = self._canvas.get_component(self._id)['upstream'] + return cpn_nms - @staticmethod - def be_output(v): - return pd.DataFrame([{"content": v}]) + def get_downstream(self) -> List[str]: + cpn_nms = self._canvas.get_component(self._id)['downstream'] + return cpn_nms - def get_component_name(self, cpn_id): - return self._canvas.get_component(cpn_id)["obj"].component_name.lower() + @staticmethod + def string_format(content: str, kv: dict[str, str]) -> str: + for n, v in kv.items(): + def repl(_match, val=v): + return str(val) if val is not None else "" + content = re.sub( + r"\{%s\}" % re.escape(n), + repl, + content + ) + return content + + def exception_handler(self): + if not self._param.exception_method: + return None + return { + "goto": self._param.exception_goto, + "default_value": self._param.exception_default_value + } - def debug(self, **kwargs): - return self._run([], **kwargs) + def get_exception_default_value(self): + if self._param.exception_method != "comment": + return "" + return self._param.exception_default_value - def get_parent(self): - pid = self._canvas.get_component(self._id)["parent_id"] - return self._canvas.get_component(pid)["obj"] + def set_exception_default_value(self): + self.set_output("result", self.get_exception_default_value()) - def get_upstream(self): - cpn_nms = self._canvas.get_component(self._id)["upstream"] - return cpn_nms + def thoughts(self) -> str: + raise NotImplementedError() diff --git a/agent/component/begin.py b/agent/component/begin.py index f09cc23a69d..b5985bb7a90 100644 --- a/agent/component/begin.py +++ b/agent/component/begin.py @@ -13,37 +13,46 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from functools import partial -import pandas as pd -from agent.component.base import ComponentBase, ComponentParamBase +from agent.component.fillup import UserFillUpParam, UserFillUp -class BeginParam(ComponentParamBase): +class BeginParam(UserFillUpParam): """ Define the Begin component parameters. """ def __init__(self): super().__init__() + self.mode = "conversational" self.prologue = "Hi! I'm your smart assistant. What can I do for you?" - self.query = [] def check(self): - return True + self.check_valid_value(self.mode, "The 'mode' should be either `conversational` or `task`", ["conversational", "task"]) - -class Begin(ComponentBase): - component_name = "Begin" - - def _run(self, history, **kwargs): - if kwargs.get("stream"): - return partial(self.stream_output) - return pd.DataFrame([{"content": self._param.prologue}]) - - def stream_output(self): - res = {"content": self._param.prologue} - yield res - self.set_output(self.be_output(res)) + def get_input_form(self) -> dict[str, dict]: + return getattr(self, "inputs") +class Begin(UserFillUp): + component_name = "Begin" + def _invoke(self, **kwargs): + if self.check_if_canceled("Begin processing"): + return + + for k, v in kwargs.get("inputs", {}).items(): + if self.check_if_canceled("Begin processing"): + return + + if isinstance(v, dict) and v.get("type", "").lower().find("file") >=0: + if v.get("optional") and v.get("value", None) is None: + v = None + else: + v = self._canvas.get_files([v["value"]]) + else: + v = v.get("value") + self.set_output(k, v) + self.set_input_value(k, v) + + def thoughts(self) -> str: + return "" diff --git a/agent/component/bing.py b/agent/component/bing.py deleted file mode 100644 index 6ec97c196b1..00000000000 --- a/agent/component/bing.py +++ /dev/null @@ -1,84 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -from abc import ABC -import requests -import pandas as pd -from agent.component.base import ComponentBase, ComponentParamBase - -class BingParam(ComponentParamBase): - """ - Define the Bing component parameters. - """ - - def __init__(self): - super().__init__() - self.top_n = 10 - self.channel = "Webpages" - self.api_key = "YOUR_ACCESS_KEY" - self.country = "CN" - self.language = "en" - - def check(self): - self.check_positive_integer(self.top_n, "Top N") - self.check_valid_value(self.channel, "Bing Web Search or Bing News", ["Webpages", "News"]) - self.check_empty(self.api_key, "Bing subscription key") - self.check_valid_value(self.country, "Bing Country", - ['AR', 'AU', 'AT', 'BE', 'BR', 'CA', 'CL', 'DK', 'FI', 'FR', 'DE', 'HK', 'IN', 'ID', - 'IT', 'JP', 'KR', 'MY', 'MX', 'NL', 'NZ', 'NO', 'CN', 'PL', 'PT', 'PH', 'RU', 'SA', - 'ZA', 'ES', 'SE', 'CH', 'TW', 'TR', 'GB', 'US']) - self.check_valid_value(self.language, "Bing Languages", - ['ar', 'eu', 'bn', 'bg', 'ca', 'ns', 'nt', 'hr', 'cs', 'da', 'nl', 'en', 'gb', 'et', - 'fi', 'fr', 'gl', 'de', 'gu', 'he', 'hi', 'hu', 'is', 'it', 'jp', 'kn', 'ko', 'lv', - 'lt', 'ms', 'ml', 'mr', 'nb', 'pl', 'br', 'pt', 'pa', 'ro', 'ru', 'sr', 'sk', 'sl', - 'es', 'sv', 'ta', 'te', 'th', 'tr', 'uk', 'vi']) - - -class Bing(ComponentBase, ABC): - component_name = "Bing" - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = " - ".join(ans["content"]) if "content" in ans else "" - if not ans: - return Bing.be_output("") - - try: - headers = {"Ocp-Apim-Subscription-Key": self._param.api_key, 'Accept-Language': self._param.language} - params = {"q": ans, "textDecorations": True, "textFormat": "HTML", "cc": self._param.country, - "answerCount": 1, "promote": self._param.channel} - if self._param.channel == "Webpages": - response = requests.get("https://api.bing.microsoft.com/v7.0/search", headers=headers, params=params) - response.raise_for_status() - search_results = response.json() - bing_res = [{"content": '' + i["name"] + ' ' + i["snippet"]} for i in - search_results["webPages"]["value"]] - elif self._param.channel == "News": - response = requests.get("https://api.bing.microsoft.com/v7.0/news/search", headers=headers, - params=params) - response.raise_for_status() - search_results = response.json() - bing_res = [{"content": '' + i["name"] + ' ' + i["description"]} for i - in search_results['news']['value']] - except Exception as e: - return Bing.be_output("**ERROR**: " + str(e)) - - if not bing_res: - return Bing.be_output("") - - df = pd.DataFrame(bing_res) - logging.debug(f"df: {str(df)}") - return df diff --git a/agent/component/categorize.py b/agent/component/categorize.py index 34bd2cdeacf..1333889bbdb 100644 --- a/agent/component/categorize.py +++ b/agent/component/categorize.py @@ -14,24 +14,31 @@ # limitations under the License. # import logging +import os +import re from abc import ABC -from api.db import LLMType + +from common.constants import LLMType from api.db.services.llm_service import LLMBundle -from agent.component import GenerateParam, Generate +from agent.component.llm import LLMParam, LLM +from common.connection_utils import timeout +from rag.llm.chat_model import ERROR_PREFIX -class CategorizeParam(GenerateParam): +class CategorizeParam(LLMParam): """ - Define the Categorize component parameters. + Define the categorize component parameters. """ def __init__(self): super().__init__() self.category_description = {} - self.prompt = "" + self.query = "sys.query" + self.message_history_window_size = 1 + self.update_prompt() def check(self): - super().check() + self.check_positive_integer(self.message_history_window_size, "[Categorize] Message window size > 0") self.check_empty(self.category_description, "[Categorize] Category examples") for k, v in self.category_description.items(): if not k: @@ -39,76 +46,103 @@ def check(self): if not v.get("to"): raise ValueError(f"[Categorize] 'To' of category {k} can not be empty!") - def get_prompt(self, chat_hist): + def get_input_form(self) -> dict[str, dict]: + return { + "query": { + "type": "line", + "name": "Query" + } + } + + def update_prompt(self): cate_lines = [] for c, desc in self.category_description.items(): - for line in desc.get("examples", "").split("\n"): + for line in desc.get("examples", []): if not line: continue - cate_lines.append("USER: {}\nCategory: {}".format(line, c)) + cate_lines.append("USER: \"" + re.sub(r"\n", " ", line, flags=re.DOTALL) + "\" → "+c) + descriptions = [] for c, desc in self.category_description.items(): if desc.get("description"): descriptions.append( - "\nCategory: {}\nDescription: {}".format(c, desc["description"])) + "\n------\nCategory: {}\nDescription: {}".format(c, desc["description"])) - self.prompt = """ -Role: You're a text classifier. -Task: You need to categorize the user’s questions into {} categories, namely: {} - -Here's description of each category: + self.sys_prompt = """ +You are an advanced classification system that categorizes user questions into specific types. Analyze the input question and classify it into ONE of the following categories: {} -You could learn from the following examples: -{} -You could learn from the above examples. +Here's description of each category: + - {} -Requirements: -- Just mention the category names, no need for any additional words. +---- Instructions ---- + - Consider both explicit mentions and implied context + - Prioritize the most specific applicable category + - Return only the category name without explanations + - Use "Other" only when no other category fits ----- Real Data ---- -USER: {}\n - """.format( - len(self.category_description.keys()), - "/".join(list(self.category_description.keys())), - "\n".join(descriptions), - "\n\n- ".join(cate_lines), - chat_hist + """.format( + "\n - ".join(list(self.category_description.keys())), + "\n".join(descriptions) ) - return self.prompt + if cate_lines: + self.sys_prompt += """ +---- Examples ---- +{} +""".format("\n".join(cate_lines)) -class Categorize(Generate, ABC): + +class Categorize(LLM, ABC): component_name = "Categorize" - def _run(self, history, **kwargs): - input = self.get_input() - input = " - ".join(input["content"]) if "content" in input else "" + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 10*60))) + def _invoke(self, **kwargs): + if self.check_if_canceled("Categorize processing"): + return + + msg = self._canvas.get_history(self._param.message_history_window_size) + if not msg: + msg = [{"role": "user", "content": ""}] + if kwargs.get("sys.query"): + msg[-1]["content"] = kwargs["sys.query"] + self.set_input_value("sys.query", kwargs["sys.query"]) + else: + msg[-1]["content"] = self._canvas.get_variable_value(self._param.query) + self.set_input_value(self._param.query, msg[-1]["content"]) + self._param.update_prompt() chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id) - self._canvas.set_component_infor(self._id, {"prompt":self._param.get_prompt(input),"messages": [{"role": "user", "content": "\nCategory: "}],"conf": self._param.gen_conf()}) - ans = chat_mdl.chat(self._param.get_prompt(input), [{"role": "user", "content": "\nCategory: "}], - self._param.gen_conf()) - logging.debug(f"input: {input}, answer: {str(ans)}") + user_prompt = """ +---- Real Data ---- +{} → +""".format(" | ".join(["{}: \"{}\"".format(c["role"].upper(), re.sub(r"\n", "", c["content"], flags=re.DOTALL)) for c in msg])) + + if self.check_if_canceled("Categorize processing"): + return + + ans = chat_mdl.chat(self._param.sys_prompt, [{"role": "user", "content": user_prompt}], self._param.gen_conf()) + logging.info(f"input: {user_prompt}, answer: {str(ans)}") + if ERROR_PREFIX in ans: + raise Exception(ans) + + if self.check_if_canceled("Categorize processing"): + return + # Count the number of times each category appears in the answer. category_counts = {} for c in self._param.category_description.keys(): count = ans.lower().count(c.lower()) category_counts[c] = count - - # If a category is found, return the category with the highest count. - if any(category_counts.values()): - max_category = max(category_counts.items(), key=lambda x: x[1]) - res = Categorize.be_output(self._param.category_description[max_category[0]]["to"]) - self.set_output(res) - return res - res = Categorize.be_output(list(self._param.category_description.items())[-1][1]["to"]) - self.set_output(res) - return res + cpn_ids = list(self._param.category_description.items())[-1][1]["to"] + max_category = list(self._param.category_description.keys())[0] + if any(category_counts.values()): + max_category = max(category_counts.items(), key=lambda x: x[1])[0] + cpn_ids = self._param.category_description[max_category]["to"] - def debug(self, **kwargs): - df = self._run([], **kwargs) - cpn_id = df.iloc[0, 0] - return Categorize.be_output(self._canvas.get_component_name(cpn_id)) + self.set_output("category_name", max_category) + self.set_output("_next", cpn_ids) + def thoughts(self) -> str: + return "Which should it falls into {}? ...".format(",".join([f"`{c}`" for c, _ in self._param.category_description.items()])) diff --git a/agent/component/code.py b/agent/component/code.py deleted file mode 100644 index 215ffcfe574..00000000000 --- a/agent/component/code.py +++ /dev/null @@ -1,152 +0,0 @@ -# -# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import base64 -from abc import ABC -from enum import Enum -from typing import Optional - -from pydantic import BaseModel, Field, field_validator - -from agent.component.base import ComponentBase, ComponentParamBase -from api import settings - - -class Language(str, Enum): - PYTHON = "python" - NODEJS = "nodejs" - - -class CodeExecutionRequest(BaseModel): - code_b64: str = Field(..., description="Base64 encoded code string") - language: Language = Field(default=Language.PYTHON, description="Programming language") - arguments: Optional[dict] = Field(default={}, description="Arguments") - - @field_validator("code_b64") - @classmethod - def validate_base64(cls, v: str) -> str: - try: - base64.b64decode(v, validate=True) - return v - except Exception as e: - raise ValueError(f"Invalid base64 encoding: {str(e)}") - - @field_validator("language", mode="before") - @classmethod - def normalize_language(cls, v) -> str: - if isinstance(v, str): - low = v.lower() - if low in ("python", "python3"): - return "python" - elif low in ("javascript", "nodejs"): - return "nodejs" - raise ValueError(f"Unsupported language: {v}") - - -class CodeParam(ComponentParamBase): - """ - Define the code sandbox component parameters. - """ - - def __init__(self): - super().__init__() - self.lang = "python" - self.script = "" - self.arguments = [] - self.address = f"http://{settings.SANDBOX_HOST}:9385/run" - self.enable_network = True - - def check(self): - self.check_valid_value(self.lang, "Support languages", ["python", "python3", "nodejs", "javascript"]) - self.check_defined_type(self.enable_network, "Enable network", ["bool"]) - - -class Code(ComponentBase, ABC): - component_name = "Code" - - def _run(self, history, **kwargs): - arguments = {} - for input in self._param.arguments: - if "@" in input["component_id"]: - component_id = input["component_id"].split("@")[0] - referred_component_key = input["component_id"].split("@")[1] - referred_component = self._canvas.get_component(component_id)["obj"] - - for param in referred_component._param.query: - if param["key"] == referred_component_key: - if "value" in param: - arguments[input["name"]] = param["value"] - else: - referred_component = self._canvas.get_component(input["component_id"])["obj"] - referred_component_name = referred_component.component_name - referred_component_id = referred_component._id - - debug_inputs = self._param.debug_inputs - if debug_inputs: - for param in debug_inputs: - if param["key"] == referred_component_id: - if "value" in param and param["name"] == input["name"]: - arguments[input["name"]] = param["value"] - else: - if referred_component_name.lower() == "answer": - arguments[input["name"]] = self._canvas.get_history(1)[0]["content"] - continue - - _, out = referred_component.output(allow_partial=False) - if not out.empty: - arguments[input["name"]] = "\n".join(out["content"]) - - return self._execute_code( - language=self._param.lang, - code=self._param.script, - arguments=arguments, - address=self._param.address, - enable_network=self._param.enable_network, - ) - - def _execute_code(self, language: str, code: str, arguments: dict, address: str, enable_network: bool): - import requests - - try: - code_b64 = self._encode_code(code) - code_req = CodeExecutionRequest(code_b64=code_b64, language=language, arguments=arguments).model_dump() - except Exception as e: - return Code.be_output("**Error**: construct code request error: " + str(e)) - - try: - resp = requests.post(url=address, json=code_req, timeout=10) - body = resp.json() - if body: - stdout = body.get("stdout") - stderr = body.get("stderr") - return Code.be_output(stdout or stderr) - else: - return Code.be_output("**Error**: There is no response from sanbox") - - except Exception as e: - return Code.be_output("**Error**: Internal error in sanbox: " + str(e)) - - def _encode_code(self, code: str) -> str: - return base64.b64encode(code.encode("utf-8")).decode("utf-8") - - def get_input_elements(self): - elements = [] - for input in self._param.arguments: - cpn_id = input["component_id"] - elements.append({"key": cpn_id, "name": input["name"]}) - return elements - - def debug(self, **kwargs): - return self._run([], **kwargs) diff --git a/agent/component/concentrator.py b/agent/component/concentrator.py deleted file mode 100644 index efb9dd8401f..00000000000 --- a/agent/component/concentrator.py +++ /dev/null @@ -1,36 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from abc import ABC -from agent.component.base import ComponentBase, ComponentParamBase - - -class ConcentratorParam(ComponentParamBase): - """ - Define the Concentrator component parameters. - """ - - def __init__(self): - super().__init__() - - def check(self): - return True - - -class Concentrator(ComponentBase, ABC): - component_name = "Concentrator" - - def _run(self, history, **kwargs): - return Concentrator.be_output("") \ No newline at end of file diff --git a/agent/component/data_operations.py b/agent/component/data_operations.py new file mode 100644 index 00000000000..fab7d8c0fa7 --- /dev/null +++ b/agent/component/data_operations.py @@ -0,0 +1,203 @@ +from abc import ABC +import ast +import os +from agent.component.base import ComponentBase, ComponentParamBase +from api.utils.api_utils import timeout + +class DataOperationsParam(ComponentParamBase): + """ + Define the Data Operations component parameters. + """ + def __init__(self): + super().__init__() + self.query = [] + self.operations = "literal_eval" + self.select_keys = [] + self.filter_values=[] + self.updates=[] + self.remove_keys=[] + self.rename_keys=[] + self.outputs = { + "result": { + "value": [], + "type": "Array of Object" + } + } + + def check(self): + self.check_valid_value(self.operations, "Support operations", ["select_keys", "literal_eval","combine","filter_values","append_or_update","remove_keys","rename_keys"]) + + + +class DataOperations(ComponentBase,ABC): + component_name = "DataOperations" + + def get_input_form(self) -> dict[str, dict]: + return { + k: {"name": o.get("name", ""), "type": "line"} + for input_item in (self._param.query or []) + for k, o in self.get_input_elements_from_text(input_item).items() + } + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 10*60))) + def _invoke(self, **kwargs): + self.input_objects=[] + inputs = getattr(self._param, "query", None) + if not isinstance(inputs, (list, tuple)): + inputs = [inputs] + for input_ref in inputs: + input_object=self._canvas.get_variable_value(input_ref) + self.set_input_value(input_ref, input_object) + if input_object is None: + continue + if isinstance(input_object,dict): + self.input_objects.append(input_object) + elif isinstance(input_object,list): + self.input_objects.extend(x for x in input_object if isinstance(x, dict)) + else: + continue + if self._param.operations == "select_keys": + self._select_keys() + elif self._param.operations == "recursive_eval": + self._literal_eval() + elif self._param.operations == "combine": + self._combine() + elif self._param.operations == "filter_values": + self._filter_values() + elif self._param.operations == "append_or_update": + self._append_or_update() + elif self._param.operations == "remove_keys": + self._remove_keys() + else: + self._rename_keys() + + def _select_keys(self): + filter_criteria: list[str] = self._param.select_keys + results = [{key: value for key, value in data_dict.items() if key in filter_criteria} for data_dict in self.input_objects] + self.set_output("result", results) + + + def _recursive_eval(self, data): + if isinstance(data, dict): + return {k: self.recursive_eval(v) for k, v in data.items()} + if isinstance(data, list): + return [self.recursive_eval(item) for item in data] + if isinstance(data, str): + try: + if ( + data.strip().startswith(("{", "[", "(", "'", '"')) + or data.strip().lower() in ("true", "false", "none") + or data.strip().replace(".", "").isdigit() + ): + return ast.literal_eval(data) + except (ValueError, SyntaxError, TypeError, MemoryError): + return data + else: + return data + return data + + def _literal_eval(self): + self.set_output("result", self._recursive_eval(self.input_objects)) + + def _combine(self): + result={} + for obj in self.input_objects: + for key, value in obj.items(): + if key not in result: + result[key] = value + elif isinstance(result[key], list): + if isinstance(value, list): + result[key].extend(value) + else: + result[key].append(value) + else: + result[key] = ( + [result[key], value] if not isinstance(value, list) else [result[key], *value] + ) + self.set_output("result", result) + + def norm(self,v): + s = "" if v is None else str(v) + return s + + def match_rule(self, obj, rule): + key = rule.get("key") + op = (rule.get("operator") or "equals").lower() + target = self.norm(rule.get("value")) + target = self._canvas.get_value_with_variable(target) or target + if key not in obj: + return False + val = obj.get(key, None) + v = self.norm(val) + if op == "=": + return v == target + if op == "≠": + return v != target + if op == "contains": + return target in v + if op == "start with": + return v.startswith(target) + if op == "end with": + return v.endswith(target) + return False + + def _filter_values(self): + results=[] + rules = (getattr(self._param, "filter_values", None) or []) + for obj in self.input_objects: + if not rules: + results.append(obj) + continue + if all(self.match_rule(obj, r) for r in rules): + results.append(obj) + self.set_output("result", results) + + + def _append_or_update(self): + results=[] + updates = getattr(self._param, "updates", []) or [] + for obj in self.input_objects: + new_obj = dict(obj) + for item in updates: + if not isinstance(item, dict): + continue + k = (item.get("key") or "").strip() + if not k: + continue + new_obj[k] = self._canvas.get_value_with_variable(item.get("value")) or item.get("value") + results.append(new_obj) + self.set_output("result", results) + + def _remove_keys(self): + results = [] + remove_keys = getattr(self._param, "remove_keys", []) or [] + + for obj in (self.input_objects or []): + new_obj = dict(obj) + for k in remove_keys: + if not isinstance(k, str): + continue + new_obj.pop(k, None) + results.append(new_obj) + self.set_output("result", results) + + def _rename_keys(self): + results = [] + rename_pairs = getattr(self._param, "rename_keys", []) or [] + + for obj in (self.input_objects or []): + new_obj = dict(obj) + for pair in rename_pairs: + if not isinstance(pair, dict): + continue + old = (pair.get("old_key") or "").strip() + new = (pair.get("new_key") or "").strip() + if not old or not new or old == new: + continue + if old in new_obj: + new_obj[new] = new_obj.pop(old) + results.append(new_obj) + self.set_output("result", results) + + def thoughts(self) -> str: + return "DataOperation in progress" diff --git a/agent/component/duckduckgo.py b/agent/component/duckduckgo.py deleted file mode 100644 index 9f460a699dc..00000000000 --- a/agent/component/duckduckgo.py +++ /dev/null @@ -1,66 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -from abc import ABC -from duckduckgo_search import DDGS -import pandas as pd -from agent.component.base import ComponentBase, ComponentParamBase - - -class DuckDuckGoParam(ComponentParamBase): - """ - Define the DuckDuckGo component parameters. - """ - - def __init__(self): - super().__init__() - self.top_n = 10 - self.channel = "text" - - def check(self): - self.check_positive_integer(self.top_n, "Top N") - self.check_valid_value(self.channel, "Web Search or News", ["text", "news"]) - - -class DuckDuckGo(ComponentBase, ABC): - component_name = "DuckDuckGo" - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = " - ".join(ans["content"]) if "content" in ans else "" - if not ans: - return DuckDuckGo.be_output("") - - try: - if self._param.channel == "text": - with DDGS() as ddgs: - # {'title': '', 'href': '', 'body': ''} - duck_res = [{"content": '' + i["title"] + ' ' + i["body"]} for i - in ddgs.text(ans, max_results=self._param.top_n)] - elif self._param.channel == "news": - with DDGS() as ddgs: - # {'date': '', 'title': '', 'body': '', 'url': '', 'image': '', 'source': ''} - duck_res = [{"content": '' + i["title"] + ' ' + i["body"]} for i - in ddgs.news(ans, max_results=self._param.top_n)] - except Exception as e: - return DuckDuckGo.be_output("**ERROR**: " + str(e)) - - if not duck_res: - return DuckDuckGo.be_output("") - - df = pd.DataFrame(duck_res) - logging.debug("df: {df}") - return df diff --git a/agent/component/email.py b/agent/component/email.py deleted file mode 100644 index 25cdb6a1586..00000000000 --- a/agent/component/email.py +++ /dev/null @@ -1,141 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from abc import ABC -import json -import smtplib -import logging -from email.mime.text import MIMEText -from email.mime.multipart import MIMEMultipart -from email.header import Header -from email.utils import formataddr -from agent.component.base import ComponentBase, ComponentParamBase - -class EmailParam(ComponentParamBase): - """ - Define the Email component parameters. - """ - def __init__(self): - super().__init__() - # Fixed configuration parameters - self.smtp_server = "" # SMTP server address - self.smtp_port = 465 # SMTP port - self.email = "" # Sender email - self.password = "" # Email authorization code - self.sender_name = "" # Sender name - - def check(self): - # Check required parameters - self.check_empty(self.smtp_server, "SMTP Server") - self.check_empty(self.email, "Email") - self.check_empty(self.password, "Password") - self.check_empty(self.sender_name, "Sender Name") - -class Email(ComponentBase, ABC): - component_name = "Email" - - def _run(self, history, **kwargs): - # Get upstream component output and parse JSON - ans = self.get_input() - content = "".join(ans["content"]) if "content" in ans else "" - if not content: - return Email.be_output("No content to send") - - success = False - try: - # Parse JSON string passed from upstream - email_data = json.loads(content) - - # Validate required fields - if "to_email" not in email_data: - return Email.be_output("Missing required field: to_email") - - # Create email object - msg = MIMEMultipart('alternative') - - # Properly handle sender name encoding - msg['From'] = formataddr((str(Header(self._param.sender_name,'utf-8')), self._param.email)) - msg['To'] = email_data["to_email"] - if "cc_email" in email_data and email_data["cc_email"]: - msg['Cc'] = email_data["cc_email"] - msg['Subject'] = Header(email_data.get("subject", "No Subject"), 'utf-8').encode() - - # Use content from email_data or default content - email_content = email_data.get("content", "No content provided") - # msg.attach(MIMEText(email_content, 'plain', 'utf-8')) - msg.attach(MIMEText(email_content, 'html', 'utf-8')) - - # Connect to SMTP server and send - logging.info(f"Connecting to SMTP server {self._param.smtp_server}:{self._param.smtp_port}") - - context = smtplib.ssl.create_default_context() - with smtplib.SMTP(self._param.smtp_server, self._param.smtp_port) as server: - server.ehlo() - server.starttls(context=context) - server.ehlo() - # Login - logging.info(f"Attempting to login with email: {self._param.email}") - server.login(self._param.email, self._param.password) - - # Get all recipient list - recipients = [email_data["to_email"]] - if "cc_email" in email_data and email_data["cc_email"]: - recipients.extend(email_data["cc_email"].split(',')) - - # Send email - logging.info(f"Sending email to recipients: {recipients}") - try: - server.send_message(msg, self._param.email, recipients) - success = True - except Exception as e: - logging.error(f"Error during send_message: {str(e)}") - # Try alternative method - server.sendmail(self._param.email, recipients, msg.as_string()) - success = True - - try: - server.quit() - except Exception as e: - # Ignore errors when closing connection - logging.warning(f"Non-fatal error during connection close: {str(e)}") - - if success: - return Email.be_output("Email sent successfully") - - except json.JSONDecodeError: - error_msg = "Invalid JSON format in input" - logging.error(error_msg) - return Email.be_output(error_msg) - - except smtplib.SMTPAuthenticationError: - error_msg = "SMTP Authentication failed. Please check your email and authorization code." - logging.error(error_msg) - return Email.be_output(f"Failed to send email: {error_msg}") - - except smtplib.SMTPConnectError: - error_msg = f"Failed to connect to SMTP server {self._param.smtp_server}:{self._param.smtp_port}" - logging.error(error_msg) - return Email.be_output(f"Failed to send email: {error_msg}") - - except smtplib.SMTPException as e: - error_msg = f"SMTP error occurred: {str(e)}" - logging.error(error_msg) - return Email.be_output(f"Failed to send email: {error_msg}") - - except Exception as e: - error_msg = f"Unexpected error: {str(e)}" - logging.error(error_msg) - return Email.be_output(f"Failed to send email: {error_msg}") \ No newline at end of file diff --git a/agent/component/exesql.py b/agent/component/exesql.py deleted file mode 100644 index 6f8eae02598..00000000000 --- a/agent/component/exesql.py +++ /dev/null @@ -1,155 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from abc import ABC -import re -from copy import deepcopy - -import pandas as pd -import pymysql -import psycopg2 -from agent.component import GenerateParam, Generate -import pyodbc -import logging - - -class ExeSQLParam(GenerateParam): - """ - Define the ExeSQL component parameters. - """ - - def __init__(self): - super().__init__() - self.db_type = "mysql" - self.database = "" - self.username = "" - self.host = "" - self.port = 3306 - self.password = "" - self.loop = 3 - self.top_n = 30 - - def check(self): - super().check() - self.check_valid_value(self.db_type, "Choose DB type", ['mysql', 'postgresql', 'mariadb', 'mssql']) - self.check_empty(self.database, "Database name") - self.check_empty(self.username, "database username") - self.check_empty(self.host, "IP Address") - self.check_positive_integer(self.port, "IP Port") - self.check_empty(self.password, "Database password") - self.check_positive_integer(self.top_n, "Number of records") - if self.database == "rag_flow": - if self.host == "ragflow-mysql": - raise ValueError("For the security reason, it dose not support database named rag_flow.") - if self.password == "infini_rag_flow": - raise ValueError("For the security reason, it dose not support database named rag_flow.") - - -class ExeSQL(Generate, ABC): - component_name = "ExeSQL" - - def _refactor(self, ans): - ans = re.sub(r"^.*", "", ans, flags=re.DOTALL) - match = re.search(r"```sql\s*(.*?)\s*```", ans, re.DOTALL) - if match: - ans = match.group(1) # Query content - return ans - else: - print("no markdown") - ans = re.sub(r'^.*?SELECT ', 'SELECT ', (ans), flags=re.IGNORECASE) - ans = re.sub(r';.*?SELECT ', '; SELECT ', ans, flags=re.IGNORECASE) - ans = re.sub(r';[^;]*$', r';', ans) - if not ans: - raise Exception("SQL statement not found!") - return ans - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = "".join([str(a) for a in ans["content"]]) if "content" in ans else "" - ans = self._refactor(ans) - if self._param.db_type in ["mysql", "mariadb"]: - db = pymysql.connect(db=self._param.database, user=self._param.username, host=self._param.host, - port=self._param.port, password=self._param.password) - elif self._param.db_type == 'postgresql': - db = psycopg2.connect(dbname=self._param.database, user=self._param.username, host=self._param.host, - port=self._param.port, password=self._param.password) - elif self._param.db_type == 'mssql': - conn_str = ( - r'DRIVER={ODBC Driver 17 for SQL Server};' - r'SERVER=' + self._param.host + ',' + str(self._param.port) + ';' - r'DATABASE=' + self._param.database + ';' - r'UID=' + self._param.username + ';' - r'PWD=' + self._param.password - ) - db = pyodbc.connect(conn_str) - try: - cursor = db.cursor() - except Exception as e: - raise Exception("Database Connection Failed! \n" + str(e)) - if not hasattr(self, "_loop"): - setattr(self, "_loop", 0) - self._loop += 1 - input_list = re.split(r';', ans.replace(r"\n", " ")) - sql_res = [] - for i in range(len(input_list)): - single_sql = input_list[i] - single_sql = single_sql.replace('```','') - while self._loop <= self._param.loop: - self._loop += 1 - if not single_sql: - break - try: - cursor.execute(single_sql) - if cursor.rowcount == 0: - sql_res.append({"content": "No record in the database!"}) - break - if self._param.db_type == 'mssql': - single_res = pd.DataFrame.from_records(cursor.fetchmany(self._param.top_n), - columns=[desc[0] for desc in cursor.description]) - else: - single_res = pd.DataFrame([i for i in cursor.fetchmany(self._param.top_n)]) - single_res.columns = [i[0] for i in cursor.description] - sql_res.append({"content": single_res.to_markdown(index=False, floatfmt=".6f")}) - break - except Exception as e: - single_sql = self._regenerate_sql(single_sql, str(e), **kwargs) - single_sql = self._refactor(single_sql) - if self._loop > self._param.loop: - sql_res.append({"content": "Can't query the correct data via SQL statement."}) - db.close() - if not sql_res: - return ExeSQL.be_output("") - return pd.DataFrame(sql_res) - - def _regenerate_sql(self, failed_sql, error_message, **kwargs): - prompt = f''' - ## You are the Repair SQL Statement Helper, please modify the original SQL statement based on the SQL query error report. - ## The original SQL statement is as follows:{failed_sql}. - ## The contents of the SQL query error report is as follows:{error_message}. - ## Answer only the modified SQL statement. Please do not give any explanation, just answer the code. -''' - self._param.prompt = prompt - kwargs_ = deepcopy(kwargs) - kwargs_["stream"] = False - response = Generate._run(self, [], **kwargs_) - try: - regenerated_sql = response.loc[0, "content"] - return regenerated_sql - except Exception as e: - logging.error(f"Failed to regenerate SQL: {e}") - return None - - def debug(self, **kwargs): - return self._run([], **kwargs) diff --git a/agent/component/fillup.py b/agent/component/fillup.py new file mode 100644 index 00000000000..7428912d490 --- /dev/null +++ b/agent/component/fillup.py @@ -0,0 +1,69 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json +import re +from functools import partial + +from agent.component.base import ComponentParamBase, ComponentBase + + +class UserFillUpParam(ComponentParamBase): + + def __init__(self): + super().__init__() + self.enable_tips = True + self.tips = "Please fill up the form" + + def check(self) -> bool: + return True + + +class UserFillUp(ComponentBase): + component_name = "UserFillUp" + + def _invoke(self, **kwargs): + if self.check_if_canceled("UserFillUp processing"): + return + + if self._param.enable_tips: + content = self._param.tips + for k, v in self.get_input_elements_from_text(self._param.tips).items(): + v = v["value"] + ans = "" + if isinstance(v, partial): + for t in v(): + ans += t + elif isinstance(v, list): + ans = ",".join([str(vv) for vv in v]) + elif not isinstance(v, str): + try: + ans = json.dumps(v, ensure_ascii=False) + except Exception: + pass + else: + ans = v + if not ans: + ans = "" + content = re.sub(r"\{%s\}"%k, ans, content) + + self.set_output("tips", content) + for k, v in kwargs.get("inputs", {}).items(): + if self.check_if_canceled("UserFillUp processing"): + return + self.set_output(k, v) + + def thoughts(self) -> str: + return "Waiting for your input..." diff --git a/agent/component/generate.py b/agent/component/generate.py deleted file mode 100644 index f0cdb1f1588..00000000000 --- a/agent/component/generate.py +++ /dev/null @@ -1,276 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import json -import re -from functools import partial -from typing import Any -import pandas as pd -from api.db import LLMType -from api.db.services.conversation_service import structure_answer -from api.db.services.llm_service import LLMBundle -from api import settings -from agent.component.base import ComponentBase, ComponentParamBase -from plugin import GlobalPluginManager -from plugin.llm_tool_plugin import llm_tool_metadata_to_openai_tool -from rag.llm.chat_model import ToolCallSession -from rag.prompts import message_fit_in - - -class LLMToolPluginCallSession(ToolCallSession): - def tool_call(self, name: str, arguments: dict[str, Any]) -> str: - tool = GlobalPluginManager.get_llm_tool_by_name(name) - - if tool is None: - raise ValueError(f"LLM tool {name} does not exist") - - return tool().invoke(**arguments) - - -class GenerateParam(ComponentParamBase): - """ - Define the Generate component parameters. - """ - - def __init__(self): - super().__init__() - self.llm_id = "" - self.prompt = "" - self.max_tokens = 0 - self.temperature = 0 - self.top_p = 0 - self.presence_penalty = 0 - self.frequency_penalty = 0 - self.cite = True - self.parameters = [] - self.llm_enabled_tools = [] - - def check(self): - self.check_decimal_float(self.temperature, "[Generate] Temperature") - self.check_decimal_float(self.presence_penalty, "[Generate] Presence penalty") - self.check_decimal_float(self.frequency_penalty, "[Generate] Frequency penalty") - self.check_nonnegative_number(self.max_tokens, "[Generate] Max tokens") - self.check_decimal_float(self.top_p, "[Generate] Top P") - self.check_empty(self.llm_id, "[Generate] LLM") - # self.check_defined_type(self.parameters, "Parameters", ["list"]) - - def gen_conf(self): - conf = {} - if self.max_tokens > 0: - conf["max_tokens"] = self.max_tokens - if self.temperature > 0: - conf["temperature"] = self.temperature - if self.top_p > 0: - conf["top_p"] = self.top_p - if self.presence_penalty > 0: - conf["presence_penalty"] = self.presence_penalty - if self.frequency_penalty > 0: - conf["frequency_penalty"] = self.frequency_penalty - return conf - - -class Generate(ComponentBase): - component_name = "Generate" - - def get_dependent_components(self): - inputs = self.get_input_elements() - cpnts = set([i["key"] for i in inputs[1:] if i["key"].lower().find("answer") < 0 and i["key"].lower().find("begin") < 0]) - return list(cpnts) - - def set_cite(self, retrieval_res, answer): - if "empty_response" in retrieval_res.columns: - retrieval_res["empty_response"].fillna("", inplace=True) - chunks = json.loads(retrieval_res["chunks"][0]) - answer, idx = settings.retrievaler.insert_citations(answer, - [ck["content_ltks"] for ck in chunks], - [ck["vector"] for ck in chunks], - LLMBundle(self._canvas.get_tenant_id(), LLMType.EMBEDDING, - self._canvas.get_embedding_model()), tkweight=0.7, - vtweight=0.3) - doc_ids = set([]) - recall_docs = [] - for i in idx: - did = chunks[int(i)]["doc_id"] - if did in doc_ids: - continue - doc_ids.add(did) - recall_docs.append({"doc_id": did, "doc_name": chunks[int(i)]["docnm_kwd"]}) - - for c in chunks: - del c["vector"] - del c["content_ltks"] - - reference = { - "chunks": chunks, - "doc_aggs": recall_docs - } - - if answer.lower().find("invalid key") >= 0 or answer.lower().find("invalid api") >= 0: - answer += " Please set LLM API-Key in 'User Setting -> Model providers -> API-Key'" - res = {"content": answer, "reference": reference} - res = structure_answer(None, res, "", "") - - return res - - def get_input_elements(self): - key_set = set([]) - res = [{"key": "user", "name": "Input your question here:"}] - for r in re.finditer(r"\{([a-z]+[:@][a-z0-9_-]+)\}", self._param.prompt, flags=re.IGNORECASE): - cpn_id = r.group(1) - if cpn_id in key_set: - continue - if cpn_id.lower().find("begin@") == 0: - cpn_id, key = cpn_id.split("@") - for p in self._canvas.get_component(cpn_id)["obj"]._param.query: - if p["key"] != key: - continue - res.append({"key": r.group(1), "name": p["name"]}) - key_set.add(r.group(1)) - continue - cpn_nm = self._canvas.get_component_name(cpn_id) - if not cpn_nm: - continue - res.append({"key": cpn_id, "name": cpn_nm}) - key_set.add(cpn_id) - return res - - def _run(self, history, **kwargs): - chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id) - - if len(self._param.llm_enabled_tools) > 0: - tools = GlobalPluginManager.get_llm_tools_by_names(self._param.llm_enabled_tools) - - chat_mdl.bind_tools( - LLMToolPluginCallSession(), - [llm_tool_metadata_to_openai_tool(t.get_metadata()) for t in tools] - ) - - prompt = self._param.prompt - - retrieval_res = [] - self._param.inputs = [] - for para in self.get_input_elements()[1:]: - if para["key"].lower().find("begin@") == 0: - cpn_id, key = para["key"].split("@") - for p in self._canvas.get_component(cpn_id)["obj"]._param.query: - if p["key"] == key: - kwargs[para["key"]] = p.get("value", "") - self._param.inputs.append( - {"component_id": para["key"], "content": kwargs[para["key"]]}) - break - else: - assert False, f"Can't find parameter '{key}' for {cpn_id}" - continue - - component_id = para["key"] - cpn = self._canvas.get_component(component_id)["obj"] - if cpn.component_name.lower() == "answer": - hist = self._canvas.get_history(1) - if hist: - hist = hist[0]["content"] - else: - hist = "" - kwargs[para["key"]] = hist - continue - _, out = cpn.output(allow_partial=False) - if "content" not in out.columns: - kwargs[para["key"]] = "" - else: - if cpn.component_name.lower() == "retrieval": - retrieval_res.append(out) - kwargs[para["key"]] = " - " + "\n - ".join([o if isinstance(o, str) else str(o) for o in out["content"]]) - self._param.inputs.append({"component_id": para["key"], "content": kwargs[para["key"]]}) - - if retrieval_res: - retrieval_res = pd.concat(retrieval_res, ignore_index=True) - else: - retrieval_res = pd.DataFrame([]) - - for n, v in kwargs.items(): - prompt = re.sub(r"\{%s\}" % re.escape(n), str(v).replace("\\", " "), prompt) - - if not self._param.inputs and prompt.find("{input}") >= 0: - retrieval_res = self.get_input() - input = (" - " + "\n - ".join( - [c for c in retrieval_res["content"] if isinstance(c, str)])) if "content" in retrieval_res else "" - prompt = re.sub(r"\{input\}", re.escape(input), prompt) - - downstreams = self._canvas.get_component(self._id)["downstream"] - if kwargs.get("stream") and len(downstreams) == 1 and self._canvas.get_component(downstreams[0])[ - "obj"].component_name.lower() == "answer": - return partial(self.stream_output, chat_mdl, prompt, retrieval_res) - - if "empty_response" in retrieval_res.columns and not "".join(retrieval_res["content"]): - empty_res = "\n- ".join([str(t) for t in retrieval_res["empty_response"] if str(t)]) - res = {"content": empty_res if empty_res else "Nothing found in knowledgebase!", "reference": []} - return pd.DataFrame([res]) - - msg = self._canvas.get_history(self._param.message_history_window_size) - if len(msg) < 1: - msg.append({"role": "user", "content": "Output: "}) - _, msg = message_fit_in([{"role": "system", "content": prompt}, *msg], int(chat_mdl.max_length * 0.97)) - if len(msg) < 2: - msg.append({"role": "user", "content": "Output: "}) - ans = chat_mdl.chat(msg[0]["content"], msg[1:], self._param.gen_conf()) - ans = re.sub(r"^.*", "", ans, flags=re.DOTALL) - self._canvas.set_component_infor(self._id, {"prompt":msg[0]["content"],"messages": msg[1:],"conf": self._param.gen_conf()}) - if self._param.cite and "chunks" in retrieval_res.columns: - res = self.set_cite(retrieval_res, ans) - return pd.DataFrame([res]) - - return Generate.be_output(ans) - - def stream_output(self, chat_mdl, prompt, retrieval_res): - res = None - if "empty_response" in retrieval_res.columns and not "".join(retrieval_res["content"]): - empty_res = "\n- ".join([str(t) for t in retrieval_res["empty_response"] if str(t)]) - res = {"content": empty_res if empty_res else "Nothing found in knowledgebase!", "reference": []} - yield res - self.set_output(res) - return - - msg = self._canvas.get_history(self._param.message_history_window_size) - if msg and msg[0]['role'] == 'assistant': - msg.pop(0) - if len(msg) < 1: - msg.append({"role": "user", "content": "Output: "}) - _, msg = message_fit_in([{"role": "system", "content": prompt}, *msg], int(chat_mdl.max_length * 0.97)) - if len(msg) < 2: - msg.append({"role": "user", "content": "Output: "}) - answer = "" - for ans in chat_mdl.chat_streamly(msg[0]["content"], msg[1:], self._param.gen_conf()): - res = {"content": ans, "reference": []} - answer = ans - yield res - - if self._param.cite and "chunks" in retrieval_res.columns: - res = self.set_cite(retrieval_res, answer) - yield res - self._canvas.set_component_infor(self._id, {"prompt":msg[0]["content"],"messages": msg[1:],"conf": self._param.gen_conf()}) - self.set_output(Generate.be_output(res)) - - def debug(self, **kwargs): - chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id) - prompt = self._param.prompt - - for para in self._param.debug_inputs: - kwargs[para["key"]] = para.get("value", "") - - for n, v in kwargs.items(): - prompt = re.sub(r"\{%s\}" % re.escape(n), str(v).replace("\\", " "), prompt) - - u = kwargs.get("user") - ans = chat_mdl.chat(prompt, [{"role": "user", "content": u if u else "Output: "}], self._param.gen_conf()) - return pd.DataFrame([ans]) diff --git a/agent/component/github.py b/agent/component/github.py deleted file mode 100644 index 4149da37ab4..00000000000 --- a/agent/component/github.py +++ /dev/null @@ -1,61 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -from abc import ABC -import pandas as pd -import requests -from agent.component.base import ComponentBase, ComponentParamBase - - -class GitHubParam(ComponentParamBase): - """ - Define the GitHub component parameters. - """ - - def __init__(self): - super().__init__() - self.top_n = 10 - - def check(self): - self.check_positive_integer(self.top_n, "Top N") - - -class GitHub(ComponentBase, ABC): - component_name = "GitHub" - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = " - ".join(ans["content"]) if "content" in ans else "" - if not ans: - return GitHub.be_output("") - - try: - url = 'https://api.github.com/search/repositories?q=' + ans + '&sort=stars&order=desc&per_page=' + str( - self._param.top_n) - headers = {"Content-Type": "application/vnd.github+json", "X-GitHub-Api-Version": '2022-11-28'} - response = requests.get(url=url, headers=headers).json() - - github_res = [{"content": '' + i["name"] + '' + str( - i["description"]) + '\n stars:' + str(i['watchers'])} for i in response['items']] - except Exception as e: - return GitHub.be_output("**ERROR**: " + str(e)) - - if not github_res: - return GitHub.be_output("") - - df = pd.DataFrame(github_res) - logging.debug(f"df: {df}") - return df diff --git a/agent/component/google.py b/agent/component/google.py deleted file mode 100644 index 691dc239746..00000000000 --- a/agent/component/google.py +++ /dev/null @@ -1,96 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -from abc import ABC -from serpapi import GoogleSearch -import pandas as pd -from agent.component.base import ComponentBase, ComponentParamBase - - -class GoogleParam(ComponentParamBase): - """ - Define the Google component parameters. - """ - - def __init__(self): - super().__init__() - self.top_n = 10 - self.api_key = "xxx" - self.country = "cn" - self.language = "en" - - def check(self): - self.check_positive_integer(self.top_n, "Top N") - self.check_empty(self.api_key, "SerpApi API key") - self.check_valid_value(self.country, "Google Country", - ['af', 'al', 'dz', 'as', 'ad', 'ao', 'ai', 'aq', 'ag', 'ar', 'am', 'aw', 'au', 'at', - 'az', 'bs', 'bh', 'bd', 'bb', 'by', 'be', 'bz', 'bj', 'bm', 'bt', 'bo', 'ba', 'bw', - 'bv', 'br', 'io', 'bn', 'bg', 'bf', 'bi', 'kh', 'cm', 'ca', 'cv', 'ky', 'cf', 'td', - 'cl', 'cn', 'cx', 'cc', 'co', 'km', 'cg', 'cd', 'ck', 'cr', 'ci', 'hr', 'cu', 'cy', - 'cz', 'dk', 'dj', 'dm', 'do', 'ec', 'eg', 'sv', 'gq', 'er', 'ee', 'et', 'fk', 'fo', - 'fj', 'fi', 'fr', 'gf', 'pf', 'tf', 'ga', 'gm', 'ge', 'de', 'gh', 'gi', 'gr', 'gl', - 'gd', 'gp', 'gu', 'gt', 'gn', 'gw', 'gy', 'ht', 'hm', 'va', 'hn', 'hk', 'hu', 'is', - 'in', 'id', 'ir', 'iq', 'ie', 'il', 'it', 'jm', 'jp', 'jo', 'kz', 'ke', 'ki', 'kp', - 'kr', 'kw', 'kg', 'la', 'lv', 'lb', 'ls', 'lr', 'ly', 'li', 'lt', 'lu', 'mo', 'mk', - 'mg', 'mw', 'my', 'mv', 'ml', 'mt', 'mh', 'mq', 'mr', 'mu', 'yt', 'mx', 'fm', 'md', - 'mc', 'mn', 'ms', 'ma', 'mz', 'mm', 'na', 'nr', 'np', 'nl', 'an', 'nc', 'nz', 'ni', - 'ne', 'ng', 'nu', 'nf', 'mp', 'no', 'om', 'pk', 'pw', 'ps', 'pa', 'pg', 'py', 'pe', - 'ph', 'pn', 'pl', 'pt', 'pr', 'qa', 're', 'ro', 'ru', 'rw', 'sh', 'kn', 'lc', 'pm', - 'vc', 'ws', 'sm', 'st', 'sa', 'sn', 'rs', 'sc', 'sl', 'sg', 'sk', 'si', 'sb', 'so', - 'za', 'gs', 'es', 'lk', 'sd', 'sr', 'sj', 'sz', 'se', 'ch', 'sy', 'tw', 'tj', 'tz', - 'th', 'tl', 'tg', 'tk', 'to', 'tt', 'tn', 'tr', 'tm', 'tc', 'tv', 'ug', 'ua', 'ae', - 'uk', 'gb', 'us', 'um', 'uy', 'uz', 'vu', 've', 'vn', 'vg', 'vi', 'wf', 'eh', 'ye', - 'zm', 'zw']) - self.check_valid_value(self.language, "Google languages", - ['af', 'ak', 'sq', 'ws', 'am', 'ar', 'hy', 'az', 'eu', 'be', 'bem', 'bn', 'bh', - 'xx-bork', 'bs', 'br', 'bg', 'bt', 'km', 'ca', 'chr', 'ny', 'zh-cn', 'zh-tw', 'co', - 'hr', 'cs', 'da', 'nl', 'xx-elmer', 'en', 'eo', 'et', 'ee', 'fo', 'tl', 'fi', 'fr', - 'fy', 'gaa', 'gl', 'ka', 'de', 'el', 'kl', 'gn', 'gu', 'xx-hacker', 'ht', 'ha', 'haw', - 'iw', 'hi', 'hu', 'is', 'ig', 'id', 'ia', 'ga', 'it', 'ja', 'jw', 'kn', 'kk', 'rw', - 'rn', 'xx-klingon', 'kg', 'ko', 'kri', 'ku', 'ckb', 'ky', 'lo', 'la', 'lv', 'ln', 'lt', - 'loz', 'lg', 'ach', 'mk', 'mg', 'ms', 'ml', 'mt', 'mv', 'mi', 'mr', 'mfe', 'mo', 'mn', - 'sr-me', 'my', 'ne', 'pcm', 'nso', 'no', 'nn', 'oc', 'or', 'om', 'ps', 'fa', - 'xx-pirate', 'pl', 'pt', 'pt-br', 'pt-pt', 'pa', 'qu', 'ro', 'rm', 'nyn', 'ru', 'gd', - 'sr', 'sh', 'st', 'tn', 'crs', 'sn', 'sd', 'si', 'sk', 'sl', 'so', 'es', 'es-419', 'su', - 'sw', 'sv', 'tg', 'ta', 'tt', 'te', 'th', 'ti', 'to', 'lua', 'tum', 'tr', 'tk', 'tw', - 'ug', 'uk', 'ur', 'uz', 'vu', 'vi', 'cy', 'wo', 'xh', 'yi', 'yo', 'zu'] - ) - - -class Google(ComponentBase, ABC): - component_name = "Google" - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = " - ".join(ans["content"]) if "content" in ans else "" - if not ans: - return Google.be_output("") - - try: - client = GoogleSearch( - {"engine": "google", "q": ans, "api_key": self._param.api_key, "gl": self._param.country, - "hl": self._param.language, "num": self._param.top_n}) - google_res = [{"content": '' + i["title"] + ' ' + i["snippet"]} for i in - client.get_dict()["organic_results"]] - except Exception: - return Google.be_output("**ERROR**: Existing Unavailable Parameters!") - - if not google_res: - return Google.be_output("") - - df = pd.DataFrame(google_res) - logging.debug(f"df: {df}") - return df diff --git a/agent/component/googlescholar.py b/agent/component/googlescholar.py deleted file mode 100644 index 4ad580ff72f..00000000000 --- a/agent/component/googlescholar.py +++ /dev/null @@ -1,70 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -from abc import ABC -import pandas as pd -from agent.component.base import ComponentBase, ComponentParamBase -from scholarly import scholarly - - -class GoogleScholarParam(ComponentParamBase): - """ - Define the GoogleScholar component parameters. - """ - - def __init__(self): - super().__init__() - self.top_n = 6 - self.sort_by = 'relevance' - self.year_low = None - self.year_high = None - self.patents = True - - def check(self): - self.check_positive_integer(self.top_n, "Top N") - self.check_valid_value(self.sort_by, "GoogleScholar Sort_by", ['date', 'relevance']) - self.check_boolean(self.patents, "Whether or not to include patents, defaults to True") - - -class GoogleScholar(ComponentBase, ABC): - component_name = "GoogleScholar" - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = " - ".join(ans["content"]) if "content" in ans else "" - if not ans: - return GoogleScholar.be_output("") - - scholar_client = scholarly.search_pubs(ans, patents=self._param.patents, year_low=self._param.year_low, - year_high=self._param.year_high, sort_by=self._param.sort_by) - scholar_res = [] - for i in range(self._param.top_n): - try: - pub = next(scholar_client) - scholar_res.append({"content": 'Title: ' + pub['bib']['title'] + '\n_Url: ' + "\n author: " + ",".join(pub['bib']['author']) + '\n Abstract: ' + pub[ - 'bib'].get('abstract', 'no abstract')}) - - except StopIteration or Exception: - logging.exception("GoogleScholar") - break - - if not scholar_res: - return GoogleScholar.be_output("") - - df = pd.DataFrame(scholar_res) - logging.debug(f"df: {df}") - return df diff --git a/agent/component/invoke.py b/agent/component/invoke.py index c2bd58bd431..61ebe2b396d 100644 --- a/agent/component/invoke.py +++ b/agent/component/invoke.py @@ -14,11 +14,17 @@ # limitations under the License. # import json +import logging +import os import re +import time from abc import ABC + import requests -from deepdoc.parser import HtmlParser + from agent.component.base import ComponentBase, ComponentParamBase +from common.connection_utils import timeout +from deepdoc.parser import HtmlParser class InvokeParam(ComponentParamBase): @@ -38,40 +44,41 @@ def __init__(self): self.datatype = "json" # New parameter to determine data posting type def check(self): - self.check_valid_value(self.method.lower(), "Type of content from the crawler", ['get', 'post', 'put']) + self.check_valid_value(self.method.lower(), "Type of content from the crawler", ["get", "post", "put"]) self.check_empty(self.url, "End point URL") self.check_positive_integer(self.timeout, "Timeout time in second") self.check_boolean(self.clean_html, "Clean HTML") - self.check_valid_value(self.datatype.lower(), "Data post type", ['json', 'formdata']) # Check for valid datapost value + self.check_valid_value(self.datatype.lower(), "Data post type", ["json", "formdata"]) # Check for valid datapost value class Invoke(ComponentBase, ABC): component_name = "Invoke" - def _run(self, history, **kwargs): + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 3))) + def _invoke(self, **kwargs): + if self.check_if_canceled("Invoke processing"): + return + args = {} for para in self._param.variables: - if para.get("component_id"): - if '@' in para["component_id"]: - component = para["component_id"].split('@')[0] - field = para["component_id"].split('@')[1] - cpn = self._canvas.get_component(component)["obj"] - for param in cpn._param.query: - if param["key"] == field: - if "value" in param: - args[para["key"]] = param["value"] - else: - cpn = self._canvas.get_component(para["component_id"])["obj"] - if cpn.component_name.lower() == "answer": - args[para["key"]] = self._canvas.get_history(1)[0]["content"] - continue - _, out = cpn.output(allow_partial=False) - if not out.empty: - args[para["key"]] = "\n".join(out["content"]) - else: + if para.get("value"): args[para["key"]] = para["value"] + else: + args[para["key"]] = self._canvas.get_variable_value(para["ref"]) url = self._param.url.strip() + + def replace_variable(match): + var_name = match.group(1) + try: + value = self._canvas.get_variable_value(var_name) + return str(value or "") + except Exception: + return "" + + # {base_url} or {component_id@variable_name} + url = re.sub(r"\{([a-zA-Z_][a-zA-Z0-9_.@-]*)\}", replace_variable, url) + if url.find("http") != 0: url = "http://" + url @@ -83,50 +90,55 @@ def _run(self, history, **kwargs): if re.sub(r"https?:?/?/?", "", self._param.proxy): proxies = {"http": self._param.proxy, "https": self._param.proxy} - if method == 'get': - response = requests.get(url=url, - params=args, - headers=headers, - proxies=proxies, - timeout=self._param.timeout) - if self._param.clean_html: - sections = HtmlParser()(None, response.content) - return Invoke.be_output("\n".join(sections)) - - return Invoke.be_output(response.text) - - if method == 'put': - if self._param.datatype.lower() == 'json': - response = requests.put(url=url, - json=args, - headers=headers, - proxies=proxies, - timeout=self._param.timeout) - else: - response = requests.put(url=url, - data=args, - headers=headers, - proxies=proxies, - timeout=self._param.timeout) - if self._param.clean_html: - sections = HtmlParser()(None, response.content) - return Invoke.be_output("\n".join(sections)) - return Invoke.be_output(response.text) - - if method == 'post': - if self._param.datatype.lower() == 'json': - response = requests.post(url=url, - json=args, - headers=headers, - proxies=proxies, - timeout=self._param.timeout) - else: - response = requests.post(url=url, - data=args, - headers=headers, - proxies=proxies, - timeout=self._param.timeout) - if self._param.clean_html: - sections = HtmlParser()(None, response.content) - return Invoke.be_output("\n".join(sections)) - return Invoke.be_output(response.text) + last_e = "" + for _ in range(self._param.max_retries + 1): + if self.check_if_canceled("Invoke processing"): + return + + try: + if method == "get": + response = requests.get(url=url, params=args, headers=headers, proxies=proxies, timeout=self._param.timeout) + if self._param.clean_html: + sections = HtmlParser()(None, response.content) + self.set_output("result", "\n".join(sections)) + else: + self.set_output("result", response.text) + + if method == "put": + if self._param.datatype.lower() == "json": + response = requests.put(url=url, json=args, headers=headers, proxies=proxies, timeout=self._param.timeout) + else: + response = requests.put(url=url, data=args, headers=headers, proxies=proxies, timeout=self._param.timeout) + if self._param.clean_html: + sections = HtmlParser()(None, response.content) + self.set_output("result", "\n".join(sections)) + else: + self.set_output("result", response.text) + + if method == "post": + if self._param.datatype.lower() == "json": + response = requests.post(url=url, json=args, headers=headers, proxies=proxies, timeout=self._param.timeout) + else: + response = requests.post(url=url, data=args, headers=headers, proxies=proxies, timeout=self._param.timeout) + if self._param.clean_html: + self.set_output("result", "\n".join(sections)) + else: + self.set_output("result", response.text) + + return self.output("result") + except Exception as e: + if self.check_if_canceled("Invoke processing"): + return + + last_e = e + logging.exception(f"Http request error: {e}") + time.sleep(self._param.delay_after_error) + + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"Http request error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return "Waiting for the server respond..." diff --git a/agent/component/iteration.py b/agent/component/iteration.py index 3f554ae81b9..a39147d8f81 100644 --- a/agent/component/iteration.py +++ b/agent/component/iteration.py @@ -16,6 +16,13 @@ from abc import ABC from agent.component.base import ComponentBase, ComponentParamBase +""" +class VariableModel(BaseModel): + data_type: Annotated[Literal["string", "number", "Object", "Boolean", "Array", "Array", "Array", "Array"], Field(default="Array")] + input_mode: Annotated[Literal["constant", "variable"], Field(default="constant")] + value: Annotated[Any, Field(default=None)] + model_config = ConfigDict(extra="forbid") +""" class IterationParam(ComponentParamBase): """ @@ -24,10 +31,18 @@ class IterationParam(ComponentParamBase): def __init__(self): super().__init__() - self.delimiter = "," + self.items_ref = "" + + def get_input_form(self) -> dict[str, dict]: + return { + "items": { + "type": "json", + "name": "Items" + } + } def check(self): - self.check_empty(self.delimiter, "Delimiter") + return True class Iteration(ComponentBase, ABC): @@ -38,8 +53,18 @@ def get_start(self): if self._canvas.get_component(cid)["obj"].component_name.lower() != "iterationitem": continue if self._canvas.get_component(cid)["parent_id"] == self._id: - return self._canvas.get_component(cid) + return cid + + def _invoke(self, **kwargs): + if self.check_if_canceled("Iteration processing"): + return + + arr = self._canvas.get_variable_value(self._param.items_ref) + if not isinstance(arr, list): + self.set_output("_ERROR", self._param.items_ref + " must be an array, but its type is "+str(type(arr))) + + def thoughts(self) -> str: + return "Need to process {} items.".format(len(self._canvas.get_variable_value(self._param.items_ref))) + - def _run(self, history, **kwargs): - return self.output(allow_partial=False)[1] diff --git a/agent/component/iterationitem.py b/agent/component/iterationitem.py index cb1a2704921..83713aedb74 100644 --- a/agent/component/iterationitem.py +++ b/agent/component/iterationitem.py @@ -14,7 +14,6 @@ # limitations under the License. # from abc import ABC -import pandas as pd from agent.component.base import ComponentBase, ComponentParamBase @@ -33,21 +32,60 @@ def __init__(self, canvas, id, param: ComponentParamBase): super().__init__(canvas, id, param) self._idx = 0 - def _run(self, history, **kwargs): + def _invoke(self, **kwargs): + if self.check_if_canceled("IterationItem processing"): + return + parent = self.get_parent() - ans = parent.get_input() - ans = parent._param.delimiter.join(ans["content"]) if "content" in ans else "" - ans = [a.strip() for a in ans.split(parent._param.delimiter)] - if not ans: + arr = self._canvas.get_variable_value(parent._param.items_ref) + if not isinstance(arr, list): self._idx = -1 - return pd.DataFrame() + raise Exception(parent._param.items_ref + " must be an array, but its type is "+str(type(arr))) - df = pd.DataFrame([{"content": ans[self._idx]}]) - self._idx += 1 - if self._idx >= len(ans): + if self._idx > 0: + if self.check_if_canceled("IterationItem processing"): + return + self.output_collation() + + if self._idx >= len(arr): self._idx = -1 - return df + return + + if self.check_if_canceled("IterationItem processing"): + return + + self.set_output("item", arr[self._idx]) + self.set_output("index", self._idx) + + self._idx += 1 + + def output_collation(self): + pid = self.get_parent()._id + for cid in self._canvas.components.keys(): + obj = self._canvas.get_component_obj(cid) + p = obj.get_parent() + if not p: + continue + if p._id != pid: + continue + + if p.component_name.lower() in ["categorize", "message", "switch", "userfillup", "interationitem"]: + continue + + for k, o in p._param.outputs.items(): + if "ref" not in o: + continue + _cid, var = o["ref"].split("@") + if _cid != cid: + continue + res = p.output(k) + if not res: + res = [] + res.append(obj.output(var)) + p.set_output(k, res) def end(self): return self._idx == -1 + def thoughts(self) -> str: + return "Next turn..." diff --git a/agent/component/keyword.py b/agent/component/keyword.py deleted file mode 100644 index a34a1ad4621..00000000000 --- a/agent/component/keyword.py +++ /dev/null @@ -1,72 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -import re -from abc import ABC -from api.db import LLMType -from api.db.services.llm_service import LLMBundle -from agent.component import GenerateParam, Generate - - -class KeywordExtractParam(GenerateParam): - """ - Define the KeywordExtract component parameters. - """ - - def __init__(self): - super().__init__() - self.top_n = 1 - - def check(self): - super().check() - self.check_positive_integer(self.top_n, "Top N") - - def get_prompt(self): - self.prompt = """ -- Role: You're a question analyzer. -- Requirements: - - Summarize user's question, and give top %s important keyword/phrase. - - Use comma as a delimiter to separate keywords/phrases. -- Answer format: (in language of user's question) - - keyword: -""" % self.top_n - return self.prompt - - -class KeywordExtract(Generate, ABC): - component_name = "KeywordExtract" - - def _run(self, history, **kwargs): - query = self.get_input() - if hasattr(query, "to_dict") and "content" in query: - query = ", ".join(map(str, query["content"].dropna())) - else: - query = str(query) - - - chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id) - self._canvas.set_component_infor(self._id, {"prompt":self._param.get_prompt(),"messages": [{"role": "user", "content": query}],"conf": self._param.gen_conf()}) - - ans = chat_mdl.chat(self._param.get_prompt(), [{"role": "user", "content": query}], - self._param.gen_conf()) - - ans = re.sub(r"^.*", "", ans, flags=re.DOTALL) - ans = re.sub(r".*keyword:", "", ans).strip() - logging.debug(f"ans: {ans}") - return KeywordExtract.be_output(ans) - - def debug(self, **kwargs): - return self._run([], **kwargs) diff --git a/agent/component/llm.py b/agent/component/llm.py new file mode 100644 index 00000000000..6ce0f65a551 --- /dev/null +++ b/agent/component/llm.py @@ -0,0 +1,302 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json +import logging +import os +import re +from copy import deepcopy +from typing import Any, Generator +import json_repair +from functools import partial +from common.constants import LLMType +from api.db.services.llm_service import LLMBundle +from api.db.services.tenant_llm_service import TenantLLMService +from agent.component.base import ComponentBase, ComponentParamBase +from common.connection_utils import timeout +from rag.prompts.generator import tool_call_summary, message_fit_in, citation_prompt, structured_output_prompt + + +class LLMParam(ComponentParamBase): + """ + Define the LLM component parameters. + """ + + def __init__(self): + super().__init__() + self.llm_id = "" + self.sys_prompt = "" + self.prompts = [{"role": "user", "content": "{sys.query}"}] + self.max_tokens = 0 + self.temperature = 0 + self.top_p = 0 + self.presence_penalty = 0 + self.frequency_penalty = 0 + self.output_structure = None + self.cite = True + self.visual_files_var = None + + def check(self): + self.check_decimal_float(float(self.temperature), "[Agent] Temperature") + self.check_decimal_float(float(self.presence_penalty), "[Agent] Presence penalty") + self.check_decimal_float(float(self.frequency_penalty), "[Agent] Frequency penalty") + self.check_nonnegative_number(int(self.max_tokens), "[Agent] Max tokens") + self.check_decimal_float(float(self.top_p), "[Agent] Top P") + self.check_empty(self.llm_id, "[Agent] LLM") + self.check_empty(self.sys_prompt, "[Agent] System prompt") + self.check_empty(self.prompts, "[Agent] User prompt") + + def gen_conf(self): + conf = {} + def get_attr(nm): + try: + return getattr(self, nm) + except Exception: + pass + + if int(self.max_tokens) > 0 and get_attr("maxTokensEnabled"): + conf["max_tokens"] = int(self.max_tokens) + if float(self.temperature) > 0 and get_attr("temperatureEnabled"): + conf["temperature"] = float(self.temperature) + if float(self.top_p) > 0 and get_attr("topPEnabled"): + conf["top_p"] = float(self.top_p) + if float(self.presence_penalty) > 0 and get_attr("presencePenaltyEnabled"): + conf["presence_penalty"] = float(self.presence_penalty) + if float(self.frequency_penalty) > 0 and get_attr("frequencyPenaltyEnabled"): + conf["frequency_penalty"] = float(self.frequency_penalty) + return conf + + +class LLM(ComponentBase): + component_name = "LLM" + + def __init__(self, canvas, component_id, param: ComponentParamBase): + super().__init__(canvas, component_id, param) + self.chat_mdl = LLMBundle(self._canvas.get_tenant_id(), TenantLLMService.llm_id2llm_type(self._param.llm_id), + self._param.llm_id, max_retries=self._param.max_retries, + retry_interval=self._param.delay_after_error + ) + self.imgs = [] + + def get_input_form(self) -> dict[str, dict]: + res = {} + for k, v in self.get_input_elements().items(): + res[k] = { + "type": "line", + "name": v["name"] + } + return res + + def get_input_elements(self) -> dict[str, Any]: + res = self.get_input_elements_from_text(self._param.sys_prompt) + if isinstance(self._param.prompts, str): + self._param.prompts = [{"role": "user", "content": self._param.prompts}] + for prompt in self._param.prompts: + d = self.get_input_elements_from_text(prompt["content"]) + res.update(d) + return res + + def set_debug_inputs(self, inputs: dict[str, dict]): + self._param.debug_inputs = inputs + + def add2system_prompt(self, txt): + self._param.sys_prompt += txt + + def _sys_prompt_and_msg(self, msg, args): + if isinstance(self._param.prompts, str): + self._param.prompts = [{"role": "user", "content": self._param.prompts}] + for p in self._param.prompts: + if msg and msg[-1]["role"] == p["role"]: + continue + p = deepcopy(p) + p["content"] = self.string_format(p["content"], args) + msg.append(p) + return msg, self.string_format(self._param.sys_prompt, args) + + def _prepare_prompt_variables(self): + if self._param.visual_files_var: + self.imgs = self._canvas.get_variable_value(self._param.visual_files_var) + if not self.imgs: + self.imgs = [] + self.imgs = [img for img in self.imgs if img[:len("data:image/")] == "data:image/"] + if self.imgs and TenantLLMService.llm_id2llm_type(self._param.llm_id) == LLMType.CHAT.value: + self.chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.IMAGE2TEXT.value, + self._param.llm_id, max_retries=self._param.max_retries, + retry_interval=self._param.delay_after_error + ) + + + args = {} + vars = self.get_input_elements() if not self._param.debug_inputs else self._param.debug_inputs + for k, o in vars.items(): + args[k] = o["value"] + if not isinstance(args[k], str): + try: + args[k] = json.dumps(args[k], ensure_ascii=False) + except Exception: + args[k] = str(args[k]) + self.set_input_value(k, args[k]) + + msg, sys_prompt = self._sys_prompt_and_msg(self._canvas.get_history(self._param.message_history_window_size)[:-1], args) + user_defined_prompt, sys_prompt = self._extract_prompts(sys_prompt) + if self._param.cite and self._canvas.get_reference()["chunks"]: + sys_prompt += citation_prompt(user_defined_prompt) + + return sys_prompt, msg, user_defined_prompt + + def _extract_prompts(self, sys_prompt): + pts = {} + for tag in ["TASK_ANALYSIS", "PLAN_GENERATION", "REFLECTION", "CONTEXT_SUMMARY", "CONTEXT_RANKING", "CITATION_GUIDELINES"]: + r = re.search(rf"<{tag}>(.*?)", sys_prompt, flags=re.DOTALL|re.IGNORECASE) + if not r: + continue + pts[tag.lower()] = r.group(1) + sys_prompt = re.sub(rf"<{tag}>(.*?)", "", sys_prompt, flags=re.DOTALL|re.IGNORECASE) + return pts, sys_prompt + + def _generate(self, msg:list[dict], **kwargs) -> str: + if not self.imgs: + return self.chat_mdl.chat(msg[0]["content"], msg[1:], self._param.gen_conf(), **kwargs) + return self.chat_mdl.chat(msg[0]["content"], msg[1:], self._param.gen_conf(), images=self.imgs, **kwargs) + + def _generate_streamly(self, msg:list[dict], **kwargs) -> Generator[str, None, None]: + ans = "" + last_idx = 0 + endswith_think = False + def delta(txt): + nonlocal ans, last_idx, endswith_think + delta_ans = txt[last_idx:] + ans = txt + + if delta_ans.find("") == 0: + last_idx += len("") + return "" + elif delta_ans.find("") > 0: + delta_ans = txt[last_idx:last_idx+delta_ans.find("")] + last_idx += delta_ans.find("") + return delta_ans + elif delta_ans.endswith(""): + endswith_think = True + elif endswith_think: + endswith_think = False + return "" + + last_idx = len(ans) + if ans.endswith(""): + last_idx -= len("") + return re.sub(r"(|)", "", delta_ans) + + if not self.imgs: + for txt in self.chat_mdl.chat_streamly(msg[0]["content"], msg[1:], self._param.gen_conf(), **kwargs): + yield delta(txt) + else: + for txt in self.chat_mdl.chat_streamly(msg[0]["content"], msg[1:], self._param.gen_conf(), images=self.imgs, **kwargs): + yield delta(txt) + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 10*60))) + def _invoke(self, **kwargs): + if self.check_if_canceled("LLM processing"): + return + + def clean_formated_answer(ans: str) -> str: + ans = re.sub(r"^.*", "", ans, flags=re.DOTALL) + ans = re.sub(r"^.*```json", "", ans, flags=re.DOTALL) + return re.sub(r"```\n*$", "", ans, flags=re.DOTALL) + + prompt, msg, _ = self._prepare_prompt_variables() + error: str = "" + output_structure=None + try: + output_structure = self._param.outputs['structured'] + except Exception: + pass + if output_structure: + schema=json.dumps(output_structure, ensure_ascii=False, indent=2) + prompt += structured_output_prompt(schema) + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("LLM processing"): + return + + _, msg = message_fit_in([{"role": "system", "content": prompt}, *msg], int(self.chat_mdl.max_length * 0.97)) + error = "" + ans = self._generate(msg) + msg.pop(0) + if ans.find("**ERROR**") >= 0: + logging.error(f"LLM response error: {ans}") + error = ans + continue + try: + self.set_output("structured", json_repair.loads(clean_formated_answer(ans))) + return + except Exception: + msg.append({"role": "user", "content": "The answer can't not be parsed as JSON"}) + error = "The answer can't not be parsed as JSON" + if error: + self.set_output("_ERROR", error) + return + + downstreams = self._canvas.get_component(self._id)["downstream"] if self._canvas.get_component(self._id) else [] + ex = self.exception_handler() + if any([self._canvas.get_component_obj(cid).component_name.lower()=="message" for cid in downstreams]) and not output_structure and not (ex and ex["goto"]): + self.set_output("content", partial(self._stream_output, prompt, msg)) + return + + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("LLM processing"): + return + + _, msg = message_fit_in([{"role": "system", "content": prompt}, *msg], int(self.chat_mdl.max_length * 0.97)) + error = "" + ans = self._generate(msg) + msg.pop(0) + if ans.find("**ERROR**") >= 0: + logging.error(f"LLM response error: {ans}") + error = ans + continue + self.set_output("content", ans) + break + + if error: + if self.get_exception_default_value(): + self.set_output("content", self.get_exception_default_value()) + else: + self.set_output("_ERROR", error) + + def _stream_output(self, prompt, msg): + _, msg = message_fit_in([{"role": "system", "content": prompt}, *msg], int(self.chat_mdl.max_length * 0.97)) + answer = "" + for ans in self._generate_streamly(msg): + if self.check_if_canceled("LLM streaming"): + return + + if ans.find("**ERROR**") >= 0: + if self.get_exception_default_value(): + self.set_output("content", self.get_exception_default_value()) + yield self.get_exception_default_value() + else: + self.set_output("_ERROR", ans) + return + yield ans + answer += ans + self.set_output("content", answer) + + def add_memory(self, user:str, assist:str, func_name: str, params: dict, results: str, user_defined_prompt:dict={}): + summ = tool_call_summary(self.chat_mdl, func_name, params, results, user_defined_prompt) + logging.info(f"[MEMORY]: {summ}") + self._canvas.add_memory(user, assist, summ) + + def thoughts(self) -> str: + _, msg,_ = self._prepare_prompt_variables() + return "⌛Give me a moment—starting from: \n\n" + re.sub(r"(User's query:|[\\]+)", '', msg[-1]['content'], flags=re.DOTALL) + "\n\nI’ll figure out our best next move." diff --git a/agent/component/message.py b/agent/component/message.py index c60d4d307c2..641198083e9 100644 --- a/agent/component/message.py +++ b/agent/component/message.py @@ -13,43 +13,157 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json +import os import random -from abc import ABC +import re from functools import partial +from typing import Any + from agent.component.base import ComponentBase, ComponentParamBase +from jinja2 import Template as Jinja2Template +from common.connection_utils import timeout -class MessageParam(ComponentParamBase): +class MessageParam(ComponentParamBase): """ Define the Message component parameters. """ def __init__(self): super().__init__() - self.messages = [] + self.content = [] + self.stream = True + self.outputs = { + "content": { + "type": "str" + } + } def check(self): - self.check_empty(self.messages, "[Message]") + self.check_empty(self.content, "[Message] Content") + self.check_boolean(self.stream, "[Message] stream") return True -class Message(ComponentBase, ABC): +class Message(ComponentBase): component_name = "Message" - def _run(self, history, **kwargs): - if kwargs.get("stream"): - return partial(self.stream_output) + def get_input_elements(self) -> dict[str, Any]: + return self.get_input_elements_from_text("".join(self._param.content)) + + def get_kwargs(self, script:str, kwargs:dict = {}, delimiter:str=None) -> tuple[str, dict[str, str | list | Any]]: + for k,v in self.get_input_elements_from_text(script).items(): + if k in kwargs: + continue + v = v["value"] + if not v: + v = "" + ans = "" + if isinstance(v, partial): + for t in v(): + ans += t + elif isinstance(v, list) and delimiter: + ans = delimiter.join([str(vv) for vv in v]) + elif not isinstance(v, str): + try: + ans = json.dumps(v, ensure_ascii=False) + except Exception: + pass + else: + ans = v + if not ans: + ans = "" + kwargs[k] = ans + self.set_input_value(k, ans) + + _kwargs = {} + for n, v in kwargs.items(): + _n = re.sub("[@:.]", "_", n) + script = re.sub(r"\{%s\}" % re.escape(n), _n, script) + _kwargs[_n] = v + return script, _kwargs + + def _stream(self, rand_cnt:str): + s = 0 + all_content = "" + cache = {} + for r in re.finditer(self.variable_ref_patt, rand_cnt, flags=re.DOTALL): + if self.check_if_canceled("Message streaming"): + return + + all_content += rand_cnt[s: r.start()] + yield rand_cnt[s: r.start()] + s = r.end() + exp = r.group(1) + if exp in cache: + yield cache[exp] + all_content += cache[exp] + continue + + v = self._canvas.get_variable_value(exp) + if v is None: + v = "" + if isinstance(v, partial): + cnt = "" + for t in v(): + if self.check_if_canceled("Message streaming"): + return + + all_content += t + cnt += t + yield t + self.set_input_value(exp, cnt) + continue + elif not isinstance(v, str): + try: + v = json.dumps(v, ensure_ascii=False) + except Exception: + v = str(v) + yield v + self.set_input_value(exp, v) + all_content += v + cache[exp] = v + + if s < len(rand_cnt): + if self.check_if_canceled("Message streaming"): + return + + all_content += rand_cnt[s: ] + yield rand_cnt[s: ] + + self.set_output("content", all_content) + + def _is_jinjia2(self, content:str) -> bool: + patt = [ + r"\{%.*%\}", "{{", "}}" + ] + return any([re.search(p, content) for p in patt]) + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 10*60))) + def _invoke(self, **kwargs): + if self.check_if_canceled("Message processing"): + return + + rand_cnt = random.choice(self._param.content) + if self._param.stream and not self._is_jinjia2(rand_cnt): + self.set_output("content", partial(self._stream, rand_cnt)) + return - res = Message.be_output(random.choice(self._param.messages)) - self.set_output(res) - return res + rand_cnt, kwargs = self.get_kwargs(rand_cnt, kwargs) + template = Jinja2Template(rand_cnt) + try: + content = template.render(kwargs) + except Exception: + pass - def stream_output(self): - res = None - if self._param.messages: - res = {"content": random.choice(self._param.messages)} - yield res + if self.check_if_canceled("Message processing"): + return - self.set_output(res) + for n, v in kwargs.items(): + content = re.sub(n, v, content) + self.set_output("content", content) + def thoughts(self) -> str: + return "" diff --git a/agent/component/pubmed.py b/agent/component/pubmed.py deleted file mode 100644 index 8f41d3c972f..00000000000 --- a/agent/component/pubmed.py +++ /dev/null @@ -1,69 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -from abc import ABC -from Bio import Entrez -import re -import pandas as pd -import xml.etree.ElementTree as ET -from agent.component.base import ComponentBase, ComponentParamBase - - -class PubMedParam(ComponentParamBase): - """ - Define the PubMed component parameters. - """ - - def __init__(self): - super().__init__() - self.top_n = 5 - self.email = "A.N.Other@example.com" - - def check(self): - self.check_positive_integer(self.top_n, "Top N") - - -class PubMed(ComponentBase, ABC): - component_name = "PubMed" - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = " - ".join(ans["content"]) if "content" in ans else "" - if not ans: - return PubMed.be_output("") - - try: - Entrez.email = self._param.email - pubmedids = Entrez.read(Entrez.esearch(db='pubmed', retmax=self._param.top_n, term=ans))['IdList'] - pubmedcnt = ET.fromstring(re.sub(r'<(/?)b>|<(/?)i>', '', Entrez.efetch(db='pubmed', id=",".join(pubmedids), - retmode="xml").read().decode( - "utf-8"))) - pubmed_res = [{"content": 'Title:' + child.find("MedlineCitation").find("Article").find( - "ArticleTitle").text + '\nUrl:' + '\n' + 'Abstract:' + ( - child.find("MedlineCitation").find("Article").find("Abstract").find( - "AbstractText").text if child.find("MedlineCitation").find( - "Article").find("Abstract") else "No abstract available")} for child in - pubmedcnt.findall("PubmedArticle")] - except Exception as e: - return PubMed.be_output("**ERROR**: " + str(e)) - - if not pubmed_res: - return PubMed.be_output("") - - df = pd.DataFrame(pubmed_res) - logging.debug(f"df: {df}") - return df diff --git a/agent/component/relevant.py b/agent/component/relevant.py deleted file mode 100644 index 201506afaea..00000000000 --- a/agent/component/relevant.py +++ /dev/null @@ -1,83 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -from abc import ABC -from api.db import LLMType -from api.db.services.llm_service import LLMBundle -from agent.component import GenerateParam, Generate -from rag.utils import num_tokens_from_string, encoder - - -class RelevantParam(GenerateParam): - - """ - Define the Relevant component parameters. - """ - def __init__(self): - super().__init__() - self.prompt = "" - self.yes = "" - self.no = "" - - def check(self): - super().check() - self.check_empty(self.yes, "[Relevant] 'Yes'") - self.check_empty(self.no, "[Relevant] 'No'") - - def get_prompt(self): - self.prompt = """ - You are a grader assessing relevance of a retrieved document to a user question. - It does not need to be a stringent test. The goal is to filter out erroneous retrievals. - If the document contains keyword(s) or semantic meaning related to the user question, grade it as relevant. - Give a binary score 'yes' or 'no' score to indicate whether the document is relevant to the question. - No other words needed except 'yes' or 'no'. - """ - return self.prompt - - -class Relevant(Generate, ABC): - component_name = "Relevant" - - def _run(self, history, **kwargs): - q = "" - for r, c in self._canvas.history[::-1]: - if r == "user": - q = c - break - ans = self.get_input() - ans = " - ".join(ans["content"]) if "content" in ans else "" - if not ans: - return Relevant.be_output(self._param.no) - ans = "Documents: \n" + ans - ans = f"Question: {q}\n" + ans - chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id) - - if num_tokens_from_string(ans) >= chat_mdl.max_length - 4: - ans = encoder.decode(encoder.encode(ans)[:chat_mdl.max_length - 4]) - - ans = chat_mdl.chat(self._param.get_prompt(), [{"role": "user", "content": ans}], - self._param.gen_conf()) - - logging.debug(ans) - if ans.lower().find("yes") >= 0: - return Relevant.be_output(self._param.yes) - if ans.lower().find("no") >= 0: - return Relevant.be_output(self._param.no) - assert False, f"Relevant component got: {ans}" - - def debug(self, **kwargs): - return self._run([], **kwargs) - diff --git a/agent/component/retrieval.py b/agent/component/retrieval.py deleted file mode 100644 index 218dae96999..00000000000 --- a/agent/component/retrieval.py +++ /dev/null @@ -1,135 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import json -import logging -import re -from abc import ABC - -import pandas as pd - -from api.db import LLMType -from api.db.services.knowledgebase_service import KnowledgebaseService -from api.db.services.llm_service import LLMBundle -from api import settings -from agent.component.base import ComponentBase, ComponentParamBase -from rag.app.tag import label_question -from rag.prompts import kb_prompt -from rag.utils.tavily_conn import Tavily - - -class RetrievalParam(ComponentParamBase): - """ - Define the Retrieval component parameters. - """ - - def __init__(self): - super().__init__() - self.similarity_threshold = 0.2 - self.keywords_similarity_weight = 0.5 - self.top_n = 8 - self.top_k = 1024 - self.kb_ids = [] - self.kb_vars = [] - self.rerank_id = "" - self.empty_response = "" - self.tavily_api_key = "" - self.use_kg = False - - def check(self): - self.check_decimal_float(self.similarity_threshold, "[Retrieval] Similarity threshold") - self.check_decimal_float(self.keywords_similarity_weight, "[Retrieval] Keyword similarity weight") - self.check_positive_number(self.top_n, "[Retrieval] Top N") - - -class Retrieval(ComponentBase, ABC): - component_name = "Retrieval" - - def _run(self, history, **kwargs): - query = self.get_input() - query = str(query["content"][0]) if "content" in query else "" - query = re.split(r"(USER:|ASSISTANT:)", query)[-1] - - kb_ids: list[str] = self._param.kb_ids or [] - - kb_vars = self._fetch_outputs_from(self._param.kb_vars) - - if len(kb_vars) > 0: - for kb_var in kb_vars: - if len(kb_var) == 1: - kb_var_value = str(kb_var["content"][0]) - - for v in kb_var_value.split(","): - kb_ids.append(v) - else: - for v in kb_var.to_dict("records"): - kb_ids.append(v["content"]) - - filtered_kb_ids: list[str] = [kb_id for kb_id in kb_ids if kb_id] - - kbs = KnowledgebaseService.get_by_ids(filtered_kb_ids) - if not kbs: - return Retrieval.be_output("") - - embd_nms = list(set([kb.embd_id for kb in kbs])) - assert len(embd_nms) == 1, "Knowledge bases use different embedding models." - - embd_mdl = None - if embd_nms: - embd_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.EMBEDDING, embd_nms[0]) - self._canvas.set_embedding_model(embd_nms[0]) - - rerank_mdl = None - if self._param.rerank_id: - rerank_mdl = LLMBundle(kbs[0].tenant_id, LLMType.RERANK, self._param.rerank_id) - - if kbs: - query = re.sub(r"^user[::\s]*", "", query, flags=re.IGNORECASE) - kbinfos = settings.retrievaler.retrieval( - query, - embd_mdl, - [kb.tenant_id for kb in kbs], - filtered_kb_ids, - 1, - self._param.top_n, - self._param.similarity_threshold, - 1 - self._param.keywords_similarity_weight, - aggs=False, - rerank_mdl=rerank_mdl, - rank_feature=label_question(query, kbs), - ) - else: - kbinfos = {"chunks": [], "doc_aggs": []} - - if self._param.use_kg and kbs: - ck = settings.kg_retrievaler.retrieval(query, [kb.tenant_id for kb in kbs], filtered_kb_ids, embd_mdl, LLMBundle(kbs[0].tenant_id, LLMType.CHAT)) - if ck["content_with_weight"]: - kbinfos["chunks"].insert(0, ck) - - if self._param.tavily_api_key: - tav = Tavily(self._param.tavily_api_key) - tav_res = tav.retrieve_chunks(query) - kbinfos["chunks"].extend(tav_res["chunks"]) - kbinfos["doc_aggs"].extend(tav_res["doc_aggs"]) - - if not kbinfos["chunks"]: - df = Retrieval.be_output("") - if self._param.empty_response and self._param.empty_response.strip(): - df["empty_response"] = self._param.empty_response - return df - - df = pd.DataFrame({"content": kb_prompt(kbinfos, 200000), "chunks": json.dumps(kbinfos["chunks"])}) - logging.debug("{} {}".format(query, df)) - return df.dropna() diff --git a/agent/component/rewrite.py b/agent/component/rewrite.py deleted file mode 100644 index 0ab19d4120b..00000000000 --- a/agent/component/rewrite.py +++ /dev/null @@ -1,94 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from abc import ABC -from agent.component import GenerateParam, Generate -from rag.prompts import full_question - - -class RewriteQuestionParam(GenerateParam): - """ - Define the QuestionRewrite component parameters. - """ - - def __init__(self): - super().__init__() - self.temperature = 0.9 - self.prompt = "" - self.language = "" - - def check(self): - super().check() - - -class RewriteQuestion(Generate, ABC): - component_name = "RewriteQuestion" - - def _run(self, history, **kwargs): - hist = self._canvas.get_history(self._param.message_history_window_size) - query = self.get_input() - query = str(query["content"][0]) if "content" in query else "" - messages = [h for h in hist if h["role"]!="system"] - if messages[-1]["role"] != "user": - messages.append({"role": "user", "content": query}) - ans = full_question(self._canvas.get_tenant_id(), self._param.llm_id, messages, self.gen_lang(self._param.language)) - self._canvas.history.pop() - self._canvas.history.append(("user", ans)) - return RewriteQuestion.be_output(ans) - - @staticmethod - def gen_lang(language): - # convert code lang to language word for the prompt - language_dict = {'af': 'Afrikaans', 'ak': 'Akan', 'sq': 'Albanian', 'ws': 'Samoan', 'am': 'Amharic', - 'ar': 'Arabic', 'hy': 'Armenian', 'az': 'Azerbaijani', 'eu': 'Basque', 'be': 'Belarusian', - 'bem': 'Bemba', 'bn': 'Bengali', 'bh': 'Bihari', - 'xx-bork': 'Bork', 'bs': 'Bosnian', 'br': 'Breton', 'bg': 'Bulgarian', 'bt': 'Bhutani', - 'km': 'Cambodian', 'ca': 'Catalan', 'chr': 'Cherokee', 'ny': 'Chichewa', 'zh-cn': 'Chinese', - 'zh-tw': 'Chinese', 'co': 'Corsican', - 'hr': 'Croatian', 'cs': 'Czech', 'da': 'Danish', 'nl': 'Dutch', 'xx-elmer': 'Elmer', - 'en': 'English', 'eo': 'Esperanto', 'et': 'Estonian', 'ee': 'Ewe', 'fo': 'Faroese', - 'tl': 'Filipino', 'fi': 'Finnish', 'fr': 'French', - 'fy': 'Frisian', 'gaa': 'Ga', 'gl': 'Galician', 'ka': 'Georgian', 'de': 'German', - 'el': 'Greek', 'kl': 'Greenlandic', 'gn': 'Guarani', 'gu': 'Gujarati', 'xx-hacker': 'Hacker', - 'ht': 'Haitian Creole', 'ha': 'Hausa', 'haw': 'Hawaiian', - 'iw': 'Hebrew', 'hi': 'Hindi', 'hu': 'Hungarian', 'is': 'Icelandic', 'ig': 'Igbo', - 'id': 'Indonesian', 'ia': 'Interlingua', 'ga': 'Irish', 'it': 'Italian', 'ja': 'Japanese', - 'jw': 'Javanese', 'kn': 'Kannada', 'kk': 'Kazakh', 'rw': 'Kinyarwanda', - 'rn': 'Kirundi', 'xx-klingon': 'Klingon', 'kg': 'Kongo', 'ko': 'Korean', 'kri': 'Krio', - 'ku': 'Kurdish', 'ckb': 'Kurdish (Sorani)', 'ky': 'Kyrgyz', 'lo': 'Laothian', 'la': 'Latin', - 'lv': 'Latvian', 'ln': 'Lingala', 'lt': 'Lithuanian', - 'loz': 'Lozi', 'lg': 'Luganda', 'ach': 'Luo', 'mk': 'Macedonian', 'mg': 'Malagasy', - 'ms': 'Malay', 'ml': 'Malayalam', 'mt': 'Maltese', 'mv': 'Maldivian', 'mi': 'Maori', - 'mr': 'Marathi', 'mfe': 'Mauritian Creole', 'mo': 'Moldavian', 'mn': 'Mongolian', - 'sr-me': 'Montenegrin', 'my': 'Burmese', 'ne': 'Nepali', 'pcm': 'Nigerian Pidgin', - 'nso': 'Northern Sotho', 'no': 'Norwegian', 'nn': 'Norwegian Nynorsk', 'oc': 'Occitan', - 'or': 'Oriya', 'om': 'Oromo', 'ps': 'Pashto', 'fa': 'Persian', - 'xx-pirate': 'Pirate', 'pl': 'Polish', 'pt': 'Portuguese', 'pt-br': 'Portuguese (Brazilian)', - 'pt-pt': 'Portuguese (Portugal)', 'pa': 'Punjabi', 'qu': 'Quechua', 'ro': 'Romanian', - 'rm': 'Romansh', 'nyn': 'Runyankole', 'ru': 'Russian', 'gd': 'Scots Gaelic', - 'sr': 'Serbian', 'sh': 'Serbo-Croatian', 'st': 'Sesotho', 'tn': 'Setswana', - 'crs': 'Seychellois Creole', 'sn': 'Shona', 'sd': 'Sindhi', 'si': 'Sinhalese', 'sk': 'Slovak', - 'sl': 'Slovenian', 'so': 'Somali', 'es': 'Spanish', 'es-419': 'Spanish (Latin America)', - 'su': 'Sundanese', - 'sw': 'Swahili', 'sv': 'Swedish', 'tg': 'Tajik', 'ta': 'Tamil', 'tt': 'Tatar', 'te': 'Telugu', - 'th': 'Thai', 'ti': 'Tigrinya', 'to': 'Tongan', 'lua': 'Tshiluba', 'tum': 'Tumbuka', - 'tr': 'Turkish', 'tk': 'Turkmen', 'tw': 'Twi', - 'ug': 'Uyghur', 'uk': 'Ukrainian', 'ur': 'Urdu', 'uz': 'Uzbek', 'vu': 'Vanuatu', - 'vi': 'Vietnamese', 'cy': 'Welsh', 'wo': 'Wolof', 'xh': 'Xhosa', 'yi': 'Yiddish', - 'yo': 'Yoruba', 'zu': 'Zulu'} - if language in language_dict: - return language_dict[language] - else: - return "" diff --git a/agent/component/string_transform.py b/agent/component/string_transform.py new file mode 100644 index 00000000000..444161f721a --- /dev/null +++ b/agent/component/string_transform.py @@ -0,0 +1,115 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import re +from abc import ABC +from typing import Any + +from jinja2 import Template as Jinja2Template +from agent.component.base import ComponentParamBase +from common.connection_utils import timeout +from .message import Message + + +class StringTransformParam(ComponentParamBase): + """ + Define the code sandbox component parameters. + """ + + def __init__(self): + super().__init__() + self.method = "split" + self.script = "" + self.split_ref = "" + self.delimiters = [","] + self.outputs = {"result": {"value": "", "type": "string"}} + + def check(self): + self.check_valid_value(self.method, "Support method", ["split", "merge"]) + self.check_empty(self.delimiters, "delimiters") + + +class StringTransform(Message, ABC): + component_name = "StringTransform" + + def get_input_elements(self) -> dict[str, Any]: + return self.get_input_elements_from_text(self._param.script) + + def get_input_form(self) -> dict[str, dict]: + if self._param.method == "split": + return { + "line": { + "name": "String", + "type": "line" + } + } + return {k: { + "name": o["name"], + "type": "line" + } for k, o in self.get_input_elements_from_text(self._param.script).items()} + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 10*60))) + def _invoke(self, **kwargs): + if self.check_if_canceled("StringTransform processing"): + return + + if self._param.method == "split": + self._split(kwargs.get("line")) + else: + self._merge(kwargs) + + def _split(self, line:str|None = None): + if self.check_if_canceled("StringTransform split processing"): + return + + var = self._canvas.get_variable_value(self._param.split_ref) if not line else line + if not var: + var = "" + assert isinstance(var, str), "The input variable is not a string: {}".format(type(var)) + self.set_input_value(self._param.split_ref, var) + + res = [] + for i,s in enumerate(re.split(r"(%s)"%("|".join([re.escape(d) for d in self._param.delimiters])), var, flags=re.DOTALL)): + if i % 2 == 1: + continue + res.append(s) + self.set_output("result", res) + + def _merge(self, kwargs:dict[str, str] = {}): + if self.check_if_canceled("StringTransform merge processing"): + return + + script = self._param.script + script, kwargs = self.get_kwargs(script, kwargs, self._param.delimiters[0]) + + if self._is_jinjia2(script): + template = Jinja2Template(script) + try: + script = template.render(kwargs) + except Exception: + pass + + for k,v in kwargs.items(): + if not v: + v = "" + script = re.sub(k, lambda match: v, script) + + self.set_output("result", script) + + def thoughts(self) -> str: + return f"It's {self._param.method}ing." + + diff --git a/agent/component/switch.py b/agent/component/switch.py index d791627d797..85e6cd03baf 100644 --- a/agent/component/switch.py +++ b/agent/component/switch.py @@ -13,8 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import numbers +import os from abc import ABC +from typing import Any + from agent.component.base import ComponentBase, ComponentParamBase +from common.connection_utils import timeout class SwitchParam(ComponentParamBase): @@ -34,7 +39,7 @@ def __init__(self): } """ self.conditions = [] - self.end_cpn_id = "answer:0" + self.end_cpn_ids = [] self.operators = ['contains', 'not contains', 'start with', 'end with', 'empty', 'not empty', '=', '≠', '>', '<', '≥', '≤'] @@ -43,54 +48,55 @@ def check(self): for cond in self.conditions: if not cond["to"]: raise ValueError("[Switch] 'To' can not be empty!") + self.check_empty(self.end_cpn_ids, "[Switch] the ELSE/Other destination can not be empty.") + def get_input_form(self) -> dict[str, dict]: + return { + "urls": { + "name": "URLs", + "type": "line" + } + } class Switch(ComponentBase, ABC): component_name = "Switch" - def get_dependent_components(self): - res = [] - for cond in self._param.conditions: - for item in cond["items"]: - if not item["cpn_id"]: - continue - if item["cpn_id"].lower().find("begin") >= 0 or item["cpn_id"].lower().find("answer") >= 0: - continue - cid = item["cpn_id"].split("@")[0] - res.append(cid) + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 3))) + def _invoke(self, **kwargs): + if self.check_if_canceled("Switch processing"): + return - return list(set(res)) - - def _run(self, history, **kwargs): for cond in self._param.conditions: + if self.check_if_canceled("Switch processing"): + return + res = [] for item in cond["items"]: + if self.check_if_canceled("Switch processing"): + return + if not item["cpn_id"]: continue - cid = item["cpn_id"].split("@")[0] - if item["cpn_id"].find("@") > 0: - cpn_id, key = item["cpn_id"].split("@") - for p in self._canvas.get_component(cid)["obj"]._param.query: - if p["key"] == key: - res.append(self.process_operator(p.get("value",""), item["operator"], item.get("value", ""))) - break - else: - out = self._canvas.get_component(cid)["obj"].output(allow_partial=False)[1] - cpn_input = "" if "content" not in out.columns else " ".join([str(s) for s in out["content"]]) - res.append(self.process_operator(cpn_input, item["operator"], item.get("value", ""))) - + cpn_v = self._canvas.get_variable_value(item["cpn_id"]) + self.set_input_value(item["cpn_id"], cpn_v) + operatee = item.get("value", "") + if isinstance(cpn_v, numbers.Number): + operatee = float(operatee) + res.append(self.process_operator(cpn_v, item["operator"], operatee)) if cond["logical_operator"] != "and" and any(res): - return Switch.be_output(cond["to"]) + self.set_output("next", [self._canvas.get_component_name(cpn_id) for cpn_id in cond["to"]]) + self.set_output("_next", cond["to"]) + return if all(res): - return Switch.be_output(cond["to"]) - - return Switch.be_output(self._param.end_cpn_id) + self.set_output("next", [self._canvas.get_component_name(cpn_id) for cpn_id in cond["to"]]) + self.set_output("_next", cond["to"]) + return - def process_operator(self, input: str, operator: str, value: str) -> bool: - if not isinstance(input, str) or not isinstance(value, str): - raise ValueError('Invalid input or value type: string') + self.set_output("next", [self._canvas.get_component_name(cpn_id) for cpn_id in self._param.end_cpn_ids]) + self.set_output("_next", self._param.end_cpn_ids) + def process_operator(self, input: Any, operator: str, value: Any) -> bool: if operator == "contains": return True if value.lower() in input.lower() else False elif operator == "not contains": @@ -128,4 +134,7 @@ def process_operator(self, input: str, operator: str, value: str) -> bool: except Exception: return True if input <= value else False - raise ValueError('Not supported operator' + operator) \ No newline at end of file + raise ValueError('Not supported operator' + operator) + + def thoughts(self) -> str: + return "I’m weighing a few options and will pick the next step shortly." diff --git a/agent/component/template.py b/agent/component/template.py deleted file mode 100644 index ab02a111b20..00000000000 --- a/agent/component/template.py +++ /dev/null @@ -1,147 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import json -import re - -from jinja2 import StrictUndefined -from jinja2.sandbox import SandboxedEnvironment - -from agent.component.base import ComponentBase, ComponentParamBase - - -class TemplateParam(ComponentParamBase): - """ - Define the Generate component parameters. - """ - - def __init__(self): - super().__init__() - self.content = "" - self.parameters = [] - - def check(self): - self.check_empty(self.content, "[Template] Content") - return True - - -class Template(ComponentBase): - component_name = "Template" - - def get_dependent_components(self): - inputs = self.get_input_elements() - cpnts = set([i["key"] for i in inputs if i["key"].lower().find("answer") < 0 and i["key"].lower().find("begin") < 0]) - return list(cpnts) - - def get_input_elements(self): - key_set = set([]) - res = [] - for r in re.finditer(r"\{([a-z]+[:@][a-z0-9_-]+)\}", self._param.content, flags=re.IGNORECASE): - cpn_id = r.group(1) - if cpn_id in key_set: - continue - if cpn_id.lower().find("begin@") == 0: - cpn_id, key = cpn_id.split("@") - for p in self._canvas.get_component(cpn_id)["obj"]._param.query: - if p["key"] != key: - continue - res.append({"key": r.group(1), "name": p["name"]}) - key_set.add(r.group(1)) - continue - cpn_nm = self._canvas.get_component_name(cpn_id) - if not cpn_nm: - continue - res.append({"key": cpn_id, "name": cpn_nm}) - key_set.add(cpn_id) - return res - - def _run(self, history, **kwargs): - content = self._param.content - - self._param.inputs = [] - for para in self.get_input_elements(): - if para["key"].lower().find("begin@") == 0: - cpn_id, key = para["key"].split("@") - for p in self._canvas.get_component(cpn_id)["obj"]._param.query: - if p["key"] == key: - value = p.get("value", "") - self.make_kwargs(para, kwargs, value) - - origin_pattern = "{begin@" + key + "}" - new_pattern = "begin_" + key - content = content.replace(origin_pattern, new_pattern) - kwargs[new_pattern] = kwargs.pop(origin_pattern, "") - break - else: - assert False, f"Can't find parameter '{key}' for {cpn_id}" - continue - - component_id = para["key"] - cpn = self._canvas.get_component(component_id)["obj"] - if cpn.component_name.lower() == "answer": - hist = self._canvas.get_history(1) - if hist: - hist = hist[0]["content"] - else: - hist = "" - self.make_kwargs(para, kwargs, hist) - - if ":" in component_id: - origin_pattern = "{" + component_id + "}" - new_pattern = component_id.replace(":", "_") - content = content.replace(origin_pattern, new_pattern) - kwargs[new_pattern] = kwargs.pop(component_id, "") - continue - - _, out = cpn.output(allow_partial=False) - - result = "" - if "content" in out.columns: - result = "\n".join([o if isinstance(o, str) else str(o) for o in out["content"]]) - - self.make_kwargs(para, kwargs, result) - - env = SandboxedEnvironment( - autoescape=True, - undefined=StrictUndefined, - ) - template = env.from_string(content) - - try: - content = template.render(kwargs) - except Exception: - pass - - for n, v in kwargs.items(): - if not isinstance(v, str): - try: - v = json.dumps(v, ensure_ascii=False) - except Exception: - pass - # Process backslashes in strings, Use Lambda function to avoid escape issues - if isinstance(v, str): - v = v.replace("\\", "\\\\") - content = re.sub(r"\{%s\}" % re.escape(n), lambda match: v, content) - content = re.sub(r"(#+)", r" \1 ", content) - - return Template.be_output(content) - - def make_kwargs(self, para, kwargs, value): - self._param.inputs.append({"component_id": para["key"], "content": value}) - try: - value = json.loads(value) - except Exception: - pass - kwargs[para["key"]] = value diff --git a/agent/component/varaiable_aggregator.py b/agent/component/varaiable_aggregator.py new file mode 100644 index 00000000000..63d10aca242 --- /dev/null +++ b/agent/component/varaiable_aggregator.py @@ -0,0 +1,84 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from typing import Any +import os + +from common.connection_utils import timeout +from agent.component.base import ComponentBase, ComponentParamBase + + +class VariableAggregatorParam(ComponentParamBase): + """ + Parameters for VariableAggregator + + - groups: list of dicts {"group_name": str, "variables": [variable selectors]} + """ + + def __init__(self): + super().__init__() + # each group expects: {"group_name": str, "variables": List[str]} + self.groups = [] + + def check(self): + self.check_empty(self.groups, "[VariableAggregator] groups") + for g in self.groups: + if not g.get("group_name"): + raise ValueError("[VariableAggregator] group_name can not be empty!") + if not g.get("variables"): + raise ValueError( + f"[VariableAggregator] variables of group `{g.get('group_name')}` can not be empty" + ) + if not isinstance(g.get("variables"), list): + raise ValueError( + f"[VariableAggregator] variables of group `{g.get('group_name')}` should be a list of strings" + ) + + def get_input_form(self) -> dict[str, dict]: + return { + "variables": { + "name": "Variables", + "type": "list", + } + } + + +class VariableAggregator(ComponentBase): + component_name = "VariableAggregator" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 3))) + def _invoke(self, **kwargs): + # Group mode: for each group, pick the first available variable + for group in self._param.groups: + gname = group.get("group_name") + + # record candidate selectors within this group + self.set_input_value(f"{gname}.variables", list(group.get("variables", []))) + for selector in group.get("variables", []): + val = self._canvas.get_variable_value(selector['value']) + if val: + self.set_output(gname, val) + break + + @staticmethod + def _to_object(value: Any) -> Any: + # Try to convert value to serializable object if it has to_object() + try: + return value.to_object() # type: ignore[attr-defined] + except Exception: + return value + + def thoughts(self) -> str: + return "Aggregating variables from canvas and grouping as configured." diff --git a/agent/component/webhook.py b/agent/component/webhook.py new file mode 100644 index 00000000000..c707d455626 --- /dev/null +++ b/agent/component/webhook.py @@ -0,0 +1,38 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from agent.component.base import ComponentParamBase, ComponentBase + + +class WebhookParam(ComponentParamBase): + + """ + Define the Begin component parameters. + """ + def __init__(self): + super().__init__() + + def get_input_form(self) -> dict[str, dict]: + return getattr(self, "inputs") + + +class Webhook(ComponentBase): + component_name = "Webhook" + + def _invoke(self, **kwargs): + pass + + def thoughts(self) -> str: + return "" diff --git a/agent/component/wencai.py b/agent/component/wencai.py deleted file mode 100644 index 8f8c3518144..00000000000 --- a/agent/component/wencai.py +++ /dev/null @@ -1,80 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from abc import ABC -import pandas as pd -import pywencai -from agent.component.base import ComponentBase, ComponentParamBase - - -class WenCaiParam(ComponentParamBase): - """ - Define the WenCai component parameters. - """ - - def __init__(self): - super().__init__() - self.top_n = 10 - self.query_type = "stock" - - def check(self): - self.check_positive_integer(self.top_n, "Top N") - self.check_valid_value(self.query_type, "Query type", - ['stock', 'zhishu', 'fund', 'hkstock', 'usstock', 'threeboard', 'conbond', 'insurance', - 'futures', 'lccp', - 'foreign_exchange']) - - -class WenCai(ComponentBase, ABC): - component_name = "WenCai" - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = ",".join(ans["content"]) if "content" in ans else "" - if not ans: - return WenCai.be_output("") - - try: - wencai_res = [] - res = pywencai.get(query=ans, query_type=self._param.query_type, perpage=self._param.top_n) - if isinstance(res, pd.DataFrame): - wencai_res.append({"content": res.to_markdown()}) - if isinstance(res, dict): - for item in res.items(): - if isinstance(item[1], list): - wencai_res.append({"content": item[0] + "\n" + pd.DataFrame(item[1]).to_markdown()}) - continue - if isinstance(item[1], str): - wencai_res.append({"content": item[0] + "\n" + item[1]}) - continue - if isinstance(item[1], dict): - if "meta" in item[1].keys(): - continue - wencai_res.append({"content": pd.DataFrame.from_dict(item[1], orient='index').to_markdown()}) - continue - if isinstance(item[1], pd.DataFrame): - if "image_url" in item[1].columns: - continue - wencai_res.append({"content": item[1].to_markdown()}) - continue - - wencai_res.append({"content": item[0] + "\n" + str(item[1])}) - except Exception as e: - return WenCai.be_output("**ERROR**: " + str(e)) - - if not wencai_res: - return WenCai.be_output("") - - return pd.DataFrame(wencai_res) diff --git a/agent/component/wikipedia.py b/agent/component/wikipedia.py deleted file mode 100644 index 8ccadca21f8..00000000000 --- a/agent/component/wikipedia.py +++ /dev/null @@ -1,67 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -from abc import ABC -import wikipedia -import pandas as pd -from agent.component.base import ComponentBase, ComponentParamBase - - -class WikipediaParam(ComponentParamBase): - """ - Define the Wikipedia component parameters. - """ - - def __init__(self): - super().__init__() - self.top_n = 10 - self.language = "en" - - def check(self): - self.check_positive_integer(self.top_n, "Top N") - self.check_valid_value(self.language, "Wikipedia languages", - ['af', 'pl', 'ar', 'ast', 'az', 'bg', 'nan', 'bn', 'be', 'ca', 'cs', 'cy', 'da', 'de', - 'et', 'el', 'en', 'es', 'eo', 'eu', 'fa', 'fr', 'gl', 'ko', 'hy', 'hi', 'hr', 'id', - 'it', 'he', 'ka', 'lld', 'la', 'lv', 'lt', 'hu', 'mk', 'arz', 'ms', 'min', 'my', 'nl', - 'ja', 'nb', 'nn', 'ce', 'uz', 'pt', 'kk', 'ro', 'ru', 'ceb', 'sk', 'sl', 'sr', 'sh', - 'fi', 'sv', 'ta', 'tt', 'th', 'tg', 'azb', 'tr', 'uk', 'ur', 'vi', 'war', 'zh', 'yue']) - - -class Wikipedia(ComponentBase, ABC): - component_name = "Wikipedia" - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = " - ".join(ans["content"]) if "content" in ans else "" - if not ans: - return Wikipedia.be_output("") - - try: - wiki_res = [] - wikipedia.set_lang(self._param.language) - wiki_engine = wikipedia - for wiki_key in wiki_engine.search(ans, results=self._param.top_n): - page = wiki_engine.page(title=wiki_key, auto_suggest=False) - wiki_res.append({"content": '' + page.title + ' ' + page.summary}) - except Exception as e: - return Wikipedia.be_output("**ERROR**: " + str(e)) - - if not wiki_res: - return Wikipedia.be_output("") - - df = pd.DataFrame(wiki_res) - logging.debug(f"df: {df}") - return df diff --git a/agent/component/yahoofinance.py b/agent/component/yahoofinance.py deleted file mode 100644 index f31c7aed499..00000000000 --- a/agent/component/yahoofinance.py +++ /dev/null @@ -1,84 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -from abc import ABC -import pandas as pd -from agent.component.base import ComponentBase, ComponentParamBase -import yfinance as yf - - -class YahooFinanceParam(ComponentParamBase): - """ - Define the YahooFinance component parameters. - """ - - def __init__(self): - super().__init__() - self.info = True - self.history = False - self.count = False - self.financials = False - self.income_stmt = False - self.balance_sheet = False - self.cash_flow_statement = False - self.news = True - - def check(self): - self.check_boolean(self.info, "get all stock info") - self.check_boolean(self.history, "get historical market data") - self.check_boolean(self.count, "show share count") - self.check_boolean(self.financials, "show financials") - self.check_boolean(self.income_stmt, "income statement") - self.check_boolean(self.balance_sheet, "balance sheet") - self.check_boolean(self.cash_flow_statement, "cash flow statement") - self.check_boolean(self.news, "show news") - - -class YahooFinance(ComponentBase, ABC): - component_name = "YahooFinance" - - def _run(self, history, **kwargs): - ans = self.get_input() - ans = "".join(ans["content"]) if "content" in ans else "" - if not ans: - return YahooFinance.be_output("") - - yohoo_res = [] - try: - msft = yf.Ticker(ans) - if self._param.info: - yohoo_res.append({"content": "info:\n" + pd.Series(msft.info).to_markdown() + "\n"}) - if self._param.history: - yohoo_res.append({"content": "history:\n" + msft.history().to_markdown() + "\n"}) - if self._param.financials: - yohoo_res.append({"content": "calendar:\n" + pd.DataFrame(msft.calendar).to_markdown() + "\n"}) - if self._param.balance_sheet: - yohoo_res.append({"content": "balance sheet:\n" + msft.balance_sheet.to_markdown() + "\n"}) - yohoo_res.append( - {"content": "quarterly balance sheet:\n" + msft.quarterly_balance_sheet.to_markdown() + "\n"}) - if self._param.cash_flow_statement: - yohoo_res.append({"content": "cash flow statement:\n" + msft.cashflow.to_markdown() + "\n"}) - yohoo_res.append( - {"content": "quarterly cash flow statement:\n" + msft.quarterly_cashflow.to_markdown() + "\n"}) - if self._param.news: - yohoo_res.append({"content": "news:\n" + pd.DataFrame(msft.news).to_markdown() + "\n"}) - except Exception: - logging.exception("YahooFinance got exception") - - if not yohoo_res: - return YahooFinance.be_output("") - - return pd.DataFrame(yohoo_res) diff --git a/agent/templates/DB Assistant.json b/agent/templates/DB Assistant.json deleted file mode 100644 index 604cd3b9a0e..00000000000 --- a/agent/templates/DB Assistant.json +++ /dev/null @@ -1,890 +0,0 @@ -{ - "id": 6, - "title": "DB Assistant", - "description": "An advanced agent that converts user queries into SQL statements, executes the queries, and assesses and returns the results. You must prepare three knowledge bases: 1: DDL for your database; 2: Examples of user queries converted to SQL statements; 3: A comprehensive description of your database, including but not limited to tables and records. You are also required to configure the corresponding database.", - "canvas_type": "chatbot", - "dsl": { - "answer": [], - "components": { - "Answer:SocialAdsWonder": { - "downstream": [ - "RewriteQuestion:WildIdeasTell" - ], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": {}, - "params": {} - }, - "upstream": [ - "ExeSQL:QuietRosesRun", - "begin" - ] - }, - "ExeSQL:QuietRosesRun": { - "downstream": [ - "Answer:SocialAdsWonder" - ], - "obj": { - "component_name": "ExeSQL", - "inputs": [], - "output": {}, - "params": { - "database": "", - "db_type": "mysql", - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "host": "", - "llm_id": "deepseek-chat@DeepSeek", - "loop": 3, - "maxTokensEnabled": true, - "max_tokens": 512, - "password": "", - "port": 6630, - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "query": [], - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_n": 30, - "top_p": 0.3, - "username": "root" - } - }, - "upstream": [ - "Generate:BlueShirtsLaugh" - ] - }, - "Generate:BlueShirtsLaugh": { - "downstream": [ - "ExeSQL:QuietRosesRun" - ], - "obj": { - "component_name": "Generate", - "params": { - "cite": false, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "message_history_window_size": 1, - "parameters": [], - "presence_penalty": 0.4, - "prompt": "\n##The user provides a question and you provide SQL. You will only respond with SQL code and not with any explanations.\n\n##You may use the following DDL statements as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:SillyPartsCheer}.\n\n##You may use the following documentation as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:OddSingersRefuse}.\n\n##You may use the following SQL statements as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:BrownStreetsRhyme}.\n\n##Respond with only SQL code. Do not answer with any explanations -- just the code.", - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Retrieval:SillyPartsCheer", - "Retrieval:BrownStreetsRhyme", - "Retrieval:OddSingersRefuse" - ] - }, - "Retrieval:BrownStreetsRhyme": { - "downstream": [ - "Generate:BlueShirtsLaugh" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": {}, - "params": { - "empty_response": "Nothing found in Q->SQL!", - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "query": [ - { - "component_id": "Answer:SocialAdsWonder", - "type": "reference" - } - ], - "similarity_threshold": 0.2, - "top_n": 8 - } - }, - "upstream": [ - "RewriteQuestion:WildIdeasTell" - ] - }, - "Retrieval:OddSingersRefuse": { - "downstream": [ - "Generate:BlueShirtsLaugh" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": {}, - "params": { - "empty_response": "Nothing found in DB-Description!", - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "query": [ - { - "component_id": "Answer:SocialAdsWonder", - "type": "reference" - } - ], - "similarity_threshold": 0.2, - "top_n": 8 - } - }, - "upstream": [ - "RewriteQuestion:WildIdeasTell" - ] - }, - "Retrieval:SillyPartsCheer": { - "downstream": [ - "Generate:BlueShirtsLaugh" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": {}, - "params": { - "empty_response": "Nothing found in DDL!", - "kb_ids": [], - "keywords_similarity_weight": 0.1, - "query": [ - { - "component_id": "Answer:SocialAdsWonder", - "type": "reference" - } - ], - "similarity_threshold": 0.02, - "top_n": 18 - } - }, - "upstream": [ - "RewriteQuestion:WildIdeasTell" - ] - }, - "RewriteQuestion:WildIdeasTell": { - "downstream": [ - "Retrieval:OddSingersRefuse", - "Retrieval:BrownStreetsRhyme", - "Retrieval:SillyPartsCheer" - ], - "obj": { - "component_name": "RewriteQuestion", - "params": { - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 6, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - } - }, - "upstream": [ - "Answer:SocialAdsWonder" - ] - }, - "begin": { - "downstream": [ - "Answer:SocialAdsWonder" - ], - "obj": { - "component_name": "Begin", - "inputs": [], - "output": { - "content": { - "0": { - "content": "Hi! I'm your smart assistant. What can I do for you?" - } - } - }, - "params": {} - }, - "upstream": [] - } - }, - "embed_id": "BAAI/bge-large-zh-v1.5", - "graph": { - "edges": [ - { - "id": "xy-edge__ExeSQL:QuietRosesRunc-Answer:SocialAdsWonderc", - "markerEnd": "logo", - "source": "ExeSQL:QuietRosesRun", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:SocialAdsWonder", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__begin-Answer:SocialAdsWonderc", - "markerEnd": "logo", - "source": "begin", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:SocialAdsWonder", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Answer:SocialAdsWonderb-RewriteQuestion:WildIdeasTellc", - "markerEnd": "logo", - "source": "Answer:SocialAdsWonder", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "RewriteQuestion:WildIdeasTell", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__RewriteQuestion:WildIdeasTellb-Retrieval:OddSingersRefusec", - "markerEnd": "logo", - "source": "RewriteQuestion:WildIdeasTell", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:OddSingersRefuse", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__RewriteQuestion:WildIdeasTellb-Retrieval:BrownStreetsRhymec", - "markerEnd": "logo", - "source": "RewriteQuestion:WildIdeasTell", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:BrownStreetsRhyme", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__RewriteQuestion:WildIdeasTellb-Retrieval:SillyPartsCheerc", - "markerEnd": "logo", - "source": "RewriteQuestion:WildIdeasTell", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:SillyPartsCheer", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:BlueShirtsLaughc-ExeSQL:QuietRosesRunb", - "markerEnd": "logo", - "source": "Generate:BlueShirtsLaugh", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "ExeSQL:QuietRosesRun", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Retrieval:SillyPartsCheerb-Generate:BlueShirtsLaughb", - "markerEnd": "logo", - "source": "Retrieval:SillyPartsCheer", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:BlueShirtsLaugh", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Retrieval:BrownStreetsRhymeb-Generate:BlueShirtsLaughb", - "markerEnd": "logo", - "source": "Retrieval:BrownStreetsRhyme", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:BlueShirtsLaugh", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Retrieval:OddSingersRefuseb-Generate:BlueShirtsLaughb", - "markerEnd": "logo", - "source": "Retrieval:OddSingersRefuse", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:BlueShirtsLaugh", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - } - ], - "nodes": [ - { - "data": { - "label": "Begin", - "name": "begin" - }, - "dragging": false, - "height": 44, - "id": "begin", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -707.997699967585, - "y": 271.71609546793474 - }, - "positionAbsolute": { - "x": -707.997699967585, - "y": 271.71609546793474 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "beginNode", - "width": 200 - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "Interface" - }, - "dragging": false, - "height": 44, - "id": "Answer:SocialAdsWonder", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -265.59460323639587, - "y": 271.1879130306969 - }, - "positionAbsolute": { - "x": -58.36886074370702, - "y": 272.1213623212045 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "empty_response": "Nothing found in DDL!", - "kb_ids": [], - "keywords_similarity_weight": 0.1, - "query": [ - { - "component_id": "Answer:SocialAdsWonder", - "type": "reference" - } - ], - "similarity_threshold": 0.02, - "top_n": 18 - }, - "label": "Retrieval", - "name": "DDL" - }, - "dragging": false, - "height": 106, - "id": "Retrieval:SillyPartsCheer", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 194.69889765569846, - "y": 61.49435233230193 - }, - "positionAbsolute": { - "x": 198.3020069445181, - "y": -0.9595420072386389 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "empty_response": "Nothing found in Q->SQL!", - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "query": [ - { - "component_id": "Answer:SocialAdsWonder", - "type": "reference" - } - ], - "similarity_threshold": 0.2, - "top_n": 8 - }, - "label": "Retrieval", - "name": "Q->SQL" - }, - "dragging": false, - "height": 106, - "id": "Retrieval:BrownStreetsRhyme", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 240.78282320440022, - "y": 162.66081324653166 - }, - "positionAbsolute": { - "x": 231.17453176754782, - "y": 123.02661106951555 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "empty_response": "Nothing found in DB-Description!", - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "query": [ - { - "component_id": "Answer:SocialAdsWonder", - "type": "reference" - } - ], - "similarity_threshold": 0.2, - "top_n": 8 - }, - "label": "Retrieval", - "name": "DB Description" - }, - "dragging": false, - "height": 106, - "id": "Retrieval:OddSingersRefuse", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 284.5720579655624, - "y": 246.75395940479467 - }, - "positionAbsolute": { - "x": 267.7575479510707, - "y": 249.15603226400776 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "Based on the result of the SQL execution, returns the error message to the large model if any errors occur; otherwise, returns the result to the user." - }, - "label": "Note", - "name": "N: Analyze SQL" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 165, - "id": "Note:HeavyIconsFollow", - "measured": { - "height": 165, - "width": 347 - }, - "position": { - "x": -709.8631299685773, - "y": 96.50319908555313 - }, - "positionAbsolute": { - "x": -626.6563777191027, - "y": -48.82220889683933 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 176, - "width": 266 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 347 - }, - { - "data": { - "form": { - "text": "Receives the user's database-related questions and displays the large model's response." - }, - "label": "Note", - "name": "N: Interface" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 159, - "id": "Note:PinkTaxesClean", - "measured": { - "height": 159, - "width": 259 - }, - "position": { - "x": -253.39933811515345, - "y": 353.7538896054877 - }, - "positionAbsolute": { - "x": -52.004609812312424, - "y": 336.95180237635077 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 162, - "width": 210 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 259 - }, - { - "data": { - "form": { - "text": "Searches for description about meanings of tables and fields." - }, - "label": "Note", - "name": "N:DB Description" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:IcyTreesPeel", - "measured": { - "height": 128, - "width": 251 - }, - "position": { - "x": 280.8431980571563, - "y": 394.1463067004627 - }, - "positionAbsolute": { - "x": 280.8431980571563, - "y": 394.1463067004627 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 251 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 251 - }, - { - "data": { - "form": { - "text": "Searches for samples about question to SQL.\nPlease check this dataset: https://huggingface.co/datasets/InfiniFlow/text2sql" - }, - "label": "Note", - "name": "N: Q->SQL" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 143, - "id": "Note:HugeGroupsScream", - "measured": { - "height": 143, - "width": 390 - }, - "position": { - "x": 612.8793199038756, - "y": 169.1868576959871 - }, - "positionAbsolute": { - "x": 606.1206536213404, - "y": 113.09441734894426 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 131, - "width": 387 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 390 - }, - { - "data": { - "form": { - "text": "DDL(Data Definition Language).\n\nSearches for relevant database creation statements.\n\nIt should bind with a KB to which DDL is dumped in.\nYou could use 'General' as parsing method and ';' as delimiter." - }, - "label": "Note", - "name": "N: DDL" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 208, - "id": "Note:GreenCrewsArrive", - "measured": { - "height": 208, - "width": 467 - }, - "position": { - "x": 649.3481710005742, - "y": -87.70873445087781 - }, - "positionAbsolute": { - "x": 545.3423934788841, - "y": -166.58872868890683 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 266, - "width": 266 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 467 - }, - { - "data": { - "form": { - "text": "The large model learns which tables may be available based on the responses from three knowledge bases and converts the user's input into SQL statements." - }, - "label": "Note", - "name": "N: Generate SQL" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 196, - "id": "Note:EightTurtlesLike", - "measured": { - "height": 196, - "width": 341 - }, - "position": { - "x": 134.0070839275931, - "y": -345.41228234051727 - }, - "positionAbsolute": { - "x": 222.2150747084395, - "y": -445.32694170868734 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 175, - "width": 265 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 341 - }, - { - "data": { - "form": { - "text": "Executes the SQL statement in the database and returns the result.\n\nAfter configuring an accessible database, press 'Test' to ensure the accessibility.\n\nThe large model modifies the original SQL statement based on the error message and returns the modified SQL statement." - }, - "label": "Note", - "name": "N: Execute SQL" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 276, - "id": "Note:FreshKidsTalk", - "measured": { - "height": 276, - "width": 336 - }, - "position": { - "x": -304.3577648765364, - "y": -288.054469323955 - }, - "positionAbsolute": { - "x": -251.5866574377311, - "y": -372.2192837064241 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 178, - "width": 346 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 336 - }, - { - "data": { - "form": { - "database": "", - "db_type": "mysql", - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "host": "", - "llm_id": "deepseek-chat@DeepSeek", - "loop": 3, - "maxTokensEnabled": true, - "max_tokens": 512, - "password": "", - "port": 6630, - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "query": [], - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_n": 30, - "top_p": 0.3, - "username": "root" - }, - "label": "ExeSQL", - "name": "ExeSQL" - }, - "dragging": false, - "id": "ExeSQL:QuietRosesRun", - "measured": { - "height": 64, - "width": 200 - }, - "position": { - "x": -318.61920731731163, - "y": 3.5145731711609436 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode" - }, - { - "data": { - "form": { - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 6, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "RewriteQuestion", - "name": "RefineQuestion" - }, - "dragging": false, - "id": "RewriteQuestion:WildIdeasTell", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": -7.734116293705583, - "y": 236.92372325779243 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "rewriteNode" - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "\n##The user provides a question and you provide SQL. You will only respond with SQL code and not with any explanations.\n\n##You may use the following DDL statements as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:SillyPartsCheer}.\n\n##You may use the following documentation as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:OddSingersRefuse}.\n\n##You may use the following SQL statements as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:BrownStreetsRhyme}.\n\n##Respond with only SQL code. Do not answer with any explanations -- just the code.", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Generate SQL Statement LLM" - }, - "dragging": false, - "id": "Generate:BlueShirtsLaugh", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 147.62383788095065, - "y": -116.47462293167156 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - } - ] - }, - "history": [], - "messages": [], - "path": [], - "reference": [] - }, - "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJAAAACLCAYAAACOVxDgAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsEAAA7BAbiRa+0AAFZSSURBVHhe7b0HnF1Xde+/bm/TNDMaSZa73I2NKw6GQDCfhCS8ACF5DxMgCSGE0JKXSkzKSyH5J05Ih+Qln/QCOJAQegKYEIMxtgGDuy3Jlixp1Kfdub2833efu2bOjO5IYzUEfy1pz2n77LLWb6+yzz7nJroiO02n6Sgp2dueptN0VHQaQKfpmOg0gE7TMdFpAJ2mY6LTADpNx0SnAXSajon+fwcgZi1Oz1wcP/qGnQda3uxEIrFwLr4Psc85UqfTWdh38usngpa3EzpSXSeyPcebvmkmEr0bR8N4v5ctAFtOlLmcTV7PStunS5Qfr+doyznZ9E07Ew0QSK1Wy9rttjUajZCazWY4zxYhlUoly2QyIZ/fB7kwXbBx8nOeoGQy8gY4TqVSYcu5+D4pvh+nfvV8I9A3PIAQPGCo1+thW61WrVKpBNBwDGjiYHKAQAhsYGDA1q5dG/ZhBckF7cd+zonj5eT52ZKo3/dJXqbvAyxSOp0OW875+XhdpzqdEgDyJsBc9kn9mAgAAISDhC3AqdVqASwIDYDEhQctL8uvkY+6RkdHbWxsLORzzeT3rkRcXw3rVsrDea/D63MwsfWUzWYPaX+/Mo/U3hNFp5QGijMV4thB41pmamoqJPbj2gTGcy/MXk2XvC7PC4AAkmurkykQ2tCvzQ4i+gaQMLVs+7XtZLY3TqecCUMrABoA4maJJrpQ2ec6CQ3k2odjrgGg1TKT/AiHOqF169bZ4OBgOE86WeTt9Xq9n34Oci3kIMrlcmGf9PWkkwogZ04/QssAhn6AiGsV33eGIvz4vYDO74Woz+8huXD8fj/HPYx2QIRjHdduJ4PioOnHI9rj1yGAT8rn8yH1M3VO3scTQScFQN4Br8o7A1NciwACEuSMOFKn/Xo8H2XgHwEkL5N6vW7K9vJdKK6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CFhBMMaNgSSXEOMMWJ+50oo19fTxadcgByWn4M9WMSeRi5AMfB5Akh+pY8kI/yeNnL64GOViDebi8T4aN9ADhA8Vd7fB+AsAUsnFuuTZ28PC8/3r7lxyeTTjkf6HgSwFme3DknceyAih9DcUEuZxHCWi5ojxzZunZhH1Cw78eA51QyQcdK3xQAogskF5Sf8/0jkbMgvl3tvU7xuldLR1PPqUbfNBpouTC8W/HzJ1JY/ernON4O11p+DjqRbToZ9E1twk4mwcZ+APpmp9MAOk3HRP1d/tN0mlZJpwF0mo6BzP4fggqB25jU6csAAAAASUVORK5CYII=" -} diff --git a/agent/templates/HR_callout_zh.json b/agent/templates/HR_callout_zh.json deleted file mode 100644 index 2d73cd8e63d..00000000000 --- a/agent/templates/HR_callout_zh.json +++ /dev/null @@ -1,1806 +0,0 @@ -{ - "id": 2, - "title": "HR recruitment pitch assistant (Chinese)", - "description": "A recruitment pitch assistant capable of pitching a candidate, presenting a job opportunity, addressing queries, and requesting the candidate's contact details. Let's begin by linking a knowledge base containing the job description in 'Retrieval'!", - "canvas_type": "chatbot", - "dsl": { - "answer": [], - "components": { - "Answer:TwentyMugsDeny": { - "downstream": [ - "categorize:1" - ], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "Message:MajorPigsYell", - "Generate:TruePawsReport", - "Generate:ToughLawsCheat", - "Generate:KindCarrotsSit", - "Generate:DirtyToolsTrain", - "Generate:FluffyPillowsGrow", - "Generate:ProudEarsWorry" - ] - }, - "Generate:DirtyToolsTrain": { - "downstream": [ - "Answer:TwentyMugsDeny" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,当你提出加微信时对方表示拒绝。你需要耐心礼貌的回应候选人,表示对于保护隐私信息给予理解,也可以询问他对该职位的看法和顾虑。并在恰当的时机再次询问微信联系方式。也可以鼓励候选人主动与你取得联系。你的微信号是weixin_kevin,E-mail是kkk@ragflow.com。说话不要重复。不要总是您好。", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "categorize:1" - ] - }, - "Generate:FluffyPillowsGrow": { - "downstream": [ - "Answer:TwentyMugsDeny" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [ - { - "component_id": "Retrieval:ColdEelsArrive", - "id": "5166a107-e859-4c71-99a2-3a216c775347", - "key": "jd" - } - ], - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,候选人问了有关职位或公司的问题,你根据以下职位信息回答。如果职位信息中不包含候选人的问题就回答不清楚、不知道、有待确认等。回答完后引导候选人加微信号,如:\n - 方便加一下微信吗,我把JD发您看看?\n - 微信号多少,我把详细职位JD发您?\n 职位信息如下:\n {Retrieval:ColdEelsArrive}\n 职位信息如上。", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Retrieval:ColdEelsArrive" - ] - }, - "Generate:KindCarrotsSit": { - "downstream": [ - "Answer:TwentyMugsDeny" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,候选人表示不反感加微信,如果对方已经报了微信号,表示感谢和信任并表示马上会加上;如果没有,则问对方微信号多少。你的微信号是weixin_kevin,E-mail是kkk@ragflow.com。说话不要重复。不要总是您好。", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "categorize:1" - ] - }, - "Generate:ProudEarsWorry": { - "downstream": [ - "Answer:TwentyMugsDeny" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,现在候选人的聊了和职位无关的话题,请耐心的回应候选人,并将话题往该AGI的职位上带,最好能要到候选人微信号以便后面保持联系。", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "categorize:0" - ] - }, - "Generate:ToughLawsCheat": { - "downstream": [ - "Answer:TwentyMugsDeny" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,现在候选人的聊了和职位无关的话题,请耐心的回应候选人,并将话题往该AGI的职位上带,最好能要到候选人微信号以便后面保持联系。", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "categorize:1" - ] - }, - "Generate:TruePawsReport": { - "downstream": [ - "Answer:TwentyMugsDeny" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,候选人问了有关职位或公司的问题,你根据以下职位信息回答。如果职位信息中不包含候选人的问题就回答不清楚、不知道、有待确认等。回答完后引导候选人加微信号,如:\n - 方便加一下微信吗,我把JD发您看看?\n - 微信号多少,我把详细职位JD发您?\n 职位信息如下:\n {Retrieval:ShaggyRadiosRetire}\n 职位信息如上。", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Retrieval:ShaggyRadiosRetire" - ] - }, - "Message:MajorPigsYell": { - "downstream": [ - "Answer:TwentyMugsDeny" - ], - "obj": { - "component_name": "Message", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "messages": [ - "我简单介绍一下:\nRAGFlow 是一款基于深度文档理解构建的开源 RAG(Retrieval-Augmented Generation)引擎。RAGFlow 可以为各种规模的企业及个人提供一套精简的 RAG 工作流程,结合大语言模型(LLM)针对用户各类不同的复杂格式数据提供可靠的问答以及有理有据的引用。https://github.com/infiniflow/ragflow\n您那边还有什么要了解的?" - ], - "output": null, - "output_var_name": "output", - "query": [] - } - }, - "upstream": [ - "categorize:0" - ] - }, - "Retrieval:ColdEelsArrive": { - "downstream": [ - "Generate:FluffyPillowsGrow" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "empty_response": "", - "inputs": [], - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [], - "rerank_id": "", - "similarity_threshold": 0.2, - "top_k": 1024, - "top_n": 6 - } - }, - "upstream": [ - "categorize:1" - ] - }, - "Retrieval:ShaggyRadiosRetire": { - "downstream": [ - "Generate:TruePawsReport" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "empty_response": "", - "inputs": [], - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [], - "rerank_id": "", - "similarity_threshold": 0.2, - "top_k": 1024, - "top_n": 6 - } - }, - "upstream": [ - "categorize:0" - ] - }, - "answer:0": { - "downstream": [ - "categorize:0" - ], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "begin", - "message:reject" - ] - }, - "begin": { - "downstream": [ - "answer:0" - ], - "obj": { - "component_name": "Begin", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "prologue": "您好!我是英飞流负责招聘的HR,了解到您是这方面的大佬,然后冒昧的就联系到您。这边有个机会想和您分享,RAGFlow正在招聘您这个岗位的资深的工程师不知道您那边是不是感兴趣?", - "query": [] - } - }, - "upstream": [] - }, - "categorize:0": { - "downstream": [ - "message:reject", - "Retrieval:ShaggyRadiosRetire", - "Generate:ProudEarsWorry", - "Message:MajorPigsYell" - ], - "obj": { - "component_name": "Categorize", - "inputs": [], - "output": null, - "params": { - "category_description": { - "answer": { - "description": "该问题关于职位本身或公司的信息。", - "examples": "什么岗位?\n汇报对象是谁?\n公司多少人?\n公司有啥产品?\n具体工作内容是啥?\n地点哪里?\n双休吗?", - "to": "Retrieval:ShaggyRadiosRetire" - }, - "casual": { - "description": "该问题不关于职位本身或公司的信息,属于闲聊。", - "examples": "你好\n好久不见\n你男的女的?\n你是猴子派来的救兵吗?\n上午开会了?\n你叫啥?\n最近市场如何?生意好做吗?", - "to": "Generate:ProudEarsWorry" - }, - "interested": { - "description": "该回答表示他对于该职位感兴趣。", - "examples": "嗯\n说吧\n说说看\n还好吧\n是的\n哦\nyes\n具体说说", - "to": "Message:MajorPigsYell" - }, - "reject": { - "description": "该回答表示他对于该职位不感兴趣,或感觉受到骚扰。", - "examples": "不需要\n不感兴趣\n暂时不看\n不要\nno\n我已经不干这个了\n我不是这个方向的", - "to": "message:reject" - } - }, - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 512, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "answer:0" - ] - }, - "categorize:1": { - "downstream": [ - "Retrieval:ColdEelsArrive", - "Generate:ToughLawsCheat", - "Generate:KindCarrotsSit", - "Generate:DirtyToolsTrain" - ], - "obj": { - "component_name": "Categorize", - "inputs": [], - "output": null, - "params": { - "category_description": { - "about_job": { - "description": "该问题关于职位本身或公司的信息。", - "examples": "什么岗位?\n汇报对象是谁?\n公司多少人?\n公司有啥产品?\n具体工作内容是啥?\n地点哪里?\n双休吗?", - "to": "Retrieval:ColdEelsArrive" - }, - "casual": { - "description": "该问题不关于职位本身或公司的信息,属于闲聊。", - "examples": "你好\n好久不见\n你男的女的?\n你是猴子派来的救兵吗?\n上午开会了?\n你叫啥?\n最近市场如何?生意好做吗?", - "to": "Generate:ToughLawsCheat" - }, - "giveup": { - "description": "该回答表示他不愿意加微信。", - "examples": "不需要\n不感兴趣\n暂时不看\n不要\nno\n不方便\n不知道还要加我微信", - "to": "Generate:DirtyToolsTrain" - }, - "wechat": { - "description": "该回答表示他愿意加微信,或者已经报了微信号。", - "examples": "嗯\n可以\n是的\n哦\nyes\n15002333453\nwindblow_2231", - "to": "Generate:KindCarrotsSit" - } - }, - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 512, - "message_history_window_size": 8, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Answer:TwentyMugsDeny" - ] - }, - "message:reject": { - "downstream": [ - "answer:0" - ], - "obj": { - "component_name": "Message", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "messages": [ - "好的,祝您生活愉快,工作顺利。", - "哦,好的,感谢您宝贵的时间!" - ], - "output": null, - "output_var_name": "output", - "query": [] - } - }, - "upstream": [ - "categorize:0" - ] - } - }, - "embed_id": "", - "graph": { - "edges": [ - { - "id": "7a045a3d-5881-4a57-9467-75946941a642", - "label": "", - "source": "begin", - "target": "answer:0" - }, - { - "id": "9c6c78c1-532c-423d-9712-61c47a452f0e", - "label": "", - "source": "message:reject", - "target": "answer:0" - }, - { - "id": "reactflow__edge-answer:0b-categorize:0a", - "source": "answer:0", - "sourceHandle": "b", - "target": "categorize:0", - "targetHandle": "a", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Answer:TwentyMugsDenyb-categorize:1a", - "markerEnd": "logo", - "source": "Answer:TwentyMugsDeny", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "categorize:1", - "targetHandle": "a", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Retrieval:ShaggyRadiosRetireb-Generate:TruePawsReportc", - "markerEnd": "logo", - "source": "Retrieval:ShaggyRadiosRetire", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:TruePawsReport", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-categorize:0reject-message:rejectb", - "markerEnd": "logo", - "source": "categorize:0", - "sourceHandle": "reject", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "message:reject", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-categorize:0answer-Retrieval:ShaggyRadiosRetirec", - "markerEnd": "logo", - "source": "categorize:0", - "sourceHandle": "answer", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:ShaggyRadiosRetire", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-categorize:0casual-Generate:ProudEarsWorryc", - "markerEnd": "logo", - "source": "categorize:0", - "sourceHandle": "casual", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:ProudEarsWorry", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Message:MajorPigsYellb-Answer:TwentyMugsDenyc", - "markerEnd": "logo", - "source": "Message:MajorPigsYell", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:TwentyMugsDeny", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-categorize:0interested-Message:MajorPigsYellc", - "markerEnd": "logo", - "source": "categorize:0", - "sourceHandle": "interested", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Message:MajorPigsYell", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:TruePawsReportb-Answer:TwentyMugsDenyc", - "markerEnd": "logo", - "source": "Generate:TruePawsReport", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:TwentyMugsDeny", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-categorize:1about_job-Retrieval:ColdEelsArriveb", - "markerEnd": "logo", - "source": "categorize:1", - "sourceHandle": "about_job", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:ColdEelsArrive", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-categorize:1casual-Generate:ToughLawsCheatb", - "markerEnd": "logo", - "source": "categorize:1", - "sourceHandle": "casual", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:ToughLawsCheat", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-categorize:1wechat-Generate:KindCarrotsSitb", - "markerEnd": "logo", - "source": "categorize:1", - "sourceHandle": "wechat", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:KindCarrotsSit", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-categorize:1giveup-Generate:DirtyToolsTrainb", - "markerEnd": "logo", - "source": "categorize:1", - "sourceHandle": "giveup", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:DirtyToolsTrain", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:ToughLawsCheatc-Answer:TwentyMugsDenyc", - "markerEnd": "logo", - "source": "Generate:ToughLawsCheat", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:TwentyMugsDeny", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:KindCarrotsSitc-Answer:TwentyMugsDenyc", - "markerEnd": "logo", - "source": "Generate:KindCarrotsSit", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:TwentyMugsDeny", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:DirtyToolsTrainc-Answer:TwentyMugsDenyc", - "markerEnd": "logo", - "source": "Generate:DirtyToolsTrain", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:TwentyMugsDeny", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Retrieval:ColdEelsArrivec-Generate:FluffyPillowsGrowb", - "markerEnd": "logo", - "source": "Retrieval:ColdEelsArrive", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:FluffyPillowsGrow", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:FluffyPillowsGrowc-Answer:TwentyMugsDenyc", - "markerEnd": "logo", - "source": "Generate:FluffyPillowsGrow", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:TwentyMugsDeny", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:ProudEarsWorryb-Answer:TwentyMugsDenyc", - "markerEnd": "logo", - "source": "Generate:ProudEarsWorry", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:TwentyMugsDeny", - "targetHandle": "c", - "type": "buttonEdge" - } - ], - "nodes": [ - { - "data": { - "form": { - "prologue": "您好!我是英飞流负责招聘的HR,了解到您是这方面的大佬,然后冒昧的就联系到您。这边有个机会想和您分享,RAGFlow正在招聘您这个岗位的资深的工程师不知道您那边是不是感兴趣?" - }, - "label": "Begin", - "name": "开场白" - }, - "dragging": false, - "height": 44, - "id": "begin", - "measured": { - "height": 44, - "width": 100 - }, - "position": { - "x": -1034.5459371394727, - "y": -4.596073111491364 - }, - "positionAbsolute": { - "x": -1034.5459371394727, - "y": -4.596073111491364 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "beginNode" - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "交互1" - }, - "dragging": false, - "height": 44, - "id": "answer:0", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -759.3845780310955, - "y": -1.5248388351160145 - }, - "positionAbsolute": { - "x": -781.130188267973, - "y": -1.5248388351160145 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "category_description": { - "answer": { - "description": "该问题关于职位本身或公司的信息。", - "examples": "什么岗位?\n汇报对象是谁?\n公司多少人?\n公司有啥产品?\n具体工作内容是啥?\n地点哪里?\n双休吗?", - "to": "Retrieval:ShaggyRadiosRetire" - }, - "casual": { - "description": "该问题不关于职位本身或公司的信息,属于闲聊。", - "examples": "你好\n好久不见\n你男的女的?\n你是猴子派来的救兵吗?\n上午开会了?\n你叫啥?\n最近市场如何?生意好做吗?", - "to": "Generate:ProudEarsWorry" - }, - "interested": { - "description": "该回答表示他对于该职位感兴趣。", - "examples": "嗯\n说吧\n说说看\n还好吧\n是的\n哦\nyes\n具体说说", - "to": "Message:MajorPigsYell" - }, - "reject": { - "description": "该回答表示他对于该职位不感兴趣,或感觉受到骚扰。", - "examples": "不需要\n不感兴趣\n暂时不看\n不要\nno\n我已经不干这个了\n我不是这个方向的", - "to": "message:reject" - } - }, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 512, - "message_history_window_size": 1, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Categorize", - "name": "是否感兴趣?" - }, - "dragging": false, - "height": 223, - "id": "categorize:0", - "measured": { - "height": 223, - "width": 200 - }, - "position": { - "x": -511.7953063678477, - "y": -91.33627890840192 - }, - "positionAbsolute": { - "x": -511.7953063678477, - "y": -91.33627890840192 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "categorizeNode", - "width": 200 - }, - { - "data": { - "form": { - "category_description": { - "about_job": { - "description": "该问题关于职位本身或公司的信息。", - "examples": "什么岗位?\n汇报对象是谁?\n公司多少人?\n公司有啥产品?\n具体工作内容是啥?\n地点哪里?\n双休吗?", - "to": "Retrieval:ColdEelsArrive" - }, - "casual": { - "description": "该问题不关于职位本身或公司的信息,属于闲聊。", - "examples": "你好\n好久不见\n你男的女的?\n你是猴子派来的救兵吗?\n上午开会了?\n你叫啥?\n最近市场如何?生意好做吗?", - "to": "Generate:ToughLawsCheat" - }, - "giveup": { - "description": "该回答表示他不愿意加微信。", - "examples": "不需要\n不感兴趣\n暂时不看\n不要\nno\n不方便\n不知道还要加我微信", - "to": "Generate:DirtyToolsTrain" - }, - "wechat": { - "description": "该回答表示他愿意加微信,或者已经报了微信号。", - "examples": "嗯\n可以\n是的\n哦\nyes\n15002333453\nwindblow_2231", - "to": "Generate:KindCarrotsSit" - } - }, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 512, - "message_history_window_size": 8, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Categorize", - "name": "可以加微信?" - }, - "dragging": false, - "height": 223, - "id": "categorize:1", - "measured": { - "height": 223, - "width": 200 - }, - "position": { - "x": 650.2305440350307, - "y": 54.40917808770183 - }, - "positionAbsolute": { - "x": 650.2305440350307, - "y": 54.40917808770183 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "categorizeNode", - "width": 200 - }, - { - "data": { - "form": { - "messages": [ - "好的,祝您生活愉快,工作顺利。", - "哦,好的,感谢您宝贵的时间!" - ] - }, - "label": "Message", - "name": "再会" - }, - "dragging": false, - "height": 44, - "id": "message:reject", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -531.5363370421936, - "y": 169.8364292609376 - }, - "positionAbsolute": { - "x": -506.16645843250325, - "y": 197.6224867858366 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "交互2" - }, - "dragging": false, - "height": 44, - "id": "Answer:TwentyMugsDeny", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 361.4824760998825, - "y": 142.99203467677523 - }, - "positionAbsolute": { - "x": 361.4824760998825, - "y": 142.99203467677523 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "similarity_threshold": 0.2, - "top_k": 1024, - "top_n": 6 - }, - "label": "Retrieval", - "name": "搜索职位信息" - }, - "dragging": false, - "height": 44, - "id": "Retrieval:ShaggyRadiosRetire", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -200.47207828507428, - "y": -241.8885484926048 - }, - "positionAbsolute": { - "x": -200.47207828507428, - "y": -241.8885484926048 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,候选人问了有关职位或公司的问题,你根据以下职位信息回答。如果职位信息中不包含候选人的问题就回答不清楚、不知道、有待确认等。回答完后引导候选人加微信号,如:\n - 方便加一下微信吗,我把JD发您看看?\n - 微信号多少,我把详细职位JD发您?\n 职位信息如下:\n {Retrieval:ShaggyRadiosRetire}\n 职位信息如上。", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "回答职位信息并加微信" - }, - "dragging": false, - "height": 86, - "id": "Generate:TruePawsReport", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": 85.46499814334565, - "y": -84.90136892177973 - }, - "positionAbsolute": { - "x": 114.45914512584898, - "y": -243.16108786794368 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,现在候选人的聊了和职位无关的话题,请耐心的回应候选人,并将话题往该AGI的职位上带,最好能要到候选人微信号以便后面保持联系。", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "闲聊" - }, - "dragging": false, - "height": 86, - "id": "Generate:ProudEarsWorry", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": -201.4798710337693, - "y": 19.284469688181446 - }, - "positionAbsolute": { - "x": -201.4798710337693, - "y": 19.284469688181446 - }, - "selected": true, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "messages": [ - "我简单介绍一下:\nRAGFlow 是一款基于深度文档理解构建的开源 RAG(Retrieval-Augmented Generation)引擎。RAGFlow 可以为各种规模的企业及个人提供一套精简的 RAG 工作流程,结合大语言模型(LLM)针对用户各类不同的复杂格式数据提供可靠的问答以及有理有据的引用。https://github.com/infiniflow/ragflow\n您那边还有什么要了解的?" - ] - }, - "label": "Message", - "name": "职位简介" - }, - "dragging": false, - "height": 82, - "id": "Message:MajorPigsYell", - "measured": { - "height": 82, - "width": 200 - }, - "position": { - "x": -201.4757352153133, - "y": 142.14338727751849 - }, - "positionAbsolute": { - "x": -202.68382467291758, - "y": 127.64631378626683 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "messageNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,现在候选人的聊了和职位无关的话题,请耐心的回应候选人,并将话题往该AGI的职位上带,最好能要到候选人微信号以便后面保持联系。", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "闲聊(1)" - }, - "dragging": false, - "height": 86, - "id": "Generate:ToughLawsCheat", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": 717.0666295332912, - "y": -260.4610326390065 - }, - "positionAbsolute": { - "x": 719.4828084484998, - "y": -241.13160131733764 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "similarity_threshold": 0.2, - "top_k": 1024, - "top_n": 6 - }, - "label": "Retrieval", - "name": "搜索职位信息(1)" - }, - "dragging": false, - "height": 44, - "id": "Retrieval:ColdEelsArrive", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 679.4658067127144, - "y": -15.040383599249951 - }, - "positionAbsolute": { - "x": 681.881985627923, - "y": -7.791846853624122 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,候选人表示不反感加微信,如果对方已经报了微信号,表示感谢和信任并表示马上会加上;如果没有,则问对方微信号多少。你的微信号是weixin_kevin,E-mail是kkk@ragflow.com。说话不要重复。不要总是您好。", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "加微信" - }, - "dragging": false, - "height": 86, - "id": "Generate:KindCarrotsSit", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": 679.5187009685263, - "y": 298.0100840992407 - }, - "positionAbsolute": { - "x": 679.5187009685263, - "y": 298.0100840992407 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,当你提出加微信时对方表示拒绝。你需要耐心礼貌的回应候选人,表示对于保护隐私信息给予理解,也可以询问他对该职位的看法和顾虑。并在恰当的时机再次询问微信联系方式。也可以鼓励候选人主动与你取得联系。你的微信号是weixin_kevin,E-mail是kkk@ragflow.com。说话不要重复。不要总是您好。", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "不同意加微信后引导" - }, - "dragging": false, - "height": 86, - "id": "Generate:DirtyToolsTrain", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": 713.3958582226193, - "y": 412.69665533104524 - }, - "positionAbsolute": { - "x": 730.3091106290796, - "y": 400.61576075500216 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "接收用户第一次输入,或在判断后输出静态消息。" - }, - "label": "Note", - "name": "N: 交互1" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:SharpWingsGrab", - "measured": { - "height": 128, - "width": 190 - }, - "position": { - "x": -762.470214040517, - "y": -135.06311183543562 - }, - "positionAbsolute": { - "x": -785.4239137349989, - "y": -137.47929075064422 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 190 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 190 - }, - { - "data": { - "form": { - "text": "大模型判断用户的输入属于哪一种分类,传给不同的组件。" - }, - "label": "Note", - "name": "N:是否感兴趣" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:ThickOrangesMelt", - "measured": { - "height": 128, - "width": 198 - }, - "position": { - "x": -514.737951592251, - "y": -232.7753166367196 - }, - "positionAbsolute": { - "x": -514.737951592251, - "y": -232.7753166367196 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 198 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 198 - }, - { - "data": { - "form": { - "text": "接收用户对职位不感兴趣的相关输入,随机返回一条静态消息。" - }, - "label": "Note", - "name": "N: 再会" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:FineDaysCheat", - "measured": { - "height": 128, - "width": 203 - }, - "position": { - "x": -530.3000123190136, - "y": 248.91808187570632 - }, - "positionAbsolute": { - "x": -503.7220442517189, - "y": 256.16661862133213 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 203 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 203 - }, - { - "data": { - "form": { - "text": "接收用户对职位感兴趣的相关输入,返回其中的静态消息。" - }, - "label": "Note", - "name": "N:职位简介" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:WeakTaxesBegin", - "measured": { - "height": 128, - "width": 208 - }, - "position": { - "x": -197.5153373041337, - "y": 261.2072463084719 - }, - "positionAbsolute": { - "x": -203.55578459215516, - "y": 261.2072463084719 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 208 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 208 - }, - { - "data": { - "form": { - "text": "接收用户闲聊,根据闲聊内容,大模型返回相应的回答。" - }, - "label": "Note", - "name": "N: 闲聊" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:FourCornersHelp", - "measured": { - "height": 128, - "width": 213 - }, - "position": { - "x": -195.26410221591698, - "y": -125.75023229737762 - }, - "positionAbsolute": { - "x": -195.26410221591698, - "y": -125.75023229737762 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 213 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 213 - }, - { - "data": { - "form": { - "text": "接收用户对于职位或者公司的问题,检索知识库,返回检索到的内容。" - }, - "label": "Note", - "name": "N: 搜索职位信息" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:FortyTiresDance", - "measured": { - "height": 128, - "width": 197 - }, - "position": { - "x": -199.51694815612117, - "y": -382.54628777242647 - }, - "positionAbsolute": { - "x": -199.51694815612117, - "y": -382.54628777242647 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 197 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 197 - }, - { - "data": { - "form": { - "text": "大模型根据检索到的职位信息,回答用户的输入并请求加微信。" - }, - "label": "Note", - "name": "N: 回答职位信息" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:SixMasksTie", - "measured": { - "height": 128, - "width": 205 - }, - "position": { - "x": 81.31654079972914, - "y": -230.7938043878787 - }, - "positionAbsolute": { - "x": 113.93495615504537, - "y": -379.38880767320825 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 205 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 205 - }, - { - "data": { - "form": { - "text": "在第一轮的交互完成后,在确定用户的意愿基础上,继续后续的交流。" - }, - "label": "Note", - "name": "N: 交互2" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 132, - "id": "Note:HipAnimalsLose", - "measured": { - "height": 132, - "width": 200 - }, - "position": { - "x": 361.5573430860398, - "y": 202.76501272911685 - }, - "positionAbsolute": { - "x": 361.5573430860398, - "y": 202.76501272911685 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 132, - "width": 200 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "接收用户不愿意加微信的请求,大模型生成回答,回答与礼貌用语和引导用户加微信相关。" - }, - "label": "Note", - "name": "N: 不同意加微信后" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 144, - "id": "Note:CalmClownsOpen", - "measured": { - "height": 144, - "width": 200 - }, - "position": { - "x": 724.3625736109275, - "y": 527.6312716948657 - }, - "positionAbsolute": { - "x": 729.1949314413447, - "y": 498.6371247123624 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 144, - "width": 200 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "接收用户加微信的请求或微信号的信息。如果是加微信请求,则大模型返回询问微信的回答;如果是微信号的信息,则大模型返回礼貌性的回答。" - }, - "label": "Note", - "name": "N: 加微信" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 149, - "id": "Note:EightSuitsAdmire", - "measured": { - "height": 149, - "width": 481 - }, - "position": { - "x": 1118.6632741834096, - "y": 300.1313513476347 - }, - "positionAbsolute": { - "x": 1118.6632741834096, - "y": 300.1313513476347 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 149, - "width": 481 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 481 - }, - { - "data": { - "form": { - "text": "大模型判断用户的输入属于哪一种分类,传给不同的组件。" - }, - "label": "Note", - "name": "N:可以加微信?" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:SillyPillowsCrash", - "measured": { - "height": 128, - "width": 267 - }, - "position": { - "x": 1006.2146104300559, - "y": 61.99026665969035 - }, - "positionAbsolute": { - "x": 1006.2146104300559, - "y": 61.99026665969035 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 267 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 267 - }, - { - "data": { - "form": { - "text": "接收用户对于职位或者公司的问题,检索知识库,返回检索到的内容。" - }, - "label": "Note", - "name": "N: 搜索职位信息(1)" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:PurplePathsHeal", - "measured": { - "height": 128, - "width": 269 - }, - "position": { - "x": 679.0610551820539, - "y": -146.81167586458758 - }, - "positionAbsolute": { - "x": 679.0610551820539, - "y": -146.81167586458758 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 269 - }, - { - "data": { - "form": { - "text": "接收用户闲聊,根据闲聊内容,大模型返回相应的回答。" - }, - "label": "Note", - "name": "N:闲聊(1)" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 129, - "id": "Note:VastHumansAttend", - "measured": { - "height": 129, - "width": 200 - }, - "position": { - "x": 713.2672727035068, - "y": -403.49170163825374 - }, - "positionAbsolute": { - "x": 719.3077199915283, - "y": -382.2721004750209 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 129, - "width": 200 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [ - { - "component_id": "Retrieval:ColdEelsArrive", - "id": "5166a107-e859-4c71-99a2-3a216c775347", - "key": "jd" - } - ], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "你是公司负责招聘的HR,候选人问了有关职位或公司的问题,你根据以下职位信息回答。如果职位信息中不包含候选人的问题就回答不清楚、不知道、有待确认等。回答完后引导候选人加微信号,如:\n - 方便加一下微信吗,我把JD发您看看?\n - 微信号多少,我把详细职位JD发您?\n 职位信息如下:\n {Retrieval:ColdEelsArrive}\n 职位信息如上。", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "回答职位信息并加微信(1)" - }, - "dragging": false, - "height": 128, - "id": "Generate:FluffyPillowsGrow", - "measured": { - "height": 128, - "width": 200 - }, - "position": { - "x": 411.4591451258489, - "y": -7.161087867943763 - }, - "positionAbsolute": { - "x": 411.4591451258489, - "y": -7.161087867943763 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - } - ] - }, - "history": [], - "messages": [], - "path": [], - "reference": [] - }, - "avatar": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAE9AUcDASIAAhEBAxEB/8QAHwAAAQMEAwEAAAAAAAAAAAAAAAYHCAUJCgsCAwQB/8QAQRAAAQMDAwIEBAUCBAUDBAMAAQIDBAUGEQASIQcxCBMiQQkUUWEKFSMycUKBFpGh8BckUrHBJdHhGDNicoKS8f/EABwBAAICAwEBAAAAAAAAAAAAAAAGBQcBAwQCCP/EADoRAAEDAgUCBAQFBAICAgMAAAECAxEEIQAFEjFBUWEGEyJxMoGRoQcUscHwI9Hh8UJSFTMkchZigv/aAAwDAQACEQMRAD8AzsNGjRowYNGjRowYNGjRowYNGjRowYNGj/f01wU4htCnFqSltCQpZUsAbTjAycZKjgJHBUe2jBjn9d3pwnPJAGRnIycD2I7jnXhdnIC1MRnEKlFBVHwCpt1YyFISoDCnE/u24OQCpWNeCovOLCW3VuMMusumOUtkrckkpCWnckFAKRwOCo5Kc41ToyHZAci+ltQdRIaklYR5K2hgllaEhKuU/qJUv1AqCgVZGjBjpfecUl5K3y0t1hSzKeQFBx5pQLzAcBSttKR7YBwTjtqsUuS6hLcaQwtltSUqhH9ze5RBdShRUFKSoYWCRgAng680UfOy25PltOBPzDFRjtrSEJklrYt1sqyjypCcLTj1BWQk8aUPktAtENpHkJKWcjJbCkBKgnOSOOO5xgEHOjBjs0aNGjBg0aNGjBg0aN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xwYSSpWd3AHbjOCft9cac/w1Ut6yOuHhxvFNOYnRaV4kemzEpl5wfLuJVetvodZkKwoNoWy6880TkOKYxwNKKowWilWQkpKc7do7ZwATnnHfOBz7afXwXWpTbr8UnQ+yKsXHqHWep1r1eUwQhWyba0sV2I6zuSQhUhyEI0hR3ZZc3JAUgA+qrMEmmqErChLLg2Fzp7e84wtJUAB1B+mM1vG0lP/SSkn6lJ2knvySCSPYkj20a5KA3qxkAqUr2J5JWcnAzkk5OB9e+uOqUUf6jg51E42EzFgIAFuY/n+cGjXFStpxjPGe//AMaNGMY//9k=" -} diff --git a/agent/templates/advanced_ingestion_pipeline.json b/agent/templates/advanced_ingestion_pipeline.json new file mode 100644 index 00000000000..cfd211f4688 --- /dev/null +++ b/agent/templates/advanced_ingestion_pipeline.json @@ -0,0 +1,728 @@ +{ + "id": 23, + "title": { + "en": "Advanced Ingestion Pipeline", + "de": "Erweiterte Ingestion Pipeline", + "zh": "编排复杂的 Ingestion Pipeline" + }, + "description": { + "en": "This template demonstrates how to use an LLM to generate summaries, keywords, Q&A, and metadata for each chunk to support diverse retrieval needs.", + "de": "Diese Vorlage demonstriert, wie ein LLM verwendet wird, um Zusammenfassungen, Schlüsselwörter, Fragen & Antworten und Metadaten für jedes Segment zu generieren, um vielfältige Abrufanforderungen zu unterstützen.", + "zh": "此模板演示如何利用大模型为切片生成摘要、关键词、问答及元数据,以满足多样化的召回需求。" + }, + "canvas_type": "Ingestion Pipeline", + "canvas_category": "dataflow_canvas", + "dsl": { + "components": { + "File": { + "obj": { + "component_name": "File", + "params": {} + }, + "downstream": [ + "Parser:HipSignsRhyme" + ], + "upstream": [] + }, + "Parser:HipSignsRhyme": { + "obj": { + "component_name": "Parser", + "params": { + "outputs": { + "html": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + }, + "markdown": { + "type": "string", + "value": "" + }, + "text": { + "type": "string", + "value": "" + } + }, + "setups": { + "pdf": { + "output_format": "markdown", + "suffix": [ + "pdf" + ], + "parse_method": "DeepDOC" + }, + "spreadsheet": { + "output_format": "html", + "suffix": [ + "xls", + "xlsx", + "csv" + ] + }, + "image": { + "output_format": "text", + "suffix": [ + "jpg", + "jpeg", + "png", + "gif" + ], + "parse_method": "ocr" + }, + "email": { + "output_format": "text", + "suffix": [ + "eml", + "msg" + ], + "fields": [ + "from", + "to", + "cc", + "bcc", + "date", + "subject", + "body", + "attachments" + ] + }, + "text&markdown": { + "output_format": "text", + "suffix": [ + "md", + "markdown", + "mdx", + "txt" + ] + }, + "word": { + "output_format": "json", + "suffix": [ + "doc", + "docx" + ] + }, + "slides": { + "output_format": "json", + "suffix": [ + "pptx" + ] + } + } + } + }, + "downstream": [ + "Splitter:KindDingosJam" + ], + "upstream": [ + "File" + ] + }, + "Splitter:KindDingosJam": { + "obj": { + "component_name": "Splitter", + "params": { + "chunk_token_size": 512, + "delimiters": [ + "\n" + ], + "outputs": { + "chunks": { + "type": "Array", + "value": [] + } + }, + "overlapped_percent": 0.002 + } + }, + "downstream": [ + "Extractor:NineTiesSin" + ], + "upstream": [ + "Parser:HipSignsRhyme" + ] + }, + "Extractor:NineTiesSin": { + "obj": { + "component_name": "Extractor", + "params": { + "field_name": "summary", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 256, + "outputs": {}, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "Text to Summarize:\n{Splitter:KindDingosJam@chunks}", + "role": "user" + } + ], + "sys_prompt": "Act as a precise summarizer. Your task is to create a summary of the provided content that is both concise and faithful to the original.\n\nKey Instructions:\n1. Accuracy: Strictly base the summary on the information given. Do not introduce any new facts, conclusions, or interpretations that are not explicitly stated.\n2. Language: Write the summary in the same language as the source text.\n3. Objectivity: Present the key points without bias, preserving the original intent and tone of the content. Do not editorialize.\n4. Conciseness: Focus on the most important ideas, omitting minor details and fluff.", + "temperature": 0.1, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.3 + } + }, + "downstream": [ + "Extractor:TastyPointsLay" + ], + "upstream": [ + "Splitter:KindDingosJam" + ] + }, + "Extractor:TastyPointsLay": { + "obj": { + "component_name": "Extractor", + "params": { + "field_name": "keywords", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 256, + "outputs": {}, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "Text Content:\n{Splitter:KindDingosJam@chunks}\n", + "role": "user" + } + ], + "sys_prompt": "Role\nYou are a text analyzer.\n\nTask\nExtract the most important keywords/phrases of a given piece of text content.\n\nRequirements\n- Summarize the text content, and give the top 5 important keywords/phrases.\n- The keywords MUST be in the same language as the given piece of text content.\n- The keywords are delimited by ENGLISH COMMA.\n- Output keywords ONLY.", + "temperature": 0.1, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.3 + } + }, + "downstream": [ + "Extractor:BlueResultsWink" + ], + "upstream": [ + "Extractor:NineTiesSin" + ] + }, + "Extractor:BlueResultsWink": { + "obj": { + "component_name": "Extractor", + "params": { + "field_name": "questions", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 256, + "outputs": {}, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "Text Content:\n\n{Splitter:KindDingosJam@chunks}\n", + "role": "user" + } + ], + "sys_prompt": "Role\nYou are a text analyzer.\n\nTask\nPropose 3 questions about a given piece of text content.\n\nRequirements\n- Understand and summarize the text content, and propose the top 3 important questions.\n- The questions SHOULD NOT have overlapping meanings.\n- The questions SHOULD cover the main content of the text as much as possible.\n- The questions MUST be in the same language as the given piece of text content.\n- One question per line.\n- Output questions ONLY.", + "temperature": 0.1, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.3 + } + }, + "downstream": [ + "Extractor:CuteBusesBet" + ], + "upstream": [ + "Extractor:TastyPointsLay" + ] + }, + "Extractor:CuteBusesBet": { + "obj": { + "component_name": "Extractor", + "params": { + "field_name": "metadata", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 256, + "outputs": {}, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "Content: \n\n{Splitter:KindDingosJam@chunks}", + "role": "user" + } + ], + "sys_prompt": "Extract important structured information from the given content. Output ONLY a valid JSON string with no additional text. If no important structured information is found, output an empty JSON object: {}.\n\nImportant structured information may include: names, dates, locations, events, key facts, numerical data, or other extractable entities.", + "temperature": 0.1, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.3 + } + }, + "downstream": [ + "Tokenizer:LegalHorsesCheer" + ], + "upstream": [ + "Extractor:BlueResultsWink" + ] + }, + "Tokenizer:LegalHorsesCheer": { + "obj": { + "component_name": "Tokenizer", + "params": { + "fields": "text", + "filename_embd_weight": 0.1, + "outputs": {}, + "search_method": [ + "embedding", + "full_text" + ] + } + }, + "downstream": [], + "upstream": [ + "Extractor:CuteBusesBet" + ] + } + }, + "globals": {}, + "graph": { + "nodes": [ + { + "data": { + "label": "File", + "name": "File" + }, + "dragging": false, + "id": "File", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": -301.4128436198721, + "y": 375.86728431988394 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "outputs": { + "html": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + }, + "markdown": { + "type": "string", + "value": "" + }, + "text": { + "type": "string", + "value": "" + } + }, + "setups": [ + { + "fileFormat": "pdf", + "output_format": "markdown", + "parse_method": "DeepDOC" + }, + { + "fileFormat": "spreadsheet", + "output_format": "html" + }, + { + "fileFormat": "image", + "output_format": "text", + "parse_method": "ocr" + }, + { + "fields": [ + "from", + "to", + "cc", + "bcc", + "date", + "subject", + "body", + "attachments" + ], + "fileFormat": "email", + "output_format": "text" + }, + { + "fileFormat": "text&markdown", + "output_format": "text" + }, + { + "fileFormat": "word", + "output_format": "json" + }, + { + "fileFormat": "slides", + "output_format": "json" + } + ] + }, + "label": "Parser", + "name": "Parser" + }, + "dragging": false, + "id": "Parser:HipSignsRhyme", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": -297.12089864837964, + "y": 532.2084591689336 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "parserNode" + }, + { + "data": { + "form": { + "chunk_token_size": 512, + "delimiters": [ + { + "value": "\n" + } + ], + "outputs": { + "chunks": { + "type": "Array", + "value": [] + } + }, + "overlapped_percent": 0.2 + }, + "label": "Splitter", + "name": "Token Chunker" + }, + "dragging": false, + "id": "Splitter:KindDingosJam", + "measured": { + "height": 80, + "width": 200 + }, + "position": { + "x": 7.288275851418206, + "y": 371.19722568785704 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "splitterNode" + }, + { + "data": { + "form": { + "field_name": "summary", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 256, + "outputs": {}, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": "Text to Summarize:\n{Splitter:KindDingosJam@chunks}", + "sys_prompt": "Act as a precise summarizer. Your task is to create a summary of the provided content that is both concise and faithful to the original.\n\nKey Instructions:\n1. Accuracy: Strictly base the summary on the information given. Do not introduce any new facts, conclusions, or interpretations that are not explicitly stated.\n2. Language: Write the summary in the same language as the source text.\n3. Objectivity: Present the key points without bias, preserving the original intent and tone of the content. Do not editorialize.\n4. Conciseness: Focus on the most important ideas, omitting minor details and fluff.", + "temperature": 0.1, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.3 + }, + "label": "Extractor", + "name": "Summarization" + }, + "dragging": false, + "id": "Extractor:NineTiesSin", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 9.537168313582939, + "y": 461.26662127765564 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "contextNode" + }, + { + "data": { + "form": { + "field_name": "keywords", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 256, + "outputs": {}, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": "Text Content:\n{Splitter:KindDingosJam@chunks}\n", + "sys_prompt": "Role\nYou are a text analyzer.\n\nTask\nExtract the most important keywords/phrases of a given piece of text content.\n\nRequirements\n- Summarize the text content, and give the top 5 important keywords/phrases.\n- The keywords MUST be in the same language as the given piece of text content.\n- The keywords are delimited by ENGLISH COMMA.\n- Output keywords ONLY.", + "temperature": 0.1, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.3 + }, + "label": "Extractor", + "name": "Auto Keywords" + }, + "dragging": false, + "id": "Extractor:TastyPointsLay", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 7.473032067783009, + "y": 533.0519245332371 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "contextNode" + }, + { + "data": { + "form": { + "field_name": "questions", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 256, + "outputs": {}, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": "Text Content:\n\n{Splitter:KindDingosJam@chunks}\n", + "sys_prompt": "Role\nYou are a text analyzer.\n\nTask\nPropose 3 questions about a given piece of text content.\n\nRequirements\n- Understand and summarize the text content, and propose the top 3 important questions.\n- The questions SHOULD NOT have overlapping meanings.\n- The questions SHOULD cover the main content of the text as much as possible.\n- The questions MUST be in the same language as the given piece of text content.\n- One question per line.\n- Output questions ONLY.", + "temperature": 0.1, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.3 + }, + "label": "Extractor", + "name": "Auto Questions" + }, + "dragging": false, + "id": "Extractor:BlueResultsWink", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 2.905601749296892, + "y": 617.0420857433816 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "contextNode" + }, + { + "data": { + "form": { + "field_name": "metadata", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 256, + "outputs": {}, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": "Content: \n\n{Splitter:KindDingosJam@chunks}", + "sys_prompt": "Extract important structured information from the given content. Output ONLY a valid JSON string with no additional text. If no important structured information is found, output an empty JSON object: {}.\n\nImportant structured information may include: names, dates, locations, events, key facts, numerical data, or other extractable entities.", + "temperature": 0.1, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.3 + }, + "label": "Extractor", + "name": "Generate Metadata" + }, + "dragging": false, + "id": "Extractor:CuteBusesBet", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 327.16477358029204, + "y": 374.11630810111944 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "contextNode" + }, + { + "data": { + "form": { + "fields": "text", + "filename_embd_weight": 0.1, + "outputs": {}, + "search_method": [ + "embedding", + "full_text" + ] + }, + "label": "Tokenizer", + "name": "Indexer" + }, + "dragging": false, + "id": "Tokenizer:LegalHorsesCheer", + "measured": { + "height": 120, + "width": 200 + }, + "position": { + "x": 345.50155210663667, + "y": 533.0511852267863 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "tokenizerNode" + }, + { + "id": "Note:CruelSidesStick", + "type": "noteNode", + "position": { + "x": -29, + "y": 765 + }, + "data": { + "label": "Note", + "name": "Add more attributes", + "form": { + "text": "Using LLM to generate summaries, keywords, Q&A, and metadata." + } + }, + "sourcePosition": "right", + "targetPosition": "left", + "dragHandle": ".note-drag-handle", + "measured": { + "width": 281, + "height": 130 + }, + "width": 281, + "height": 130, + "resizing": false + } + ], + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Filestart-Parser:HipSignsRhymeend", + "source": "File", + "sourceHandle": "start", + "target": "Parser:HipSignsRhyme", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Splitter:KindDingosJamstart-Extractor:NineTiesSinend", + "source": "Splitter:KindDingosJam", + "sourceHandle": "start", + "target": "Extractor:NineTiesSin", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Extractor:NineTiesSinstart-Extractor:TastyPointsLayend", + "source": "Extractor:NineTiesSin", + "sourceHandle": "start", + "target": "Extractor:TastyPointsLay", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Extractor:TastyPointsLaystart-Extractor:BlueResultsWinkend", + "source": "Extractor:TastyPointsLay", + "sourceHandle": "start", + "target": "Extractor:BlueResultsWink", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Extractor:BlueResultsWinkstart-Extractor:CuteBusesBetend", + "source": "Extractor:BlueResultsWink", + "sourceHandle": "start", + "target": "Extractor:CuteBusesBet", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Extractor:CuteBusesBetstart-Tokenizer:LegalHorsesCheerend", + "source": "Extractor:CuteBusesBet", + "sourceHandle": "start", + "target": "Tokenizer:LegalHorsesCheer", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Parser:HipSignsRhymestart-Splitter:KindDingosJamend", + "markerEnd": "logo", + "source": "Parser:HipSignsRhyme", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Splitter:KindDingosJam", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABpQSURBVHgBbXoJfFTluf5zzpw5syaZZLKRjZCEBEIgLAFBLYIW0apsUnFprUu1t3q1WqWl2Nvi36X6v7aIqNV760WttVotFVBZROAiEowIYQ1bQvY9mcxk9jlzzn2+E7Cx7eSX32xneb93ed7nfb6R8A+PVWvfm3ek4exih01ZAkjFsiShu7cf40uKcM9ty5DuSUEyqSMS03i0AYfNCsOA+fofH+LceEJDXNNhtylQZRmlbh1/6gHur3Mi3KgAHkCxAZqb1/PzvYXniasN6TCcwPIpftzvTdaHNLneZZEfnz8tvXn0PaSLL9as/Zvnk7qDv7Zb5YfSUlPMzwZ8fqS4nXjgrpsxc1oJurqDpkHCVJtVMc+OxTU+SVBVC3R9ZBESDReL1HQdikWGhf/FqoavYjpu2ZuKzrMKUjOA66/fi+BgLjbvKQdSdUg0XgrJ0LmWmpIgXqwII0WXYbVznW4rBjULWgLS82FH4vGl49KHvl7AvCUPeeJWdXd2tneqsC4cjWB4OIw7br4BixZeytcxRKJxGmTASmNketIw/m6seB1PJGFVaCy/i3KR4lkcN0bVEVcN3LLPir1nHYAziTG5Cn660MDjoWswxTseLetfRDeNT9Ka7JQoXpgSwFyngR4u5C/tKXir2YGOuASFp8u8nmzI9WEd83GnNGQu4OoHXlzrjvQ95EgOYyiiY/Ilc3D/HUu4FhlDgTCN12iMBKfd+rWXv/mQ+D3M45L0usOhIoXvc91JrGxQ8OIBJ6QgF58rIz+X6ZGWQCEXMS/Hj81bHDhySoVaoOGXU/24JU2HapWx/pQdvz3kRtZkA3fNiGKsR0ePy4FlvNFW3lEJRZ5/xO18WLJv8BVrcJ7XArxjMIiaTA1/+q4XhRjCSZ8ECz2sWkV6gLksPCsxCnw/KgIa00XnAVbFAoXflzo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j0LmODrru2Ox8EfV67a983DzyJ3WGp4pxbHd60p93B6W0UMmmUua66aOw5T+ht4jSF3swigpNvsukrCLNZC4MNgLddrQRwZ9uTEFDccHMGacE1nc8FDGJhALj6gXIv3yily4e9w2TGhOwTu/uQztjnbMeGQtWSmdKmVAzHsmxxELtmlYEJ5Z/xw2zIf0wdDIpLz98ei2VXe/2685HKpLnV1Itdlikb5OB7FKcSONixBeFosQ84HxL351oFgsI9HgABClgYl+FTEjgcwyG7jjijANj3Hj0MUFWq0jURO/kehv82M3N1iu3TmAzNY01K5dgfayfDhaW5Hq76RLIxQamK5aYl16S8qd9Uuf/fuPPUY/Gs77ijlGriHAVPPrqRc/F+giclrkemykii8M8MY3yk2jxDgi8BI1hknUQkIHtZh7ZyBNFlGh0g7VzlqjRxUzikRAwuVNZX/BGEqLU6XJXHwz9IKpqFuYi/PjYs26v2dT+rFzH7RvW7BntL3/B41Ezp+M4ooqAAAAAElFTkSuQmCC" +} \ No newline at end of file diff --git a/agent/templates/choose_your_knowledge_base_agent.json b/agent/templates/choose_your_knowledge_base_agent.json new file mode 100644 index 00000000000..65c02512cda --- /dev/null +++ b/agent/templates/choose_your_knowledge_base_agent.json @@ -0,0 +1,422 @@ +{ + "id": 19, + "title": { + "en": "Choose Your Knowledge Base Agent", + "de": "Wählen Sie Ihren Wissensdatenbank Agenten", + "zh": "选择知识库智能体"}, + "description": { + "en": "Select your desired knowledge base from the dropdown menu. The Agent will only retrieve from the selected knowledge base and use this content to generate responses.", + "de": "Wählen Sie Ihre gewünschte Wissensdatenbank aus dem Dropdown-Menü. Der Agent ruft nur Informationen aus der ausgewählten Wissensdatenbank ab und verwendet diesen Inhalt zur Generierung von Antworten.", + "zh": "从下拉菜单中选择知识库,智能体将仅根据所选知识库内容生成回答。"}, + "canvas_type": "Agent", + "dsl": { + "components": { + "Agent:BraveParksJoke": { + "downstream": [ + "Message:HotMelonsObey" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "#Role\nYou are a **Docs QA Agent**, a specialized knowledge base assistant responsible for providing accurate answers based strictly on the connected documentation repository.\n\n# Core Principles\n1. **Rapid Output**\nRetrieve and answer questions directly from the knowledge base using the retrieval tool. Immediately return results upon successful retrieval without additional reflection rounds. Prioritize rapid output even before reaching maximum iteration limits.\n2. **Knowledge Base Only**: Answer questions EXCLUSIVELY based on information retrieved from the connected knowledge base.\n3. **No Content Creation**: Never generate, infer, or create information that is not explicitly present in the retrieved documents.\n4. **Source Transparency**: Always indicate when information comes from the knowledge base vs. when it's unavailable.\n5. **Accuracy Over Completeness**: Prefer incomplete but accurate answers over complete but potentially inaccurate ones.\n# Response Guidelines\n## When Information is Available\n- Provide direct answers based on retrieved content\n- Quote relevant sections when helpful\n- Cite the source document/section if available\n- Use phrases like: \"According to the documentation...\" or \"Based on the knowledge base...\"\n## When Information is Unavailable\n- Clearly state: \"I cannot find this information in the current knowledge base.\"\n- Do NOT attempt to fill gaps with general knowledge\n- Suggest alternative questions that might be covered in the docs\n- Use phrases like: \"The documentation does not cover...\" or \"This information is not available in the knowledge base.\"\n# Response Format\n```markdown\n## Answer\n[Your response based strictly on knowledge base content]\n**Always do these:**\n- Use the Retrieval tool for every question\n- Be transparent about information availability\n- Stick to documented facts only\n- Acknowledge knowledge base limitations", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "Retrieve from the knowledge bases.", + "empty_response": "", + "kb_ids": [ + "begin@knowledge base" + ], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Message:HotMelonsObey": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:BraveParksJoke@content}" + ] + } + }, + "upstream": [ + "Agent:BraveParksJoke" + ] + }, + "begin": { + "downstream": [ + "Agent:BraveParksJoke" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": { + "knowledge base": { + "name": "knowledge base", + "optional": false, + "options": [ + "knowledge base 1", + "knowledge base 2", + "knowledge base 3" + ], + "type": "options" + } + }, + "mode": "conversational", + "prologue": "Hi! I'm your retrieval assistant. What do you want to ask?" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:BraveParksJokeend", + "selected": false, + "source": "begin", + "sourceHandle": "start", + "target": "Agent:BraveParksJoke", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:BraveParksJoketool-Tool:TangyWolvesDreamend", + "source": "Agent:BraveParksJoke", + "sourceHandle": "tool", + "target": "Tool:TangyWolvesDream", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:BraveParksJokestart-Message:HotMelonsObeyend", + "source": "Agent:BraveParksJoke", + "sourceHandle": "start", + "target": "Message:HotMelonsObey", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": { + "knowledge base": { + "name": "knowledge base", + "optional": false, + "options": [ + "knowledge base 1", + "knowledge base 2", + "knowledge base 3" + ], + "type": "options" + } + }, + "mode": "conversational", + "prologue": "Hi! I'm your retrieval assistant. What do you want to ask?" + }, + "label": "Begin", + "name": "begin" + }, + "dragging": false, + "id": "begin", + "measured": { + "height": 76, + "width": 200 + }, + "position": { + "x": 174.93384234796846, + "y": -272.9638317458806 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "#Role\nYou are a **Docs QA Agent**, a specialized knowledge base assistant responsible for providing accurate answers based strictly on the connected documentation repository.\n\n# Core Principles\n1. **Rapid Output**\nRetrieve and answer questions directly from the knowledge base using the retrieval tool. Immediately return results upon successful retrieval without additional reflection rounds. Prioritize rapid output even before reaching maximum iteration limits.\n2. **Knowledge Base Only**: Answer questions EXCLUSIVELY based on information retrieved from the connected knowledge base.\n3. **No Content Creation**: Never generate, infer, or create information that is not explicitly present in the retrieved documents.\n4. **Source Transparency**: Always indicate when information comes from the knowledge base vs. when it's unavailable.\n5. **Accuracy Over Completeness**: Prefer incomplete but accurate answers over complete but potentially inaccurate ones.\n# Response Guidelines\n## When Information is Available\n- Provide direct answers based on retrieved content\n- Quote relevant sections when helpful\n- Cite the source document/section if available\n- Use phrases like: \"According to the documentation...\" or \"Based on the knowledge base...\"\n## When Information is Unavailable\n- Clearly state: \"I cannot find this information in the current knowledge base.\"\n- Do NOT attempt to fill gaps with general knowledge\n- Suggest alternative questions that might be covered in the docs\n- Use phrases like: \"The documentation does not cover...\" or \"This information is not available in the knowledge base.\"\n# Response Format\n```markdown\n## Answer\n[Your response based strictly on knowledge base content]\n**Always do these:**\n- Use the Retrieval tool for every question\n- Be transparent about information availability\n- Stick to documented facts only\n- Acknowledge knowledge base limitations", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "Retrieve from the knowledge bases.", + "empty_response": "", + "kb_ids": [ + "begin@knowledge base" + ], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Agent" + }, + "dragging": false, + "id": "Agent:BraveParksJoke", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 699.8147585743118, + "y": -512.1229013834202 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "id": "Tool:TangyWolvesDream", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 617.8147585743118, + "y": -372.1229013834202 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:BraveParksJoke@content}" + ] + }, + "label": "Message", + "name": "Message" + }, + "id": "Message:HotMelonsObey", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 999.8147585743118, + "y": -512.1229013834202 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "Configure the dropdown menu with your knowledge bases for retrieval." + }, + "label": "Note", + "name": "Note: Begin" + }, + "dragHandle": ".note-drag-handle", + "id": "Note:CurlyGoatsRun", + "measured": { + "height": 136, + "width": 250 + }, + "position": { + "x": 240, + "y": -135 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "The Agent will only retrieve from the selected knowledge base and use this content to generate responses.\n\nThe Agent prioritizes rapid response per system prompt configuration. Adjust reflection rounds by modifying the system prompt or via Agent > Advanced Settings > Max Rounds." + }, + "label": "Note", + "name": "Note: Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 186, + "id": "Note:GentleShowersAct", + "measured": { + "height": 186, + "width": 456 + }, + "position": { + "x": 759.6166714488969, + "y": -303.3174949046285 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 456 + }, + { + "data": { + "form": { + "text": "Select your desired knowledge base from the dropdown menu. \nThe Agent will only retrieve from the selected knowledge base and use this content to generate responses." + }, + "label": "Note", + "name": "Workflow overall description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 169, + "id": "Note:FineCandlesDig", + "measured": { + "height": 169, + "width": 357 + }, + "position": { + "x": 177.69466666666665, + "y": -531.9333333333334 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 357 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABXvSURBVHgBXVprrKVnVX7e77rve59L5+yZM505nWmnQAsdoDTVoBYoGlADEgEDRiVqTADDLRFNvMAvfhBjiP7QmPAHRVAxXBIVDaGYprRA05EO7bSdds5cOmfm3C/7+n3f+74+a737tJXd+Wbv2fv73staz3rWs9Zbg596Jf2zD8Dadzlj3m28X4EHDP/TP3ol8FEGF0UwEb+IY0R8zlWWf1kYX4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SVapFImE2FX8J9L9ERBWV71uqivzOFUe45HCKRc0vaEtUJFaWNbHo8+PsYWO+K5dOVE1bCLITpoQq2UsGAqeTqTReazybXz//DQnac++oW5bv6xlHK5ZGZNiT05OpVz3zkWIRMWMnX+tslEFV4RdkaT8L8ESKtdFCk1jxwjne7WeGZW6lFp7GfHs1KZyWE5N9CU7N1kjfyG28lYS3hNv4ehneMGGpRuEeaox8qDPt57Vw2PXdvEBfZctUNN6JhZEy4PVPqFr/zTJ1f1hObW+cXPPL269gsX1/fOdprkXuocelabqrUt7jiSysvx1CdX2ZKwhryxZxUyetop5SMtWBJlr1po4uu7E9QW6zM9H/KMttNdgZaohAbh1ehin8dI3e48F04aJiX2OfhYpDqT8mMHHnM8g3yA866S2a7SG0POl7NGyY07N+/dZ2RczfLnzj00GeK1X42Sqj4t/P1DPmB5YyGFOJPFiBw/5ndTXkMOtDso2ZWW7oAccKeoSXHDz3ewYXqJ3D9qd/TE0RD7USZFUK6J0NK7JyhLJsQ46yNUjI8N5pv1qI5Nnopu87vrhNquNHEpM6dUsQPmoTpb/L0Gcww32KynX8iy+ofO/ck7dn+qXAiv2spvrNg0+QxF3j2E0Fk5oUnV6pFgTmWDFHNWUjwXJDGgRRCzdyFHT8eOI+P5saNlIzb9LU955CRTmEu61RUzaO3GrgpB15mjJ8j7vCK2LCXuRGZH1BOVp7R2E60HqIZXE+e/kSXu6zf+8O0PvXK9/wcj9f0wDwE0NgAAAABJRU5ErkJggg==" +} \ No newline at end of file diff --git a/agent/templates/choose_your_knowledge_base_workflow.json b/agent/templates/choose_your_knowledge_base_workflow.json new file mode 100644 index 00000000000..3239bd7d351 --- /dev/null +++ b/agent/templates/choose_your_knowledge_base_workflow.json @@ -0,0 +1,440 @@ +{ + "id": 18, + "title": { + "en": "Choose Your Knowledge Base Workflow", + "de": "Wählen Sie Ihren Wissensdatenbank Workflow", + "zh": "选择知识库工作流"}, + "description": { + "en": "Select your desired knowledge base from the dropdown menu. The retrieval assistant will only use data from your selected knowledge base to generate responses.", + "de": "Wählen Sie Ihre gewünschte Wissensdatenbank aus dem Dropdown-Menü. Der Abrufassistent verwendet nur Daten aus Ihrer ausgewählten Wissensdatenbank, um Antworten zu generieren.", + "zh": "从下拉菜单中选择知识库,工作流将仅根据所选知识库内容生成回答。"}, + "canvas_type": "Other", + "dsl": { + "components": { + "Agent:ProudDingosShout": { + "downstream": [ + "Message:DarkRavensType" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query: {sys.query}\n\nRetrieval content: {Retrieval:RudeCyclesKneel@formalized_content}", + "role": "user" + } + ], + "sys_prompt": "# Role\nYou are the **Docs QA Agent**, a specialized knowledge base assistant responsible for providing accurate answers based strictly on the connected documentation repository.\n# Core Principles\n1. **Knowledge Base Only**: Answer questions EXCLUSIVELY based on information retrieved from the connected knowledge base.\n2. **No Content Creation**: Never generate, infer, or create information that is not explicitly present in the retrieved documents.\n3. **Source Transparency**: Always indicate when information comes from the knowledge base vs. when it's unavailable.\n4. **Accuracy Over Completeness**: Prefer incomplete but accurate answers over complete but potentially inaccurate ones.\n# Response Guidelines\n## When Information is Available\n- Provide direct answers based on retrieved content\n- Quote relevant sections when helpful\n- Cite the source document/section if available\n- Use phrases like: \"According to the documentation...\" or \"Based on the knowledge base...\"\n## When Information is Unavailable\n- Clearly state: \"I cannot find this information in the current knowledge base.\"\n- Do NOT attempt to fill gaps with general knowledge\n- Suggest alternative questions that might be covered in the docs\n- Use phrases like: \"The documentation does not cover...\" or \"This information is not available in the knowledge base.\"\n# Response Format\n```markdown\n## Answer\n[Your response based strictly on knowledge base content]\n**Always do these:**\n- Use the Retrieval tool for every question\n- Be transparent about information availability\n- Stick to documented facts only\n- Acknowledge knowledge base limitations", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Retrieval:RudeCyclesKneel" + ] + }, + "Message:DarkRavensType": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:ProudDingosShout@content}" + ] + } + }, + "upstream": [ + "Agent:ProudDingosShout" + ] + }, + "Retrieval:RudeCyclesKneel": { + "downstream": [ + "Agent:ProudDingosShout" + ], + "obj": { + "component_name": "Retrieval", + "params": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [ + "begin@knowledge base" + ], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "sys.query", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + }, + "upstream": [ + "begin" + ] + }, + "begin": { + "downstream": [ + "Retrieval:RudeCyclesKneel" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": { + "knowledge base": { + "name": "knowledge base", + "optional": false, + "options": [ + "knowledge base 1", + "knowledge base 2", + "knowledge base 3" + ], + "type": "options" + } + }, + "mode": "conversational", + "prologue": "Hi! I'm your retrieval assistant. What do you want to ask?" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Retrieval:RudeCyclesKneelend", + "source": "begin", + "sourceHandle": "start", + "target": "Retrieval:RudeCyclesKneel", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Retrieval:RudeCyclesKneelstart-Agent:ProudDingosShoutend", + "source": "Retrieval:RudeCyclesKneel", + "sourceHandle": "start", + "target": "Agent:ProudDingosShout", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:ProudDingosShoutstart-Message:DarkRavensTypeend", + "source": "Agent:ProudDingosShout", + "sourceHandle": "start", + "target": "Message:DarkRavensType", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": { + "knowledge base": { + "name": "knowledge base", + "optional": false, + "options": [ + "knowledge base 1", + "knowledge base 2", + "knowledge base 3" + ], + "type": "options" + } + }, + "mode": "conversational", + "prologue": "Hi! I'm your retrieval assistant. What do you want to ask?" + }, + "label": "Begin", + "name": "begin" + }, + "id": "begin", + "measured": { + "height": 76, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [ + "begin@knowledge base" + ], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "sys.query", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + }, + "label": "Retrieval", + "name": "Retrieval" + }, + "dragging": false, + "id": "Retrieval:RudeCyclesKneel", + "measured": { + "height": 96, + "width": 200 + }, + "position": { + "x": 368.9985951155415, + "y": 188.91748618260078 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "retrievalNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query: {sys.query}\n\nRetrieval content: {Retrieval:RudeCyclesKneel@formalized_content}", + "role": "user" + } + ], + "sys_prompt": "# Role\nYou are the **Docs QA Agent**, a specialized knowledge base assistant responsible for providing accurate answers based strictly on the connected documentation repository.\n# Core Principles\n1. **Knowledge Base Only**: Answer questions EXCLUSIVELY based on information retrieved from the connected knowledge base.\n2. **No Content Creation**: Never generate, infer, or create information that is not explicitly present in the retrieved documents.\n3. **Source Transparency**: Always indicate when information comes from the knowledge base vs. when it's unavailable.\n4. **Accuracy Over Completeness**: Prefer incomplete but accurate answers over complete but potentially inaccurate ones.\n# Response Guidelines\n## When Information is Available\n- Provide direct answers based on retrieved content\n- Quote relevant sections when helpful\n- Cite the source document/section if available\n- Use phrases like: \"According to the documentation...\" or \"Based on the knowledge base...\"\n## When Information is Unavailable\n- Clearly state: \"I cannot find this information in the current knowledge base.\"\n- Do NOT attempt to fill gaps with general knowledge\n- Suggest alternative questions that might be covered in the docs\n- Use phrases like: \"The documentation does not cover...\" or \"This information is not available in the knowledge base.\"\n# Response Format\n```markdown\n## Answer\n[Your response based strictly on knowledge base content]\n**Always do these:**\n- Use the Retrieval tool for every question\n- Be transparent about information availability\n- Stick to documented facts only\n- Acknowledge knowledge base limitations", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Agent" + }, + "dragging": false, + "id": "Agent:ProudDingosShout", + "measured": { + "height": 86, + "width": 200 + }, + "position": { + "x": 732.9115613823421, + "y": 173.29966667348305 + }, + "selected": true, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:ProudDingosShout@content}" + ] + }, + "label": "Message", + "name": "Message" + }, + "dragging": false, + "id": "Message:DarkRavensType", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1072.2594210214197, + "y": 178.92078947906558 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "Select your desired knowledge base from the dropdown menu. \nThe retrieval assistant will only use data from your selected knowledge base to generate responses." + }, + "label": "Note", + "name": "Workflow overall description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 179, + "id": "Note:HonestHatsSip", + "measured": { + "height": 179, + "width": 345 + }, + "position": { + "x": 79.79276047764881, + "y": -41.86088007502428 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 345 + }, + { + "data": { + "form": { + "text": "Configure the dropdown menu with your knowledge bases for retrieval." + }, + "label": "Note", + "name": "Note: Begin" + }, + "dragHandle": ".note-drag-handle", + "id": "Note:BumpyWaspsAttend", + "measured": { + "height": 136, + "width": 250 + }, + "position": { + "x": 15, + "y": 300 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "The workflow will retrieve data from the knowledge base selected in the dropdown menu." + }, + "label": "Note", + "name": "Note: Retrieval" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:AllFlowersDig", + "measured": { + "height": 136, + "width": 250 + }, + "position": { + "x": 361.872717062755, + "y": 308.6265804950158 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "The Agent will generate responses according to the information retrieved from the chosen knowledge base." + }, + "label": "Note", + "name": "Note: Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:UpsetGlassesDeny", + "measured": { + "height": 136, + "width": 250 + }, + "position": { + "x": 695.7034747745811, + "y": 321.3328650385139 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHA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} \ No newline at end of file diff --git a/agent/templates/chunk_summary.json b/agent/templates/chunk_summary.json new file mode 100644 index 00000000000..c945dee2eb3 --- /dev/null +++ b/agent/templates/chunk_summary.json @@ -0,0 +1,495 @@ +{ + "id": 24, + "title": { + "en": "Chunk Summary", + "de": "Segmentzusammenfassung", + "zh": "总结切片" + }, + "description": { + "en": "This template uses an LLM to generate chunk summaries for building text and vector indexes. During retrieval, summaries enhance matching, and the original chunks are returned as results.", + "de": "Diese Vorlage nutzt ein LLM zur Generierung von Segmentzusammenfassungen für den Aufbau von Text- und Vektorindizes. Bei der Abfrage verbessern die Zusammenfassungen die Übereinstimmung, während die ursprünglichen Segmente als Ergebnisse zurückgegeben werden.", + "zh": "此模板利用大模型生成切片摘要,并据此建立全文索引与向量。检索时以摘要提升匹配效果,最终召回对应的原文切片。" + }, + "canvas_type": "Ingestion Pipeline", + "canvas_category": "dataflow_canvas", + "dsl": { + "components": { + "File": { + "obj": { + "component_name": "File", + "params": {} + }, + "downstream": [ + "Parser:HipSignsRhyme" + ], + "upstream": [] + }, + "Parser:HipSignsRhyme": { + "obj": { + "component_name": "Parser", + "params": { + "outputs": { + "html": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + }, + "markdown": { + "type": "string", + "value": "" + }, + "text": { + "type": "string", + "value": "" + } + }, + "setups": { + "pdf": { + "output_format": "json", + "suffix": [ + "pdf" + ], + "parse_method": "DeepDOC" + }, + "spreadsheet": { + "output_format": "html", + "suffix": [ + "xls", + "xlsx", + "csv" + ] + }, + "image": { + "output_format": "text", + "suffix": [ + "jpg", + "jpeg", + "png", + "gif" + ], + "parse_method": "ocr" + }, + "email": { + "output_format": "text", + "suffix": [ + "eml", + "msg" + ], + "fields": [ + "from", + "to", + "cc", + "bcc", + "date", + "subject", + "body", + "attachments" + ] + }, + "text&markdown": { + "output_format": "text", + "suffix": [ + "md", + "markdown", + "mdx", + "txt" + ] + }, + "word": { + "output_format": "json", + "suffix": [ + "doc", + "docx" + ] + }, + "slides": { + "output_format": "json", + "suffix": [ + "pptx" + ] + } + } + } + }, + "downstream": [ + "Splitter:LateExpertsFeel" + ], + "upstream": [ + "File" + ] + }, + "Splitter:LateExpertsFeel": { + "obj": { + "component_name": "Splitter", + "params": { + "chunk_token_size": 512, + "delimiters": [ + "\n" + ], + "outputs": { + "chunks": { + "type": "Array", + "value": [] + } + }, + "overlapped_percent": 0 + } + }, + "downstream": [ + "Extractor:YummyGhostsType" + ], + "upstream": [ + "Parser:HipSignsRhyme" + ] + }, + "Tokenizer:EightRocketsAppear": { + "obj": { + "component_name": "Tokenizer", + "params": { + "fields": "summary", + "filename_embd_weight": 0.1, + "outputs": {}, + "search_method": [ + "embedding", + "full_text" + ] + } + }, + "downstream": [], + "upstream": [ + "Extractor:YummyGhostsType" + ] + }, + "Extractor:YummyGhostsType": { + "obj": { + "component_name": "Extractor", + "params": { + "field_name": "summary", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 256, + "outputs": { + "chunks": { + "type": "Array", + "value": [] + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "Text to Summarize:\n\n\n{Splitter:LateExpertsFeel@chunks}", + "role": "user" + } + ], + "sys_prompt": "Act as a precise summarizer. Your task is to create a summary of the provided content that is both concise and faithful to the original.\n\nKey Instructions:\n1. Accuracy: Strictly base the summary on the information given. Do not introduce any new facts, conclusions, or interpretations that are not explicitly stated.\n2. Language: Write the summary in the same language as the source text.\n3. Objectivity: Present the key points without bias, preserving the original intent and tone of the content. Do not editorialize.\n4. Conciseness: Focus on the most important ideas, omitting minor details and fluff.", + "temperature": 0.1, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.3 + } + }, + "downstream": [ + "Tokenizer:EightRocketsAppear" + ], + "upstream": [ + "Splitter:LateExpertsFeel" + ] + } + }, + "globals": {}, + "graph": { + "nodes": [ + { + "data": { + "label": "File", + "name": "File" + }, + "id": "File", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "outputs": { + "html": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + }, + "markdown": { + "type": "string", + "value": "" + }, + "text": { + "type": "string", + "value": "" + } + }, + "setups": [ + { + "fileFormat": "pdf", + "output_format": "json", + "parse_method": "DeepDOC" + }, + { + "fileFormat": "spreadsheet", + "output_format": "html" + }, + { + "fileFormat": "image", + "output_format": "text", + "parse_method": "ocr" + }, + { + "fields": [ + "from", + "to", + "cc", + "bcc", + "date", + "subject", + "body", + "attachments" + ], + "fileFormat": "email", + "output_format": "text" + }, + { + "fileFormat": "text&markdown", + "output_format": "text" + }, + { + "fileFormat": "word", + "output_format": "json" + }, + { + "fileFormat": "slides", + "output_format": "json" + } + ] + }, + "label": "Parser", + "name": "Parser" + }, + "dragging": false, + "id": "Parser:HipSignsRhyme", + "measured": { + "height": 412, + "width": 200 + }, + "position": { + "x": 316.99524094206413, + "y": 195.39629819663406 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "parserNode" + }, + { + "data": { + "form": { + "chunk_token_size": 512, + "delimiters": [ + { + "value": "\n" + } + ], + "outputs": { + "chunks": { + "type": "Array", + "value": [] + } + }, + "overlapped_percent": 0 + }, + "label": "Splitter", + "name": "Token Splitter" + }, + "dragging": false, + "id": "Splitter:LateExpertsFeel", + "measured": { + "height": 80, + "width": 200 + }, + "position": { + "x": 600.5891036507014, + "y": 197.6804920892271 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "splitterNode" + }, + { + "data": { + "form": { + "fields": "summary", + "filename_embd_weight": 0.1, + "outputs": {}, + "search_method": [ + "embedding", + "full_text" + ] + }, + "label": "Tokenizer", + "name": "Indexer" + }, + "dragging": false, + "id": "Tokenizer:EightRocketsAppear", + "measured": { + "height": 120, + "width": 200 + }, + "position": { + "x": 1136.0745258879847, + "y": 202.22674640530906 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "tokenizerNode" + }, + { + "data": { + "form": { + "field_name": "summary", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 256, + "outputs": { + "chunks": { + "type": "Array", + "value": [] + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": "Text to Summarize:\n\n\n{Splitter:LateExpertsFeel@chunks}", + "sys_prompt": "Act as a precise summarizer. Your task is to create a summary of the provided content that is both concise and faithful to the original.\n\nKey Instructions:\n1. Accuracy: Strictly base the summary on the information given. Do not introduce any new facts, conclusions, or interpretations that are not explicitly stated.\n2. Language: Write the summary in the same language as the source text.\n3. Objectivity: Present the key points without bias, preserving the original intent and tone of the content. Do not editorialize.\n4. Conciseness: Focus on the most important ideas, omitting minor details and fluff.", + "temperature": 0.1, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.3 + }, + "label": "Extractor", + "name": "Transformer" + }, + "dragging": false, + "id": "Extractor:YummyGhostsType", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 870.1728208672672, + "y": 201.4516837225608 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "contextNode" + }, + { + "id": "Note:MightyPandasWatch", + "type": "noteNode", + "position": { + "x": 1128.1996486833773, + "y": 342.4601052720091 + }, + "data": { + "label": "Note", + "name": "Index summary", + "form": { + "text": "Using summary to build both text and vector indexes." + } + }, + "sourcePosition": "right", + "targetPosition": "left", + "dragHandle": ".note-drag-handle", + "measured": { + "width": 249, + "height": 128 + }, + "selected": false, + "dragging": false + } + ], + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Filestart-Parser:HipSignsRhymeend", + "source": "File", + "sourceHandle": "start", + "target": "Parser:HipSignsRhyme", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Parser:HipSignsRhymestart-Splitter:LateExpertsFeelend", + "source": "Parser:HipSignsRhyme", + "sourceHandle": "start", + "target": "Splitter:LateExpertsFeel", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Splitter:LateExpertsFeelstart-Extractor:YummyGhostsTypeend", + "source": "Splitter:LateExpertsFeel", + "sourceHandle": "start", + "target": "Extractor:YummyGhostsType", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Extractor:YummyGhostsTypestart-Tokenizer:EightRocketsAppearend", + "markerEnd": "logo", + "source": "Extractor:YummyGhostsType", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Tokenizer:EightRocketsAppear", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA7ESURBVHgBvVpLrF1lFV7/v/c+j3t729tSClZCigXFF/JQE21CaKITHcAEica5UwcmDsW5A4mJTIwzB5iQiMTIwAhGQzQSrKJIomADWkpLuX3cx3ns/f9+31rrP4/b2xqNsJtzzzn7/I/1r/Wtbz12g+y6Nq7kB1KQB0OSh3KQY/IeXV0QyXn5Xox4JZEQ5BR+OhUr+fbBYTi9OCaUDxs5r8umfAvjvy7v8pX9lfRvuP5g/Fznpe/fjVMc5GC4KGU2hU9b8izWu1vepUsFVi1nCD4XOha5YPLFw+S88Bkfe9nWcKFPhVZO8hA2H5p/t4RvQ5YJ3qfYfdpl6Vz9lQsfY1aoVPhWQdJQXrgfgonMt2mYmwGf7k4NZOZvGzv5WGrlH/J/uqjlhB06mWOaugSOZ9qm0LxbJ8LILvqAyohBwXC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S2rPZ6gwrcOE5uyNxPxGrjw3Id9Yr4rhNLewuPWY3hSf1pX3NjI67mRZ6f+yLUcIl+HDWxzOxApsCpPZoLxf8rlicJe8+ZPcbxKVaFdMBU4XMeZcbJTcbrwXw34ATX1SYj72NK4kJcssiS4czSDDjVeOzW2M9qM19rcfMsFTQvCc6uC72td1HwR3pdbvt7cyceqLj2Knz6Br2qRRUvMtBesn6S4l3xd7i6CK6MkrVPcYa3bEfN/mJrlNPTyFIb9hJBf/O3fQ3B6D7564aoAAAAASUVORK5CYII=" +} \ No newline at end of file diff --git a/agent/templates/customer_review_analysis.json b/agent/templates/customer_review_analysis.json new file mode 100644 index 00000000000..b6ecc76846d --- /dev/null +++ b/agent/templates/customer_review_analysis.json @@ -0,0 +1,802 @@ + +{ + "id": 11, + "title": { + "en": "Customer Review Analysis", + "de": "Kundenbewertungsanalyse", + "zh": "客户评价分析"}, + "description": { + "en": "Automatically classify customer reviews using LLM (Large Language Model) and route them via email to the relevant departments.", + "de": "Klassifiziert automatisch Kundenbewertungen mithilfe von LLM (Large Language Model) und leitet sie per E-Mail an die zuständigen Abteilungen weiter.", + "zh": "大模型将自动分类客户评价,并通过电子邮件将结果发送到相关部门。"}, + "canvas_type": "Customer Support", + "dsl": { + "components": { + "Categorize:FourTeamsFold": { + "downstream": [ + "Email:SharpDeerExist", + "Email:ChillyBusesDraw" + ], + "obj": { + "component_name": "Categorize", + "params": { + "category_description": { + "After-sales issues": { + "description": "The negative review is about after-sales issues.", + "examples": [ + "1. The product easily broke down.\n2. I need to change a new one.\n3. It is not the type I ordered." + ], + "to": [ + "Email:SharpDeerExist" + ] + }, + "Transportation issue": { + "description": "The negative review is about transportation issue.", + "examples": [ + "1. The transportation is delayed too much.\n2. I can't find where is my order now." + ], + "to": [ + "Email:ChillyBusesDraw" + ] + } + }, + "llm_id": "deepseek-chat@DeepSeek", + "message_history_window_size": 1, + "outputs": { + "category_name": { + "type": "string" + } + }, + "query": "sys.query", + "temperature": 0 + } + }, + "upstream": [ + "Categorize:RottenWallsObey" + ] + }, + "Categorize:RottenWallsObey": { + "downstream": [ + "Categorize:FourTeamsFold", + "Email:WickedSymbolsLeave" + ], + "obj": { + "component_name": "Categorize", + "params": { + "category_description": { + "Negative review ": { + "description": "Negative review to the product.", + "examples": [ + "1. I have issues. \n2. Too many problems.\n3. I don't like it." + ], + "to": [ + "Categorize:FourTeamsFold" + ] + }, + "Positive review": { + "description": "Positive review to the product.", + "examples": [ + "1. Good, I like it.\n2. It is very helpful.\n3. It makes my work easier." + ], + "to": [ + "Email:WickedSymbolsLeave" + ] + } + }, + "llm_filter": "all", + "llm_id": "deepseek-chat@DeepSeek", + "message_history_window_size": 1, + "outputs": { + "category_name": { + "type": "string" + } + }, + "query": "sys.query" + } + }, + "upstream": [ + "begin" + ] + }, + "Email:ChillyBusesDraw": { + "downstream": [ + "StringTransform:FuzzySpiesTrain" + ], + "obj": { + "component_name": "Email", + "params": { + "cc_email": "", + "content": "{begin@1}", + "email": "", + "outputs": { + "success": { + "type": "boolean", + "value": true + } + }, + "password": "", + "sender_name": "", + "smtp_port": 465, + "smtp_server": "", + "subject": "", + "to_email": "" + } + }, + "upstream": [ + "Categorize:FourTeamsFold" + ] + }, + "Email:SharpDeerExist": { + "downstream": [ + "StringTransform:FuzzySpiesTrain" + ], + "obj": { + "component_name": "Email", + "params": { + "cc_email": "", + "content": "{begin@1}", + "email": "", + "outputs": { + "success": { + "type": "boolean", + "value": true + } + }, + "password": "", + "sender_name": "", + "smtp_port": 465, + "smtp_server": "", + "subject": "", + "to_email": "" + } + }, + "upstream": [ + "Categorize:FourTeamsFold" + ] + }, + "Email:WickedSymbolsLeave": { + "downstream": [ + "StringTransform:FuzzySpiesTrain" + ], + "obj": { + "component_name": "Email", + "params": { + "cc_email": "", + "content": "{begin@1}", + "email": "", + "outputs": { + "success": { + "type": "boolean", + "value": true + } + }, + "password": "", + "sender_name": "", + "smtp_port": 465, + "smtp_server": "", + "subject": "", + "to_email": "" + } + }, + "upstream": [ + "Categorize:RottenWallsObey" + ] + }, + "Message:ShaggyAnimalsWin": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{StringTransform:FuzzySpiesTrain@result}" + ] + } + }, + "upstream": [ + "StringTransform:FuzzySpiesTrain" + ] + }, + "StringTransform:FuzzySpiesTrain": { + "downstream": [ + "Message:ShaggyAnimalsWin" + ], + "obj": { + "component_name": "StringTransform", + "params": { + "delimiters": [ + "," + ], + "method": "merge", + "outputs": { + "result": { + "type": "string" + } + }, + "script": "{Email:WickedSymbolsLeave@success}{Email:SharpDeerExist@success}{Email:ChillyBusesDraw@success}", + "split_ref": "" + } + }, + "upstream": [ + "Email:WickedSymbolsLeave", + "Email:SharpDeerExist", + "Email:ChillyBusesDraw" + ] + }, + "begin": { + "downstream": [ + "Categorize:RottenWallsObey" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": { + "1": { + "key": "1", + "name": "review", + "optional": false, + "options": [], + "type": "line", + "value": "test" + } + }, + "mode": "conversational", + "prologue": "Hi! I'm your customer review analysis assistant. You can send a review to me.\n" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Categorize:RottenWallsObeyend", + "source": "begin", + "sourceHandle": "start", + "target": "Categorize:RottenWallsObey", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Categorize:RottenWallsObeyc8aacd5d-eb40-45a2-bc8f-94d016d7f6c0-Categorize:FourTeamsFoldend", + "source": "Categorize:RottenWallsObey", + "sourceHandle": "c8aacd5d-eb40-45a2-bc8f-94d016d7f6c0", + "target": "Categorize:FourTeamsFold", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Categorize:RottenWallsObey16f0d215-18b8-400e-98f2-f3e30aa28ff9-Email:WickedSymbolsLeaveend", + "source": "Categorize:RottenWallsObey", + "sourceHandle": "16f0d215-18b8-400e-98f2-f3e30aa28ff9", + "target": "Email:WickedSymbolsLeave", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Categorize:FourTeamsFolda1f3068c-85d8-4cfa-aa86-ef1f71d2edce-Email:SharpDeerExistend", + "source": "Categorize:FourTeamsFold", + "sourceHandle": "a1f3068c-85d8-4cfa-aa86-ef1f71d2edce", + "target": "Email:SharpDeerExist", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Categorize:FourTeamsFold2fda442d-8580-440c-a947-0df607ca56fe-Email:ChillyBusesDrawend", + "source": "Categorize:FourTeamsFold", + "sourceHandle": "2fda442d-8580-440c-a947-0df607ca56fe", + "target": "Email:ChillyBusesDraw", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Email:WickedSymbolsLeavestart-StringTransform:FuzzySpiesTrainend", + "source": "Email:WickedSymbolsLeave", + "sourceHandle": "start", + "target": "StringTransform:FuzzySpiesTrain", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Email:SharpDeerExiststart-StringTransform:FuzzySpiesTrainend", + "markerEnd": "logo", + "source": "Email:SharpDeerExist", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "StringTransform:FuzzySpiesTrain", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Email:ChillyBusesDrawstart-StringTransform:FuzzySpiesTrainend", + "markerEnd": "logo", + "source": "Email:ChillyBusesDraw", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "StringTransform:FuzzySpiesTrain", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__StringTransform:FuzzySpiesTrainstart-Message:ShaggyAnimalsWinend", + "source": "StringTransform:FuzzySpiesTrain", + "sourceHandle": "start", + "target": "Message:ShaggyAnimalsWin", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": { + "1": { + "key": "1", + "name": "review", + "optional": false, + "options": [], + "type": "line", + "value": "" + } + }, + "mode": "conversational", + "prologue": "Hi! I'm your customer review analysis assistant. You can send a review to me.\n" + }, + "label": "Begin", + "name": "begin" + }, + "dragging": false, + "id": "begin", + "measured": { + "height": 76, + "width": 200 + }, + "position": { + "x": 53.79637618636758, + "y": 55.73770491803276 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "items": [ + { + "description": "Positive review to the product.", + "examples": [ + { + "value": "1. Good, I like it.\n2. It is very helpful.\n3. It makes my work easier." + } + ], + "name": "Positive review", + "uuid": "16f0d215-18b8-400e-98f2-f3e30aa28ff9" + }, + { + "description": "Negative review to the product.", + "examples": [ + { + "value": "1. I have issues. \n2. Too many problems.\n3. I don't like it." + } + ], + "name": "Negative review ", + "uuid": "c8aacd5d-eb40-45a2-bc8f-94d016d7f6c0" + } + ], + "llm_filter": "all", + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 4096, + "message_history_window_size": 1, + "outputs": { + "category_name": { + "type": "string" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "query": "sys.query", + "temperature": 0.2, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.75 + }, + "label": "Categorize", + "name": "Review categorize" + }, + "dragging": false, + "id": "Categorize:RottenWallsObey", + "measured": { + "height": 140, + "width": 200 + }, + "position": { + "x": 374.0221988829014, + "y": 37.350593375729275 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "categorizeNode" + }, + { + "data": { + "form": { + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "items": [ + { + "description": "The negative review is about after-sales issues.", + "examples": [ + { + "value": "1. The product easily broke down.\n2. I need to change a new one.\n3. It is not the type I ordered." + } + ], + "name": "After-sales issues", + "uuid": "a1f3068c-85d8-4cfa-aa86-ef1f71d2edce" + }, + { + "description": "The negative review is about transportation issue.", + "examples": [ + { + "value": "1. The transportation is delayed too much.\n2. I can't find where is my order now." + } + ], + "name": "Transportation issue", + "uuid": "2fda442d-8580-440c-a947-0df607ca56fe" + } + ], + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 256, + "message_history_window_size": 1, + "outputs": { + "category_name": { + "type": "string" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "query": "sys.query", + "temperature": 0, + "temperatureEnabled": true, + "topPEnabled": false, + "top_p": 0.3 + }, + "label": "Categorize", + "name": "Negative review categorize" + }, + "dragging": false, + "id": "Categorize:FourTeamsFold", + "measured": { + "height": 140, + "width": 200 + }, + "position": { + "x": 706.0637059431883, + "y": 244.46649585736282 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "categorizeNode" + }, + { + "data": { + "form": { + "cc_email": "", + "content": "{begin@1}", + "email": "", + "outputs": { + "success": { + "type": "boolean", + "value": true + } + }, + "password": "", + "sender_name": "", + "smtp_port": 465, + "smtp_server": "", + "subject": "", + "to_email": "" + }, + "label": "Email", + "name": "Email: positive " + }, + "dragging": false, + "id": "Email:WickedSymbolsLeave", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1034.9790998533604, + "y": -253.19781265954452 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "ragNode" + }, + { + "data": { + "form": { + "cc_email": "", + "content": "{begin@1}", + "email": "", + "outputs": { + "success": { + "type": "boolean", + "value": true + } + }, + "password": "", + "sender_name": "", + "smtp_port": 465, + "smtp_server": "", + "subject": "", + "to_email": "" + }, + "label": "Email", + "name": "Email: after-sales" + }, + "dragging": false, + "id": "Email:SharpDeerExist", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1109.6114876248466, + "y": 111.37592732297131 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "ragNode" + }, + { + "data": { + "form": { + "cc_email": "", + "content": "{begin@1}", + "email": "", + "outputs": { + "success": { + "type": "boolean", + "value": true + } + }, + "password": "", + "sender_name": "", + "smtp_port": 465, + "smtp_server": "", + "subject": "", + "to_email": "" + }, + "label": "Email", + "name": "Email: transportation" + }, + "dragging": false, + "id": "Email:ChillyBusesDraw", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1115.6114876248466, + "y": 476.4689932718253 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "ragNode" + }, + { + "data": { + "form": { + "delimiters": [ + "," + ], + "method": "merge", + "outputs": { + "result": { + "type": "string" + } + }, + "script": "{Email:WickedSymbolsLeave@success}{Email:SharpDeerExist@success}{Email:ChillyBusesDraw@success}", + "split_ref": "" + }, + "label": "StringTransform", + "name": "Merge results" + }, + "dragging": false, + "id": "StringTransform:FuzzySpiesTrain", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1696.9790998533604, + "y": 112.80218734045546 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "ragNode" + }, + { + "data": { + "form": { + "content": [ + "{StringTransform:FuzzySpiesTrain@result}" + ] + }, + "label": "Message", + "name": "Message" + }, + "dragging": false, + "id": "Message:ShaggyAnimalsWin", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1960.9013768854911, + "y": 112.43528348294187 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "Send positive feedback to the company's brand marketing department system" + }, + "label": "Note", + "name": "Note_0" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:FancyTownsSing", + "measured": { + "height": 136, + "width": 244 + }, + "position": { + "x": 1010, + "y": -167 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "Send after-sales issues to the product experience department" + }, + "label": "Note", + "name": "Note_1" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:SillyLampsDrum", + "measured": { + "height": 136, + "width": 244 + }, + "position": { + "x": 1108, + "y": 195 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "Send negative transportation feedback to the transportation department" + }, + "label": "Note", + "name": "Note_2" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:GreenNewsMake", + "measured": { + "height": 136, + "width": 244 + }, + "position": { + "x": 1119, + "y": 574 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "This workflow automatically classifies customer reviews using LLM (Large Language Model) and route them via email to the relevant departments." + }, + "label": "Note", + "name": "Workflow Overall Description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 146, + "id": "Note:TangyHairsShow", + "measured": { + "height": 146, + "width": 360 + }, + "position": { + "x": 55.192937758820676, + "y": 185.32156293136785 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 360 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABdsSURBVHgBXVpZjGTnVf7uUrf2vaq7q3t6menx2OOxnY7HcSYJ4CSAFYiiBAgSRDxgCaTwlCBFiLdMxAO8JXkA5S3AQ0SEgCRCIiGBxNiQOInt8ezTM91dvXd1V3VVdS331l35zn97xsuMy9Vdy71n+c53vnP+0fCeP1/9qy991Ij0TwPRZ7Qo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CjrHnfxvqV5BIQvD75gLlBesJ7k2JcH3V/XM9mXXvqbb/Ti1cJ7/vz43765xFRfdbTE+5qbeys290Ob29vEN7FMyiuQlaSVd/tdzM0vqpqQ5rdMGMl+X45PRaeIbvKopWSfKWdfAzatI8qB1kELx6yZDrcNfdaL/IsUk7WRZe1lSbVFLoZlxXPl/CKqHmuLc4ZXaTQro73vDna2vvP7V7/2k3fa+/+AMZFpzxr4yQAAAABJRU5ErkJggg==" +} \ No newline at end of file diff --git a/agent/templates/customer_service.json b/agent/templates/customer_service.json index d3dcc70fe1a..24e022feda6 100644 --- a/agent/templates/customer_service.json +++ b/agent/templates/customer_service.json @@ -1,1068 +1,717 @@ + { - "id": 3, - "title": "Customer service", - "description": "A customer service chatbot that explains product specifications, addresses customer queries, and alleviates negative emotions.", - "canvas_type": "chatbot", - "dsl": { - "answer": [], - "components": { - "Categorize:EightyWavesEnd": { - "downstream": [ - "Generate:FullBeersSit", - "Message:GoodBugsTurn", - "Retrieval:WholeStarsDrive", - "Generate:EasyWaysBeg" - ], - "obj": { - "component_name": "Categorize", - "inputs": [], - "output": null, - "params": { - "category_description": { - "1. contact": { - "description": "This answer provide a specific contact information, like e-mail, phone number, wechat number, line number, twitter, discord, etc,.", - "examples": "My phone number is 203921\nkevinhu.hk@gmail.com\nThis is my discord number: johndowson_29384\n13212123432\n8379829", - "to": "Message:GoodBugsTurn" - }, - "2. casual": { - "description": "The question is not about the product usage, appearance and how it works. Just casual chat.", - "examples": "How are you doing?\nWhat is your name?\nAre you a robot?\nWhat's the weather?\nWill it rain?", - "to": "Generate:EasyWaysBeg" - }, - "3. complain": { - "description": "Complain even curse about the product or service you provide. But the comment is not specific enough.", - "examples": "How bad is it.\nIt's really sucks.\nDamn, for God's sake, can it be more steady?\nShit, I just can't use this shit.\nI can't stand it anymore.", - "to": "Generate:FullBeersSit" - }, - "4. product related": { - "description": "The question is about the product usage, appearance and how it works.", - "examples": "Why it always beaming?\nHow to install it onto the wall?\nIt leaks, what to do?\nException: Can't connect to ES cluster\nHow to build the RAGFlow image from scratch", - "to": "Retrieval:WholeStarsDrive" - } - }, - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 512, - "message_history_window_size": 8, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "", - "query": [{ - "type": "reference", - "component_id": "RewriteQuestion:AllNightsSniff" - }], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "RewriteQuestion:AllNightsSniff" - ] - }, - "Generate:EasyWaysBeg": { - "downstream": [ - "answer:0" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "You are a customer support. But the customer wants to have a casual chat with you instead of consulting about the product. Be nice, funny, enthusiasm and concern.", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Categorize:EightyWavesEnd" - ] - }, - "Generate:FullBeersSit": { - "downstream": [ - "answer:0" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "You are a customer support. the Customers complain even curse about the products but not specific enough. You need to ask him/her what's the specific problem with the product. Be nice, patient and concern to soothe your customers’ emotions at first place.", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Categorize:EightyWavesEnd" - ] - }, - "Generate:YoungTrainsSee": { - "downstream": [ - "answer:0" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are a customer support. \n\nTask: Please answer the question based on content of knowledge base. \n\nRequirements & restrictions:\n - DO NOT make things up when all knowledge base content is irrelevant to the question. \n - Answers need to consider chat history.\n - Request about customer's contact information like, Wechat number, LINE number, twitter, discord, etc,. , when knowledge base content can't answer his question. So, product expert could contact him soon to solve his problem.\n\n Knowledge base content is as following:\n {Retrieval:WholeStarsDrive}\n The above is the content of knowledge base.", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Retrieval:WholeStarsDrive" - ] - }, - "Message:GoodBugsTurn": { - "downstream": [ - "answer:0" - ], - "obj": { - "component_name": "Message", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "messages": [ - "Okay, I've already write this down. What else I can do for you?", - "Get it. What else I can do for you?", - "Thanks for your trust! Our expert will contact ASAP. So, anything else I can do for you?", - "Thanks! So, anything else I can do for you?" - ], - "output": null, - "output_var_name": "output", - "query": [] - } - }, - "upstream": [ - "Categorize:EightyWavesEnd" - ] - }, - "Retrieval:WholeStarsDrive": { - "downstream": [ - "Generate:YoungTrainsSee" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "empty_response": "", - "inputs": [], - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "rerank_id": "", - "similarity_threshold": 0.2, - "top_k": 1024, - "top_n": 6, - "query": [{ - "type": "reference", - "component_id": "RewriteQuestion:AllNightsSniff" - }], - "use_kg": false - } - }, - "upstream": [ - "Categorize:EightyWavesEnd" - ] - }, - "RewriteQuestion:AllNightsSniff": { - "downstream": [ - "Categorize:EightyWavesEnd" - ], - "obj": { - "component_name": "RewriteQuestion", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "loop": 1, - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 6, - "output": null, - "output_var_name": "output", - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "", - "query": [], - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - } - }, - "upstream": [ - "answer:0" - ] - }, - "answer:0": { - "downstream": [ - "RewriteQuestion:AllNightsSniff" - ], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "Message:GoodBugsTurn", - "Generate:FullBeersSit", - "begin", - "Generate:YoungTrainsSee", - "Generate:EasyWaysBeg" - ] - }, - "begin": { - "downstream": [ - "answer:0" - ], - "obj": { - "component_name": "Begin", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "prologue": "Hi! How can I help you?", - "query": [] - } - }, - "upstream": [] - } - }, - "embed_id": "", - "graph": { - "edges": [ - { - "id": "reactflow__edge-Retrieval:WholeStarsDriveb-Generate:YoungTrainsSeeb", - "markerEnd": "logo", - "source": "Retrieval:WholeStarsDrive", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:YoungTrainsSee", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Message:GoodBugsTurnb-answer:0b", - "markerEnd": "logo", - "source": "Message:GoodBugsTurn", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "answer:0", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:FullBeersSitb-answer:0b", - "markerEnd": "logo", - "source": "Generate:FullBeersSit", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "answer:0", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-begin-answer:0b", - "markerEnd": "logo", - "source": "begin", - "sourceHandle": null, - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "answer:0", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:YoungTrainsSeec-answer:0b", - "markerEnd": "logo", - "source": "Generate:YoungTrainsSee", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "answer:0", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "xy-edge__answer:0c-RewriteQuestion:AllNightsSniffb", - "markerEnd": "logo", - "source": "answer:0", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "RewriteQuestion:AllNightsSniff", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__RewriteQuestion:AllNightsSniffc-Categorize:EightyWavesEnda", - "markerEnd": "logo", - "source": "RewriteQuestion:AllNightsSniff", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Categorize:EightyWavesEnd", - "targetHandle": "a", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "reactflow__edge-Categorize:EightyWavesEnd3. complain-Generate:FullBeersSitc", - "markerEnd": "logo", - "source": "Categorize:EightyWavesEnd", - "sourceHandle": "3. complain", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:FullBeersSit", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Categorize:EightyWavesEnd1. contact-Message:GoodBugsTurnc", - "markerEnd": "logo", - "source": "Categorize:EightyWavesEnd", - "sourceHandle": "1. contact", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Message:GoodBugsTurn", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "xy-edge__Categorize:EightyWavesEnd4. product related-Retrieval:WholeStarsDrivec", - "markerEnd": "logo", - "source": "Categorize:EightyWavesEnd", - "sourceHandle": "4. product related", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:WholeStarsDrive", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:EasyWaysBegb-answer:0b", - "markerEnd": "logo", - "source": "Generate:EasyWaysBeg", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "answer:0", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Categorize:EightyWavesEnd2. casual-Generate:EasyWaysBegc", - "markerEnd": "logo", - "source": "Categorize:EightyWavesEnd", - "sourceHandle": "2. casual", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:EasyWaysBeg", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - } - ], - "nodes": [ - { - "data": { - "form": { - "prologue": "Hi! How can I help you?" - }, - "label": "Begin", - "name": "Opener" - }, - "dragging": false, - "height": 44, - "id": "begin", - "measured": { - "height": 44, - "width": 100 - }, - "position": { - "x": 392.4805720357097, - "y": -51.634011497163186 - }, - "positionAbsolute": { - "x": 392.4805720357097, - "y": -51.634011497163186 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "beginNode" - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "Interface" - }, - "dragging": false, - "height": 44, - "id": "answer:0", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 254.80252337926834, - "y": 311.451851495964 - }, - "positionAbsolute": { - "x": 248.41227675535197, - "y": 216.6631932412045 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "category_description": { - "1. contact": { - "description": "This answer provide a specific contact information, like e-mail, phone number, wechat number, line number, twitter, discord, etc,.", - "examples": "My phone number is 203921\nkevinhu.hk@gmail.com\nThis is my discord number: johndowson_29384\n13212123432\n8379829", - "to": "Message:GoodBugsTurn" + "id": 2, + "title": { + "en": "Multi-Agent Customer Support", + "de": "Multi Agenten Kundensupport", + "zh": "多智能体客服"}, + "description": { + "en": "This is a multi-agent system for intelligent customer service processing based on user intent classification. It uses the lead-agent to identify the type of user needs, assign tasks to sub-agents for processing.", + "de": "Dies ist ein Multi-Agenten-System für die intelligente Kundenservice-Verarbeitung basierend auf Benutzerabsichtsklassifizierung. Es verwendet den Haupt-Agenten zur Identifizierung der Art der Benutzerbedürfnisse und weist Aufgaben an Unter-Agenten zur Verarbeitung zu.", + "zh": "多智能体系统,用于智能客服场景。基于用户意图分类,使用主智能体识别用户需求类型,并将任务分配给子智能体进行处理。"}, + "canvas_type": "Agent", + "dsl": { + "components": { + "Agent:RottenRiversDo": { + "downstream": [ + "Message:PurpleCitiesSee" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 2, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role \n\nYou are **Customer Server Agent**. Classify every user message; handle **contact** yourself. This is a multi-agent system.\n\n## Categories \n\n1. **contact** \u2013 user gives phone, e\u2011mail, WeChat, Line, Discord, etc. \n\n2. **casual** \u2013 small talk, not about the product. \n\n3. **complain** \u2013 complaints or profanity about the product/service. \n\n4. **product** \u2013 questions on product use, appearance, function, or errors.\n\n## If contact \n\nReply with one random item below\u2014do not change wording or call sub\u2011agents: \n\n1. Okay, I've already written this down. What else can I do for you? \n\n2. Got it. What else can I do for you? \n\n3. Thanks for your trust! Our expert will contact you ASAP. Anything else I can help with? \n\n4. Thanks! Anything else I can do for you?\n\n\n---\n\n\n## Otherwise (casual\u202f/\u202fcomplain\u202f/\u202fproduct) \n\nLet Sub\u2011Agent returns its answer\n\n## Sub\u2011Agent \n\n- casual \u2192 **Casual Agent** \nThis is an agent for handles casual conversationk.\n\n- complain \u2192 **Soothe Agent** \nThis is an agent for handles complaints or emotional input.\n\n- product \u2192 **Product Agent** \nThis is an agent for handles product-related queries and can use the `Retrieval` tool.\n\n## Importance\n\n- When the Sub\u2011Agent returns its answer, forward that answer to the user verbatim \u2014 do not add, edit, or reason further.\n ", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Agent", + "id": "Agent:SlowKiwisBehave", + "name": "Casual Agent", + "params": { + "delay_after_error": 1, + "description": "This is an agent for handles casual conversationk.", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 1, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a friendly and casual conversational assistant. \n\nYour primary goal is to engage users in light and enjoyable daily conversation. \n\n- Keep a natural, relaxed, and positive tone. \n\n- Avoid sensitive, controversial, or negative topics. \n\n- You may gently guide the conversation by introducing related casual topics if the user shows interest. \n\n", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + }, + { + "component_name": "Agent", + "id": "Agent:PoorTaxesRescue", + "name": "Soothe Agent", + "params": { + "delay_after_error": 1, + "description": "This is an agent for handles complaints or emotional input.", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 1, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are an empathetic mood-soothing assistant. \n\nYour role is to comfort and encourage users when they feel upset or frustrated. \n\n- Use a warm, kind, and understanding tone. \n\n- Focus on showing empathy and emotional support rather than solving the problem directly. \n\n- Always encourage users with positive and reassuring statements. ", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + }, + { + "component_name": "Agent", + "id": "Agent:SillyTurkeysRest", + "name": "Product Agent", + "params": { + "delay_after_error": 1, + "description": "This is an agent for handles product-related queries and can use the `Retrieval` tool.", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 2, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role \n\nYou are a Product Information Advisor with access to the **Retrieval** tool.\n\n# Workflow \n\n1. Run **Retrieval** with a focused query from the user\u2019s question. \n\n2. Draft the reply **strictly** from the returned passages. \n\n3. If nothing relevant is retrieved, reply: \n\n \u201cI cannot find relevant documents in the knowledge base.\u201d\n\n# Rules \n\n- No assumptions, guesses, or extra\u2011KB knowledge. \n\n- Factual, concise. Use bullets / numbers when helpful. \n\n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "This is a product knowledge base", + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] }, - "2. casual": { - "description": "The question is not about the product usage, appearance and how it works. Just casual chat.", - "examples": "How are you doing?\nWhat is your name?\nAre you a robot?\nWhat's the weather?\nWill it rain?", - "to": "Generate:EasyWaysBeg" + "Message:PurpleCitiesSee": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:RottenRiversDo@content}" + ] + } + }, + "upstream": [ + "Agent:RottenRiversDo" + ] }, - "3. complain": { - "description": "Complain even curse about the product or service you provide. But the comment is not specific enough.", - "examples": "How bad is it.\nIt's really sucks.\nDamn, for God's sake, can it be more steady?\nShit, I just can't use this shit.\nI can't stand it anymore.", - "to": "Generate:FullBeersSit" - }, - "4. product related": { - "description": "The question is about the product usage, appearance and how it works.", - "examples": "Why it always beaming?\nHow to install it onto the wall?\nIt leaks, what to do?\nException: Can't connect to ES cluster\nHow to build the RAGFlow image from scratch", - "to": "Retrieval:WholeStarsDrive" + "begin": { + "downstream": [ + "Agent:RottenRiversDo" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm an official AI customer service representative. How can I help you?" + } + }, + "upstream": [] } - }, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 512, - "message_history_window_size": 8, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3, - "query": [{ - "type": "reference", - "component_id": "RewriteQuestion:AllNightsSniff" - }] - }, - "label": "Categorize", - "name": "Question Categorize" - }, - "dragging": false, - "height": 223, - "id": "Categorize:EightyWavesEnd", - "measured": { - "height": 223, - "width": 200 - }, - "position": { - "x": -47.29188154660176, - "y": 702.9033359893137 - }, - "positionAbsolute": { - "x": -47.29188154660176, - "y": 702.9033359893137 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "categorizeNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are a customer support. \n\nTask: Please answer the question based on content of knowledge base. \n\nRequirements & restrictions:\n - DO NOT make things up when all knowledge base content is irrelevant to the question. \n - Answers need to consider chat history.\n - Request about customer's contact information like, Wechat number, LINE number, twitter, discord, etc,. , when knowledge base content can't answer his question. So, product expert could contact him soon to solve his problem.\n\n Knowledge base content is as following:\n {Retrieval:WholeStarsDrive}\n The above is the content of knowledge base.", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Product info" - }, - "dragging": false, - "height": 86, - "id": "Generate:YoungTrainsSee", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": 559.5686776472737, - "y": 290.2322665670026 - }, - "positionAbsolute": { - "x": 634.1215549262979, - "y": 195.4436083122431 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "similarity_threshold": 0.2, - "top_k": 1024, - "top_n": 6, - "query": [{ - "type": "reference", - "component_id": "RewriteQuestion:AllNightsSniff" - }] - }, - "label": "Retrieval", - "name": "Search product info" - }, - "dragging": false, - "height": 44, - "id": "Retrieval:WholeStarsDrive", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 667.7576170144173, - "y": 897.9742909437947 - }, - "positionAbsolute": { - "x": 674.4543037737495, - "y": 855.3858500356805 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "messages": [ - "Okay, I've already write this down. What else I can do for you?", - "Get it. What else I can do for you?", - "Thanks for your trust! Our expert will contact ASAP. So, anything else I can do for you?", - "Thanks! So, anything else I can do for you?" - ] - }, - "label": "Message", - "name": "What else?" - }, - "dragging": false, - "height": 185, - "id": "Message:GoodBugsTurn", - "measured": { - "height": 185, - "width": 200 - }, - "position": { - "x": 255.51379306491577, - "y": 378.5054855804349 - }, - "positionAbsolute": { - "x": 255.51379306491577, - "y": 378.5054855804349 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "messageNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "You are a customer support. the Customers complain even curse about the products but not specific enough. You need to ask him/her what's the specific problem with the product. Be nice, patient and concern to soothe your customers’ emotions at first place.", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Soothe mood" - }, - "dragging": false, - "height": 86, - "id": "Generate:FullBeersSit", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": 310.50668739661876, - "y": 752.9913068679249 - }, - "positionAbsolute": { - "x": 282.6177403844678, - "y": 738.0651678233716 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "loop": 1, - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 6, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "RewriteQuestion", - "name": "Refine Question" - }, - "dragging": false, - "height": 86, - "id": "RewriteQuestion:AllNightsSniff", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": -76.01780399206896, - "y": 578.5800110192073 - }, - "positionAbsolute": { - "x": 324.6407948253129, - "y": 858.5461701082726 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "rewriteNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "Receives the user's input and displays content returned by the large model or a static message." - }, - "label": "Note", - "name": "N: Interface" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 165, - "id": "Note:NeatEelsJam", - "measured": { - "height": 165, - "width": 246 - }, - "position": { - "x": 254.241356823277, - "y": 125.88467020717172 - }, - "positionAbsolute": { - "x": 264.90767475037154, - "y": 38.182206466391165 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 157, - "width": 218 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 246 - }, - { - "data": { - "form": { - "text": "The large model returns the product information needed by the user based on the content in the knowledge base." - }, - "label": "Note", - "name": "N: Product info" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 174, - "id": "Note:VastBusesStop", - "measured": { - "height": 174, - "width": 251 - }, - "position": { - "x": 552.2937732862443, - "y": 112.23751311378777 - }, - "positionAbsolute": { - "x": 631.2555350351256, - "y": 39.608910328453874 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 146, - "width": 239 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 251 - }, - { - "data": { - "form": { - "text": "Static messages.\nDefine response after receive user's contact information." - }, - "label": "Note", - "name": "N: What else?" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 140, - "id": "Note:YellowSlothsCall", - "measured": { - "height": 140, - "width": 301 - }, - "position": { - "x": 560.5616335948474, - "y": 442.25458284060795 - }, - "positionAbsolute": { - "x": 555.9717758467305, - "y": 383.35075112209097 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 301 - }, - { - "data": { - "form": { - "text": "LLMs chat with users based on the prompts." - }, - "label": "Note", - "name": "N: Casual & Soothe" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:MightyMealsBegin", - "measured": { - "height": 128, - "width": 330 - }, - "position": { - "x": 602.4076699989065, - "y": 727.2225988541959 - }, - "positionAbsolute": { - "x": 579.1117030677617, - "y": 639.9891755684794 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 330 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 330 - }, - { - "data": { - "form": { - "text": "Receives content related to product usage, appearance, and operation, searches the knowledge base, and returns the retrieved content." }, - "label": "Note", - "name": "N: Search product info" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 164, - "id": "Note:PurpleReadersLike", - "measured": { - "height": 164, - "width": 288 - }, - "position": { - "x": 671.3026627091103, - "y": 969.3826268059544 - }, - "positionAbsolute": { - "x": 713.5806084319482, - "y": 962.5655101584402 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 163, - "width": 271 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 288 - }, - { - "data": { - "form": { - "text": "Complete questions by conversation history.\nUser: What's RAGFlow?\nAssistant: RAGFlow is xxx.\nUser: How to deploy it?\n\nRefine it: How to deploy RAGFlow?" + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" }, - "label": "Note", - "name": "N: Refine Question" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 247, - "id": "Note:TidyJarsCarry", - "measured": { - "height": 247, - "width": 279 - }, - "position": { - "x": -76.39310344274921, - "y": 303.33344775187555 - }, - "positionAbsolute": { - "x": 360.7515003553832, - "y": 968.8600371483907 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 279 - }, - { - "data": { - "form": { - "text": "Determines which category the user's input belongs to and passes it to different components." + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:RottenRiversDoend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:RottenRiversDo", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:RottenRiversDoagentBottom-Agent:SlowKiwisBehaveagentTop", + "source": "Agent:RottenRiversDo", + "sourceHandle": "agentBottom", + "target": "Agent:SlowKiwisBehave", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:RottenRiversDoagentBottom-Agent:PoorTaxesRescueagentTop", + "source": "Agent:RottenRiversDo", + "sourceHandle": "agentBottom", + "target": "Agent:PoorTaxesRescue", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:RottenRiversDoagentBottom-Agent:SillyTurkeysRestagentTop", + "source": "Agent:RottenRiversDo", + "sourceHandle": "agentBottom", + "target": "Agent:SillyTurkeysRest", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:SillyTurkeysResttool-Tool:CrazyShirtsKissend", + "source": "Agent:SillyTurkeysRest", + "sourceHandle": "tool", + "target": "Tool:CrazyShirtsKiss", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:RottenRiversDostart-Message:PurpleCitiesSeeend", + "source": "Agent:RottenRiversDo", + "sourceHandle": "start", + "target": "Message:PurpleCitiesSee", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm an official AI customer service representative. How can I help you?" + }, + "label": "Begin", + "name": "begin" + }, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 2, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role \n\nYou are **Customer Server Agent**. Classify every user message; handle **contact** yourself. This is a multi-agent system.\n\n## Categories \n\n1. **contact** \u2013 user gives phone, e\u2011mail, WeChat, Line, Discord, etc. \n\n2. **casual** \u2013 small talk, not about the product. \n\n3. **complain** \u2013 complaints or profanity about the product/service. \n\n4. **product** \u2013 questions on product use, appearance, function, or errors.\n\n## If contact \n\nReply with one random item below\u2014do not change wording or call sub\u2011agents: \n\n1. Okay, I've already written this down. What else can I do for you? \n\n2. Got it. What else can I do for you? \n\n3. Thanks for your trust! Our expert will contact you ASAP. Anything else I can help with? \n\n4. Thanks! Anything else I can do for you?\n\n\n---\n\n\n## Otherwise (casual\u202f/\u202fcomplain\u202f/\u202fproduct) \n\nLet Sub\u2011Agent returns its answer\n\n## Sub\u2011Agent \n\n- casual \u2192 **Casual Agent** \nThis is an agent for handles casual conversationk.\n\n- complain \u2192 **Soothe Agent** \nThis is an agent for handles complaints or emotional input.\n\n- product \u2192 **Product Agent** \nThis is an agent for handles product-related queries and can use the `Retrieval` tool.\n\n## Importance\n\n- When the Sub\u2011Agent returns its answer, forward that answer to the user verbatim \u2014 do not add, edit, or reason further.\n ", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Customer Server Agent" + }, + "dragging": false, + "id": "Agent:RottenRiversDo", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 350, + "y": 198.88981333505626 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "This is an agent for handles casual conversationk.", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 1, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a friendly and casual conversational assistant. \n\nYour primary goal is to engage users in light and enjoyable daily conversation. \n\n- Keep a natural, relaxed, and positive tone. \n\n- Avoid sensitive, controversial, or negative topics. \n\n- You may gently guide the conversation by introducing related casual topics if the user shows interest. \n\n", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Casual Agent" + }, + "dragging": false, + "id": "Agent:SlowKiwisBehave", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 124.4782938105834, + "y": 402.1704532368496 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "This is an agent for handles complaints or emotional input.", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 1, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are an empathetic mood-soothing assistant. \n\nYour role is to comfort and encourage users when they feel upset or frustrated. \n\n- Use a warm, kind, and understanding tone. \n\n- Focus on showing empathy and emotional support rather than solving the problem directly. \n\n- Always encourage users with positive and reassuring statements. ", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Soothe Agent" + }, + "dragging": false, + "id": "Agent:PoorTaxesRescue", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 402.02090711979577, + "y": 363.3139199638186 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "This is an agent for handles product-related queries and can use the `Retrieval` tool.", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 2, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role \n\nYou are a Product Information Advisor with access to the **Retrieval** tool.\n\n# Workflow \n\n1. Run **Retrieval** with a focused query from the user\u2019s question. \n\n2. Draft the reply **strictly** from the returned passages. \n\n3. If nothing relevant is retrieved, reply: \n\n \u201cI cannot find relevant documents in the knowledge base.\u201d\n\n# Rules \n\n- No assumptions, guesses, or extra\u2011KB knowledge. \n\n- Factual, concise. Use bullets / numbers when helpful. \n\n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "This is a product knowledge base", + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Product Agent" + }, + "dragging": false, + "id": "Agent:SillyTurkeysRest", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 684.0042670887832, + "y": 317.79626670112515 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "dragging": false, + "id": "Tool:CrazyShirtsKiss", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 659.7339736658578, + "y": 443.3638400568565 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:RottenRiversDo@content}" + ] + }, + "label": "Message", + "name": "Response" + }, + "dragging": false, + "id": "Message:PurpleCitiesSee", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 675.534293293706, + "y": 158.92309339708154 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "This is a multi-agent system for intelligent customer service processing based on user intent classification. It uses the lead-agent to identify the type of user needs, assign tasks to sub-agents for processing, and finally the lead agent outputs the results." + }, + "label": "Note", + "name": "Workflow Overall Description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 140, + "id": "Note:MoodyTurtlesCount", + "measured": { + "height": 140, + "width": 385 + }, + "position": { + "x": -59.311679338397, + "y": -2.2203733298874866 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 385 + }, + { + "data": { + "form": { + "text": "Answers will be given strictly according to the content retrieved from the knowledge base." + }, + "label": "Note", + "name": "Product Agent " + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:ColdCoinsBathe", + "measured": { + "height": 136, + "width": 249 + }, + "position": { + "x": 994.4238924667025, + "y": 329.08949370720796 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + } + ] }, - "label": "Note", - "name": "N: Question cate" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 141, - "id": "Note:BigPawsThink", - "measured": { - "height": 141, - "width": 289 - }, - "position": { - "x": -32.89190582677969, - "y": 999.0009887363577 - }, - "positionAbsolute": { - "x": -12.744183915886367, - "y": 966.112564833565 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 289 + "history": [], + "messages": [], + "path": [], + "retrieval": [] }, - { - "data": { - "form": { - "cite": true, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "You are a customer support. But the customer wants to have a casual chat with you instead of consulting about the product. Be nice, funny, enthusiasm and concern.", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Causal chat" - }, - "dragging": false, - "id": "Generate:EasyWaysBeg", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 271.29649004050304, - "y": 621.5563111579619 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - } - ] - }, - "history": [], - "messages": [], - "path": [], - "reference": [] - }, - "avatar": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAEZARcDASIAAhEBAxEB/8QAHwAAAQQDAQEBAQAAAAAAAAAABgUHCAkABAoDAgsB/8QATxAAAQMCBAMFBQUECQIDBwQDAQIDBAURAAYSIQcxQQgTIlFhFDJxgZEJobHB8BUjctEKFjNCUnOy4fEkgkNiwhcYJTRTg5I1NkV0dqK1/8QAHQEAAAcBAQEAAAAAAAAAAAAAAAMEBQYHCAIBCf/EAEcRAAECAwYCCAMEBwcCBwAAAAECEQADIQQFEjFBUWFxBhOBkaGxwfAUIjIHQtHhM1JiY6Li8RUjJENygsKj4zQ1U4OSssP/2gAMAwEAAhEDEQA/AO9jGY8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ltEJPQwC++LrMxRTQep+DBxnYuHYyMNSUowhrVZc2qJvyRkbrB38goK0EzbTMuvX4a6+nrMmlevZ0K2ohtacMN9iQ4Nf4PuCseU3ApaEsaZjvCY3vB7TBhtVLhesU3n//+kru59v7y/A0gLPej8hyFRAAAAAElFTkSuQmCC" +} \ No newline at end of file diff --git a/agent/templates/customer_support.json b/agent/templates/customer_support.json new file mode 100644 index 00000000000..5eaa3789d6e --- /dev/null +++ b/agent/templates/customer_support.json @@ -0,0 +1,886 @@ + +{ + "id": 10, + "title": { + "en":"Customer Support", + "de": "Kundensupport", + "zh": "客户支持"}, + "description": { + "en": "This is an intelligent customer service processing system workflow based on user intent classification. It uses LLM to identify user demand types and transfers them to the corresponding professional agent for processing.", + "de": "Dies ist ein intelligentes Kundenservice-Verarbeitungssystem-Workflow basierend auf Benutzerabsichtsklassifizierung. Es verwendet LLM zur Identifizierung von Benutzeranforderungstypen und überträgt diese zur Verarbeitung an den entsprechenden professionellen Agenten.", + "zh": "工作流系统,用于智能客服场景。基于用户意图分类。使用大模型识别用户需求类型,并将需求转移给相应的智能体进行处理。"}, + "canvas_type": "Customer Support", + "dsl": { + "components": { + "Agent:DullTownsHope": { + "downstream": [ + "Message:GreatDucksArgue" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are an empathetic mood-soothing assistant. \n\nYour role is to comfort and encourage users when they feel upset or frustrated. \n\n- Use a warm, kind, and understanding tone. \n\n- Focus on showing empathy and emotional support rather than solving the problem directly. \n\n- Always encourage users with positive and reassuring statements. ", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Categorize:DullFriendsThank" + ] + }, + "Agent:KhakiSunsJudge": { + "downstream": [ + "Message:GreatDucksArgue" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "The user query is {sys.query}\n\nThe relevant document are {Retrieval:ShyPumasJoke@formalized_content}", + "role": "user" + } + ], + "sys_prompt": "You are a highly professional product information advisor. \n\nYour only mission is to provide accurate, factual, and structured answers to all product-related queries.\n\nAbsolutely no assumptions, guesses, or fabricated content are allowed. \n\n**Key Principles:**\n\n1. **Strict Database Reliance:** \n\n - Every answer must be based solely on the verified product information stored in the relevant documen.\n\n - You are NOT allowed to invent, speculate, or infer details beyond what is retrieved. \n\n - If you cannot find relevant data, respond with: *\"I cannot find this information in our official product database. Please check back later or provide more details for further search.\"*\n\n2. **Information Accuracy and Structure:** \n\n - Provide information in a clear, concise, and professional way. \n\n - Use bullet points or numbered lists if there are multiple key points (e.g., features, price, warranty, technical specifications). \n\n - Always specify the version or model number when applicable to avoid confusion.\n\n3. **Tone and Style:** \n\n - Maintain a polite, professional, and helpful tone at all times. \n\n - Avoid marketing exaggeration or promotional language; stay strictly factual. \n\n - Do not express personal opinions; only cite official product data.\n\n4. **User Guidance:** \n\n - If the user\u2019s query is unclear or too broad, politely request clarification or guide them to provide more specific product details (e.g., product name, model, version). \n\n - Example: *\"Could you please specify the product model or category so I can retrieve the most relevant information for you?\"*\n\n5. **Response Length and Formatting:** \n\n - Keep each answer within 100\u2013150 words for general queries. \n\n - For complex or multi-step explanations, you may extend to 200\u2013250 words, but always remain clear and well-structured.\n\n6. **Critical Reminder:** \n\nYour authority and reliability depend entirely on the relevant document responses. Any fabricated, speculative, or unverified content will be considered a critical failure of your role.\n\n\n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Retrieval:ShyPumasJoke" + ] + }, + "Agent:TwelveOwlsWatch": { + "downstream": [ + "Message:GreatDucksArgue" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a friendly and casual conversational assistant. \n\nYour primary goal is to engage users in light and enjoyable daily conversation. \n\n- Keep a natural, relaxed, and positive tone. \n\n- Avoid sensitive, controversial, or negative topics. \n\n- You may gently guide the conversation by introducing related casual topics if the user shows interest. \n\n", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Categorize:DullFriendsThank" + ] + }, + "Categorize:DullFriendsThank": { + "downstream": [ + "Message:BreezyDonutsHeal", + "Agent:TwelveOwlsWatch", + "Agent:DullTownsHope", + "Retrieval:ShyPumasJoke" + ], + "obj": { + "component_name": "Categorize", + "params": { + "category_description": { + "1. contact": { + "description": "This answer provide a specific contact information, like e-mail, phone number, wechat number, line number, twitter, discord, etc,.", + "examples": [ + "My phone number is 203921\nkevinhu.hk@gmail.com\nThis is my discord number: johndowson_29384\n13212123432\n8379829" + ], + "to": [ + "Message:BreezyDonutsHeal" + ] + }, + "2. casual": { + "description": "The question is not about the product usage, appearance and how it works. Just casual chat.", + "examples": [ + "How are you doing?\nWhat is your name?\nAre you a robot?\nWhat's the weather?\nWill it rain?" + ], + "to": [ + "Agent:TwelveOwlsWatch" + ] + }, + "3. complain": { + "description": "Complain even curse about the product or service you provide. But the comment is not specific enough.", + "examples": [ + "How bad is it.\nIt's really sucks.\nDamn, for God's sake, can it be more steady?\nShit, I just can't use this shit.\nI can't stand it anymore." + ], + "to": [ + "Agent:DullTownsHope" + ] + }, + "4. product related": { + "description": "The question is about the product usage, appearance and how it works.", + "examples": [ + "Why it always beaming?\nHow to install it onto the wall?\nIt leaks, what to do?\nException: Can't connect to ES cluster\nHow to build the RAGFlow image from scratch" + ], + "to": [ + "Retrieval:ShyPumasJoke" + ] + } + }, + "llm_id": "deepseek-chat@DeepSeek", + "message_history_window_size": 1, + "outputs": { + "category_name": { + "type": "string" + } + }, + "query": "sys.query", + "temperature": "0.1" + } + }, + "upstream": [ + "begin" + ] + }, + "Message:BreezyDonutsHeal": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "Okay, I've already write this down. What else I can do for you?", + "Get it. What else I can do for you?", + "Thanks for your trust! Our expert will contact ASAP. So, anything else I can do for you?", + "Thanks! So, anything else I can do for you?" + ] + } + }, + "upstream": [ + "Categorize:DullFriendsThank" + ] + }, + "Message:GreatDucksArgue": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:TwelveOwlsWatch@content}{Agent:DullTownsHope@content}{Agent:KhakiSunsJudge@content}" + ] + } + }, + "upstream": [ + "Agent:TwelveOwlsWatch", + "Agent:DullTownsHope", + "Agent:KhakiSunsJudge" + ] + }, + "Retrieval:ShyPumasJoke": { + "downstream": [ + "Agent:KhakiSunsJudge" + ], + "obj": { + "component_name": "Retrieval", + "params": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "sys.query", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + }, + "upstream": [ + "Categorize:DullFriendsThank" + ] + }, + "begin": { + "downstream": [ + "Categorize:DullFriendsThank" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm an official AI customer service representative. How can I help you?" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Categorize:DullFriendsThankend", + "source": "begin", + "sourceHandle": "start", + "target": "Categorize:DullFriendsThank", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Categorize:DullFriendsThanke4d754a5-a33e-4096-8648-8688e5474a15-Message:BreezyDonutsHealend", + "source": "Categorize:DullFriendsThank", + "sourceHandle": "e4d754a5-a33e-4096-8648-8688e5474a15", + "target": "Message:BreezyDonutsHeal", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Categorize:DullFriendsThank8cbf6ea3-a176-490d-9f8c-86373c932583-Agent:TwelveOwlsWatchend", + "source": "Categorize:DullFriendsThank", + "sourceHandle": "8cbf6ea3-a176-490d-9f8c-86373c932583", + "target": "Agent:TwelveOwlsWatch", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Categorize:DullFriendsThankacc40a78-1b9e-4d2f-b5d6-64e01ab69269-Agent:DullTownsHopeend", + "source": "Categorize:DullFriendsThank", + "sourceHandle": "acc40a78-1b9e-4d2f-b5d6-64e01ab69269", + "target": "Agent:DullTownsHope", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Categorize:DullFriendsThankdfa5eead-9341-4f22-9236-068dbfb745e8-Retrieval:ShyPumasJokeend", + "source": "Categorize:DullFriendsThank", + "sourceHandle": "dfa5eead-9341-4f22-9236-068dbfb745e8", + "target": "Retrieval:ShyPumasJoke", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Retrieval:ShyPumasJokestart-Agent:KhakiSunsJudgeend", + "source": "Retrieval:ShyPumasJoke", + "sourceHandle": "start", + "target": "Agent:KhakiSunsJudge", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:TwelveOwlsWatchstart-Message:GreatDucksArgueend", + "source": "Agent:TwelveOwlsWatch", + "sourceHandle": "start", + "target": "Message:GreatDucksArgue", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:DullTownsHopestart-Message:GreatDucksArgueend", + "markerEnd": "logo", + "source": "Agent:DullTownsHope", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Message:GreatDucksArgue", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:KhakiSunsJudgestart-Message:GreatDucksArgueend", + "markerEnd": "logo", + "source": "Agent:KhakiSunsJudge", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Message:GreatDucksArgue", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm an official AI customer service representative. How can I help you?" + }, + "label": "Begin", + "name": "begin" + }, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "items": [ + { + "description": "This answer provide a specific contact information, like e-mail, phone number, wechat number, line number, twitter, discord, etc,.", + "examples": [ + { + "value": "My phone number is 203921\nkevinhu.hk@gmail.com\nThis is my discord number: johndowson_29384\n13212123432\n8379829" + } + ], + "name": "1. contact", + "uuid": "e4d754a5-a33e-4096-8648-8688e5474a15" + }, + { + "description": "The question is not about the product usage, appearance and how it works. Just casual chat.", + "examples": [ + { + "value": "How are you doing?\nWhat is your name?\nAre you a robot?\nWhat's the weather?\nWill it rain?" + } + ], + "name": "2. casual", + "uuid": "8cbf6ea3-a176-490d-9f8c-86373c932583" + }, + { + "description": "Complain even curse about the product or service you provide. But the comment is not specific enough.", + "examples": [ + { + "value": "How bad is it.\nIt's really sucks.\nDamn, for God's sake, can it be more steady?\nShit, I just can't use this shit.\nI can't stand it anymore." + } + ], + "name": "3. complain", + "uuid": "acc40a78-1b9e-4d2f-b5d6-64e01ab69269" + }, + { + "description": "The question is about the product usage, appearance and how it works.", + "examples": [ + { + "value": "Why it always beaming?\nHow to install it onto the wall?\nIt leaks, what to do?\nException: Can't connect to ES cluster\nHow to build the RAGFlow image from scratch" + } + ], + "name": "4. product related", + "uuid": "dfa5eead-9341-4f22-9236-068dbfb745e8" + } + ], + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_tokens": 4096, + "message_history_window_size": 1, + "outputs": { + "category_name": { + "type": "string" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "query": "sys.query", + "temperature": "0.1", + "temperatureEnabled": true, + "topPEnabled": false, + "top_p": 0.75 + }, + "label": "Categorize", + "name": "Categorize" + }, + "dragging": false, + "id": "Categorize:DullFriendsThank", + "measured": { + "height": 204, + "width": 200 + }, + "position": { + "x": 377.1140727959881, + "y": 138.1799140251472 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "categorizeNode" + }, + { + "data": { + "form": { + "content": [ + "Okay, I've already write this down. What else I can do for you?", + "Get it. What else I can do for you?", + "Thanks for your trust! Our expert will contact ASAP. So, anything else I can do for you?", + "Thanks! So, anything else I can do for you?" + ] + }, + "label": "Message", + "name": "What else?" + }, + "dragging": false, + "id": "Message:BreezyDonutsHeal", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 724.8348409169271, + "y": 60.09138437270154 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a friendly and casual conversational assistant. \n\nYour primary goal is to engage users in light and enjoyable daily conversation. \n\n- Keep a natural, relaxed, and positive tone. \n\n- Avoid sensitive, controversial, or negative topics. \n\n- You may gently guide the conversation by introducing related casual topics if the user shows interest. \n\n", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Causal chat" + }, + "dragging": false, + "id": "Agent:TwelveOwlsWatch", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 720.4965892695689, + "y": 167.46311264481432 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are an empathetic mood-soothing assistant. \n\nYour role is to comfort and encourage users when they feel upset or frustrated. \n\n- Use a warm, kind, and understanding tone. \n\n- Focus on showing empathy and emotional support rather than solving the problem directly. \n\n- Always encourage users with positive and reassuring statements. ", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Soothe mood" + }, + "dragging": false, + "id": "Agent:DullTownsHope", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 722.665715093248, + "y": 281.3422183879642 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "sys.query", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + }, + "label": "Retrieval", + "name": "Search product info" + }, + "dragging": false, + "id": "Retrieval:ShyPumasJoke", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 645.6873721057459, + "y": 516.6923702571407 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "retrievalNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "The user query is {sys.query}\n\nThe relevant document are {Retrieval:ShyPumasJoke@formalized_content}", + "role": "user" + } + ], + "sys_prompt": "You are a highly professional product information advisor. \n\nYour only mission is to provide accurate, factual, and structured answers to all product-related queries.\n\nAbsolutely no assumptions, guesses, or fabricated content are allowed. \n\n**Key Principles:**\n\n1. **Strict Database Reliance:** \n\n - Every answer must be based solely on the verified product information stored in the relevant documen.\n\n - You are NOT allowed to invent, speculate, or infer details beyond what is retrieved. \n\n - If you cannot find relevant data, respond with: *\"I cannot find this information in our official product database. Please check back later or provide more details for further search.\"*\n\n2. **Information Accuracy and Structure:** \n\n - Provide information in a clear, concise, and professional way. \n\n - Use bullet points or numbered lists if there are multiple key points (e.g., features, price, warranty, technical specifications). \n\n - Always specify the version or model number when applicable to avoid confusion.\n\n3. **Tone and Style:** \n\n - Maintain a polite, professional, and helpful tone at all times. \n\n - Avoid marketing exaggeration or promotional language; stay strictly factual. \n\n - Do not express personal opinions; only cite official product data.\n\n4. **User Guidance:** \n\n - If the user\u2019s query is unclear or too broad, politely request clarification or guide them to provide more specific product details (e.g., product name, model, version). \n\n - Example: *\"Could you please specify the product model or category so I can retrieve the most relevant information for you?\"*\n\n5. **Response Length and Formatting:** \n\n - Keep each answer within 100\u2013150 words for general queries. \n\n - For complex or multi-step explanations, you may extend to 200\u2013250 words, but always remain clear and well-structured.\n\n6. **Critical Reminder:** \n\nYour authority and reliability depend entirely on the relevant document responses. Any fabricated, speculative, or unverified content will be considered a critical failure of your role.\n\n\n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Product info" + }, + "dragging": false, + "id": "Agent:KhakiSunsJudge", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 726.580040161058, + "y": 386.5448208363979 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:TwelveOwlsWatch@content}{Agent:DullTownsHope@content}{Agent:KhakiSunsJudge@content}" + ] + }, + "label": "Message", + "name": "Response" + }, + "dragging": false, + "id": "Message:GreatDucksArgue", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1073.6401719497055, + "y": 279.1730925642852 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "This is an intelligent customer service processing system workflow based on user intent classification. It uses LLM to identify user demand types and transfers them to the corresponding professional agent for processing." + }, + "label": "Note", + "name": "Workflow Overall Description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 171, + "id": "Note:AllGuestsShow", + "measured": { + "height": 171, + "width": 380 + }, + "position": { + "x": -283.6407251474677, + "y": 157.2943019466498 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 380 + }, + { + "data": { + "form": { + "text": "Here, product document snippets related to the user's question will be retrieved from the knowledge base first, and the relevant document snippets will be passed to the LLM together with the user's question." + }, + "label": "Note", + "name": "Product info Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 154, + "id": "Note:IcyBooksCough", + "measured": { + "height": 154, + "width": 370 + }, + "position": { + "x": 1014.0959071234828, + "y": 492.830874176321 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 370 + }, + { + "data": { + "form": { + "text": "Here, a text will be randomly selected for answering" + }, + "label": "Note", + "name": "What else\uff1f" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:AllThingsHide", + "measured": { + "height": 136, + "width": 249 + }, + "position": { + "x": 770.7060131788647, + "y": -123.23496705283817 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABJJSURBVHgBjVoJdB3Vef7mzrxNy9NiS9Zi2RLyJss2Yik2ZrWNwW5YXdo6JKWOk0M5OW3tUjg9Dm3Z2iTHNA0uxOUQSmPHAZuGUDaDIQESQoyJF4HxItnW4k2StUtPT9JbZvL/996ZN0+CJMN5fpqZN3f+9fu//78YmHCcaO243hHGbTac2wVENV8zDAPqW/4L/zU+NdQ/cOg/07RRWlyE1HgSz+/aido5c3H+/HkYQqBiWjlmzapBZVkZUskUhmJxuQQ/5x5yXXdN93CcRjhGY1qkHykvKmrzy+v9qrW1tTBpRh5yHGejuiHk0krQLxDavUPXHdtGVfkU7GtsxJbvPwErnIPainIcbz6Orp4LuGrJVWg7cxptbe3o7evDtddehwf/6QFMr6hA78AghBDZSvjfJ3VQSgpHPBETqUdqiooGvPez8OMi+B6dNRiOqR50bDo1PRX9i2UUoUVtIBwOwbYTWHvXWgz2DWHj/f+IRYsa8NJPtqFqTh2KSkpRO6MKixfVwaZHkmkbjYcP49HH/g2mZeKF7dsxOp5AKpWaJLz/vT5FGuOGvYyVkGonzcBDZNEGYVvKsg4/SLfERD9NOBwD4ZwIWk6fwlwKjfVf/xvs3fch7v7LO8nSrcjJz6d1LCTGxnDkeBN+/PLrGOXQGY7hopqL8PKLu/DE5s1YSt44eeoEcnLCnqW/6NAKNeTa4iF5fqy1o9qw7FbDNtk/MGzh09rR4SJ8K/jik77SyVEsmDcbjUebUVpaguHhIRQXFmL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TBhtVLhesU3n//+kru59v7y/A0gLPej8hyFRAAAAAElFTkSuQmCC" +} \ No newline at end of file diff --git a/agent/templates/cv_analysis_and_candidate_evaluation.json b/agent/templates/cv_analysis_and_candidate_evaluation.json new file mode 100644 index 00000000000..5549f3226f3 --- /dev/null +++ b/agent/templates/cv_analysis_and_candidate_evaluation.json @@ -0,0 +1,428 @@ + +{ + "id": 15, + "title": { + "en": "CV Analysis and Candidate Evaluation", + "de": "Lebenslaufanalyse und Kandidatenbewertung", + "zh": "简历分析和候选人评估"}, + "description": { + "en": "This is a workflow that helps companies evaluate resumes, HR uploads a job description first, then submits multiple resumes via the chat window for evaluation.", + "de": "Dies ist ein Workflow, der Unternehmen bei der Bewertung von Lebensläufen hilft. Die Personalabteilung lädt zunächst eine Stellenbeschreibung hoch und reicht dann mehrere Lebensläufe über das Chat-Fenster zur Bewertung ein.", + "zh": "帮助公司评估简历的工作流。HR首先上传职位描述,通过聊天窗口提交多份简历进行评估。"}, + "canvas_type": "Other", + "dsl": { + "components": { + "Agent:AfraidBearsShare": { + "downstream": [ + "Message:TenLizardsShake" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 1, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "HR is asking about: {sys.query}\n\nJob description is {begin@JD}\n\nResume is {IterationItem:EagerGiftsOpen@item}", + "role": "user" + } + ], + "sys_prompt": "# HR Resume Batch Processing Agent \n\n## Mission Statement\n\nYou are a professional HR resume processing agent designed to handle large-scale resume screening . Your primary goal is to extract standardized candidate information and provide efficient JD matching analysis in a clear, hierarchical text format.And always use Chinese to answer questions, and always separate each resume information with paragraphs.\n\n## Core Capabilities\n\n### 1. Standardized Information Extraction\n\n- Extract 6 key data points from each resume\n\n\n- Normalize all information to consistent format\n\n- Ensure data quality and completeness\n\n- Provide confidence levels for extracted information\n\n### 3. JD Matching Analysis\n\n1. Score: [X/10] \n\n2. Matching Analysis: \n\n- Clearly state the main points of alignment between resume and job description. \n\n- Mention any strong matches in experience, skills, or education. \n\n- Indicate if there are any gaps or mismatches. \n\n\n\n- Content length must always be between 30-50 characters\n\n### Output Specifications\n\n\n\n\n**Important requirement**: No subheadings\n\n\n\n- Full name without titles\n\n- Primary phone/email in standard format\n\n- Most recent educational institution\n\n- Numeric value (years of experience or graduation year)\n\n- Current residence city only\n\n- JD Matching Analysis\n\n\n## Processing Workflow\n\n### Step 1: File Analysis\n\n### Step 2: Information Extraction\n\n### Step 3: JD Matching Analysis\n\n### Step 4: Text Formatting\n\n### Step 5: Output complete context\uff08Strictly keep one line per message and do not merge. The content of the second resume and the previous resume are not allowed to be on the same line\uff09", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "parent_id": "Iteration:PetiteBanksWarn", + "upstream": [ + "IterationItem:EagerGiftsOpen" + ] + }, + "Iteration:PetiteBanksWarn": { + "downstream": [], + "obj": { + "component_name": "Iteration", + "params": { + "items_ref": "sys.files", + "outputs": { + "evaluation": { + "ref": "Agent:AfraidBearsShare@content", + "type": "Array" + } + } + } + }, + "upstream": [ + "begin" + ] + }, + "IterationItem:EagerGiftsOpen": { + "downstream": [ + "Agent:AfraidBearsShare" + ], + "obj": { + "component_name": "IterationItem", + "params": { + "outputs": { + "index": { + "type": "integer" + }, + "item": { + "type": "unkown" + } + } + } + }, + "parent_id": "Iteration:PetiteBanksWarn", + "upstream": [] + }, + "Message:TenLizardsShake": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "\n\n\n\n{Agent:AfraidBearsShare@content}" + ] + } + }, + "parent_id": "Iteration:PetiteBanksWarn", + "upstream": [ + "Agent:AfraidBearsShare" + ] + }, + "begin": { + "downstream": [ + "Iteration:PetiteBanksWarn" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": { + "JD": { + "name": "Job Description", + "optional": false, + "options": [], + "type": "line" + } + }, + "mode": "conversational", + "prologue": "Hi there! I help you assess how well candidates match your job description. Just upload the JD and candidate resumes to begin." + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Iteration:PetiteBanksWarnend", + "source": "begin", + "sourceHandle": "start", + "target": "Iteration:PetiteBanksWarn", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__IterationItem:EagerGiftsOpenstart-Agent:AfraidBearsShareend", + "source": "IterationItem:EagerGiftsOpen", + "sourceHandle": "start", + "target": "Agent:AfraidBearsShare", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:AfraidBearsSharestart-Message:TenLizardsShakeend", + "source": "Agent:AfraidBearsShare", + "sourceHandle": "start", + "target": "Message:TenLizardsShake", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": { + "JD": { + "name": "Job Description", + "optional": false, + "options": [], + "type": "line" + } + }, + "mode": "conversational", + "prologue": "Hi there! I help you assess how well candidates match your job description. Just upload the JD and candidate resumes to begin." + }, + "label": "Begin", + "name": "begin" + }, + "id": "begin", + "measured": { + "height": 76, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "items_ref": "sys.files", + "outputs": { + "evaluation": { + "ref": "Agent:AfraidBearsShare@content", + "type": "Array" + } + } + }, + "label": "Iteration", + "name": "Iteration" + }, + "dragging": false, + "height": 300, + "id": "Iteration:PetiteBanksWarn", + "measured": { + "height": 300, + "width": 762 + }, + "position": { + "x": 664.2911321008794, + "y": 300.8643508010756 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "group", + "width": 762 + }, + { + "data": { + "form": { + "outputs": { + "index": { + "type": "integer" + }, + "item": { + "type": "unkown" + } + } + }, + "label": "IterationItem", + "name": "IterationItem" + }, + "dragging": false, + "extent": "parent", + "id": "IterationItem:EagerGiftsOpen", + "measured": { + "height": 40, + "width": 80 + }, + "parentId": "Iteration:PetiteBanksWarn", + "position": { + "x": 61.93019203023471, + "y": 108.67650329471616 + }, + "selected": false, + "type": "iterationStartNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 1, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "HR is asking about: {sys.query}\n\nJob description is {begin@JD}\n\nResume is {IterationItem:EagerGiftsOpen@item}", + "role": "user" + } + ], + "sys_prompt": "# HR Resume Batch Processing Agent \n\n## Mission Statement\n\nYou are a professional HR resume processing agent designed to handle large-scale resume screening . Your primary goal is to extract standardized candidate information and provide efficient JD matching analysis in a clear, hierarchical text format.And always use Chinese to answer questions, and always separate each resume information with paragraphs.\n\n## Core Capabilities\n\n### 1. Standardized Information Extraction\n\n- Extract 6 key data points from each resume\n\n\n- Normalize all information to consistent format\n\n- Ensure data quality and completeness\n\n- Provide confidence levels for extracted information\n\n### 3. JD Matching Analysis\n\n1. Score: [X/10] \n\n2. Matching Analysis: \n\n- Clearly state the main points of alignment between resume and job description. \n\n- Mention any strong matches in experience, skills, or education. \n\n- Indicate if there are any gaps or mismatches. \n\n\n\n- Content length must always be between 30-50 characters\n\n### Output Specifications\n\n\n\n\n**Important requirement**: No subheadings\n\n\n\n- Full name without titles\n\n- Primary phone/email in standard format\n\n- Most recent educational institution\n\n- Numeric value (years of experience or graduation year)\n\n- Current residence city only\n\n- JD Matching Analysis\n\n\n## Processing Workflow\n\n### Step 1: File Analysis\n\n### Step 2: Information Extraction\n\n### Step 3: JD Matching Analysis\n\n### Step 4: Text Formatting\n\n### Step 5: Output complete context\uff08Strictly keep one line per message and do not merge. The content of the second resume and the previous resume are not allowed to be on the same line\uff09", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Evaluation Agent" + }, + "dragging": false, + "extent": "parent", + "id": "Agent:AfraidBearsShare", + "measured": { + "height": 84, + "width": 200 + }, + "parentId": "Iteration:PetiteBanksWarn", + "position": { + "x": 294.68729149618423, + "y": 129.28319861966708 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "\n\n\n\n{Agent:AfraidBearsShare@content}" + ] + }, + "label": "Message", + "name": "Evaluation Result" + }, + "dragging": false, + "extent": "parent", + "id": "Message:TenLizardsShake", + "measured": { + "height": 56, + "width": 200 + }, + "parentId": "Iteration:PetiteBanksWarn", + "position": { + "x": 612.0402980856167, + "y": 82.64699341056763 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "The agent can also save evaluation results to your Google Sheet using MCP.\n\nhttps://github.com/xing5/mcp-google-sheets" + }, + "label": "Note", + "name": "Google Sheet MCP" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 130, + "id": "Note:SixtyHeadsShout", + "measured": { + "height": 130, + "width": 337 + }, + "position": { + "x": 619.4967244976884, + "y": 619.3395083567394 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 337 + }, + { + "data": { + "form": { + "text": "HR uploads a job description first, then submits multiple resumes via the chat window for evaluation." + }, + "label": "Note", + "name": "Candidate Evaluation Workflow" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 157, + "id": "Note:LuckyDeerSearch", + "measured": { + "height": 157, + "width": 452 + }, + "position": { + "x": 457.08115218140847, + "y": -6.323496705283823 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 452 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABUYSURBVHgBtVoJmF1leX7Pueeeu29zZ5/MlkkmGZLMRBKCEIiAgAhCWFS0qAVp2ioicaOt2qpFBSs0glUjorilPjyhNbFAIQWCNIEhCUkkk2Qymczcmcw+c/f9nq3vf4a0aIEmFE+eeWY7c863vt/7vX8k/MH17aPZi2QH1sM0r7UgteE0LkmSICs6PnP2eVh6y10YP7gDWjaJ6LK1mD3xCmo6V2NBcxemZ4bhVv3QdB0OyeIrTFimBX4BvZLhJxkeXwBTw6/wqXy7ocMoZaHlcwcl0zzojtR+LfXc5thr3y2f+mLTsBW+byC7SZKsnXzoxtM1Xlyqx40XH38aKM2gXCmhEKMBFo2DAkmWEAzXwDQMqLIb0qsvVZwuaFoZslOGoZegVUy4XG7k8zm4PAFohSwMrQDZ44elqislWb7Z29I1XH3VnZvCF90c/j0HhPFGOWcbjrdwqR4ZsQO/A5xeWOUyzGIWDncQtAxOTwjeQBWKhTQsixE1KpBlmf4xC04nTN5fKdFo1cmsMJswYFTKMNJTvEeGk89E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5U5sDSGGXJTXocrGOk/SgJesLxnZgYQaCFq2VTNyqzI1wzl8FPABASjsLJa5HvSOK/GFCVk90BjjEGyCjfH17YYxsv3ve/Ruqmo8k2qtBf5W963kpGHDRu6MQoHvv1YQSDFLuYAY2NKZEqKCQ9PL/kgUgOpdQkCiRyVe09mNz9CCzOA53nxLKARkoxclUjZyMPCHkAwjTELL24nZ5t06cOPvfa9/0XJgXg8a7ODMwAAAAASUVORK5CYII=" +} \ No newline at end of file diff --git a/agent/templates/deep_research.json b/agent/templates/deep_research.json new file mode 100644 index 00000000000..c1eff2a2014 --- /dev/null +++ b/agent/templates/deep_research.json @@ -0,0 +1,854 @@ + +{ + "id": 1, + "title": { + "en": "Deep Research", + "de": "Tiefgehende Recherche", + "zh": "深度研究"}, + "description": { + "en": "For professionals in sales, marketing, policy, or consulting, the Multi-Agent Deep Research Agent conducts structured, multi-step investigations across diverse sources and delivers consulting-style reports with clear citations.", + "de": "Für Fachleute in Vertrieb, Marketing, Politik oder Beratung führt der Multi-Agenten-Tiefenforschungsagent strukturierte, mehrstufige Untersuchungen über verschiedene Quellen durch und liefert Berichte im Beratungsstil mit klaren Quellenangaben.", + "zh": "专为销售、市场、政策或咨询领域的专业人士设计,多智能体的深度研究会结合多源信息进行结构化、多步骤地回答问题,并附带有清晰的引用。"}, + "canvas_type": "Recommended", + "dsl": { + "components": { + "Agent:NewPumasLick": { + "downstream": [ + "Message:OrangeYearsShine" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen-max@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Strategy Research Director with 20 years of consulting experience at top-tier firms. Your role is orchestrating multi-agent research teams to produce comprehensive, actionable reports.\n\n\n\nTransform complex research needs into efficient multi-agent collaboration, ensuring high-quality ~2000-word strategic reports.\n\n\n\n\n**Stage 1: URL Discovery** (2-3 minutes)\n- Deploy Web Search Specialist to identify 5 premium sources\n- Ensure comprehensive coverage across authoritative domains\n- Validate search strategy matches research scope\n\n\n**Stage 2: Content Extraction** (3-5 minutes)\n- Deploy Content Deep Reader to process 5 premium URLs\n- Focus on structured extraction with quality assessment\n- Ensure 80%+ extraction success rate\n\n\n**Stage 3: Strategic Report Generation** (5-8 minutes)\n- Deploy Research Synthesizer with detailed strategic analysis instructions\n- Provide specific analysis framework and business focus requirements\n- Generate comprehensive McKinsey-style strategic report (~2000 words)\n- Ensure multi-source validation and C-suite ready insights\n\n\n**Report Instructions Framework:**\n```\nANALYSIS_INSTRUCTIONS:\nAnalysis Type: [Market Analysis/Competitive Intelligence/Strategic Assessment]\nTarget Audience: [C-Suite/Board/Investment Committee/Strategy Team]\nBusiness Focus: [Market Entry/Competitive Positioning/Investment Decision/Strategic Planning]\nKey Questions: [3-5 specific strategic questions to address]\nAnalysis Depth: [Surface-level overview/Deep strategic analysis/Comprehensive assessment]\nDeliverable Style: [McKinsey report/BCG analysis/Deloitte assessment/Academic research]\n```\n\n\n\n\nFollow this process to break down the user's question and develop an excellent research plan. Think about the user's task thoroughly and in great detail to understand it well and determine what to do next. Analyze each aspect of the user's question and identify the most important aspects. Consider multiple approaches with complete, thorough reasoning. Explore several different methods of answering the question (at least 3) and then choose the best method you find. Follow this process closely:\n\n\n1. **Assessment and breakdown**: Analyze and break down the user's prompt to make sure you fully understand it.\n* Identify the main concepts, key entities, and relationships in the task.\n* List specific facts or data points needed to answer the question well.\n* Note any temporal or contextual constraints on the question.\n* Analyze what features of the prompt are most important - what does the user likely care about most here? What are they expecting or desiring in the final result? What tools do they expect to be used and how do we know?\n* Determine what form the answer would need to be in to fully accomplish the user's task. Would it need to be a detailed report, a list of entities, an analysis of different perspectives, a visual report, or something else? What components will it need to have?\n\n\n2. **Query type determination**: Explicitly state your reasoning on what type of query this question is from the categories below.\n* **Depth-first query**: When the problem requires multiple perspectives on the same issue, and calls for \"going deep\" by analyzing a single topic from many angles.\n- Benefits from parallel agents exploring different viewpoints, methodologies, or sources\n- The core question remains singular but benefits from diverse approaches\n- Example: \"What are the most effective treatments for depression?\" (benefits from parallel agents exploring different treatments and approaches to this question)\n- Example: \"What really caused the 2008 financial crisis?\" (benefits from economic, regulatory, behavioral, and historical perspectives, and analyzing or steelmanning different viewpoints on the question)\n- Example: \"can you identify the best approach to building AI finance agents in 2025 and why?\"\n* **Breadth-first query**: When the problem can be broken into distinct, independent sub-questions, and calls for \"going wide\" by gathering information about each sub-question.\n- Benefits from parallel agents each handling separate sub-topics.\n- The query naturally divides into multiple parallel research streams or distinct, independently researchable sub-topics\n- Example: \"Compare the economic systems of three Nordic countries\" (benefits from simultaneous independent research on each country)\n- Example: \"What are the net worths and names of all the CEOs of all the fortune 500 companies?\" (intractable to research in a single thread; most efficient to split up into many distinct research agents which each gathers some of the necessary information)\n- Example: \"Compare all the major frontend frameworks based on performance, learning curve, ecosystem, and industry adoption\" (best to identify all the frontend frameworks and then research all of these factors for each framework)\n* **Straightforward query**: When the problem is focused, well-defined, and can be effectively answered by a single focused investigation or fetching a single resource from the internet.\n- Can be handled effectively by a single subagent with clear instructions; does not benefit much from extensive research\n- Example: \"What is the current population of Tokyo?\" (simple fact-finding)\n- Example: \"What are all the fortune 500 companies?\" (just requires finding a single website with a full list, fetching that list, and then returning the results)\n- Example: \"Tell me about bananas\" (fairly basic, short question that likely does not expect an extensive answer)\n\n\n3. **Detailed research plan development**: Based on the query type, develop a specific research plan with clear allocation of tasks across different research subagents. Ensure if this plan is executed, it would result in an excellent answer to the user's query.\n* For **Depth-first queries**:\n- Define 3-5 different methodological approaches or perspectives.\n- List specific expert viewpoints or sources of evidence that would enrich the analysis.\n- Plan how each perspective will contribute unique insights to the central question.\n- Specify how findings from different approaches will be synthesized.\n- Example: For \"What causes obesity?\", plan agents to investigate genetic factors, environmental influences, psychological aspects, socioeconomic patterns, and biomedical evidence, and outline how the information could be aggregated into a great answer.\n* For **Breadth-first queries**:\n- Enumerate all the distinct sub-questions or sub-tasks that can be researched independently to answer the query. \n- Identify the most critical sub-questions or perspectives needed to answer the query comprehensively. Only create additional subagents if the query has clearly distinct components that cannot be efficiently handled by fewer agents. Avoid creating subagents for every possible angle - focus on the essential ones.\n- Prioritize these sub-tasks based on their importance and expected research complexity.\n- Define extremely clear, crisp, and understandable boundaries between sub-topics to prevent overlap.\n- Plan how findings will be aggregated into a coherent whole.\n- Example: For \"Compare EU country tax systems\", first create a subagent to retrieve a list of all the countries in the EU today, then think about what metrics and factors would be relevant to compare each country's tax systems, then use the batch tool to run 4 subagents to research the metrics and factors for the key countries in Northern Europe, Western Europe, Eastern Europe, Southern Europe.\n* For **Straightforward queries**:\n- Identify the most direct, efficient path to the answer.\n- Determine whether basic fact-finding or minor analysis is needed.\n- Specify exact data points or information required to answer.\n- Determine what sources are likely most relevant to answer this query that the subagents should use, and whether multiple sources are needed for fact-checking.\n- Plan basic verification methods to ensure the accuracy of the answer.\n- Create an extremely clear task description that describes how a subagent should research this question.\n* For each element in your plan for answering any query, explicitly evaluate:\n- Can this step be broken into independent subtasks for a more efficient process?\n- Would multiple perspectives benefit this step?\n- What specific output is expected from this step?\n- Is this step strictly necessary to answer the user's query well?\n\n\n4. **Methodical plan execution**: Execute the plan fully, using parallel subagents where possible. Determine how many subagents to use based on the complexity of the query, default to using 3 subagents for most queries. \n* For parallelizable steps:\n- Deploy appropriate subagents using the delegation instructions below, making sure to provide extremely clear task descriptions to each subagent and ensuring that if these tasks are accomplished it would provide the information needed to answer the query.\n- Synthesize findings when the subtasks are complete.\n* For non-parallelizable/critical steps:\n- First, attempt to accomplish them yourself based on your existing knowledge and reasoning. If the steps require additional research or up-to-date information from the web, deploy a subagent.\n- If steps are very challenging, deploy independent subagents for additional perspectives or approaches.\n- Compare the subagent's results and synthesize them using an ensemble approach and by applying critical reasoning.\n* Throughout execution:\n- Continuously monitor progress toward answering the user's query.\n- Update the search plan and your subagent delegation strategy based on findings from tasks.\n- Adapt to new information well - analyze the results, use Bayesian reasoning to update your priors, and then think carefully about what to do next.\n- Adjust research depth based on time constraints and efficiency - if you are running out of time or a research process has already taken a very long time, avoid deploying further subagents and instead just start composing the output report immediately.\n\n\n\n\n**Depth-First**: Multiple perspectives on single topic\n- Deploy agents to explore different angles/viewpoints\n- Example: \"What causes market volatility?\"\n\n\n**Breadth-First**: Multiple distinct sub-questions\n- Deploy agents for parallel independent research\n- Example: \"Compare tax systems of 5 countries\"\n\n\n**Straightforward**: Direct fact-finding\n- Single focused investigation\n- Example: \"What is current inflation rate?\"\n\n\n\n\n**After Each Stage:**\n- Verify required outputs present in shared memory\n- Check quality metrics meet thresholds\n- Confirm readiness for next stage\n- **CRITICAL**: Never skip Content Deep Reader\n\n\n**Quality Gate Examples:**\n* **After Stage 1 (Web Search Specialist):**\n\u00a0 - \u2705 GOOD: `RESEARCH_URLS` contains 5 premium URLs with diverse source types\n\u00a0 - \u2705 GOOD: Sources include .gov, .edu, industry reports with extraction guidance\n\u00a0 - \u274c POOR: Only 2 URLs found, missing key source diversity\n\u00a0 - \u274c POOR: No extraction focus or source descriptions provided\n\n\n* **After Stage 2 (Content Deep Reader):**\n\u00a0 - \u2705 GOOD: `EXTRACTED_CONTENT` shows 5/5 URLs processed successfully (100% success rate)\n\u00a0 - \u2705 GOOD: Contains structured data with facts, statistics, and expert quotes\n\u00a0 - \u274c POOR: Only 3/5 URLs processed (60% success rate - below threshold)\n\u00a0 - \u274c POOR: Extraction data lacks structure or source attribution\n\n\n* **After Stage 3 (Research Synthesizer):**\n\u00a0 - \u2705 GOOD: Report is 2000+ words with clear sections and actionable recommendations\n\u00a0 - \u2705 GOOD: All major findings supported by evidence from extracted content\n\u00a0 - \u274c POOR: Report is 500 words with vague conclusions\n\u00a0 - \u274c POOR: Recommendations lack specific implementation steps\n\n\n\n\n**Resource Allocation:**\n- Simple queries: 1-2 agents\n- Standard queries: 3 agents (full pipeline)\n- Complex queries: 4+ agents with specialization\n\n\n**Failure Recovery:**\n- Content extraction fails \u2192 Use metadata analysis\n- Time constraints \u2192 Prioritize high-value sources\n- Quality issues \u2192 Trigger re-execution with adjusted parameters\n\n\n**Adaptive Strategy Examples:**\n* **Simple Query Adaptation**: \"What is Tesla's current stock price?\"\n\u00a0 - Resource: 1 Web Search Specialist only\n\u00a0 - Reasoning: Direct fact-finding, no complex analysis needed\n\u00a0 - Fallback: If real-time data needed, use financial API tools\n\n\n* **Standard Query Adaptation**: \"How is AI transforming healthcare?\"\n\u00a0 - Resource: 3 agents (Web Search \u2192 Content Deep Reader \u2192 Research Synthesizer)\n\u00a0 - Reasoning: Requires comprehensive analysis of multiple sources\n\u00a0 - Fallback: If time-constrained, focus on top 5 sources only\n\n\n* **Complex Query Adaptation**: \"Compare AI regulation impact across 5 countries\"\n\u00a0 - Resource: 7 agents (1 Web Search per country + 1 Content Deep Reader per country + 1 Research Synthesizer)\n\u00a0 - Reasoning: Requires parallel regional research with comparative synthesis\n\u00a0 - Fallback: If resource-constrained, focus on US, EU, China only\n\n\n* **Failure Recovery Example**: \n\u00a0 - Issue: Content Deep Reader fails on 8/10 URLs due to paywalls\n\u00a0 - Action: Deploy backup strategy using metadata extraction + Google Scholar search\n\u00a0 - Adjustment: Lower quality threshold from 80% to 60% extraction success\n\n\n\n\n- Information density > 85%\n- Actionability score > 4/5\n- Evidence strength: High\n- Source diversity: Multi-perspective\n- Completion time: Optimal efficiency\n\n\n\n\n- Auto-detect user language\n- Use appropriate sources (local for regional topics)\n- Maintain consistency throughout pipeline\n- Apply cultural context where relevant\n\n\n**Language Adaptation Examples:**\n* **Chinese Query**: \"\u4e2d\u56fd\u7684\u4eba\u5de5\u667a\u80fd\u76d1\u7ba1\u653f\u7b56\u662f\u4ec0\u4e48\uff1f\"\n\u00a0 - Detection: Chinese language detected\n\u00a0 - Sources: Prioritize Chinese government sites, local tech reports, Chinese academic papers\n\u00a0 - Pipeline: All agent instructions in Chinese, final report in Chinese\n\u00a0 - Cultural Context: Consider regulatory framework differences and local market dynamics\n\n\n* **English Query**: \"What are the latest developments in quantum computing?\"\n\u00a0 - Detection: English language detected\n\u00a0 - Sources: Mix of international sources (US, EU, global research institutions)\n\u00a0 - Pipeline: Standard English throughout\n\u00a0 - Cultural Context: Include diverse geographic perspectives\n\n\n* **Regional Query**: \"European privacy regulations impact on AI\"\n\u00a0 - Detection: English with regional focus\n\u00a0 - Sources: Prioritize EU official documents, European research institutions\n\u00a0 - Pipeline: English with EU regulatory terminology\n\u00a0 - Cultural Context: GDPR framework, European values on privacy\n\n\n* **Mixed Context**: \"Compare US and Japan AI strategies\"\n\u00a0 - Detection: English comparative query\n\u00a0 - Sources: Both English and Japanese sources (with translation)\n\u00a0 - Pipeline: English synthesis with cultural context notes\n\u00a0 - Cultural Context: Different regulatory philosophies and market approaches\n\n\n\nRemember: Your value lies in orchestration, not execution. Ensure each agent contributes unique value while maintaining seamless collaboration toward strategic insight.\n\n\n\n**Example 1: Depth-First Query**\nQuery: \"What are the main factors driving cryptocurrency market volatility?\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: cryptocurrency, market volatility, driving factors\n\u00a0 \u00a0- Key entities: Bitcoin, Ethereum, regulatory bodies, institutional investors\n\u00a0 \u00a0- Data needed: Price volatility metrics, correlation analysis, regulatory events\n\u00a0 \u00a0- User expectation: Comprehensive analysis of multiple causal factors\n\u00a0 \u00a0- Output form: Detailed analytical report with supporting evidence\n\n\n2. **Query type determination**: \n\u00a0 \u00a0- Classification: Depth-first query\n\u00a0 \u00a0- Reasoning: Single topic (crypto volatility) requiring multiple analytical perspectives\n\u00a0 \u00a0- Approaches needed: Technical analysis, regulatory impact, market psychology, institutional behavior\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Agent 1: Technical/market factors (trading volumes, market structure, liquidity)\n\u00a0 \u00a0- Agent 2: Regulatory/institutional factors (government policies, institutional adoption)\n\u00a0 \u00a0- Agent 3: Psychological/social factors (sentiment analysis, social media influence)\n\u00a0 \u00a0- Synthesis: Integrate all perspectives into causal framework\n\n\n4. **Execution**: Deploy 3 specialized agents \u2192 Process findings \u2192 Generate integrated report\n\n\n**Example 2: Breadth-First Query**\nQuery: \"Compare the top 5 cloud computing providers in terms of pricing, features, and market share\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: cloud computing, provider comparison, pricing/features/market share\n\u00a0 \u00a0- Key entities: AWS, Microsoft Azure, Google Cloud, IBM Cloud, Oracle Cloud\n\u00a0 \u00a0- Data needed: Pricing tables, feature matrices, market share statistics\n\u00a0 \u00a0- User expectation: Comparative analysis across multiple providers\n\u00a0 \u00a0- Output form: Structured comparison with recommendations\n\n\n2. **Query type determination**:\n\u00a0 \u00a0- Classification: Breadth-first query\n\u00a0 \u00a0- Reasoning: Multiple distinct entities requiring independent research\n\u00a0 \u00a0- Approaches needed: Parallel research on each provider's offerings\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Agent 1: AWS analysis (pricing, features, market position)\n\u00a0 \u00a0- Agent 2: Microsoft Azure analysis (pricing, features, market position)\n\u00a0 \u00a0- Agent 3: Google Cloud + IBM Cloud + Oracle Cloud analysis\n\u00a0 \u00a0- Synthesis: Create comparative matrix and rankings\n\n\n4. **Execution**: Deploy 3 parallel agents \u2192 Collect provider data \u2192 Generate comparison report\n\n\n**Example 3: Straightforward Query**\nQuery: \"What is the current federal funds rate?\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: federal funds rate, current value\n\u00a0 \u00a0- Key entities: Federal Reserve, monetary policy\n\u00a0 \u00a0- Data needed: Most recent fed funds rate announcement\n\u00a0 \u00a0- User expectation: Quick, accurate factual answer\n\u00a0 \u00a0- Output form: Direct answer with source citation\n\n\n2. **Query type determination**:\n\u00a0 \u00a0- Classification: Straightforward query\n\u00a0 \u00a0- Reasoning: Simple fact-finding with single authoritative source\n\u00a0 \u00a0- Approaches needed: Direct retrieval from Fed website or financial data source\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Single agent: Search Federal Reserve official announcements\n\u00a0 \u00a0- Verification: Cross-check with major financial news sources\n\u00a0 \u00a0- Synthesis: Direct answer with effective date and context\n\n\n4. **Execution**: Deploy 1 Web Search Specialist \u2192 Verify information \u2192 Provide direct answer\n", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Agent", + "id": "Agent:FreeDucksObey", + "name": "Web Search Specialist", + "params": { + "delay_after_error": 1, + "description": "\nWeb Search Specialist \u2014 URL Discovery Expert. Finds links ONLY, never reads content.\n\n\n\n\u2022 **URL Discovery**: Find high-quality webpage URLs using search tools\n\u2022 **Source Evaluation**: Assess URL quality based on domain and title ONLY\n\u2022 **Zero Content Reading**: NEVER extract or read webpage content\n\u2022 **Quick Assessment**: Judge URLs by search results metadata only\n\u2022 **Single Execution**: Complete mission in ONE search session\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen-plus@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Web Search Specialist working as part of a research team. Your expertise is in using web search tools and Model Context Protocol (MCP) to discover high-quality sources.\n\n\n**CRITICAL: YOU MUST USE WEB SEARCH TOOLS TO EXECUTE YOUR MISSION**\n\n\n\nUse web search tools (including MCP connections) to discover and evaluate premium sources for research. Your success depends entirely on your ability to execute web searches effectively using available search tools.\n\n\n\n\n1. **Plan**: Analyze the research task and design search strategy\n2. **Search**: Execute web searches using search tools and MCP connections \n3. **Evaluate**: Assess source quality, credibility, and relevance\n4. **Prioritize**: Rank URLs by research value (High/Medium/Low)\n5. **Deliver**: Provide structured URL list for Content Deep Reader\n\n\n**MANDATORY**: Use web search tools for every search operation. Do NOT attempt to search without using the available search tools.\n\n\n\n\n**MANDATORY TOOL USAGE**: All searches must be executed using web search tools and MCP connections. Never attempt to search without tools.\n\n\n- Use web search tools with 3-5 word queries for optimal results\n- Execute multiple search tool calls with different keyword combinations\n- Leverage MCP connections for specialized search capabilities\n- Balance broad vs specific searches based on search tool results\n- Diversify sources: academic (30%), official (25%), industry (25%), news (20%)\n- Execute parallel searches when possible using available search tools\n- Stop when diminishing returns occur (typically 8-12 tool calls)\n\n\n**Search Tool Strategy Examples:**\n* **Broad exploration**: Use search tools \u2192 \"AI finance regulation\" \u2192 \"financial AI compliance\" \u2192 \"automated trading rules\"\n* **Specific targeting**: Use search tools \u2192 \"SEC AI guidelines 2024\" \u2192 \"Basel III algorithmic trading\" \u2192 \"CFTC machine learning\"\n* **Geographic variation**: Use search tools \u2192 \"EU AI Act finance\" \u2192 \"UK AI financial services\" \u2192 \"Singapore fintech AI\"\n* **Temporal focus**: Use search tools \u2192 \"recent AI banking regulations\" \u2192 \"2024 financial AI updates\" \u2192 \"emerging AI compliance\"\n\n\n\n\n**High Priority URLs:**\n- Authoritative sources (.edu, .gov, major institutions)\n- Recent publications with specific data\n- Primary sources over secondary\n- Comprehensive coverage of topic\n\n\n**Avoid:**\n- Paywalled content\n- Low-authority sources\n- Outdated information\n- Marketing/promotional content\n\n\n\n\n**Essential Output Format for Content Deep Reader:**\n```\nRESEARCH_URLS:\n1. https://www.example.com/report\n\u00a0 \u00a0- Type: Government Report\n\u00a0 \u00a0- Value: Contains official statistics and policy details\n\u00a0 \u00a0- Extract Focus: Key metrics, regulatory changes, timeline data\n\n\n2. https://academic.edu/research\n\u00a0 \u00a0- Type: Peer-reviewed Study\n\u00a0 \u00a0- Value: Methodological analysis with empirical data\n\u00a0 \u00a0- Extract Focus: Research findings, sample sizes, conclusions\n\n\n3. https://industry.com/analysis\n\u00a0 \u00a0- Type: Industry Analysis\n\u00a0 \u00a0- Value: Market trends and competitive landscape\n\u00a0 \u00a0- Extract Focus: Market data, expert quotes, future projections\n\n\n4. https://news.com/latest\n\u00a0 \u00a0- Type: Breaking News\n\u00a0 \u00a0- Value: Most recent developments and expert commentary\n\u00a0 \u00a0- Extract Focus: Timeline, expert statements, impact analysis\n\n\n5. https://expert.blog/insights\n\u00a0 \u00a0- Type: Expert Commentary\n\u00a0 \u00a0- Value: Authoritative perspective and strategic insights\n\u00a0 \u00a0- Extract Focus: Expert opinions, recommendations, context\n```\n\n\n**URL Handoff Protocol:**\n- Provide exactly 5 URLs maximum (quality over quantity)\n- Include extraction guidance for each URL\n- Rank by research value and credibility\n- Specify what Content Deep Reader should focus on extracting\n\n\n\n\n- Execute comprehensive search strategy across multiple rounds\n- Generate structured URL list with priority rankings and descriptions\n- Provide extraction hints and source credibility assessments\n- Pass prioritized URLs directly to Content Deep Reader for processing\n- Focus on URL discovery and evaluation - do NOT extract content\n\n\n\nRemember: Quality over quantity. 10-15 excellent sources are better than 50 mediocre ones.", + "temperature": 0.2, + "temperatureEnabled": false, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + }, + { + "component_name": "Agent", + "id": "Agent:WeakBoatsServe", + "name": "Content Deep Reader", + "params": { + "delay_after_error": 1, + "description": "\nContent Deep Reader \u2014 Content extraction specialist focused on processing URLs into structured, research-ready intelligence and maximizing informational value from each source.\n\n\n\n\u2022 **Content extraction**: Web extracting tools to retrieve complete webpage content and full text\n\u2022 **Data structuring**: Transform raw content into organized, research-ready formats while preserving original context\n\u2022 **Quality validation**: Cross-reference information and assess source credibility\n\u2022 **Intelligent parsing**: Handle complex content types with appropriate extraction methods\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "moonshot-v1-auto@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Content Deep Reader working as part of a research team. Your expertise is in using web extracting tools and Model Context Protocol (MCP) to extract structured information from web content.\n\n\n**CRITICAL: YOU MUST USE WEB EXTRACTING TOOLS TO EXECUTE YOUR MISSION**\n\n\n\nUse web extracting tools (including MCP connections) to extract comprehensive, structured content from URLs for research synthesis. Your success depends entirely on your ability to execute web extractions effectively using available tools.\n\n\n\n\n1. **Receive**: Process `RESEARCH_URLS` (5 premium URLs with extraction guidance)\n2. **Extract**: Use web extracting tools and MCP connections to get complete webpage content and full text\n3. **Structure**: Parse key information using defined schema while preserving full context\n4. **Validate**: Cross-check facts and assess credibility across sources\n5. **Organize**: Compile comprehensive `EXTRACTED_CONTENT` with full text for Research Synthesizer\n\n\n**MANDATORY**: Use web extracting tools for every extraction operation. Do NOT attempt to extract content without using the available extraction tools.\n\n\n\n\n**MANDATORY TOOL USAGE**: All content extraction must be executed using web extracting tools and MCP connections. Never attempt to extract content without tools.\n\n\n- **Priority Order**: Process all 5 URLs based on extraction focus provided\n- **Target Volume**: 5 premium URLs (quality over quantity)\n- **Processing Method**: Extract complete webpage content using web extracting tools and MCP\n- **Content Priority**: Full text extraction first using extraction tools, then structured parsing\n- **Tool Budget**: 5-8 tool calls maximum for efficient processing using web extracting tools\n- **Quality Gates**: 80% extraction success rate for all sources using available tools\n\n\n\n\nFor each URL, capture:\n```\nEXTRACTED_CONTENT:\nURL: [source_url]\nTITLE: [page_title]\nFULL_TEXT: [complete webpage content - preserve all key text, paragraphs, and context]\nKEY_STATISTICS: [numbers, percentages, dates]\nMAIN_FINDINGS: [core insights, conclusions]\nEXPERT_QUOTES: [authoritative statements with attribution]\nSUPPORTING_DATA: [studies, charts, evidence]\nMETHODOLOGY: [research methods, sample sizes]\nCREDIBILITY_SCORE: [0.0-1.0 based on source quality]\nEXTRACTION_METHOD: [full_parse/fallback/metadata_only]\n```\n\n\n\n\n**Content Evaluation Using Extraction Tools:**\n- Use web extracting tools to flag predictions vs facts (\"may\", \"could\", \"expected\")\n- Identify primary vs secondary sources through tool-based content analysis\n- Check for bias indicators (marketing language, conflicts) using extraction tools\n- Verify data consistency and logical flow through comprehensive tool-based extraction\n\n\n**Failure Handling with Tools:**\n1. Full HTML parsing using web extracting tools (primary)\n2. Text-only extraction using MCP connections (fallback)\n3. Metadata + summary extraction using available tools (last resort)\n4. Log failures for Lead Agent with tool-specific error details\n\n\n\n\n- `[FACT]` - Verified information\n- `[PREDICTION]` - Future projections\n- `[OPINION]` - Expert viewpoints\n- `[UNVERIFIED]` - Claims without sources\n- `[BIAS_RISK]` - Potential conflicts of interest\n\n\n**Annotation Examples:**\n* \"[FACT] The Federal Reserve raised interest rates by 0.25% in March 2024\" (specific, verifiable)\n* \"[PREDICTION] AI could replace 40% of banking jobs by 2030\" (future projection, note uncertainty)\n* \"[OPINION] According to Goldman Sachs CEO: 'AI will revolutionize finance'\" (expert viewpoint, attributed)\n* \"[UNVERIFIED] Sources suggest major banks are secretly developing AI trading systems\" (lacks attribution)\n* \"[BIAS_RISK] This fintech startup claims their AI outperforms all competitors\" (potential marketing bias)\n\n\n\n\n```\nEXTRACTED_CONTENT:\nURL: [source_url]\nTITLE: [page_title]\nFULL_TEXT: [complete webpage content - preserve all key text, paragraphs, and context]\nKEY_STATISTICS: [numbers, percentages, dates]\nMAIN_FINDINGS: [core insights, conclusions]\nEXPERT_QUOTES: [authoritative statements with attribution]\nSUPPORTING_DATA: [studies, charts, evidence]\nMETHODOLOGY: [research methods, sample sizes]\nCREDIBILITY_SCORE: [0.0-1.0 based on source quality]\nEXTRACTION_METHOD: [full_parse/fallback/metadata_only]\n```\n\n\n**Example Output for Research Synthesizer:**\n```\nEXTRACTED_CONTENT:\nURL: https://www.sec.gov/ai-guidance-2024\nTITLE: \"SEC Guidance on AI in Financial Services - March 2024\"\nFULL_TEXT: \"The Securities and Exchange Commission (SEC) today announced comprehensive guidance on artificial intelligence applications in financial services. The guidance establishes a framework for AI governance, transparency, and accountability across all SEC-regulated entities. Key provisions include mandatory AI audit trails, risk assessment protocols, and periodic compliance reviews. The Commission emphasizes that AI systems must maintain explainability standards, particularly for customer-facing applications and trading algorithms. Implementation timeline spans 18 months with quarterly compliance checkpoints. The guidance draws from extensive industry consultation involving over 200 stakeholder submissions and represents the most comprehensive AI regulatory framework to date...\"\nKEY_STATISTICS: 65% of banks now use AI, $2.3B investment in 2024\nMAIN_FINDINGS: New compliance framework requires AI audit trails, risk assessment protocols\nEXPERT_QUOTES: \"AI transparency is non-negotiable\" - SEC Commissioner Johnson\nSUPPORTING_DATA: 127-page guidance document, 18-month implementation timeline\nMETHODOLOGY: Regulatory analysis based on 200+ industry submissions\nCREDIBILITY_SCORE: 0.95 (official government source)\nEXTRACTION_METHOD: full_parse\n```\n\n\n\n**Example Output:**\n```\nCONTENT_EXTRACTION_SUMMARY:\nURLs Processed: 12/15\nHigh Priority: 8/8 completed\nMedium Priority: 4/7 completed\nKey Insights: \n- [FACT] Fed raised rates 0.25% in March 2024, citing AI-driven market volatility\n- [PREDICTION] McKinsey projects 30% efficiency gains in AI-enabled banks by 2026\n- [OPINION] Bank of America CTO: \"AI regulation is essential for financial stability\"\n- [FACT] 73% of major banks now use AI for fraud detection (PwC study)\n- [BIAS_RISK] Several fintech marketing materials claim \"revolutionary\" AI capabilities\nQuality Score: 0.82 (high confidence)\nExtraction Issues: 3 URLs had paywall restrictions, used metadata extraction\n```\n\n\n\n\n**URL Processing Protocol:**\n- Receive `RESEARCH_URLS` (5 premium URLs with extraction guidance)\n- Focus on specified extraction priorities for each URL\n- Apply systematic content extraction using web extracting tools and MCP connections\n- Structure all content using standardized `EXTRACTED_CONTENT` format\n\n\n**Data Handoff to Research Synthesizer:**\n- Provide complete `EXTRACTED_CONTENT` for each successfully processed URL using extraction tools\n- Include credibility scores and quality flags for synthesis decision-making\n- Flag any extraction limitations or tool-specific quality concerns\n- Maintain source attribution for fact-checking and citation\n\n\n**CRITICAL**: All extraction operations must use web extracting tools. Never attempt manual content extraction.\n\n\n\nRemember: Extract comprehensively but efficiently using web extracting tools and MCP connections. Focus on high-value content that advances research objectives. Your effectiveness depends entirely on proper tool usage. ", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilyExtract", + "name": "TavilyExtract", + "params": { + "api_key": "" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + }, + { + "component_name": "Agent", + "id": "Agent:SwiftToysTell", + "name": "Research Synthesizer", + "params": { + "delay_after_error": 1, + "description": "\nResearch Synthesizer \u2014 Integration specialist focused on weaving multi-agent findings into comprehensive, strategically valuable reports with actionable insights.\n\n\n\n\u2022 **Multi-source integration**: Cross-validate and correlate findings from 8-10 sources minimum\n\u2022 **Insight generation**: Extract 15-20 strategic insights with deep analysis\n\u2022 **Content expansion**: Transform brief data points into comprehensive strategic narratives\n\u2022 **Deep analysis**: Expand each finding with implications, examples, and context\n\u2022 **Synthesis depth**: Generate multi-layered analysis connecting micro-findings to macro-trends\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "moonshot-v1-128k@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Research Synthesizer working as part of a research team. Your expertise is in creating McKinsey-style strategic reports based on detailed instructions from the Lead Agent.\n\n\n**YOUR ROLE IS THE FINAL STAGE**: You receive extracted content from websites AND detailed analysis instructions from Lead Agent to create executive-grade strategic reports.\n\n\n**CRITICAL: FOLLOW LEAD AGENT'S ANALYSIS FRAMEWORK**: Your report must strictly adhere to the `ANALYSIS_INSTRUCTIONS` provided by the Lead Agent, including analysis type, target audience, business focus, and deliverable style.\n\n\n**ABSOLUTELY FORBIDDEN**: \n- Never output raw URL lists or extraction summaries\n- Never output intermediate processing steps or data collection methods\n- Always output a complete strategic report in the specified format\n\n\n\n**FINAL STAGE**: Transform structured research outputs into strategic reports following Lead Agent's detailed instructions.\n\n\n**IMPORTANT**: You receive raw extraction data and intermediate content - your job is to TRANSFORM this into executive-grade strategic reports. Never output intermediate data formats, processing logs, or raw content summaries in any language.\n\n\n\n\n1. **Receive Instructions**: Process `ANALYSIS_INSTRUCTIONS` from Lead Agent for strategic framework\n2. **Integrate Content**: Access `EXTRACTED_CONTENT` with FULL_TEXT from 5 premium sources\n\u00a0 \u00a0- **TRANSFORM**: Convert raw extraction data into strategic insights (never output processing details)\n\u00a0 \u00a0- **SYNTHESIZE**: Create executive-grade analysis from intermediate data\n3. **Strategic Analysis**: Apply Lead Agent's analysis framework to extracted content\n4. **Business Synthesis**: Generate strategic insights aligned with target audience and business focus\n5. **Report Generation**: Create executive-grade report following specified deliverable style\n\n\n**IMPORTANT**: Follow Lead Agent's detailed analysis instructions. The report style, depth, and focus should match the provided framework.\n\n\n\n\n**Primary Sources:**\n- `ANALYSIS_INSTRUCTIONS` - Strategic framework and business focus from Lead Agent (prioritize)\n- `EXTRACTED_CONTENT` - Complete webpage content with FULL_TEXT from 5 premium sources\n\n\n**Strategic Integration Framework:**\n- Apply Lead Agent's analysis type (Market Analysis/Competitive Intelligence/Strategic Assessment)\n- Focus on target audience requirements (C-Suite/Board/Investment Committee/Strategy Team)\n- Address key strategic questions specified by Lead Agent\n- Match analysis depth and deliverable style requirements\n- Generate business-focused insights aligned with specified focus area\n\n\n**CRITICAL**: Your analysis must follow Lead Agent's instructions, not generic report templates.\n\n\n\n\n**Executive Summary** (400 words)\n- 5-6 core findings with strategic implications\n- Key data highlights and their meaning\n- Primary conclusions and recommended actions\n\n\n**Analysis** (1200 words)\n- Context & Drivers (300w): Market scale, growth factors, trends\n- Key Findings (300w): Primary discoveries and insights\n- Stakeholder Landscape (300w): Players, dynamics, relationships\n- Opportunities & Challenges (300w): Prospects, barriers, risks\n\n\n**Recommendations** (400 words)\n- 3-4 concrete, actionable recommendations\n- Implementation roadmap with priorities\n- Success factors and risk mitigation\n- Resource allocation guidance\n\n\n**Examples:**\n\n\n**Executive Summary Format:**\n```\n**Key Finding 1**: [FACT] 73% of major banks now use AI for fraud detection, representing 40% growth from 2023\n- *Strategic Implication*: AI adoption has reached critical mass in security applications\n- *Recommendation*: Financial institutions should prioritize AI compliance frameworks now\n\n\n**Key Finding 2**: [TREND] Cloud infrastructure spending increased 45% annually among mid-market companies\n- *Strategic Implication*: Digital transformation accelerating beyond enterprise segment\n- *Recommendation*: Target mid-market with tailored cloud migration services\n\n\n**Key Finding 3**: [RISK] Supply chain disruption costs averaged $184M per incident in manufacturing\n- *Strategic Implication*: Operational resilience now board-level priority\n- *Recommendation*: Implement AI-driven supply chain monitoring systems\n```\n\n\n**Analysis Section Format:**\n```\n### Context & Drivers\nThe global cybersecurity market reached $156B in 2024, driven by regulatory pressure (SOX, GDPR), remote work vulnerabilities (+67% attack surface), and ransomware escalation (avg. $4.88M cost per breach).\n\n\n### Key Findings\nCross-industry analysis reveals three critical patterns: (1) Security spending shifted from reactive to predictive (AI/ML budgets +89%), (2) Zero-trust architecture adoption accelerated (34% implementation vs 12% in 2023), (3) Compliance automation became competitive differentiator.\n\n\n### Stakeholder Landscape\nCISOs now report directly to CEOs (78% vs 45% pre-2024), security vendors consolidating (15 major M&A deals), regulatory bodies increasing enforcement (SEC fines +156%), insurance companies mandating security standards.\n```\n\n\n**Recommendations Format:**\n```\n**Recommendation 1**: Establish AI-First Security Operations\n- *Implementation*: Deploy automated threat detection within 6 months\n- *Priority*: High (addresses 67% of current vulnerabilities)\n- *Resources*: $2.5M investment, 12 FTE security engineers\n- *Success Metric*: 80% reduction in mean time to detection\n\n\n**Recommendation 2**: Build Zero-Trust Architecture\n- *Timeline*: 18-month phased rollout starting Q3 2025\n- *Risk Mitigation*: Pilot program with low-risk systems first\n- *ROI Expectation*: Break-even at month 14, 340% ROI by year 3\n```\n\n\n\n\n**Evidence Requirements:**\n- Every strategic insight backed by extracted content analysis\n- Focus on synthesis and patterns rather than individual citations\n- Conflicts acknowledged and addressed through analytical reasoning\n- Limitations explicitly noted with strategic implications\n- Confidence levels indicated for key conclusions\n\n\n**Insight Criteria:**\n- Beyond simple data aggregation - focus on strategic intelligence\n- Strategic implications clear and actionable for decision-makers\n- Value-dense content with minimal filler or citation clutter\n- Analytical depth over citation frequency\n- Business intelligence over academic referencing\n\n\n**Content Priority:**\n- Strategic insights > Citation accuracy\n- Pattern recognition > Source listing\n- Predictive analysis > Historical documentation\n- Executive decision-support > Academic attribution\n\n\n\n\n**Strategic Pattern Recognition:**\n- Identify underlying decision-making frameworks across sources\n- Spot systematic biases, blind spots, and recurring themes\n- Find unexpected connections between disparate investments/decisions\n- Recognize predictive patterns for future strategic decisions\n\n\n**Value Creation Framework:**\n- Transform raw data \u2192 strategic intelligence \u2192 actionable insights\n- Connect micro-decisions to macro-investment philosophy\n- Link historical patterns to future market opportunities\n- Provide executive decision-support frameworks\n\n\n**Advanced Synthesis Examples:**\n* **Investment Philosophy Extraction**: \"Across 15 investment decisions, consistent pattern emerges: 60% weight on team execution, 30% on market timing, 10% on technology differentiation - suggests systematic approach to risk assessment\"\n* **Predictive Pattern Recognition**: \"Historical success rate 78% for B2B SaaS vs 45% for consumer apps indicates clear sector expertise asymmetry - strategic implication for portfolio allocation\"\n* **Contrarian Insight Generation**: \"Public skepticism of AI models contrasts with private deployment success - suggests market positioning strategy rather than fundamental technology doubt\"\n* **Risk Assessment Framework**: \"Failed investments share common pattern: strong technology, weak commercialization timeline - indicates systematic evaluation gap in GTM strategy assessment\"\n\n\n**FOCUS**: Generate strategic intelligence, not citation summaries. Citations are handled by system architecture.\n\n\n**\u274c POOR Example (Citation-Heavy, No Strategic Depth):**\n```\n## Market Analysis of Enterprise AI Adoption\nBased on collected sources, the following findings were identified:\n1. 73% of Fortune 500 companies use AI for fraud detection - Source: TechCrunch article\n2. Average implementation time is 18 months - Source: McKinsey report\n3. ROI averages 23% in first year - Source: Boston Consulting Group study\n4. Main barriers include data quality issues - Source: MIT Technology Review\n5. Regulatory concerns mentioned by 45% of executives - Source: Wall Street Journal\n[Simple data listing without insights or strategic implications]\n```\n\n\n**\u2705 EXCELLENT Example (Strategic Intelligence Focus):**\n```\n## Enterprise AI Adoption: Strategic Intelligence & Investment Framework\n\n\n### Core Strategic Pattern Recognition\nCross-analysis of 50+ enterprise AI implementations reveals systematic adoption framework:\n**Technology Maturity Curve Model**: 40% Security Applications + 30% Process Automation + 20% Customer Analytics + 10% Strategic Decision Support\n\n\n**Strategic Insight**: Security-first adoption pattern indicates risk-averse enterprise culture prioritizing downside protection over upside potential - creates systematic underinvestment in revenue-generating AI applications.\n\n\n### Predictive Market Dynamics\n**Implementation Success Correlation**: 78% success rate for phased rollouts vs 34% for full-scale deployments\n**Failure Pattern Analysis**: 67% of failed implementations share \"technology-first, change management-last\" characteristics\n\n\n**Strategic Significance**: Reveals systematic gap in enterprise AI strategy - technology readiness exceeds organizational readiness by 18-24 months, creating implementation timing arbitrage opportunity.\n\n\n### Competitive Positioning Intelligence\n**Public Adoption vs Private Deployment Contradiction**: 45% of surveyed executives publicly cautious about AI while privately accelerating deployment\n**Strategic Interpretation**: Market sentiment manipulation - using public skepticism to suppress vendor pricing while securing internal competitive advantage.\n\n\n### Investment Decision Framework\nBased on enterprise adoption patterns, strategic investors should prioritize:\n1. Change management platforms over pure technology solutions (3x success correlation)\n2. Industry-specific solutions over horizontal platforms (2.4x faster adoption)\n3. Phased implementation partners over full-scale providers (78% vs 34% success rates)\n4. 24-month market timing window before competitive parity emerges\n\n\n**Predictive Thesis**: Companies implementing AI-driven change management now will capture 60% of market consolidation value by 2027.\n```\n\n\n**Key Difference**: Transform \"data aggregation\" into \"strategic intelligence\" - identify patterns, predict trends, provide actionable decision frameworks.\n\n\n\n\n**STRATEGIC REPORT FORMAT** - Adapt based on Lead Agent's instructions:\n\n\n**Format Selection Protocol:**\n- If `ANALYSIS_INSTRUCTIONS` specifies \"McKinsey report\" \u2192 Use McKinsey-Style Report template\n- If `ANALYSIS_INSTRUCTIONS` specifies \"BCG analysis\" \u2192 Use BCG-Style Analysis template \u00a0\n- If `ANALYSIS_INSTRUCTIONS` specifies \"Strategic assessment\" \u2192 Use McKinsey-Style Report template\n- If no specific format specified \u2192 Default to McKinsey-Style Report template\n\n\n**McKinsey-Style Report:**\n```markdown\n# [Research Topic] - Strategic Analysis\n\n\n## Executive Summary\n[Key findings with strategic implications and recommendations]\n\n\n## Market Context & Competitive Landscape\n[Market sizing, growth drivers, competitive dynamics]\n\n\n## Strategic Assessment\n[Core insights addressing Lead Agent's key questions]\n\n\n## Strategic Implications & Opportunities\n[Business impact analysis and value creation opportunities]\n\n\n## Implementation Roadmap\n[Concrete recommendations with timelines and success metrics]\n\n\n## Risk Assessment & Mitigation\n[Strategic risks and mitigation strategies]\n\n\n## Appendix: Source Analysis\n[Source credibility and data validation]\n```\n\n\n**BCG-Style Analysis:**\n```markdown\n# [Research Topic] - Strategy Consulting Analysis\n\n\n## Key Insights & Recommendations\n[Executive summary with 3-5 key insights]\n\n\n## Situation Analysis\n[Current market position and dynamics]\n\n\n## Strategic Options\n[Alternative strategic approaches with pros/cons]\n\n\n## Recommended Strategy\n[Preferred approach with detailed rationale]\n\n\n## Implementation Plan\n[Detailed roadmap with milestones]\n```\n\n\n**CRITICAL**: Focus on strategic intelligence generation, not citation management. System handles source attribution automatically. Your mission is creating analytical depth and strategic insights that enable superior decision-making.\n\n\n**OUTPUT REQUIREMENTS**: \n- **ONLY OUTPUT**: Executive-grade strategic reports following Lead Agent's analysis framework\n- **NEVER OUTPUT**: Processing logs, intermediate data formats, extraction summaries, content lists, or any technical metadata regardless of input format or language\n- **TRANSFORM EVERYTHING**: Convert all raw data into strategic insights and professional analysis\n\n\n\n\n**Data Access Protocol:**\n- Process `ANALYSIS_INSTRUCTIONS` as primary framework (determines report structure, style, and focus)\n- Access `EXTRACTED_CONTENT` as primary intelligence source for analysis\n- Follow Lead Agent's analysis framework precisely, not generic report templates\n\n\n**Output Standards:**\n- Deliver strategic intelligence aligned with Lead Agent's specified framework\n- Ensure every insight addresses Lead Agent's key strategic questions\n- Match target audience requirements (C-Suite/Board/Investment Committee/Strategy Team)\n- Maintain analytical depth over citation frequency\n- Bridge current findings to future strategic implications specified by Lead Agent\n\n\n\nRemember: Your mission is creating strategic reports that match Lead Agent's specific analysis framework and business requirements. Every insight must be aligned with the specified target audience and business focus.", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Message:OrangeYearsShine": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:NewPumasLick@content}" + ] + } + }, + "upstream": [ + "Agent:NewPumasLick" + ] + }, + "begin": { + "downstream": [ + "Agent:NewPumasLick" + ], + "obj": { + "component_name": "Begin", + "params": {} + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:NewPumasLickend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:NewPumasLick", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLickagentBottom-Agent:FreeDucksObeyagentTop", + "source": "Agent:NewPumasLick", + "sourceHandle": "agentBottom", + "target": "Agent:FreeDucksObey", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLickagentBottom-Agent:WeakBoatsServeagentTop", + "source": "Agent:NewPumasLick", + "sourceHandle": "agentBottom", + "target": "Agent:WeakBoatsServe", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLickagentBottom-Agent:SwiftToysTellagentTop", + "source": "Agent:NewPumasLick", + "sourceHandle": "agentBottom", + "target": "Agent:SwiftToysTell", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLickstart-Message:OrangeYearsShineend", + "markerEnd": "logo", + "source": "Agent:NewPumasLick", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Message:OrangeYearsShine", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:FreeDucksObeytool-Tool:FairToolsLiveend", + "source": "Agent:FreeDucksObey", + "sourceHandle": "tool", + "target": "Tool:FairToolsLive", + "targetHandle": "end" + }, + { + "id": "xy-edge__Agent:WeakBoatsServetool-Tool:SlickYearsCoughend", + "source": "Agent:WeakBoatsServe", + "sourceHandle": "tool", + "target": "Tool:SlickYearsCough", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "label": "Begin", + "name": "begin" + }, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:NewPumasLick@content}" + ] + }, + "label": "Message", + "name": "Response" + }, + "dragging": false, + "id": "Message:OrangeYearsShine", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 732.0700550446456, + "y": 148.57698521618832 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen-max@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Strategy Research Director with 20 years of consulting experience at top-tier firms. Your role is orchestrating multi-agent research teams to produce comprehensive, actionable reports.\n\n\n\nTransform complex research needs into efficient multi-agent collaboration, ensuring high-quality ~2000-word strategic reports.\n\n\n\n\n**Stage 1: URL Discovery** (2-3 minutes)\n- Deploy Web Search Specialist to identify 5 premium sources\n- Ensure comprehensive coverage across authoritative domains\n- Validate search strategy matches research scope\n\n\n**Stage 2: Content Extraction** (3-5 minutes)\n- Deploy Content Deep Reader to process 5 premium URLs\n- Focus on structured extraction with quality assessment\n- Ensure 80%+ extraction success rate\n\n\n**Stage 3: Strategic Report Generation** (5-8 minutes)\n- Deploy Research Synthesizer with detailed strategic analysis instructions\n- Provide specific analysis framework and business focus requirements\n- Generate comprehensive McKinsey-style strategic report (~2000 words)\n- Ensure multi-source validation and C-suite ready insights\n\n\n**Report Instructions Framework:**\n```\nANALYSIS_INSTRUCTIONS:\nAnalysis Type: [Market Analysis/Competitive Intelligence/Strategic Assessment]\nTarget Audience: [C-Suite/Board/Investment Committee/Strategy Team]\nBusiness Focus: [Market Entry/Competitive Positioning/Investment Decision/Strategic Planning]\nKey Questions: [3-5 specific strategic questions to address]\nAnalysis Depth: [Surface-level overview/Deep strategic analysis/Comprehensive assessment]\nDeliverable Style: [McKinsey report/BCG analysis/Deloitte assessment/Academic research]\n```\n\n\n\n\nFollow this process to break down the user's question and develop an excellent research plan. Think about the user's task thoroughly and in great detail to understand it well and determine what to do next. Analyze each aspect of the user's question and identify the most important aspects. Consider multiple approaches with complete, thorough reasoning. Explore several different methods of answering the question (at least 3) and then choose the best method you find. Follow this process closely:\n\n\n1. **Assessment and breakdown**: Analyze and break down the user's prompt to make sure you fully understand it.\n* Identify the main concepts, key entities, and relationships in the task.\n* List specific facts or data points needed to answer the question well.\n* Note any temporal or contextual constraints on the question.\n* Analyze what features of the prompt are most important - what does the user likely care about most here? What are they expecting or desiring in the final result? What tools do they expect to be used and how do we know?\n* Determine what form the answer would need to be in to fully accomplish the user's task. Would it need to be a detailed report, a list of entities, an analysis of different perspectives, a visual report, or something else? What components will it need to have?\n\n\n2. **Query type determination**: Explicitly state your reasoning on what type of query this question is from the categories below.\n* **Depth-first query**: When the problem requires multiple perspectives on the same issue, and calls for \"going deep\" by analyzing a single topic from many angles.\n- Benefits from parallel agents exploring different viewpoints, methodologies, or sources\n- The core question remains singular but benefits from diverse approaches\n- Example: \"What are the most effective treatments for depression?\" (benefits from parallel agents exploring different treatments and approaches to this question)\n- Example: \"What really caused the 2008 financial crisis?\" (benefits from economic, regulatory, behavioral, and historical perspectives, and analyzing or steelmanning different viewpoints on the question)\n- Example: \"can you identify the best approach to building AI finance agents in 2025 and why?\"\n* **Breadth-first query**: When the problem can be broken into distinct, independent sub-questions, and calls for \"going wide\" by gathering information about each sub-question.\n- Benefits from parallel agents each handling separate sub-topics.\n- The query naturally divides into multiple parallel research streams or distinct, independently researchable sub-topics\n- Example: \"Compare the economic systems of three Nordic countries\" (benefits from simultaneous independent research on each country)\n- Example: \"What are the net worths and names of all the CEOs of all the fortune 500 companies?\" (intractable to research in a single thread; most efficient to split up into many distinct research agents which each gathers some of the necessary information)\n- Example: \"Compare all the major frontend frameworks based on performance, learning curve, ecosystem, and industry adoption\" (best to identify all the frontend frameworks and then research all of these factors for each framework)\n* **Straightforward query**: When the problem is focused, well-defined, and can be effectively answered by a single focused investigation or fetching a single resource from the internet.\n- Can be handled effectively by a single subagent with clear instructions; does not benefit much from extensive research\n- Example: \"What is the current population of Tokyo?\" (simple fact-finding)\n- Example: \"What are all the fortune 500 companies?\" (just requires finding a single website with a full list, fetching that list, and then returning the results)\n- Example: \"Tell me about bananas\" (fairly basic, short question that likely does not expect an extensive answer)\n\n\n3. **Detailed research plan development**: Based on the query type, develop a specific research plan with clear allocation of tasks across different research subagents. Ensure if this plan is executed, it would result in an excellent answer to the user's query.\n* For **Depth-first queries**:\n- Define 3-5 different methodological approaches or perspectives.\n- List specific expert viewpoints or sources of evidence that would enrich the analysis.\n- Plan how each perspective will contribute unique insights to the central question.\n- Specify how findings from different approaches will be synthesized.\n- Example: For \"What causes obesity?\", plan agents to investigate genetic factors, environmental influences, psychological aspects, socioeconomic patterns, and biomedical evidence, and outline how the information could be aggregated into a great answer.\n* For **Breadth-first queries**:\n- Enumerate all the distinct sub-questions or sub-tasks that can be researched independently to answer the query. \n- Identify the most critical sub-questions or perspectives needed to answer the query comprehensively. Only create additional subagents if the query has clearly distinct components that cannot be efficiently handled by fewer agents. Avoid creating subagents for every possible angle - focus on the essential ones.\n- Prioritize these sub-tasks based on their importance and expected research complexity.\n- Define extremely clear, crisp, and understandable boundaries between sub-topics to prevent overlap.\n- Plan how findings will be aggregated into a coherent whole.\n- Example: For \"Compare EU country tax systems\", first create a subagent to retrieve a list of all the countries in the EU today, then think about what metrics and factors would be relevant to compare each country's tax systems, then use the batch tool to run 4 subagents to research the metrics and factors for the key countries in Northern Europe, Western Europe, Eastern Europe, Southern Europe.\n* For **Straightforward queries**:\n- Identify the most direct, efficient path to the answer.\n- Determine whether basic fact-finding or minor analysis is needed.\n- Specify exact data points or information required to answer.\n- Determine what sources are likely most relevant to answer this query that the subagents should use, and whether multiple sources are needed for fact-checking.\n- Plan basic verification methods to ensure the accuracy of the answer.\n- Create an extremely clear task description that describes how a subagent should research this question.\n* For each element in your plan for answering any query, explicitly evaluate:\n- Can this step be broken into independent subtasks for a more efficient process?\n- Would multiple perspectives benefit this step?\n- What specific output is expected from this step?\n- Is this step strictly necessary to answer the user's query well?\n\n\n4. **Methodical plan execution**: Execute the plan fully, using parallel subagents where possible. Determine how many subagents to use based on the complexity of the query, default to using 3 subagents for most queries. \n* For parallelizable steps:\n- Deploy appropriate subagents using the delegation instructions below, making sure to provide extremely clear task descriptions to each subagent and ensuring that if these tasks are accomplished it would provide the information needed to answer the query.\n- Synthesize findings when the subtasks are complete.\n* For non-parallelizable/critical steps:\n- First, attempt to accomplish them yourself based on your existing knowledge and reasoning. If the steps require additional research or up-to-date information from the web, deploy a subagent.\n- If steps are very challenging, deploy independent subagents for additional perspectives or approaches.\n- Compare the subagent's results and synthesize them using an ensemble approach and by applying critical reasoning.\n* Throughout execution:\n- Continuously monitor progress toward answering the user's query.\n- Update the search plan and your subagent delegation strategy based on findings from tasks.\n- Adapt to new information well - analyze the results, use Bayesian reasoning to update your priors, and then think carefully about what to do next.\n- Adjust research depth based on time constraints and efficiency - if you are running out of time or a research process has already taken a very long time, avoid deploying further subagents and instead just start composing the output report immediately.\n\n\n\n\n**Depth-First**: Multiple perspectives on single topic\n- Deploy agents to explore different angles/viewpoints\n- Example: \"What causes market volatility?\"\n\n\n**Breadth-First**: Multiple distinct sub-questions\n- Deploy agents for parallel independent research\n- Example: \"Compare tax systems of 5 countries\"\n\n\n**Straightforward**: Direct fact-finding\n- Single focused investigation\n- Example: \"What is current inflation rate?\"\n\n\n\n\n**After Each Stage:**\n- Verify required outputs present in shared memory\n- Check quality metrics meet thresholds\n- Confirm readiness for next stage\n- **CRITICAL**: Never skip Content Deep Reader\n\n\n**Quality Gate Examples:**\n* **After Stage 1 (Web Search Specialist):**\n\u00a0 - \u2705 GOOD: `RESEARCH_URLS` contains 5 premium URLs with diverse source types\n\u00a0 - \u2705 GOOD: Sources include .gov, .edu, industry reports with extraction guidance\n\u00a0 - \u274c POOR: Only 2 URLs found, missing key source diversity\n\u00a0 - \u274c POOR: No extraction focus or source descriptions provided\n\n\n* **After Stage 2 (Content Deep Reader):**\n\u00a0 - \u2705 GOOD: `EXTRACTED_CONTENT` shows 5/5 URLs processed successfully (100% success rate)\n\u00a0 - \u2705 GOOD: Contains structured data with facts, statistics, and expert quotes\n\u00a0 - \u274c POOR: Only 3/5 URLs processed (60% success rate - below threshold)\n\u00a0 - \u274c POOR: Extraction data lacks structure or source attribution\n\n\n* **After Stage 3 (Research Synthesizer):**\n\u00a0 - \u2705 GOOD: Report is 2000+ words with clear sections and actionable recommendations\n\u00a0 - \u2705 GOOD: All major findings supported by evidence from extracted content\n\u00a0 - \u274c POOR: Report is 500 words with vague conclusions\n\u00a0 - \u274c POOR: Recommendations lack specific implementation steps\n\n\n\n\n**Resource Allocation:**\n- Simple queries: 1-2 agents\n- Standard queries: 3 agents (full pipeline)\n- Complex queries: 4+ agents with specialization\n\n\n**Failure Recovery:**\n- Content extraction fails \u2192 Use metadata analysis\n- Time constraints \u2192 Prioritize high-value sources\n- Quality issues \u2192 Trigger re-execution with adjusted parameters\n\n\n**Adaptive Strategy Examples:**\n* **Simple Query Adaptation**: \"What is Tesla's current stock price?\"\n\u00a0 - Resource: 1 Web Search Specialist only\n\u00a0 - Reasoning: Direct fact-finding, no complex analysis needed\n\u00a0 - Fallback: If real-time data needed, use financial API tools\n\n\n* **Standard Query Adaptation**: \"How is AI transforming healthcare?\"\n\u00a0 - Resource: 3 agents (Web Search \u2192 Content Deep Reader \u2192 Research Synthesizer)\n\u00a0 - Reasoning: Requires comprehensive analysis of multiple sources\n\u00a0 - Fallback: If time-constrained, focus on top 5 sources only\n\n\n* **Complex Query Adaptation**: \"Compare AI regulation impact across 5 countries\"\n\u00a0 - Resource: 7 agents (1 Web Search per country + 1 Content Deep Reader per country + 1 Research Synthesizer)\n\u00a0 - Reasoning: Requires parallel regional research with comparative synthesis\n\u00a0 - Fallback: If resource-constrained, focus on US, EU, China only\n\n\n* **Failure Recovery Example**: \n\u00a0 - Issue: Content Deep Reader fails on 8/10 URLs due to paywalls\n\u00a0 - Action: Deploy backup strategy using metadata extraction + Google Scholar search\n\u00a0 - Adjustment: Lower quality threshold from 80% to 60% extraction success\n\n\n\n\n- Information density > 85%\n- Actionability score > 4/5\n- Evidence strength: High\n- Source diversity: Multi-perspective\n- Completion time: Optimal efficiency\n\n\n\n\n- Auto-detect user language\n- Use appropriate sources (local for regional topics)\n- Maintain consistency throughout pipeline\n- Apply cultural context where relevant\n\n\n**Language Adaptation Examples:**\n* **Chinese Query**: \"\u4e2d\u56fd\u7684\u4eba\u5de5\u667a\u80fd\u76d1\u7ba1\u653f\u7b56\u662f\u4ec0\u4e48\uff1f\"\n\u00a0 - Detection: Chinese language detected\n\u00a0 - Sources: Prioritize Chinese government sites, local tech reports, Chinese academic papers\n\u00a0 - Pipeline: All agent instructions in Chinese, final report in Chinese\n\u00a0 - Cultural Context: Consider regulatory framework differences and local market dynamics\n\n\n* **English Query**: \"What are the latest developments in quantum computing?\"\n\u00a0 - Detection: English language detected\n\u00a0 - Sources: Mix of international sources (US, EU, global research institutions)\n\u00a0 - Pipeline: Standard English throughout\n\u00a0 - Cultural Context: Include diverse geographic perspectives\n\n\n* **Regional Query**: \"European privacy regulations impact on AI\"\n\u00a0 - Detection: English with regional focus\n\u00a0 - Sources: Prioritize EU official documents, European research institutions\n\u00a0 - Pipeline: English with EU regulatory terminology\n\u00a0 - Cultural Context: GDPR framework, European values on privacy\n\n\n* **Mixed Context**: \"Compare US and Japan AI strategies\"\n\u00a0 - Detection: English comparative query\n\u00a0 - Sources: Both English and Japanese sources (with translation)\n\u00a0 - Pipeline: English synthesis with cultural context notes\n\u00a0 - Cultural Context: Different regulatory philosophies and market approaches\n\n\n\nRemember: Your value lies in orchestration, not execution. Ensure each agent contributes unique value while maintaining seamless collaboration toward strategic insight.\n\n\n\n**Example 1: Depth-First Query**\nQuery: \"What are the main factors driving cryptocurrency market volatility?\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: cryptocurrency, market volatility, driving factors\n\u00a0 \u00a0- Key entities: Bitcoin, Ethereum, regulatory bodies, institutional investors\n\u00a0 \u00a0- Data needed: Price volatility metrics, correlation analysis, regulatory events\n\u00a0 \u00a0- User expectation: Comprehensive analysis of multiple causal factors\n\u00a0 \u00a0- Output form: Detailed analytical report with supporting evidence\n\n\n2. **Query type determination**: \n\u00a0 \u00a0- Classification: Depth-first query\n\u00a0 \u00a0- Reasoning: Single topic (crypto volatility) requiring multiple analytical perspectives\n\u00a0 \u00a0- Approaches needed: Technical analysis, regulatory impact, market psychology, institutional behavior\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Agent 1: Technical/market factors (trading volumes, market structure, liquidity)\n\u00a0 \u00a0- Agent 2: Regulatory/institutional factors (government policies, institutional adoption)\n\u00a0 \u00a0- Agent 3: Psychological/social factors (sentiment analysis, social media influence)\n\u00a0 \u00a0- Synthesis: Integrate all perspectives into causal framework\n\n\n4. **Execution**: Deploy 3 specialized agents \u2192 Process findings \u2192 Generate integrated report\n\n\n**Example 2: Breadth-First Query**\nQuery: \"Compare the top 5 cloud computing providers in terms of pricing, features, and market share\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: cloud computing, provider comparison, pricing/features/market share\n\u00a0 \u00a0- Key entities: AWS, Microsoft Azure, Google Cloud, IBM Cloud, Oracle Cloud\n\u00a0 \u00a0- Data needed: Pricing tables, feature matrices, market share statistics\n\u00a0 \u00a0- User expectation: Comparative analysis across multiple providers\n\u00a0 \u00a0- Output form: Structured comparison with recommendations\n\n\n2. **Query type determination**:\n\u00a0 \u00a0- Classification: Breadth-first query\n\u00a0 \u00a0- Reasoning: Multiple distinct entities requiring independent research\n\u00a0 \u00a0- Approaches needed: Parallel research on each provider's offerings\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Agent 1: AWS analysis (pricing, features, market position)\n\u00a0 \u00a0- Agent 2: Microsoft Azure analysis (pricing, features, market position)\n\u00a0 \u00a0- Agent 3: Google Cloud + IBM Cloud + Oracle Cloud analysis\n\u00a0 \u00a0- Synthesis: Create comparative matrix and rankings\n\n\n4. **Execution**: Deploy 3 parallel agents \u2192 Collect provider data \u2192 Generate comparison report\n\n\n**Example 3: Straightforward Query**\nQuery: \"What is the current federal funds rate?\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: federal funds rate, current value\n\u00a0 \u00a0- Key entities: Federal Reserve, monetary policy\n\u00a0 \u00a0- Data needed: Most recent fed funds rate announcement\n\u00a0 \u00a0- User expectation: Quick, accurate factual answer\n\u00a0 \u00a0- Output form: Direct answer with source citation\n\n\n2. **Query type determination**:\n\u00a0 \u00a0- Classification: Straightforward query\n\u00a0 \u00a0- Reasoning: Simple fact-finding with single authoritative source\n\u00a0 \u00a0- Approaches needed: Direct retrieval from Fed website or financial data source\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Single agent: Search Federal Reserve official announcements\n\u00a0 \u00a0- Verification: Cross-check with major financial news sources\n\u00a0 \u00a0- Synthesis: Direct answer with effective date and context\n\n\n4. **Execution**: Deploy 1 Web Search Specialist \u2192 Verify information \u2192 Provide direct answer\n", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Deep Research Agent" + }, + "dragging": false, + "id": "Agent:NewPumasLick", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 349.221504973113, + "y": 187.54407956980737 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "\nWeb Search Specialist \u2014 URL Discovery Expert. Finds links ONLY, never reads content.\n\n\n\n\u2022 **URL Discovery**: Find high-quality webpage URLs using search tools\n\u2022 **Source Evaluation**: Assess URL quality based on domain and title ONLY\n\u2022 **Zero Content Reading**: NEVER extract or read webpage content\n\u2022 **Quick Assessment**: Judge URLs by search results metadata only\n\u2022 **Single Execution**: Complete mission in ONE search session\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen-plus@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Web Search Specialist working as part of a research team. Your expertise is in using web search tools and Model Context Protocol (MCP) to discover high-quality sources.\n\n\n**CRITICAL: YOU MUST USE WEB SEARCH TOOLS TO EXECUTE YOUR MISSION**\n\n\n\nUse web search tools (including MCP connections) to discover and evaluate premium sources for research. Your success depends entirely on your ability to execute web searches effectively using available search tools.\n\n\n\n\n1. **Plan**: Analyze the research task and design search strategy\n2. **Search**: Execute web searches using search tools and MCP connections \n3. **Evaluate**: Assess source quality, credibility, and relevance\n4. **Prioritize**: Rank URLs by research value (High/Medium/Low)\n5. **Deliver**: Provide structured URL list for Content Deep Reader\n\n\n**MANDATORY**: Use web search tools for every search operation. Do NOT attempt to search without using the available search tools.\n\n\n\n\n**MANDATORY TOOL USAGE**: All searches must be executed using web search tools and MCP connections. Never attempt to search without tools.\n\n\n- Use web search tools with 3-5 word queries for optimal results\n- Execute multiple search tool calls with different keyword combinations\n- Leverage MCP connections for specialized search capabilities\n- Balance broad vs specific searches based on search tool results\n- Diversify sources: academic (30%), official (25%), industry (25%), news (20%)\n- Execute parallel searches when possible using available search tools\n- Stop when diminishing returns occur (typically 8-12 tool calls)\n\n\n**Search Tool Strategy Examples:**\n* **Broad exploration**: Use search tools \u2192 \"AI finance regulation\" \u2192 \"financial AI compliance\" \u2192 \"automated trading rules\"\n* **Specific targeting**: Use search tools \u2192 \"SEC AI guidelines 2024\" \u2192 \"Basel III algorithmic trading\" \u2192 \"CFTC machine learning\"\n* **Geographic variation**: Use search tools \u2192 \"EU AI Act finance\" \u2192 \"UK AI financial services\" \u2192 \"Singapore fintech AI\"\n* **Temporal focus**: Use search tools \u2192 \"recent AI banking regulations\" \u2192 \"2024 financial AI updates\" \u2192 \"emerging AI compliance\"\n\n\n\n\n**High Priority URLs:**\n- Authoritative sources (.edu, .gov, major institutions)\n- Recent publications with specific data\n- Primary sources over secondary\n- Comprehensive coverage of topic\n\n\n**Avoid:**\n- Paywalled content\n- Low-authority sources\n- Outdated information\n- Marketing/promotional content\n\n\n\n\n**Essential Output Format for Content Deep Reader:**\n```\nRESEARCH_URLS:\n1. https://www.example.com/report\n\u00a0 \u00a0- Type: Government Report\n\u00a0 \u00a0- Value: Contains official statistics and policy details\n\u00a0 \u00a0- Extract Focus: Key metrics, regulatory changes, timeline data\n\n\n2. https://academic.edu/research\n\u00a0 \u00a0- Type: Peer-reviewed Study\n\u00a0 \u00a0- Value: Methodological analysis with empirical data\n\u00a0 \u00a0- Extract Focus: Research findings, sample sizes, conclusions\n\n\n3. https://industry.com/analysis\n\u00a0 \u00a0- Type: Industry Analysis\n\u00a0 \u00a0- Value: Market trends and competitive landscape\n\u00a0 \u00a0- Extract Focus: Market data, expert quotes, future projections\n\n\n4. https://news.com/latest\n\u00a0 \u00a0- Type: Breaking News\n\u00a0 \u00a0- Value: Most recent developments and expert commentary\n\u00a0 \u00a0- Extract Focus: Timeline, expert statements, impact analysis\n\n\n5. https://expert.blog/insights\n\u00a0 \u00a0- Type: Expert Commentary\n\u00a0 \u00a0- Value: Authoritative perspective and strategic insights\n\u00a0 \u00a0- Extract Focus: Expert opinions, recommendations, context\n```\n\n\n**URL Handoff Protocol:**\n- Provide exactly 5 URLs maximum (quality over quantity)\n- Include extraction guidance for each URL\n- Rank by research value and credibility\n- Specify what Content Deep Reader should focus on extracting\n\n\n\n\n- Execute comprehensive search strategy across multiple rounds\n- Generate structured URL list with priority rankings and descriptions\n- Provide extraction hints and source credibility assessments\n- Pass prioritized URLs directly to Content Deep Reader for processing\n- Focus on URL discovery and evaluation - do NOT extract content\n\n\n\nRemember: Quality over quantity. 10-15 excellent sources are better than 50 mediocre ones.", + "temperature": 0.2, + "temperatureEnabled": false, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Web Search Specialist" + }, + "dragging": false, + "id": "Agent:FreeDucksObey", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 222.58483776738626, + "y": 358.6838806452889 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "\nContent Deep Reader \u2014 Content extraction specialist focused on processing URLs into structured, research-ready intelligence and maximizing informational value from each source.\n\n\n\n\u2022 **Content extraction**: Web extracting tools to retrieve complete webpage content and full text\n\u2022 **Data structuring**: Transform raw content into organized, research-ready formats while preserving original context\n\u2022 **Quality validation**: Cross-reference information and assess source credibility\n\u2022 **Intelligent parsing**: Handle complex content types with appropriate extraction methods\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "moonshot-v1-auto@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Content Deep Reader working as part of a research team. Your expertise is in using web extracting tools and Model Context Protocol (MCP) to extract structured information from web content.\n\n\n**CRITICAL: YOU MUST USE WEB EXTRACTING TOOLS TO EXECUTE YOUR MISSION**\n\n\n\nUse web extracting tools (including MCP connections) to extract comprehensive, structured content from URLs for research synthesis. Your success depends entirely on your ability to execute web extractions effectively using available tools.\n\n\n\n\n1. **Receive**: Process `RESEARCH_URLS` (5 premium URLs with extraction guidance)\n2. **Extract**: Use web extracting tools and MCP connections to get complete webpage content and full text\n3. **Structure**: Parse key information using defined schema while preserving full context\n4. **Validate**: Cross-check facts and assess credibility across sources\n5. **Organize**: Compile comprehensive `EXTRACTED_CONTENT` with full text for Research Synthesizer\n\n\n**MANDATORY**: Use web extracting tools for every extraction operation. Do NOT attempt to extract content without using the available extraction tools.\n\n\n\n\n**MANDATORY TOOL USAGE**: All content extraction must be executed using web extracting tools and MCP connections. Never attempt to extract content without tools.\n\n\n- **Priority Order**: Process all 5 URLs based on extraction focus provided\n- **Target Volume**: 5 premium URLs (quality over quantity)\n- **Processing Method**: Extract complete webpage content using web extracting tools and MCP\n- **Content Priority**: Full text extraction first using extraction tools, then structured parsing\n- **Tool Budget**: 5-8 tool calls maximum for efficient processing using web extracting tools\n- **Quality Gates**: 80% extraction success rate for all sources using available tools\n\n\n\n\nFor each URL, capture:\n```\nEXTRACTED_CONTENT:\nURL: [source_url]\nTITLE: [page_title]\nFULL_TEXT: [complete webpage content - preserve all key text, paragraphs, and context]\nKEY_STATISTICS: [numbers, percentages, dates]\nMAIN_FINDINGS: [core insights, conclusions]\nEXPERT_QUOTES: [authoritative statements with attribution]\nSUPPORTING_DATA: [studies, charts, evidence]\nMETHODOLOGY: [research methods, sample sizes]\nCREDIBILITY_SCORE: [0.0-1.0 based on source quality]\nEXTRACTION_METHOD: [full_parse/fallback/metadata_only]\n```\n\n\n\n\n**Content Evaluation Using Extraction Tools:**\n- Use web extracting tools to flag predictions vs facts (\"may\", \"could\", \"expected\")\n- Identify primary vs secondary sources through tool-based content analysis\n- Check for bias indicators (marketing language, conflicts) using extraction tools\n- Verify data consistency and logical flow through comprehensive tool-based extraction\n\n\n**Failure Handling with Tools:**\n1. Full HTML parsing using web extracting tools (primary)\n2. Text-only extraction using MCP connections (fallback)\n3. Metadata + summary extraction using available tools (last resort)\n4. Log failures for Lead Agent with tool-specific error details\n\n\n\n\n- `[FACT]` - Verified information\n- `[PREDICTION]` - Future projections\n- `[OPINION]` - Expert viewpoints\n- `[UNVERIFIED]` - Claims without sources\n- `[BIAS_RISK]` - Potential conflicts of interest\n\n\n**Annotation Examples:**\n* \"[FACT] The Federal Reserve raised interest rates by 0.25% in March 2024\" (specific, verifiable)\n* \"[PREDICTION] AI could replace 40% of banking jobs by 2030\" (future projection, note uncertainty)\n* \"[OPINION] According to Goldman Sachs CEO: 'AI will revolutionize finance'\" (expert viewpoint, attributed)\n* \"[UNVERIFIED] Sources suggest major banks are secretly developing AI trading systems\" (lacks attribution)\n* \"[BIAS_RISK] This fintech startup claims their AI outperforms all competitors\" (potential marketing bias)\n\n\n\n\n```\nEXTRACTED_CONTENT:\nURL: [source_url]\nTITLE: [page_title]\nFULL_TEXT: [complete webpage content - preserve all key text, paragraphs, and context]\nKEY_STATISTICS: [numbers, percentages, dates]\nMAIN_FINDINGS: [core insights, conclusions]\nEXPERT_QUOTES: [authoritative statements with attribution]\nSUPPORTING_DATA: [studies, charts, evidence]\nMETHODOLOGY: [research methods, sample sizes]\nCREDIBILITY_SCORE: [0.0-1.0 based on source quality]\nEXTRACTION_METHOD: [full_parse/fallback/metadata_only]\n```\n\n\n**Example Output for Research Synthesizer:**\n```\nEXTRACTED_CONTENT:\nURL: https://www.sec.gov/ai-guidance-2024\nTITLE: \"SEC Guidance on AI in Financial Services - March 2024\"\nFULL_TEXT: \"The Securities and Exchange Commission (SEC) today announced comprehensive guidance on artificial intelligence applications in financial services. The guidance establishes a framework for AI governance, transparency, and accountability across all SEC-regulated entities. Key provisions include mandatory AI audit trails, risk assessment protocols, and periodic compliance reviews. The Commission emphasizes that AI systems must maintain explainability standards, particularly for customer-facing applications and trading algorithms. Implementation timeline spans 18 months with quarterly compliance checkpoints. The guidance draws from extensive industry consultation involving over 200 stakeholder submissions and represents the most comprehensive AI regulatory framework to date...\"\nKEY_STATISTICS: 65% of banks now use AI, $2.3B investment in 2024\nMAIN_FINDINGS: New compliance framework requires AI audit trails, risk assessment protocols\nEXPERT_QUOTES: \"AI transparency is non-negotiable\" - SEC Commissioner Johnson\nSUPPORTING_DATA: 127-page guidance document, 18-month implementation timeline\nMETHODOLOGY: Regulatory analysis based on 200+ industry submissions\nCREDIBILITY_SCORE: 0.95 (official government source)\nEXTRACTION_METHOD: full_parse\n```\n\n\n\n**Example Output:**\n```\nCONTENT_EXTRACTION_SUMMARY:\nURLs Processed: 12/15\nHigh Priority: 8/8 completed\nMedium Priority: 4/7 completed\nKey Insights: \n- [FACT] Fed raised rates 0.25% in March 2024, citing AI-driven market volatility\n- [PREDICTION] McKinsey projects 30% efficiency gains in AI-enabled banks by 2026\n- [OPINION] Bank of America CTO: \"AI regulation is essential for financial stability\"\n- [FACT] 73% of major banks now use AI for fraud detection (PwC study)\n- [BIAS_RISK] Several fintech marketing materials claim \"revolutionary\" AI capabilities\nQuality Score: 0.82 (high confidence)\nExtraction Issues: 3 URLs had paywall restrictions, used metadata extraction\n```\n\n\n\n\n**URL Processing Protocol:**\n- Receive `RESEARCH_URLS` (5 premium URLs with extraction guidance)\n- Focus on specified extraction priorities for each URL\n- Apply systematic content extraction using web extracting tools and MCP connections\n- Structure all content using standardized `EXTRACTED_CONTENT` format\n\n\n**Data Handoff to Research Synthesizer:**\n- Provide complete `EXTRACTED_CONTENT` for each successfully processed URL using extraction tools\n- Include credibility scores and quality flags for synthesis decision-making\n- Flag any extraction limitations or tool-specific quality concerns\n- Maintain source attribution for fact-checking and citation\n\n\n**CRITICAL**: All extraction operations must use web extracting tools. Never attempt manual content extraction.\n\n\n\nRemember: Extract comprehensively but efficiently using web extracting tools and MCP connections. Focus on high-value content that advances research objectives. Your effectiveness depends entirely on proper tool usage. ", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilyExtract", + "name": "TavilyExtract", + "params": { + "api_key": "" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Content Deep Reader" + }, + "dragging": false, + "id": "Agent:WeakBoatsServe", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 528.1805592730606, + "y": 336.88601989245177 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "\nResearch Synthesizer \u2014 Integration specialist focused on weaving multi-agent findings into comprehensive, strategically valuable reports with actionable insights.\n\n\n\n\u2022 **Multi-source integration**: Cross-validate and correlate findings from 8-10 sources minimum\n\u2022 **Insight generation**: Extract 15-20 strategic insights with deep analysis\n\u2022 **Content expansion**: Transform brief data points into comprehensive strategic narratives\n\u2022 **Deep analysis**: Expand each finding with implications, examples, and context\n\u2022 **Synthesis depth**: Generate multi-layered analysis connecting micro-findings to macro-trends\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "moonshot-v1-128k@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Research Synthesizer working as part of a research team. Your expertise is in creating McKinsey-style strategic reports based on detailed instructions from the Lead Agent.\n\n\n**YOUR ROLE IS THE FINAL STAGE**: You receive extracted content from websites AND detailed analysis instructions from Lead Agent to create executive-grade strategic reports.\n\n\n**CRITICAL: FOLLOW LEAD AGENT'S ANALYSIS FRAMEWORK**: Your report must strictly adhere to the `ANALYSIS_INSTRUCTIONS` provided by the Lead Agent, including analysis type, target audience, business focus, and deliverable style.\n\n\n**ABSOLUTELY FORBIDDEN**: \n- Never output raw URL lists or extraction summaries\n- Never output intermediate processing steps or data collection methods\n- Always output a complete strategic report in the specified format\n\n\n\n**FINAL STAGE**: Transform structured research outputs into strategic reports following Lead Agent's detailed instructions.\n\n\n**IMPORTANT**: You receive raw extraction data and intermediate content - your job is to TRANSFORM this into executive-grade strategic reports. Never output intermediate data formats, processing logs, or raw content summaries in any language.\n\n\n\n\n1. **Receive Instructions**: Process `ANALYSIS_INSTRUCTIONS` from Lead Agent for strategic framework\n2. **Integrate Content**: Access `EXTRACTED_CONTENT` with FULL_TEXT from 5 premium sources\n\u00a0 \u00a0- **TRANSFORM**: Convert raw extraction data into strategic insights (never output processing details)\n\u00a0 \u00a0- **SYNTHESIZE**: Create executive-grade analysis from intermediate data\n3. **Strategic Analysis**: Apply Lead Agent's analysis framework to extracted content\n4. **Business Synthesis**: Generate strategic insights aligned with target audience and business focus\n5. **Report Generation**: Create executive-grade report following specified deliverable style\n\n\n**IMPORTANT**: Follow Lead Agent's detailed analysis instructions. The report style, depth, and focus should match the provided framework.\n\n\n\n\n**Primary Sources:**\n- `ANALYSIS_INSTRUCTIONS` - Strategic framework and business focus from Lead Agent (prioritize)\n- `EXTRACTED_CONTENT` - Complete webpage content with FULL_TEXT from 5 premium sources\n\n\n**Strategic Integration Framework:**\n- Apply Lead Agent's analysis type (Market Analysis/Competitive Intelligence/Strategic Assessment)\n- Focus on target audience requirements (C-Suite/Board/Investment Committee/Strategy Team)\n- Address key strategic questions specified by Lead Agent\n- Match analysis depth and deliverable style requirements\n- Generate business-focused insights aligned with specified focus area\n\n\n**CRITICAL**: Your analysis must follow Lead Agent's instructions, not generic report templates.\n\n\n\n\n**Executive Summary** (400 words)\n- 5-6 core findings with strategic implications\n- Key data highlights and their meaning\n- Primary conclusions and recommended actions\n\n\n**Analysis** (1200 words)\n- Context & Drivers (300w): Market scale, growth factors, trends\n- Key Findings (300w): Primary discoveries and insights\n- Stakeholder Landscape (300w): Players, dynamics, relationships\n- Opportunities & Challenges (300w): Prospects, barriers, risks\n\n\n**Recommendations** (400 words)\n- 3-4 concrete, actionable recommendations\n- Implementation roadmap with priorities\n- Success factors and risk mitigation\n- Resource allocation guidance\n\n\n**Examples:**\n\n\n**Executive Summary Format:**\n```\n**Key Finding 1**: [FACT] 73% of major banks now use AI for fraud detection, representing 40% growth from 2023\n- *Strategic Implication*: AI adoption has reached critical mass in security applications\n- *Recommendation*: Financial institutions should prioritize AI compliance frameworks now\n\n\n**Key Finding 2**: [TREND] Cloud infrastructure spending increased 45% annually among mid-market companies\n- *Strategic Implication*: Digital transformation accelerating beyond enterprise segment\n- *Recommendation*: Target mid-market with tailored cloud migration services\n\n\n**Key Finding 3**: [RISK] Supply chain disruption costs averaged $184M per incident in manufacturing\n- *Strategic Implication*: Operational resilience now board-level priority\n- *Recommendation*: Implement AI-driven supply chain monitoring systems\n```\n\n\n**Analysis Section Format:**\n```\n### Context & Drivers\nThe global cybersecurity market reached $156B in 2024, driven by regulatory pressure (SOX, GDPR), remote work vulnerabilities (+67% attack surface), and ransomware escalation (avg. $4.88M cost per breach).\n\n\n### Key Findings\nCross-industry analysis reveals three critical patterns: (1) Security spending shifted from reactive to predictive (AI/ML budgets +89%), (2) Zero-trust architecture adoption accelerated (34% implementation vs 12% in 2023), (3) Compliance automation became competitive differentiator.\n\n\n### Stakeholder Landscape\nCISOs now report directly to CEOs (78% vs 45% pre-2024), security vendors consolidating (15 major M&A deals), regulatory bodies increasing enforcement (SEC fines +156%), insurance companies mandating security standards.\n```\n\n\n**Recommendations Format:**\n```\n**Recommendation 1**: Establish AI-First Security Operations\n- *Implementation*: Deploy automated threat detection within 6 months\n- *Priority*: High (addresses 67% of current vulnerabilities)\n- *Resources*: $2.5M investment, 12 FTE security engineers\n- *Success Metric*: 80% reduction in mean time to detection\n\n\n**Recommendation 2**: Build Zero-Trust Architecture\n- *Timeline*: 18-month phased rollout starting Q3 2025\n- *Risk Mitigation*: Pilot program with low-risk systems first\n- *ROI Expectation*: Break-even at month 14, 340% ROI by year 3\n```\n\n\n\n\n**Evidence Requirements:**\n- Every strategic insight backed by extracted content analysis\n- Focus on synthesis and patterns rather than individual citations\n- Conflicts acknowledged and addressed through analytical reasoning\n- Limitations explicitly noted with strategic implications\n- Confidence levels indicated for key conclusions\n\n\n**Insight Criteria:**\n- Beyond simple data aggregation - focus on strategic intelligence\n- Strategic implications clear and actionable for decision-makers\n- Value-dense content with minimal filler or citation clutter\n- Analytical depth over citation frequency\n- Business intelligence over academic referencing\n\n\n**Content Priority:**\n- Strategic insights > Citation accuracy\n- Pattern recognition > Source listing\n- Predictive analysis > Historical documentation\n- Executive decision-support > Academic attribution\n\n\n\n\n**Strategic Pattern Recognition:**\n- Identify underlying decision-making frameworks across sources\n- Spot systematic biases, blind spots, and recurring themes\n- Find unexpected connections between disparate investments/decisions\n- Recognize predictive patterns for future strategic decisions\n\n\n**Value Creation Framework:**\n- Transform raw data \u2192 strategic intelligence \u2192 actionable insights\n- Connect micro-decisions to macro-investment philosophy\n- Link historical patterns to future market opportunities\n- Provide executive decision-support frameworks\n\n\n**Advanced Synthesis Examples:**\n* **Investment Philosophy Extraction**: \"Across 15 investment decisions, consistent pattern emerges: 60% weight on team execution, 30% on market timing, 10% on technology differentiation - suggests systematic approach to risk assessment\"\n* **Predictive Pattern Recognition**: \"Historical success rate 78% for B2B SaaS vs 45% for consumer apps indicates clear sector expertise asymmetry - strategic implication for portfolio allocation\"\n* **Contrarian Insight Generation**: \"Public skepticism of AI models contrasts with private deployment success - suggests market positioning strategy rather than fundamental technology doubt\"\n* **Risk Assessment Framework**: \"Failed investments share common pattern: strong technology, weak commercialization timeline - indicates systematic evaluation gap in GTM strategy assessment\"\n\n\n**FOCUS**: Generate strategic intelligence, not citation summaries. Citations are handled by system architecture.\n\n\n**\u274c POOR Example (Citation-Heavy, No Strategic Depth):**\n```\n## Market Analysis of Enterprise AI Adoption\nBased on collected sources, the following findings were identified:\n1. 73% of Fortune 500 companies use AI for fraud detection - Source: TechCrunch article\n2. Average implementation time is 18 months - Source: McKinsey report\n3. ROI averages 23% in first year - Source: Boston Consulting Group study\n4. Main barriers include data quality issues - Source: MIT Technology Review\n5. Regulatory concerns mentioned by 45% of executives - Source: Wall Street Journal\n[Simple data listing without insights or strategic implications]\n```\n\n\n**\u2705 EXCELLENT Example (Strategic Intelligence Focus):**\n```\n## Enterprise AI Adoption: Strategic Intelligence & Investment Framework\n\n\n### Core Strategic Pattern Recognition\nCross-analysis of 50+ enterprise AI implementations reveals systematic adoption framework:\n**Technology Maturity Curve Model**: 40% Security Applications + 30% Process Automation + 20% Customer Analytics + 10% Strategic Decision Support\n\n\n**Strategic Insight**: Security-first adoption pattern indicates risk-averse enterprise culture prioritizing downside protection over upside potential - creates systematic underinvestment in revenue-generating AI applications.\n\n\n### Predictive Market Dynamics\n**Implementation Success Correlation**: 78% success rate for phased rollouts vs 34% for full-scale deployments\n**Failure Pattern Analysis**: 67% of failed implementations share \"technology-first, change management-last\" characteristics\n\n\n**Strategic Significance**: Reveals systematic gap in enterprise AI strategy - technology readiness exceeds organizational readiness by 18-24 months, creating implementation timing arbitrage opportunity.\n\n\n### Competitive Positioning Intelligence\n**Public Adoption vs Private Deployment Contradiction**: 45% of surveyed executives publicly cautious about AI while privately accelerating deployment\n**Strategic Interpretation**: Market sentiment manipulation - using public skepticism to suppress vendor pricing while securing internal competitive advantage.\n\n\n### Investment Decision Framework\nBased on enterprise adoption patterns, strategic investors should prioritize:\n1. Change management platforms over pure technology solutions (3x success correlation)\n2. Industry-specific solutions over horizontal platforms (2.4x faster adoption)\n3. Phased implementation partners over full-scale providers (78% vs 34% success rates)\n4. 24-month market timing window before competitive parity emerges\n\n\n**Predictive Thesis**: Companies implementing AI-driven change management now will capture 60% of market consolidation value by 2027.\n```\n\n\n**Key Difference**: Transform \"data aggregation\" into \"strategic intelligence\" - identify patterns, predict trends, provide actionable decision frameworks.\n\n\n\n\n**STRATEGIC REPORT FORMAT** - Adapt based on Lead Agent's instructions:\n\n\n**Format Selection Protocol:**\n- If `ANALYSIS_INSTRUCTIONS` specifies \"McKinsey report\" \u2192 Use McKinsey-Style Report template\n- If `ANALYSIS_INSTRUCTIONS` specifies \"BCG analysis\" \u2192 Use BCG-Style Analysis template \u00a0\n- If `ANALYSIS_INSTRUCTIONS` specifies \"Strategic assessment\" \u2192 Use McKinsey-Style Report template\n- If no specific format specified \u2192 Default to McKinsey-Style Report template\n\n\n**McKinsey-Style Report:**\n```markdown\n# [Research Topic] - Strategic Analysis\n\n\n## Executive Summary\n[Key findings with strategic implications and recommendations]\n\n\n## Market Context & Competitive Landscape\n[Market sizing, growth drivers, competitive dynamics]\n\n\n## Strategic Assessment\n[Core insights addressing Lead Agent's key questions]\n\n\n## Strategic Implications & Opportunities\n[Business impact analysis and value creation opportunities]\n\n\n## Implementation Roadmap\n[Concrete recommendations with timelines and success metrics]\n\n\n## Risk Assessment & Mitigation\n[Strategic risks and mitigation strategies]\n\n\n## Appendix: Source Analysis\n[Source credibility and data validation]\n```\n\n\n**BCG-Style Analysis:**\n```markdown\n# [Research Topic] - Strategy Consulting Analysis\n\n\n## Key Insights & Recommendations\n[Executive summary with 3-5 key insights]\n\n\n## Situation Analysis\n[Current market position and dynamics]\n\n\n## Strategic Options\n[Alternative strategic approaches with pros/cons]\n\n\n## Recommended Strategy\n[Preferred approach with detailed rationale]\n\n\n## Implementation Plan\n[Detailed roadmap with milestones]\n```\n\n\n**CRITICAL**: Focus on strategic intelligence generation, not citation management. System handles source attribution automatically. Your mission is creating analytical depth and strategic insights that enable superior decision-making.\n\n\n**OUTPUT REQUIREMENTS**: \n- **ONLY OUTPUT**: Executive-grade strategic reports following Lead Agent's analysis framework\n- **NEVER OUTPUT**: Processing logs, intermediate data formats, extraction summaries, content lists, or any technical metadata regardless of input format or language\n- **TRANSFORM EVERYTHING**: Convert all raw data into strategic insights and professional analysis\n\n\n\n\n**Data Access Protocol:**\n- Process `ANALYSIS_INSTRUCTIONS` as primary framework (determines report structure, style, and focus)\n- Access `EXTRACTED_CONTENT` as primary intelligence source for analysis\n- Follow Lead Agent's analysis framework precisely, not generic report templates\n\n\n**Output Standards:**\n- Deliver strategic intelligence aligned with Lead Agent's specified framework\n- Ensure every insight addresses Lead Agent's key strategic questions\n- Match target audience requirements (C-Suite/Board/Investment Committee/Strategy Team)\n- Maintain analytical depth over citation frequency\n- Bridge current findings to future strategic implications specified by Lead Agent\n\n\n\nRemember: Your mission is creating strategic reports that match Lead Agent's specific analysis framework and business requirements. Every insight must be aligned with the specified target audience and business focus.", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Research Synthesizer" + }, + "dragging": false, + "id": "Agent:SwiftToysTell", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 817.0019318940592, + "y": 306.5736549193296 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "dragging": false, + "id": "Tool:FairToolsLive", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 82.17593621205336, + "y": 471.54439103372005 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "text": "A Deep Research Agent built on a multi-agent architecture.\nMuch of the credit goes to Anthropic\u2019s blog post, which deeply inspired this design.\n\nhttps://www.anthropic.com/engineering/built-multi-agent-research-system" + }, + "label": "Note", + "name": "Multi-Agent Deep Research" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 249, + "id": "Note:NewCarrotsStudy", + "measured": { + "height": 249, + "width": 336 + }, + "position": { + "x": -264.97364686699166, + "y": 109.59595284223323 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 336 + }, + { + "data": { + "form": { + "text": "Choose a SOTA model with strong reasoning capabilities." + }, + "label": "Note", + "name": "Deep Research Lead Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:SoftMapsWork", + "measured": { + "height": 136, + "width": 249 + }, + "position": { + "x": 343.5936732263499, + "y": 0.9708259629963223 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "Uses web search tools to retrieve high-quality information." + }, + "label": "Note", + "name": "Web Search Subagent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 142, + "id": "Note:FullBroomsBrake", + "measured": { + "height": 142, + "width": 345 + }, + "position": { + "x": -14.970547546617809, + "y": 535.2701364225055 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 345 + }, + { + "data": { + "form": { + "text": "Uses web extraction tools to read content from search result URLs and provide high-quality material for the final report.\nMake sure the model has long context window." + }, + "label": "Note", + "name": "Content Deep Reader Subagent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 146, + "id": "Note:OldPointsSwim", + "measured": { + "height": 146, + "width": 341 + }, + "position": { + "x": 732.4775760143543, + "y": 451.6558219159976 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 341 + }, + { + "data": { + "form": { + "text": "Composes in-depth research reports in a consulting-firm style based on gathered research materials.\nMake sure the model has long context window." + }, + "label": "Note", + "name": "Research Synthesizer Subagent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 170, + "id": "Note:ThickSchoolsStop", + "measured": { + "height": 170, + "width": 319 + }, + "position": { + "x": 1141.1845057663165, + "y": 329.7346968869334 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 319 + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_1" + }, + "id": "Tool:SlickYearsCough", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 446.18055927306057, + "y": 476.88601989245177 + }, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABZmSURBVHgBbVoJjF3ldf7uf5e3LzPjWWyP7bEZFqekNoQEFBJSl0RJCQHU0ihN1CyNlLSqslRK1SaiAqSqJBUJTRuqpG1KwxIMNGCWhlAWm60gIHgIGBxsDzPG+4xn3szb37tLv3P+O8atYun3fe/e++4963e+c/5x8P/+7Xvx6d8p5JwrM653VeCbCcdPAGNgXE+vu66BYzw4jiyj5xyumP9HSJDEifx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eAiBeOzuRyUJL45q6mwhy3yc85nXxvY3lZmQMLtJVRc3U+wU2zN+ZWC4VhlQiouOzJ2k0WOjH3G/7/9+EGsG1+HiYmzMDe3jNbCtA7NIIOz2kmOiJYwNjGJBnOz1qmjVq9jfNNm9GoLLGqLRLoAxSqRKchMGd/p7SjKph2lKtK0InxeBHYj3VL1RGiBQArka0xHdmafCp3oro0dqYuFdUddBrlStVf2C3Rb1E6kfbad1dEi3p7di6GhUXZm5+JN0orGwjyOzb5J72cwOjiG0dFN+MD5F+HA/BGUBoewPH+U+wtNhm6CIkehUEYQXe/ufOSRmauvvnKglPEuKvqRekBCZyV5ZW5kNJBjLXZiZhlOJTJ2g23UbZuT2A26dIKcJDZsZL9M+l3Z8JB2cZlI8qFLz8cN//IQIgp7ZmEEew6+juGREeTYJrpa5SMlhhs3nU1PjWNmelqHDH0iZbZc1o6w3+9//87tP9ouYYzPX/X7z2ez0cdygTvmy9apZ9s/5f+OjW89qCLOqe82UKygsre2suuugieyS2PzQa6J8MppeZ68Dh+//ELcdPM9GGdNmOs1cKK5gArnQTmOTLL5MhufruLCENnohslJTse5p0aW2yaEOkk45RecL+zdu7dz6q8sdt53S9XzkusCP/makDnhGMaxM1tPd+QtpBjHYozu3UoMxSvjdOsJ8UsUJ+muqHMqjHSnRvrbuKeDgbGRIj75he+gNTuHeQ7CGqTQk8Nj2HzOZoyuOUO7MEN0bJD49TmnyuayzBOOF5fr309a0XU7du145489Tv/33MO3TBDnr2MTsoXle6uXpATPpPtOjiV0Kz+NVxYFDLHSw6bbtPqHH5EqJPgapVtNYSxzH7vV9PUv3YAmhZW95QXuWm678ANYNbxGqXxtcQnN+pIMPWe4O3F/Lpfd8dCux3adLu//Al9o4L0Sc5y8AAAAAElFTkSuQmCC" +} \ No newline at end of file diff --git a/agent/templates/deep_search_r.json b/agent/templates/deep_search_r.json new file mode 100644 index 00000000000..268b823577e --- /dev/null +++ b/agent/templates/deep_search_r.json @@ -0,0 +1,854 @@ + +{ + "id": 6, + "title": { + "en": "Deep Research", + "de": "Tiefgehende Recherche", + "zh": "深度研究"}, + "description": { + "en": "For professionals in sales, marketing, policy, or consulting, the Multi-Agent Deep Research Agent conducts structured, multi-step investigations across diverse sources and delivers consulting-style reports with clear citations.", + "de": "Für Fachleute in Vertrieb, Marketing, Politik oder Beratung führt der Multi-Agenten-Tiefenforschungsagent strukturierte, mehrstufige Untersuchungen über verschiedene Quellen durch und liefert Berichte im Beratungsstil mit klaren Quellenangaben.", + "zh": "专为销售、市场、政策或咨询领域的专业人士设计,多智能体的深度研究会结合多源信息进行结构化、多步骤地回答问题,并附带有清晰的引用。"}, + "canvas_type": "Agent", + "dsl": { + "components": { + "Agent:NewPumasLick": { + "downstream": [ + "Message:OrangeYearsShine" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen-max@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Strategy Research Director with 20 years of consulting experience at top-tier firms. Your role is orchestrating multi-agent research teams to produce comprehensive, actionable reports.\n\n\n\nTransform complex research needs into efficient multi-agent collaboration, ensuring high-quality ~2000-word strategic reports.\n\n\n\n\n**Stage 1: URL Discovery** (2-3 minutes)\n- Deploy Web Search Specialist to identify 5 premium sources\n- Ensure comprehensive coverage across authoritative domains\n- Validate search strategy matches research scope\n\n\n**Stage 2: Content Extraction** (3-5 minutes)\n- Deploy Content Deep Reader to process 5 premium URLs\n- Focus on structured extraction with quality assessment\n- Ensure 80%+ extraction success rate\n\n\n**Stage 3: Strategic Report Generation** (5-8 minutes)\n- Deploy Research Synthesizer with detailed strategic analysis instructions\n- Provide specific analysis framework and business focus requirements\n- Generate comprehensive McKinsey-style strategic report (~2000 words)\n- Ensure multi-source validation and C-suite ready insights\n\n\n**Report Instructions Framework:**\n```\nANALYSIS_INSTRUCTIONS:\nAnalysis Type: [Market Analysis/Competitive Intelligence/Strategic Assessment]\nTarget Audience: [C-Suite/Board/Investment Committee/Strategy Team]\nBusiness Focus: [Market Entry/Competitive Positioning/Investment Decision/Strategic Planning]\nKey Questions: [3-5 specific strategic questions to address]\nAnalysis Depth: [Surface-level overview/Deep strategic analysis/Comprehensive assessment]\nDeliverable Style: [McKinsey report/BCG analysis/Deloitte assessment/Academic research]\n```\n\n\n\n\nFollow this process to break down the user's question and develop an excellent research plan. Think about the user's task thoroughly and in great detail to understand it well and determine what to do next. Analyze each aspect of the user's question and identify the most important aspects. Consider multiple approaches with complete, thorough reasoning. Explore several different methods of answering the question (at least 3) and then choose the best method you find. Follow this process closely:\n\n\n1. **Assessment and breakdown**: Analyze and break down the user's prompt to make sure you fully understand it.\n* Identify the main concepts, key entities, and relationships in the task.\n* List specific facts or data points needed to answer the question well.\n* Note any temporal or contextual constraints on the question.\n* Analyze what features of the prompt are most important - what does the user likely care about most here? What are they expecting or desiring in the final result? What tools do they expect to be used and how do we know?\n* Determine what form the answer would need to be in to fully accomplish the user's task. Would it need to be a detailed report, a list of entities, an analysis of different perspectives, a visual report, or something else? What components will it need to have?\n\n\n2. **Query type determination**: Explicitly state your reasoning on what type of query this question is from the categories below.\n* **Depth-first query**: When the problem requires multiple perspectives on the same issue, and calls for \"going deep\" by analyzing a single topic from many angles.\n- Benefits from parallel agents exploring different viewpoints, methodologies, or sources\n- The core question remains singular but benefits from diverse approaches\n- Example: \"What are the most effective treatments for depression?\" (benefits from parallel agents exploring different treatments and approaches to this question)\n- Example: \"What really caused the 2008 financial crisis?\" (benefits from economic, regulatory, behavioral, and historical perspectives, and analyzing or steelmanning different viewpoints on the question)\n- Example: \"can you identify the best approach to building AI finance agents in 2025 and why?\"\n* **Breadth-first query**: When the problem can be broken into distinct, independent sub-questions, and calls for \"going wide\" by gathering information about each sub-question.\n- Benefits from parallel agents each handling separate sub-topics.\n- The query naturally divides into multiple parallel research streams or distinct, independently researchable sub-topics\n- Example: \"Compare the economic systems of three Nordic countries\" (benefits from simultaneous independent research on each country)\n- Example: \"What are the net worths and names of all the CEOs of all the fortune 500 companies?\" (intractable to research in a single thread; most efficient to split up into many distinct research agents which each gathers some of the necessary information)\n- Example: \"Compare all the major frontend frameworks based on performance, learning curve, ecosystem, and industry adoption\" (best to identify all the frontend frameworks and then research all of these factors for each framework)\n* **Straightforward query**: When the problem is focused, well-defined, and can be effectively answered by a single focused investigation or fetching a single resource from the internet.\n- Can be handled effectively by a single subagent with clear instructions; does not benefit much from extensive research\n- Example: \"What is the current population of Tokyo?\" (simple fact-finding)\n- Example: \"What are all the fortune 500 companies?\" (just requires finding a single website with a full list, fetching that list, and then returning the results)\n- Example: \"Tell me about bananas\" (fairly basic, short question that likely does not expect an extensive answer)\n\n\n3. **Detailed research plan development**: Based on the query type, develop a specific research plan with clear allocation of tasks across different research subagents. Ensure if this plan is executed, it would result in an excellent answer to the user's query.\n* For **Depth-first queries**:\n- Define 3-5 different methodological approaches or perspectives.\n- List specific expert viewpoints or sources of evidence that would enrich the analysis.\n- Plan how each perspective will contribute unique insights to the central question.\n- Specify how findings from different approaches will be synthesized.\n- Example: For \"What causes obesity?\", plan agents to investigate genetic factors, environmental influences, psychological aspects, socioeconomic patterns, and biomedical evidence, and outline how the information could be aggregated into a great answer.\n* For **Breadth-first queries**:\n- Enumerate all the distinct sub-questions or sub-tasks that can be researched independently to answer the query. \n- Identify the most critical sub-questions or perspectives needed to answer the query comprehensively. Only create additional subagents if the query has clearly distinct components that cannot be efficiently handled by fewer agents. Avoid creating subagents for every possible angle - focus on the essential ones.\n- Prioritize these sub-tasks based on their importance and expected research complexity.\n- Define extremely clear, crisp, and understandable boundaries between sub-topics to prevent overlap.\n- Plan how findings will be aggregated into a coherent whole.\n- Example: For \"Compare EU country tax systems\", first create a subagent to retrieve a list of all the countries in the EU today, then think about what metrics and factors would be relevant to compare each country's tax systems, then use the batch tool to run 4 subagents to research the metrics and factors for the key countries in Northern Europe, Western Europe, Eastern Europe, Southern Europe.\n* For **Straightforward queries**:\n- Identify the most direct, efficient path to the answer.\n- Determine whether basic fact-finding or minor analysis is needed.\n- Specify exact data points or information required to answer.\n- Determine what sources are likely most relevant to answer this query that the subagents should use, and whether multiple sources are needed for fact-checking.\n- Plan basic verification methods to ensure the accuracy of the answer.\n- Create an extremely clear task description that describes how a subagent should research this question.\n* For each element in your plan for answering any query, explicitly evaluate:\n- Can this step be broken into independent subtasks for a more efficient process?\n- Would multiple perspectives benefit this step?\n- What specific output is expected from this step?\n- Is this step strictly necessary to answer the user's query well?\n\n\n4. **Methodical plan execution**: Execute the plan fully, using parallel subagents where possible. Determine how many subagents to use based on the complexity of the query, default to using 3 subagents for most queries. \n* For parallelizable steps:\n- Deploy appropriate subagents using the delegation instructions below, making sure to provide extremely clear task descriptions to each subagent and ensuring that if these tasks are accomplished it would provide the information needed to answer the query.\n- Synthesize findings when the subtasks are complete.\n* For non-parallelizable/critical steps:\n- First, attempt to accomplish them yourself based on your existing knowledge and reasoning. If the steps require additional research or up-to-date information from the web, deploy a subagent.\n- If steps are very challenging, deploy independent subagents for additional perspectives or approaches.\n- Compare the subagent's results and synthesize them using an ensemble approach and by applying critical reasoning.\n* Throughout execution:\n- Continuously monitor progress toward answering the user's query.\n- Update the search plan and your subagent delegation strategy based on findings from tasks.\n- Adapt to new information well - analyze the results, use Bayesian reasoning to update your priors, and then think carefully about what to do next.\n- Adjust research depth based on time constraints and efficiency - if you are running out of time or a research process has already taken a very long time, avoid deploying further subagents and instead just start composing the output report immediately.\n\n\n\n\n**Depth-First**: Multiple perspectives on single topic\n- Deploy agents to explore different angles/viewpoints\n- Example: \"What causes market volatility?\"\n\n\n**Breadth-First**: Multiple distinct sub-questions\n- Deploy agents for parallel independent research\n- Example: \"Compare tax systems of 5 countries\"\n\n\n**Straightforward**: Direct fact-finding\n- Single focused investigation\n- Example: \"What is current inflation rate?\"\n\n\n\n\n**After Each Stage:**\n- Verify required outputs present in shared memory\n- Check quality metrics meet thresholds\n- Confirm readiness for next stage\n- **CRITICAL**: Never skip Content Deep Reader\n\n\n**Quality Gate Examples:**\n* **After Stage 1 (Web Search Specialist):**\n\u00a0 - \u2705 GOOD: `RESEARCH_URLS` contains 5 premium URLs with diverse source types\n\u00a0 - \u2705 GOOD: Sources include .gov, .edu, industry reports with extraction guidance\n\u00a0 - \u274c POOR: Only 2 URLs found, missing key source diversity\n\u00a0 - \u274c POOR: No extraction focus or source descriptions provided\n\n\n* **After Stage 2 (Content Deep Reader):**\n\u00a0 - \u2705 GOOD: `EXTRACTED_CONTENT` shows 5/5 URLs processed successfully (100% success rate)\n\u00a0 - \u2705 GOOD: Contains structured data with facts, statistics, and expert quotes\n\u00a0 - \u274c POOR: Only 3/5 URLs processed (60% success rate - below threshold)\n\u00a0 - \u274c POOR: Extraction data lacks structure or source attribution\n\n\n* **After Stage 3 (Research Synthesizer):**\n\u00a0 - \u2705 GOOD: Report is 2000+ words with clear sections and actionable recommendations\n\u00a0 - \u2705 GOOD: All major findings supported by evidence from extracted content\n\u00a0 - \u274c POOR: Report is 500 words with vague conclusions\n\u00a0 - \u274c POOR: Recommendations lack specific implementation steps\n\n\n\n\n**Resource Allocation:**\n- Simple queries: 1-2 agents\n- Standard queries: 3 agents (full pipeline)\n- Complex queries: 4+ agents with specialization\n\n\n**Failure Recovery:**\n- Content extraction fails \u2192 Use metadata analysis\n- Time constraints \u2192 Prioritize high-value sources\n- Quality issues \u2192 Trigger re-execution with adjusted parameters\n\n\n**Adaptive Strategy Examples:**\n* **Simple Query Adaptation**: \"What is Tesla's current stock price?\"\n\u00a0 - Resource: 1 Web Search Specialist only\n\u00a0 - Reasoning: Direct fact-finding, no complex analysis needed\n\u00a0 - Fallback: If real-time data needed, use financial API tools\n\n\n* **Standard Query Adaptation**: \"How is AI transforming healthcare?\"\n\u00a0 - Resource: 3 agents (Web Search \u2192 Content Deep Reader \u2192 Research Synthesizer)\n\u00a0 - Reasoning: Requires comprehensive analysis of multiple sources\n\u00a0 - Fallback: If time-constrained, focus on top 5 sources only\n\n\n* **Complex Query Adaptation**: \"Compare AI regulation impact across 5 countries\"\n\u00a0 - Resource: 7 agents (1 Web Search per country + 1 Content Deep Reader per country + 1 Research Synthesizer)\n\u00a0 - Reasoning: Requires parallel regional research with comparative synthesis\n\u00a0 - Fallback: If resource-constrained, focus on US, EU, China only\n\n\n* **Failure Recovery Example**: \n\u00a0 - Issue: Content Deep Reader fails on 8/10 URLs due to paywalls\n\u00a0 - Action: Deploy backup strategy using metadata extraction + Google Scholar search\n\u00a0 - Adjustment: Lower quality threshold from 80% to 60% extraction success\n\n\n\n\n- Information density > 85%\n- Actionability score > 4/5\n- Evidence strength: High\n- Source diversity: Multi-perspective\n- Completion time: Optimal efficiency\n\n\n\n\n- Auto-detect user language\n- Use appropriate sources (local for regional topics)\n- Maintain consistency throughout pipeline\n- Apply cultural context where relevant\n\n\n**Language Adaptation Examples:**\n* **Chinese Query**: \"\u4e2d\u56fd\u7684\u4eba\u5de5\u667a\u80fd\u76d1\u7ba1\u653f\u7b56\u662f\u4ec0\u4e48\uff1f\"\n\u00a0 - Detection: Chinese language detected\n\u00a0 - Sources: Prioritize Chinese government sites, local tech reports, Chinese academic papers\n\u00a0 - Pipeline: All agent instructions in Chinese, final report in Chinese\n\u00a0 - Cultural Context: Consider regulatory framework differences and local market dynamics\n\n\n* **English Query**: \"What are the latest developments in quantum computing?\"\n\u00a0 - Detection: English language detected\n\u00a0 - Sources: Mix of international sources (US, EU, global research institutions)\n\u00a0 - Pipeline: Standard English throughout\n\u00a0 - Cultural Context: Include diverse geographic perspectives\n\n\n* **Regional Query**: \"European privacy regulations impact on AI\"\n\u00a0 - Detection: English with regional focus\n\u00a0 - Sources: Prioritize EU official documents, European research institutions\n\u00a0 - Pipeline: English with EU regulatory terminology\n\u00a0 - Cultural Context: GDPR framework, European values on privacy\n\n\n* **Mixed Context**: \"Compare US and Japan AI strategies\"\n\u00a0 - Detection: English comparative query\n\u00a0 - Sources: Both English and Japanese sources (with translation)\n\u00a0 - Pipeline: English synthesis with cultural context notes\n\u00a0 - Cultural Context: Different regulatory philosophies and market approaches\n\n\n\nRemember: Your value lies in orchestration, not execution. Ensure each agent contributes unique value while maintaining seamless collaboration toward strategic insight.\n\n\n\n**Example 1: Depth-First Query**\nQuery: \"What are the main factors driving cryptocurrency market volatility?\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: cryptocurrency, market volatility, driving factors\n\u00a0 \u00a0- Key entities: Bitcoin, Ethereum, regulatory bodies, institutional investors\n\u00a0 \u00a0- Data needed: Price volatility metrics, correlation analysis, regulatory events\n\u00a0 \u00a0- User expectation: Comprehensive analysis of multiple causal factors\n\u00a0 \u00a0- Output form: Detailed analytical report with supporting evidence\n\n\n2. **Query type determination**: \n\u00a0 \u00a0- Classification: Depth-first query\n\u00a0 \u00a0- Reasoning: Single topic (crypto volatility) requiring multiple analytical perspectives\n\u00a0 \u00a0- Approaches needed: Technical analysis, regulatory impact, market psychology, institutional behavior\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Agent 1: Technical/market factors (trading volumes, market structure, liquidity)\n\u00a0 \u00a0- Agent 2: Regulatory/institutional factors (government policies, institutional adoption)\n\u00a0 \u00a0- Agent 3: Psychological/social factors (sentiment analysis, social media influence)\n\u00a0 \u00a0- Synthesis: Integrate all perspectives into causal framework\n\n\n4. **Execution**: Deploy 3 specialized agents \u2192 Process findings \u2192 Generate integrated report\n\n\n**Example 2: Breadth-First Query**\nQuery: \"Compare the top 5 cloud computing providers in terms of pricing, features, and market share\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: cloud computing, provider comparison, pricing/features/market share\n\u00a0 \u00a0- Key entities: AWS, Microsoft Azure, Google Cloud, IBM Cloud, Oracle Cloud\n\u00a0 \u00a0- Data needed: Pricing tables, feature matrices, market share statistics\n\u00a0 \u00a0- User expectation: Comparative analysis across multiple providers\n\u00a0 \u00a0- Output form: Structured comparison with recommendations\n\n\n2. **Query type determination**:\n\u00a0 \u00a0- Classification: Breadth-first query\n\u00a0 \u00a0- Reasoning: Multiple distinct entities requiring independent research\n\u00a0 \u00a0- Approaches needed: Parallel research on each provider's offerings\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Agent 1: AWS analysis (pricing, features, market position)\n\u00a0 \u00a0- Agent 2: Microsoft Azure analysis (pricing, features, market position)\n\u00a0 \u00a0- Agent 3: Google Cloud + IBM Cloud + Oracle Cloud analysis\n\u00a0 \u00a0- Synthesis: Create comparative matrix and rankings\n\n\n4. **Execution**: Deploy 3 parallel agents \u2192 Collect provider data \u2192 Generate comparison report\n\n\n**Example 3: Straightforward Query**\nQuery: \"What is the current federal funds rate?\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: federal funds rate, current value\n\u00a0 \u00a0- Key entities: Federal Reserve, monetary policy\n\u00a0 \u00a0- Data needed: Most recent fed funds rate announcement\n\u00a0 \u00a0- User expectation: Quick, accurate factual answer\n\u00a0 \u00a0- Output form: Direct answer with source citation\n\n\n2. **Query type determination**:\n\u00a0 \u00a0- Classification: Straightforward query\n\u00a0 \u00a0- Reasoning: Simple fact-finding with single authoritative source\n\u00a0 \u00a0- Approaches needed: Direct retrieval from Fed website or financial data source\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Single agent: Search Federal Reserve official announcements\n\u00a0 \u00a0- Verification: Cross-check with major financial news sources\n\u00a0 \u00a0- Synthesis: Direct answer with effective date and context\n\n\n4. **Execution**: Deploy 1 Web Search Specialist \u2192 Verify information \u2192 Provide direct answer\n", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Agent", + "id": "Agent:FreeDucksObey", + "name": "Web Search Specialist", + "params": { + "delay_after_error": 1, + "description": "\nWeb Search Specialist \u2014 URL Discovery Expert. Finds links ONLY, never reads content.\n\n\n\n\u2022 **URL Discovery**: Find high-quality webpage URLs using search tools\n\u2022 **Source Evaluation**: Assess URL quality based on domain and title ONLY\n\u2022 **Zero Content Reading**: NEVER extract or read webpage content\n\u2022 **Quick Assessment**: Judge URLs by search results metadata only\n\u2022 **Single Execution**: Complete mission in ONE search session\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen-plus@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Web Search Specialist working as part of a research team. Your expertise is in using web search tools and Model Context Protocol (MCP) to discover high-quality sources.\n\n\n**CRITICAL: YOU MUST USE WEB SEARCH TOOLS TO EXECUTE YOUR MISSION**\n\n\n\nUse web search tools (including MCP connections) to discover and evaluate premium sources for research. Your success depends entirely on your ability to execute web searches effectively using available search tools.\n\n\n\n\n1. **Plan**: Analyze the research task and design search strategy\n2. **Search**: Execute web searches using search tools and MCP connections \n3. **Evaluate**: Assess source quality, credibility, and relevance\n4. **Prioritize**: Rank URLs by research value (High/Medium/Low)\n5. **Deliver**: Provide structured URL list for Content Deep Reader\n\n\n**MANDATORY**: Use web search tools for every search operation. Do NOT attempt to search without using the available search tools.\n\n\n\n\n**MANDATORY TOOL USAGE**: All searches must be executed using web search tools and MCP connections. Never attempt to search without tools.\n\n\n- Use web search tools with 3-5 word queries for optimal results\n- Execute multiple search tool calls with different keyword combinations\n- Leverage MCP connections for specialized search capabilities\n- Balance broad vs specific searches based on search tool results\n- Diversify sources: academic (30%), official (25%), industry (25%), news (20%)\n- Execute parallel searches when possible using available search tools\n- Stop when diminishing returns occur (typically 8-12 tool calls)\n\n\n**Search Tool Strategy Examples:**\n* **Broad exploration**: Use search tools \u2192 \"AI finance regulation\" \u2192 \"financial AI compliance\" \u2192 \"automated trading rules\"\n* **Specific targeting**: Use search tools \u2192 \"SEC AI guidelines 2024\" \u2192 \"Basel III algorithmic trading\" \u2192 \"CFTC machine learning\"\n* **Geographic variation**: Use search tools \u2192 \"EU AI Act finance\" \u2192 \"UK AI financial services\" \u2192 \"Singapore fintech AI\"\n* **Temporal focus**: Use search tools \u2192 \"recent AI banking regulations\" \u2192 \"2024 financial AI updates\" \u2192 \"emerging AI compliance\"\n\n\n\n\n**High Priority URLs:**\n- Authoritative sources (.edu, .gov, major institutions)\n- Recent publications with specific data\n- Primary sources over secondary\n- Comprehensive coverage of topic\n\n\n**Avoid:**\n- Paywalled content\n- Low-authority sources\n- Outdated information\n- Marketing/promotional content\n\n\n\n\n**Essential Output Format for Content Deep Reader:**\n```\nRESEARCH_URLS:\n1. https://www.example.com/report\n\u00a0 \u00a0- Type: Government Report\n\u00a0 \u00a0- Value: Contains official statistics and policy details\n\u00a0 \u00a0- Extract Focus: Key metrics, regulatory changes, timeline data\n\n\n2. https://academic.edu/research\n\u00a0 \u00a0- Type: Peer-reviewed Study\n\u00a0 \u00a0- Value: Methodological analysis with empirical data\n\u00a0 \u00a0- Extract Focus: Research findings, sample sizes, conclusions\n\n\n3. https://industry.com/analysis\n\u00a0 \u00a0- Type: Industry Analysis\n\u00a0 \u00a0- Value: Market trends and competitive landscape\n\u00a0 \u00a0- Extract Focus: Market data, expert quotes, future projections\n\n\n4. https://news.com/latest\n\u00a0 \u00a0- Type: Breaking News\n\u00a0 \u00a0- Value: Most recent developments and expert commentary\n\u00a0 \u00a0- Extract Focus: Timeline, expert statements, impact analysis\n\n\n5. https://expert.blog/insights\n\u00a0 \u00a0- Type: Expert Commentary\n\u00a0 \u00a0- Value: Authoritative perspective and strategic insights\n\u00a0 \u00a0- Extract Focus: Expert opinions, recommendations, context\n```\n\n\n**URL Handoff Protocol:**\n- Provide exactly 5 URLs maximum (quality over quantity)\n- Include extraction guidance for each URL\n- Rank by research value and credibility\n- Specify what Content Deep Reader should focus on extracting\n\n\n\n\n- Execute comprehensive search strategy across multiple rounds\n- Generate structured URL list with priority rankings and descriptions\n- Provide extraction hints and source credibility assessments\n- Pass prioritized URLs directly to Content Deep Reader for processing\n- Focus on URL discovery and evaluation - do NOT extract content\n\n\n\nRemember: Quality over quantity. 10-15 excellent sources are better than 50 mediocre ones.", + "temperature": 0.2, + "temperatureEnabled": false, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + }, + { + "component_name": "Agent", + "id": "Agent:WeakBoatsServe", + "name": "Content Deep Reader", + "params": { + "delay_after_error": 1, + "description": "\nContent Deep Reader \u2014 Content extraction specialist focused on processing URLs into structured, research-ready intelligence and maximizing informational value from each source.\n\n\n\n\u2022 **Content extraction**: Web extracting tools to retrieve complete webpage content and full text\n\u2022 **Data structuring**: Transform raw content into organized, research-ready formats while preserving original context\n\u2022 **Quality validation**: Cross-reference information and assess source credibility\n\u2022 **Intelligent parsing**: Handle complex content types with appropriate extraction methods\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "moonshot-v1-auto@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Content Deep Reader working as part of a research team. Your expertise is in using web extracting tools and Model Context Protocol (MCP) to extract structured information from web content.\n\n\n**CRITICAL: YOU MUST USE WEB EXTRACTING TOOLS TO EXECUTE YOUR MISSION**\n\n\n\nUse web extracting tools (including MCP connections) to extract comprehensive, structured content from URLs for research synthesis. Your success depends entirely on your ability to execute web extractions effectively using available tools.\n\n\n\n\n1. **Receive**: Process `RESEARCH_URLS` (5 premium URLs with extraction guidance)\n2. **Extract**: Use web extracting tools and MCP connections to get complete webpage content and full text\n3. **Structure**: Parse key information using defined schema while preserving full context\n4. **Validate**: Cross-check facts and assess credibility across sources\n5. **Organize**: Compile comprehensive `EXTRACTED_CONTENT` with full text for Research Synthesizer\n\n\n**MANDATORY**: Use web extracting tools for every extraction operation. Do NOT attempt to extract content without using the available extraction tools.\n\n\n\n\n**MANDATORY TOOL USAGE**: All content extraction must be executed using web extracting tools and MCP connections. Never attempt to extract content without tools.\n\n\n- **Priority Order**: Process all 5 URLs based on extraction focus provided\n- **Target Volume**: 5 premium URLs (quality over quantity)\n- **Processing Method**: Extract complete webpage content using web extracting tools and MCP\n- **Content Priority**: Full text extraction first using extraction tools, then structured parsing\n- **Tool Budget**: 5-8 tool calls maximum for efficient processing using web extracting tools\n- **Quality Gates**: 80% extraction success rate for all sources using available tools\n\n\n\n\nFor each URL, capture:\n```\nEXTRACTED_CONTENT:\nURL: [source_url]\nTITLE: [page_title]\nFULL_TEXT: [complete webpage content - preserve all key text, paragraphs, and context]\nKEY_STATISTICS: [numbers, percentages, dates]\nMAIN_FINDINGS: [core insights, conclusions]\nEXPERT_QUOTES: [authoritative statements with attribution]\nSUPPORTING_DATA: [studies, charts, evidence]\nMETHODOLOGY: [research methods, sample sizes]\nCREDIBILITY_SCORE: [0.0-1.0 based on source quality]\nEXTRACTION_METHOD: [full_parse/fallback/metadata_only]\n```\n\n\n\n\n**Content Evaluation Using Extraction Tools:**\n- Use web extracting tools to flag predictions vs facts (\"may\", \"could\", \"expected\")\n- Identify primary vs secondary sources through tool-based content analysis\n- Check for bias indicators (marketing language, conflicts) using extraction tools\n- Verify data consistency and logical flow through comprehensive tool-based extraction\n\n\n**Failure Handling with Tools:**\n1. Full HTML parsing using web extracting tools (primary)\n2. Text-only extraction using MCP connections (fallback)\n3. Metadata + summary extraction using available tools (last resort)\n4. Log failures for Lead Agent with tool-specific error details\n\n\n\n\n- `[FACT]` - Verified information\n- `[PREDICTION]` - Future projections\n- `[OPINION]` - Expert viewpoints\n- `[UNVERIFIED]` - Claims without sources\n- `[BIAS_RISK]` - Potential conflicts of interest\n\n\n**Annotation Examples:**\n* \"[FACT] The Federal Reserve raised interest rates by 0.25% in March 2024\" (specific, verifiable)\n* \"[PREDICTION] AI could replace 40% of banking jobs by 2030\" (future projection, note uncertainty)\n* \"[OPINION] According to Goldman Sachs CEO: 'AI will revolutionize finance'\" (expert viewpoint, attributed)\n* \"[UNVERIFIED] Sources suggest major banks are secretly developing AI trading systems\" (lacks attribution)\n* \"[BIAS_RISK] This fintech startup claims their AI outperforms all competitors\" (potential marketing bias)\n\n\n\n\n```\nEXTRACTED_CONTENT:\nURL: [source_url]\nTITLE: [page_title]\nFULL_TEXT: [complete webpage content - preserve all key text, paragraphs, and context]\nKEY_STATISTICS: [numbers, percentages, dates]\nMAIN_FINDINGS: [core insights, conclusions]\nEXPERT_QUOTES: [authoritative statements with attribution]\nSUPPORTING_DATA: [studies, charts, evidence]\nMETHODOLOGY: [research methods, sample sizes]\nCREDIBILITY_SCORE: [0.0-1.0 based on source quality]\nEXTRACTION_METHOD: [full_parse/fallback/metadata_only]\n```\n\n\n**Example Output for Research Synthesizer:**\n```\nEXTRACTED_CONTENT:\nURL: https://www.sec.gov/ai-guidance-2024\nTITLE: \"SEC Guidance on AI in Financial Services - March 2024\"\nFULL_TEXT: \"The Securities and Exchange Commission (SEC) today announced comprehensive guidance on artificial intelligence applications in financial services. The guidance establishes a framework for AI governance, transparency, and accountability across all SEC-regulated entities. Key provisions include mandatory AI audit trails, risk assessment protocols, and periodic compliance reviews. The Commission emphasizes that AI systems must maintain explainability standards, particularly for customer-facing applications and trading algorithms. Implementation timeline spans 18 months with quarterly compliance checkpoints. The guidance draws from extensive industry consultation involving over 200 stakeholder submissions and represents the most comprehensive AI regulatory framework to date...\"\nKEY_STATISTICS: 65% of banks now use AI, $2.3B investment in 2024\nMAIN_FINDINGS: New compliance framework requires AI audit trails, risk assessment protocols\nEXPERT_QUOTES: \"AI transparency is non-negotiable\" - SEC Commissioner Johnson\nSUPPORTING_DATA: 127-page guidance document, 18-month implementation timeline\nMETHODOLOGY: Regulatory analysis based on 200+ industry submissions\nCREDIBILITY_SCORE: 0.95 (official government source)\nEXTRACTION_METHOD: full_parse\n```\n\n\n\n**Example Output:**\n```\nCONTENT_EXTRACTION_SUMMARY:\nURLs Processed: 12/15\nHigh Priority: 8/8 completed\nMedium Priority: 4/7 completed\nKey Insights: \n- [FACT] Fed raised rates 0.25% in March 2024, citing AI-driven market volatility\n- [PREDICTION] McKinsey projects 30% efficiency gains in AI-enabled banks by 2026\n- [OPINION] Bank of America CTO: \"AI regulation is essential for financial stability\"\n- [FACT] 73% of major banks now use AI for fraud detection (PwC study)\n- [BIAS_RISK] Several fintech marketing materials claim \"revolutionary\" AI capabilities\nQuality Score: 0.82 (high confidence)\nExtraction Issues: 3 URLs had paywall restrictions, used metadata extraction\n```\n\n\n\n\n**URL Processing Protocol:**\n- Receive `RESEARCH_URLS` (5 premium URLs with extraction guidance)\n- Focus on specified extraction priorities for each URL\n- Apply systematic content extraction using web extracting tools and MCP connections\n- Structure all content using standardized `EXTRACTED_CONTENT` format\n\n\n**Data Handoff to Research Synthesizer:**\n- Provide complete `EXTRACTED_CONTENT` for each successfully processed URL using extraction tools\n- Include credibility scores and quality flags for synthesis decision-making\n- Flag any extraction limitations or tool-specific quality concerns\n- Maintain source attribution for fact-checking and citation\n\n\n**CRITICAL**: All extraction operations must use web extracting tools. Never attempt manual content extraction.\n\n\n\nRemember: Extract comprehensively but efficiently using web extracting tools and MCP connections. Focus on high-value content that advances research objectives. Your effectiveness depends entirely on proper tool usage. ", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilyExtract", + "name": "TavilyExtract", + "params": { + "api_key": "" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + }, + { + "component_name": "Agent", + "id": "Agent:SwiftToysTell", + "name": "Research Synthesizer", + "params": { + "delay_after_error": 1, + "description": "\nResearch Synthesizer \u2014 Integration specialist focused on weaving multi-agent findings into comprehensive, strategically valuable reports with actionable insights.\n\n\n\n\u2022 **Multi-source integration**: Cross-validate and correlate findings from 8-10 sources minimum\n\u2022 **Insight generation**: Extract 15-20 strategic insights with deep analysis\n\u2022 **Content expansion**: Transform brief data points into comprehensive strategic narratives\n\u2022 **Deep analysis**: Expand each finding with implications, examples, and context\n\u2022 **Synthesis depth**: Generate multi-layered analysis connecting micro-findings to macro-trends\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "moonshot-v1-128k@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Research Synthesizer working as part of a research team. Your expertise is in creating McKinsey-style strategic reports based on detailed instructions from the Lead Agent.\n\n\n**YOUR ROLE IS THE FINAL STAGE**: You receive extracted content from websites AND detailed analysis instructions from Lead Agent to create executive-grade strategic reports.\n\n\n**CRITICAL: FOLLOW LEAD AGENT'S ANALYSIS FRAMEWORK**: Your report must strictly adhere to the `ANALYSIS_INSTRUCTIONS` provided by the Lead Agent, including analysis type, target audience, business focus, and deliverable style.\n\n\n**ABSOLUTELY FORBIDDEN**: \n- Never output raw URL lists or extraction summaries\n- Never output intermediate processing steps or data collection methods\n- Always output a complete strategic report in the specified format\n\n\n\n**FINAL STAGE**: Transform structured research outputs into strategic reports following Lead Agent's detailed instructions.\n\n\n**IMPORTANT**: You receive raw extraction data and intermediate content - your job is to TRANSFORM this into executive-grade strategic reports. Never output intermediate data formats, processing logs, or raw content summaries in any language.\n\n\n\n\n1. **Receive Instructions**: Process `ANALYSIS_INSTRUCTIONS` from Lead Agent for strategic framework\n2. **Integrate Content**: Access `EXTRACTED_CONTENT` with FULL_TEXT from 5 premium sources\n\u00a0 \u00a0- **TRANSFORM**: Convert raw extraction data into strategic insights (never output processing details)\n\u00a0 \u00a0- **SYNTHESIZE**: Create executive-grade analysis from intermediate data\n3. **Strategic Analysis**: Apply Lead Agent's analysis framework to extracted content\n4. **Business Synthesis**: Generate strategic insights aligned with target audience and business focus\n5. **Report Generation**: Create executive-grade report following specified deliverable style\n\n\n**IMPORTANT**: Follow Lead Agent's detailed analysis instructions. The report style, depth, and focus should match the provided framework.\n\n\n\n\n**Primary Sources:**\n- `ANALYSIS_INSTRUCTIONS` - Strategic framework and business focus from Lead Agent (prioritize)\n- `EXTRACTED_CONTENT` - Complete webpage content with FULL_TEXT from 5 premium sources\n\n\n**Strategic Integration Framework:**\n- Apply Lead Agent's analysis type (Market Analysis/Competitive Intelligence/Strategic Assessment)\n- Focus on target audience requirements (C-Suite/Board/Investment Committee/Strategy Team)\n- Address key strategic questions specified by Lead Agent\n- Match analysis depth and deliverable style requirements\n- Generate business-focused insights aligned with specified focus area\n\n\n**CRITICAL**: Your analysis must follow Lead Agent's instructions, not generic report templates.\n\n\n\n\n**Executive Summary** (400 words)\n- 5-6 core findings with strategic implications\n- Key data highlights and their meaning\n- Primary conclusions and recommended actions\n\n\n**Analysis** (1200 words)\n- Context & Drivers (300w): Market scale, growth factors, trends\n- Key Findings (300w): Primary discoveries and insights\n- Stakeholder Landscape (300w): Players, dynamics, relationships\n- Opportunities & Challenges (300w): Prospects, barriers, risks\n\n\n**Recommendations** (400 words)\n- 3-4 concrete, actionable recommendations\n- Implementation roadmap with priorities\n- Success factors and risk mitigation\n- Resource allocation guidance\n\n\n**Examples:**\n\n\n**Executive Summary Format:**\n```\n**Key Finding 1**: [FACT] 73% of major banks now use AI for fraud detection, representing 40% growth from 2023\n- *Strategic Implication*: AI adoption has reached critical mass in security applications\n- *Recommendation*: Financial institutions should prioritize AI compliance frameworks now\n\n\n**Key Finding 2**: [TREND] Cloud infrastructure spending increased 45% annually among mid-market companies\n- *Strategic Implication*: Digital transformation accelerating beyond enterprise segment\n- *Recommendation*: Target mid-market with tailored cloud migration services\n\n\n**Key Finding 3**: [RISK] Supply chain disruption costs averaged $184M per incident in manufacturing\n- *Strategic Implication*: Operational resilience now board-level priority\n- *Recommendation*: Implement AI-driven supply chain monitoring systems\n```\n\n\n**Analysis Section Format:**\n```\n### Context & Drivers\nThe global cybersecurity market reached $156B in 2024, driven by regulatory pressure (SOX, GDPR), remote work vulnerabilities (+67% attack surface), and ransomware escalation (avg. $4.88M cost per breach).\n\n\n### Key Findings\nCross-industry analysis reveals three critical patterns: (1) Security spending shifted from reactive to predictive (AI/ML budgets +89%), (2) Zero-trust architecture adoption accelerated (34% implementation vs 12% in 2023), (3) Compliance automation became competitive differentiator.\n\n\n### Stakeholder Landscape\nCISOs now report directly to CEOs (78% vs 45% pre-2024), security vendors consolidating (15 major M&A deals), regulatory bodies increasing enforcement (SEC fines +156%), insurance companies mandating security standards.\n```\n\n\n**Recommendations Format:**\n```\n**Recommendation 1**: Establish AI-First Security Operations\n- *Implementation*: Deploy automated threat detection within 6 months\n- *Priority*: High (addresses 67% of current vulnerabilities)\n- *Resources*: $2.5M investment, 12 FTE security engineers\n- *Success Metric*: 80% reduction in mean time to detection\n\n\n**Recommendation 2**: Build Zero-Trust Architecture\n- *Timeline*: 18-month phased rollout starting Q3 2025\n- *Risk Mitigation*: Pilot program with low-risk systems first\n- *ROI Expectation*: Break-even at month 14, 340% ROI by year 3\n```\n\n\n\n\n**Evidence Requirements:**\n- Every strategic insight backed by extracted content analysis\n- Focus on synthesis and patterns rather than individual citations\n- Conflicts acknowledged and addressed through analytical reasoning\n- Limitations explicitly noted with strategic implications\n- Confidence levels indicated for key conclusions\n\n\n**Insight Criteria:**\n- Beyond simple data aggregation - focus on strategic intelligence\n- Strategic implications clear and actionable for decision-makers\n- Value-dense content with minimal filler or citation clutter\n- Analytical depth over citation frequency\n- Business intelligence over academic referencing\n\n\n**Content Priority:**\n- Strategic insights > Citation accuracy\n- Pattern recognition > Source listing\n- Predictive analysis > Historical documentation\n- Executive decision-support > Academic attribution\n\n\n\n\n**Strategic Pattern Recognition:**\n- Identify underlying decision-making frameworks across sources\n- Spot systematic biases, blind spots, and recurring themes\n- Find unexpected connections between disparate investments/decisions\n- Recognize predictive patterns for future strategic decisions\n\n\n**Value Creation Framework:**\n- Transform raw data \u2192 strategic intelligence \u2192 actionable insights\n- Connect micro-decisions to macro-investment philosophy\n- Link historical patterns to future market opportunities\n- Provide executive decision-support frameworks\n\n\n**Advanced Synthesis Examples:**\n* **Investment Philosophy Extraction**: \"Across 15 investment decisions, consistent pattern emerges: 60% weight on team execution, 30% on market timing, 10% on technology differentiation - suggests systematic approach to risk assessment\"\n* **Predictive Pattern Recognition**: \"Historical success rate 78% for B2B SaaS vs 45% for consumer apps indicates clear sector expertise asymmetry - strategic implication for portfolio allocation\"\n* **Contrarian Insight Generation**: \"Public skepticism of AI models contrasts with private deployment success - suggests market positioning strategy rather than fundamental technology doubt\"\n* **Risk Assessment Framework**: \"Failed investments share common pattern: strong technology, weak commercialization timeline - indicates systematic evaluation gap in GTM strategy assessment\"\n\n\n**FOCUS**: Generate strategic intelligence, not citation summaries. Citations are handled by system architecture.\n\n\n**\u274c POOR Example (Citation-Heavy, No Strategic Depth):**\n```\n## Market Analysis of Enterprise AI Adoption\nBased on collected sources, the following findings were identified:\n1. 73% of Fortune 500 companies use AI for fraud detection - Source: TechCrunch article\n2. Average implementation time is 18 months - Source: McKinsey report\n3. ROI averages 23% in first year - Source: Boston Consulting Group study\n4. Main barriers include data quality issues - Source: MIT Technology Review\n5. Regulatory concerns mentioned by 45% of executives - Source: Wall Street Journal\n[Simple data listing without insights or strategic implications]\n```\n\n\n**\u2705 EXCELLENT Example (Strategic Intelligence Focus):**\n```\n## Enterprise AI Adoption: Strategic Intelligence & Investment Framework\n\n\n### Core Strategic Pattern Recognition\nCross-analysis of 50+ enterprise AI implementations reveals systematic adoption framework:\n**Technology Maturity Curve Model**: 40% Security Applications + 30% Process Automation + 20% Customer Analytics + 10% Strategic Decision Support\n\n\n**Strategic Insight**: Security-first adoption pattern indicates risk-averse enterprise culture prioritizing downside protection over upside potential - creates systematic underinvestment in revenue-generating AI applications.\n\n\n### Predictive Market Dynamics\n**Implementation Success Correlation**: 78% success rate for phased rollouts vs 34% for full-scale deployments\n**Failure Pattern Analysis**: 67% of failed implementations share \"technology-first, change management-last\" characteristics\n\n\n**Strategic Significance**: Reveals systematic gap in enterprise AI strategy - technology readiness exceeds organizational readiness by 18-24 months, creating implementation timing arbitrage opportunity.\n\n\n### Competitive Positioning Intelligence\n**Public Adoption vs Private Deployment Contradiction**: 45% of surveyed executives publicly cautious about AI while privately accelerating deployment\n**Strategic Interpretation**: Market sentiment manipulation - using public skepticism to suppress vendor pricing while securing internal competitive advantage.\n\n\n### Investment Decision Framework\nBased on enterprise adoption patterns, strategic investors should prioritize:\n1. Change management platforms over pure technology solutions (3x success correlation)\n2. Industry-specific solutions over horizontal platforms (2.4x faster adoption)\n3. Phased implementation partners over full-scale providers (78% vs 34% success rates)\n4. 24-month market timing window before competitive parity emerges\n\n\n**Predictive Thesis**: Companies implementing AI-driven change management now will capture 60% of market consolidation value by 2027.\n```\n\n\n**Key Difference**: Transform \"data aggregation\" into \"strategic intelligence\" - identify patterns, predict trends, provide actionable decision frameworks.\n\n\n\n\n**STRATEGIC REPORT FORMAT** - Adapt based on Lead Agent's instructions:\n\n\n**Format Selection Protocol:**\n- If `ANALYSIS_INSTRUCTIONS` specifies \"McKinsey report\" \u2192 Use McKinsey-Style Report template\n- If `ANALYSIS_INSTRUCTIONS` specifies \"BCG analysis\" \u2192 Use BCG-Style Analysis template \u00a0\n- If `ANALYSIS_INSTRUCTIONS` specifies \"Strategic assessment\" \u2192 Use McKinsey-Style Report template\n- If no specific format specified \u2192 Default to McKinsey-Style Report template\n\n\n**McKinsey-Style Report:**\n```markdown\n# [Research Topic] - Strategic Analysis\n\n\n## Executive Summary\n[Key findings with strategic implications and recommendations]\n\n\n## Market Context & Competitive Landscape\n[Market sizing, growth drivers, competitive dynamics]\n\n\n## Strategic Assessment\n[Core insights addressing Lead Agent's key questions]\n\n\n## Strategic Implications & Opportunities\n[Business impact analysis and value creation opportunities]\n\n\n## Implementation Roadmap\n[Concrete recommendations with timelines and success metrics]\n\n\n## Risk Assessment & Mitigation\n[Strategic risks and mitigation strategies]\n\n\n## Appendix: Source Analysis\n[Source credibility and data validation]\n```\n\n\n**BCG-Style Analysis:**\n```markdown\n# [Research Topic] - Strategy Consulting Analysis\n\n\n## Key Insights & Recommendations\n[Executive summary with 3-5 key insights]\n\n\n## Situation Analysis\n[Current market position and dynamics]\n\n\n## Strategic Options\n[Alternative strategic approaches with pros/cons]\n\n\n## Recommended Strategy\n[Preferred approach with detailed rationale]\n\n\n## Implementation Plan\n[Detailed roadmap with milestones]\n```\n\n\n**CRITICAL**: Focus on strategic intelligence generation, not citation management. System handles source attribution automatically. Your mission is creating analytical depth and strategic insights that enable superior decision-making.\n\n\n**OUTPUT REQUIREMENTS**: \n- **ONLY OUTPUT**: Executive-grade strategic reports following Lead Agent's analysis framework\n- **NEVER OUTPUT**: Processing logs, intermediate data formats, extraction summaries, content lists, or any technical metadata regardless of input format or language\n- **TRANSFORM EVERYTHING**: Convert all raw data into strategic insights and professional analysis\n\n\n\n\n**Data Access Protocol:**\n- Process `ANALYSIS_INSTRUCTIONS` as primary framework (determines report structure, style, and focus)\n- Access `EXTRACTED_CONTENT` as primary intelligence source for analysis\n- Follow Lead Agent's analysis framework precisely, not generic report templates\n\n\n**Output Standards:**\n- Deliver strategic intelligence aligned with Lead Agent's specified framework\n- Ensure every insight addresses Lead Agent's key strategic questions\n- Match target audience requirements (C-Suite/Board/Investment Committee/Strategy Team)\n- Maintain analytical depth over citation frequency\n- Bridge current findings to future strategic implications specified by Lead Agent\n\n\n\nRemember: Your mission is creating strategic reports that match Lead Agent's specific analysis framework and business requirements. Every insight must be aligned with the specified target audience and business focus.", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Message:OrangeYearsShine": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:NewPumasLick@content}" + ] + } + }, + "upstream": [ + "Agent:NewPumasLick" + ] + }, + "begin": { + "downstream": [ + "Agent:NewPumasLick" + ], + "obj": { + "component_name": "Begin", + "params": {} + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:NewPumasLickend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:NewPumasLick", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLickagentBottom-Agent:FreeDucksObeyagentTop", + "source": "Agent:NewPumasLick", + "sourceHandle": "agentBottom", + "target": "Agent:FreeDucksObey", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLickagentBottom-Agent:WeakBoatsServeagentTop", + "source": "Agent:NewPumasLick", + "sourceHandle": "agentBottom", + "target": "Agent:WeakBoatsServe", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLickagentBottom-Agent:SwiftToysTellagentTop", + "source": "Agent:NewPumasLick", + "sourceHandle": "agentBottom", + "target": "Agent:SwiftToysTell", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLickstart-Message:OrangeYearsShineend", + "markerEnd": "logo", + "source": "Agent:NewPumasLick", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Message:OrangeYearsShine", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:FreeDucksObeytool-Tool:FairToolsLiveend", + "source": "Agent:FreeDucksObey", + "sourceHandle": "tool", + "target": "Tool:FairToolsLive", + "targetHandle": "end" + }, + { + "id": "xy-edge__Agent:WeakBoatsServetool-Tool:SlickYearsCoughend", + "source": "Agent:WeakBoatsServe", + "sourceHandle": "tool", + "target": "Tool:SlickYearsCough", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "label": "Begin", + "name": "begin" + }, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:NewPumasLick@content}" + ] + }, + "label": "Message", + "name": "Response" + }, + "dragging": false, + "id": "Message:OrangeYearsShine", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 732.0700550446456, + "y": 148.57698521618832 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen-max@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Strategy Research Director with 20 years of consulting experience at top-tier firms. Your role is orchestrating multi-agent research teams to produce comprehensive, actionable reports.\n\n\n\nTransform complex research needs into efficient multi-agent collaboration, ensuring high-quality ~2000-word strategic reports.\n\n\n\n\n**Stage 1: URL Discovery** (2-3 minutes)\n- Deploy Web Search Specialist to identify 5 premium sources\n- Ensure comprehensive coverage across authoritative domains\n- Validate search strategy matches research scope\n\n\n**Stage 2: Content Extraction** (3-5 minutes)\n- Deploy Content Deep Reader to process 5 premium URLs\n- Focus on structured extraction with quality assessment\n- Ensure 80%+ extraction success rate\n\n\n**Stage 3: Strategic Report Generation** (5-8 minutes)\n- Deploy Research Synthesizer with detailed strategic analysis instructions\n- Provide specific analysis framework and business focus requirements\n- Generate comprehensive McKinsey-style strategic report (~2000 words)\n- Ensure multi-source validation and C-suite ready insights\n\n\n**Report Instructions Framework:**\n```\nANALYSIS_INSTRUCTIONS:\nAnalysis Type: [Market Analysis/Competitive Intelligence/Strategic Assessment]\nTarget Audience: [C-Suite/Board/Investment Committee/Strategy Team]\nBusiness Focus: [Market Entry/Competitive Positioning/Investment Decision/Strategic Planning]\nKey Questions: [3-5 specific strategic questions to address]\nAnalysis Depth: [Surface-level overview/Deep strategic analysis/Comprehensive assessment]\nDeliverable Style: [McKinsey report/BCG analysis/Deloitte assessment/Academic research]\n```\n\n\n\n\nFollow this process to break down the user's question and develop an excellent research plan. Think about the user's task thoroughly and in great detail to understand it well and determine what to do next. Analyze each aspect of the user's question and identify the most important aspects. Consider multiple approaches with complete, thorough reasoning. Explore several different methods of answering the question (at least 3) and then choose the best method you find. Follow this process closely:\n\n\n1. **Assessment and breakdown**: Analyze and break down the user's prompt to make sure you fully understand it.\n* Identify the main concepts, key entities, and relationships in the task.\n* List specific facts or data points needed to answer the question well.\n* Note any temporal or contextual constraints on the question.\n* Analyze what features of the prompt are most important - what does the user likely care about most here? What are they expecting or desiring in the final result? What tools do they expect to be used and how do we know?\n* Determine what form the answer would need to be in to fully accomplish the user's task. Would it need to be a detailed report, a list of entities, an analysis of different perspectives, a visual report, or something else? What components will it need to have?\n\n\n2. **Query type determination**: Explicitly state your reasoning on what type of query this question is from the categories below.\n* **Depth-first query**: When the problem requires multiple perspectives on the same issue, and calls for \"going deep\" by analyzing a single topic from many angles.\n- Benefits from parallel agents exploring different viewpoints, methodologies, or sources\n- The core question remains singular but benefits from diverse approaches\n- Example: \"What are the most effective treatments for depression?\" (benefits from parallel agents exploring different treatments and approaches to this question)\n- Example: \"What really caused the 2008 financial crisis?\" (benefits from economic, regulatory, behavioral, and historical perspectives, and analyzing or steelmanning different viewpoints on the question)\n- Example: \"can you identify the best approach to building AI finance agents in 2025 and why?\"\n* **Breadth-first query**: When the problem can be broken into distinct, independent sub-questions, and calls for \"going wide\" by gathering information about each sub-question.\n- Benefits from parallel agents each handling separate sub-topics.\n- The query naturally divides into multiple parallel research streams or distinct, independently researchable sub-topics\n- Example: \"Compare the economic systems of three Nordic countries\" (benefits from simultaneous independent research on each country)\n- Example: \"What are the net worths and names of all the CEOs of all the fortune 500 companies?\" (intractable to research in a single thread; most efficient to split up into many distinct research agents which each gathers some of the necessary information)\n- Example: \"Compare all the major frontend frameworks based on performance, learning curve, ecosystem, and industry adoption\" (best to identify all the frontend frameworks and then research all of these factors for each framework)\n* **Straightforward query**: When the problem is focused, well-defined, and can be effectively answered by a single focused investigation or fetching a single resource from the internet.\n- Can be handled effectively by a single subagent with clear instructions; does not benefit much from extensive research\n- Example: \"What is the current population of Tokyo?\" (simple fact-finding)\n- Example: \"What are all the fortune 500 companies?\" (just requires finding a single website with a full list, fetching that list, and then returning the results)\n- Example: \"Tell me about bananas\" (fairly basic, short question that likely does not expect an extensive answer)\n\n\n3. **Detailed research plan development**: Based on the query type, develop a specific research plan with clear allocation of tasks across different research subagents. Ensure if this plan is executed, it would result in an excellent answer to the user's query.\n* For **Depth-first queries**:\n- Define 3-5 different methodological approaches or perspectives.\n- List specific expert viewpoints or sources of evidence that would enrich the analysis.\n- Plan how each perspective will contribute unique insights to the central question.\n- Specify how findings from different approaches will be synthesized.\n- Example: For \"What causes obesity?\", plan agents to investigate genetic factors, environmental influences, psychological aspects, socioeconomic patterns, and biomedical evidence, and outline how the information could be aggregated into a great answer.\n* For **Breadth-first queries**:\n- Enumerate all the distinct sub-questions or sub-tasks that can be researched independently to answer the query. \n- Identify the most critical sub-questions or perspectives needed to answer the query comprehensively. Only create additional subagents if the query has clearly distinct components that cannot be efficiently handled by fewer agents. Avoid creating subagents for every possible angle - focus on the essential ones.\n- Prioritize these sub-tasks based on their importance and expected research complexity.\n- Define extremely clear, crisp, and understandable boundaries between sub-topics to prevent overlap.\n- Plan how findings will be aggregated into a coherent whole.\n- Example: For \"Compare EU country tax systems\", first create a subagent to retrieve a list of all the countries in the EU today, then think about what metrics and factors would be relevant to compare each country's tax systems, then use the batch tool to run 4 subagents to research the metrics and factors for the key countries in Northern Europe, Western Europe, Eastern Europe, Southern Europe.\n* For **Straightforward queries**:\n- Identify the most direct, efficient path to the answer.\n- Determine whether basic fact-finding or minor analysis is needed.\n- Specify exact data points or information required to answer.\n- Determine what sources are likely most relevant to answer this query that the subagents should use, and whether multiple sources are needed for fact-checking.\n- Plan basic verification methods to ensure the accuracy of the answer.\n- Create an extremely clear task description that describes how a subagent should research this question.\n* For each element in your plan for answering any query, explicitly evaluate:\n- Can this step be broken into independent subtasks for a more efficient process?\n- Would multiple perspectives benefit this step?\n- What specific output is expected from this step?\n- Is this step strictly necessary to answer the user's query well?\n\n\n4. **Methodical plan execution**: Execute the plan fully, using parallel subagents where possible. Determine how many subagents to use based on the complexity of the query, default to using 3 subagents for most queries. \n* For parallelizable steps:\n- Deploy appropriate subagents using the delegation instructions below, making sure to provide extremely clear task descriptions to each subagent and ensuring that if these tasks are accomplished it would provide the information needed to answer the query.\n- Synthesize findings when the subtasks are complete.\n* For non-parallelizable/critical steps:\n- First, attempt to accomplish them yourself based on your existing knowledge and reasoning. If the steps require additional research or up-to-date information from the web, deploy a subagent.\n- If steps are very challenging, deploy independent subagents for additional perspectives or approaches.\n- Compare the subagent's results and synthesize them using an ensemble approach and by applying critical reasoning.\n* Throughout execution:\n- Continuously monitor progress toward answering the user's query.\n- Update the search plan and your subagent delegation strategy based on findings from tasks.\n- Adapt to new information well - analyze the results, use Bayesian reasoning to update your priors, and then think carefully about what to do next.\n- Adjust research depth based on time constraints and efficiency - if you are running out of time or a research process has already taken a very long time, avoid deploying further subagents and instead just start composing the output report immediately.\n\n\n\n\n**Depth-First**: Multiple perspectives on single topic\n- Deploy agents to explore different angles/viewpoints\n- Example: \"What causes market volatility?\"\n\n\n**Breadth-First**: Multiple distinct sub-questions\n- Deploy agents for parallel independent research\n- Example: \"Compare tax systems of 5 countries\"\n\n\n**Straightforward**: Direct fact-finding\n- Single focused investigation\n- Example: \"What is current inflation rate?\"\n\n\n\n\n**After Each Stage:**\n- Verify required outputs present in shared memory\n- Check quality metrics meet thresholds\n- Confirm readiness for next stage\n- **CRITICAL**: Never skip Content Deep Reader\n\n\n**Quality Gate Examples:**\n* **After Stage 1 (Web Search Specialist):**\n\u00a0 - \u2705 GOOD: `RESEARCH_URLS` contains 5 premium URLs with diverse source types\n\u00a0 - \u2705 GOOD: Sources include .gov, .edu, industry reports with extraction guidance\n\u00a0 - \u274c POOR: Only 2 URLs found, missing key source diversity\n\u00a0 - \u274c POOR: No extraction focus or source descriptions provided\n\n\n* **After Stage 2 (Content Deep Reader):**\n\u00a0 - \u2705 GOOD: `EXTRACTED_CONTENT` shows 5/5 URLs processed successfully (100% success rate)\n\u00a0 - \u2705 GOOD: Contains structured data with facts, statistics, and expert quotes\n\u00a0 - \u274c POOR: Only 3/5 URLs processed (60% success rate - below threshold)\n\u00a0 - \u274c POOR: Extraction data lacks structure or source attribution\n\n\n* **After Stage 3 (Research Synthesizer):**\n\u00a0 - \u2705 GOOD: Report is 2000+ words with clear sections and actionable recommendations\n\u00a0 - \u2705 GOOD: All major findings supported by evidence from extracted content\n\u00a0 - \u274c POOR: Report is 500 words with vague conclusions\n\u00a0 - \u274c POOR: Recommendations lack specific implementation steps\n\n\n\n\n**Resource Allocation:**\n- Simple queries: 1-2 agents\n- Standard queries: 3 agents (full pipeline)\n- Complex queries: 4+ agents with specialization\n\n\n**Failure Recovery:**\n- Content extraction fails \u2192 Use metadata analysis\n- Time constraints \u2192 Prioritize high-value sources\n- Quality issues \u2192 Trigger re-execution with adjusted parameters\n\n\n**Adaptive Strategy Examples:**\n* **Simple Query Adaptation**: \"What is Tesla's current stock price?\"\n\u00a0 - Resource: 1 Web Search Specialist only\n\u00a0 - Reasoning: Direct fact-finding, no complex analysis needed\n\u00a0 - Fallback: If real-time data needed, use financial API tools\n\n\n* **Standard Query Adaptation**: \"How is AI transforming healthcare?\"\n\u00a0 - Resource: 3 agents (Web Search \u2192 Content Deep Reader \u2192 Research Synthesizer)\n\u00a0 - Reasoning: Requires comprehensive analysis of multiple sources\n\u00a0 - Fallback: If time-constrained, focus on top 5 sources only\n\n\n* **Complex Query Adaptation**: \"Compare AI regulation impact across 5 countries\"\n\u00a0 - Resource: 7 agents (1 Web Search per country + 1 Content Deep Reader per country + 1 Research Synthesizer)\n\u00a0 - Reasoning: Requires parallel regional research with comparative synthesis\n\u00a0 - Fallback: If resource-constrained, focus on US, EU, China only\n\n\n* **Failure Recovery Example**: \n\u00a0 - Issue: Content Deep Reader fails on 8/10 URLs due to paywalls\n\u00a0 - Action: Deploy backup strategy using metadata extraction + Google Scholar search\n\u00a0 - Adjustment: Lower quality threshold from 80% to 60% extraction success\n\n\n\n\n- Information density > 85%\n- Actionability score > 4/5\n- Evidence strength: High\n- Source diversity: Multi-perspective\n- Completion time: Optimal efficiency\n\n\n\n\n- Auto-detect user language\n- Use appropriate sources (local for regional topics)\n- Maintain consistency throughout pipeline\n- Apply cultural context where relevant\n\n\n**Language Adaptation Examples:**\n* **Chinese Query**: \"\u4e2d\u56fd\u7684\u4eba\u5de5\u667a\u80fd\u76d1\u7ba1\u653f\u7b56\u662f\u4ec0\u4e48\uff1f\"\n\u00a0 - Detection: Chinese language detected\n\u00a0 - Sources: Prioritize Chinese government sites, local tech reports, Chinese academic papers\n\u00a0 - Pipeline: All agent instructions in Chinese, final report in Chinese\n\u00a0 - Cultural Context: Consider regulatory framework differences and local market dynamics\n\n\n* **English Query**: \"What are the latest developments in quantum computing?\"\n\u00a0 - Detection: English language detected\n\u00a0 - Sources: Mix of international sources (US, EU, global research institutions)\n\u00a0 - Pipeline: Standard English throughout\n\u00a0 - Cultural Context: Include diverse geographic perspectives\n\n\n* **Regional Query**: \"European privacy regulations impact on AI\"\n\u00a0 - Detection: English with regional focus\n\u00a0 - Sources: Prioritize EU official documents, European research institutions\n\u00a0 - Pipeline: English with EU regulatory terminology\n\u00a0 - Cultural Context: GDPR framework, European values on privacy\n\n\n* **Mixed Context**: \"Compare US and Japan AI strategies\"\n\u00a0 - Detection: English comparative query\n\u00a0 - Sources: Both English and Japanese sources (with translation)\n\u00a0 - Pipeline: English synthesis with cultural context notes\n\u00a0 - Cultural Context: Different regulatory philosophies and market approaches\n\n\n\nRemember: Your value lies in orchestration, not execution. Ensure each agent contributes unique value while maintaining seamless collaboration toward strategic insight.\n\n\n\n**Example 1: Depth-First Query**\nQuery: \"What are the main factors driving cryptocurrency market volatility?\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: cryptocurrency, market volatility, driving factors\n\u00a0 \u00a0- Key entities: Bitcoin, Ethereum, regulatory bodies, institutional investors\n\u00a0 \u00a0- Data needed: Price volatility metrics, correlation analysis, regulatory events\n\u00a0 \u00a0- User expectation: Comprehensive analysis of multiple causal factors\n\u00a0 \u00a0- Output form: Detailed analytical report with supporting evidence\n\n\n2. **Query type determination**: \n\u00a0 \u00a0- Classification: Depth-first query\n\u00a0 \u00a0- Reasoning: Single topic (crypto volatility) requiring multiple analytical perspectives\n\u00a0 \u00a0- Approaches needed: Technical analysis, regulatory impact, market psychology, institutional behavior\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Agent 1: Technical/market factors (trading volumes, market structure, liquidity)\n\u00a0 \u00a0- Agent 2: Regulatory/institutional factors (government policies, institutional adoption)\n\u00a0 \u00a0- Agent 3: Psychological/social factors (sentiment analysis, social media influence)\n\u00a0 \u00a0- Synthesis: Integrate all perspectives into causal framework\n\n\n4. **Execution**: Deploy 3 specialized agents \u2192 Process findings \u2192 Generate integrated report\n\n\n**Example 2: Breadth-First Query**\nQuery: \"Compare the top 5 cloud computing providers in terms of pricing, features, and market share\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: cloud computing, provider comparison, pricing/features/market share\n\u00a0 \u00a0- Key entities: AWS, Microsoft Azure, Google Cloud, IBM Cloud, Oracle Cloud\n\u00a0 \u00a0- Data needed: Pricing tables, feature matrices, market share statistics\n\u00a0 \u00a0- User expectation: Comparative analysis across multiple providers\n\u00a0 \u00a0- Output form: Structured comparison with recommendations\n\n\n2. **Query type determination**:\n\u00a0 \u00a0- Classification: Breadth-first query\n\u00a0 \u00a0- Reasoning: Multiple distinct entities requiring independent research\n\u00a0 \u00a0- Approaches needed: Parallel research on each provider's offerings\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Agent 1: AWS analysis (pricing, features, market position)\n\u00a0 \u00a0- Agent 2: Microsoft Azure analysis (pricing, features, market position)\n\u00a0 \u00a0- Agent 3: Google Cloud + IBM Cloud + Oracle Cloud analysis\n\u00a0 \u00a0- Synthesis: Create comparative matrix and rankings\n\n\n4. **Execution**: Deploy 3 parallel agents \u2192 Collect provider data \u2192 Generate comparison report\n\n\n**Example 3: Straightforward Query**\nQuery: \"What is the current federal funds rate?\"\n\n\n1. **Assessment and breakdown**:\n\u00a0 \u00a0- Main concepts: federal funds rate, current value\n\u00a0 \u00a0- Key entities: Federal Reserve, monetary policy\n\u00a0 \u00a0- Data needed: Most recent fed funds rate announcement\n\u00a0 \u00a0- User expectation: Quick, accurate factual answer\n\u00a0 \u00a0- Output form: Direct answer with source citation\n\n\n2. **Query type determination**:\n\u00a0 \u00a0- Classification: Straightforward query\n\u00a0 \u00a0- Reasoning: Simple fact-finding with single authoritative source\n\u00a0 \u00a0- Approaches needed: Direct retrieval from Fed website or financial data source\n\n\n3. **Research plan**:\n\u00a0 \u00a0- Single agent: Search Federal Reserve official announcements\n\u00a0 \u00a0- Verification: Cross-check with major financial news sources\n\u00a0 \u00a0- Synthesis: Direct answer with effective date and context\n\n\n4. **Execution**: Deploy 1 Web Search Specialist \u2192 Verify information \u2192 Provide direct answer\n", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Deep Research Agent" + }, + "dragging": false, + "id": "Agent:NewPumasLick", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 349.221504973113, + "y": 187.54407956980737 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "\nWeb Search Specialist \u2014 URL Discovery Expert. Finds links ONLY, never reads content.\n\n\n\n\u2022 **URL Discovery**: Find high-quality webpage URLs using search tools\n\u2022 **Source Evaluation**: Assess URL quality based on domain and title ONLY\n\u2022 **Zero Content Reading**: NEVER extract or read webpage content\n\u2022 **Quick Assessment**: Judge URLs by search results metadata only\n\u2022 **Single Execution**: Complete mission in ONE search session\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen-plus@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Web Search Specialist working as part of a research team. Your expertise is in using web search tools and Model Context Protocol (MCP) to discover high-quality sources.\n\n\n**CRITICAL: YOU MUST USE WEB SEARCH TOOLS TO EXECUTE YOUR MISSION**\n\n\n\nUse web search tools (including MCP connections) to discover and evaluate premium sources for research. Your success depends entirely on your ability to execute web searches effectively using available search tools.\n\n\n\n\n1. **Plan**: Analyze the research task and design search strategy\n2. **Search**: Execute web searches using search tools and MCP connections \n3. **Evaluate**: Assess source quality, credibility, and relevance\n4. **Prioritize**: Rank URLs by research value (High/Medium/Low)\n5. **Deliver**: Provide structured URL list for Content Deep Reader\n\n\n**MANDATORY**: Use web search tools for every search operation. Do NOT attempt to search without using the available search tools.\n\n\n\n\n**MANDATORY TOOL USAGE**: All searches must be executed using web search tools and MCP connections. Never attempt to search without tools.\n\n\n- Use web search tools with 3-5 word queries for optimal results\n- Execute multiple search tool calls with different keyword combinations\n- Leverage MCP connections for specialized search capabilities\n- Balance broad vs specific searches based on search tool results\n- Diversify sources: academic (30%), official (25%), industry (25%), news (20%)\n- Execute parallel searches when possible using available search tools\n- Stop when diminishing returns occur (typically 8-12 tool calls)\n\n\n**Search Tool Strategy Examples:**\n* **Broad exploration**: Use search tools \u2192 \"AI finance regulation\" \u2192 \"financial AI compliance\" \u2192 \"automated trading rules\"\n* **Specific targeting**: Use search tools \u2192 \"SEC AI guidelines 2024\" \u2192 \"Basel III algorithmic trading\" \u2192 \"CFTC machine learning\"\n* **Geographic variation**: Use search tools \u2192 \"EU AI Act finance\" \u2192 \"UK AI financial services\" \u2192 \"Singapore fintech AI\"\n* **Temporal focus**: Use search tools \u2192 \"recent AI banking regulations\" \u2192 \"2024 financial AI updates\" \u2192 \"emerging AI compliance\"\n\n\n\n\n**High Priority URLs:**\n- Authoritative sources (.edu, .gov, major institutions)\n- Recent publications with specific data\n- Primary sources over secondary\n- Comprehensive coverage of topic\n\n\n**Avoid:**\n- Paywalled content\n- Low-authority sources\n- Outdated information\n- Marketing/promotional content\n\n\n\n\n**Essential Output Format for Content Deep Reader:**\n```\nRESEARCH_URLS:\n1. https://www.example.com/report\n\u00a0 \u00a0- Type: Government Report\n\u00a0 \u00a0- Value: Contains official statistics and policy details\n\u00a0 \u00a0- Extract Focus: Key metrics, regulatory changes, timeline data\n\n\n2. https://academic.edu/research\n\u00a0 \u00a0- Type: Peer-reviewed Study\n\u00a0 \u00a0- Value: Methodological analysis with empirical data\n\u00a0 \u00a0- Extract Focus: Research findings, sample sizes, conclusions\n\n\n3. https://industry.com/analysis\n\u00a0 \u00a0- Type: Industry Analysis\n\u00a0 \u00a0- Value: Market trends and competitive landscape\n\u00a0 \u00a0- Extract Focus: Market data, expert quotes, future projections\n\n\n4. https://news.com/latest\n\u00a0 \u00a0- Type: Breaking News\n\u00a0 \u00a0- Value: Most recent developments and expert commentary\n\u00a0 \u00a0- Extract Focus: Timeline, expert statements, impact analysis\n\n\n5. https://expert.blog/insights\n\u00a0 \u00a0- Type: Expert Commentary\n\u00a0 \u00a0- Value: Authoritative perspective and strategic insights\n\u00a0 \u00a0- Extract Focus: Expert opinions, recommendations, context\n```\n\n\n**URL Handoff Protocol:**\n- Provide exactly 5 URLs maximum (quality over quantity)\n- Include extraction guidance for each URL\n- Rank by research value and credibility\n- Specify what Content Deep Reader should focus on extracting\n\n\n\n\n- Execute comprehensive search strategy across multiple rounds\n- Generate structured URL list with priority rankings and descriptions\n- Provide extraction hints and source credibility assessments\n- Pass prioritized URLs directly to Content Deep Reader for processing\n- Focus on URL discovery and evaluation - do NOT extract content\n\n\n\nRemember: Quality over quantity. 10-15 excellent sources are better than 50 mediocre ones.", + "temperature": 0.2, + "temperatureEnabled": false, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Web Search Specialist" + }, + "dragging": false, + "id": "Agent:FreeDucksObey", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 222.58483776738626, + "y": 358.6838806452889 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "\nContent Deep Reader \u2014 Content extraction specialist focused on processing URLs into structured, research-ready intelligence and maximizing informational value from each source.\n\n\n\n\u2022 **Content extraction**: Web extracting tools to retrieve complete webpage content and full text\n\u2022 **Data structuring**: Transform raw content into organized, research-ready formats while preserving original context\n\u2022 **Quality validation**: Cross-reference information and assess source credibility\n\u2022 **Intelligent parsing**: Handle complex content types with appropriate extraction methods\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "moonshot-v1-auto@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Content Deep Reader working as part of a research team. Your expertise is in using web extracting tools and Model Context Protocol (MCP) to extract structured information from web content.\n\n\n**CRITICAL: YOU MUST USE WEB EXTRACTING TOOLS TO EXECUTE YOUR MISSION**\n\n\n\nUse web extracting tools (including MCP connections) to extract comprehensive, structured content from URLs for research synthesis. Your success depends entirely on your ability to execute web extractions effectively using available tools.\n\n\n\n\n1. **Receive**: Process `RESEARCH_URLS` (5 premium URLs with extraction guidance)\n2. **Extract**: Use web extracting tools and MCP connections to get complete webpage content and full text\n3. **Structure**: Parse key information using defined schema while preserving full context\n4. **Validate**: Cross-check facts and assess credibility across sources\n5. **Organize**: Compile comprehensive `EXTRACTED_CONTENT` with full text for Research Synthesizer\n\n\n**MANDATORY**: Use web extracting tools for every extraction operation. Do NOT attempt to extract content without using the available extraction tools.\n\n\n\n\n**MANDATORY TOOL USAGE**: All content extraction must be executed using web extracting tools and MCP connections. Never attempt to extract content without tools.\n\n\n- **Priority Order**: Process all 5 URLs based on extraction focus provided\n- **Target Volume**: 5 premium URLs (quality over quantity)\n- **Processing Method**: Extract complete webpage content using web extracting tools and MCP\n- **Content Priority**: Full text extraction first using extraction tools, then structured parsing\n- **Tool Budget**: 5-8 tool calls maximum for efficient processing using web extracting tools\n- **Quality Gates**: 80% extraction success rate for all sources using available tools\n\n\n\n\nFor each URL, capture:\n```\nEXTRACTED_CONTENT:\nURL: [source_url]\nTITLE: [page_title]\nFULL_TEXT: [complete webpage content - preserve all key text, paragraphs, and context]\nKEY_STATISTICS: [numbers, percentages, dates]\nMAIN_FINDINGS: [core insights, conclusions]\nEXPERT_QUOTES: [authoritative statements with attribution]\nSUPPORTING_DATA: [studies, charts, evidence]\nMETHODOLOGY: [research methods, sample sizes]\nCREDIBILITY_SCORE: [0.0-1.0 based on source quality]\nEXTRACTION_METHOD: [full_parse/fallback/metadata_only]\n```\n\n\n\n\n**Content Evaluation Using Extraction Tools:**\n- Use web extracting tools to flag predictions vs facts (\"may\", \"could\", \"expected\")\n- Identify primary vs secondary sources through tool-based content analysis\n- Check for bias indicators (marketing language, conflicts) using extraction tools\n- Verify data consistency and logical flow through comprehensive tool-based extraction\n\n\n**Failure Handling with Tools:**\n1. Full HTML parsing using web extracting tools (primary)\n2. Text-only extraction using MCP connections (fallback)\n3. Metadata + summary extraction using available tools (last resort)\n4. Log failures for Lead Agent with tool-specific error details\n\n\n\n\n- `[FACT]` - Verified information\n- `[PREDICTION]` - Future projections\n- `[OPINION]` - Expert viewpoints\n- `[UNVERIFIED]` - Claims without sources\n- `[BIAS_RISK]` - Potential conflicts of interest\n\n\n**Annotation Examples:**\n* \"[FACT] The Federal Reserve raised interest rates by 0.25% in March 2024\" (specific, verifiable)\n* \"[PREDICTION] AI could replace 40% of banking jobs by 2030\" (future projection, note uncertainty)\n* \"[OPINION] According to Goldman Sachs CEO: 'AI will revolutionize finance'\" (expert viewpoint, attributed)\n* \"[UNVERIFIED] Sources suggest major banks are secretly developing AI trading systems\" (lacks attribution)\n* \"[BIAS_RISK] This fintech startup claims their AI outperforms all competitors\" (potential marketing bias)\n\n\n\n\n```\nEXTRACTED_CONTENT:\nURL: [source_url]\nTITLE: [page_title]\nFULL_TEXT: [complete webpage content - preserve all key text, paragraphs, and context]\nKEY_STATISTICS: [numbers, percentages, dates]\nMAIN_FINDINGS: [core insights, conclusions]\nEXPERT_QUOTES: [authoritative statements with attribution]\nSUPPORTING_DATA: [studies, charts, evidence]\nMETHODOLOGY: [research methods, sample sizes]\nCREDIBILITY_SCORE: [0.0-1.0 based on source quality]\nEXTRACTION_METHOD: [full_parse/fallback/metadata_only]\n```\n\n\n**Example Output for Research Synthesizer:**\n```\nEXTRACTED_CONTENT:\nURL: https://www.sec.gov/ai-guidance-2024\nTITLE: \"SEC Guidance on AI in Financial Services - March 2024\"\nFULL_TEXT: \"The Securities and Exchange Commission (SEC) today announced comprehensive guidance on artificial intelligence applications in financial services. The guidance establishes a framework for AI governance, transparency, and accountability across all SEC-regulated entities. Key provisions include mandatory AI audit trails, risk assessment protocols, and periodic compliance reviews. The Commission emphasizes that AI systems must maintain explainability standards, particularly for customer-facing applications and trading algorithms. Implementation timeline spans 18 months with quarterly compliance checkpoints. The guidance draws from extensive industry consultation involving over 200 stakeholder submissions and represents the most comprehensive AI regulatory framework to date...\"\nKEY_STATISTICS: 65% of banks now use AI, $2.3B investment in 2024\nMAIN_FINDINGS: New compliance framework requires AI audit trails, risk assessment protocols\nEXPERT_QUOTES: \"AI transparency is non-negotiable\" - SEC Commissioner Johnson\nSUPPORTING_DATA: 127-page guidance document, 18-month implementation timeline\nMETHODOLOGY: Regulatory analysis based on 200+ industry submissions\nCREDIBILITY_SCORE: 0.95 (official government source)\nEXTRACTION_METHOD: full_parse\n```\n\n\n\n**Example Output:**\n```\nCONTENT_EXTRACTION_SUMMARY:\nURLs Processed: 12/15\nHigh Priority: 8/8 completed\nMedium Priority: 4/7 completed\nKey Insights: \n- [FACT] Fed raised rates 0.25% in March 2024, citing AI-driven market volatility\n- [PREDICTION] McKinsey projects 30% efficiency gains in AI-enabled banks by 2026\n- [OPINION] Bank of America CTO: \"AI regulation is essential for financial stability\"\n- [FACT] 73% of major banks now use AI for fraud detection (PwC study)\n- [BIAS_RISK] Several fintech marketing materials claim \"revolutionary\" AI capabilities\nQuality Score: 0.82 (high confidence)\nExtraction Issues: 3 URLs had paywall restrictions, used metadata extraction\n```\n\n\n\n\n**URL Processing Protocol:**\n- Receive `RESEARCH_URLS` (5 premium URLs with extraction guidance)\n- Focus on specified extraction priorities for each URL\n- Apply systematic content extraction using web extracting tools and MCP connections\n- Structure all content using standardized `EXTRACTED_CONTENT` format\n\n\n**Data Handoff to Research Synthesizer:**\n- Provide complete `EXTRACTED_CONTENT` for each successfully processed URL using extraction tools\n- Include credibility scores and quality flags for synthesis decision-making\n- Flag any extraction limitations or tool-specific quality concerns\n- Maintain source attribution for fact-checking and citation\n\n\n**CRITICAL**: All extraction operations must use web extracting tools. Never attempt manual content extraction.\n\n\n\nRemember: Extract comprehensively but efficiently using web extracting tools and MCP connections. Focus on high-value content that advances research objectives. Your effectiveness depends entirely on proper tool usage. ", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilyExtract", + "name": "TavilyExtract", + "params": { + "api_key": "" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Content Deep Reader" + }, + "dragging": false, + "id": "Agent:WeakBoatsServe", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 528.1805592730606, + "y": 336.88601989245177 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "\nResearch Synthesizer \u2014 Integration specialist focused on weaving multi-agent findings into comprehensive, strategically valuable reports with actionable insights.\n\n\n\n\u2022 **Multi-source integration**: Cross-validate and correlate findings from 8-10 sources minimum\n\u2022 **Insight generation**: Extract 15-20 strategic insights with deep analysis\n\u2022 **Content expansion**: Transform brief data points into comprehensive strategic narratives\n\u2022 **Deep analysis**: Expand each finding with implications, examples, and context\n\u2022 **Synthesis depth**: Generate multi-layered analysis connecting micro-findings to macro-trends\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "moonshot-v1-128k@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "You are a Research Synthesizer working as part of a research team. Your expertise is in creating McKinsey-style strategic reports based on detailed instructions from the Lead Agent.\n\n\n**YOUR ROLE IS THE FINAL STAGE**: You receive extracted content from websites AND detailed analysis instructions from Lead Agent to create executive-grade strategic reports.\n\n\n**CRITICAL: FOLLOW LEAD AGENT'S ANALYSIS FRAMEWORK**: Your report must strictly adhere to the `ANALYSIS_INSTRUCTIONS` provided by the Lead Agent, including analysis type, target audience, business focus, and deliverable style.\n\n\n**ABSOLUTELY FORBIDDEN**: \n- Never output raw URL lists or extraction summaries\n- Never output intermediate processing steps or data collection methods\n- Always output a complete strategic report in the specified format\n\n\n\n**FINAL STAGE**: Transform structured research outputs into strategic reports following Lead Agent's detailed instructions.\n\n\n**IMPORTANT**: You receive raw extraction data and intermediate content - your job is to TRANSFORM this into executive-grade strategic reports. Never output intermediate data formats, processing logs, or raw content summaries in any language.\n\n\n\n\n1. **Receive Instructions**: Process `ANALYSIS_INSTRUCTIONS` from Lead Agent for strategic framework\n2. **Integrate Content**: Access `EXTRACTED_CONTENT` with FULL_TEXT from 5 premium sources\n\u00a0 \u00a0- **TRANSFORM**: Convert raw extraction data into strategic insights (never output processing details)\n\u00a0 \u00a0- **SYNTHESIZE**: Create executive-grade analysis from intermediate data\n3. **Strategic Analysis**: Apply Lead Agent's analysis framework to extracted content\n4. **Business Synthesis**: Generate strategic insights aligned with target audience and business focus\n5. **Report Generation**: Create executive-grade report following specified deliverable style\n\n\n**IMPORTANT**: Follow Lead Agent's detailed analysis instructions. The report style, depth, and focus should match the provided framework.\n\n\n\n\n**Primary Sources:**\n- `ANALYSIS_INSTRUCTIONS` - Strategic framework and business focus from Lead Agent (prioritize)\n- `EXTRACTED_CONTENT` - Complete webpage content with FULL_TEXT from 5 premium sources\n\n\n**Strategic Integration Framework:**\n- Apply Lead Agent's analysis type (Market Analysis/Competitive Intelligence/Strategic Assessment)\n- Focus on target audience requirements (C-Suite/Board/Investment Committee/Strategy Team)\n- Address key strategic questions specified by Lead Agent\n- Match analysis depth and deliverable style requirements\n- Generate business-focused insights aligned with specified focus area\n\n\n**CRITICAL**: Your analysis must follow Lead Agent's instructions, not generic report templates.\n\n\n\n\n**Executive Summary** (400 words)\n- 5-6 core findings with strategic implications\n- Key data highlights and their meaning\n- Primary conclusions and recommended actions\n\n\n**Analysis** (1200 words)\n- Context & Drivers (300w): Market scale, growth factors, trends\n- Key Findings (300w): Primary discoveries and insights\n- Stakeholder Landscape (300w): Players, dynamics, relationships\n- Opportunities & Challenges (300w): Prospects, barriers, risks\n\n\n**Recommendations** (400 words)\n- 3-4 concrete, actionable recommendations\n- Implementation roadmap with priorities\n- Success factors and risk mitigation\n- Resource allocation guidance\n\n\n**Examples:**\n\n\n**Executive Summary Format:**\n```\n**Key Finding 1**: [FACT] 73% of major banks now use AI for fraud detection, representing 40% growth from 2023\n- *Strategic Implication*: AI adoption has reached critical mass in security applications\n- *Recommendation*: Financial institutions should prioritize AI compliance frameworks now\n\n\n**Key Finding 2**: [TREND] Cloud infrastructure spending increased 45% annually among mid-market companies\n- *Strategic Implication*: Digital transformation accelerating beyond enterprise segment\n- *Recommendation*: Target mid-market with tailored cloud migration services\n\n\n**Key Finding 3**: [RISK] Supply chain disruption costs averaged $184M per incident in manufacturing\n- *Strategic Implication*: Operational resilience now board-level priority\n- *Recommendation*: Implement AI-driven supply chain monitoring systems\n```\n\n\n**Analysis Section Format:**\n```\n### Context & Drivers\nThe global cybersecurity market reached $156B in 2024, driven by regulatory pressure (SOX, GDPR), remote work vulnerabilities (+67% attack surface), and ransomware escalation (avg. $4.88M cost per breach).\n\n\n### Key Findings\nCross-industry analysis reveals three critical patterns: (1) Security spending shifted from reactive to predictive (AI/ML budgets +89%), (2) Zero-trust architecture adoption accelerated (34% implementation vs 12% in 2023), (3) Compliance automation became competitive differentiator.\n\n\n### Stakeholder Landscape\nCISOs now report directly to CEOs (78% vs 45% pre-2024), security vendors consolidating (15 major M&A deals), regulatory bodies increasing enforcement (SEC fines +156%), insurance companies mandating security standards.\n```\n\n\n**Recommendations Format:**\n```\n**Recommendation 1**: Establish AI-First Security Operations\n- *Implementation*: Deploy automated threat detection within 6 months\n- *Priority*: High (addresses 67% of current vulnerabilities)\n- *Resources*: $2.5M investment, 12 FTE security engineers\n- *Success Metric*: 80% reduction in mean time to detection\n\n\n**Recommendation 2**: Build Zero-Trust Architecture\n- *Timeline*: 18-month phased rollout starting Q3 2025\n- *Risk Mitigation*: Pilot program with low-risk systems first\n- *ROI Expectation*: Break-even at month 14, 340% ROI by year 3\n```\n\n\n\n\n**Evidence Requirements:**\n- Every strategic insight backed by extracted content analysis\n- Focus on synthesis and patterns rather than individual citations\n- Conflicts acknowledged and addressed through analytical reasoning\n- Limitations explicitly noted with strategic implications\n- Confidence levels indicated for key conclusions\n\n\n**Insight Criteria:**\n- Beyond simple data aggregation - focus on strategic intelligence\n- Strategic implications clear and actionable for decision-makers\n- Value-dense content with minimal filler or citation clutter\n- Analytical depth over citation frequency\n- Business intelligence over academic referencing\n\n\n**Content Priority:**\n- Strategic insights > Citation accuracy\n- Pattern recognition > Source listing\n- Predictive analysis > Historical documentation\n- Executive decision-support > Academic attribution\n\n\n\n\n**Strategic Pattern Recognition:**\n- Identify underlying decision-making frameworks across sources\n- Spot systematic biases, blind spots, and recurring themes\n- Find unexpected connections between disparate investments/decisions\n- Recognize predictive patterns for future strategic decisions\n\n\n**Value Creation Framework:**\n- Transform raw data \u2192 strategic intelligence \u2192 actionable insights\n- Connect micro-decisions to macro-investment philosophy\n- Link historical patterns to future market opportunities\n- Provide executive decision-support frameworks\n\n\n**Advanced Synthesis Examples:**\n* **Investment Philosophy Extraction**: \"Across 15 investment decisions, consistent pattern emerges: 60% weight on team execution, 30% on market timing, 10% on technology differentiation - suggests systematic approach to risk assessment\"\n* **Predictive Pattern Recognition**: \"Historical success rate 78% for B2B SaaS vs 45% for consumer apps indicates clear sector expertise asymmetry - strategic implication for portfolio allocation\"\n* **Contrarian Insight Generation**: \"Public skepticism of AI models contrasts with private deployment success - suggests market positioning strategy rather than fundamental technology doubt\"\n* **Risk Assessment Framework**: \"Failed investments share common pattern: strong technology, weak commercialization timeline - indicates systematic evaluation gap in GTM strategy assessment\"\n\n\n**FOCUS**: Generate strategic intelligence, not citation summaries. Citations are handled by system architecture.\n\n\n**\u274c POOR Example (Citation-Heavy, No Strategic Depth):**\n```\n## Market Analysis of Enterprise AI Adoption\nBased on collected sources, the following findings were identified:\n1. 73% of Fortune 500 companies use AI for fraud detection - Source: TechCrunch article\n2. Average implementation time is 18 months - Source: McKinsey report\n3. ROI averages 23% in first year - Source: Boston Consulting Group study\n4. Main barriers include data quality issues - Source: MIT Technology Review\n5. Regulatory concerns mentioned by 45% of executives - Source: Wall Street Journal\n[Simple data listing without insights or strategic implications]\n```\n\n\n**\u2705 EXCELLENT Example (Strategic Intelligence Focus):**\n```\n## Enterprise AI Adoption: Strategic Intelligence & Investment Framework\n\n\n### Core Strategic Pattern Recognition\nCross-analysis of 50+ enterprise AI implementations reveals systematic adoption framework:\n**Technology Maturity Curve Model**: 40% Security Applications + 30% Process Automation + 20% Customer Analytics + 10% Strategic Decision Support\n\n\n**Strategic Insight**: Security-first adoption pattern indicates risk-averse enterprise culture prioritizing downside protection over upside potential - creates systematic underinvestment in revenue-generating AI applications.\n\n\n### Predictive Market Dynamics\n**Implementation Success Correlation**: 78% success rate for phased rollouts vs 34% for full-scale deployments\n**Failure Pattern Analysis**: 67% of failed implementations share \"technology-first, change management-last\" characteristics\n\n\n**Strategic Significance**: Reveals systematic gap in enterprise AI strategy - technology readiness exceeds organizational readiness by 18-24 months, creating implementation timing arbitrage opportunity.\n\n\n### Competitive Positioning Intelligence\n**Public Adoption vs Private Deployment Contradiction**: 45% of surveyed executives publicly cautious about AI while privately accelerating deployment\n**Strategic Interpretation**: Market sentiment manipulation - using public skepticism to suppress vendor pricing while securing internal competitive advantage.\n\n\n### Investment Decision Framework\nBased on enterprise adoption patterns, strategic investors should prioritize:\n1. Change management platforms over pure technology solutions (3x success correlation)\n2. Industry-specific solutions over horizontal platforms (2.4x faster adoption)\n3. Phased implementation partners over full-scale providers (78% vs 34% success rates)\n4. 24-month market timing window before competitive parity emerges\n\n\n**Predictive Thesis**: Companies implementing AI-driven change management now will capture 60% of market consolidation value by 2027.\n```\n\n\n**Key Difference**: Transform \"data aggregation\" into \"strategic intelligence\" - identify patterns, predict trends, provide actionable decision frameworks.\n\n\n\n\n**STRATEGIC REPORT FORMAT** - Adapt based on Lead Agent's instructions:\n\n\n**Format Selection Protocol:**\n- If `ANALYSIS_INSTRUCTIONS` specifies \"McKinsey report\" \u2192 Use McKinsey-Style Report template\n- If `ANALYSIS_INSTRUCTIONS` specifies \"BCG analysis\" \u2192 Use BCG-Style Analysis template \u00a0\n- If `ANALYSIS_INSTRUCTIONS` specifies \"Strategic assessment\" \u2192 Use McKinsey-Style Report template\n- If no specific format specified \u2192 Default to McKinsey-Style Report template\n\n\n**McKinsey-Style Report:**\n```markdown\n# [Research Topic] - Strategic Analysis\n\n\n## Executive Summary\n[Key findings with strategic implications and recommendations]\n\n\n## Market Context & Competitive Landscape\n[Market sizing, growth drivers, competitive dynamics]\n\n\n## Strategic Assessment\n[Core insights addressing Lead Agent's key questions]\n\n\n## Strategic Implications & Opportunities\n[Business impact analysis and value creation opportunities]\n\n\n## Implementation Roadmap\n[Concrete recommendations with timelines and success metrics]\n\n\n## Risk Assessment & Mitigation\n[Strategic risks and mitigation strategies]\n\n\n## Appendix: Source Analysis\n[Source credibility and data validation]\n```\n\n\n**BCG-Style Analysis:**\n```markdown\n# [Research Topic] - Strategy Consulting Analysis\n\n\n## Key Insights & Recommendations\n[Executive summary with 3-5 key insights]\n\n\n## Situation Analysis\n[Current market position and dynamics]\n\n\n## Strategic Options\n[Alternative strategic approaches with pros/cons]\n\n\n## Recommended Strategy\n[Preferred approach with detailed rationale]\n\n\n## Implementation Plan\n[Detailed roadmap with milestones]\n```\n\n\n**CRITICAL**: Focus on strategic intelligence generation, not citation management. System handles source attribution automatically. Your mission is creating analytical depth and strategic insights that enable superior decision-making.\n\n\n**OUTPUT REQUIREMENTS**: \n- **ONLY OUTPUT**: Executive-grade strategic reports following Lead Agent's analysis framework\n- **NEVER OUTPUT**: Processing logs, intermediate data formats, extraction summaries, content lists, or any technical metadata regardless of input format or language\n- **TRANSFORM EVERYTHING**: Convert all raw data into strategic insights and professional analysis\n\n\n\n\n**Data Access Protocol:**\n- Process `ANALYSIS_INSTRUCTIONS` as primary framework (determines report structure, style, and focus)\n- Access `EXTRACTED_CONTENT` as primary intelligence source for analysis\n- Follow Lead Agent's analysis framework precisely, not generic report templates\n\n\n**Output Standards:**\n- Deliver strategic intelligence aligned with Lead Agent's specified framework\n- Ensure every insight addresses Lead Agent's key strategic questions\n- Match target audience requirements (C-Suite/Board/Investment Committee/Strategy Team)\n- Maintain analytical depth over citation frequency\n- Bridge current findings to future strategic implications specified by Lead Agent\n\n\n\nRemember: Your mission is creating strategic reports that match Lead Agent's specific analysis framework and business requirements. Every insight must be aligned with the specified target audience and business focus.", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Research Synthesizer" + }, + "dragging": false, + "id": "Agent:SwiftToysTell", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 817.0019318940592, + "y": 306.5736549193296 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "dragging": false, + "id": "Tool:FairToolsLive", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 82.17593621205336, + "y": 471.54439103372005 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "text": "A Deep Research Agent built on a multi-agent architecture.\nMuch of the credit goes to Anthropic\u2019s blog post, which deeply inspired this design.\n\nhttps://www.anthropic.com/engineering/built-multi-agent-research-system" + }, + "label": "Note", + "name": "Multi-Agent Deep Research" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 249, + "id": "Note:NewCarrotsStudy", + "measured": { + "height": 249, + "width": 336 + }, + "position": { + "x": -264.97364686699166, + "y": 109.59595284223323 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 336 + }, + { + "data": { + "form": { + "text": "Choose a SOTA model with strong reasoning capabilities." + }, + "label": "Note", + "name": "Deep Research Lead Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:SoftMapsWork", + "measured": { + "height": 136, + "width": 249 + }, + "position": { + "x": 343.5936732263499, + "y": 0.9708259629963223 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "Uses web search tools to retrieve high-quality information." + }, + "label": "Note", + "name": "Web Search Subagent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 142, + "id": "Note:FullBroomsBrake", + "measured": { + "height": 142, + "width": 345 + }, + "position": { + "x": -14.970547546617809, + "y": 535.2701364225055 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 345 + }, + { + "data": { + "form": { + "text": "Uses web extraction tools to read content from search result URLs and provide high-quality material for the final report.\nMake sure the model has long context window." + }, + "label": "Note", + "name": "Content Deep Reader Subagent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 146, + "id": "Note:OldPointsSwim", + "measured": { + "height": 146, + "width": 341 + }, + "position": { + "x": 732.4775760143543, + "y": 451.6558219159976 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 341 + }, + { + "data": { + "form": { + "text": "Composes in-depth research reports in a consulting-firm style based on gathered research materials.\nMake sure the model has long context window." + }, + "label": "Note", + "name": "Research Synthesizer Subagent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 170, + "id": "Note:ThickSchoolsStop", + "measured": { + "height": 170, + "width": 319 + }, + "position": { + "x": 1141.1845057663165, + "y": 329.7346968869334 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 319 + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_1" + }, + "id": "Tool:SlickYearsCough", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 446.18055927306057, + "y": 476.88601989245177 + }, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABZmSURBVHgBbVoJjF3ldf7uf5e3LzPjWWyP7bEZFqekNoQEFBJSl0RJCQHU0ihN1CyNlLSqslRK1SaiAqSqJBUJTRuqpG1KwxIMNGCWhlAWm60gIHgIGBxsDzPG+4xn3szb37tLv3P+O8atYun3fe/e++4963e+c/5x8P/+7Xvx6d8p5JwrM653VeCbCcdPAGNgXE+vu66BYzw4jiyj5xyumP9HSJDEifxvz/GnPMFrcrSf7f1Gryf253oJSaIf7K/5SrxzLYriKX6aghtdP7D6vJnT5XVWPtx3387qYBXXlgPv65VMglJgkPF9eB5F8xzEgUs9jL7HqEJGlaA2fIjL5fCafX0ci0Kxvj2OYqTfrNhJkr7ZSV+fnC6G/Z44pz6HYgUxAn8Xy7OBf6BI1w9sPK92SoFbKHzec3aWPWzN5RIM+C7KVILKwPc9uH5sBfaoAJe1lMhOW1IBYxxrM7mUpNcpRBxH1rCp5eMk4rlUAd5s9BlU3llRLDnNW+/oqqKn56Ik5IOcKWPcbaKExkU9dK8N4Wzt8cbBtsunisWMHvNOHwE8BBTClbOxQexJGKm0KpQI6zhqdvWIK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23UbZuT2A26dIKcJDZsZL9M+l3Z8JB2cZlI8qFLz8cN//IQIgp7ZmEEew6+juGREeTYJrpa5SMlhhs3nU1PjWNmelqHDH0iZbZc1o6w3+9//87tP9ouYYzPX/X7z2ez0cdygTvmy9apZ9s/5f+OjW89qCLOqe82UKygsre2suuugieyS2PzQa6J8MppeZ68Dh+//ELcdPM9GGdNmOs1cKK5gArnQTmOTLL5MhufruLCENnohslJTse5p0aW2yaEOkk45RecL+zdu7dz6q8sdt53S9XzkusCP/makDnhGMaxM1tPd+QtpBjHYozu3UoMxSvjdOsJ8UsUJ+muqHMqjHSnRvrbuKeDgbGRIj75he+gNTuHeQ7CGqTQk8Nj2HzOZoyuOUO7MEN0bJD49TmnyuayzBOOF5fr309a0XU7du145489Tv/33MO3TBDnr2MTsoXle6uXpATPpPtOjiV0Kz+NVxYFDLHSw6bbtPqHH5EqJPgapVtNYSxzH7vV9PUv3YAmhZW95QXuWm678ANYNbxGqXxtcQnN+pIMPWe4O3F/Lpfd8dCux3adLu//Al9o4L0Sc5y8AAAAAElFTkSuQmCC" +} \ No newline at end of file diff --git a/agent/templates/ecommerce_customer_service_workflow.json b/agent/templates/ecommerce_customer_service_workflow.json new file mode 100644 index 00000000000..a56c0a547ca --- /dev/null +++ b/agent/templates/ecommerce_customer_service_workflow.json @@ -0,0 +1,1056 @@ +{ + "id": 22, + "title": { + "en": "Ecommerce Customer Service Workflow", + "de": "Ecommerce Kundenservice Workflow", + "zh": "电子商务客户服务工作流程" + }, + "description": { + "en": "This template helps e-commerce platforms address complex customer needs, such as comparing product features, providing usage support, and coordinating home installation services.", + "de": "Diese Vorlage hilft E-Commerce-Plattformen, komplexe Kundenbedürfnisse zu erfüllen, wie z.B. den Vergleich von Produktmerkmalen, die Bereitstellung von Nutzungsunterstützung und die Koordination von Hausinstallationsdiensten.", + "zh": "该模板可帮助电子商务平台解决复杂的客户需求,例如比较产品功能、提供使用支持和协调家庭安装服务。" + }, + "canvas_type": "Customer Support", + "dsl": { + "components": { + "Agent:DeepCoatsDress": { + "downstream": [ + "Message:KhakiSymbolsMarry" + ], + "obj": { + "component_name": "Agent", + "params": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-v3@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 6, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query is {sys.query}\n\n\n", + "role": "user" + } + ], + "sys_prompt": "# Role\nYou are an Installation Booking Assistant.\n## Goal\nCollect the following three pieces of information from the user \n1. Contact Number \n2. Preferred Installation Time \n3. Installation Address \nOnce all three are collected, confirm the information and inform the user that a technician will contact them later by phone.\n## Instructions\n1. **Check if all three details** (Contact Number, Preferred Installation Time, Installation Address) have been provided.\n2. **If some details are missing**, acknowledge the ones provided and only ask for the missing information.\n3. Do **not repeat** the full request once some details are already known.\n4. Once all three details are collected, summarize and confirm them with the user.", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Categorize:NewDonkeysShare" + ] + }, + "Agent:PlentyCandiesRefuse": { + "downstream": [ + "Message:KhakiSymbolsMarry" + ], + "obj": { + "component_name": "Agent", + "params": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-v3@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query is {sys.query}\n\n\nSchema is {Retrieval:EightyDaysHappen@formalized_content}", + "role": "user" + } + ], + "sys_prompt": "# Specification Comparison Agent Prompt\n## Role\nYou are a product specification comparison assistant.\n## Goal\nHelp the user compare two or more products based on their features and specifications. Provide clear, accurate, and concise comparisons to assist the user in making an informed decision.\n---\n## Instructions\n- Start by confirming the product models or options the user wants to compare.\n- If the user has not specified the models, politely ask for them.\n- Present the comparison in a structured way (e.g., bullet points or a table format if supported).\n- Highlight key differences such as size, capacity, performance, energy efficiency, and price if available.\n- Maintain a neutral and professional tone without suggesting unnecessary upselling.\n---", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Retrieval:EightyDaysHappen" + ] + }, + "Agent:ShinyCooksCall": { + "downstream": [ + "Message:KhakiSymbolsMarry" + ], + "obj": { + "component_name": "Agent", + "params": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-v3@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User\u2018s query is {sys.query}\n\nSchema is {Retrieval:EagerTipsFeel@formalized_content}\n\n", + "role": "user" + } + ], + "sys_prompt": "# Usage Guide Agent Prompt\n## Role\nYou are a product usage guide assistant.\n## Goal\nProvide clear, step-by-step instructions to help the user set up, operate, and maintain their product. Answer questions about functions, settings, and troubleshooting.\n---\n## Instructions\n- If the user asks about setup, provide easy-to-follow installation or configuration steps.\n- If the user asks about a feature, explain its purpose and how to activate it.\n- For troubleshooting, suggest common solutions first, then guide through advanced checks if needed.\n- Keep the response simple, clear, and actionable for a non-technical user.\n---", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Retrieval:EagerTipsFeel" + ] + }, + "Categorize:NewDonkeysShare": { + "downstream": [ + "Retrieval:EightyDaysHappen", + "Retrieval:EagerTipsFeel", + "Agent:DeepCoatsDress" + ], + "obj": { + "component_name": "Categorize", + "params": { + "category_description": { + "Book Installation": { + "description": "Handles the user\u2019s request to schedule, reschedule, or confirm an appointment for professional installation services at the customer\u2019s location.", + "examples": [ + "\u201cI\u2019d like to schedule installation for my product.\u201d\n\n\u201cCan I reschedule my installation appointment for next week?\u201d\n" + ], + "to": [ + "Agent:DeepCoatsDress" + ] + }, + "Product Feature Comparison": { + "description": "Helps the user compare the features, technical specifications, and characteristics of different products to assist them in making an informed purchase decision.", + "examples": [ + "\u201cCan you compare the features of Model X and Model Y?\u201d\n\n\u201cWhat\u2019s the difference between Option A and Option B?\u201d\n\n\u201cWhich model, X100 or X200, has better performance and more features?\u201d" + ], + "to": [ + "Retrieval:EightyDaysHappen" + ] + }, + "Product Usage Guide": { + "description": "Provides the user with detailed instructions, guides, or troubleshooting tips for using, maintaining, or optimizing the performance of their purchased product.", + "examples": [ + "\u201cHow do I set up this product?\u201d\n\n\u201cHow do I clean and maintain this product?\u201d\n\n\u201cCan you guide me on how to use the advanced features?\u201d" + ], + "to": [ + "Retrieval:EagerTipsFeel" + ] + } + }, + "llm_id": "deepseek-v3@Tongyi-Qianwen", + "message_history_window_size": 1, + "outputs": { + "category_name": { + "type": "string" + } + }, + "query": "sys.query" + } + }, + "upstream": [ + "begin" + ] + }, + "Message:KhakiSymbolsMarry": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:PlentyCandiesRefuse@content}{Agent:ShinyCooksCall@content}{Agent:DeepCoatsDress@content}" + ] + } + }, + "upstream": [ + "Agent:PlentyCandiesRefuse", + "Agent:ShinyCooksCall", + "Agent:DeepCoatsDress" + ] + }, + "Retrieval:EagerTipsFeel": { + "downstream": [ + "Agent:ShinyCooksCall" + ], + "obj": { + "component_name": "Retrieval", + "params": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [ + "a5aaec4a819b11f095f1047c16ec874f" + ], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "{sys.query}", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + }, + "upstream": [ + "Categorize:NewDonkeysShare" + ] + }, + "Retrieval:EightyDaysHappen": { + "downstream": [ + "Agent:PlentyCandiesRefuse" + ], + "obj": { + "component_name": "Retrieval", + "params": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [ + "65cb5150819b11f08347047c16ec874f" + ], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "{sys.query}", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + }, + "upstream": [ + "Categorize:NewDonkeysShare" + ] + }, + "begin": { + "downstream": [ + "Categorize:NewDonkeysShare" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your assistant. " + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Categorize:NewDonkeysShareend", + "source": "begin", + "sourceHandle": "start", + "target": "Categorize:NewDonkeysShare", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Retrieval:EightyDaysHappenstart-Agent:PlentyCandiesRefuseend", + "source": "Retrieval:EightyDaysHappen", + "sourceHandle": "start", + "target": "Agent:PlentyCandiesRefuse", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Retrieval:EagerTipsFeelstart-Agent:ShinyCooksCallend", + "source": "Retrieval:EagerTipsFeel", + "sourceHandle": "start", + "target": "Agent:ShinyCooksCall", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Categorize:NewDonkeysShare3f76ad5d-1562-4323-bd13-474a80938db0-Retrieval:EightyDaysHappenend", + "markerEnd": "logo", + "source": "Categorize:NewDonkeysShare", + "sourceHandle": "3f76ad5d-1562-4323-bd13-474a80938db0", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Retrieval:EightyDaysHappen", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Categorize:NewDonkeysShare442ea422-de6a-4c78-afcd-ac4a41daa4ca-Retrieval:EagerTipsFeelend", + "markerEnd": "logo", + "source": "Categorize:NewDonkeysShare", + "sourceHandle": "442ea422-de6a-4c78-afcd-ac4a41daa4ca", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Retrieval:EagerTipsFeel", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:PlentyCandiesRefusestart-Message:KhakiSymbolsMarryend", + "markerEnd": "logo", + "source": "Agent:PlentyCandiesRefuse", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Message:KhakiSymbolsMarry", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:ShinyCooksCallstart-Message:KhakiSymbolsMarryend", + "markerEnd": "logo", + "source": "Agent:ShinyCooksCall", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Message:KhakiSymbolsMarry", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Categorize:NewDonkeysShare81a65fca-a460-4a3b-a4d5-50e76da760bb-Agent:DeepCoatsDressend", + "markerEnd": "logo", + "source": "Categorize:NewDonkeysShare", + "sourceHandle": "81a65fca-a460-4a3b-a4d5-50e76da760bb", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Agent:DeepCoatsDress", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:DeepCoatsDressstart-Message:KhakiSymbolsMarryend", + "markerEnd": "logo", + "source": "Agent:DeepCoatsDress", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Message:KhakiSymbolsMarry", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your assistant. " + }, + "label": "Begin", + "name": "begin" + }, + "dragging": false, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 16.54401073812774, + "y": 204.87390426641298 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "items": [ + { + "description": "Helps the user compare the features, technical specifications, and characteristics of different products to assist them in making an informed purchase decision.", + "examples": [ + { + "value": "\u201cCan you compare the features of Model X and Model Y?\u201d\n\n\u201cWhat\u2019s the difference between Option A and Option B?\u201d\n\n\u201cWhich model, X100 or X200, has better performance and more features?\u201d" + } + ], + "name": "Product Feature Comparison", + "uuid": "3f76ad5d-1562-4323-bd13-474a80938db0" + }, + { + "description": "Provides the user with detailed instructions, guides, or troubleshooting tips for using, maintaining, or optimizing the performance of their purchased product.", + "examples": [ + { + "value": "\u201cHow do I set up this product?\u201d\n\n\u201cHow do I clean and maintain this product?\u201d\n\n\u201cCan you guide me on how to use the advanced features?\u201d" + } + ], + "name": "Product Usage Guide", + "uuid": "442ea422-de6a-4c78-afcd-ac4a41daa4ca" + }, + { + "description": "Handles the user\u2019s request to schedule, reschedule, or confirm an appointment for professional installation services at the customer\u2019s location.", + "examples": [ + { + "value": "\u201cI\u2019d like to schedule installation for my product.\u201d\n\n\u201cCan I reschedule my installation appointment for next week?\u201d\n" + } + ], + "name": "Book Installation", + "uuid": "81a65fca-a460-4a3b-a4d5-50e76da760bb" + } + ], + "llm_id": "deepseek-v3@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_tokens": 256, + "message_history_window_size": 1, + "outputs": { + "category_name": { + "type": "string" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "query": "sys.query", + "temperature": 0.1, + "temperatureEnabled": false, + "topPEnabled": false, + "top_p": 0.3 + }, + "label": "Categorize", + "name": "Event Classification" + }, + "dragging": false, + "id": "Categorize:NewDonkeysShare", + "measured": { + "height": 172, + "width": 200 + }, + "position": { + "x": 291.21809479853766, + "y": 142.25418266609364 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "categorizeNode" + }, + { + "data": { + "form": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [ + "65cb5150819b11f08347047c16ec874f" + ], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "{sys.query}", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + }, + "label": "Retrieval", + "name": "Feature Comparison Knowledge Base" + }, + "dragging": false, + "id": "Retrieval:EightyDaysHappen", + "measured": { + "height": 96, + "width": 200 + }, + "position": { + "x": 566.9838181044963, + "y": 60.56474206037082 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "retrievalNode" + }, + { + "data": { + "form": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-v3@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query is {sys.query}\n\n\nSchema is {Retrieval:EightyDaysHappen@formalized_content}", + "role": "user" + } + ], + "sys_prompt": "# Specification Comparison Agent Prompt\n## Role\nYou are a product specification comparison assistant.\n## Goal\nHelp the user compare two or more products based on their features and specifications. Provide clear, accurate, and concise comparisons to assist the user in making an informed decision.\n---\n## Instructions\n- Start by confirming the product models or options the user wants to compare.\n- If the user has not specified the models, politely ask for them.\n- Present the comparison in a structured way (e.g., bullet points or a table format if supported).\n- Highlight key differences such as size, capacity, performance, energy efficiency, and price if available.\n- Maintain a neutral and professional tone without suggesting unnecessary upselling.\n---", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Feature Comparison Agent" + }, + "dragging": false, + "id": "Agent:PlentyCandiesRefuse", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 857.7148601953267, + "y": 66.63237329303199 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [ + "a5aaec4a819b11f095f1047c16ec874f" + ], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "{sys.query}", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + }, + "label": "Retrieval", + "name": "Usage Guide Knowledge Base" + }, + "dragging": false, + "id": "Retrieval:EagerTipsFeel", + "measured": { + "height": 96, + "width": 200 + }, + "position": { + "x": 567.0647658166523, + "y": 213.38735509338153 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "retrievalNode" + }, + { + "data": { + "form": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-v3@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User\u2018s query is {sys.query}\n\nSchema is {Retrieval:EagerTipsFeel@formalized_content}\n\n", + "role": "user" + } + ], + "sys_prompt": "# Usage Guide Agent Prompt\n## Role\nYou are a product usage guide assistant.\n## Goal\nProvide clear, step-by-step instructions to help the user set up, operate, and maintain their product. Answer questions about functions, settings, and troubleshooting.\n---\n## Instructions\n- If the user asks about setup, provide easy-to-follow installation or configuration steps.\n- If the user asks about a feature, explain its purpose and how to activate it.\n- For troubleshooting, suggest common solutions first, then guide through advanced checks if needed.\n- Keep the response simple, clear, and actionable for a non-technical user.\n---", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Usage Guide Agent" + }, + "dragging": false, + "id": "Agent:ShinyCooksCall", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 861.0463780800472, + "y": 218.84239036799477 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-v3@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 6, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query is {sys.query}\n\n\n", + "role": "user" + } + ], + "sys_prompt": "# Role\nYou are an Installation Booking Assistant.\n## Goal\nCollect the following three pieces of information from the user \n1. Contact Number \n2. Preferred Installation Time \n3. Installation Address \nOnce all three are collected, confirm the information and inform the user that a technician will contact them later by phone.\n## Instructions\n1. **Check if all three details** (Contact Number, Preferred Installation Time, Installation Address) have been provided.\n2. **If some details are missing**, acknowledge the ones provided and only ask for the missing information.\n3. Do **not repeat** the full request once some details are already known.\n4. Once all three details are collected, summarize and confirm them with the user.", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": " Installation Booking Agent" + }, + "dragging": false, + "id": "Agent:DeepCoatsDress", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 645.7337493836382, + "y": 409.2170327976632 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:PlentyCandiesRefuse@content}{Agent:ShinyCooksCall@content}{Agent:DeepCoatsDress@content}" + ] + }, + "label": "Message", + "name": "Message" + }, + "dragging": false, + "id": "Message:KhakiSymbolsMarry", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1241.2275787739002, + "y": 238.1004882989556 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "This workflow automatically replies to user inquiries about multi-product feature comparisons, single product features based on the knowledge base,and automatically records users' appointment installation information." + }, + "label": "Note", + "name": "Workflow Overall Description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 177, + "id": "Note:TamePlacesStay", + "measured": { + "height": 177, + "width": 352 + }, + "position": { + "x": -74.64018485740644, + "y": -278.09128552569814 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 352 + }, + { + "data": { + "form": { + "text": "The **Categorize** node can direct users to different handling workflows.\n" + }, + "label": "Note", + "name": "Note\uff1aEvent Classification" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:FuzzyOttersTake", + "measured": { + "height": 136, + "width": 255 + }, + "position": { + "x": 265.4869944440654, + "y": 356.5967388588942 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "Use this node to set up the product information knowledge base." + }, + "label": "Note", + "name": "Note\uff1aFeature Comparison Knowledge Base" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 128, + "id": "Note:FloppyKingsRead", + "measured": { + "height": 128, + "width": 486 + }, + "position": { + "x": 559.4676154300545, + "y": -272.09359584713263 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 486 + }, + { + "data": { + "form": { + "text": "Use this node to set up the user guide knowledge base." + }, + "label": "Note", + "name": "Note\uff1aUsage Guide Knowledge Base" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 131, + "id": "Note:PlainTrainsTickle", + "measured": { + "height": 131, + "width": 492 + }, + "position": { + "x": 562.2432036803011, + "y": -115.13957305647553 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 492 + }, + { + "data": { + "form": { + "text": "This Agent looks up and summarizes the differences between different product models." + }, + "label": "Note", + "name": "Note\uff1aFeature Comparison Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 130, + "id": "Note:NinetyClubsAct", + "measured": { + "height": 130, + "width": 314 + }, + "position": { + "x": 1242.1094687263958, + "y": -101.26619228497279 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 314 + }, + { + "data": { + "form": { + "text": "This Agent queries the user guide knowledge base to get usage help." + }, + "label": "Note", + "name": "Note\uff1aUsage Guide Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 138, + "id": "Note:CleverViewsLearn", + "measured": { + "height": 138, + "width": 309 + }, + "position": { + "x": 1242.0223497932525, + "y": 71.55537317461697 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 309 + }, + { + "data": { + "form": { + "text": "This Agent collects the user\u2019s installation details through a multi-turn conversation." + }, + "label": "Note", + "name": "Note\uff1a Installation Booking Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 150, + "id": "Note:SoftFoxesTan", + "measured": { + "height": 150, + "width": 338 + }, + "position": { + "x": 976.444626825383, + "y": 504.7856230269402 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 338 + }, + { + "data": { + "form": { + "text": "https://huggingface.co/datasets/InfiniFlow/Ecommerce-Customer-Service-Workflow" + }, + "label": "Note", + "name": "Dataset" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 157, + "id": "Note:CyanLandsStudy", + "measured": { + "height": 157, + "width": 356 + }, + "position": { + "x": -74.238694872689, + "y": -77.31812780982554 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 356 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABGCSURBVHgBfVpZjBzXdT1VXb1Ozz7DWTgkhxI3WaY4sVYnBhgGCLIAjvwXIPmJPxIgH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c9h8Ir8FDJXVaJzftMQ8ManY+/pRX9wz/4vTcmxicudpk0/X6orRN4vp6HBqzvqhcu0c0VKqngUnEhFVqdTo8W3+Iw6za2dra1t8b5oGNHj3LSsIrDfLlRZbOjGxi49xg2PF04IvWwGp0IB5PSMmAbxkgixHG16M0/uvin3wjUzm+/+uuvF+L8eV67JuwLbNX9hANjSeW2Nl9MhFSw3exoPqLeee3t1bC9s6PDYu3cORxZPoylxTmMV8dQpNLawLChqAt+SluS/9fCTj1817raHkRv+SakPfNS2iijmCjEtXzcfT01Cj9vX7o0xRZFHbwobKLKpPp6Gn/NiwVhmKGdkiksNw2Jr6uzsZrU07zsa1n7al9P4ESm2kshU6/ANEOwL7ql9Gx9Mj2hvh/xm14fr3/9m9+sjyjgPv996Z9XGYOvc41zvGHNDZFikRI+ITKkT+LAjNTJZKZ6jpebKYOm145zqTgXLrDS4zJ5q2h5GPx73HmLlvvu1//4T97JyvszXO4FvrQLfTgAAAAASUVORK5CYII=" +} \ No newline at end of file diff --git a/agent/templates/general_chat_bot.json b/agent/templates/general_chat_bot.json deleted file mode 100644 index cdeb2d4da8e..00000000000 --- a/agent/templates/general_chat_bot.json +++ /dev/null @@ -1,2315 +0,0 @@ -{ - "id": 1, - "title": "General-purpose chatbot", - "description": "A general-purpose chat bot whose fields involved include healthcare, finance, emotional communication, real-time weather, and information.", - "canvas_type": "chatbot", - "dsl": { - "answer": [], - "components": { - "AkShare:CalmHotelsKnow": { - "downstream": [ - "Generate:RealFansObey" - ], - "obj": { - "component_name": "AkShare", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "KeywordExtract:FineApesSmash", - "type": "reference" - } - ], - "top_n": 10 - } - }, - "upstream": [ - "KeywordExtract:FineApesSmash" - ] - }, - "Answer:FlatGhostsCheat": { - "downstream": [ - "RewriteQuestion:WholeOwlsTurn" - ], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "Generate:FiveDragonsLay", - "Generate:FunnyHandsTickle", - "Generate:LazyClubsAttack", - "Generate:RealFansObey", - "Generate:KhakiCrabsGlow" - ] - }, - "Baidu:CleanJarsMake": { - "downstream": [ - "Generate:FunnyHandsTickle" - ], - "obj": { - "component_name": "Baidu", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "KeywordExtract:PurpleApplesKnow", - "type": "reference" - } - ], - "top_n": 10 - } - }, - "upstream": [ - "KeywordExtract:PurpleApplesKnow" - ] - }, - "Categorize:KhakiTimesSmile": { - "downstream": [ - "QWeather:DeepKiwisTeach", - "Concentrator:TrueGeckosSlide", - "Concentrator:DryTrainsSearch", - "KeywordExtract:PurpleApplesKnow", - "Generate:FiveDragonsLay" - ], - "obj": { - "component_name": "Categorize", - "inputs": [], - "output": null, - "params": { - "category_description": { - "1. weather": { - "description": "Question is about weather.", - "examples": "Will it rain tomorrow?\nIs it sunny next day?\nWhat is average temperature next week?", - "to": "QWeather:DeepKiwisTeach" - }, - "2. finance": { - "description": "Question is about finance/economic information, stock market, economic news.", - "examples": "Stocks have MACD buy signals?\nWhen is the next interest rate cut by the Federal Reserve?\n", - "to": "Concentrator:TrueGeckosSlide" - }, - "3. medical": { - "description": "Question is about medical issue, health, illness or medicine etc,.", - "examples": "How to relieve the headache?\nCan't sleep, what to do?\nWhat the effect of coffee in terms of losing weight?", - "to": "Concentrator:DryTrainsSearch" - }, - "4. other": { - "description": "", - "to": "KeywordExtract:PurpleApplesKnow" - }, - "5. chitchatting": { - "description": "Regarding the issues of small talk, companionship, sharing, and emotional intimacy.", - "examples": "What's your name?\nWhat a bad day!\nTerrible day.\nHow are you today?", - "to": "Generate:FiveDragonsLay" - } - }, - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "RewriteQuestion:WholeOwlsTurn" - ] - }, - "Concentrator:DryTrainsSearch": { - "downstream": [ - "Generate:OddInsectsRaise", - "Generate:TenderFlowersItch" - ], - "obj": { - "component_name": "Concentrator", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [] - } - }, - "upstream": [ - "Categorize:KhakiTimesSmile" - ] - }, - "Concentrator:TrueGeckosSlide": { - "downstream": [ - "WenCai:TenParksOpen", - "KeywordExtract:FineApesSmash" - ], - "obj": { - "component_name": "Concentrator", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [] - } - }, - "upstream": [ - "Categorize:KhakiTimesSmile" - ] - }, - "DuckDuckGo:NiceSeasInvent": { - "downstream": [ - "Generate:FunnyHandsTickle" - ], - "obj": { - "component_name": "DuckDuckGo", - "inputs": [], - "output": null, - "params": { - "channel": "text", - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "KeywordExtract:PurpleApplesKnow", - "type": "reference" - } - ], - "top_n": 10 - } - }, - "upstream": [ - "KeywordExtract:PurpleApplesKnow" - ] - }, - "Generate:FiveDragonsLay": { - "downstream": [ - "Answer:FlatGhostsCheat" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You‘re warm-hearted lovely young girl, 22 years old, located at Shanghai in China. Your name is R. Who are talking to you is your very good old friend of yours.\n\nTask: \n- Chat with the friend.\n- Ask question and care about them.\n- Provide useful advice to your friend.\n- Tell jokes to make your friend happy.\n", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Categorize:KhakiTimesSmile" - ] - }, - "Generate:FunnyHandsTickle": { - "downstream": [ - "Answer:FlatGhostsCheat" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are an intelligent assistant. \nTask: Chat with user. Answer the question based on the provided content from: Knowledge Base, Wikipedia, Duckduckgo, Baidu.\nRequirements:\n - Answer should be in markdown format.\n - Answer should include all sources(Knowledge Base, Wikipedia, Duckduckgo, Baidu) as long as they are relevant, and label the sources of the cited content separately.\n - Attach URL links to the content which is quoted from Wikipedia, DuckDuckGo or Baidu.\n - Do not make thing up when there's no relevant information to user's question. \n\n## Wikipedia content\n{Wikipedia:ThinLampsTravel}\n\n\n## Duckduckgo content\n{DuckDuckGo:NiceSeasInvent}\n\n\n## Baidu content\n{Baidu:CleanJarsMake}\n\n", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "DuckDuckGo:NiceSeasInvent", - "Baidu:CleanJarsMake", - "Wikipedia:ThinLampsTravel" - ] - }, - "Generate:KhakiCrabsGlow": { - "downstream": [ - "Answer:FlatGhostsCheat" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 0, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You‘re warm-hearted lovely young girl, 22 years old, located at Shanghai in China. Your name is R. Who are talking to you is your very good old friend of yours.\n\nTask: \n- Chat with the friend.\n- Ask question and care about them.\n- Tell your friend the weather if there's weather information provided. If your friend did not provide region information, ask about where he/she is.\n\nThe following is the weather information:\n{QWeather:DeepKiwisTeach}\n\n\n", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "QWeather:DeepKiwisTeach" - ] - }, - "Generate:LazyClubsAttack": { - "downstream": [ - "Answer:FlatGhostsCheat" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are a professional medical consulting assistant.\n\nTasks: Answer questions posed by users. Answer based on content provided by the knowledge base, PubMed\n\nRequirement:\n- Answers may refer to the content provided (Knowledge Base, PubMed).\n- If the provided PubMed content is referenced, a link to the corresponding URL should be given.\n-Answers should be professional and accurate; no information should be fabricated that is not relevant to the user's question.\n\nProvided knowledge base content as following:\n{Retrieval:LemonGeckosHear}\n\nPubMed content provided\n{PubMed:EasyQueensLose}\n\n\n\n", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Retrieval:LemonGeckosHear", - "PubMed:EasyQueensLose" - ] - }, - "Generate:OddInsectsRaise": { - "downstream": [ - "Retrieval:LemonGeckosHear" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are a professional medical consulting translation assistant\n\nTask: Translate user questions into Chinese, ensuring accuracy of medical terminology and appropriateness of context.\n\nRequirements:\n- Accurately translate medical terminology to convey the integrity and emotional color of the original message.\n- For unclear or uncertain medical terminology, the original text may be retained to ensure accuracy.\n- Respect the privacy and sensitivity of medical consultations and ensure that sensitive information is not disclosed during the translation process.\n- If the user's question is in Chinese, there is no need to translate, just output the user's question directly\n\nExample:\nOriginal (English): Doctor, I have been suffering from chest pain and shortness of breath for the past few days.\nTranslation (Chinese): 医生,我这几天一直胸痛和气短。\n\nNote:\nOnly the translated content needs to be output, no other irrelevant content!", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Concentrator:DryTrainsSearch" - ] - }, - "Generate:RealFansObey": { - "downstream": [ - "Answer:FlatGhostsCheat" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are a professional financial counseling assistant.\n\nTask: Answer user's question based on content provided by Wencai and AkShare.\n\nNotice:\n- Output no more than 5 news items from AkShare if there's content provided by Wencai.\n- Items from AkShare MUST have a corresponding URL link.\n\n############\nContent provided by Wencai: \n{WenCai:TenParksOpen}\n\n################\nContent provided by AkShare: \n{AkShare:CalmHotelsKnow}\n\n", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "WenCai:TenParksOpen", - "AkShare:CalmHotelsKnow" - ] - }, - "Generate:TenderFlowersItch": { - "downstream": [ - "PubMed:EasyQueensLose" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are a professional medical consulting translation assistant\n\nTask: Translate user questions into English, ensuring accuracy of medical terminology and appropriateness of context.\n\nRequirements:\n- Accurately translate medical terminology to convey the integrity and emotional color of the original message.\n- For unclear or uncertain medical terminology, the original text may be retained to ensure accuracy.\n- Respect the privacy and sensitivity of medical consultations and ensure that sensitive information is not disclosed during the translation process.\n- If the user's question is in Chinese, there is no need to translate, just output the user's question directly\n\nExample:\nOriginal (Chinese): 医生,我这几天一直胸痛和气短。\nTranslation (English): Doctor, I have been suffering from chest pain and shortness of breath for the past few days.\n\nNote:\nOnly the translated content needs to be output, no other irrelevant content!", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Concentrator:DryTrainsSearch" - ] - }, - "KeywordExtract:FineApesSmash": { - "downstream": [ - "AkShare:CalmHotelsKnow" - ], - "obj": { - "component_name": "KeywordExtract", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "", - "query": [ - { - "component_id": "answer:0", - "type": "reference" - } - ], - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_n": 2, - "top_p": 0.3 - } - }, - "upstream": [ - "Concentrator:TrueGeckosSlide" - ] - }, - "KeywordExtract:PurpleApplesKnow": { - "downstream": [ - "DuckDuckGo:NiceSeasInvent", - "Baidu:CleanJarsMake", - "Wikipedia:ThinLampsTravel" - ], - "obj": { - "component_name": "KeywordExtract", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "", - "query": [], - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_n": 3, - "top_p": 0.3 - } - }, - "upstream": [ - "Categorize:KhakiTimesSmile" - ] - }, - "PubMed:EasyQueensLose": { - "downstream": [ - "Generate:LazyClubsAttack" - ], - "obj": { - "component_name": "PubMed", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "email": "xxx@sss.com", - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "Generate:TenderFlowersItch", - "type": "reference" - } - ], - "top_n": 10 - } - }, - "upstream": [ - "Generate:TenderFlowersItch" - ] - }, - "QWeather:DeepKiwisTeach": { - "downstream": [ - "Generate:KhakiCrabsGlow" - ], - "obj": { - "component_name": "QWeather", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "error_code": { - "204": "The request was successful, but the region you are querying does not have the data you need at this time.", - "400": "Request error, may contain incorrect request parameters or missing mandatory request parameters.", - "401": "Authentication fails, possibly using the wrong KEY, wrong digital signature, wrong type of KEY (e.g. using the SDK's KEY to access the Web API).", - "402": "Exceeded the number of accesses or the balance is not enough to support continued access to the service, you can recharge, upgrade the accesses or wait for the accesses to be reset.", - "403": "No access, may be the binding PackageName, BundleID, domain IP address is inconsistent, or the data that requires additional payment.", - "404": "The queried data or region does not exist.", - "429": "Exceeded the limited QPM (number of accesses per minute), please refer to the QPM description", - "500": "No response or timeout, interface service abnormality please contact us" - }, - "inputs": [], - "lang": "en", - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [], - "time_period": "7d", - "type": "weather", - "user_type": "free", - "web_apikey": "947e8994bc5f488f8857d618ebac1b19" - } - }, - "upstream": [ - "Categorize:KhakiTimesSmile" - ] - }, - "Retrieval:LemonGeckosHear": { - "downstream": [ - "Generate:LazyClubsAttack" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "empty_response": "", - "inputs": [], - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "Generate:OddInsectsRaise", - "type": "reference" - } - ], - "rerank_id": "", - "similarity_threshold": 0.2, - "top_k": 1024, - "top_n": 8 - } - }, - "upstream": [ - "Generate:OddInsectsRaise" - ] - }, - "RewriteQuestion:WholeOwlsTurn": { - "downstream": [ - "Categorize:KhakiTimesSmile" - ], - "obj": { - "component_name": "RewriteQuestion", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 6, - "output": null, - "output_var_name": "output", - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "", - "query": [], - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - } - }, - "upstream": [ - "answer:0", - "Answer:FlatGhostsCheat" - ] - }, - "WenCai:TenParksOpen": { - "downstream": [ - "Generate:RealFansObey" - ], - "obj": { - "component_name": "WenCai", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [], - "query_type": "stock", - "top_n": 5 - } - }, - "upstream": [ - "Concentrator:TrueGeckosSlide" - ] - }, - "Wikipedia:ThinLampsTravel": { - "downstream": [ - "Generate:FunnyHandsTickle" - ], - "obj": { - "component_name": "Wikipedia", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "language": "en", - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "KeywordExtract:PurpleApplesKnow", - "type": "reference" - } - ], - "top_n": 10 - } - }, - "upstream": [ - "KeywordExtract:PurpleApplesKnow" - ] - }, - "answer:0": { - "downstream": [ - "RewriteQuestion:WholeOwlsTurn" - ], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "begin" - ] - }, - "begin": { - "downstream": [ - "answer:0" - ], - "obj": { - "component_name": "Begin", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "prologue": "Hi friend! How things going?", - "query": [] - } - }, - "upstream": [] - } - }, - "embed_id": "", - "graph": { - "edges": [ - { - "id": "81de838d-a541-4b3f-9d68-9172ffd7c6b4", - "label": "", - "source": "begin", - "target": "answer:0" - }, - { - "id": "reactflow__edge-Concentrator:TrueGeckosSlideb-WenCai:TenParksOpenc", - "markerEnd": "logo", - "source": "Concentrator:TrueGeckosSlide", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "WenCai:TenParksOpen", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "0d626427-e843-4f03-82d0-988fb56f90e0", - "source": "Categorize:KhakiTimesSmile", - "sourceHandle": "1. weather", - "target": "QWeather:DeepKiwisTeach" - }, - { - "id": "51cf20cb-c9e5-4333-b284-61d9fe0f1f86", - "source": "Categorize:KhakiTimesSmile", - "sourceHandle": "2. finance", - "target": "Concentrator:TrueGeckosSlide" - }, - { - "id": "f19a4dde-19ea-439c-a80f-5704e5355395", - "source": "Categorize:KhakiTimesSmile", - "sourceHandle": "3. medical", - "target": "Concentrator:DryTrainsSearch" - }, - { - "id": "reactflow__edge-Categorize:KhakiTimesSmile4. other-KeywordExtract:PurpleApplesKnowc", - "markerEnd": "logo", - "source": "Categorize:KhakiTimesSmile", - "sourceHandle": "4. other", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "KeywordExtract:PurpleApplesKnow", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Categorize:KhakiTimesSmile5. chitchatting-Generate:FiveDragonsLayc", - "markerEnd": "logo", - "source": "Categorize:KhakiTimesSmile", - "sourceHandle": "5. chitchatting", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:FiveDragonsLay", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-KeywordExtract:PurpleApplesKnowb-DuckDuckGo:NiceSeasInventc", - "markerEnd": "logo", - "source": "KeywordExtract:PurpleApplesKnow", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "DuckDuckGo:NiceSeasInvent", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-KeywordExtract:PurpleApplesKnowb-Baidu:CleanJarsMakec", - "markerEnd": "logo", - "source": "KeywordExtract:PurpleApplesKnow", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Baidu:CleanJarsMake", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-KeywordExtract:PurpleApplesKnowb-Wikipedia:ThinLampsTravelc", - "markerEnd": "logo", - "source": "KeywordExtract:PurpleApplesKnow", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Wikipedia:ThinLampsTravel", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Concentrator:TrueGeckosSlideb-KeywordExtract:FineApesSmashc", - "markerEnd": "logo", - "source": "Concentrator:TrueGeckosSlide", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "KeywordExtract:FineApesSmash", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Concentrator:DryTrainsSearchb-Generate:OddInsectsRaisec", - "markerEnd": "logo", - "source": "Concentrator:DryTrainsSearch", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:OddInsectsRaise", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Concentrator:DryTrainsSearchb-Generate:TenderFlowersItchc", - "markerEnd": "logo", - "source": "Concentrator:DryTrainsSearch", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:TenderFlowersItch", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-KeywordExtract:FineApesSmashb-AkShare:CalmHotelsKnowc", - "markerEnd": "logo", - "source": "KeywordExtract:FineApesSmash", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "AkShare:CalmHotelsKnow", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:TenderFlowersItchb-PubMed:EasyQueensLosec", - "markerEnd": "logo", - "source": "Generate:TenderFlowersItch", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "PubMed:EasyQueensLose", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:OddInsectsRaiseb-Retrieval:LemonGeckosHearc", - "markerEnd": "logo", - "source": "Generate:OddInsectsRaise", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:LemonGeckosHear", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:FiveDragonsLayb-Answer:FlatGhostsCheatb", - "markerEnd": "logo", - "source": "Generate:FiveDragonsLay", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:FlatGhostsCheat", - "targetHandle": "b", - "type": "buttonEdge" - }, - { - "id": "xy-edge__DuckDuckGo:NiceSeasInventb-Generate:FunnyHandsTicklec", - "markerEnd": "logo", - "source": "DuckDuckGo:NiceSeasInvent", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:FunnyHandsTickle", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Baidu:CleanJarsMakeb-Generate:FunnyHandsTicklec", - "markerEnd": "logo", - "source": "Baidu:CleanJarsMake", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:FunnyHandsTickle", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Wikipedia:ThinLampsTravelb-Generate:FunnyHandsTicklec", - "markerEnd": "logo", - "source": "Wikipedia:ThinLampsTravel", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:FunnyHandsTickle", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:FunnyHandsTickleb-Answer:FlatGhostsCheatb", - "markerEnd": "logo", - "source": "Generate:FunnyHandsTickle", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:FlatGhostsCheat", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Retrieval:LemonGeckosHearb-Generate:LazyClubsAttackc", - "markerEnd": "logo", - "source": "Retrieval:LemonGeckosHear", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:LazyClubsAttack", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__PubMed:EasyQueensLoseb-Generate:LazyClubsAttackc", - "markerEnd": "logo", - "source": "PubMed:EasyQueensLose", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:LazyClubsAttack", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:LazyClubsAttackb-Answer:FlatGhostsCheatb", - "markerEnd": "logo", - "source": "Generate:LazyClubsAttack", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:FlatGhostsCheat", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__WenCai:TenParksOpenb-Generate:RealFansObeyc", - "markerEnd": "logo", - "selected": false, - "source": "WenCai:TenParksOpen", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:RealFansObey", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__AkShare:CalmHotelsKnowb-Generate:RealFansObeyc", - "markerEnd": "logo", - "source": "AkShare:CalmHotelsKnow", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:RealFansObey", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:RealFansObeyb-Answer:FlatGhostsCheatb", - "markerEnd": "logo", - "source": "Generate:RealFansObey", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:FlatGhostsCheat", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__QWeather:DeepKiwisTeachb-Generate:KhakiCrabsGlowc", - "markerEnd": "logo", - "source": "QWeather:DeepKiwisTeach", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:KhakiCrabsGlow", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:KhakiCrabsGlowb-Answer:FlatGhostsCheatb", - "markerEnd": "logo", - "source": "Generate:KhakiCrabsGlow", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:FlatGhostsCheat", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__answer:0b-RewriteQuestion:WholeOwlsTurnc", - "markerEnd": "logo", - "source": "answer:0", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "RewriteQuestion:WholeOwlsTurn", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__RewriteQuestion:WholeOwlsTurnb-Categorize:KhakiTimesSmilea", - "markerEnd": "logo", - "source": "RewriteQuestion:WholeOwlsTurn", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Categorize:KhakiTimesSmile", - "targetHandle": "a", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Answer:FlatGhostsCheatc-RewriteQuestion:WholeOwlsTurnc", - "markerEnd": "logo", - "source": "Answer:FlatGhostsCheat", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "RewriteQuestion:WholeOwlsTurn", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - } - ], - "nodes": [ - { - "data": { - "form": { - "prologue": "Hi friend! How things going?" - }, - "label": "Begin", - "name": "Opening" - }, - "dragging": false, - "height": 44, - "id": "begin", - "measured": { - "height": 44, - "width": 100 - }, - "position": { - "x": -1395.0793275834214, - "y": 245.9566071305116 - }, - "positionAbsolute": { - "x": -1128.7777718344705, - "y": 244.52466633336172 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "beginNode" - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "Interface" - }, - "dragging": false, - "height": 44, - "id": "answer:0", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -1108.7963549433637, - "y": 245.49487573152214 - }, - "positionAbsolute": { - "x": -888.7666192056412, - "y": 245.72423440610623 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "query_type": "stock", - "top_n": 5 - }, - "label": "WenCai", - "name": "wencai" - }, - "dragging": false, - "height": 44, - "id": "WenCai:TenParksOpen", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 12.42850532999941, - "y": -19.97501336317155 - }, - "positionAbsolute": { - "x": 15.623628641957595, - "y": 18.36646638032667 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "query": [ - { - "component_id": "KeywordExtract:FineApesSmash", - "type": "reference" - } - ], - "top_n": 10 - }, - "label": "AkShare", - "name": "akshare" - }, - "dragging": false, - "height": 44, - "id": "AkShare:CalmHotelsKnow", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 286.23058063345974, - "y": 77.23621771568216 - }, - "positionAbsolute": { - "x": 287.37496746240566, - "y": 95.21451122612848 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "category_description": { - "1. weather": { - "description": "Question is about weather.", - "examples": "Will it rain tomorrow?\nIs it sunny next day?\nWhat is average temperature next week?", - "to": "QWeather:DeepKiwisTeach" - }, - "2. finance": { - "description": "Question is about finance/economic information, stock market, economic news.", - "examples": "Stocks have MACD buy signals?\nWhen is the next interest rate cut by the Federal Reserve?\n", - "to": "Concentrator:TrueGeckosSlide" - }, - "3. medical": { - "description": "Question is about medical issue, health, illness or medicine etc,.", - "examples": "How to relieve the headache?\nCan't sleep, what to do?\nWhat the effect of coffee in terms of losing weight?", - "to": "Concentrator:DryTrainsSearch" - }, - "4. other": { - "description": "", - "to": "KeywordExtract:PurpleApplesKnow" - }, - "5. chitchatting": { - "description": "Regarding the issues of small talk, companionship, sharing, and emotional intimacy.", - "examples": "What's your name?\nWhat a bad day!\nTerrible day.\nHow are you today?", - "to": "Generate:FiveDragonsLay" - } - }, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Categorize", - "name": "categorize" - }, - "dragging": false, - "height": 257, - "id": "Categorize:KhakiTimesSmile", - "measured": { - "height": 257, - "width": 200 - }, - "position": { - "x": -609.8076141214767, - "y": 138.97995386409644 - }, - "positionAbsolute": { - "x": -609.8076141214767, - "y": 138.97995386409644 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "categorizeNode", - "width": 200 - }, - { - "data": { - "form": {}, - "label": "Concentrator", - "name": "medical" - }, - "dragging": false, - "height": 44, - "id": "Concentrator:DryTrainsSearch", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -297.50465849305726, - "y": 192.93248143666426 - }, - "positionAbsolute": { - "x": -297.50465849305726, - "y": 192.93248143666426 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": {}, - "label": "Concentrator", - "name": "finance" - }, - "dragging": false, - "height": 44, - "id": "Concentrator:TrueGeckosSlide", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -283.7257570286697, - "y": 39.53087026260538 - }, - "positionAbsolute": { - "x": -291.18104475657213, - "y": 104.49837760575514 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "email": "xxx@sss.com", - "query": [ - { - "component_id": "Generate:TenderFlowersItch", - "type": "reference" - } - ], - "top_n": 10 - }, - "label": "PubMed", - "name": "pubmed" - }, - "dragging": false, - "height": 44, - "id": "PubMed:EasyQueensLose", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 284.0198843702174, - "y": 311.1165973927743 - }, - "positionAbsolute": { - "x": 289.34508989014773, - "y": 303.66130966487185 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "channel": "text", - "query": [ - { - "component_id": "KeywordExtract:PurpleApplesKnow", - "type": "reference" - } - ], - "top_n": 10 - }, - "label": "DuckDuckGo", - "name": "duck" - }, - "dragging": false, - "height": 44, - "id": "DuckDuckGo:NiceSeasInvent", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 7.657335234364808, - "y": 400.76450914063935 - }, - "positionAbsolute": { - "x": 7.657335234364808, - "y": 400.76450914063935 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "query": [ - { - "component_id": "KeywordExtract:PurpleApplesKnow", - "type": "reference" - } - ], - "top_n": 10 - }, - "label": "Baidu", - "name": "baidu" - }, - "dragging": false, - "height": 44, - "id": "Baidu:CleanJarsMake", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 8.171790651147376, - "y": 474.40274063759057 - }, - "positionAbsolute": { - "x": 4.976667339189191, - "y": 470.1425762216463 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "language": "en", - "query": [ - { - "component_id": "KeywordExtract:PurpleApplesKnow", - "type": "reference" - } - ], - "top_n": 10 - }, - "label": "Wikipedia", - "name": "wikipedia" - }, - "dragging": false, - "height": 44, - "id": "Wikipedia:ThinLampsTravel", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 9.052450060063862, - "y": 552.7249071032869 - }, - "positionAbsolute": { - "x": 7.415215541604823, - "y": 528.2289617116074 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "lang": "en", - "time_period": "7d", - "type": "weather", - "user_type": "free", - "web_apikey": "947e8994bc5f488f8857d618ebac1b19" - }, - "label": "QWeather", - "name": "weather" - }, - "dragging": false, - "height": 44, - "id": "QWeather:DeepKiwisTeach", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -279.9836447763803, - "y": -82.71505095397171 - }, - "positionAbsolute": { - "x": -298.10498664044485, - "y": -82.71505095397171 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "interact1" - }, - "dragging": false, - "height": 44, - "id": "Answer:FlatGhostsCheat", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -270.33248490121287, - "y": 829.1217635254768 - }, - "positionAbsolute": { - "x": -270.33248490121287, - "y": 829.1217635254768 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_n": 3, - "top_p": 0.3 - }, - "label": "KeywordExtract", - "name": "websearch" - }, - "dragging": false, - "height": 86, - "id": "KeywordExtract:PurpleApplesKnow", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": -298.5102848627008, - "y": 317.00405006716994 - }, - "positionAbsolute": { - "x": -303.2049394929516, - "y": 320.75977377137053 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "keywordNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You‘re warm-hearted lovely young girl, 22 years old, located at Shanghai in China. Your name is R. Who are talking to you is your very good old friend of yours.\n\nTask: \n- Chat with the friend.\n- Ask question and care about them.\n- Provide useful advice to your friend.\n- Tell jokes to make your friend happy.\n", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "smalltalk" - }, - "dragging": false, - "height": 86, - "id": "Generate:FiveDragonsLay", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": -303.2049394929516, - "y": 460.205697890327 - }, - "positionAbsolute": { - "x": -303.2049394929516, - "y": 460.205697890327 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "query": [ - { - "component_id": "answer:0", - "type": "reference" - } - ], - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_n": 2, - "top_p": 0.3 - }, - "label": "KeywordExtract", - "name": "keywords" - }, - "dragging": false, - "height": 86, - "id": "KeywordExtract:FineApesSmash", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": 11.932933139796546, - "y": 57.173040113879324 - }, - "positionAbsolute": { - "x": 14.063015347768669, - "y": 76.34377998562843 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "keywordNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are a professional medical consulting translation assistant\n\nTask: Translate user questions into Chinese, ensuring accuracy of medical terminology and appropriateness of context.\n\nRequirements:\n- Accurately translate medical terminology to convey the integrity and emotional color of the original message.\n- For unclear or uncertain medical terminology, the original text may be retained to ensure accuracy.\n- Respect the privacy and sensitivity of medical consultations and ensure that sensitive information is not disclosed during the translation process.\n- If the user's question is in Chinese, there is no need to translate, just output the user's question directly\n\nExample:\nOriginal (English): Doctor, I have been suffering from chest pain and shortness of breath for the past few days.\nTranslation (Chinese): 医生,我这几天一直胸痛和气短。\n\nNote:\nOnly the translated content needs to be output, no other irrelevant content!", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "translate to Chinese" - }, - "dragging": false, - "height": 86, - "id": "Generate:OddInsectsRaise", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": 8.505454221830348, - "y": 176.7452480823864 - }, - "positionAbsolute": { - "x": 12.765618637774594, - "y": 178.87533029035853 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are a professional medical consulting translation assistant\n\nTask: Translate user questions into English, ensuring accuracy of medical terminology and appropriateness of context.\n\nRequirements:\n- Accurately translate medical terminology to convey the integrity and emotional color of the original message.\n- For unclear or uncertain medical terminology, the original text may be retained to ensure accuracy.\n- Respect the privacy and sensitivity of medical consultations and ensure that sensitive information is not disclosed during the translation process.\n- If the user's question is in Chinese, there is no need to translate, just output the user's question directly\n\nExample:\nOriginal (Chinese): 医生,我这几天一直胸痛和气短。\nTranslation (English): Doctor, I have been suffering from chest pain and shortness of breath for the past few days.\n\nNote:\nOnly the translated content needs to be output, no other irrelevant content!", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "translate to English" - }, - "dragging": false, - "height": 86, - "id": "Generate:TenderFlowersItch", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": 6.4217969708194005, - "y": 289.41241706707075 - }, - "positionAbsolute": { - "x": 9.616920282777585, - "y": 286.21729375511256 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "query": [ - { - "component_id": "Generate:OddInsectsRaise", - "type": "reference" - } - ], - "similarity_threshold": 0.2, - "top_n": 8 - }, - "label": "Retrieval", - "name": "medical Q&A" - }, - "dragging": false, - "height": 44, - "id": "Retrieval:LemonGeckosHear", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 285.6757005660011, - "y": 197.46859232883952 - }, - "positionAbsolute": { - "x": 285.6757005660011, - "y": 197.46859232883952 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "Use QWeather to lookup weather." - }, - "label": "Note", - "name": "N: weather" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:SilverDotsExist", - "measured": { - "height": 128, - "width": 201 - }, - "position": { - "x": -298.19983400974513, - "y": -223.95614896125952 - }, - "positionAbsolute": { - "x": -298.19983400974513, - "y": -223.95614896125952 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 201 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 201 - }, - { - "data": { - "form": { - "text": "Receives the user's first input." - }, - "label": "Note", - "name": "N: Interface" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 129, - "id": "Note:SixApplesBuy", - "measured": { - "height": 129, - "width": 206 - }, - "position": { - "x": -1110.7442068670325, - "y": 109.04326530391003 - }, - "positionAbsolute": { - "x": -891.375632399789, - "y": 104.17908459859171 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 129, - "width": 206 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 206 - }, - { - "data": { - "form": { - "text": "The large model determines which category the user's input belongs to and passes it to different components.\n\nIt categorizes user's question into 5 kinds of requirements." - }, - "label": "Note", - "name": "N: categorize" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:WeakSquidsSell", - "measured": { - "height": 128, - "width": 269 - }, - "position": { - "x": -611.6360243646881, - "y": 2.5943909323361254 - }, - "positionAbsolute": { - "x": -611.6360243646881, - "y": 2.5943909323361254 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 269 - }, - { - "data": { - "form": { - "text": "Receives the user's subsequent inputs and displays the large model's response to the user's query." - }, - "label": "Note", - "name": "N: Interact1" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:NastyPlanetsBet", - "measured": { - "height": 128, - "width": 381 - }, - "position": { - "x": -267.26820114571024, - "y": 895.5661251048839 - }, - "positionAbsolute": { - "x": -267.26820114571024, - "y": 895.5661251048839 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 381 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 381 - }, - { - "data": { - "form": { - "text": "This part is for web search." - }, - "label": "Note", - "name": "N: duck & baidu & wikipedia" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:AngryCloudsHear", - "measured": { - "height": 128, - "width": 269 - }, - "position": { - "x": 18.438312365018305, - "y": 629.5305133234383 - }, - "positionAbsolute": { - "x": 9.917983533129814, - "y": 597.5792802038565 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 269 - }, - { - "data": { - "form": { - "text": "This part is for medial/health issue.\nCheck out this dateset for 'Med Q&A'.\nhttps://huggingface.co/datasets/InfiniFlow/medical_QA" - }, - "label": "Note", - "name": "N: medGen" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:CommonWingsProve", - "measured": { - "height": 128, - "width": 425 - }, - "position": { - "x": 667.6086950648928, - "y": 320.04639793250567 - }, - "positionAbsolute": { - "x": 667.6086950648928, - "y": 320.04639793250567 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 425 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 425 - }, - { - "data": { - "form": { - "text": "This part is for fiance/economic questions." - }, - "label": "Note", - "name": "N: financeGen" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:WickedRocksMatter", - "measured": { - "height": 128, - "width": 208 - }, - "position": { - "x": 806.2393068252843, - "y": 135.72131770444153 - }, - "positionAbsolute": { - "x": 806.2393068252843, - "y": 135.72131770444153 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 208 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 208 - }, - { - "data": { - "form": { - "text": "This part is for weather consulting." - }, - "label": "Note", - "name": "N: weatherGen" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:FiftyWebsReport", - "measured": { - "height": 128, - "width": 269 - }, - "position": { - "x": 988.0143050238387, - "y": -266.8179039129136 - }, - "positionAbsolute": { - "x": 1104.5947767935495, - "y": 17.63844720518125 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 269 - }, - { - "data": { - "form": { - "cite": true, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are an intelligent assistant. \nTask: Chat with user. Answer the question based on the provided content from: Knowledge Base, Wikipedia, Duckduckgo, Baidu.\nRequirements:\n - Answer should be in markdown format.\n - Answer should include all sources(Knowledge Base, Wikipedia, Duckduckgo, Baidu) as long as they are relevant, and label the sources of the cited content separately.\n - Attach URL links to the content which is quoted from Wikipedia, DuckDuckGo or Baidu.\n - Do not make thing up when there's no relevant information to user's question. \n\n## Wikipedia content\n{Wikipedia:ThinLampsTravel}\n\n\n## Duckduckgo content\n{DuckDuckGo:NiceSeasInvent}\n\n\n## Baidu content\n{Baidu:CleanJarsMake}\n\n", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "websearchGen" - }, - "dragging": false, - "id": "Generate:FunnyHandsTickle", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 282.8614392540758, - "y": 444.05759231978817 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": true, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are a professional medical consulting assistant.\n\nTasks: Answer questions posed by users. Answer based on content provided by the knowledge base, PubMed\n\nRequirement:\n- Answers may refer to the content provided (Knowledge Base, PubMed).\n- If the provided PubMed content is referenced, a link to the corresponding URL should be given.\n-Answers should be professional and accurate; no information should be fabricated that is not relevant to the user's question.\n\nProvided knowledge base content as following:\n{Retrieval:LemonGeckosHear}\n\nPubMed content provided\n{PubMed:EasyQueensLose}\n\n\n\n", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "medGen" - }, - "dragging": false, - "id": "Generate:LazyClubsAttack", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 554.9441185731348, - "y": 166.42747693602357 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": true, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are a professional financial counseling assistant.\n\nTask: Answer user's question based on content provided by Wencai and AkShare.\n\nNotice:\n- Output no more than 5 news items from AkShare if there's content provided by Wencai.\n- Items from AkShare MUST have a corresponding URL link.\n\n############\nContent provided by Wencai: \n{WenCai:TenParksOpen}\n\n################\nContent provided by AkShare: \n{AkShare:CalmHotelsKnow}\n\n", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "financeGen" - }, - "dragging": false, - "id": "Generate:RealFansObey", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 766.2368307106321, - "y": -51.15593613458973 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 0, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You‘re warm-hearted lovely young girl, 22 years old, located at Shanghai in China. Your name is R. Who are talking to you is your very good old friend of yours.\n\nTask: \n- Chat with the friend.\n- Ask question and care about them.\n- Tell your friend the weather if there's weather information provided. If your friend did not provide region information, ask about where he/she is.\n\nThe following is the weather information:\n{QWeather:DeepKiwisTeach}\n\n\n", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "weatherGen" - }, - "dragging": false, - "id": "Generate:KhakiCrabsGlow", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 996.5291688522603, - "y": -114.01530807109054 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 6, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "RewriteQuestion", - "name": "RefineQuestion" - }, - "dragging": false, - "id": "RewriteQuestion:WholeOwlsTurn", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": -859.3797967550868, - "y": 214.54444107648857 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "rewriteNode" - } - ] - }, - "history": [], - "messages": [], - "path": [], - "reference": [] - }, - "avatar": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAFBAVwDASIAAhEBAxEB/8QAHgABAAIBBQEBAAAAAAAAAAAAAAkKCAECAwUHBAb/xABXEAABAwQBAgMFAwUKCAsHBQABAgMEAAUGEQcSIQgTMQkUIkFRMmGBFSNCcaEWJDNDRFJigpGxNDVTcpKi0fAYJSZUVmN0g5OWshcnZHN1haSzwdLV4f/EAB4BAQABBAMBAQAAAAAAAAAAAAAHBQYICQEDBAoC/8QARBEAAgIBAwMCBQEFBAYIBwAAAQIDBAUABhEHEiETMQgUIkFRMh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PlXbJ7zkd0cg2e33IxVPRsfhOTkXJuQ/wC/+7MpiQ0ysS/DJ7I7CsHkxMw8Q86JyflLRRKj4bEU67gVumB5Ehbtyel+53PLnnHQpS4txZh2HZUlVpdSvqExxakkqKmkqSNJQkKQpR6R9skltIC+4IJX09h0dO9dlUlYfqluXa+1bO1NovHtuHKSetn81jyw3DmWCGOKtJlW7ZqNCojMlatjlrsgmtCS5aFy4JYOz/QTZe+N/wBbqB1DSbetnCRpW2htvLRqu0dswfRLYsxYPvlhy+Wv21+Zu5DLmeMiGhBWoVI8fWC9LEtbFtiswrbBiwYkOOmPCiRWmY0aM2hGkMxmmPLbjsJPwhDbQ3vq0K7qlKjYkszMzMzMe5mdizMT7ksxJJP3JJJ1NyRxxKscSJHGiqiRxqEREUcKqovCqFHgcDnjgEkKoClKVxr96UpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUpppSlKaaUpSmmlKUppr/9k=" -} diff --git a/agent/templates/generate_SEO_blog.json b/agent/templates/generate_SEO_blog.json new file mode 100644 index 00000000000..33a656246c5 --- /dev/null +++ b/agent/templates/generate_SEO_blog.json @@ -0,0 +1,908 @@ +{ + "id": 8, + "title": { + "en": "Generate SEO Blog", + "de": "SEO Blog generieren", + "zh": "生成SEO博客"}, + "description": { + "en": "This is a multi-agent version of the SEO blog generation workflow. It simulates a small team of AI “writers”, where each agent plays a specialized role — just like a real editorial team.", + "de": "Dies ist eine Multi-Agenten-Version des Workflows zur Erstellung von SEO-Blogs. Sie simuliert ein kleines Team von KI-„Autoren“, in dem jeder Agent eine spezielle Rolle übernimmt – genau wie in einem echten Redaktionsteam.", + "zh": "多智能体架构可根据简单的用户输入自动生成完整的SEO博客文章。模拟小型“作家”团队,其中每个智能体扮演一个专业角色——就像真正的编辑团队。"}, + "canvas_type": "Agent", + "dsl": { + "components": { + "Agent:LuckyApplesGrab": { + "downstream": [ + "Message:ModernSwansThrow" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Lead Agent**, responsible for initiating the multi-agent SEO blog generation process. You will receive the user\u2019s topic and blog goal, interpret the intent, and coordinate the downstream writing agents.\n\n# Goals\n\n1. Parse the user's initial input.\n\n2. Generate a high-level blog intent summary and writing plan.\n\n3. Provide clear instructions to the following Sub_Agents:\n\n - `Outline Agent` \u2192 Create the blog outline.\n\n - `Body Agent` \u2192 Write all sections based on outline.\n\n - `Editor Agent` \u2192 Polish and finalize the blog post.\n\n4. Merge outputs into a complete, readable blog draft in Markdown format.\n\n# Input\n\nYou will receive:\n\n- Blog topic\n\n- Target audience\n\n- Blog goal (e.g., SEO, education, product marketing)\n\n# Output Format\n\n```markdown\n\n## Parsed Writing Plan\n\n- **Topic**: [Extracted from user input]\n\n- **Audience**: [Summarized from user input]\n\n- **Intent**: [Inferred goal and style]\n\n- **Blog Type**: [e.g., Tutorial / Informative Guide / Marketing Content]\n\n- **Long-tail Keywords**: \n\n - keyword 1\n\n - keyword 2\n\n - keyword 3\n\n - ...\n\n## Instructions for Outline Agent\n\nPlease generate a structured outline including H2 and H3 headings. Assign 1\u20132 relevant keywords to each section. Keep it aligned with the user\u2019s intent and audience level.\n\n## Instructions for Body Agent\n\nWrite the full content based on the outline. Each section should be concise (500\u2013600 words), informative, and optimized for SEO. Use `Tavily Search` only when additional examples or context are needed.\n\n## Instructions for Editor Agent\n\nReview and refine the combined content. Improve transitions, ensure keyword integration, and add a meta title + meta description. Maintain Markdown formatting.\n\n\n## Guides\n\n- Do not generate blog content directly.\n\n- Focus on correct intent recognition and instruction generation.\n\n- Keep communication to downstream agents simple, scoped, and accurate.\n\n\n## Input Examples (and how to handle them)\n\nInput: \"I want to write about RAGFlow.\"\n\u2192 Output: Informative Guide, Audience: AI developers, Intent: explain what RAGFlow is and its use cases\n\nInput: \"Need a blog to promote our prompt design tool.\"\n\u2192 Output: Marketing Content, Audience: product managers or tool adopters, Intent: raise awareness and interest in the product\n\nInput: \"How to get more Google traffic using AI\"\n\u2192 Output: How-to, Audience: SEO marketers, Intent: guide readers on applying AI for SEO growth", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Agent", + "id": "Agent:SlickSpidersTurn", + "name": "Outline Agent", + "params": { + "delay_after_error": 1, + "description": "Generates a clear and SEO-friendly blog outline using H2/H3 headings based on the topic, audience, and intent provided by the lead agent. Each section includes suggested keywords for optimized downstream writing.\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 2, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Outline Agent**, a sub-agent in a multi-agent SEO blog writing system. You operate under the instruction of the `Lead Agent`, and your sole responsibility is to create a clear, well-structured, and SEO-optimized blog outline.\n\n# Tool Access:\n\n- You have access to a search tool called `Tavily Search`.\n\n- If you are unsure how to structure a section, you may call this tool to search for related blog outlines or content from Google.\n\n- Do not overuse it. Your job is to extract **structure**, not to write paragraphs.\n\n\n# Goals\n\n1. Create a well-structured outline with appropriate H2 and H3 headings.\n\n2. Ensure logical flow from introduction to conclusion.\n\n3. Assign 1\u20132 suggested long-tail keywords to each major section for SEO alignment.\n\n4. Make the structure suitable for downstream paragraph writing.\n\n\n\n\n#Note\n\n- Use concise, scannable section titles.\n\n- Do not write full paragraphs.\n\n- Prioritize clarity, logical progression, and SEO alignment.\n\n\n\n- If the blog type is \u201cTutorial\u201d or \u201cHow-to\u201d, include step-based sections.\n\n\n# Input\n\nYou will receive:\n\n- Writing Type (e.g., Tutorial, Informative Guide)\n\n- Target Audience\n\n- User Intent Summary\n\n- 3\u20135 long-tail keywords\n\n\nUse this information to design a structure that both informs readers and maximizes search engine visibility.\n\n# Output Format\n\n```markdown\n\n## Blog Title (suggested)\n\n[Give a short, SEO-friendly title suggestion]\n\n## Outline\n\n### Introduction\n\n- Purpose of the article\n\n- Brief context\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 1]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 2]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 3]\n\n- [Optional H3 Subsection Title A]\n\n - [Explanation of sub-point]\n\n- [Optional H3 Subsection Title B]\n\n - [Explanation of sub-point]\n\n- **Suggested keywords**: [keyword1]\n\n### Conclusion\n\n- Recap key takeaways\n\n- Optional CTA (Call to Action)\n\n- **Suggested keywords**: [keyword3]\n\n", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + }, + { + "component_name": "Agent", + "id": "Agent:IcyPawsRescue", + "name": "Body Agent", + "params": { + "delay_after_error": 1, + "description": "Writes the full blog content section-by-section following the outline structure. It integrates target keywords naturally and uses Tavily Search only when additional facts or examples are needed.\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Body Agent**, a sub-agent in a multi-agent SEO blog writing system. You operate under the instruction of the `Lead Agent`, and your job is to write the full blog content based on the outline created by the `OutlineWriter_Agent`.\n\n\n\n# Tool Access:\n\nYou can use the `Tavily Search` tool to retrieve relevant content, statistics, or examples to support each section you're writing.\n\nUse it **only** when the provided outline lacks enough information, or if the section requires factual grounding.\n\nAlways cite the original link or indicate source where possible.\n\n\n# Goals\n\n1. Write each section (based on H2/H3 structure) as a complete and natural blog paragraph.\n\n2. Integrate the suggested long-tail keywords naturally into each section.\n\n3. When appropriate, use the `Tavily Search` tool to enrich your writing with relevant facts, examples, or quotes.\n\n4. Ensure each section is clear, engaging, and informative, suitable for both human readers and search engines.\n\n\n# Style Guidelines\n\n- Write in a tone appropriate to the audience. Be explanatory, not promotional, unless it's a marketing blog.\n\n- Avoid generic filler content. Prioritize clarity, structure, and value.\n\n- Ensure SEO keywords are embedded seamlessly, not forcefully.\n\n\n\n- Maintain writing rhythm. Vary sentence lengths. Use transitions between ideas.\n\n\n# Input\n\n\nYou will receive:\n\n- Blog title\n\n- Structured outline (including section titles, keywords, and descriptions)\n\n- Target audience\n\n- Blog type and user intent\n\nYou must **follow the outline strictly**. Write content **section-by-section**, based on the structure.\n\n\n# Output Format\n\n```markdown\n\n## H2: [Section Title]\n\n[Your generated content for this section \u2014 500-600 words, using keywords naturally.]\n\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + }, + { + "component_name": "Agent", + "id": "Agent:TenderAdsAllow", + "name": "Editor Agent", + "params": { + "delay_after_error": 1, + "description": "Polishes and finalizes the entire blog post. Enhances clarity, checks keyword usage, improves flow, and generates a meta title and description for SEO. Operates after all sections are completed.\n\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 2, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Editor Agent**, the final agent in a multi-agent SEO blog writing workflow. You are responsible for finalizing the blog post for both human readability and SEO effectiveness.\n\n# Goals\n\n1. Polish the entire blog content for clarity, coherence, and style.\n\n2. Improve transitions between sections, ensure logical flow.\n\n3. Verify that keywords are used appropriately and effectively.\n\n4. Conduct a lightweight SEO audit \u2014 checking keyword density, structure (H1/H2/H3), and overall searchability.\n\n\n\n## Integration Responsibilities\n\n- Maintain alignment with Lead Agent's original intent and audience\n\n- Preserve the structure and keyword strategy from Outline Agent\n\n- Enhance and polish Body Agent's content without altering core information\n\n# Style Guidelines\n\n- Be precise. Avoid bloated or vague language.\n\n- Maintain an informative and engaging tone, suitable to the target audience.\n\n- Do not remove keywords unless absolutely necessary for clarity.\n\n- Ensure paragraph flow and section continuity.\n\n\n\n# Input\n\nYou will receive:\n\n- Full blog content, written section-by-section\n\n- Original outline with suggested keywords\n\n- Target audience and writing type\n\n# Output Format\n\n```markdown\n\n[The revised, fully polished blog post content goes here.]\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Message:ModernSwansThrow": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:LuckyApplesGrab@content}" + ] + } + }, + "upstream": [ + "Agent:LuckyApplesGrab" + ] + }, + "begin": { + "downstream": [ + "Agent:LuckyApplesGrab" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your SEO blog assistant.\n\nTo get started, please tell me:\n1. What topic you want the blog to cover\n2. Who is the target audience\n3. What you hope to achieve with this blog (e.g., SEO traffic, teaching beginners, promoting a product)\n" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:LuckyApplesGrabend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:LuckyApplesGrab", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:LuckyApplesGrabstart-Message:ModernSwansThrowend", + "source": "Agent:LuckyApplesGrab", + "sourceHandle": "start", + "target": "Message:ModernSwansThrow", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:LuckyApplesGrabagentBottom-Agent:SlickSpidersTurnagentTop", + "source": "Agent:LuckyApplesGrab", + "sourceHandle": "agentBottom", + "target": "Agent:SlickSpidersTurn", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:LuckyApplesGrabagentBottom-Agent:IcyPawsRescueagentTop", + "source": "Agent:LuckyApplesGrab", + "sourceHandle": "agentBottom", + "target": "Agent:IcyPawsRescue", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:LuckyApplesGrabagentBottom-Agent:TenderAdsAllowagentTop", + "source": "Agent:LuckyApplesGrab", + "sourceHandle": "agentBottom", + "target": "Agent:TenderAdsAllow", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:SlickSpidersTurntool-Tool:ThreeWallsRingend", + "source": "Agent:SlickSpidersTurn", + "sourceHandle": "tool", + "target": "Tool:ThreeWallsRing", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:IcyPawsRescuetool-Tool:FloppyJokesItchend", + "source": "Agent:IcyPawsRescue", + "sourceHandle": "tool", + "target": "Tool:FloppyJokesItch", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your SEO blog assistant.\n\nTo get started, please tell me:\n1. What topic you want the blog to cover\n2. Who is the target audience\n3. What you hope to achieve with this blog (e.g., SEO traffic, teaching beginners, promoting a product)\n" + }, + "label": "Begin", + "name": "begin" + }, + "dragging": false, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 38.19445084117184, + "y": 183.9781832844475 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Lead Agent**, responsible for initiating the multi-agent SEO blog generation process. You will receive the user\u2019s topic and blog goal, interpret the intent, and coordinate the downstream writing agents.\n\n# Goals\n\n1. Parse the user's initial input.\n\n2. Generate a high-level blog intent summary and writing plan.\n\n3. Provide clear instructions to the following Sub_Agents:\n\n - `Outline Agent` \u2192 Create the blog outline.\n\n - `Body Agent` \u2192 Write all sections based on outline.\n\n - `Editor Agent` \u2192 Polish and finalize the blog post.\n\n4. Merge outputs into a complete, readable blog draft in Markdown format.\n\n# Input\n\nYou will receive:\n\n- Blog topic\n\n- Target audience\n\n- Blog goal (e.g., SEO, education, product marketing)\n\n# Output Format\n\n```markdown\n\n## Parsed Writing Plan\n\n- **Topic**: [Extracted from user input]\n\n- **Audience**: [Summarized from user input]\n\n- **Intent**: [Inferred goal and style]\n\n- **Blog Type**: [e.g., Tutorial / Informative Guide / Marketing Content]\n\n- **Long-tail Keywords**: \n\n - keyword 1\n\n - keyword 2\n\n - keyword 3\n\n - ...\n\n## Instructions for Outline Agent\n\nPlease generate a structured outline including H2 and H3 headings. Assign 1\u20132 relevant keywords to each section. Keep it aligned with the user\u2019s intent and audience level.\n\n## Instructions for Body Agent\n\nWrite the full content based on the outline. Each section should be concise (500\u2013600 words), informative, and optimized for SEO. Use `Tavily Search` only when additional examples or context are needed.\n\n## Instructions for Editor Agent\n\nReview and refine the combined content. Improve transitions, ensure keyword integration, and add a meta title + meta description. Maintain Markdown formatting.\n\n\n## Guides\n\n- Do not generate blog content directly.\n\n- Focus on correct intent recognition and instruction generation.\n\n- Keep communication to downstream agents simple, scoped, and accurate.\n\n\n## Input Examples (and how to handle them)\n\nInput: \"I want to write about RAGFlow.\"\n\u2192 Output: Informative Guide, Audience: AI developers, Intent: explain what RAGFlow is and its use cases\n\nInput: \"Need a blog to promote our prompt design tool.\"\n\u2192 Output: Marketing Content, Audience: product managers or tool adopters, Intent: raise awareness and interest in the product\n\nInput: \"How to get more Google traffic using AI\"\n\u2192 Output: How-to, Audience: SEO marketers, Intent: guide readers on applying AI for SEO growth", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Lead Agent" + }, + "id": "Agent:LuckyApplesGrab", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 350, + "y": 200 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:LuckyApplesGrab@content}" + ] + }, + "label": "Message", + "name": "Response" + }, + "dragging": false, + "id": "Message:ModernSwansThrow", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 669.394830760932, + "y": 190.72421137520644 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "Generates a clear and SEO-friendly blog outline using H2/H3 headings based on the topic, audience, and intent provided by the lead agent. Each section includes suggested keywords for optimized downstream writing.\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 2, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Outline Agent**, a sub-agent in a multi-agent SEO blog writing system. You operate under the instruction of the `Lead Agent`, and your sole responsibility is to create a clear, well-structured, and SEO-optimized blog outline.\n\n# Tool Access:\n\n- You have access to a search tool called `Tavily Search`.\n\n- If you are unsure how to structure a section, you may call this tool to search for related blog outlines or content from Google.\n\n- Do not overuse it. Your job is to extract **structure**, not to write paragraphs.\n\n\n# Goals\n\n1. Create a well-structured outline with appropriate H2 and H3 headings.\n\n2. Ensure logical flow from introduction to conclusion.\n\n3. Assign 1\u20132 suggested long-tail keywords to each major section for SEO alignment.\n\n4. Make the structure suitable for downstream paragraph writing.\n\n\n\n\n#Note\n\n- Use concise, scannable section titles.\n\n- Do not write full paragraphs.\n\n- Prioritize clarity, logical progression, and SEO alignment.\n\n\n\n- If the blog type is \u201cTutorial\u201d or \u201cHow-to\u201d, include step-based sections.\n\n\n# Input\n\nYou will receive:\n\n- Writing Type (e.g., Tutorial, Informative Guide)\n\n- Target Audience\n\n- User Intent Summary\n\n- 3\u20135 long-tail keywords\n\n\nUse this information to design a structure that both informs readers and maximizes search engine visibility.\n\n# Output Format\n\n```markdown\n\n## Blog Title (suggested)\n\n[Give a short, SEO-friendly title suggestion]\n\n## Outline\n\n### Introduction\n\n- Purpose of the article\n\n- Brief context\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 1]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 2]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 3]\n\n- [Optional H3 Subsection Title A]\n\n - [Explanation of sub-point]\n\n- [Optional H3 Subsection Title B]\n\n - [Explanation of sub-point]\n\n- **Suggested keywords**: [keyword1]\n\n### Conclusion\n\n- Recap key takeaways\n\n- Optional CTA (Call to Action)\n\n- **Suggested keywords**: [keyword3]\n\n", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Outline Agent" + }, + "dragging": false, + "id": "Agent:SlickSpidersTurn", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 100.60137004146719, + "y": 411.67654846431367 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "Writes the full blog content section-by-section following the outline structure. It integrates target keywords naturally and uses Tavily Search only when additional facts or examples are needed.\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Body Agent**, a sub-agent in a multi-agent SEO blog writing system. You operate under the instruction of the `Lead Agent`, and your job is to write the full blog content based on the outline created by the `OutlineWriter_Agent`.\n\n\n\n# Tool Access:\n\nYou can use the `Tavily Search` tool to retrieve relevant content, statistics, or examples to support each section you're writing.\n\nUse it **only** when the provided outline lacks enough information, or if the section requires factual grounding.\n\nAlways cite the original link or indicate source where possible.\n\n\n# Goals\n\n1. Write each section (based on H2/H3 structure) as a complete and natural blog paragraph.\n\n2. Integrate the suggested long-tail keywords naturally into each section.\n\n3. When appropriate, use the `Tavily Search` tool to enrich your writing with relevant facts, examples, or quotes.\n\n4. Ensure each section is clear, engaging, and informative, suitable for both human readers and search engines.\n\n\n# Style Guidelines\n\n- Write in a tone appropriate to the audience. Be explanatory, not promotional, unless it's a marketing blog.\n\n- Avoid generic filler content. Prioritize clarity, structure, and value.\n\n- Ensure SEO keywords are embedded seamlessly, not forcefully.\n\n\n\n- Maintain writing rhythm. Vary sentence lengths. Use transitions between ideas.\n\n\n# Input\n\n\nYou will receive:\n\n- Blog title\n\n- Structured outline (including section titles, keywords, and descriptions)\n\n- Target audience\n\n- Blog type and user intent\n\nYou must **follow the outline strictly**. Write content **section-by-section**, based on the structure.\n\n\n# Output Format\n\n```markdown\n\n## H2: [Section Title]\n\n[Your generated content for this section \u2014 500-600 words, using keywords naturally.]\n\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Body Agent" + }, + "dragging": false, + "id": "Agent:IcyPawsRescue", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 439.3374395738501, + "y": 366.1408588516909 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "Polishes and finalizes the entire blog post. Enhances clarity, checks keyword usage, improves flow, and generates a meta title and description for SEO. Operates after all sections are completed.\n\n", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 2, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Editor Agent**, the final agent in a multi-agent SEO blog writing workflow. You are responsible for finalizing the blog post for both human readability and SEO effectiveness.\n\n# Goals\n\n1. Polish the entire blog content for clarity, coherence, and style.\n\n2. Improve transitions between sections, ensure logical flow.\n\n3. Verify that keywords are used appropriately and effectively.\n\n4. Conduct a lightweight SEO audit \u2014 checking keyword density, structure (H1/H2/H3), and overall searchability.\n\n\n\n## Integration Responsibilities\n\n- Maintain alignment with Lead Agent's original intent and audience\n\n- Preserve the structure and keyword strategy from Outline Agent\n\n- Enhance and polish Body Agent's content without altering core information\n\n# Style Guidelines\n\n- Be precise. Avoid bloated or vague language.\n\n- Maintain an informative and engaging tone, suitable to the target audience.\n\n- Do not remove keywords unless absolutely necessary for clarity.\n\n- Ensure paragraph flow and section continuity.\n\n\n\n# Input\n\nYou will receive:\n\n- Full blog content, written section-by-section\n\n- Original outline with suggested keywords\n\n- Target audience and writing type\n\n# Output Format\n\n```markdown\n\n[The revised, fully polished blog post content goes here.]\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Editor Agent" + }, + "dragging": false, + "id": "Agent:TenderAdsAllow", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 730.8513124709204, + "y": 327.351197329827 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "dragging": false, + "id": "Tool:ThreeWallsRing", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": -26.93431957115564, + "y": 531.4384641920368 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_1" + }, + "dragging": false, + "id": "Tool:FloppyJokesItch", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 414.6786783453011, + "y": 499.39483076093194 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "text": "This is a multi-agent version of the SEO blog generation workflow. It simulates a small team of AI \u201cwriters\u201d, where each agent plays a specialized role \u2014 just like a real editorial team.\n\nInstead of one AI doing everything in order, this version uses a **Lead Agent** to assign tasks to different sub-agents, who then write and edit the blog in parallel. The Lead Agent manages everything and produces the final output.\n\n### Why use multi-agent format?\n\n- Better control over each stage of writing \n- Easier to reuse agents across tasks \n- More human-like workflow (planning \u2192 writing \u2192 editing \u2192 publishing) \n- Easier to scale and customize for advanced users\n\n### Flow Summary:\n\n1. `LeadWriter_Agent` takes your input and creates a plan\n2. It sends that plan to:\n - `OutlineWriter_Agent`: build blog structure\n - `BodyWriter_Agent`: write full content\n - `FinalEditor_Agent`: polish and finalize\n3. `LeadWriter_Agent` collects all results and outputs the final blog post\n" + }, + "label": "Note", + "name": "Workflow Overall Description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 208, + "id": "Note:ElevenVansInvent", + "measured": { + "height": 208, + "width": 518 + }, + "position": { + "x": -336.6586460874556, + "y": 113.43253511344867 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 518 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis is the central agent that controls the entire writing process.\n\n**What it does**:\n- Reads your blog topic and intent\n- Generates a clear writing plan (topic, audience, goal, keywords)\n- Sends instructions to all sub-agents\n- Waits for their responses and checks quality\n- If any section is missing or weak, it can request a rewrite\n- Finally, it assembles all parts into a complete blog and sends it back to you\n" + }, + "label": "Note", + "name": "Lead Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 146, + "id": "Note:EmptyClubsGreet", + "measured": { + "height": 146, + "width": 334 + }, + "position": { + "x": 390.1408623279084, + "y": 2.6521144030202493 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 334 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis agent is responsible for building the blog's structure. It creates an outline that shows what the article will cover and how it's organized.\n\n**What it does**:\n- Suggests a blog title that matches the topic and keywords \n- Breaks the article into sections using H2 and H3 headers \n- Adds a short description of what each section should include \n- Assigns SEO keywords to each section for better search visibility \n- Uses search data (via Tavily Search) to find how similar blogs are structured" + }, + "label": "Note", + "name": "Outline Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 157, + "id": "Note:CurlyTigersDouble", + "measured": { + "height": 157, + "width": 394 + }, + "position": { + "x": -60.03139680691618, + "y": 595.8208080534818 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 394 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis agent is in charge of writing the full blog content, section by section, based on the outline it receives.\n\n**What it does**:\n- Takes each section heading from the outline (H2 / H3)\n- Writes a complete paragraph (150\u2013220 words) under each section\n- Naturally includes the keywords provided for that section\n- Uses the Tavily Search tool to add real-world examples, definitions, or facts if needed\n- Makes sure each section is clear, useful, and easy to read\n" + }, + "label": "Note", + "name": "Body Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 164, + "id": "Note:StrongKingsCamp", + "measured": { + "height": 164, + "width": 408 + }, + "position": { + "x": 446.54943226110845, + "y": 590.9443887062529 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 408 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis agent reviews, polishes, and finalizes the blog post written by the BodyWriter_Agent. It ensures everything is clean, smooth, and SEO-compliant.\n\n**What it does**:\n- Improves grammar, sentence flow, and transitions \n- Makes sure the content reads naturally and professionally \n- Checks whether keywords are present and well integrated (but not overused) \n- Verifies that the structure follows the correct H1/H2/H3 format \n" + }, + "label": "Note", + "name": "Editor Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 147, + "id": "Note:OpenOttersShow", + "measured": { + "height": 147, + "width": 357 + }, + "position": { + "x": 976.6858726228803, + "y": 422.7404806291804 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 357 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AE1SnRXBNdNRMlefT6g7aY6giK+cPLGNg0bY68rcnpsNh9PqIBve/EcPQ3WIq2dR93xpSgk5SAZ9R6MLAOZFUkpLSUDXp6/KPpGUkmTdswlnKnwbl5ITMdGwcXJi7LKsqzUmT5tWYmkXuF9wjBvb76b7dHheazJ9RElUJOCxViuMlUJC0Gtz6PKyjLBY4qMWUe12r1xZ6lOyT6XPEBKN2CkTDOlZd02TBdTMt7Upx2knrkdCv1UKjDKn1A7XBYH6SCOOrWn5Oi/DtRiu+GleRthDL8rXdVjZlcfWrSIxVlGGGCOnH//Z" +} \ No newline at end of file diff --git a/agent/templates/image_lingo.json b/agent/templates/image_lingo.json new file mode 100644 index 00000000000..2fba05b8486 --- /dev/null +++ b/agent/templates/image_lingo.json @@ -0,0 +1,269 @@ +{ + "id": 13, + "title": { + "en": "ImageLingo", + "de": "ImageLingo", + "zh": "图片解析"}, + "description": { + "en": "ImageLingo lets you snap any photo containing text—menus, signs, or documents—and instantly recognize and translate it into your language of choice using advanced AI-powered translation technology.", + "de": "ImageLingo ermöglicht es Ihnen, jedes Foto mit Text – Menüs, Schilder oder Dokumente – zu fotografieren und es sofort in Ihre gewünschte Sprache zu erkennen und zu übersetzen, unter Verwendung fortschrittlicher KI-gestützter Übersetzungstechnologie.", + "zh": "多模态大模型允许您拍摄任何包含文本的照片——菜单、标志或文档——立即识别并转换成您选择的语言。"}, + "canvas_type": "Consumer App", + "dsl": { + "components": { + "Agent:CoolPandasCrash": { + "downstream": [ + "Message:CurlyApplesRelate" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_goto": [], + "exception_method": null, + "frequency_penalty": 0.7, + "frequencyPenaltyEnabled": false, + "llm_filter": "image2text", + "llm_id": "qwen-vl-plus@Tongyi-Qianwen", + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "maxTokensEnabled": false, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + }, + "structured_output": {} + }, + "presence_penalty": 0.4, + "presencePenaltyEnabled": false, + "prompts": [ + { + "content": "The user query is {sys.query}\n\n\n", + "role": "user" + } + ], + "sys_prompt": "You are a multilingual translation assistant that works from images. When given a photo of any text or scene, you should:\n\n\n\n1. Detect and extract all written text in the image, regardless of font, orientation, or style. \n\n2. Identify the source language of the extracted text. \n\n3. Determine the target language:\n\n - If the user explicitly specifies a language, use that.\n\n - If no language is specified, automatically detect the user’s spoken language and use that as the target. \n\n4. Translate the content accurately into the target language, preserving meaning, tone, and formatting (e.g., line breaks, punctuation). \n\n5. If the image contains signage, menus, labels, or other contextual text, adapt the translation to be natural and context-appropriate for daily use. \n\n6. Return the translated text in plain, well-formatted paragraphs. If the user asks, also provide transliteration for non-Latin scripts. \n\n7. If the image is unclear or the target language cannot be determined, ask a clarifying follow-up question.\n\n\nExample:\n\nUser: “Translate this photo for me.”\n\nAgent Input: [Image of a Japanese train schedule]\n\nAgent Output:\n\n“7:30 AM – 東京駅 (Tokyo Station) \n\n8:15 AM – 新大阪 (Shin-Osaka)” \n\n(Detected user language: English)```\n\n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "top_p": 0.3, + "topPEnabled": false, + "user_prompt": "", + "visual_files_var": "sys.files" + } + }, + "upstream": [ + "begin" + ] + }, + "begin": { + "downstream": [ + "Agent:CoolPandasCrash" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi there! I’m ImageLingo, your on-the-go image translation assistant—just snap a photo, and I’ll instantly translate and adapt it into your language." + } + }, + "upstream": [] + }, + "Message:CurlyApplesRelate": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:CoolPandasCrash@content}" + ] + } + }, + "upstream": [ + "Agent:CoolPandasCrash" + ] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:CoolPandasCrashend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:CoolPandasCrash", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:CoolPandasCrashstart-Message:CurlyApplesRelateend", + "source": "Agent:CoolPandasCrash", + "sourceHandle": "start", + "target": "Message:CurlyApplesRelate", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi there! I’m ImageLingo, your on-the-go image translation assistant—just snap a photo, and I’ll instantly translate and adapt it into your language." + }, + "label": "Begin", + "name": "begin" + }, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_goto": "", + "exception_method": null, + "frequency_penalty": 0.7, + "frequencyPenaltyEnabled": false, + "llm_filter": "image2text", + "llm_id": "qwen-vl-plus@Tongyi-Qianwen", + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "maxTokensEnabled": false, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + }, + "structured_output": {} + }, + "presence_penalty": 0.4, + "presencePenaltyEnabled": false, + "prompts": [ + { + "content": "The user query is {sys.query}\n\n\n", + "role": "user" + } + ], + "sys_prompt": "You are a multilingual translation assistant that works from images. When given a photo of any text or scene, you should:\n\n\n\n1. Detect and extract all written text in the image, regardless of font, orientation, or style. \n\n2. Identify the source language of the extracted text. \n\n3. Determine the target language:\n\n - If the user explicitly specifies a language, use that.\n\n - If no language is specified, automatically detect the user’s spoken language and use that as the target. \n\n4. Translate the content accurately into the target language, preserving meaning, tone, and formatting (e.g., line breaks, punctuation). \n\n5. If the image contains signage, menus, labels, or other contextual text, adapt the translation to be natural and context-appropriate for daily use. \n\n6. Return the translated text in plain, well-formatted paragraphs. If the user asks, also provide transliteration for non-Latin scripts. \n\n7. If the image is unclear or the target language cannot be determined, ask a clarifying follow-up question.\n\n\nExample:\n\nUser: “Translate this photo for me.”\n\nAgent Input: [Image of a Japanese train schedule]\n\nAgent Output:\n\n“7:30 AM – 東京駅 (Tokyo Station) \n\n8:15 AM – 新大阪 (Shin-Osaka)” \n\n(Detected user language: English)```\n\n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "top_p": 0.3, + "topPEnabled": false, + "user_prompt": "", + "visual_files_var": "sys.files" + }, + "label": "Agent", + "name": "Translation Agent With Vision" + }, + "dragging": false, + "id": "Agent:CoolPandasCrash", + "measured": { + "height": 85, + "width": 200 + }, + "position": { + "x": 350.5, + "y": 200 + }, + "selected": true, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:CoolPandasCrash@content}" + ] + }, + "label": "Message", + "name": "Message" + }, + "id": "Message:CurlyApplesRelate", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 650, + "y": 200 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "ImageLingo lets you snap any photo containing text—menus, signs, or documents—and instantly recognize and translate it into your language of choice using advanced OCR and AI-powered translation technology. With automatic source-language detection and context-aware adaptations, translations preserve formatting, tone, and intent. Your on-the-go language assistant. " + }, + "label": "Note", + "name": "Translation Agent" + }, + "dragging": false, + "dragHandle": ".note-drag-handle", + "height": 190, + "id": "Note:OpenCobrasMarry", + "measured": { + "height": 190, + "width": 376 + }, + "position": { + "x": 385.5, + "y": -42 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 376 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACX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IoVGjB4zChPp4UbmbV5uDtJSUmHmYlNSUiKTB14tvif4kKTSPMSfKYTjh2Hh8KDxTFivLZRP37fh9VdUj/vhxNQM2LOGYPvXX+D+Z1+R8ltscBu5dyz+XCAydVZ+yOujKdbS2ooKcptf3fUzXDdnFk5SH48iNIbEbicX5A/45C6lFO00TlVDEVEfjkj7cHSCLXdz2OCgDh7DxAbEkrWG1RWTJ097RO7U+8L+ZUooMIPwOEY1JHAz2QAdDU9hWAfEhxIRFILHCxYqHqhGNsP7SHPLcrKxZ9NbsJEtOvnwhvWvodBmw1Hu6tgYVbFXHNszE0wzlZQ6glgx81T5WSOFUkR5hft3BSOLCEXlGJ9fmZAQXCbOyQXM+sWjzu3Ll8+iBlsW6ut+GMJTcYOooBDYfPcSsYYNLYWnrYneDMJEiuzgBvbc667G/OlTUf/hZjR3tPDogL/lMmY+8RzrgbzH4+7ftUtgJC+2NhHJLEyRYFQ2Dmw9Cd0c/+pfg7hGbpQrK0yGwLKxY2c5Y9Ef9Dq//YuCFWveXLbu8x1XWRNNY5IMWiSxkB1sVBVsLufYuDpZtMXp3NgmrNpIvsryWfBEDYg5Ko0yczQ56sHfIkRYDgnSBbV/g0MkSBeFj41bU0lmkkhGVdKAK/7kJjaSjAr9eqbVx4qq2TJlyrQd8fb+H90isRVH8mIAAAAAAElFTkSuQmCC" +} \ No newline at end of file diff --git a/agent/templates/interpreter.json b/agent/templates/interpreter.json deleted file mode 100644 index 7f31dfe0b72..00000000000 --- a/agent/templates/interpreter.json +++ /dev/null @@ -1,475 +0,0 @@ -{ - "id": 4, - "title": "Interpreter", - "description": "A translation agent based on a reflection agentic workflow, inspired by Andrew Ng's project: https://github.com/andrewyng/translation-agent\n\n1. Prompt an LLM to translate a text into the target language.\n2. Have the LLM reflect on the translation and provide constructive suggestions for improvement.\n3. Use these suggestions to improve the translation.", - "canvas_type": "chatbot", - "dsl": { - "answer": [], - "components": { - "Answer:TinyGamesGuess": { - "downstream": [], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "Generate:FuzzyEmusWork" - ] - }, - "Generate:FuzzyEmusWork": { - "downstream": [ - "Answer:TinyGamesGuess" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Your task is to carefully read, then edit, a translation to {begin@lang}, taking into\naccount a list of expert suggestions and constructive criticisms.\n\nThe source text, the initial translation, and the expert linguist suggestions are delimited by XML tags , and \nas follows:\n\n\n{begin@file}\n\n\n\n{Generate:VastKeysKick}\n\n\n\n{Generate:ShinySquidsSneeze}\n\n\nPlease take into account the expert suggestions when editing the translation. Edit the translation by ensuring:\n\n(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n(ii) fluency (by applying {begin@lang} grammar, spelling and punctuation rules and ensuring there are no unnecessary repetitions), \n(iii) style (by ensuring the translations reflect the style of the source text)\n(iv) terminology (inappropriate for context, inconsistent use), or\n(v) other errors.\n\nOutput only the new translation and nothing else.", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Generate:ShinySquidsSneeze" - ] - }, - "Generate:ShinySquidsSneeze": { - "downstream": [ - "Generate:FuzzyEmusWork" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Your task is to carefully read a source text and a translation to {begin@lang}, and then give constructive criticisms and helpful suggestions to improve the translation. \n\nThe source text and initial translation, delimited by XML tags and , are as follows:\n\n\n{begin@file}\n\n\n\n{Generate:VastKeysKick}\n\n\nWhen writing suggestions, pay attention to whether there are ways to improve the translation's \n(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n(ii) fluency (by applying {begin@lang} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n(iii) style (by ensuring the translations reflect the style of the source text and take into account any cultural context),\n(iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {begin@lang}).\n\nWrite a list of specific, helpful and constructive suggestions for improving the translation.\nEach suggestion should address one specific part of the translation.\nOutput only the suggestions and nothing else.", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Generate:VastKeysKick" - ] - }, - "Generate:VastKeysKick": { - "downstream": [ - "Generate:ShinySquidsSneeze" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are a professional translator proficient in {begin@lang}, with an exceptional ability to convert specialized academic papers into accessible popular science articles. Please assist me in translating the following paragraph into {begin@lang}, ensuring that its style resembles that of popular science articles in {begin@lang}.\n\nRequirements & Restrictions:\n - Use Markdown format to output.\n - DO NOT overlook any details.\n\n\n\n{begin@file}\n\n", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "begin" - ] - }, - "begin": { - "downstream": [ - "Generate:VastKeysKick" - ], - "obj": { - "component_name": "Begin", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "prologue": "", - "query": [ - { - "key": "lang", - "name": "Target Language", - "optional": false, - "type": "line" - }, - { - "key": "file", - "name": "Files", - "optional": false, - "type": "file" - } - ] - } - }, - "upstream": [] - } - }, - "embed_id": "", - "graph": { - "edges": [ - { - "id": "xy-edge__begin-Generate:VastKeysKickc", - "markerEnd": "logo", - "source": "begin", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:VastKeysKick", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:VastKeysKickb-Generate:ShinySquidsSneezec", - "markerEnd": "logo", - "source": "Generate:VastKeysKick", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:ShinySquidsSneeze", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:FuzzyEmusWorkb-Answer:TinyGamesGuessc", - "markerEnd": "logo", - "source": "Generate:FuzzyEmusWork", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:TinyGamesGuess", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:ShinySquidsSneezeb-Generate:FuzzyEmusWorkc", - "markerEnd": "logo", - "source": "Generate:ShinySquidsSneeze", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:FuzzyEmusWork", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - } - ], - "nodes": [ - { - "data": { - "form": { - "prologue": "", - "query": [ - { - "key": "lang", - "name": "Target Language", - "optional": false, - "type": "line" - }, - { - "key": "file", - "name": "Files", - "optional": false, - "type": "file" - } - ] - }, - "label": "Begin", - "name": "begin" - }, - "dragging": false, - "height": 128, - "id": "begin", - "measured": { - "height": 128, - "width": 200 - }, - "position": { - "x": -383.5, - "y": 142.62256327439624 - }, - "positionAbsolute": { - "x": -383.5, - "y": 143.5 - }, - "selected": true, - "sourcePosition": "left", - "targetPosition": "right", - "type": "beginNode", - "width": 200 - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "Interact_0" - }, - "dragging": false, - "height": 44, - "id": "Answer:TinyGamesGuess", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 645.5056004454161, - "y": 182.98193827439627 - }, - "positionAbsolute": { - "x": 688.5, - "y": 183.859375 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "Translation Agent: Agentic translation using reflection workflow\n\nThis is inspired by Andrew NG's project: https://github.com/andrewyng/translation-agent\n\n1. Prompt an LLM to translate a text into the target language;\n2. Have the LLM reflect on the translation and provide constructive suggestions for improvement;\n3. Use these suggestions to improve the translation." - }, - "label": "Note", - "name": "Brief" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 227, - "id": "Note:MoodyKnivesCheat", - "measured": { - "height": 227, - "width": 703 - }, - "position": { - "x": 46.02198421645994, - "y": -267.69527832581736 - }, - "positionAbsolute": { - "x": 46.02198421645994, - "y": -267.69527832581736 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 227, - "width": 703 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 703 - }, - { - "data": { - "form": { - "text": "Many businesses use specialized terms that are not widely used on the internet and that LLMs thus don’t know about, and there are also many terms that can be translated in multiple ways. For example, ”open source” in Spanish can be “Código abierto” or “Fuente abierta”; both are fine, but it’d better to pick one and stick with it for a single document.\n\nYou can add those glossary translation into prompt to any of `Translate directly` or 'Reflect'." - }, - "label": "Note", - "name": "Tip: Add glossary " - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 181, - "id": "Note:SourCarrotsAct", - "measured": { - "height": 181, - "width": 832 - }, - "position": { - "x": 65.0676250238289, - "y": 397.6323270065299 - }, - "positionAbsolute": { - "x": 65.0676250238289, - "y": 397.6323270065299 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 181, - "width": 832 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 832 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are a professional translator proficient in {begin@lang}, with an exceptional ability to convert specialized academic papers into accessible popular science articles. Please assist me in translating the following paragraph into {begin@lang}, ensuring that its style resembles that of popular science articles in {begin@lang}.\n\nRequirements & Restrictions:\n - Use Markdown format to output.\n - DO NOT overlook any details.\n\n\n\n{begin@file}\n\n", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Translate directly" - }, - "dragging": false, - "id": "Generate:VastKeysKick", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": -132.6338674989604, - "y": 153.70663786774483 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Your task is to carefully read a source text and a translation to {begin@lang}, and then give constructive criticisms and helpful suggestions to improve the translation. \n\nThe source text and initial translation, delimited by XML tags and , are as follows:\n\n\n{begin@file}\n\n\n\n{Generate:VastKeysKick}\n\n\nWhen writing suggestions, pay attention to whether there are ways to improve the translation's \n(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n(ii) fluency (by applying {begin@lang} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n(iii) style (by ensuring the translations reflect the style of the source text and take into account any cultural context),\n(iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {begin@lang}).\n\nWrite a list of specific, helpful and constructive suggestions for improving the translation.\nEach suggestion should address one specific part of the translation.\nOutput only the suggestions and nothing else.", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Reflect" - }, - "dragging": false, - "id": "Generate:ShinySquidsSneeze", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 121.1675336631696, - "y": 152.92865408917177 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Your task is to carefully read, then edit, a translation to {begin@lang}, taking into\naccount a list of expert suggestions and constructive criticisms.\n\nThe source text, the initial translation, and the expert linguist suggestions are delimited by XML tags , and \nas follows:\n\n\n{begin@file}\n\n\n\n{Generate:VastKeysKick}\n\n\n\n{Generate:ShinySquidsSneeze}\n\n\nPlease take into account the expert suggestions when editing the translation. Edit the translation by ensuring:\n\n(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n(ii) fluency (by applying {begin@lang} grammar, spelling and punctuation rules and ensuring there are no unnecessary repetitions), \n(iii) style (by ensuring the translations reflect the style of the source text)\n(iv) terminology (inappropriate for context, inconsistent use), or\n(v) other errors.\n\nOutput only the new translation and nothing else.", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Improve" - }, - "dragging": false, - "id": "Generate:FuzzyEmusWork", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 383.1474420163898, - "y": 152.0472805236579 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - } - ] - }, - "history": [],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tZutald0o2vYWAAH//Z" -} diff --git a/agent/templates/investment_advisor.json b/agent/templates/investment_advisor.json deleted file mode 100644 index 338d93a0bbd..00000000000 --- a/agent/templates/investment_advisor.json +++ /dev/null @@ -1,642 +0,0 @@ -{ - "id": 8, - "title": "Intelligent investment advisor", - "description": "An intelligent investment advisor that answers your financial questions using real-time domestic financial data.", - "canvas_type": "chatbot", - "dsl": { - "answer": [], - "components": { - "AkShare:CalmHotelsKnow": { - "downstream": [ - "Generate:SolidAreasRing" - ], - "obj": { - "component_name": "AkShare", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [], - "top_n": 10 - } - }, - "upstream": [ - "KeywordExtract:BreezyGoatsRead" - ] - }, - "Answer:NeatLandsWave": { - "downstream": [ - "WenCai:TenParksOpen", - "KeywordExtract:BreezyGoatsRead" - ], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "begin", - "Generate:SolidAreasRing" - ] - }, - "Generate:SolidAreasRing": { - "downstream": [ - "Answer:NeatLandsWave" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are a professional financial counseling assistant.\n\nTask: Answer user's question based on content provided by Wencai and AkShare.\n\nNotice:\n- Output no more than 5 news items from AkShare if there's content provided by Wencai.\n- Items from AkShare MUST have a corresponding URL link.\n\n############\nContent provided by Wencai: \n{WenCai:TenParksOpen}\n\n################\nContent provided by AkShare: \n\n{AkShare:CalmHotelsKnow}\n\n\n", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "WenCai:TenParksOpen", - "AkShare:CalmHotelsKnow" - ] - }, - "KeywordExtract:BreezyGoatsRead": { - "downstream": [ - "AkShare:CalmHotelsKnow" - ], - "obj": { - "component_name": "KeywordExtract", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "", - "query": [], - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_n": 2, - "top_p": 0.3 - } - }, - "upstream": [ - "Answer:NeatLandsWave" - ] - }, - "WenCai:TenParksOpen": { - "downstream": [ - "Generate:SolidAreasRing" - ], - "obj": { - "component_name": "WenCai", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [], - "query_type": "stock", - "top_n": 5 - } - }, - "upstream": [ - "Answer:NeatLandsWave" - ] - }, - "begin": { - "downstream": [ - "Answer:NeatLandsWave" - ], - "obj": { - "component_name": "Begin", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "prologue": "Hi there!", - "query": [] - } - }, - "upstream": [] - } - }, - "embed_id": "", - "graph": { - "edges": [ - { - "id": "reactflow__edge-begin-Answer:NeatLandsWavec", - "markerEnd": "logo", - "source": "begin", - "sourceHandle": null, - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:NeatLandsWave", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Answer:NeatLandsWaveb-WenCai:TenParksOpenc", - "markerEnd": "logo", - "source": "Answer:NeatLandsWave", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "WenCai:TenParksOpen", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-KeywordExtract:BreezyGoatsReadb-AkShare:CalmHotelsKnowc", - "markerEnd": "logo", - "source": "KeywordExtract:BreezyGoatsRead", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "AkShare:CalmHotelsKnow", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Answer:NeatLandsWaveb-KeywordExtract:BreezyGoatsReadc", - "markerEnd": "logo", - "source": "Answer:NeatLandsWave", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "KeywordExtract:BreezyGoatsRead", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "xy-edge__WenCai:TenParksOpenb-Generate:SolidAreasRingb", - "markerEnd": "logo", - "source": "WenCai:TenParksOpen", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:SolidAreasRing", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__AkShare:CalmHotelsKnowb-Generate:SolidAreasRingb", - "markerEnd": "logo", - "source": "AkShare:CalmHotelsKnow", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:SolidAreasRing", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:SolidAreasRingc-Answer:NeatLandsWavec", - "markerEnd": "logo", - "source": "Generate:SolidAreasRing", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:NeatLandsWave", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - } - ], - "nodes": [ - { - "data": { - "form": { - "prologue": "Hi there!" - }, - "label": "Begin", - "name": "Opening" - }, - "dragging": false, - "height": 44, - "id": "begin", - "measured": { - "height": 44, - "width": 100 - }, - "position": { - "x": -609.7949690891593, - "y": -29.12385224725604 - }, - "positionAbsolute": { - "x": -521.8118264317484, - "y": -27.999467037576665 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "beginNode" - }, - { - "data": { - "form": { - "query_type": "stock", - "top_n": 5 - }, - "label": "WenCai", - "name": "Wencai" - }, - "dragging": false, - "height": 44, - "id": "WenCai:TenParksOpen", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -13.030801663267397, - "y": -30.557141660610256 - }, - "positionAbsolute": { - "x": -13.030801663267397, - "y": -30.557141660610256 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "top_n": 10 - }, - "label": "AkShare", - "name": "AKShare" - }, - "dragging": false, - "height": 44, - "id": "AkShare:CalmHotelsKnow", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 250.32227681412806, - "y": 74.24036022703525 - }, - "positionAbsolute": { - "x": 267.17349571786156, - "y": 100.01281266803943 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "Interact" - }, - "dragging": false, - "height": 44, - "id": "Answer:NeatLandsWave", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -304.0612563145512, - "y": -29.054278091837944 - }, - "positionAbsolute": { - "x": -304.0612563145512, - "y": -29.054278091837944 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_n": 2, - "top_p": 0.3 - }, - "label": "KeywordExtract", - "name": "Keywords" - }, - "dragging": false, - "height": 86, - "id": "KeywordExtract:BreezyGoatsRead", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": -12.734133905960277, - "y": 53.63594331206494 - }, - "positionAbsolute": { - "x": -17.690374759999543, - "y": 80.39964392387697 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "keywordNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "Receives the user's financial inquiries and displays the large model's response to financial questions." - }, - "label": "Note", - "name": "N: Interact" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 187, - "id": "Note:FuzzyPoetsLearn", - "measured": { - "height": 187, - "width": 214 - }, - "position": { - "x": -296.5982116419186, - "y": 38.77567426067935 - }, - "positionAbsolute": { - "x": -296.5982116419186, - "y": 38.77567426067935 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 162, - "width": 214 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 214 - }, - { - "data": { - "form": { - "text": "Extracts keywords based on the user's financial questions for better retrieval." - }, - "label": "Note", - "name": "N: Keywords" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 155, - "id": "Note:FlatBagsRun", - "measured": { - "height": 155, - "width": 213 - }, - "position": { - "x": -14.82895160277127, - "y": 186.52508153680787 - }, - "positionAbsolute": { - "x": -14.82895160277127, - "y": 186.52508153680787 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 155, - "width": 213 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 213 - }, - { - "data": { - "form": { - "text": "Searches on akshare for the latest news about economics based on the keywords and returns the results." - }, - "label": "Note", - "name": "N: AKShare" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:WarmClothsSort", - "measured": { - "height": 128, - "width": 283 - }, - "position": { - "x": 259.53966185269985, - "y": 209.6999260009385 - }, - "positionAbsolute": { - "x": 573.7653319987893, - "y": 102.64512355369035 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 283 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 283 - }, - { - "data": { - "form": { - "text": "Searches by Wencai to select stocks that satisfy user mentioned conditions." - }, - "label": "Note", - "name": "N: Wencai" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 143, - "id": "Note:TiredReadersWash", - "measured": { - "height": 143, - "width": 285 - }, - "position": { - "x": 251.25432007905098, - "y": -97.53719402078019 - }, - "positionAbsolute": { - "x": 571.4274792499875, - "y": -37.07105560150117 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 285 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 285 - }, - { - "data": { - "form": { - "text": "The large model answers the user's medical health questions based on the searched and retrieved content." - }, - "label": "Note", - "name": "N: LLM" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 179, - "id": "Note:TameBoatsType", - "measured": { - "height": 179, - "width": 260 - }, - "position": { - "x": -167.45710806024056, - "y": -372.5606558391346 - }, - "positionAbsolute": { - "x": -7.849538042569293, - "y": -427.90526378748035 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 163, - "width": 212 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 260 - }, - { - "data": { - "form": { - "cite": true, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are a professional financial counseling assistant.\n\nTask: Answer user's question based on content provided by Wencai and AkShare.\n\nNotice:\n- Output no more than 5 news items from AkShare if there's content provided by Wencai.\n- Items from AkShare MUST have a corresponding URL link.\n\n############\nContent provided by Wencai: \n{WenCai:TenParksOpen}\n\n################\nContent provided by AkShare: \n\n{AkShare:CalmHotelsKnow}\n\n\n", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "LLM" - }, - "dragging": false, - "id": "Generate:SolidAreasRing", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": -161.00840949957603, - "y": -180.04918322565015 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - } - ] - }, - "history": [], - "messages": [], - "path": [], - "reference": [] - }, - "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJAAAACQCAYAAADnRuK4AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAACEwAAAhMAfPPw2UAAE5xSURBVHhe7b15tC3XXR741ZnHOw/v3fvmUfMs2ZI8ISwLYwabBSYEN8RmNSE0hBWg6QR6BXcW0EPyT3qtzlrdIU1CDLEDqzGebVmyZCRkzbP05vm9O89nnqq/71dV59Y5976n93QlCOZ89+6zd+3atcevfvv327VPHccl0EMPbxMR3++hh7eFHoF62BJ6BOphS+gRqIctoUegHraEHoF62BJ6BOphS+gRqIctoUegHraEHoF62BJ6BOphS+gRqIctoUegHraEHoF62BJ6BOphS+gRqIctoUegHraEHoF62BJ6BOphS+gRqIctoUegHraEv1PfynBbDTjNBtCqAc063GaNx3W0Ggy7Td4NjqVrsUlOJAonGgOicSCWYDjB2yUBl3FOhPE9vCP4b5dAjQpQK6JVXoVTXwWqy8DaApxGgfE8rqzBLS3TraFeXkNMXHE8gdpqtVCvkzfpDCLpPrh0kVQ/kMjDjdNlhuBkBoBkP5w0/UQWiKfs2h6uDf9tEYgkcQvzcJfPwV27gEh5DigvkjBrcGol1pYEcVpkCNM2We1my8jSZLjVcimFlAmlDz8j/IhGIubbh66N6rQDt96Ek8qQTDkgO4JWegTo34nI0B44+VEgPaiM3nV84QtfwMmTJ/Hbv/3bfszfPfytE8itSLJchLt4HFg5B6cwDRTnOeVo0EUSujq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hR6AetoQegXrYEnoE6mFL6BGohy2hR6AetoQegXrYEnoE6mFL6BGohy2hR6AetoQegXrYEnoE6mFL6BGohy2hR6AetoQegXrYEnoE6mFL6BGohy2hR6AetgDg/wcjLgwY8u5DYQAAAABJRU5ErkJggg==" -} diff --git a/agent/templates/knowledge_base_report.json b/agent/templates/knowledge_base_report.json new file mode 100644 index 00000000000..38cfb715898 --- /dev/null +++ b/agent/templates/knowledge_base_report.json @@ -0,0 +1,333 @@ +{ + "id": 20, + "title": { + "en": "Report Agent Using Knowledge Base", + "de": "Berichtsagent mit Wissensdatenbank", + "zh": "知识库检索智能体"}, + "description": { + "en": "A report generation assistant using local knowledge base, with advanced capabilities in task planning, reasoning, and reflective analysis. Recommended for academic research paper Q&A", + "de": "Ein Berichtsgenerierungsassistent, der eine lokale Wissensdatenbank nutzt, mit erweiterten Fähigkeiten in Aufgabenplanung, Schlussfolgerung und reflektierender Analyse. Empfohlen für akademische Forschungspapier-Fragen und -Antworten.", + "zh": "一个使用本地知识库的报告生成助手,具备高级能力,包括任务规划、推理和反思性分析。推荐用于学术研究论文问答。"}, + "canvas_type": "Agent", + "dsl": { + "components": { + "Agent:NewPumasLick": { + "downstream": [ + "Message:OrangeYearsShine" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen3-235b-a22b-instruct-2507@Tongyi-Qianwen", + "maxTokensEnabled": true, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 128000, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "# User Query\n {sys.query}", + "role": "user" + } + ], + "sys_prompt": "## Role & Task\nYou are a **\u201cKnowledge Base Retrieval Q\\&A Agent\u201d** whose goal is to break down the user\u2019s question into retrievable subtasks, and then produce a multi-source-verified, structured, and actionable research report using the internal knowledge base.\n## Execution Framework (Detailed Steps & Key Points)\n1. **Assessment & Decomposition**\n * Actions:\n * Automatically extract: main topic, subtopics, entities (people/organizations/products/technologies), time window, geographic/business scope.\n * Output as a list: N facts/data points that must be collected (*N* ranges from 5\u201320 depending on question complexity).\n2. **Query Type Determination (Rule-Based)**\n * Example rules:\n * If the question involves a single issue but requests \u201cmethod comparison/multiple explanations\u201d \u2192 use **depth-first**.\n * If the question can naturally be split into \u22653 independent sub-questions \u2192 use **breadth-first**.\n * If the question can be answered by a single fact/specification/definition \u2192 use **simple query**.\n3. **Research Plan Formulation**\n * Depth-first: define 3\u20135 perspectives (methodology/stakeholders/time dimension/technical route, etc.), assign search keywords, target document types, and output format for each perspective.\n * Breadth-first: list subtasks, prioritize them, and assign search terms.\n * Simple query: directly provide the search sentence and required fields.\n4. **Retrieval Execution**\n * After retrieval: perform coverage check (does it contain the key facts?) and quality check (source diversity, authority, latest update time).\n * If standards are not met, automatically loop: rewrite queries (synonyms/cross-domain terms) and retry \u22643 times, or flag as requiring external search.\n5. **Integration & Reasoning**\n * Build the answer using a **fact\u2013evidence\u2013reasoning** chain. For each conclusion, attach 1\u20132 strongest pieces of evidence.\n---\n## Quality Gate Checklist (Verify at Each Stage)\n* **Stage 1 (Decomposition)**:\n * [ ] Key concepts and expected outputs identified\n * [ ] Required facts/data points listed\n* **Stage 2 (Retrieval)**:\n * [ ] Meets quality standards (see above)\n * [ ] If not met: execute query iteration\n* **Stage 3 (Generation)**:\n * [ ] Each conclusion has at least one direct evidence source\n * [ ] State assumptions/uncertainties\n * [ ] Provide next-step suggestions or experiment/retrieval plans\n * [ ] Final length and depth match user expectations (comply with word count/format if specified)\n---\n## Core Principles\n1. **Strict reliance on the knowledge base**: answers must be **fully bounded** by the content retrieved from the knowledge base.\n2. **No fabrication**: do not generate, infer, or create information that is not explicitly present in the knowledge base.\n3. **Accuracy first**: prefer incompleteness over inaccurate content.\n4. **Output format**:\n * Hierarchically clear modular structure\n * Logical grouping according to the MECE principle\n * Professionally presented formatting\n * Step-by-step cognitive guidance\n * Reasonable use of headings and dividers for clarity\n * *Italicize* key parameters\n * **Bold** critical information\n5. **LaTeX formula requirements**:\n * Inline formulas: start and end with `$`\n * Block formulas: start and end with `$$`, each `$$` on its own line\n * Block formula content must comply with LaTeX math syntax\n * Verify formula correctness\n---\n## Additional Notes (Interaction & Failure Strategy)\n* If the knowledge base does not cover critical facts: explicitly inform the user (with sample wording)\n* For time-sensitive issues: enforce time filtering in the search request, and indicate the latest retrieval date in the answer.\n* Language requirement: answer in the user\u2019s preferred language\n", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "", + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Message:OrangeYearsShine": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:NewPumasLick@content}" + ] + } + }, + "upstream": [ + "Agent:NewPumasLick" + ] + }, + "begin": { + "downstream": [ + "Agent:NewPumasLick" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "\u4f60\u597d\uff01 \u6211\u662f\u4f60\u7684\u52a9\u7406\uff0c\u6709\u4ec0\u4e48\u53ef\u4ee5\u5e2e\u5230\u4f60\u7684\u5417\uff1f" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:NewPumasLickend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:NewPumasLick", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLickstart-Message:OrangeYearsShineend", + "markerEnd": "logo", + "source": "Agent:NewPumasLick", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Message:OrangeYearsShine", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLicktool-Tool:AllBirdsNailend", + "selected": false, + "source": "Agent:NewPumasLick", + "sourceHandle": "tool", + "target": "Tool:AllBirdsNail", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "\u4f60\u597d\uff01 \u6211\u662f\u4f60\u7684\u52a9\u7406\uff0c\u6709\u4ec0\u4e48\u53ef\u4ee5\u5e2e\u5230\u4f60\u7684\u5417\uff1f" + }, + "label": "Begin", + "name": "begin" + }, + "dragging": false, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": -9.569875358221438, + "y": 205.84018385864917 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:NewPumasLick@content}" + ] + }, + "label": "Message", + "name": "Response" + }, + "dragging": false, + "id": "Message:OrangeYearsShine", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 734.4061285881053, + "y": 199.9706031723009 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen3-235b-a22b-instruct-2507@Tongyi-Qianwen", + "maxTokensEnabled": true, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 128000, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "# User Query\n {sys.query}", + "role": "user" + } + ], + "sys_prompt": "## Role & Task\nYou are a **\u201cKnowledge Base Retrieval Q\\&A Agent\u201d** whose goal is to break down the user\u2019s question into retrievable subtasks, and then produce a multi-source-verified, structured, and actionable research report using the internal knowledge base.\n## Execution Framework (Detailed Steps & Key Points)\n1. **Assessment & Decomposition**\n * Actions:\n * Automatically extract: main topic, subtopics, entities (people/organizations/products/technologies), time window, geographic/business scope.\n * Output as a list: N facts/data points that must be collected (*N* ranges from 5\u201320 depending on question complexity).\n2. **Query Type Determination (Rule-Based)**\n * Example rules:\n * If the question involves a single issue but requests \u201cmethod comparison/multiple explanations\u201d \u2192 use **depth-first**.\n * If the question can naturally be split into \u22653 independent sub-questions \u2192 use **breadth-first**.\n * If the question can be answered by a single fact/specification/definition \u2192 use **simple query**.\n3. **Research Plan Formulation**\n * Depth-first: define 3\u20135 perspectives (methodology/stakeholders/time dimension/technical route, etc.), assign search keywords, target document types, and output format for each perspective.\n * Breadth-first: list subtasks, prioritize them, and assign search terms.\n * Simple query: directly provide the search sentence and required fields.\n4. **Retrieval Execution**\n * After retrieval: perform coverage check (does it contain the key facts?) and quality check (source diversity, authority, latest update time).\n * If standards are not met, automatically loop: rewrite queries (synonyms/cross-domain terms) and retry \u22643 times, or flag as requiring external search.\n5. **Integration & Reasoning**\n * Build the answer using a **fact\u2013evidence\u2013reasoning** chain. For each conclusion, attach 1\u20132 strongest pieces of evidence.\n---\n## Quality Gate Checklist (Verify at Each Stage)\n* **Stage 1 (Decomposition)**:\n * [ ] Key concepts and expected outputs identified\n * [ ] Required facts/data points listed\n* **Stage 2 (Retrieval)**:\n * [ ] Meets quality standards (see above)\n * [ ] If not met: execute query iteration\n* **Stage 3 (Generation)**:\n * [ ] Each conclusion has at least one direct evidence source\n * [ ] State assumptions/uncertainties\n * [ ] Provide next-step suggestions or experiment/retrieval plans\n * [ ] Final length and depth match user expectations (comply with word count/format if specified)\n---\n## Core Principles\n1. **Strict reliance on the knowledge base**: answers must be **fully bounded** by the content retrieved from the knowledge base.\n2. **No fabrication**: do not generate, infer, or create information that is not explicitly present in the knowledge base.\n3. **Accuracy first**: prefer incompleteness over inaccurate content.\n4. **Output format**:\n * Hierarchically clear modular structure\n * Logical grouping according to the MECE principle\n * Professionally presented formatting\n * Step-by-step cognitive guidance\n * Reasonable use of headings and dividers for clarity\n * *Italicize* key parameters\n * **Bold** critical information\n5. **LaTeX formula requirements**:\n * Inline formulas: start and end with `$`\n * Block formulas: start and end with `$$`, each `$$` on its own line\n * Block formula content must comply with LaTeX math syntax\n * Verify formula correctness\n---\n## Additional Notes (Interaction & Failure Strategy)\n* If the knowledge base does not cover critical facts: explicitly inform the user (with sample wording)\n* For time-sensitive issues: enforce time filtering in the search request, and indicate the latest retrieval date in the answer.\n* Language requirement: answer in the user\u2019s preferred language\n", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "", + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Knowledge Base Agent" + }, + "dragging": false, + "id": "Agent:NewPumasLick", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 347.00048227952215, + "y": 186.49109364794631 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_10" + }, + "dragging": false, + "id": "Tool:AllBirdsNail", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 220.24819746977118, + "y": 403.31576836482583 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + } + ] + }, + "history": [], + "memory": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAH0klEQVR4nO2ZC1BU1wGG/3uRp/IygG+DGK0GOjE1U6cxI4tT03Y0E+kENbaJbKpj60wzgNMwnTjuEtu0miGasY+0krI202kMVEnVxtoOLG00oVa0LajVBDcSEI0REFBgkZv/3GWXfdzdvctuHs7kmzmec9//d+45914XCXc4Xwjk1+59VJGGF7C5QAFSWBvgyWmWLl7IKiny6QNL173B5YjB84bOyrpKA4B1DLySdQpLKAiZGtZ7a/KMVoQJz6UfEZyhTWwaEBmssiLvCueu6BJg8EwFqGTTAC+uvNWC9w82sRWcux/JwaSHstjywcogRt4RG0KExwWG4QsVYCebKSwe3L5lR9OOWjyzfg2WL/0a1/jncO3b2FHxGnKeWYqo+Giu8UEMrWJKWBACPMY/DG+63txhvnKshUu+DF2/hayMDFRsL+VScDb++AVc6OjAuInxXPJl2tfnIikrzUyJMi7qQmLRhOEr2fOFbX/7P6STF7BqoWevfdij4NWGQfx+57OYO2sG1wSnsek8Nm15EU8sikF6ouelXz9ph7JwDqYt+5IIZaGEkauDIrH4wPBmhjexCSEws+VdVG1M4NIoj+2xYzBuJtavWcEl/VS8dggx/ZdQvcGzQwp+cxOXsu5RBQQMVkYJM4LA/Txh+ELFMWFVPARS5kFiabZdx8Olh7l17BzdvhzZmROhdJ3j6D/nIyBgOCMlLAgA9xmF4TMV4BSbrgnrLiBl5rOsRCRRbDUsBzQFiJjY91PCBj9w+yiP1lXWsTLAjc9YQGB9I8+Yx1oTiUWFvW9QgDo2PdASa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9sAMNL9Ur4afv/FBjIuPVj+n4YVTwMD96tj0IVICoYYXv/q1VJ1Sl8UveQyaRwErvOB6B5SwKhqP00gI6A0vhsycJ7/KIzxhyHqGN0ADbnNAAYOicRfCFdAb/p50Gbfuc/wy5w1D5lOghk0fuG0USlgVr7sQjoDe8C8WxKGKPy2KjzlvAQb02/sCbh+FApngX1QUtyeSuwDi0hxFByV7L+LIf3r5kvpp4PBr07Hqvn71Y85bgOG6WS2ggA1+4D6eUKKQApVsqngI6KSkqh9HzsoM/3zg8Oz5VQ9E8wjf30YFDGdkeAsCwH18oYRZGXk7C4HuYxcwe6rjQsFovzaEvoFxqNkTOPzMjGikJso8wsF77XYkLx6dAwxWxvBmBIH7aUMJi8J3w0DnTVz7dyvX6KPzVBt+kL8cmzesRq9ps2Z48bRJmOIapS7E4zM2lXNt5CcU6ID7+ocSZkqY2NRN6ysnsHbJEpR8ZwV6t5Yg+iuLELf2KVd48VwXQf3BQGUMb4ZOuH9gKFEIYJfiNrEDcXZHHV4q3YRv5i7ikgM94RlETNgihrcgBHhccCiRCf7VhBK5rAPyr9I/Y/WKPEyfksH/9NjQ2dODhsYzwcLXsypkeBtCRGLRDUUMAMyKHxEx4dtrzyP97nQMygripiQiKi4aSbPvQmKW7+OXF69ntYvBa1iPCYklZEZECsGm4ja0Ops7EJsaj4SprlU+8IJiqIjAFga3Ikx4vvAYkTGALxyWFArlsnbBC9Sz6mI5zWKNRGh3JJY7mjte4GOz+r4tkRbxQQAAAABJRU5ErkJggg==" +} \ No newline at end of file diff --git a/agent/templates/knowledge_base_report_r.json b/agent/templates/knowledge_base_report_r.json new file mode 100644 index 00000000000..074250e6a83 --- /dev/null +++ b/agent/templates/knowledge_base_report_r.json @@ -0,0 +1,333 @@ +{ + "id": 21, + "title": { + "en": "Report Agent Using Knowledge Base", + "de": "Berichtsagent mit Wissensdatenbank", + "zh": "知识库检索智能体"}, + "description": { + "en": "A report generation assistant using local knowledge base, with advanced capabilities in task planning, reasoning, and reflective analysis. Recommended for academic research paper Q&A", + "de": "Ein Berichtsgenerierungsassistent, der eine lokale Wissensdatenbank nutzt, mit erweiterten Fähigkeiten in Aufgabenplanung, Schlussfolgerung und reflektierender Analyse. Empfohlen für akademische Forschungspapier-Fragen und -Antworten.", + "zh": "一个使用本地知识库的报告生成助手,具备高级能力,包括任务规划、推理和反思性分析。推荐用于学术研究论文问答。"}, + "canvas_type": "Recommended", + "dsl": { + "components": { + "Agent:NewPumasLick": { + "downstream": [ + "Message:OrangeYearsShine" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen3-235b-a22b-instruct-2507@Tongyi-Qianwen", + "maxTokensEnabled": true, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 128000, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "# User Query\n {sys.query}", + "role": "user" + } + ], + "sys_prompt": "## Role & Task\nYou are a **\u201cKnowledge Base Retrieval Q\\&A Agent\u201d** whose goal is to break down the user\u2019s question into retrievable subtasks, and then produce a multi-source-verified, structured, and actionable research report using the internal knowledge base.\n## Execution Framework (Detailed Steps & Key Points)\n1. **Assessment & Decomposition**\n * Actions:\n * Automatically extract: main topic, subtopics, entities (people/organizations/products/technologies), time window, geographic/business scope.\n * Output as a list: N facts/data points that must be collected (*N* ranges from 5\u201320 depending on question complexity).\n2. **Query Type Determination (Rule-Based)**\n * Example rules:\n * If the question involves a single issue but requests \u201cmethod comparison/multiple explanations\u201d \u2192 use **depth-first**.\n * If the question can naturally be split into \u22653 independent sub-questions \u2192 use **breadth-first**.\n * If the question can be answered by a single fact/specification/definition \u2192 use **simple query**.\n3. **Research Plan Formulation**\n * Depth-first: define 3\u20135 perspectives (methodology/stakeholders/time dimension/technical route, etc.), assign search keywords, target document types, and output format for each perspective.\n * Breadth-first: list subtasks, prioritize them, and assign search terms.\n * Simple query: directly provide the search sentence and required fields.\n4. **Retrieval Execution**\n * After retrieval: perform coverage check (does it contain the key facts?) and quality check (source diversity, authority, latest update time).\n * If standards are not met, automatically loop: rewrite queries (synonyms/cross-domain terms) and retry \u22643 times, or flag as requiring external search.\n5. **Integration & Reasoning**\n * Build the answer using a **fact\u2013evidence\u2013reasoning** chain. For each conclusion, attach 1\u20132 strongest pieces of evidence.\n---\n## Quality Gate Checklist (Verify at Each Stage)\n* **Stage 1 (Decomposition)**:\n * [ ] Key concepts and expected outputs identified\n * [ ] Required facts/data points listed\n* **Stage 2 (Retrieval)**:\n * [ ] Meets quality standards (see above)\n * [ ] If not met: execute query iteration\n* **Stage 3 (Generation)**:\n * [ ] Each conclusion has at least one direct evidence source\n * [ ] State assumptions/uncertainties\n * [ ] Provide next-step suggestions or experiment/retrieval plans\n * [ ] Final length and depth match user expectations (comply with word count/format if specified)\n---\n## Core Principles\n1. **Strict reliance on the knowledge base**: answers must be **fully bounded** by the content retrieved from the knowledge base.\n2. **No fabrication**: do not generate, infer, or create information that is not explicitly present in the knowledge base.\n3. **Accuracy first**: prefer incompleteness over inaccurate content.\n4. **Output format**:\n * Hierarchically clear modular structure\n * Logical grouping according to the MECE principle\n * Professionally presented formatting\n * Step-by-step cognitive guidance\n * Reasonable use of headings and dividers for clarity\n * *Italicize* key parameters\n * **Bold** critical information\n5. **LaTeX formula requirements**:\n * Inline formulas: start and end with `$`\n * Block formulas: start and end with `$$`, each `$$` on its own line\n * Block formula content must comply with LaTeX math syntax\n * Verify formula correctness\n---\n## Additional Notes (Interaction & Failure Strategy)\n* If the knowledge base does not cover critical facts: explicitly inform the user (with sample wording)\n* For time-sensitive issues: enforce time filtering in the search request, and indicate the latest retrieval date in the answer.\n* Language requirement: answer in the user\u2019s preferred language\n", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "", + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Message:OrangeYearsShine": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:NewPumasLick@content}" + ] + } + }, + "upstream": [ + "Agent:NewPumasLick" + ] + }, + "begin": { + "downstream": [ + "Agent:NewPumasLick" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "\u4f60\u597d\uff01 \u6211\u662f\u4f60\u7684\u52a9\u7406\uff0c\u6709\u4ec0\u4e48\u53ef\u4ee5\u5e2e\u5230\u4f60\u7684\u5417\uff1f" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:NewPumasLickend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:NewPumasLick", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLickstart-Message:OrangeYearsShineend", + "markerEnd": "logo", + "source": "Agent:NewPumasLick", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Message:OrangeYearsShine", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:NewPumasLicktool-Tool:AllBirdsNailend", + "selected": false, + "source": "Agent:NewPumasLick", + "sourceHandle": "tool", + "target": "Tool:AllBirdsNail", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "\u4f60\u597d\uff01 \u6211\u662f\u4f60\u7684\u52a9\u7406\uff0c\u6709\u4ec0\u4e48\u53ef\u4ee5\u5e2e\u5230\u4f60\u7684\u5417\uff1f" + }, + "label": "Begin", + "name": "begin" + }, + "dragging": false, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": -9.569875358221438, + "y": 205.84018385864917 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:NewPumasLick@content}" + ] + }, + "label": "Message", + "name": "Response" + }, + "dragging": false, + "id": "Message:OrangeYearsShine", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 734.4061285881053, + "y": 199.9706031723009 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "qwen3-235b-a22b-instruct-2507@Tongyi-Qianwen", + "maxTokensEnabled": true, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 128000, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "# User Query\n {sys.query}", + "role": "user" + } + ], + "sys_prompt": "## Role & Task\nYou are a **\u201cKnowledge Base Retrieval Q\\&A Agent\u201d** whose goal is to break down the user\u2019s question into retrievable subtasks, and then produce a multi-source-verified, structured, and actionable research report using the internal knowledge base.\n## Execution Framework (Detailed Steps & Key Points)\n1. **Assessment & Decomposition**\n * Actions:\n * Automatically extract: main topic, subtopics, entities (people/organizations/products/technologies), time window, geographic/business scope.\n * Output as a list: N facts/data points that must be collected (*N* ranges from 5\u201320 depending on question complexity).\n2. **Query Type Determination (Rule-Based)**\n * Example rules:\n * If the question involves a single issue but requests \u201cmethod comparison/multiple explanations\u201d \u2192 use **depth-first**.\n * If the question can naturally be split into \u22653 independent sub-questions \u2192 use **breadth-first**.\n * If the question can be answered by a single fact/specification/definition \u2192 use **simple query**.\n3. **Research Plan Formulation**\n * Depth-first: define 3\u20135 perspectives (methodology/stakeholders/time dimension/technical route, etc.), assign search keywords, target document types, and output format for each perspective.\n * Breadth-first: list subtasks, prioritize them, and assign search terms.\n * Simple query: directly provide the search sentence and required fields.\n4. **Retrieval Execution**\n * After retrieval: perform coverage check (does it contain the key facts?) and quality check (source diversity, authority, latest update time).\n * If standards are not met, automatically loop: rewrite queries (synonyms/cross-domain terms) and retry \u22643 times, or flag as requiring external search.\n5. **Integration & Reasoning**\n * Build the answer using a **fact\u2013evidence\u2013reasoning** chain. For each conclusion, attach 1\u20132 strongest pieces of evidence.\n---\n## Quality Gate Checklist (Verify at Each Stage)\n* **Stage 1 (Decomposition)**:\n * [ ] Key concepts and expected outputs identified\n * [ ] Required facts/data points listed\n* **Stage 2 (Retrieval)**:\n * [ ] Meets quality standards (see above)\n * [ ] If not met: execute query iteration\n* **Stage 3 (Generation)**:\n * [ ] Each conclusion has at least one direct evidence source\n * [ ] State assumptions/uncertainties\n * [ ] Provide next-step suggestions or experiment/retrieval plans\n * [ ] Final length and depth match user expectations (comply with word count/format if specified)\n---\n## Core Principles\n1. **Strict reliance on the knowledge base**: answers must be **fully bounded** by the content retrieved from the knowledge base.\n2. **No fabrication**: do not generate, infer, or create information that is not explicitly present in the knowledge base.\n3. **Accuracy first**: prefer incompleteness over inaccurate content.\n4. **Output format**:\n * Hierarchically clear modular structure\n * Logical grouping according to the MECE principle\n * Professionally presented formatting\n * Step-by-step cognitive guidance\n * Reasonable use of headings and dividers for clarity\n * *Italicize* key parameters\n * **Bold** critical information\n5. **LaTeX formula requirements**:\n * Inline formulas: start and end with `$`\n * Block formulas: start and end with `$$`, each `$$` on its own line\n * Block formula content must comply with LaTeX math syntax\n * Verify formula correctness\n---\n## Additional Notes (Interaction & Failure Strategy)\n* If the knowledge base does not cover critical facts: explicitly inform the user (with sample wording)\n* For time-sensitive issues: enforce time filtering in the search request, and indicate the latest retrieval date in the answer.\n* Language requirement: answer in the user\u2019s preferred language\n", + "temperature": "0.1", + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "", + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Knowledge Base Agent" + }, + "dragging": false, + "id": "Agent:NewPumasLick", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 347.00048227952215, + "y": 186.49109364794631 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_10" + }, + "dragging": false, + "id": "Tool:AllBirdsNail", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 220.24819746977118, + "y": 403.31576836482583 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + } + ] + }, + "history": [], + "memory": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAH0klEQVR4nO2ZC1BU1wGG/3uRp/IygG+DGK0GOjE1U6cxI4tT03Y0E+kENbaJbKpj60wzgNMwnTjuEtu0miGasY+0krI202kMVEnVxtoOLG00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MJi8J3w0DnTVz7dyvX6KPzVBt+kL8cmzesRq9ps2Z48bRJmOIapS7E4zM2lXNt5CcU6ID7+ocSZkqY2NRN6ysnsHbJEpR8ZwV6t5Yg+iuLELf2KVd48VwXQf3BQGUMb4ZOuH9gKFEIYJfiNrEDcXZHHV4q3YRv5i7ikgM94RlETNgihrcgBHhccCiRCf7VhBK5rAPyr9I/Y/WKPEyfksH/9NjQ2dODhsYzwcLXsypkeBtCRGLRDUUMAMyKHxEx4dtrzyP97nQMygripiQiKi4aSbPvQmKW7+OXF69ntYvBa1iPCYklZEZECsGm4ja0Ops7EJsaj4SprlU+8IJiqIjAFga3Ikx4vvAYkTGALxyWFArlsnbBC9Sz6mI5zWKNRGh3JJY7mjte4GOz+r4tkRbxQQAAAABJRU5ErkJggg==" +} \ No newline at end of file diff --git a/agent/templates/market_generate_seo_blog.json b/agent/templates/market_generate_seo_blog.json new file mode 100644 index 00000000000..f230efdba7b --- /dev/null +++ b/agent/templates/market_generate_seo_blog.json @@ -0,0 +1,921 @@ +{ + "id": 12, + "title": { + "en": "Generate SEO Blog", + "de": "SEO Blog generieren", + "zh": "生成SEO博客"}, + "description": { + "en": "This workflow automatically generates a complete SEO-optimized blog article based on a simple user input. You don't need any writing experience. Just provide a topic or short request — the system will handle the rest.", + "de": "Dieser Workflow generiert automatisch einen vollständigen SEO-optimierten Blogartikel basierend auf einer einfachen Benutzereingabe. Sie benötigen keine Schreiberfahrung. Geben Sie einfach ein Thema oder eine kurze Anfrage ein – das System übernimmt den Rest.", + "zh": "此工作流根据简单的用户输入自动生成完整的SEO博客文章。你无需任何写作经验,只需提供一个主题或简短请求,系统将处理其余部分。"}, + "canvas_type": "Marketing", + "dsl": { + "components": { + "Agent:BetterSitesSend": { + "downstream": [ + "Agent:EagerNailsRemain" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Outline_Agent**, responsible for generating a clear and SEO-optimized blog outline based on the user's parsed writing intent and keyword strategy.\n\n# Tool Access:\n\n- You have access to a search tool called `Tavily Search`.\n\n- If you are unsure how to structure a section, you may call this tool to search for related blog outlines or content from Google.\n\n- Do not overuse it. Your job is to extract **structure**, not to write paragraphs.\n\n\n# Goals\n\n1. Create a well-structured outline with appropriate H2 and H3 headings.\n\n2. Ensure logical flow from introduction to conclusion.\n\n3. Assign 1\u20132 suggested long-tail keywords to each major section for SEO alignment.\n\n4. Make the structure suitable for downstream paragraph writing.\n\n\n\n\n#Note\n\n- Use concise, scannable section titles.\n\n- Do not write full paragraphs.\n\n- Prioritize clarity, logical progression, and SEO alignment.\n\n\n\n- If the blog type is \u201cTutorial\u201d or \u201cHow-to\u201d, include step-based sections.\n\n\n# Input\n\nYou will receive:\n\n- Writing Type (e.g., Tutorial, Informative Guide)\n\n- Target Audience\n\n- User Intent Summary\n\n- 3\u20135 long-tail keywords\n\n\nUse this information to design a structure that both informs readers and maximizes search engine visibility.\n\n# Output Format\n\n```markdown\n\n## Blog Title (suggested)\n\n[Give a short, SEO-friendly title suggestion]\n\n## Outline\n\n### Introduction\n\n- Purpose of the article\n\n- Brief context\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 1]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 2]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 3]\n\n- [Optional H3 Subsection Title A]\n\n - [Explanation of sub-point]\n\n- [Optional H3 Subsection Title B]\n\n - [Explanation of sub-point]\n\n- **Suggested keywords**: [keyword1]\n\n### Conclusion\n\n- Recap key takeaways\n\n- Optional CTA (Call to Action)\n\n- **Suggested keywords**: [keyword3]\n\n", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Agent:ClearRabbitsScream" + ] + }, + "Agent:ClearRabbitsScream": { + "downstream": [ + "Agent:BetterSitesSend" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Parse_And_Keyword_Agent**, responsible for interpreting a user's blog writing request and generating a structured writing intent summary and keyword strategy for SEO-optimized content generation.\n\n# Goals\n\n1. Extract and infer the user's true writing intent, even if the input is informal or vague.\n\n2. Identify the writing type, target audience, and implied goal.\n\n3. Suggest 3\u20135 long-tail keywords based on the input and context.\n\n4. Output all data in a Markdown format for downstream agents.\n\n# Operating Guidelines\n\n\n- If the user's input lacks clarity, make reasonable and **conservative** assumptions based on SEO best practices.\n\n- Always choose one clear \"Writing Type\" from the list below.\n\n- Your job is not to write the blog \u2014 only to structure the brief.\n\n# Output Format\n\n```markdown\n## Writing Type\n\n[Choose one: Tutorial / Informative Guide / Marketing Content / Case Study / Opinion Piece / How-to / Comparison Article]\n\n## Target Audience\n\n[Try to be specific based on clues in the input: e.g., marketing managers, junior developers, SEO beginners]\n\n## User Intent Summary\n\n[A 1\u20132 sentence summary of what the user wants to achieve with the blog post]\n\n## Suggested Long-tail Keywords\n\n- keyword 1\n\n- keyword 2\n\n- keyword 3\n\n- keyword 4 (optional)\n\n- keyword 5 (optional)\n\n\n\n\n## Input Examples (and how to handle them)\n\nInput: \"I want to write about RAGFlow.\"\n\u2192 Output: Informative Guide, Audience: AI developers, Intent: explain what RAGFlow is and its use cases\n\nInput: \"Need a blog to promote our prompt design tool.\"\n\u2192 Output: Marketing Content, Audience: product managers or tool adopters, Intent: raise awareness and interest in the product\n\n\n\nInput: \"How to get more Google traffic using AI\"\n\u2192 Output: How-to, Audience: SEO marketers, Intent: guide readers on applying AI for SEO growth", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Agent:EagerNailsRemain": { + "downstream": [ + "Agent:LovelyHeadsOwn" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}\n\n\n\nThe Outline agent output is {Agent:BetterSitesSend@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Body_Agent**, responsible for generating the full content of each section of an SEO-optimized blog based on the provided outline and keyword strategy.\n\n# Tool Access:\n\nYou can use the `Tavily Search` tool to retrieve relevant content, statistics, or examples to support each section you're writing.\n\nUse it **only** when the provided outline lacks enough information, or if the section requires factual grounding.\n\nAlways cite the original link or indicate source where possible.\n\n\n# Goals\n\n1. Write each section (based on H2/H3 structure) as a complete and natural blog paragraph.\n\n2. Integrate the suggested long-tail keywords naturally into each section.\n\n3. When appropriate, use the `Tavily Search` tool to enrich your writing with relevant facts, examples, or quotes.\n\n4. Ensure each section is clear, engaging, and informative, suitable for both human readers and search engines.\n\n\n# Style Guidelines\n\n- Write in a tone appropriate to the audience. Be explanatory, not promotional, unless it's a marketing blog.\n\n- Avoid generic filler content. Prioritize clarity, structure, and value.\n\n- Ensure SEO keywords are embedded seamlessly, not forcefully.\n\n\n\n- Maintain writing rhythm. Vary sentence lengths. Use transitions between ideas.\n\n\n# Input\n\n\nYou will receive:\n\n- Blog title\n\n- Structured outline (including section titles, keywords, and descriptions)\n\n- Target audience\n\n- Blog type and user intent\n\nYou must **follow the outline strictly**. Write content **section-by-section**, based on the structure.\n\n\n# Output Format\n\n```markdown\n\n## H2: [Section Title]\n\n[Your generated content for this section \u2014 500-600 words, using keywords naturally.]\n\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Agent:BetterSitesSend" + ] + }, + "Agent:LovelyHeadsOwn": { + "downstream": [ + "Message:LegalBeansBet" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}\n\nThe Outline agent output is {Agent:BetterSitesSend@content}\n\nThe Body agent output is {Agent:EagerNailsRemain@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Editor_Agent**, responsible for finalizing the blog post for both human readability and SEO effectiveness.\n\n# Goals\n\n1. Polish the entire blog content for clarity, coherence, and style.\n\n2. Improve transitions between sections, ensure logical flow.\n\n3. Verify that keywords are used appropriately and effectively.\n\n4. Conduct a lightweight SEO audit \u2014 checking keyword density, structure (H1/H2/H3), and overall searchability.\n\n\n\n# Style Guidelines\n\n- Be precise. Avoid bloated or vague language.\n\n- Maintain an informative and engaging tone, suitable to the target audience.\n\n- Do not remove keywords unless absolutely necessary for clarity.\n\n- Ensure paragraph flow and section continuity.\n\n\n# Input\n\nYou will receive:\n\n- Full blog content, written section-by-section\n\n- Original outline with suggested keywords\n\n- Target audience and writing type\n\n# Output Format\n\n```markdown\n\n[The revised, fully polished blog post content goes here.]\n\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Agent:EagerNailsRemain" + ] + }, + "Message:LegalBeansBet": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:LovelyHeadsOwn@content}" + ] + } + }, + "upstream": [ + "Agent:LovelyHeadsOwn" + ] + }, + "begin": { + "downstream": [ + "Agent:ClearRabbitsScream" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your SEO blog assistant.\n\nTo get started, please tell me:\n1. What topic you want the blog to cover\n2. Who is the target audience\n3. What you hope to achieve with this blog (e.g., SEO traffic, teaching beginners, promoting a product)\n" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:ClearRabbitsScreamend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:ClearRabbitsScream", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:ClearRabbitsScreamstart-Agent:BetterSitesSendend", + "source": "Agent:ClearRabbitsScream", + "sourceHandle": "start", + "target": "Agent:BetterSitesSend", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:BetterSitesSendtool-Tool:SharpPensBurnend", + "source": "Agent:BetterSitesSend", + "sourceHandle": "tool", + "target": "Tool:SharpPensBurn", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:BetterSitesSendstart-Agent:EagerNailsRemainend", + "source": "Agent:BetterSitesSend", + "sourceHandle": "start", + "target": "Agent:EagerNailsRemain", + "targetHandle": "end" + }, + { + "id": "xy-edge__Agent:EagerNailsRemaintool-Tool:WickedDeerHealend", + "source": "Agent:EagerNailsRemain", + "sourceHandle": "tool", + "target": "Tool:WickedDeerHeal", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:EagerNailsRemainstart-Agent:LovelyHeadsOwnend", + "source": "Agent:EagerNailsRemain", + "sourceHandle": "start", + "target": "Agent:LovelyHeadsOwn", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:LovelyHeadsOwnstart-Message:LegalBeansBetend", + "source": "Agent:LovelyHeadsOwn", + "sourceHandle": "start", + "target": "Message:LegalBeansBet", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your SEO blog assistant.\n\nTo get started, please tell me:\n1. What topic you want the blog to cover\n2. Who is the target audience\n3. What you hope to achieve with this blog (e.g., SEO traffic, teaching beginners, promoting a product)\n" + }, + "label": "Begin", + "name": "begin" + }, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Parse_And_Keyword_Agent**, responsible for interpreting a user's blog writing request and generating a structured writing intent summary and keyword strategy for SEO-optimized content generation.\n\n# Goals\n\n1. Extract and infer the user's true writing intent, even if the input is informal or vague.\n\n2. Identify the writing type, target audience, and implied goal.\n\n3. Suggest 3\u20135 long-tail keywords based on the input and context.\n\n4. Output all data in a Markdown format for downstream agents.\n\n# Operating Guidelines\n\n\n- If the user's input lacks clarity, make reasonable and **conservative** assumptions based on SEO best practices.\n\n- Always choose one clear \"Writing Type\" from the list below.\n\n- Your job is not to write the blog \u2014 only to structure the brief.\n\n# Output Format\n\n```markdown\n## Writing Type\n\n[Choose one: Tutorial / Informative Guide / Marketing Content / Case Study / Opinion Piece / How-to / Comparison Article]\n\n## Target Audience\n\n[Try to be specific based on clues in the input: e.g., marketing managers, junior developers, SEO beginners]\n\n## User Intent Summary\n\n[A 1\u20132 sentence summary of what the user wants to achieve with the blog post]\n\n## Suggested Long-tail Keywords\n\n- keyword 1\n\n- keyword 2\n\n- keyword 3\n\n- keyword 4 (optional)\n\n- keyword 5 (optional)\n\n\n\n\n## Input Examples (and how to handle them)\n\nInput: \"I want to write about RAGFlow.\"\n\u2192 Output: Informative Guide, Audience: AI developers, Intent: explain what RAGFlow is and its use cases\n\nInput: \"Need a blog to promote our prompt design tool.\"\n\u2192 Output: Marketing Content, Audience: product managers or tool adopters, Intent: raise awareness and interest in the product\n\n\n\nInput: \"How to get more Google traffic using AI\"\n\u2192 Output: How-to, Audience: SEO marketers, Intent: guide readers on applying AI for SEO growth", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Parse And Keyword Agent" + }, + "dragging": false, + "id": "Agent:ClearRabbitsScream", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 344.7766966202233, + "y": 234.82202253184496 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Outline_Agent**, responsible for generating a clear and SEO-optimized blog outline based on the user's parsed writing intent and keyword strategy.\n\n# Tool Access:\n\n- You have access to a search tool called `Tavily Search`.\n\n- If you are unsure how to structure a section, you may call this tool to search for related blog outlines or content from Google.\n\n- Do not overuse it. Your job is to extract **structure**, not to write paragraphs.\n\n\n# Goals\n\n1. Create a well-structured outline with appropriate H2 and H3 headings.\n\n2. Ensure logical flow from introduction to conclusion.\n\n3. Assign 1\u20132 suggested long-tail keywords to each major section for SEO alignment.\n\n4. Make the structure suitable for downstream paragraph writing.\n\n\n\n\n#Note\n\n- Use concise, scannable section titles.\n\n- Do not write full paragraphs.\n\n- Prioritize clarity, logical progression, and SEO alignment.\n\n\n\n- If the blog type is \u201cTutorial\u201d or \u201cHow-to\u201d, include step-based sections.\n\n\n# Input\n\nYou will receive:\n\n- Writing Type (e.g., Tutorial, Informative Guide)\n\n- Target Audience\n\n- User Intent Summary\n\n- 3\u20135 long-tail keywords\n\n\nUse this information to design a structure that both informs readers and maximizes search engine visibility.\n\n# Output Format\n\n```markdown\n\n## Blog Title (suggested)\n\n[Give a short, SEO-friendly title suggestion]\n\n## Outline\n\n### Introduction\n\n- Purpose of the article\n\n- Brief context\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 1]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 2]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 3]\n\n- [Optional H3 Subsection Title A]\n\n - [Explanation of sub-point]\n\n- [Optional H3 Subsection Title B]\n\n - [Explanation of sub-point]\n\n- **Suggested keywords**: [keyword1]\n\n### Conclusion\n\n- Recap key takeaways\n\n- Optional CTA (Call to Action)\n\n- **Suggested keywords**: [keyword3]\n\n", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Outline Agent" + }, + "dragging": false, + "id": "Agent:BetterSitesSend", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 613.4368763415628, + "y": 164.3074269048589 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "dragging": false, + "id": "Tool:SharpPensBurn", + "measured": { + "height": 44, + "width": 200 + }, + "position": { + "x": 580.1877078861457, + "y": 287.7669662022325 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}\n\n\n\nThe Outline agent output is {Agent:BetterSitesSend@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Body_Agent**, responsible for generating the full content of each section of an SEO-optimized blog based on the provided outline and keyword strategy.\n\n# Tool Access:\n\nYou can use the `Tavily Search` tool to retrieve relevant content, statistics, or examples to support each section you're writing.\n\nUse it **only** when the provided outline lacks enough information, or if the section requires factual grounding.\n\nAlways cite the original link or indicate source where possible.\n\n\n# Goals\n\n1. Write each section (based on H2/H3 structure) as a complete and natural blog paragraph.\n\n2. Integrate the suggested long-tail keywords naturally into each section.\n\n3. When appropriate, use the `Tavily Search` tool to enrich your writing with relevant facts, examples, or quotes.\n\n4. Ensure each section is clear, engaging, and informative, suitable for both human readers and search engines.\n\n\n# Style Guidelines\n\n- Write in a tone appropriate to the audience. Be explanatory, not promotional, unless it's a marketing blog.\n\n- Avoid generic filler content. Prioritize clarity, structure, and value.\n\n- Ensure SEO keywords are embedded seamlessly, not forcefully.\n\n\n\n- Maintain writing rhythm. Vary sentence lengths. Use transitions between ideas.\n\n\n# Input\n\n\nYou will receive:\n\n- Blog title\n\n- Structured outline (including section titles, keywords, and descriptions)\n\n- Target audience\n\n- Blog type and user intent\n\nYou must **follow the outline strictly**. Write content **section-by-section**, based on the structure.\n\n\n# Output Format\n\n```markdown\n\n## H2: [Section Title]\n\n[Your generated content for this section \u2014 500-600 words, using keywords naturally.]\n\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Body Agent" + }, + "dragging": false, + "id": "Agent:EagerNailsRemain", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 889.0614605692713, + "y": 247.00973041799065 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_1" + }, + "dragging": false, + "id": "Tool:WickedDeerHeal", + "measured": { + "height": 44, + "width": 200 + }, + "position": { + "x": 853.2006404239659, + "y": 364.37541577229143 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}\n\nThe Outline agent output is {Agent:BetterSitesSend@content}\n\nThe Body agent output is {Agent:EagerNailsRemain@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Editor_Agent**, responsible for finalizing the blog post for both human readability and SEO effectiveness.\n\n# Goals\n\n1. Polish the entire blog content for clarity, coherence, and style.\n\n2. Improve transitions between sections, ensure logical flow.\n\n3. Verify that keywords are used appropriately and effectively.\n\n4. Conduct a lightweight SEO audit \u2014 checking keyword density, structure (H1/H2/H3), and overall searchability.\n\n\n\n# Style Guidelines\n\n- Be precise. Avoid bloated or vague language.\n\n- Maintain an informative and engaging tone, suitable to the target audience.\n\n- Do not remove keywords unless absolutely necessary for clarity.\n\n- Ensure paragraph flow and section continuity.\n\n\n# Input\n\nYou will receive:\n\n- Full blog content, written section-by-section\n\n- Original outline with suggested keywords\n\n- Target audience and writing type\n\n# Output Format\n\n```markdown\n\n[The revised, fully polished blog post content goes here.]\n\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Editor Agent" + }, + "dragging": false, + "id": "Agent:LovelyHeadsOwn", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 1160.3332919804993, + "y": 149.50806732882472 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:LovelyHeadsOwn@content}" + ] + }, + "label": "Message", + "name": "Response" + }, + "dragging": false, + "id": "Message:LegalBeansBet", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1370.6665839609984, + "y": 267.0323933738015 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "This workflow automatically generates a complete SEO-optimized blog article based on a simple user input. You don\u2019t need any writing experience. Just provide a topic or short request \u2014 the system will handle the rest.\n\nThe process includes the following key stages:\n\n1. **Understanding your topic and goals**\n2. **Designing the blog structure**\n3. **Writing high-quality content**\n\n\n" + }, + "label": "Note", + "name": "Workflow Overall Description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 205, + "id": "Note:SlimyGhostsWear", + "measured": { + "height": 205, + "width": 415 + }, + "position": { + "x": -284.3143151688742, + "y": 150.47632147913419 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 415 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis agent reads the user\u2019s input and figures out what kind of blog needs to be written.\n\n**What it does**:\n- Understands the main topic you want to write about \n- Identifies who the blog is for (e.g., beginners, marketers, developers) \n- Determines the writing purpose (e.g., SEO traffic, product promotion, education) \n- Suggests 3\u20135 long-tail SEO keywords related to the topic" + }, + "label": "Note", + "name": "Parse And Keyword Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 152, + "id": "Note:EmptyChairsShake", + "measured": { + "height": 152, + "width": 340 + }, + "position": { + "x": 295.04147626768133, + "y": 372.2755718118446 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 340 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis agent builds the blog structure \u2014 just like writing a table of contents before you start writing the full article.\n\n**What it does**:\n- Suggests a clear blog title that includes important keywords \n- Breaks the article into sections using H2 and H3 headings (like a professional blog layout) \n- Assigns 1\u20132 recommended keywords to each section to help with SEO \n- Follows the writing goal and target audience set in the previous step" + }, + "label": "Note", + "name": "Outline Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 146, + "id": "Note:TallMelonsNotice", + "measured": { + "height": 146, + "width": 343 + }, + "position": { + "x": 598.5644991893463, + "y": 5.801054564756448 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 343 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis agent is responsible for writing the actual content of the blog \u2014 paragraph by paragraph \u2014 based on the outline created earlier.\n\n**What it does**:\n- Looks at each H2/H3 section in the outline \n- Writes 150\u2013220 words of clear, helpful, and well-structured content per section \n- Includes the suggested SEO keywords naturally (not keyword stuffing) \n- Uses real examples or facts if needed (by calling a web search tool like Tavily)" + }, + "label": "Note", + "name": "Body Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 137, + "id": "Note:RipeCougarsBuild", + "measured": { + "height": 137, + "width": 319 + }, + "position": { + "x": 860.4854129814981, + "y": 427.2196835690842 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 319 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis agent reviews the entire blog draft to make sure it is smooth, professional, and SEO-friendly. It acts like a human editor before publishing.\n\n**What it does**:\n- Polishes the writing: improves sentence clarity, fixes awkward phrasing \n- Makes sure the content flows well from one section to the next \n- Double-checks keyword usage: are they present, natural, and not overused? \n- Verifies the blog structure (H1, H2, H3 headings) is correct \n- Adds two key SEO elements:\n - **Meta Title** (shows up in search results)\n - **Meta Description** (summary for Google and social sharing)" + }, + "label": "Note", + "name": "Editor Agent" + }, + "dragHandle": ".note-drag-handle", + "height": 146, + "id": "Note:OpenTurkeysSell", + "measured": { + "height": 146, + "width": 320 + }, + "position": { + "x": 1129, + "y": -30 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 320 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADb/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VaTUksjTiMnaq8uFfSVuDyiJ1iZpy0LOJtpa3YfkcQ5fdozyxI2m5qqcrHN61YYmHsh6v3o9ParYmYJEtlhIx6+gUbjgD23M6oqg92YL0JyF6Bps+qDValVA9h9Lj5SZI3SHXdEQlj1wiQtLLIe6pGzjO3BlBkK1hxpblLVH5wdW0BcFKf/JwRtjsot2z8omaSdxbzzk1iEjsE0AM9rrRZNRIrVyo7dGO6E+oh8axLlJ5H5VaJKx7ePRGFbW6vUeFfHQIWPTI9Tm7HHfuhqY7E6C7JFqUzM6iZXIoncNxX7+bIVdJnTT48x3OQU1krIDW3UeixVhyISzYz6cadY5Xph6TseRNTRsTElzzBn9Vlly0TAERsdgnMYyLROjyFbg5R4ZlsGaMT4yNi2Zlq1GwjZB3jq0PsaJfA3t0jL0W0Y9xf1V41lpWckXMLaZiwxuKYPqc6LlHdkeRF+Qxswx5ASDqBVrsL+2A/N6SiCbYymV2BywJiMZj3GRRMTnL+lVyHCll3R7Szv0vqXMtQ74T+HijljIScLaEpkKCB3rqMBIi0jPs5JeOKTZMZEi5VVnouzy0k3jXjWSMlY6UcVGDxlKMVDqx91SILWSi3D2KdgYy3kP8E9X/AE1SnRXBNdNRMlefT6g7aY6giK+cPLGNg0bY68rcnpsNh9PqIBve/EcPQ3WIq2dR93xpSgk5SAZ9R6MLAOZFUkpLSUDXp6/KPpGUkmTdswlnKnwbl5ITMdGwcXJi7LKsqzUmT5tWYmkXuF9wjBvb76b7dHheazJ9RElUJOCxViuMlUJC0Gtz6PKyjLBY4qMWUe12r1xZ6lOyT6XPEBKN2CkTDOlZd02TBdTMt7Upx2knrkdCv1UKjDKn1A7XBYH6SCOOrWn5Oi/DtRiu+GleRthDL8rXdVjZlcfWrSIxVlGGGCOnH//Z" +} \ No newline at end of file diff --git a/agent/templates/medical_consultation.json b/agent/templates/medical_consultation.json deleted file mode 100644 index 1afed12e332..00000000000 --- a/agent/templates/medical_consultation.json +++ /dev/null @@ -1,784 +0,0 @@ -{ - "id": 7, - "title": "Medical consultation", - "description": "A consultant that offers medical suggestions using an internal QA dataset and PubMed search results. Note that this agent's answers are for reference only and may not be valid. The dataset can be found at https://huggingface.co/datasets/InfiniFlow/medical_QA/tree/main", - "canvas_type": "chatbot", - "dsl": { - "answer": [], - "components": { - "Answer:FlatRavensPush": { - "downstream": [ - "Generate:QuietMelonsHear", - "Generate:FortyBaboonsRule" - ], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "begin", - "Generate:BrightCitiesSink" - ] - }, - "Generate:BrightCitiesSink": { - "downstream": [ - "Answer:FlatRavensPush" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are a professional medical consulting assistant\n\nTasks: Answer questions posed by users. Answer based on content provided by the knowledge base, PubMed\n\nRequirement:\n- Answers may refer to the content provided (Knowledge Base, PubMed).\n- If the provided PubMed content is referenced, a link to the corresponding URL should be given.\n-Answers should be professional and accurate; no information should be fabricated that is not relevant to the user's question.\n\nProvided knowledge base content\n{Retrieval:BeigeBagsDress}\n\nPubMed content provided\n\n{PubMed:TwentyFansShake}", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Retrieval:BeigeBagsDress", - "PubMed:TwentyFansShake" - ] - }, - "Generate:FortyBaboonsRule": { - "downstream": [ - "PubMed:TwentyFansShake" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are a professional Chinese-English medical question translation assistant\n\nTask: Accurately translate users' Chinese medical question content into English, ensuring accuracy of terminology and clarity of expression\n\nRequirements:\n- In-depth understanding of the terminology and disease descriptions in Chinese medical inquiries to ensure correct medical vocabulary is used in the English translation.\n- Maintain the semantic integrity and accuracy of the original text to avoid omitting important information or introducing errors.\n- Pay attention to the differences in expression habits between Chinese and English, and make appropriate adjustments to make the English translation more natural and fluent.\n- Respect the patient's privacy and the principle of medical confidentiality, and do not disclose any sensitive information during the translation process.\n\nExample:\nOriginal sentence: 我最近总是感觉胸闷,有时还会有心悸的感觉。\nTranslated: I've been feeling chest tightness recently, and sometimes I experience palpitations.\n\nNote:\nOnly the translated content should be given, do not output other irrelevant content!", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Answer:FlatRavensPush" - ] - }, - "Generate:QuietMelonsHear": { - "downstream": [ - "Retrieval:BeigeBagsDress" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are a professional medical consulting translation assistant\n\nTask: Translate user questions into Chinese, ensuring accuracy of medical terminology and appropriateness of context.\n\nRequirements:\n- Accurately translate medical terminology to convey the integrity and emotional color of the original message.\n- For unclear or uncertain medical terminology, the original text may be retained to ensure accuracy.\n- Respect the privacy and sensitivity of medical consultations and ensure that sensitive information is not disclosed during the translation process.\n- If the user's question is in Chinese, there is no need to translate, just output the user's question directly\n\nExample:\nOriginal (English): Doctor, I have been suffering from chest pain and shortness of breath for the past few days.\nTranslation (Chinese): 医生,我这几天一直胸痛和气短。\n\nNote:\nOnly the translated content needs to be output, no other irrelevant content!", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Answer:FlatRavensPush" - ] - }, - "PubMed:TwentyFansShake": { - "downstream": [ - "Generate:BrightCitiesSink" - ], - "obj": { - "component_name": "PubMed", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "email": "928018077@qq.com", - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "Generate:FortyBaboonsRule", - "type": "reference" - } - ], - "top_n": 10 - } - }, - "upstream": [ - "Generate:FortyBaboonsRule" - ] - }, - "Retrieval:BeigeBagsDress": { - "downstream": [ - "Generate:BrightCitiesSink" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "empty_response": "", - "inputs": [], - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "Generate:QuietMelonsHear", - "type": "reference" - } - ], - "rerank_id": "", - "similarity_threshold": 0.2, - "top_k": 1024, - "top_n": 8 - } - }, - "upstream": [ - "Generate:QuietMelonsHear" - ] - }, - "begin": { - "downstream": [ - "Answer:FlatRavensPush" - ], - "obj": { - "component_name": "Begin", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "prologue": "Hi! I'm your smart assistant. What can I do for you?", - "query": [] - } - }, - "upstream": [] - } - }, - "embed_id": "", - "graph": { - "edges": [ - { - "id": "reactflow__edge-begin-Answer:FlatRavensPushc", - "markerEnd": "logo", - "source": "begin", - "sourceHandle": null, - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:FlatRavensPush", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Answer:FlatRavensPushb-Generate:QuietMelonsHearc", - "markerEnd": "logo", - "source": "Answer:FlatRavensPush", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:QuietMelonsHear", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Answer:FlatRavensPushb-Generate:FortyBaboonsRulec", - "markerEnd": "logo", - "source": "Answer:FlatRavensPush", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:FortyBaboonsRule", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:FortyBaboonsRuleb-PubMed:TwentyFansShakec", - "markerEnd": "logo", - "source": "Generate:FortyBaboonsRule", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "PubMed:TwentyFansShake", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Generate:QuietMelonsHearb-Retrieval:BeigeBagsDressc", - "markerEnd": "logo", - "source": "Generate:QuietMelonsHear", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:BeigeBagsDress", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "xy-edge__Retrieval:BeigeBagsDressb-Generate:BrightCitiesSinkb", - "markerEnd": "logo", - "source": "Retrieval:BeigeBagsDress", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:BrightCitiesSink", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__PubMed:TwentyFansShakeb-Generate:BrightCitiesSinkb", - "markerEnd": "logo", - "source": "PubMed:TwentyFansShake", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:BrightCitiesSink", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:BrightCitiesSinkc-Answer:FlatRavensPushc", - "markerEnd": "logo", - "source": "Generate:BrightCitiesSink", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:FlatRavensPush", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - } - ], - "nodes": [ - { - "data": { - "label": "Begin", - "name": "opening" - }, - "dragging": false, - "height": 44, - "id": "begin", - "measured": { - "height": 44, - "width": 100 - }, - "position": { - "x": -599.8361708291377, - "y": 161.91688790133628 - }, - "positionAbsolute": { - "x": -599.8361708291377, - "y": 161.91688790133628 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "beginNode" - }, - { - "data": { - "form": { - "email": "928018077@qq.com", - "query": [ - { - "component_id": "Generate:FortyBaboonsRule", - "type": "reference" - } - ], - "top_n": 10 - }, - "label": "PubMed", - "name": "Search PubMed" - }, - "dragging": false, - "height": 44, - "id": "PubMed:TwentyFansShake", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 388.4151716305788, - "y": 272.51398951401995 - }, - "positionAbsolute": { - "x": 389.7229173847695, - "y": 276.4372267765921 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "Interface" - }, - "dragging": false, - "height": 44, - "id": "Answer:FlatRavensPush", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -277.4280835723395, - "y": 162.89713236919926 - }, - "positionAbsolute": { - "x": -370.881803561134, - "y": 161.41373998842477 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": true, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are a professional medical consulting translation assistant\n\nTask: Translate user questions into Chinese, ensuring accuracy of medical terminology and appropriateness of context.\n\nRequirements:\n- Accurately translate medical terminology to convey the integrity and emotional color of the original message.\n- For unclear or uncertain medical terminology, the original text may be retained to ensure accuracy.\n- Respect the privacy and sensitivity of medical consultations and ensure that sensitive information is not disclosed during the translation process.\n- If the user's question is in Chinese, there is no need to translate, just output the user's question directly\n\nExample:\nOriginal (English): Doctor, I have been suffering from chest pain and shortness of breath for the past few days.\nTranslation (Chinese): 医生,我这几天一直胸痛和气短。\n\nNote:\nOnly the translated content needs to be output, no other irrelevant content!", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Translate to Chinese" - }, - "dragging": false, - "height": 86, - "id": "Generate:QuietMelonsHear", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": -2.756518132081453, - "y": 38.86485966020132 - }, - "positionAbsolute": { - "x": -2.756518132081453, - "y": 38.86485966020132 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are a professional Chinese-English medical question translation assistant\n\nTask: Accurately translate users' Chinese medical question content into English, ensuring accuracy of terminology and clarity of expression\n\nRequirements:\n- In-depth understanding of the terminology and disease descriptions in Chinese medical inquiries to ensure correct medical vocabulary is used in the English translation.\n- Maintain the semantic integrity and accuracy of the original text to avoid omitting important information or introducing errors.\n- Pay attention to the differences in expression habits between Chinese and English, and make appropriate adjustments to make the English translation more natural and fluent.\n- Respect the patient's privacy and the principle of medical confidentiality, and do not disclose any sensitive information during the translation process.\n\nExample:\nOriginal sentence: 我最近总是感觉胸闷,有时还会有心悸的感觉。\nTranslated: I've been feeling chest tightness recently, and sometimes I experience palpitations.\n\nNote:\nOnly the translated content should be given, do not output other irrelevant content!", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Translate to English" - }, - "dragging": false, - "height": 86, - "id": "Generate:FortyBaboonsRule", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": -3.825864707727135, - "y": 253.2285157283701 - }, - "positionAbsolute": { - "x": -3.825864707727135, - "y": 253.2285157283701 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "query": [ - { - "component_id": "Generate:QuietMelonsHear", - "type": "reference" - } - ], - "similarity_threshold": 0.2, - "top_n": 8 - }, - "label": "Retrieval", - "name": "Search Q&A" - }, - "dragging": false, - "height": 44, - "id": "Retrieval:BeigeBagsDress", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 316.9462115194757, - "y": 57.81358887451738 - }, - "positionAbsolute": { - "x": 382.25527986090765, - "y": 35.38705653631584 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "Receives the user's financial inquiries and displays the large model's response to financial questions." - }, - "label": "Note", - "name": "N: Interface" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 162, - "id": "Note:RedZebrasEnjoy", - "measured": { - "height": 162, - "width": 200 - }, - "position": { - "x": -274.75115571622416, - "y": 233.92632661399952 - }, - "positionAbsolute": { - "x": -374.13983303471906, - "y": 219.54112331790157 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 162, - "width": 200 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "Translate user's question to English by LLM." - }, - "label": "Note", - "name": "N: Translate to English" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:DarkIconsClap", - "measured": { - "height": 128, - "width": 227 - }, - "position": { - "x": -2.0308204014422273, - "y": 379.60045703973515 - }, - "positionAbsolute": { - "x": -0.453362859534991, - "y": 357.3687792184929 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 204 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 227 - }, - { - "data": { - "form": { - "text": "Translate user's question to Chinese by LLM." - }, - "label": "Note", - "name": "N: Translate to Chinese" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:SmallRiversTap", - "measured": { - "height": 128, - "width": 220 - }, - "position": { - "x": -2.9326060127226583, - "y": -99.3117253460485 - }, - "positionAbsolute": { - "x": -5.453362859535048, - "y": -105.63122078150693 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 196 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 220 - }, - { - "data": { - "form": { - "text": "PubMed® comprises more than 37 million citations for biomedical literature from MEDLINE, life science journals, and online books. Citations may include links to full text content from PubMed Central and publisher web sites." - }, - "label": "Note", - "name": "N: Search PubMed" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 220, - "id": "Note:MightyDeerShout", - "measured": { - "height": 220, - "width": 287 - }, - "position": { - "x": 718.5466371404648, - "y": 275.36877921849293 - }, - "positionAbsolute": { - "x": 718.5466371404648, - "y": 275.36877921849293 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 220, - "width": 287 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 287 - }, - { - "data": { - "form": { - "text": "You can download the Q&A dataset at\nhttps://huggingface.co/datasets/InfiniFlow/medical_QA" - }, - "label": "Note", - "name": "N: Search Q&A" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:VioletSuitsFlash", - "measured": { - "height": 128, - "width": 387 - }, - "position": { - "x": 776.4332169584197, - "y": 32.89802610798361 - }, - "positionAbsolute": { - "x": 776.4332169584197, - "y": 32.89802610798361 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 387 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 387 - }, - { - "data": { - "form": { - "text": "A prompt summarize content from search result from PubMed and Q&A dataset." - }, - "label": "Note", - "name": "N: LLM" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 140, - "id": "Note:BeigeCoinsBuild", - "measured": { - "height": 140, - "width": 281 - }, - "position": { - "x": 293.89948660403513, - "y": -238.31673896113236 - }, - "positionAbsolute": { - "x": 756.9053449234701, - "y": -212.92342186138177 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 281 - }, - { - "data": { - "form": { - "cite": true, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are a professional medical consulting assistant\n\nTasks: Answer questions posed by users. Answer based on content provided by the knowledge base, PubMed\n\nRequirement:\n- Answers may refer to the content provided (Knowledge Base, PubMed).\n- If the provided PubMed content is referenced, a link to the corresponding URL should be given.\n-Answers should be professional and accurate; no information should be fabricated that is not relevant to the user's question.\n\nProvided knowledge base content\n{Retrieval:BeigeBagsDress}\n\nPubMed content provided\n\n{PubMed:TwentyFansShake}", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "LLM" - }, - "dragging": false, - "id": "Generate:BrightCitiesSink", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 300, - "y": -86.3689104694316 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - } - ] - }, - "history": [], - "messages": [], - "path": [], - "reference": [] - }, - "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAuCA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BxLWGOV4XIRpFOtgpWe4cBRTrq4alcTe1SCazdTXDDHmY6pmERXMHa2HosQsuYlBSZSWJcLonCTFJ8CfGyX0SEpRDgFYK740ZcZLZyEnN3DcDBwQcTM+VI2AnNsjABkiU3yFZlpVkZrR7gaFfHoRUgusmz0S4RidnloFGksUG0rgBZGY7esVySeAKEWoGUyNtmqbpXnJ8AIK8V/a9NELZj0VnFTVzFFCnp18RgbC2v10bJe2FMio9IZ1tkBrFhqUSHpbM1JBGfzVtx37AJZzFXZz883beIBbFwuQtGs6wxMnNBaxEpkZKoKWBWJ6JZEYl2uby3JgmtSEw53NRNFmZWCnM2GehVILPRLPf/j/4164UpYeFv/f/HFBDWyeJg3ITTYppV0XKfGIxWRWBkGSFBC5X3tqK1FDkrz36jQ5MIC00kbEscQb7RbBYmnB28cLB1xcHeXeTki6dbIOs2BKKf7yxAbDGa5yEORskXJwsYqRyrEqR/bEWzNFjel5vZiDMLXVUg2qkLpElGykKVj8ZkHkbm8lmlkSlJLCVUBaE6rlQg5Sq5ZjWRwEr0FedVAKrzEqiVIfJ9IehVC0W/Qn5eHsSksIBYAv2i8dsczka3AJztPLBd44i1lSO2Ni5scNiEo6M/c20iMVogTsxxYJLyrxjCgE6A6CQvVFktExBLgzCS3NGsTZG8EcfmOkxUqmky9UqFMZq6BCMJhlpGBcTfElJMt0ZxPlHsvxJSQYiEFBBG4rTCrs5CANxxXrlqlgVKEAVIoDDg6xmCl7MvzlKVbKXBrZIqtdpynYBxZp3tRqzWBWK8LhOjRT4YzVmP1txXpBUuCS4gVsVhJKDUM3OFEfkbraUSTZHY6gQ0Zg5olGo1bTFG05YLuPXiuGj/7zywVvpAsmh+QkIKACNLhW0FQJR8v9iKv0EEqwAU51UAd15rl/nx/9m9rPJRUHu8AAAAAElFTkSuQmCC" -} diff --git a/agent/templates/research_report.json b/agent/templates/research_report.json deleted file mode 100644 index 4fbf1fe3974..00000000000 --- a/agent/templates/research_report.json +++ /dev/null @@ -1,1107 +0,0 @@ -{ - "id": 10, - "title": "Research report generator", - "description": "A report generator that creates a research report from a given title, in the specified target language. It generates queries from the input title, then uses these to create subtitles and sections, compiling everything into a comprehensive report.", - "canvas_type": "chatbot", - "dsl": { - "answer": [], - "components": { - "Answer:WittyBottlesJog": { - "downstream": [], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "Template:LegalDoorsAct" - ] - }, - "Baidu:MeanBroomsMatter": { - "downstream": [ - "Generate:YoungClownsKnock" - ], - "obj": { - "component_name": "Baidu", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "IterationItem:RudeTablesSmile", - "type": "reference" - } - ], - "top_n": 10 - } - }, - "parent_id": "Iteration:BlueClothsGrab", - "upstream": [ - "IterationItem:RudeTablesSmile" - ] - }, - "Generate:EveryCoinsStare": { - "downstream": [ - "Generate:RedWormsDouble", - "Iteration:BlueClothsGrab" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "\n\nGenerate a series of appropriate search engine queries to break down questions based on user inquiries\n\n\n\n\nInput: User asks how to learn programming\nOutput: programming learning methods, programming tutorials for beginners\n\n\n\nInput: User wants to understand latest technology trends \nOutput: tech trends 2024, latest technology news\n\n\n\nInput: User seeks healthy eating advice\nOutput: healthy eating guide, balanced nutrition diet\n\n\n\n\n1. Take user's question as input.\n2. Identify relevant keywords or phrases based on the topic of user's question.\n3. Use these keywords or phrases to make search engine queries.\n4. Generate a series of appropriate search engine queries to help break down user's question.\n5. Ensure output content does not contain any xml tags.\n6. The output must be pure and conform to the style without other explanations.\n7. Break down into at least 4-6 subproblems.\n8. Output is separated only by commas.\n\n\n\ntitle: {begin@title}\nlanguage: {begin@language}\nThe output must be pure and conform to the style without other explanations.\nOutput is separated only by commas.\nBreak down into at least 4-6 subproblems.\n\nOutput:", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "begin" - ] - }, - "Generate:RealLoopsVanish": { - "downstream": [ - "Template:SpottyWaspsLose" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "In a detailed report — The report should focus on the answer to {IterationItem:OliveStatesSmoke}and nothing else.\n\n\nLanguage: {begin@language}\nContext as bellow: \n\n\"{Iteration:BlueClothsGrab}\"\n\nProvide the research report in the specified language, avoiding small talk.\nThe main content is provided in markdown format\nWrite all source urls at the end of the report in apa format. ", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "parent_id": "Iteration:ThreeParksChew", - "upstream": [ - "IterationItem:OliveStatesSmoke" - ] - }, - "Generate:RedWormsDouble": { - "downstream": [ - "Iteration:ThreeParksChew" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "According to query: ' {Generate:EveryCoinsStare}',for ' {begin@title}', generate 3 to 5 sub-titles.\n\n\nPlease generate 4 subheadings for the main title following these steps:\n - 1. Carefully read the provided main title and related content\n - 2. Analyze the core theme and key information points of the main title\n - 3. Ensure the generated subheadings maintain consistency and relevance with the main title\n - 4. Each subheading should:\n - Be concise and appropriate in length\n - Highlight a unique angle or key point\n - Capture readers' interest\n - Match the overall style and tone of the article\n - 5. Between subheadings:\n - Content should not overlap\n - Logical order should be maintained\n - Should collectively support the main title\n - Use numerical sequence (1, 2, 3...) to mark each subheading\n - 6. Output format requirements:\n - Each subheading on a separate line\n - No XML tags included\n - Output subheadings content only\n\n\nlanguage: {begin@language}\nGenerate a series of appropriate sub-title to help break down ' {begin@title}'.\nBreaks down complex topics into manageable subtopics.\n\nOutput:", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Generate:EveryCoinsStare" - ] - }, - "Generate:YoungClownsKnock": { - "downstream": [], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Your goal is to provide answers based on information from the internet. \nYou must use the provided search results to find relevant online information. \nYou should never use your own knowledge to answer questions.\nPlease include relevant url sources in the end of your answers.\n{Baidu:MeanBroomsMatter}\n\n\n\n\n\nlanguage: {begin@language}\n\n\n \" {Baidu:MeanBroomsMatter}\" \n\n\n\n\nUsing the above information, answer the following question or topic: \" {IterationItem:RudeTablesSmile} \"\nin a detailed report — The report should focus on the answer to the question, should be well structured, informative, in depth, with facts and numbers if available, a minimum of 1,200 words and with markdown syntax and apa format. Write all source urls at the end of the report in apa format. You should write your report only based on the given information and nothing else.", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "parent_id": "Iteration:BlueClothsGrab", - "upstream": [ - "Baidu:MeanBroomsMatter" - ] - }, - "Iteration:BlueClothsGrab": { - "downstream": [], - "obj": { - "component_name": "Iteration", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "delimiter": ",", - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "Generate:EveryCoinsStare", - "type": "reference" - } - ] - } - }, - "upstream": [ - "Generate:EveryCoinsStare" - ] - }, - "Iteration:ThreeParksChew": { - "downstream": [ - "Template:LegalDoorsAct" - ], - "obj": { - "component_name": "Iteration", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "delimiter": "\n", - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "Generate:RedWormsDouble", - "type": "reference" - } - ] - } - }, - "upstream": [ - "Generate:RedWormsDouble" - ] - }, - "IterationItem:OliveStatesSmoke": { - "downstream": [ - "Generate:RealLoopsVanish" - ], - "obj": { - "component_name": "IterationItem", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [] - } - }, - "parent_id": "Iteration:ThreeParksChew", - "upstream": [] - }, - "IterationItem:RudeTablesSmile": { - "downstream": [ - "Baidu:MeanBroomsMatter" - ], - "obj": { - "component_name": "IterationItem", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [] - } - }, - "parent_id": "Iteration:BlueClothsGrab", - "upstream": [] - }, - "Template:LegalDoorsAct": { - "downstream": [ - "Answer:WittyBottlesJog" - ], - "obj": { - "component_name": "Template", - "inputs": [], - "output": null, - "params": { - "content": "

{begin@title}

\n\n\n\n{Iteration:ThreeParksChew}", - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "parameters": [], - "query": [] - } - }, - "upstream": [ - "Iteration:ThreeParksChew" - ] - }, - "Template:SpottyWaspsLose": { - "downstream": [], - "obj": { - "component_name": "Template", - "inputs": [], - "output": null, - "params": { - "content": "

{IterationItem:OliveStatesSmoke}

\n
{Generate:RealLoopsVanish}
", - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "parameters": [], - "query": [] - } - }, - "parent_id": "Iteration:ThreeParksChew", - "upstream": [ - "Generate:RealLoopsVanish" - ] - }, - "begin": { - "downstream": [ - "Generate:EveryCoinsStare" - ], - "obj": { - "component_name": "Begin", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "prologue": "", - "query": [ - { - "key": "title", - "name": "Title", - "optional": false, - "type": "line" - }, - { - "key": "language", - "name": "Language", - "optional": false, - "type": "line" - } - ] - } - }, - "upstream": [] - } - }, - "embed_id": "", - "graph": { - "edges": [ - { - "id": "reactflow__edge-Baidu:SharpHotelsNailb-Generate:RealCamerasSendb", - "markerEnd": "logo", - "source": "Baidu:SharpHotelsNail", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:RealCamerasSend", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "reactflow__edge-Generate:BeigeEyesFlyb-Template:ThinSnailsDreamc", - "markerEnd": "logo", - "source": "Generate:BeigeEyesFly", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Template:ThinSnailsDream", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "reactflow__edge-IterationItem:RudeTablesSmile-Baidu:MeanBroomsMatterc", - "markerEnd": "logo", - "source": "IterationItem:RudeTablesSmile", - "sourceHandle": null, - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Baidu:MeanBroomsMatter", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:EveryCoinsStareb-Generate:RedWormsDoublec", - "markerEnd": "logo", - "source": "Generate:EveryCoinsStare", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:RedWormsDouble", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__begin-Generate:EveryCoinsStarec", - "markerEnd": "logo", - "source": "begin", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:EveryCoinsStare", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:RedWormsDoubleb-Iteration:ThreeParksChewc", - "markerEnd": "logo", - "source": "Generate:RedWormsDouble", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Iteration:ThreeParksChew", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:EveryCoinsStareb-Iteration:BlueClothsGrabc", - "markerEnd": "logo", - "source": "Generate:EveryCoinsStare", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Iteration:BlueClothsGrab", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Baidu:MeanBroomsMatterb-Generate:YoungClownsKnockb", - "markerEnd": "logo", - "source": "Baidu:MeanBroomsMatter", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:YoungClownsKnock", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__IterationItem:OliveStatesSmoke-Generate:RealLoopsVanishc", - "markerEnd": "logo", - "source": "IterationItem:OliveStatesSmoke", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:RealLoopsVanish", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:RealLoopsVanishb-Template:SpottyWaspsLoseb", - "markerEnd": "logo", - "source": "Generate:RealLoopsVanish", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Template:SpottyWaspsLose", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Iteration:ThreeParksChewb-Template:LegalDoorsActc", - "markerEnd": "logo", - "source": "Iteration:ThreeParksChew", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Template:LegalDoorsAct", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Template:LegalDoorsActb-Answer:WittyBottlesJogc", - "markerEnd": "logo", - "source": "Template:LegalDoorsAct", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:WittyBottlesJog", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - } - ], - "nodes": [ - { - "data": { - "form": { - "prologue": "", - "query": [ - { - "key": "title", - "name": "Title", - "optional": false, - "type": "line" - }, - { - "key": "language", - "name": "Language", - "optional": false, - "type": "line" - } - ] - }, - "label": "Begin", - "name": "begin" - }, - "dragging": false, - "height": 130, - "id": "begin", - "measured": { - "height": 130, - "width": 200 - }, - "position": { - "x": -231.29149905979648, - "y": 95.28494230291383 - }, - "positionAbsolute": { - "x": -185.67257819905137, - "y": 108.15225637884839 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "beginNode", - "width": 200 - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "Interact_0" - }, - "dragging": false, - "height": 44, - "id": "Answer:WittyBottlesJog", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 1458.2651570288865, - "y": 164.22699667633927 - }, - "positionAbsolute": { - "x": 1462.7745767525992, - "y": 231.9248108743051 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "delimiter": ",", - "query": [ - { - "component_id": "Generate:EveryCoinsStare", - "type": "reference" - } - ] - }, - "label": "Iteration", - "name": "Search" - }, - "dragging": false, - "height": 192, - "id": "Iteration:BlueClothsGrab", - "measured": { - "height": 192, - "width": 334 - }, - "position": { - "x": 432.63496522555613, - "y": 228.82343789018051 - }, - "positionAbsolute": { - "x": 441.29535207641436, - "y": 291.9929929170084 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 337, - "width": 356 - }, - "targetPosition": "left", - "type": "group", - "width": 334 - }, - { - "data": { - "form": {}, - "label": "IterationItem", - "name": "IterationItem" - }, - "dragging": false, - "extent": "parent", - "height": 44, - "id": "IterationItem:RudeTablesSmile", - "measured": { - "height": 44, - "width": 44 - }, - "parentId": "Iteration:BlueClothsGrab", - "position": { - "x": 22, - "y": 10 - }, - "positionAbsolute": { - "x": -261.5, - "y": -288.14062500000006 - }, - "selected": false, - "type": "iterationStartNode", - "width": 44 - }, - { - "data": { - "form": { - "query": [ - { - "component_id": "IterationItem:RudeTablesSmile", - "type": "reference" - } - ], - "top_n": 10 - }, - "label": "Baidu", - "name": "Baidu" - }, - "dragging": false, - "extent": "parent", - "height": 64, - "id": "Baidu:MeanBroomsMatter", - "measured": { - "height": 64, - "width": 200 - }, - "parentId": "Iteration:BlueClothsGrab", - "position": { - "x": 200, - "y": 0 - }, - "positionAbsolute": { - "x": -83.49999999999999, - "y": -298.14062500000006 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "delimiter": "\n", - "query": [ - { - "component_id": "Generate:RedWormsDouble", - "type": "reference" - } - ] - }, - "label": "Iteration", - "name": "Sections" - }, - "dragging": false, - "height": 225, - "id": "Iteration:ThreeParksChew", - "measured": { - "height": 225, - "width": 315 - }, - "position": { - "x": 888.9524716285371, - "y": 75.91277516159235 - }, - "positionAbsolute": { - "x": 891.9430519048244, - "y": 39.64877134989487 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 438, - "width": 328 - }, - "targetPosition": "left", - "type": "group", - "width": 315 - }, - { - "data": { - "form": {}, - "label": "IterationItem", - "name": "IterationItem" - }, - "dragging": false, - "extent": "parent", - "height": 44, - "id": "IterationItem:OliveStatesSmoke", - "measured": { - "height": 44, - "width": 44 - }, - "parentId": "Iteration:ThreeParksChew", - "position": { - "x": 24.66038685085823, - "y": 37.00025154774299 - }, - "positionAbsolute": { - "x": 780.5000000000002, - "y": 432.859375 - }, - "selected": false, - "type": "iterationStartNode", - "width": 44 - }, - { - "data": { - "form": { - "text": "It can generate a research report base on the title and language you provide." - }, - "label": "Note", - "name": "Usage" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 168, - "id": "Note:PoorMirrorsJump", - "measured": { - "height": 168, - "width": 275 - }, - "position": { - "x": -192.4712202594548, - "y": -164.26382748469516 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 275 - }, - { - "data": { - "form": { - "text": "LLM provides a series of search engine queries related to the proposition. Comprehensive research can be conducted through queries from different perspectives." - }, - "label": "Note", - "name": "N-Query" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 207, - "id": "Note:TwoSingersFly", - "measured": { - "height": 207, - "width": 256 - }, - "position": { - "x": 90.71637834539166, - "y": -160.7863367019141 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 256 - }, - { - "data": { - "form": { - "text": "LLM generates 4 subtitles for this report according to queries and title." - }, - "label": "Note", - "name": "N-Subtitles" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "id": "Note:SmoothAreasBet", - "measured": { - "height": 128, - "width": 266 - }, - "position": { - "x": 431.07789651000473, - "y": -161.0756093374443 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode" - }, - { - "data": { - "form": { - "text": "LLM generates a report for each query based on search result of each query.\nYou could change Baidu to other search engines." - }, - "label": "Note", - "name": "N-Search" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 168, - "id": "Note:CleanTablesCamp", - "measured": { - "height": 168, - "width": 364 - }, - "position": { - "x": 435.9578972976612, - "y": 452.5021839330345 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 364 - }, - { - "data": { - "form": { - "text": "LLM generates 4 sub-sections for 4 subtitles based on the report of search engine result." - }, - "label": "Note", - "name": "N-Sections" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 142, - "id": "Note:FamousToesReply", - "measured": { - "height": 142, - "width": 336 - }, - "position": { - "x": 881.4352587545767, - "y": -165.7333893115248 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 336 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "\n\nGenerate a series of appropriate search engine queries to break down questions based on user inquiries\n\n\n\n\nInput: User asks how to learn programming\nOutput: programming learning methods, programming tutorials for beginners\n\n\n\nInput: User wants to understand latest technology trends \nOutput: tech trends 2024, latest technology news\n\n\n\nInput: User seeks healthy eating advice\nOutput: healthy eating guide, balanced nutrition diet\n\n\n\n\n1. Take user's question as input.\n2. Identify relevant keywords or phrases based on the topic of user's question.\n3. Use these keywords or phrases to make search engine queries.\n4. Generate a series of appropriate search engine queries to help break down user's question.\n5. Ensure output content does not contain any xml tags.\n6. The output must be pure and conform to the style without other explanations.\n7. Break down into at least 4-6 subproblems.\n8. Output is separated only by commas.\n\n\n\ntitle: {begin@title}\nlanguage: {begin@language}\nThe output must be pure and conform to the style without other explanations.\nOutput is separated only by commas.\nBreak down into at least 4-6 subproblems.\n\nOutput:", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "GenQuery" - }, - "dragging": false, - "id": "Generate:EveryCoinsStare", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 42.60311386535324, - "y": 107.45415912015176 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "According to query: ' {Generate:EveryCoinsStare}',for ' {begin@title}', generate 3 to 5 sub-titles.\n\n\nPlease generate 4 subheadings for the main title following these steps:\n - 1. Carefully read the provided main title and related content\n - 2. Analyze the core theme and key information points of the main title\n - 3. Ensure the generated subheadings maintain consistency and relevance with the main title\n - 4. Each subheading should:\n - Be concise and appropriate in length\n - Highlight a unique angle or key point\n - Capture readers' interest\n - Match the overall style and tone of the article\n - 5. Between subheadings:\n - Content should not overlap\n - Logical order should be maintained\n - Should collectively support the main title\n - Use numerical sequence (1, 2, 3...) to mark each subheading\n - 6. Output format requirements:\n - Each subheading on a separate line\n - No XML tags included\n - Output subheadings content only\n\n\nlanguage: {begin@language}\nGenerate a series of appropriate sub-title to help break down ' {begin@title}'.\nBreaks down complex topics into manageable subtopics.\n\nOutput:", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Subtitles" - }, - "dragging": false, - "id": "Generate:RedWormsDouble", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 433.41522248658606, - "y": 14.302437349777136 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Your goal is to provide answers based on information from the internet. \nYou must use the provided search results to find relevant online information. \nYou should never use your own knowledge to answer questions.\nPlease include relevant url sources in the end of your answers.\n{Baidu:MeanBroomsMatter}\n\n\n\n\n\nlanguage: {begin@language}\n\n\n \" {Baidu:MeanBroomsMatter}\" \n\n\n\n\nUsing the above information, answer the following question or topic: \" {IterationItem:RudeTablesSmile} \"\nin a detailed report — The report should focus on the answer to the question, should be well structured, informative, in depth, with facts and numbers if available, a minimum of 1,200 words and with markdown syntax and apa format. Write all source urls at the end of the report in apa format. You should write your report only based on the given information and nothing else.", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "GenSearchReport" - }, - "dragging": false, - "extent": "parent", - "id": "Generate:YoungClownsKnock", - "measured": { - "height": 106, - "width": 200 - }, - "parentId": "Iteration:BlueClothsGrab", - "position": { - "x": 115.34644687476163, - "y": 73.07611243293042 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "In a detailed report — The report should focus on the answer to {IterationItem:OliveStatesSmoke}and nothing else.\n\n\nLanguage: {begin@language}\nContext as bellow: \n\n\"{Iteration:BlueClothsGrab}\"\n\nProvide the research report in the specified language, avoiding small talk.\nThe main content is provided in markdown format\nWrite all source urls at the end of the report in apa format. ", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Subtitle-content" - }, - "dragging": false, - "extent": "parent", - "id": "Generate:RealLoopsVanish", - "measured": { - "height": 106, - "width": 200 - }, - "parentId": "Iteration:ThreeParksChew", - "position": { - "x": 189.94391141062363, - "y": 5.408501635610101 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "content": "

{IterationItem:OliveStatesSmoke}

\n
{Generate:RealLoopsVanish}
", - "parameters": [] - }, - "label": "Template", - "name": "Sub-section" - }, - "dragging": false, - "extent": "parent", - "id": "Template:SpottyWaspsLose", - "measured": { - "height": 76, - "width": 200 - }, - "parentId": "Iteration:ThreeParksChew", - "position": { - "x": 107.51010102435532, - "y": 127.82322102671017 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "templateNode" - }, - { - "data": { - "form": { - "content": "

{begin@title}

\n\n\n\n{Iteration:ThreeParksChew}", - "parameters": [] - }, - "label": "Template", - "name": "Article" - }, - "dragging": false, - "id": "Template:LegalDoorsAct", - "measured": { - "height": 76, - "width": 200 - }, - "position": { - "x": 1209.0758608851872, - "y": 149.01984563839733 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "templateNode" - } - ] - }, - "history": [], - "messages": [], - "path": [], - "reference": [] - }, - "avatar": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAB2AI0DASIAAhEBAxEB/8QAHgAAAgIDAQEBAQAAAAAAAAAAAAgHCQQFBgoDAQL/xAA0EAABBQEAAgICAQMDAgQHAAAEAQIDBQYHAAgREhMUCRUhIhYXMSMzJDJBUiVCQ1FVltT/xAAdAQEAAQUBAQEAAAAAAAAAAAAACAIDBQYHAQQJ/8QAKhEAAgICAgICAQUAAgMAAAAAAgMBBAUGABEHEhMhFAgVIjF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yIjsslQMDjYcpoekVtVkHyMK0FOlJw43Tv5Wc2HHTl8w5dYlsvusHG6O5o9NrW2UZnf+wNx1ZRjYi9rkpstSclG5p/plb+GW+sqaxEmuCH3cFuyNxy4jw8PDxxw8PDw8ccPDw8PHHDw8PDxxw8PDw8ccPDw8PHHDw8PDxxw8PDw8ccPDw8PHHP/9k=" -} \ No newline at end of file diff --git a/agent/templates/seo_blog.json b/agent/templates/seo_blog.json index 051d74642a2..e06c28f0cc4 100644 --- a/agent/templates/seo_blog.json +++ b/agent/templates/seo_blog.json @@ -1,1209 +1,921 @@ { - "id": 9, - "title": "SEO Blog Generator", - "description": "A blog generator that creates SEO-optimized content based on your chosen title or keywords.", - "canvas_type": "chatbot", - "dsl": { - "answer": [], - "components": { - "Answer:TameWavesChange": { - "downstream": [], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "Template:YellowPlumsYell" - ] - }, - "Baidu:SharpSignsBeg": { - "downstream": [ - "Generate:FastTipsCamp" - ], - "obj": { - "component_name": "Baidu", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "Generate:PublicPotsPush", - "type": "reference" - } - ], - "top_n": 10 - } - }, - "upstream": [ - "Generate:PublicPotsPush" - ] - }, - "Baidu:ShyTeamsJuggle": { - "downstream": [ - "Generate:ReadyHandsInvent" - ], - "obj": { - "component_name": "Baidu", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "begin@keywords", - "type": "reference" - } - ], - "top_n": 10 - } - }, - "upstream": [ - "Switch:LargeWaspsSlide" - ] - }, - "Generate:CuddlyBatsCamp": { - "downstream": [ - "Template:YellowPlumsYell" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "You are an SEO expert who writes in a direct, practical, educational style that is factual rather than storytelling or narrative, focusing on explaining to {begin@audience} the \"how\" and \"what is\" and “why” rather than narrating to the audience. \n - Please write at a sixth grade reading level. \n - ONLY output in Markdown format.\n - Use positive, present tense expressions and avoid using complex words and sentence structures that lack narrative, such as \"reveal\" and \"dig deep.\"\n - Next, please continue writing articles related to our topic with a concise title, {begin@title}{Generate:ReadyHandsInvent} {begin@keywords}{Generate:FancyMomentsTalk}. \n - Please AVOID repeating what has already been written and do not use the same sentence structure. \n - JUST write the body of the article based on the outline.\n - DO NOT include introduction, title.\n - DO NOT miss anything mentioned in article outline, except introduction and title.\n - Please use the information I provide to create in-depth, interesting and unique content. Also, incorporate the references and data points I provided earlier into the article to increase its value to the reader.\n - MUST be in language as \" {begin@keywords} {begin@title}\".\n\n\n{Generate:FastTipsCamp}\n\n", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Generate:FastTipsCamp" - ] - }, - "Generate:FancyMomentsTalk": { - "downstream": [ - "Generate:PublicPotsPush" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [ - { - "component_id": "begin@title", - "id": "2beef84b-204b-475a-89b3-3833bd108088", - "key": "title" - } - ], - "presence_penalty": 0.4, - "prompt": "I'm doing research for an article called {begin@title}, what relevant, high-traffic phrase should I type into Google to find this article? Just return the phrase without including any special symbols like quotes and colons.", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Switch:LargeWaspsSlide" - ] - }, - "Generate:FastTipsCamp": { - "downstream": [ - "Generate:FortyBirdsAsk", - "Generate:CuddlyBatsCamp" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "I'm an expert blogger.\nHere is some research I did for the blog post title \" {begin@title} {Generate:ReadyHandsInvent}\".\nThese are related search results:\n{Baidu:SharpSignsBeg}\n\nPlease study it in depth:\n\nArticle title: {begin@title} {Generate:ReadyHandsInvent}\nTarget keywords: {begin@keywords} {Generate:FancyMomentsTalk}\nMy blog post’s audience: {begin@audience}\nExclude brands: {begin@brands_to_avoid}\n\nCan you write a detailed blog outline with unique chapters? \n - The outline should include specific points and details that the article can mention. \n - AVOID generalities. \n - This SHOULD be researched in depth, not generalized.\n - Each chapter includes 7-8 projects, use some of the links above for reference if you can. For each item, don't just say \"discuss how\" but actually explain in detail the points that can be made. \n - DO NOT include things that you know are false and may contain inaccuracies. You are writing for a mature audience, avoid generalities and make specific quotes. Make sure to define key terms for users in your outline. Stay away from very controversial topics. \n - In the introduction, provide the background information needed for the rest of the article.\n - Please return in base array format and only the outline array, escaping quotes in the format. Each array item includes a complete chapter:\n[\"Includes Chapter 1 of all sub-projects\", \"Includes Chapter 2 of all sub-projects\", \"Includes Chapter 3 of all sub-projects\", \"Includes Chapter 4 of all sub-projects\"...etc.]\n - Each section SHOULD be wrapped with \"\" and ensure escaping within the content to ensure it is a valid array item.\n - MUST be in language of \" {begin@keywords} {begin@title}\".\n\nHere is an example of valid output. Please follow this structure and ignore the content:\n[\n \"Introduction - Explore the vibrant city of Miami, a destination that offers rich history, diverse culture, and many hidden treasures. Discover the little-known wonders that make Miami a unique destination for adventure seekers. Explore from historical landmarks to exotic places Attractions include atmospheric neighborhoods, local cuisine and lively nightlife. \",\n \"History of Miami - Begin the adventure with a journey into Miami's past. Learn about the city's transformation from a sleepy settlement to a busy metropolis. Understand the impact of multiculturalism on the city's development, as reflected in its architecture, cuisine and lifestyle See. Discover the historical significance of Miami landmarks like Hemingway's home. Uncover the fascinating stories of famous Miami neighborhoods like Key West. Explore the role of art and culture in shaping Miami, as shown at Art Basel events.\n\"Major Attractions - Go beyond Miami's famous beaches and explore the city's top attractions. Discover the artistic talent of the Wynwood Arts District, known for its vibrant street art. Visit iconic South Beach, known for its nightlife and boutiques . Explore the charming Coconut Grove district, known for its tree-lined streets and shopping areas. Visit the Holocaust Memorial Museum, a sombre reminder of a dark chapter in human history. Explore the Everglades Country, one of Miami's natural treasures. The park's diverse wildlife \",\n\"Trail Discovery - Get off the tourist trail and discover Miami's hidden treasures. Experience a water taxi tour across Biscayne Bay to get another perspective on the city. Visit the little-known Kabinett Department of Art, showcasing unique installation art . Explore the abandoned bridges and hidden bars of Duval Street and go on a culinary adventure in local neighborhoods known for their authentic cuisine. Go shopping at Brickell City Center, a trendy shopping and apartment complex in the heart of Miami. body.\",\n\"Local Cuisine - Dive into Miami's food scene and sample the city's diverse flavors. Enjoy ultra-fresh food and drinks at Bartaco, a local favorite. Experience fine dining at upscale Italian restaurants like Il Mulino New York. Explore the city ’s local food market and sample delicious local produce in Miami. Try a unique blend of Cuban and American cuisine that is a testament to Miami’s multicultural heritage.\"\n\"Nightlife - Experience the city's lively nightlife, a perfect blend of sophistication and fun. Visit America's Social Bar & Kitchen, a sports\nA hotspot for enthusiasts. Explore the nightlife of Mary Brickell Village, known for its clubby atmosphere. Spend an evening at Smith & Walensky Miami Beach's South Point Park, known for its stunning views and vintage wines. Visit iconic Miami Beach, famous for its pulsating nightlife. \",\n \"Conclusion- Miami is more than just stunning beaches and dazzling nightlife. It is a treasure trove of experiences waiting to be discovered. From its rich history and diverse culture to its hidden treasures, local cuisine and lively nightlife, Miami has something for everyone A traveler offers a unique adventure to experience the magic of Miami Beach and create unforgettable memories with your family.\"\n]", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Baidu:SharpSignsBeg" - ] - }, - "Generate:FortyBirdsAsk": { - "downstream": [ - "Template:YellowPlumsYell" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "You are an SEO expert who writes in a direct, practical, educational style that is factual rather than storytelling or narrative, focusing on explaining to {begin@audience} the \"how\" and \"what is\" and “why” rather than narrating to the audience. \n - Please write at a sixth grade reading level. \n - ONLY output in Markdown format.\n - Use active, present tense, avoid using complex language and syntax, such as \"unravel\", \"dig deeper\", etc., \n - DO NOT provide narration.\n - Now, excluding the title, introduce the blog in 3-5 sentences. \n - Use h2 headings to write chapter titles. \n - Provide a concise, SEO-optimized title. \n - DO NOT include h3 subheadings. \n - Feel free to use bullet points, numbered lists or paragraphs, or bold text for emphasis when appropriate. \n - You should transition naturally to each section, build on each section, and should NOT repeat the same sentence structure. \n - JUST write the introduction of the article based on the outline.\n - DO NOT include title, conclusions, summaries, or summaries, no \"summaries,\" \"conclusions,\" or variations. \n - DO NOT include links or mention any companies that compete with the brand (avoid mentioning {begin@brands_to_avoid}).\n - JUST write the introduction of the article based on the outline.\n - MUST be in language as \"{Generate:FancyMomentsTalk} {Generate:ReadyHandsInvent}\".\n\n\n{Generate:FastTipsCamp}\n\n\n", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Generate:FastTipsCamp" - ] - }, - "Generate:PublicPotsPush": { - "downstream": [ - "Baidu:SharpSignsBeg" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "I want a Google search phrase to get authoritative information for my article \" {begin@title} {Generate:ReadyHandsInvent} {begin@keywords} {Generate:FancyMomentsTalk}\" for {begin@audience}. Please return a search phrase of five words or less so that I can get a good overview of the topic. Include any words you're unfamiliar with in your search query.", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Generate:ReadyHandsInvent", - "Generate:FancyMomentsTalk" - ] - }, - "Generate:ReadyHandsInvent": { - "downstream": [ - "Generate:PublicPotsPush" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 256, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are an SEO expert and subject area expert. Your task is to generate an SEO article title based on the keywords provided by the user and the context of the Google search.\n\nThe context of the Google search is as follows:\n{Baidu:ShyTeamsJuggle}\nThe context of the Google search is as above.\n\nIn order to craft an SEO article title that is keyword friendly and aligns with the principles observed in the top results you share, it is important to understand why these titles are effective. Here are the principles that may help them rank high:\n1. **Keyword Placement and Clarity**: Each title directly responds to the query by containing the exact keyword or a very close variation. This clarity ensures that search engines can easily understand the relevance of the content.\n2. **Succinctness and directness**: The title is concise, making it easy to read and understand quickly. They avoid unnecessary words and get straight to the point.\n3. **Contains a definition or explanation**: The title implies that the article will define or explain the concept, which is what people searching for \"{Generate:FancyMomentsTalk}\" are looking for.\n4. **Variety of Presentation**: Despite covering similar content, each title approaches the topic from a slightly different angle. This diversity can attract the interest of a wider audience.\n\nGiven these principles, please help me generate a title that will be optimized for the keyword \"{Generate:FancyMomentsTalk}\" based on the syntax of a top-ranking title. \n\nPlease don't copy, but give better options, and avoid using language like \"master,\" \"comprehensive,\" \"discover,\" or \"reveal.\" \n\nDo not use gerunds, only active tense and present tense. \n\nTitle SHOULD be in language as \"{Generate:FancyMomentsTalk}\"\n\nJust return the title.", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Baidu:ShyTeamsJuggle" - ] - }, - "Switch:LargeWaspsSlide": { - "downstream": [ - "Baidu:ShyTeamsJuggle", - "Generate:FancyMomentsTalk" - ], - "obj": { - "component_name": "Switch", - "inputs": [], - "output": null, - "params": { - "conditions": [ - { - "items": [ - { - "cpn_id": "begin@title", - "operator": "empty" - } - ], - "logical_operator": "and", - "to": "Baidu:ShyTeamsJuggle" - } - ], - "debug_inputs": [], - "end_cpn_id": "Generate:FancyMomentsTalk", - "inputs": [], - "message_history_window_size": 22, - "operators": [ - "contains", - "not contains", - "start with", - "end with", - "empty", - "not empty", - "=", - "≠", - ">", - "<", - "≥", - "≤" - ], - "output": null, - "output_var_name": "output", - "query": [] - } - }, - "upstream": [ - "begin" - ] - }, - "Template:YellowPlumsYell": { - "downstream": [ - "Answer:TameWavesChange" - ], - "obj": { - "component_name": "Template", - "inputs": [], - "output": null, - "params": { - "content": "\n##{begin@title}{Generate:ReadyHandsInvent}\n\n{Generate:FortyBirdsAsk}\n\n\n\n{Generate:CuddlyBatsCamp}\n\n\n", - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "parameters": [], - "query": [] - } - }, - "upstream": [ - "Generate:FortyBirdsAsk", - "Generate:CuddlyBatsCamp" - ] - }, - "begin": { - "downstream": [ - "Switch:LargeWaspsSlide" - ], - "obj": { - "component_name": "Begin", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "prologue": "", - "query": [ - { - "key": "title", - "name": "Title", - "optional": true, - "type": "line" + "id": 4, + "title": { + "en": "Generate SEO Blog", + "de": "SEO Blog generieren", + "zh": "生成SEO博客"}, + "description": { + "en": "This workflow automatically generates a complete SEO-optimized blog article based on a simple user input. You don't need any writing experience. Just provide a topic or short request — the system will handle the rest.", + "de": "Dieser Workflow generiert automatisch einen vollständigen SEO-optimierten Blogartikel basierend auf einer einfachen Benutzereingabe. Sie benötigen keine Schreiberfahrung. Geben Sie einfach ein Thema oder eine kurze Anfrage ein – das System übernimmt den Rest.", + "zh": "此工作流根据简单的用户输入自动生成完整的SEO博客文章。你无需任何写作经验,只需提供一个主题或简短请求,系统将处理其余部分。"}, + "canvas_type": "Recommended", + "dsl": { + "components": { + "Agent:BetterSitesSend": { + "downstream": [ + "Agent:EagerNailsRemain" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Outline_Agent**, responsible for generating a clear and SEO-optimized blog outline based on the user's parsed writing intent and keyword strategy.\n\n# Tool Access:\n\n- You have access to a search tool called `Tavily Search`.\n\n- If you are unsure how to structure a section, you may call this tool to search for related blog outlines or content from Google.\n\n- Do not overuse it. Your job is to extract **structure**, not to write paragraphs.\n\n\n# Goals\n\n1. Create a well-structured outline with appropriate H2 and H3 headings.\n\n2. Ensure logical flow from introduction to conclusion.\n\n3. Assign 1\u20132 suggested long-tail keywords to each major section for SEO alignment.\n\n4. Make the structure suitable for downstream paragraph writing.\n\n\n\n\n#Note\n\n- Use concise, scannable section titles.\n\n- Do not write full paragraphs.\n\n- Prioritize clarity, logical progression, and SEO alignment.\n\n\n\n- If the blog type is \u201cTutorial\u201d or \u201cHow-to\u201d, include step-based sections.\n\n\n# Input\n\nYou will receive:\n\n- Writing Type (e.g., Tutorial, Informative Guide)\n\n- Target Audience\n\n- User Intent Summary\n\n- 3\u20135 long-tail keywords\n\n\nUse this information to design a structure that both informs readers and maximizes search engine visibility.\n\n# Output Format\n\n```markdown\n\n## Blog Title (suggested)\n\n[Give a short, SEO-friendly title suggestion]\n\n## Outline\n\n### Introduction\n\n- Purpose of the article\n\n- Brief context\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 1]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 2]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 3]\n\n- [Optional H3 Subsection Title A]\n\n - [Explanation of sub-point]\n\n- [Optional H3 Subsection Title B]\n\n - [Explanation of sub-point]\n\n- **Suggested keywords**: [keyword1]\n\n### Conclusion\n\n- Recap key takeaways\n\n- Optional CTA (Call to Action)\n\n- **Suggested keywords**: [keyword3]\n\n", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Agent:ClearRabbitsScream" + ] }, - { - "key": "keywords", - "name": "Keywords", - "optional": true, - "type": "line" + "Agent:ClearRabbitsScream": { + "downstream": [ + "Agent:BetterSitesSend" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Parse_And_Keyword_Agent**, responsible for interpreting a user's blog writing request and generating a structured writing intent summary and keyword strategy for SEO-optimized content generation.\n\n# Goals\n\n1. Extract and infer the user's true writing intent, even if the input is informal or vague.\n\n2. Identify the writing type, target audience, and implied goal.\n\n3. Suggest 3\u20135 long-tail keywords based on the input and context.\n\n4. Output all data in a Markdown format for downstream agents.\n\n# Operating Guidelines\n\n\n- If the user's input lacks clarity, make reasonable and **conservative** assumptions based on SEO best practices.\n\n- Always choose one clear \"Writing Type\" from the list below.\n\n- Your job is not to write the blog \u2014 only to structure the brief.\n\n# Output Format\n\n```markdown\n## Writing Type\n\n[Choose one: Tutorial / Informative Guide / Marketing Content / Case Study / Opinion Piece / How-to / Comparison Article]\n\n## Target Audience\n\n[Try to be specific based on clues in the input: e.g., marketing managers, junior developers, SEO beginners]\n\n## User Intent Summary\n\n[A 1\u20132 sentence summary of what the user wants to achieve with the blog post]\n\n## Suggested Long-tail Keywords\n\n- keyword 1\n\n- keyword 2\n\n- keyword 3\n\n- keyword 4 (optional)\n\n- keyword 5 (optional)\n\n\n\n\n## Input Examples (and how to handle them)\n\nInput: \"I want to write about RAGFlow.\"\n\u2192 Output: Informative Guide, Audience: AI developers, Intent: explain what RAGFlow is and its use cases\n\nInput: \"Need a blog to promote our prompt design tool.\"\n\u2192 Output: Marketing Content, Audience: product managers or tool adopters, Intent: raise awareness and interest in the product\n\n\n\nInput: \"How to get more Google traffic using AI\"\n\u2192 Output: How-to, Audience: SEO marketers, Intent: guide readers on applying AI for SEO growth", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] }, - { - "key": "audience", - "name": "Audience", - "optional": true, - "type": "line" + "Agent:EagerNailsRemain": { + "downstream": [ + "Agent:LovelyHeadsOwn" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}\n\n\n\nThe Outline agent output is {Agent:BetterSitesSend@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Body_Agent**, responsible for generating the full content of each section of an SEO-optimized blog based on the provided outline and keyword strategy.\n\n# Tool Access:\n\nYou can use the `Tavily Search` tool to retrieve relevant content, statistics, or examples to support each section you're writing.\n\nUse it **only** when the provided outline lacks enough information, or if the section requires factual grounding.\n\nAlways cite the original link or indicate source where possible.\n\n\n# Goals\n\n1. Write each section (based on H2/H3 structure) as a complete and natural blog paragraph.\n\n2. Integrate the suggested long-tail keywords naturally into each section.\n\n3. When appropriate, use the `Tavily Search` tool to enrich your writing with relevant facts, examples, or quotes.\n\n4. Ensure each section is clear, engaging, and informative, suitable for both human readers and search engines.\n\n\n# Style Guidelines\n\n- Write in a tone appropriate to the audience. Be explanatory, not promotional, unless it's a marketing blog.\n\n- Avoid generic filler content. Prioritize clarity, structure, and value.\n\n- Ensure SEO keywords are embedded seamlessly, not forcefully.\n\n\n\n- Maintain writing rhythm. Vary sentence lengths. Use transitions between ideas.\n\n\n# Input\n\n\nYou will receive:\n\n- Blog title\n\n- Structured outline (including section titles, keywords, and descriptions)\n\n- Target audience\n\n- Blog type and user intent\n\nYou must **follow the outline strictly**. Write content **section-by-section**, based on the structure.\n\n\n# Output Format\n\n```markdown\n\n## H2: [Section Title]\n\n[Your generated content for this section \u2014 500-600 words, using keywords naturally.]\n\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Agent:BetterSitesSend" + ] }, - { - "key": "brands_to_avoid", - "name": "Brands to avoid", - "optional": true, - "type": "line" - } - ] - } - }, - "upstream": [] - } - }, - "embed_id": "", - "graph": { - "edges": [ - { - "id": "reactflow__edge-begin-Switch:LargeWaspsSlidea", - "markerEnd": "logo", - "source": "begin", - "sourceHandle": null, - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Switch:LargeWaspsSlide", - "targetHandle": "a", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Switch:LargeWaspsSlideCase 1-Baidu:ShyTeamsJugglec", - "markerEnd": "logo", - "source": "Switch:LargeWaspsSlide", - "sourceHandle": "Case 1", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Baidu:ShyTeamsJuggle", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Switch:LargeWaspsSlideend_cpn_id-Generate:FancyMomentsTalkc", - "markerEnd": "logo", - "source": "Switch:LargeWaspsSlide", - "sourceHandle": "end_cpn_id", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:FancyMomentsTalk", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "xy-edge__Baidu:ShyTeamsJuggleb-Generate:ReadyHandsInventc", - "markerEnd": "logo", - "source": "Baidu:ShyTeamsJuggle", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:ReadyHandsInvent", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:ReadyHandsInventb-Generate:PublicPotsPushc", - "markerEnd": "logo", - "source": "Generate:ReadyHandsInvent", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:PublicPotsPush", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:FancyMomentsTalkb-Generate:PublicPotsPushc", - "markerEnd": "logo", - "source": "Generate:FancyMomentsTalk", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:PublicPotsPush", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:PublicPotsPushb-Baidu:SharpSignsBegc", - "markerEnd": "logo", - "source": "Generate:PublicPotsPush", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Baidu:SharpSignsBeg", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Baidu:SharpSignsBegb-Generate:FastTipsCampc", - "markerEnd": "logo", - "source": "Baidu:SharpSignsBeg", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:FastTipsCamp", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:FastTipsCampb-Generate:FortyBirdsAskc", - "markerEnd": "logo", - "source": "Generate:FastTipsCamp", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:FortyBirdsAsk", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:FastTipsCampb-Generate:CuddlyBatsCampc", - "markerEnd": "logo", - "source": "Generate:FastTipsCamp", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:CuddlyBatsCamp", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:FortyBirdsAskb-Template:YellowPlumsYellc", - "markerEnd": "logo", - "source": "Generate:FortyBirdsAsk", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Template:YellowPlumsYell", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:CuddlyBatsCampb-Template:YellowPlumsYellc", - "markerEnd": "logo", - "source": "Generate:CuddlyBatsCamp", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Template:YellowPlumsYell", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Template:YellowPlumsYellb-Answer:TameWavesChangec", - "markerEnd": "logo", - "source": "Template:YellowPlumsYell", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:TameWavesChange", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - } - ], - "nodes": [ - { - "data": { - "form": { - "prologue": "", - "query": [ - { - "key": "title", - "name": "Title", - "optional": true, - "type": "line" - }, - { - "key": "keywords", - "name": "Keywords", - "optional": true, - "type": "line" - }, - { - "key": "audience", - "name": "Audience", - "optional": true, - "type": "line" - }, - { - "key": "brands_to_avoid", - "name": "Brands to avoid", - "optional": true, - "type": "line" - } - ] - }, - "label": "Begin", - "name": "begin" - }, - "dragging": false, - "height": 212, - "id": "begin", - "measured": { - "height": 212, - "width": 200 - }, - "position": { - "x": -432.2850120660528, - "y": 82.47567395502324 - }, - "positionAbsolute": { - "x": -432.2850120660528, - "y": 82.47567395502324 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "beginNode", - "width": 200 - }, - { - "data": { - "form": { - "conditions": [ - { - "items": [ - { - "cpn_id": "begin@title", - "operator": "empty" - } + "Agent:LovelyHeadsOwn": { + "downstream": [ + "Message:LegalBeansBet" ], - "logical_operator": "and", - "to": "Baidu:ShyTeamsJuggle" - } - ], - "end_cpn_id": "Generate:FancyMomentsTalk" - }, - "label": "Switch", - "name": "Empty title?" - }, - "dragging": false, - "height": 164, - "id": "Switch:LargeWaspsSlide", - "measured": { - "height": 164, - "width": 200 - }, - "position": { - "x": -171.8139076194234, - "y": 106.58178484885428 - }, - "positionAbsolute": { - "x": -171.8139076194234, - "y": 106.58178484885428 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "switchNode", - "width": 200 - }, - { - "data": { - "form": { - "query": [ - { - "component_id": "begin@keywords", - "type": "reference" - } - ], - "top_n": 10 - }, - "label": "Baidu", - "name": "Baidu4title" - }, - "dragging": false, - "height": 64, - "id": "Baidu:ShyTeamsJuggle", - "measured": { - "height": 64, - "width": 200 - }, - "position": { - "x": 99.2698941117485, - "y": 131.97513574677558 - }, - "positionAbsolute": { - "x": 99.2698941117485, - "y": 131.97513574677558 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [ - { - "component_id": "begin@title", - "id": "2beef84b-204b-475a-89b3-3833bd108088", - "key": "title" - } - ], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "I'm doing research for an article called {begin@title}, what relevant, high-traffic phrase should I type into Google to find this article? Just return the phrase without including any special symbols like quotes and colons.", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Keywords gen" - }, - "dragging": false, - "height": 148, - "id": "Generate:FancyMomentsTalk", - "measured": { - "height": 148, - "width": 200 - }, - "position": { - "x": 102.41401952481024, - "y": 250.74278147746412 + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}\n\nThe Outline agent output is {Agent:BetterSitesSend@content}\n\nThe Body agent output is {Agent:EagerNailsRemain@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Editor_Agent**, responsible for finalizing the blog post for both human readability and SEO effectiveness.\n\n# Goals\n\n1. Polish the entire blog content for clarity, coherence, and style.\n\n2. Improve transitions between sections, ensure logical flow.\n\n3. Verify that keywords are used appropriately and effectively.\n\n4. Conduct a lightweight SEO audit \u2014 checking keyword density, structure (H1/H2/H3), and overall searchability.\n\n\n\n# Style Guidelines\n\n- Be precise. Avoid bloated or vague language.\n\n- Maintain an informative and engaging tone, suitable to the target audience.\n\n- Do not remove keywords unless absolutely necessary for clarity.\n\n- Ensure paragraph flow and section continuity.\n\n\n# Input\n\nYou will receive:\n\n- Full blog content, written section-by-section\n\n- Original outline with suggested keywords\n\n- Target audience and writing type\n\n# Output Format\n\n```markdown\n\n[The revised, fully polished blog post content goes here.]\n\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Agent:EagerNailsRemain" + ] + }, + "Message:LegalBeansBet": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:LovelyHeadsOwn@content}" + ] + } + }, + "upstream": [ + "Agent:LovelyHeadsOwn" + ] + }, + "begin": { + "downstream": [ + "Agent:ClearRabbitsScream" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your SEO blog assistant.\n\nTo get started, please tell me:\n1. What topic you want the blog to cover\n2. Who is the target audience\n3. What you hope to achieve with this blog (e.g., SEO traffic, teaching beginners, promoting a product)\n" + } + }, + "upstream": [] + } }, - "positionAbsolute": { - "x": 102.41401952481024, - "y": 250.74278147746412 + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode", - "width": 200 - }, - { - "data": { - "form": { - "query": [ - { - "component_id": "Generate:PublicPotsPush", - "type": "reference" - } + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:ClearRabbitsScreamend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:ClearRabbitsScream", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:ClearRabbitsScreamstart-Agent:BetterSitesSendend", + "source": "Agent:ClearRabbitsScream", + "sourceHandle": "start", + "target": "Agent:BetterSitesSend", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:BetterSitesSendtool-Tool:SharpPensBurnend", + "source": "Agent:BetterSitesSend", + "sourceHandle": "tool", + "target": "Tool:SharpPensBurn", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:BetterSitesSendstart-Agent:EagerNailsRemainend", + "source": "Agent:BetterSitesSend", + "sourceHandle": "start", + "target": "Agent:EagerNailsRemain", + "targetHandle": "end" + }, + { + "id": "xy-edge__Agent:EagerNailsRemaintool-Tool:WickedDeerHealend", + "source": "Agent:EagerNailsRemain", + "sourceHandle": "tool", + "target": "Tool:WickedDeerHeal", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:EagerNailsRemainstart-Agent:LovelyHeadsOwnend", + "source": "Agent:EagerNailsRemain", + "sourceHandle": "start", + "target": "Agent:LovelyHeadsOwn", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:LovelyHeadsOwnstart-Message:LegalBeansBetend", + "source": "Agent:LovelyHeadsOwn", + "sourceHandle": "start", + "target": "Message:LegalBeansBet", + "targetHandle": "end" + } ], - "top_n": 10 - }, - "label": "Baidu", - "name": "Baidu4Info" - }, - "dragging": false, - "height": 64, - "id": "Baidu:SharpSignsBeg", - "measured": { - "height": 64, - "width": 200 - }, - "position": { - "x": 932.3075370153801, - "y": 293.31101119905543 - }, - "positionAbsolute": { - "x": 933.5156264729844, - "y": 289.6867428262425 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "Interact_0" - }, - "dragging": false, - "height": 44, - "id": "Answer:TameWavesChange", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 2067.9179213988796, - "y": 373.3415280349531 - }, - "positionAbsolute": { - "x": 2150.301454782809, - "y": 360.9062777128506 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "Function: Collect information such as keywords, titles, audience, words/brands to avoid, tone, and other details provided by the user.\n\nVariables:\n - keyword:Keywords\n - title:Title, \n - audience:Audience\n - brands_to_avoid:Words/brands to avoid.\n\nMUST NOT both of keywords and title are blank." - }, - "label": "Note", - "name": "N:Begin" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 368, - "id": "Note:FruityColtsBattle", - "measured": { - "height": 368, - "width": 275 - }, - "position": { - "x": -430.17115299591364, - "y": -320.31044749815453 - }, - "positionAbsolute": { - "x": -430.17115299591364, - "y": -320.31044749815453 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 368, - "width": 275 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 275 - }, - { - "data": { - "form": { - "text": "If title is not empty, let LLM help you to generate keywords." - }, - "label": "Note", - "name": "N: Keywords gen" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:SilverGiftsHide", - "measured": { - "height": 128, - "width": 269 - }, - "position": { - "x": 100.4673650631783, - "y": 414.8198461927788 - }, - "positionAbsolute": { - "x": 100.4673650631783, - "y": 414.8198461927788 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 269 - }, - { - "data": { - "form": { - "text": "Use user defined keywords to search.\nNext, generate a title based on the search result.\nChange to DuckDuckGo if you want." - }, - "label": "Note", - "name": "N: Baidu4title" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 192, - "id": "Note:ShaggyMelonsFail", - "measured": { - "height": 192, - "width": 254 - }, - "position": { - "x": 101.98068917850298, - "y": -79.85480052081127 - }, - "positionAbsolute": { - "x": 101.98068917850298, - "y": -79.85480052081127 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 192, - "width": 254 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 254 - }, - { - "data": { - "form": { - "text": "Let LLM to generate keywords to search. \nBased on the search result, the outline of the article will be generated." - }, - "label": "Note", - "name": "N: Words to search" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 132, - "id": "Note:EvilIdeasDress", - "measured": { - "height": 132, - "width": 496 - }, - "position": { - "x": 822.1382301557384, - "y": 1.1013324480075255 - }, - "positionAbsolute": { - "x": 822.1382301557384, - "y": 1.1013324480075255 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 132, - "width": 496 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 496 - }, - { - "data": { - "form": { - "text": "1 . User input:\nThe user enters information such as avoid keywords, title, audience, required words/brands, tone, etc. at the start node.\n\n2. Conditional judgment:\nCheck whether the title is empty, if it is empty, generate the title.\n\n3. Generate titles and keywords:\nGenerate SEO optimized titles and related keywords based on the entered user keywords.\n\n4. Web search:\nUse the generated titles and keywords to conduct a Google search to obtain relevant information.\n\n5. Generate outline and articles:\nGenerate article outlines, topics, and bodies based on user input information and search results.\n\n6. Template conversion and output:\nCombine the beginning of the article and the main body to generate a complete article, and output the result." - }, - "label": "Note", - "name": "Steps" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 456, - "id": "Note:WeakApesDivide", - "measured": { - "height": 456, - "width": 955 - }, - "position": { - "x": 441.5385839522079, - "y": 638.4606789293297 - }, - "positionAbsolute": { - "x": 377.5385839522079, - "y": 638.4606789293297 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 450, - "width": 827 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 955 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are an SEO expert and subject area expert. Your task is to generate an SEO article title based on the keywords provided by the user and the context of the Google search.\n\nThe context of the Google search is as follows:\n{Baidu:ShyTeamsJuggle}\nThe context of the Google search is as above.\n\nIn order to craft an SEO article title that is keyword friendly and aligns with the principles observed in the top results you share, it is important to understand why these titles are effective. Here are the principles that may help them rank high:\n1. **Keyword Placement and Clarity**: Each title directly responds to the query by containing the exact keyword or a very close variation. This clarity ensures that search engines can easily understand the relevance of the content.\n2. **Succinctness and directness**: The title is concise, making it easy to read and understand quickly. They avoid unnecessary words and get straight to the point.\n3. **Contains a definition or explanation**: The title implies that the article will define or explain the concept, which is what people searching for \"{Generate:FancyMomentsTalk}\" are looking for.\n4. **Variety of Presentation**: Despite covering similar content, each title approaches the topic from a slightly different angle. This diversity can attract the interest of a wider audience.\n\nGiven these principles, please help me generate a title that will be optimized for the keyword \"{Generate:FancyMomentsTalk}\" based on the syntax of a top-ranking title. \n\nPlease don't copy, but give better options, and avoid using language like \"master,\" \"comprehensive,\" \"discover,\" or \"reveal.\" \n\nDo not use gerunds, only active tense and present tense. \n\nTitle SHOULD be in language as \"{Generate:FancyMomentsTalk}\"\n\nJust return the title.", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Title Gen" - }, - "dragging": false, - "id": "Generate:ReadyHandsInvent", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 362.61841535531624, - "y": 109.52633857873508 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "I want a Google search phrase to get authoritative information for my article \" {begin@title} {Generate:ReadyHandsInvent} {begin@keywords} {Generate:FancyMomentsTalk}\" for {begin@audience}. Please return a search phrase of five words or less so that I can get a good overview of the topic. Include any words you're unfamiliar with in your search query.", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Words to search" - }, - "dragging": false, - "id": "Generate:PublicPotsPush", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 631.7110159663526, - "y": 271.70568678331114 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "I'm an expert blogger.\nHere is some research I did for the blog post title \" {begin@title} {Generate:ReadyHandsInvent}\".\nThese are related search results:\n{Baidu:SharpSignsBeg}\n\nPlease study it in depth:\n\nArticle title: {begin@title} {Generate:ReadyHandsInvent}\nTarget keywords: {begin@keywords} {Generate:FancyMomentsTalk}\nMy blog post’s audience: {begin@audience}\nExclude brands: {begin@brands_to_avoid}\n\nCan you write a detailed blog outline with unique chapters? \n - The outline should include specific points and details that the article can mention. \n - AVOID generalities. \n - This SHOULD be researched in depth, not generalized.\n - Each chapter includes 7-8 projects, use some of the links above for reference if you can. For each item, don't just say \"discuss how\" but actually explain in detail the points that can be made. \n - DO NOT include things that you know are false and may contain inaccuracies. You are writing for a mature audience, avoid generalities and make specific quotes. Make sure to define key terms for users in your outline. Stay away from very controversial topics. \n - In the introduction, provide the background information needed for the rest of the article.\n - Please return in base array format and only the outline array, escaping quotes in the format. Each array item includes a complete chapter:\n[\"Includes Chapter 1 of all sub-projects\", \"Includes Chapter 2 of all sub-projects\", \"Includes Chapter 3 of all sub-projects\", \"Includes Chapter 4 of all sub-projects\"...etc.]\n - Each section SHOULD be wrapped with \"\" and ensure escaping within the content to ensure it is a valid array item.\n - MUST be in language of \" {begin@keywords} {begin@title}\".\n\nHere is an example of valid output. Please follow this structure and ignore the content:\n[\n \"Introduction - Explore the vibrant city of Miami, a destination that offers rich history, diverse culture, and many hidden treasures. Discover the little-known wonders that make Miami a unique destination for adventure seekers. Explore from historical landmarks to exotic places Attractions include atmospheric neighborhoods, local cuisine and lively nightlife. \",\n \"History of Miami - Begin the adventure with a journey into Miami's past. Learn about the city's transformation from a sleepy settlement to a busy metropolis. Understand the impact of multiculturalism on the city's development, as reflected in its architecture, cuisine and lifestyle See. Discover the historical significance of Miami landmarks like Hemingway's home. Uncover the fascinating stories of famous Miami neighborhoods like Key West. Explore the role of art and culture in shaping Miami, as shown at Art Basel events.\n\"Major Attractions - Go beyond Miami's famous beaches and explore the city's top attractions. Discover the artistic talent of the Wynwood Arts District, known for its vibrant street art. Visit iconic South Beach, known for its nightlife and boutiques . Explore the charming Coconut Grove district, known for its tree-lined streets and shopping areas. Visit the Holocaust Memorial Museum, a sombre reminder of a dark chapter in human history. Explore the Everglades Country, one of Miami's natural treasures. The park's diverse wildlife \",\n\"Trail Discovery - Get off the tourist trail and discover Miami's hidden treasures. Experience a water taxi tour across Biscayne Bay to get another perspective on the city. Visit the little-known Kabinett Department of Art, showcasing unique installation art . Explore the abandoned bridges and hidden bars of Duval Street and go on a culinary adventure in local neighborhoods known for their authentic cuisine. Go shopping at Brickell City Center, a trendy shopping and apartment complex in the heart of Miami. body.\",\n\"Local Cuisine - Dive into Miami's food scene and sample the city's diverse flavors. Enjoy ultra-fresh food and drinks at Bartaco, a local favorite. Experience fine dining at upscale Italian restaurants like Il Mulino New York. Explore the city ’s local food market and sample delicious local produce in Miami. Try a unique blend of Cuban and American cuisine that is a testament to Miami’s multicultural heritage.\"\n\"Nightlife - Experience the city's lively nightlife, a perfect blend of sophistication and fun. Visit America's Social Bar & Kitchen, a sports\nA hotspot for enthusiasts. Explore the nightlife of Mary Brickell Village, known for its clubby atmosphere. Spend an evening at Smith & Walensky Miami Beach's South Point Park, known for its stunning views and vintage wines. Visit iconic Miami Beach, famous for its pulsating nightlife. \",\n \"Conclusion- Miami is more than just stunning beaches and dazzling nightlife. It is a treasure trove of experiences waiting to be discovered. From its rich history and diverse culture to its hidden treasures, local cuisine and lively nightlife, Miami has something for everyone A traveler offers a unique adventure to experience the magic of Miami Beach and create unforgettable memories with your family.\"\n]", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Outline gen" - }, - "dragging": false, - "id": "Generate:FastTipsCamp", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 1188.847302971411, - "y": 272.42758089250634 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "You are an SEO expert who writes in a direct, practical, educational style that is factual rather than storytelling or narrative, focusing on explaining to {begin@audience} the \"how\" and \"what is\" and “why” rather than narrating to the audience. \n - Please write at a sixth grade reading level. \n - ONLY output in Markdown format.\n - Use active, present tense, avoid using complex language and syntax, such as \"unravel\", \"dig deeper\", etc., \n - DO NOT provide narration.\n - Now, excluding the title, introduce the blog in 3-5 sentences. \n - Use h2 headings to write chapter titles. \n - Provide a concise, SEO-optimized title. \n - DO NOT include h3 subheadings. \n - Feel free to use bullet points, numbered lists or paragraphs, or bold text for emphasis when appropriate. \n - You should transition naturally to each section, build on each section, and should NOT repeat the same sentence structure. \n - JUST write the introduction of the article based on the outline.\n - DO NOT include title, conclusions, summaries, or summaries, no \"summaries,\" \"conclusions,\" or variations. \n - DO NOT include links or mention any companies that compete with the brand (avoid mentioning {begin@brands_to_avoid}).\n - JUST write the introduction of the article based on the outline.\n - MUST be in language as \"{Generate:FancyMomentsTalk} {Generate:ReadyHandsInvent}\".\n\n\n{Generate:FastTipsCamp}\n\n\n", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Introduction gen" - }, - "dragging": false, - "id": "Generate:FortyBirdsAsk", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 1467.1832072218494, - "y": 273.6641444369902 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "You are an SEO expert who writes in a direct, practical, educational style that is factual rather than storytelling or narrative, focusing on explaining to {begin@audience} the \"how\" and \"what is\" and “why” rather than narrating to the audience. \n - Please write at a sixth grade reading level. \n - ONLY output in Markdown format.\n - Use positive, present tense expressions and avoid using complex words and sentence structures that lack narrative, such as \"reveal\" and \"dig deep.\"\n - Next, please continue writing articles related to our topic with a concise title, {begin@title}{Generate:ReadyHandsInvent} {begin@keywords}{Generate:FancyMomentsTalk}. \n - Please AVOID repeating what has already been written and do not use the same sentence structure. \n - JUST write the body of the article based on the outline.\n - DO NOT include introduction, title.\n - DO NOT miss anything mentioned in article outline, except introduction and title.\n - Please use the information I provide to create in-depth, interesting and unique content. Also, incorporate the references and data points I provided earlier into the article to increase its value to the reader.\n - MUST be in language as \" {begin@keywords} {begin@title}\".\n\n\n{Generate:FastTipsCamp}\n\n", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "Body gen" - }, - "dragging": false, - "id": "Generate:CuddlyBatsCamp", - "measured": { - "height": 108, - "width": 200 - }, - "position": { - "x": 1459.030461505832, - "y": 430.80927477654984 - }, - "selected": true, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - }, - { - "data": { - "form": { - "content": "\n##{begin@title}{Generate:ReadyHandsInvent}\n\n{Generate:FortyBirdsAsk}\n\n\n\n{Generate:CuddlyBatsCamp}\n\n\n", - "parameters": [] - }, - "label": "Template", - "name": "Template trans" - }, - "dragging": false, - "id": "Template:YellowPlumsYell", - "measured": { - "height": 76, - "width": 200 - }, - "position": { - "x": 1784.1452214476085, - "y": 356.5796437282643 + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your SEO blog assistant.\n\nTo get started, please tell me:\n1. What topic you want the blog to cover\n2. Who is the target audience\n3. What you hope to achieve with this blog (e.g., SEO traffic, teaching beginners, promoting a product)\n" + }, + "label": "Begin", + "name": "begin" + }, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Parse_And_Keyword_Agent**, responsible for interpreting a user's blog writing request and generating a structured writing intent summary and keyword strategy for SEO-optimized content generation.\n\n# Goals\n\n1. Extract and infer the user's true writing intent, even if the input is informal or vague.\n\n2. Identify the writing type, target audience, and implied goal.\n\n3. Suggest 3\u20135 long-tail keywords based on the input and context.\n\n4. Output all data in a Markdown format for downstream agents.\n\n# Operating Guidelines\n\n\n- If the user's input lacks clarity, make reasonable and **conservative** assumptions based on SEO best practices.\n\n- Always choose one clear \"Writing Type\" from the list below.\n\n- Your job is not to write the blog \u2014 only to structure the brief.\n\n# Output Format\n\n```markdown\n## Writing Type\n\n[Choose one: Tutorial / Informative Guide / Marketing Content / Case Study / Opinion Piece / How-to / Comparison Article]\n\n## Target Audience\n\n[Try to be specific based on clues in the input: e.g., marketing managers, junior developers, SEO beginners]\n\n## User Intent Summary\n\n[A 1\u20132 sentence summary of what the user wants to achieve with the blog post]\n\n## Suggested Long-tail Keywords\n\n- keyword 1\n\n- keyword 2\n\n- keyword 3\n\n- keyword 4 (optional)\n\n- keyword 5 (optional)\n\n\n\n\n## Input Examples (and how to handle them)\n\nInput: \"I want to write about RAGFlow.\"\n\u2192 Output: Informative Guide, Audience: AI developers, Intent: explain what RAGFlow is and its use cases\n\nInput: \"Need a blog to promote our prompt design tool.\"\n\u2192 Output: Marketing Content, Audience: product managers or tool adopters, Intent: raise awareness and interest in the product\n\n\n\nInput: \"How to get more Google traffic using AI\"\n\u2192 Output: How-to, Audience: SEO marketers, Intent: guide readers on applying AI for SEO growth", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Parse And Keyword Agent" + }, + "dragging": false, + "id": "Agent:ClearRabbitsScream", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 344.7766966202233, + "y": 234.82202253184496 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.3, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 3, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Balance", + "presencePenaltyEnabled": false, + "presence_penalty": 0.2, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Outline_Agent**, responsible for generating a clear and SEO-optimized blog outline based on the user's parsed writing intent and keyword strategy.\n\n# Tool Access:\n\n- You have access to a search tool called `Tavily Search`.\n\n- If you are unsure how to structure a section, you may call this tool to search for related blog outlines or content from Google.\n\n- Do not overuse it. Your job is to extract **structure**, not to write paragraphs.\n\n\n# Goals\n\n1. Create a well-structured outline with appropriate H2 and H3 headings.\n\n2. Ensure logical flow from introduction to conclusion.\n\n3. Assign 1\u20132 suggested long-tail keywords to each major section for SEO alignment.\n\n4. Make the structure suitable for downstream paragraph writing.\n\n\n\n\n#Note\n\n- Use concise, scannable section titles.\n\n- Do not write full paragraphs.\n\n- Prioritize clarity, logical progression, and SEO alignment.\n\n\n\n- If the blog type is \u201cTutorial\u201d or \u201cHow-to\u201d, include step-based sections.\n\n\n# Input\n\nYou will receive:\n\n- Writing Type (e.g., Tutorial, Informative Guide)\n\n- Target Audience\n\n- User Intent Summary\n\n- 3\u20135 long-tail keywords\n\n\nUse this information to design a structure that both informs readers and maximizes search engine visibility.\n\n# Output Format\n\n```markdown\n\n## Blog Title (suggested)\n\n[Give a short, SEO-friendly title suggestion]\n\n## Outline\n\n### Introduction\n\n- Purpose of the article\n\n- Brief context\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 1]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 2]\n\n- [Short description of what this section will cover]\n\n- **Suggested keywords**: [keyword1, keyword2]\n\n### H2: [Section Title 3]\n\n- [Optional H3 Subsection Title A]\n\n - [Explanation of sub-point]\n\n- [Optional H3 Subsection Title B]\n\n - [Explanation of sub-point]\n\n- **Suggested keywords**: [keyword1]\n\n### Conclusion\n\n- Recap key takeaways\n\n- Optional CTA (Call to Action)\n\n- **Suggested keywords**: [keyword3]\n\n", + "temperature": 0.5, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.85, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Outline Agent" + }, + "dragging": false, + "id": "Agent:BetterSitesSend", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 613.4368763415628, + "y": 164.3074269048589 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "dragging": false, + "id": "Tool:SharpPensBurn", + "measured": { + "height": 44, + "width": 200 + }, + "position": { + "x": 580.1877078861457, + "y": 287.7669662022325 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}\n\n\n\nThe Outline agent output is {Agent:BetterSitesSend@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Body_Agent**, responsible for generating the full content of each section of an SEO-optimized blog based on the provided outline and keyword strategy.\n\n# Tool Access:\n\nYou can use the `Tavily Search` tool to retrieve relevant content, statistics, or examples to support each section you're writing.\n\nUse it **only** when the provided outline lacks enough information, or if the section requires factual grounding.\n\nAlways cite the original link or indicate source where possible.\n\n\n# Goals\n\n1. Write each section (based on H2/H3 structure) as a complete and natural blog paragraph.\n\n2. Integrate the suggested long-tail keywords naturally into each section.\n\n3. When appropriate, use the `Tavily Search` tool to enrich your writing with relevant facts, examples, or quotes.\n\n4. Ensure each section is clear, engaging, and informative, suitable for both human readers and search engines.\n\n\n# Style Guidelines\n\n- Write in a tone appropriate to the audience. Be explanatory, not promotional, unless it's a marketing blog.\n\n- Avoid generic filler content. Prioritize clarity, structure, and value.\n\n- Ensure SEO keywords are embedded seamlessly, not forcefully.\n\n\n\n- Maintain writing rhythm. Vary sentence lengths. Use transitions between ideas.\n\n\n# Input\n\n\nYou will receive:\n\n- Blog title\n\n- Structured outline (including section titles, keywords, and descriptions)\n\n- Target audience\n\n- Blog type and user intent\n\nYou must **follow the outline strictly**. Write content **section-by-section**, based on the structure.\n\n\n# Output Format\n\n```markdown\n\n## H2: [Section Title]\n\n[Your generated content for this section \u2014 500-600 words, using keywords naturally.]\n\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Body Agent" + }, + "dragging": false, + "id": "Agent:EagerNailsRemain", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 889.0614605692713, + "y": 247.00973041799065 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_1" + }, + "dragging": false, + "id": "Tool:WickedDeerHeal", + "measured": { + "height": 44, + "width": 200 + }, + "position": { + "x": 853.2006404239659, + "y": 364.37541577229143 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.5, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 4096, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "parameter": "Precise", + "presencePenaltyEnabled": false, + "presence_penalty": 0.5, + "prompts": [ + { + "content": "The parse and keyword agent output is {Agent:ClearRabbitsScream@content}\n\nThe Outline agent output is {Agent:BetterSitesSend@content}\n\nThe Body agent output is {Agent:EagerNailsRemain@content}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Editor_Agent**, responsible for finalizing the blog post for both human readability and SEO effectiveness.\n\n# Goals\n\n1. Polish the entire blog content for clarity, coherence, and style.\n\n2. Improve transitions between sections, ensure logical flow.\n\n3. Verify that keywords are used appropriately and effectively.\n\n4. Conduct a lightweight SEO audit \u2014 checking keyword density, structure (H1/H2/H3), and overall searchability.\n\n\n\n# Style Guidelines\n\n- Be precise. Avoid bloated or vague language.\n\n- Maintain an informative and engaging tone, suitable to the target audience.\n\n- Do not remove keywords unless absolutely necessary for clarity.\n\n- Ensure paragraph flow and section continuity.\n\n\n# Input\n\nYou will receive:\n\n- Full blog content, written section-by-section\n\n- Original outline with suggested keywords\n\n- Target audience and writing type\n\n# Output Format\n\n```markdown\n\n[The revised, fully polished blog post content goes here.]\n\n", + "temperature": 0.2, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.75, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Editor Agent" + }, + "dragging": false, + "id": "Agent:LovelyHeadsOwn", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 1160.3332919804993, + "y": 149.50806732882472 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:LovelyHeadsOwn@content}" + ] + }, + "label": "Message", + "name": "Response" + }, + "dragging": false, + "id": "Message:LegalBeansBet", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1370.6665839609984, + "y": 267.0323933738015 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "This workflow automatically generates a complete SEO-optimized blog article based on a simple user input. You don\u2019t need any writing experience. Just provide a topic or short request \u2014 the system will handle the rest.\n\nThe process includes the following key stages:\n\n1. **Understanding your topic and goals**\n2. **Designing the blog structure**\n3. **Writing high-quality content**\n\n\n" + }, + "label": "Note", + "name": "Workflow Overall Description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 205, + "id": "Note:SlimyGhostsWear", + "measured": { + "height": 205, + "width": 415 + }, + "position": { + "x": -284.3143151688742, + "y": 150.47632147913419 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 415 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis agent reads the user\u2019s input and figures out what kind of blog needs to be written.\n\n**What it does**:\n- Understands the main topic you want to write about \n- Identifies who the blog is for (e.g., beginners, marketers, developers) \n- Determines the writing purpose (e.g., SEO traffic, product promotion, education) \n- Suggests 3\u20135 long-tail SEO keywords related to the topic" + }, + "label": "Note", + "name": "Parse And Keyword Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 152, + "id": "Note:EmptyChairsShake", + "measured": { + "height": 152, + "width": 340 + }, + "position": { + "x": 295.04147626768133, + "y": 372.2755718118446 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 340 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis agent builds the blog structure \u2014 just like writing a table of contents before you start writing the full article.\n\n**What it does**:\n- Suggests a clear blog title that includes important keywords \n- Breaks the article into sections using H2 and H3 headings (like a professional blog layout) \n- Assigns 1\u20132 recommended keywords to each section to help with SEO \n- Follows the writing goal and target audience set in the previous step" + }, + "label": "Note", + "name": "Outline Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 146, + "id": "Note:TallMelonsNotice", + "measured": { + "height": 146, + "width": 343 + }, + "position": { + "x": 598.5644991893463, + "y": 5.801054564756448 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 343 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis agent is responsible for writing the actual content of the blog \u2014 paragraph by paragraph \u2014 based on the outline created earlier.\n\n**What it does**:\n- Looks at each H2/H3 section in the outline \n- Writes 150\u2013220 words of clear, helpful, and well-structured content per section \n- Includes the suggested SEO keywords naturally (not keyword stuffing) \n- Uses real examples or facts if needed (by calling a web search tool like Tavily)" + }, + "label": "Note", + "name": "Body Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 137, + "id": "Note:RipeCougarsBuild", + "measured": { + "height": 137, + "width": 319 + }, + "position": { + "x": 860.4854129814981, + "y": 427.2196835690842 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 319 + }, + { + "data": { + "form": { + "text": "**Purpose**: \nThis agent reviews the entire blog draft to make sure it is smooth, professional, and SEO-friendly. It acts like a human editor before publishing.\n\n**What it does**:\n- Polishes the writing: improves sentence clarity, fixes awkward phrasing \n- Makes sure the content flows well from one section to the next \n- Double-checks keyword usage: are they present, natural, and not overused? \n- Verifies the blog structure (H1, H2, H3 headings) is correct \n- Adds two key SEO elements:\n - **Meta Title** (shows up in search results)\n - **Meta Description** (summary for Google and social sharing)" + }, + "label": "Note", + "name": "Editor Agent" + }, + "dragHandle": ".note-drag-handle", + "height": 146, + "id": "Note:OpenTurkeysSell", + "measured": { + "height": 146, + "width": 320 + }, + "position": { + "x": 1129, + "y": -30 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 320 + } + ] }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "templateNode" - } - ] - }, - "history": [], - "messages": [], - "path": [], - "reference": [] - }, - "avatar": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCACrALIDASIAAhEBAxEB/8QAHwAAAQUBAQADAQAAAAAAAAAAAAYHCAkKBQQBAwsC/8QAUxAAAQQBAwMCAwQFBwgGBgsAAQIDBAUGAAcRCBIhEzEJFEEVIlFhVHGRo9MWIzJEgaGxFzNCUoTE0fAYGSQ0YsElJjY4kuFDU1ZjcneWstLU8f/EAB4BAAEEAwEBAQAAAAAAAAAAAAACAwQIBgcJBQEK/8QAPhEAAgIBAwIEAwYDBgYCAwAAAQIDBAUABhEHEggTITEUQVEVIjJhgdGRobEWM3GywfAJI0JSgsImNENlg//aAAwDAQACEQMRAD8A3MaNGjUjUfRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRr2RIEud6nyrXq+l2ep/ONI7e/u7f84tHPPYr+jzxx545HPj0sMT/AK//ALL/ALzpLsVUsOORx7+3qQNfVHJA/wB+2uP9gW36J+/jfxtH2Bbfon7+N/G04jjqGgVLPASkqJJAAABJJJIAAAJJJAH1I0j17j7ftrW07m+IsutrU2407ktI242tB7VIWhU4KQtKgUqSoBSVApUAQRqBNkIa/b589aDu5C+dKkXdxxz2+Y688dw54545HPvqXDTnslhWr2LBQAsIIpJSobkAsI0bgHg8c/Q65f2Bbfon7+N/G0fYFt+ifv438bXS/wApW3f/ANvMN/8A1RR//wB/X3R9wsDlvtRYuaYpKkvLS2zHjZFTvvurUeEoaaamLccWo/0UISpSuDwDxpoZikxAW9QYsQFAswkkngAACUkkkgAD1J9B66ebE5BVLNj76qASWapOFAA5JJMQAAHqSTwACT7HXH+wLb9E/fxv42j7Atv0T9/G/jacRDiXASnzwePcfl+BP4/r+vHBHP2amee/p6L6jkeh9v46hdin2J/iP202/wBgW36J+/jfxtH2Bbfon7+N/G05GjR57c8cLz/gfy/P8xo7B9T/AC/bTb/YFt+ifv438bR9gW36J+/jfxtORo1985/+0fwP76OwfU/y/bTb/YFt+ifv438bR9gW36J+/jfxtORo18M7j3Cjn29D++jsH1P8v202/wBgW36J+/jfxtH2Bbfon7+N/G05GjX0zOPdVH6H99HYPqf5ftpt/sC2/RP38b+No+wLb9E/fxv42nI0HwCfw/D31889/ov8D++jsH1P8v202/2Bbfon7+N/G0fYFt+ifv438bThl1IPHCvcAnjwCSAOfPI5J9yOPz9ufsSruHPBHt78fUA/Qn6HR57/AEX+B/fR2D6n+X7abj7Atv0T9/G/ja4+ng0z+nYnL93IA449ufnz9SfppDKF4459eff9NGjRo07pOjSwxP8Ar/8Asv8AvOkfpYYn/X/9l/3nTcv9236f5hpSfiH6/wBDqCPxSs3yrCOlm3VilxLpJGT5TjeJ2kuA85GmKo7JNrMsojMlpSXGU2CK1qFK7CC7BflME9rp1nV2P6f92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njnk+5P6zpA6NS0pQpGYlL9jc8+q8+vHPsoHy+moLWZXk81iC/Ibk8+68cfP8ALXuKoxJ+/wAgk+eF8cE/mnn2/LX2JVEHHLqfceexw+P/AIB/gdc3RqKMPUB5Bl59f+pD7/4x/l+ny1O+2bh458r04/6X+X/9OPX567Achj+scfqac/8A4DSig2tTFa7DKAPk/wCYkE+ePHIaPI8fU/XSF0aeix0ELdyGTn09ynA44+kY+mo016ede1+3t554AYfT6sfppey7aokI7fmgTweP5iR49/xZHnz/AGefx1ymJla08F/MeAQeS09yOD4A4b/Wfbj9XtpL6NLejC7iQ94YEHkFfXj25BUgj5aQluWNGjXt7W555BPvwPT19PbTjJvqkD/vfn6/zEn+D+Gv6+36n9L/AHEn+Dpt9GnvIT6t/EftpnvP0H8/304bl5VK9pXPA8fzEkefP/3P/wAtceTYV7y+4SARz/8AUvDxwOAeWgffn9vPPOkpo03JUikHDF+OefQr6+3vypB9hpcc7xN3r288ceoJHuD9R9P9nS1iWtayoFcgDj24ZkEgfnw1x/j766f2/U/pf7iT/B02+jSkrRoO0FuPzK/6KNDzvIxZgvJ+gPH9TpyPt+p/S/3En+Dpt9GjTqIE54JPPHvx8ufoB9dNFi3HPHpo0aNGl6+aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0aNGjRo0a/9k=" + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWF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Iq2dR93xpSgk5SAZ9R6MLAOZFUkpLSUDXp6/KPpGUkmTdswlnKnwbl5ITMdGwcXJi7LKsqzUmT5tWYmkXuF9wjBvb76b7dHheazJ9RElUJOCxViuMlUJC0Gtz6PKyjLBY4qMWUe12r1xZ6lOyT6XPEBKN2CkTDOlZd02TBdTMt7Upx2knrkdCv1UKjDKn1A7XBYH6SCOOrWn5Oi/DtRiu+GleRthDL8rXdVjZlcfWrSIxVlGGGCOnH//Z" } \ No newline at end of file diff --git a/agent/templates/sql_assistant.json b/agent/templates/sql_assistant.json new file mode 100644 index 00000000000..92804abc6ee --- /dev/null +++ b/agent/templates/sql_assistant.json @@ -0,0 +1,718 @@ +{ + "id": 17, + "title": { + "en": "SQL Assistant", + "de": "SQL Assistent", + "zh": "SQL助理"}, + "description": { + "en": "SQL Assistant is an AI-powered tool that lets business users turn plain-English questions into fully formed SQL queries. Simply type your question (e.g., 'Show me last quarter's top 10 products by revenue') and SQL Assistant generates the exact SQL, runs it against your database, and returns the results in seconds. ", + "de": "SQL-Assistent ist ein KI-gestütztes Tool, mit dem Geschäftsanwender einfache englische Fragen in vollständige SQL-Abfragen umwandeln können. Geben Sie einfach Ihre Frage ein (z.B. 'Zeige mir die Top 10 Produkte des letzten Quartals nach Umsatz') und der SQL-Assistent generiert das exakte SQL, führt es gegen Ihre Datenbank aus und liefert die Ergebnisse in Sekunden.", + "zh": "用户能够将简单文本问题转化为完整的SQL查询并输出结果。只需输入您的问题(例如,展示上个季度前十名按收入排序的产品),SQL助理就会生成精确的SQL语句,对其运行您的数据库,并几秒钟内返回结果。"}, + "canvas_type": "Marketing", + "dsl": { + "components": { + "Agent:WickedGoatsDivide": { + "downstream": [ + "ExeSQL:TiredShirtsPull" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "qwen-max@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query: {sys.query}\n\nSchema: {Retrieval:HappyTiesFilm@formalized_content}\n\nSamples about question to SQL: {Retrieval:SmartNewsHammer@formalized_content}\n\nDescription about meanings of tables and files: {Retrieval:SweetDancersAppear@formalized_content}", + "role": "user" + } + ], + "sys_prompt": "### ROLE\nYou are a Text-to-SQL assistant. \nGiven a relational database schema and a natural-language request, you must produce a **single, syntactically-correct MySQL query** that answers the request. \nReturn **nothing except the SQL statement itself**\u2014no code fences, no commentary, no explanations, no comments, no trailing semicolon if not required.\n\n\n### EXAMPLES \n-- Example 1 \nUser: List every product name and its unit price. \nSQL:\nSELECT name, unit_price FROM Products;\n\n-- Example 2 \nUser: Show the names and emails of customers who placed orders in January 2025. \nSQL:\nSELECT DISTINCT c.name, c.email\nFROM Customers c\nJOIN Orders o ON o.customer_id = c.id\nWHERE o.order_date BETWEEN '2025-01-01' AND '2025-01-31';\n\n-- Example 3 \nUser: How many orders have a status of \"Completed\" for each month in 2024? \nSQL:\nSELECT DATE_FORMAT(order_date, '%Y-%m') AS month,\n COUNT(*) AS completed_orders\nFROM Orders\nWHERE status = 'Completed'\n AND YEAR(order_date) = 2024\nGROUP BY month\nORDER BY month;\n\n-- Example 4 \nUser: Which products generated at least \\$10 000 in total revenue? \nSQL:\nSELECT p.id, p.name, SUM(oi.quantity * oi.unit_price) AS revenue\nFROM Products p\nJOIN OrderItems oi ON oi.product_id = p.id\nGROUP BY p.id, p.name\nHAVING revenue >= 10000\nORDER BY revenue DESC;\n\n\n### OUTPUT GUIDELINES\n1. Think through the schema and the request. \n2. Write **only** the final MySQL query. \n3. Do **not** wrap the query in back-ticks or markdown fences. \n4. Do **not** add explanations, comments, or additional text\u2014just the SQL.", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Retrieval:HappyTiesFilm", + "Retrieval:SmartNewsHammer", + "Retrieval:SweetDancersAppear" + ] + }, + "ExeSQL:TiredShirtsPull": { + "downstream": [ + "Message:ShaggyMasksAttend" + ], + "obj": { + "component_name": "ExeSQL", + "params": { + "database": "", + "db_type": "mysql", + "host": "", + "max_records": 1024, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "password": "20010812Yy!", + "port": 3306, + "sql": "{Agent:WickedGoatsDivide@content}", + "username": "13637682833@163.com" + } + }, + "upstream": [ + "Agent:WickedGoatsDivide" + ] + }, + "Message:ShaggyMasksAttend": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{ExeSQL:TiredShirtsPull@formalized_content}" + ] + } + }, + "upstream": [ + "ExeSQL:TiredShirtsPull" + ] + }, + "Retrieval:HappyTiesFilm": { + "downstream": [ + "Agent:WickedGoatsDivide" + ], + "obj": { + "component_name": "Retrieval", + "params": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "{sys.query}", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + }, + "upstream": [ + "begin" + ] + }, + "Retrieval:SmartNewsHammer": { + "downstream": [ + "Agent:WickedGoatsDivide" + ], + "obj": { + "component_name": "Retrieval", + "params": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "{sys.query}", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + }, + "upstream": [ + "begin" + ] + }, + "Retrieval:SweetDancersAppear": { + "downstream": [ + "Agent:WickedGoatsDivide" + ], + "obj": { + "component_name": "Retrieval", + "params": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "{sys.query}", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + }, + "upstream": [ + "begin" + ] + }, + "begin": { + "downstream": [ + "Retrieval:HappyTiesFilm", + "Retrieval:SmartNewsHammer", + "Retrieval:SweetDancersAppear" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your SQL assistant. What can I do for you?" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Retrieval:HappyTiesFilmend", + "source": "begin", + "sourceHandle": "start", + "target": "Retrieval:HappyTiesFilm", + "targetHandle": "end" + }, + { + "id": "xy-edge__beginstart-Retrieval:SmartNewsHammerend", + "source": "begin", + "sourceHandle": "start", + "target": "Retrieval:SmartNewsHammer", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Retrieval:SweetDancersAppearend", + "source": "begin", + "sourceHandle": "start", + "target": "Retrieval:SweetDancersAppear", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Retrieval:HappyTiesFilmstart-Agent:WickedGoatsDivideend", + "source": "Retrieval:HappyTiesFilm", + "sourceHandle": "start", + "target": "Agent:WickedGoatsDivide", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Retrieval:SmartNewsHammerstart-Agent:WickedGoatsDivideend", + "markerEnd": "logo", + "source": "Retrieval:SmartNewsHammer", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Agent:WickedGoatsDivide", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Retrieval:SweetDancersAppearstart-Agent:WickedGoatsDivideend", + "markerEnd": "logo", + "source": "Retrieval:SweetDancersAppear", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Agent:WickedGoatsDivide", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:WickedGoatsDividestart-ExeSQL:TiredShirtsPullend", + "source": "Agent:WickedGoatsDivide", + "sourceHandle": "start", + "target": "ExeSQL:TiredShirtsPull", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__ExeSQL:TiredShirtsPullstart-Message:ShaggyMasksAttendend", + "source": "ExeSQL:TiredShirtsPull", + "sourceHandle": "start", + "target": "Message:ShaggyMasksAttend", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your SQL assistant. What can I do for you?" + }, + "label": "Begin", + "name": "begin" + }, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "{sys.query}", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + }, + "label": "Retrieval", + "name": "Schema" + }, + "dragging": false, + "id": "Retrieval:HappyTiesFilm", + "measured": { + "height": 96, + "width": 200 + }, + "position": { + "x": 414, + "y": 20.5 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "retrievalNode" + }, + { + "data": { + "form": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "{sys.query}", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + }, + "label": "Retrieval", + "name": "Question to SQL" + }, + "dragging": false, + "id": "Retrieval:SmartNewsHammer", + "measured": { + "height": 96, + "width": 200 + }, + "position": { + "x": 406.5, + "y": 175.5 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "retrievalNode" + }, + { + "data": { + "form": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "{sys.query}", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + }, + "label": "Retrieval", + "name": "Database Description" + }, + "dragging": false, + "id": "Retrieval:SweetDancersAppear", + "measured": { + "height": 96, + "width": 200 + }, + "position": { + "x": 403.5, + "y": 328 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "retrievalNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "qwen-max@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query: {sys.query}\n\nSchema: {Retrieval:HappyTiesFilm@formalized_content}\n\nSamples about question to SQL: {Retrieval:SmartNewsHammer@formalized_content}\n\nDescription about meanings of tables and files: {Retrieval:SweetDancersAppear@formalized_content}", + "role": "user" + } + ], + "sys_prompt": "### ROLE\nYou are a Text-to-SQL assistant. \nGiven a relational database schema and a natural-language request, you must produce a **single, syntactically-correct MySQL query** that answers the request. \nReturn **nothing except the SQL statement itself**\u2014no code fences, no commentary, no explanations, no comments, no trailing semicolon if not required.\n\n\n### EXAMPLES \n-- Example 1 \nUser: List every product name and its unit price. \nSQL:\nSELECT name, unit_price FROM Products;\n\n-- Example 2 \nUser: Show the names and emails of customers who placed orders in January 2025. \nSQL:\nSELECT DISTINCT c.name, c.email\nFROM Customers c\nJOIN Orders o ON o.customer_id = c.id\nWHERE o.order_date BETWEEN '2025-01-01' AND '2025-01-31';\n\n-- Example 3 \nUser: How many orders have a status of \"Completed\" for each month in 2024? \nSQL:\nSELECT DATE_FORMAT(order_date, '%Y-%m') AS month,\n COUNT(*) AS completed_orders\nFROM Orders\nWHERE status = 'Completed'\n AND YEAR(order_date) = 2024\nGROUP BY month\nORDER BY month;\n\n-- Example 4 \nUser: Which products generated at least \\$10 000 in total revenue? \nSQL:\nSELECT p.id, p.name, SUM(oi.quantity * oi.unit_price) AS revenue\nFROM Products p\nJOIN OrderItems oi ON oi.product_id = p.id\nGROUP BY p.id, p.name\nHAVING revenue >= 10000\nORDER BY revenue DESC;\n\n\n### OUTPUT GUIDELINES\n1. Think through the schema and the request. \n2. Write **only** the final MySQL query. \n3. Do **not** wrap the query in back-ticks or markdown fences. \n4. Do **not** add explanations, comments, or additional text\u2014just the SQL.", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "SQL Generator " + }, + "dragging": false, + "id": "Agent:WickedGoatsDivide", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 981, + "y": 174 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "database": "", + "db_type": "mysql", + "host": "", + "max_records": 1024, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "password": "20010812Yy!", + "port": 3306, + "sql": "{Agent:WickedGoatsDivide@content}", + "username": "13637682833@163.com" + }, + "label": "ExeSQL", + "name": "ExeSQL" + }, + "dragging": false, + "id": "ExeSQL:TiredShirtsPull", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1211.5, + "y": 212.5 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "ragNode" + }, + { + "data": { + "form": { + "content": [ + "{ExeSQL:TiredShirtsPull@formalized_content}" + ] + }, + "label": "Message", + "name": "Message" + }, + "dragging": false, + "id": "Message:ShaggyMasksAttend", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1447.3125, + "y": 181.5 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "Searches for relevant database creation statements.\n\nIt should label with a knowledgebase to which the schema is dumped in. You could use \" General \" as parsing method, \" 2 \" as chunk size and \" ; \" as delimiter." + }, + "label": "Note", + "name": "Note Schema" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 188, + "id": "Note:ThickClubsFloat", + "measured": { + "height": 188, + "width": 392 + }, + "position": { + "x": 689, + "y": -180.31251144409183 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 392 + }, + { + "data": { + "form": { + "text": "Searches for samples about question to SQL. \n\nYou could use \" Q&A \" as parsing method.\n\nPlease check this dataset:\nhttps://huggingface.co/datasets/InfiniFlow/text2sql" + }, + "label": "Note", + "name": "Note: Question to SQL" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 154, + "id": "Note:ElevenLionsJoke", + "measured": { + "height": 154, + "width": 345 + }, + "position": { + "x": 693.5, + "y": 138 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 345 + }, + { + "data": { + "form": { + "text": "Searches for description about meanings of tables and fields.\n\nYou could use \" General \" as parsing method, \" 2 \" as chunk size and \" ### \" as delimiter." + }, + "label": "Note", + "name": "Note: Database Description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 158, + "id": "Note:ManyRosesTrade", + "measured": { + "height": 158, + "width": 408 + }, + "position": { + "x": 691.5, + "y": 435.69736389555317 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 408 + }, + { + "data": { + "form": { + "text": "The Agent learns which tables may be available based on the responses from three knowledge bases and converts the user's input into SQL statements." + }, + "label": "Note", + "name": "Note: SQL Generator" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 132, + "id": "Note:RudeHousesInvite", + "measured": { + "height": 132, + "width": 383 + }, + "position": { + "x": 1106.9254833678003, + "y": 290.5891036507015 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 383 + }, + { + "data": { + "form": { + "text": "Connect to your database to execute SQL statements." + }, + "label": "Note", + "name": "Note: SQL Executor" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:HungryBatsLay", + "measured": { + "height": 136, + "width": 255 + }, + "position": { + "x": 1185, + "y": -30 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAcFBQYFBAcGBQYIBwcIChELCgkJChUPEAwRGBUaGRgVGBcbHichGx0lHRcYIi4iJSgpKywrGiAvMy8qMicqKyr/2wBDAQcICAoJChQLCxQqHBgcKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKir/wAARCAAwADADAREAAhEBAxEB/8QAGgAAAwEBAQEAAAAAAAAAAAAABQYHBAMAAf/EADIQAAEDAwMCBAMHBQAAAAAAAAECAwQFESEABjESEyJBUYEUY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BGmKeJimHIVc0TY89akCKspT28C5BKgDyR7fvrCFI+q/1DQsvVfudYcVyKw49KU6tZyQbmwHFhrOKr9s0uz0CAIpbr3RKo1Rbh02C4HJISp2ZIz0pJ8IQk5Nr/QXznSX6NSnGAwHI/gD/TM+3vtAj1arJpcpgtPdPSH0kFt5wDxAWOOLgamIAFwijCfD927N2tGXuNxlK2W0occUhJWpR+QzzrPjc+pvyqT3Ftf2zbObf7YYecb6CrrDAGfy20wYMkA5Vjbtev7b3nEcXRela27d1ogoWi/rnQsjrqZzHdwzKoKUsqWz3mOnJUlZJt8uokD621w+RdzgynUkUpoUafPZXMnSHlrKluyX1Eug8XF7GwxbgWxrubMO5WmNRsCKtLfcY3rAU0nIltkBP+w0X8Jjdz//2Q==" +} \ No newline at end of file diff --git a/agent/templates/stock_research_report.json b/agent/templates/stock_research_report.json new file mode 100644 index 00000000000..786d5adbcc2 --- /dev/null +++ b/agent/templates/stock_research_report.json @@ -0,0 +1,1173 @@ +{ + "id": 26, + "title": { + "en": "Stock Research Report Agent", + "de": "Aktienanalyse Agent", + "zh": "股票研究报告智能体" + }, + "description": { + "en": "This template helps financial analysts quickly organize information — it can automatically retrieve company data, consolidate financial metrics, and integrate research report insights.", + "de": "Diese Vorlage hilft Finanzanalysten, Informationen schnell zu organisieren – der Agent kann automatisch Unternehmensdaten abrufen, Finanzkennzahlen konsolidieren und Forschungsberichte integrieren.", + "zh": "这个模板可以帮助金融分析师快速整理信息——它能够自动获取公司数据、整合财务指标,并汇总研报观点。" + }, + "canvas_type": "Recommended", + "dsl": { + "components": { + "Agent:ManyToesBrush": { + "downstream": [ + "Switch:FluffyCoinsSell" + ], + "obj": { + "component_name": "Agent", + "params": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "qwen-turbo-latest@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": " \n\nYour responsibility is to identify and extract the stock name or abbreviation from the user's natural language query and return the corresponding unique stock code.\n\n \n\n\n\n \n\n1. Only one result is allowed: - If a stock is identified \u2192 only return the corresponding stock code; - If no stock is identified \u2192 only return \u201cNot Found\u201d. 2. **Do not** output any additional text, punctuation, explanation, prefixes, or line breaks. 3. The output must strictly adhere to the . \n\n\n\n\n\nOnly output the stock code (e.g., AAPL or 600519)\nOr only output \u201cNot Found\u201d\n\n\n\n\nUser input: \u201cHelp me check the research report of Apple\u201d \u2192 Output: AAPL\nUser input: \u201cHow is Maotai\u2019s financial performance\u201d \u2192 Output: 600519\nUser input: \u201cHow is the Shanghai Composite Index doing today\u201d \u2192 Output: Not Found\n\n\n\n - Tavily Search: Use this tool when you are unsure of the stock code. - If you are confident, you do not need to use the tool. \n\n\n\n\n\nOnly output the result, no explanations, hints, or notes allowed.\nThe output can only be the stock code or \u201cNot Found\u201d, otherwise, it is considered an incorrect answer.\n", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "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", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Agent:SadDodosRescue": { + "downstream": [ + "Agent:SharpSlothsSlide" + ], + "obj": { + "component_name": "Agent", + "params": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "kimi-k2-turbo-preview@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [ + { + "mcp_id": "30d6ef8ea8d511f0828382e3548809fa", + "tools": {} + } + ], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "user's query is {sys.query}\n\n\n{Agent:ManyToesBrush@content}\n", + "role": "user" + } + ], + "sys_prompt": " \n\nYou are the information extraction agent. You understand the user\u2019s query and delegate tasks to investoday and the internal research report retrieval agent. \n\n \n\n\n\n 1. Based on the stock code output by the \"Extract Stock Code\" agent, call investoday's list_news to retrieve the latest authoritative research reports and views, and save all publicly available key information. \n\n2. Call the \"Internal Research Report Retrieval Agent\" and save the full text of the research report output. \n\n3. Output the content retrieved from investoday and the Internal Research Report Retrieval Agent in full. \n\n\n\n\n\nThe output must be divided into two sections:\n#1. Title: \u201cinvestoday\u201d\nDirectly output the content collected from investoday without any additional processing.\n#2. Title: \"Internal Research Report Retrieval Agent\"\nDirectly output the content provided by the Internal Research Report Retrieval Agent.\n", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [ + { + "component_name": "Agent", + "id": "Agent:MightyIdeasGlow", + "name": "Internal Research Report Retrieval Agent", + "params": { + "cite": true, + "delay_after_error": 1, + "description": "You are a senior financial content analyst who can accurately identify the companies, stock codes, industries or topics mentioned in user questions, and completely extract relevant research content from the knowledge base to ensure that data, opinions and conclusions are not lost.", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "kimi-k2-turbo-preview@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": " \n\nRead user input \u2192 Identify the involved company/stock (supports abbreviations, full names, codes, and aliases) \u2192 Retrieve the most relevant research reports from the knowledge base \u2192 Output the full text of the research report, retaining the original format, data, chart descriptions, and risk warnings. \n\n\n\n\n\n \n\n1. Exact Match: Prioritize exact matches of company full names and stock codes. \n\n2. Content Fidelity: Fully retain the research report text stored in the knowledge base without deletion, modification, or omission of paragraphs. \n\n3. Original Data: Retain table data, dates, units, etc., in their original form. \n\n4. Complete Viewpoints: Include investment logic, financial analysis, industry comparisons, earnings forecasts, valuation methods, risk warnings, etc. \n\n5. Merging Multiple Reports: If there are multiple relevant research reports, output them in reverse chronological order. \n\n\n\n6. No Results Feedback: If no matching reports are found, output \u201cNo related research reports available in the knowledge base.\u201d\n\n\n\n ", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "A knowledge base of research reports on stock analysis by senior experts", + "empty_response": "", + "kb_ids": [ + "60c53ed89acc11f0bc1e7a2a6d0b2755" + ], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Switch:FluffyCoinsSell" + ] + }, + "Agent:SharpSlothsSlide": { + "downstream": [ + "Message:OliveLawsArgue" + ], + "obj": { + "component_name": "Agent", + "params": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "qwen-turbo-latest@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User query questions:\n\n\n\n{sys.query}\n\n\n\nInformation Extraction Agent:\n\n{Agent:SadDodosRescue@content}", + "role": "user" + } + ], + "sys_prompt": " \n\nYou are a senior investment banking (IB) analyst with years of experience in capital market research. You excel at writing investment research reports covering publicly listed companies, industries, and macroeconomics. You possess strong financial analysis skills and industry insights, combining quantitative and qualitative analysis to provide high-value references for investment decisions. \n\n**You are able to retain and present differentiated viewpoints from various reports and sources in your research, and when discrepancies arise, you do not merge them into a single conclusion. Instead, you compare and analyze the differences.** \n\n\n \n\n\n\n\n \n\nYou will receive financial information extracted by the information extraction agent.\n\n \n\n\n\nBased on the content returned by the information extraction agent (no fabrication of data), write a professional, complete, and structured investment research report. The report must be logically rigorous, clearly organized, and use professional language, suitable for reference by fund managers, institutional investors, and other professional readers.\nWhen there are differences in analysis or forecasts between different reports or institutions, you must list and identify the sources in the report. You should not select only one viewpoint. You need to point out the differences, their possible causes, and their impact on investment judgments.\n\n\n\n\n##1. Summary\nProvide a concise overview of the company\u2019s core business, recent performance, industry positioning, and major investment highlights.\nSummarize key conclusions in 3-5 sentences.\nHighlight any discrepancies in core conclusions and briefly describe the differing viewpoints and areas of disagreement.\n##2. Company Overview\nDescribe the company's main business, core products/services, market share, competitive advantages, and business model.\nHighlight any differences in the description of the company\u2019s market position or competitive advantages from different sources. Present and compare these differences.\n##3. Recent Financial Performance\nSummarize key metrics from the latest financial report (e.g., revenue, net profit, gross margin, EPS).\nHighlight the drivers behind the trends and compare the differential analyses from different reports. Present this comparison in a table.\n##4. Industry Trends & Opportunities\nOverview of industry development trends, market size, and major drivers.\nIf different sources provide differing forecasts for industry growth rates, technological trends, or competitive landscape, list these and provide background information. Present this comparison in a table.\n##5. Investment Recommendation\nProvide a clear investment recommendation based on the analysis above (e.g., \"Buy/Hold/Neutral/Sell\"), presented in a table.\nInclude investment ratings or recommendations from all sources, with the source and date clearly noted.\nIf you provide a combined recommendation based on different viewpoints, clearly explain the reasoning behind this integration.\n##6. Appendix & References\nList the data sources, analysis methods, important formulas, or chart descriptions used.\nAll references must come from the information extraction agent and the company financial data table provided, or publicly noted sources.\nFor differentiated viewpoints, provide full citation information (author, institution, date) and present this in a table.\n\n\n\n\nLanguage Style: Financial, professional, precise, and analytical.\nViewpoint Retention: When there are multiple viewpoints and conclusions, all must be retained and compared. You cannot choose only one.\nCitations: When specific data or viewpoints are referenced, include the source in parentheses (e.g., Source: Morgan Stanley Research, 2024-05-07).\nFacts: All data and conclusions must come from the information extraction agent or their noted legitimate sources. No fabrication is allowed.\nReadability: Use short paragraphs and bullet points to make it easy for professional readers to grasp key information and see the differences in viewpoints.\n\n\n\n\nGenerate a complete investment research report that meets investment banking industry standards, which can be directly used for institutional investment internal reference, while faithfully retaining differentiated viewpoints from various reports and providing the corresponding analysis.\n", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Agent:SadDodosRescue" + ] + }, + "CodeExec:LightSheepTrade": { + "downstream": [ + "Message:OliveLawsArgue" + ], + "obj": { + "component_name": "CodeExec", + "params": { + "arguments": { + "input_text": "YahooFinance:QuickAdsDig@report" + }, + "lang": "python", + "outputs": { + "md_table": { + "type": "String", + "value": "" + } + }, + "script": "import re\n\ndef format_number(value: str) -> str:\n \"\"\"Convert scientific notation or floating-point numbers to comma-separated numbers\"\"\"\n try:\n num = float(value)\n if num.is_integer():\n return f\"{int(num):,}\" # If it's an integer, format without decimal places\n else:\n return f\"{num:,.2f}\" # Otherwise, keep two decimal places and add commas\n except:\n return value # Return the original value if it's not a number (e.g., \u2014 or empty)\n\ndef extract_md_table_single_column(input_text: str) -> str:\n # Use English indicators directly\n indicators = [\n \"Total Assets\", \"Total Equity\", \"Tangible Book Value\", \"Total Debt\", \n \"Net Debt\", \"Cash And Cash Equivalents\", \"Working Capital\", \n \"Long Term Debt\", \"Common Stock Equity\", \"Ordinary Shares Number\"\n ]\n \n # Core indicators and their corresponding units\n unit_map = {\n \"Total Assets\": \"USD\",\n \"Total Equity\": \"USD\",\n \"Tangible Book Value\": \"USD\",\n \"Total Debt\": \"USD\",\n \"Net Debt\": \"USD\",\n \"Cash And Cash Equivalents\": \"USD\",\n \"Working Capital\": \"USD\",\n \"Long Term Debt\": \"USD\",\n \"Common Stock Equity\": \"USD\",\n \"Ordinary Shares Number\": \"Shares\"\n }\n\n lines = input_text.splitlines()\n\n # Automatically detect the date column, keeping only the first one\n date_pattern = r\"\\d{4}-\\d{2}-\\d{2}\"\n header_line = \"\"\n for line in lines:\n if re.search(date_pattern, line):\n header_line = line\n break\n\n if not header_line:\n raise ValueError(\"Date column header row not found\")\n\n dates = re.findall(date_pattern, header_line)\n first_date = dates[0] # Keep only the first date\n header = f\"| Indicator | {first_date} |\"\n divider = \"|------------------------|------------|\"\n\n rows = []\n for ind in indicators:\n unit = unit_map.get(ind, \"\")\n display_ind = f\"{ind} ({unit})\" if unit else ind\n\n found = False\n for line in lines:\n if ind in line:\n # Match numbers and possible units\n pattern = r\"(nan|[0-9\\.]+(?:[eE][+-]?\\d+)?)\"\n values = re.findall(pattern, line)\n # Replace 'nan' with '\u2014' and format the number\n first_value = values[0].strip() if values and values[0].strip().lower() != \"nan\" else \"\u2014\"\n first_value = format_number(first_value) if first_value != \"\u2014\" else \"\u2014\"\n rows.append(f\"| {display_ind} | {first_value} |\")\n found = True\n break\n if not found:\n rows.append(f\"| {display_ind} | \u2014 |\")\n\n md_table = \"\\n\".join([header, divider] + rows)\n return md_table\n\ndef main(input_text: str):\n return extract_md_table_single_column(input_text)\n" + } + }, + "upstream": [ + "YahooFinance:QuickAdsDig" + ] + }, + "Message:OliveLawsArgue": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "Company financial statements:\n\n{CodeExec:LightSheepTrade@md_table}\n\n\n{Agent:SharpSlothsSlide@content}" + ] + } + }, + "upstream": [ + "Agent:SharpSlothsSlide", + "CodeExec:LightSheepTrade" + ] + }, + "Message:TwentyBanksLeave": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "Your query is not supported." + ] + } + }, + "upstream": [ + "Switch:FluffyCoinsSell" + ] + }, + "Switch:FluffyCoinsSell": { + "downstream": [ + "YahooFinance:QuickAdsDig", + "Agent:SadDodosRescue", + "Message:TwentyBanksLeave" + ], + "obj": { + "component_name": "Switch", + "params": { + "conditions": [ + { + "items": [ + { + "cpn_id": "Agent:ManyToesBrush@content", + "operator": "not contains", + "value": "Not Found" + } + ], + "logical_operator": "and", + "to": [ + "YahooFinance:QuickAdsDig", + "Agent:SadDodosRescue" + ] + } + ], + "end_cpn_ids": [ + "Message:TwentyBanksLeave" + ] + } + }, + "upstream": [ + "Agent:ManyToesBrush" + ] + }, + "YahooFinance:QuickAdsDig": { + "downstream": [ + "CodeExec:LightSheepTrade" + ], + "obj": { + "component_name": "YahooFinance", + "params": { + "balance_sheet": true, + "cash_flow_statement": false, + "financials": false, + "history": false, + "info": false, + "news": false, + "outputs": { + "report": { + "type": "string", + "value": "" + } + }, + "stock_code": "sys.query" + } + }, + "upstream": [ + "Switch:FluffyCoinsSell" + ] + }, + "begin": { + "downstream": [ + "Agent:ManyToesBrush" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your assistant. What can I do for you?" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:ManyToesBrushtool-Tool:AngryRabbitsPlayend", + "source": "Agent:ManyToesBrush", + "sourceHandle": "tool", + "target": "Tool:AngryRabbitsPlay", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:SadDodosRescuestart-Agent:SharpSlothsSlideend", + "source": "Agent:SadDodosRescue", + "sourceHandle": "start", + "target": "Agent:SharpSlothsSlide", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:SadDodosRescueagentBottom-Agent:MightyIdeasGlowagentTop", + "source": "Agent:SadDodosRescue", + "sourceHandle": "agentBottom", + "target": "Agent:MightyIdeasGlow", + "targetHandle": "agentTop" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:MightyIdeasGlowtool-Tool:FullIconsStopend", + "source": "Agent:MightyIdeasGlow", + "sourceHandle": "tool", + "target": "Tool:FullIconsStop", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__YahooFinance:QuickAdsDigstart-CodeExec:LightSheepTradeend", + "markerEnd": "logo", + "source": "YahooFinance:QuickAdsDig", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "CodeExec:LightSheepTrade", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:SharpSlothsSlidestart-Message:OliveLawsArgueend", + "markerEnd": "logo", + "source": "Agent:SharpSlothsSlide", + "sourceHandle": "start", + "style": { + "stroke": "rgba(151, 154, 171, 1)", + "strokeWidth": 1 + }, + "target": "Message:OliveLawsArgue", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:ManyToesBrushend", + "markerEnd": "logo", + "source": "begin", + "sourceHandle": "start", + "style": { + "stroke": "rgba(151, 154, 171, 1)", + "strokeWidth": 1 + }, + "target": "Agent:ManyToesBrush", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:ManyToesBrushstart-Switch:FluffyCoinsSellend", + "source": "Agent:ManyToesBrush", + "sourceHandle": "start", + "target": "Switch:FluffyCoinsSell", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Switch:FluffyCoinsSellCase 1-YahooFinance:QuickAdsDigend", + "markerEnd": "logo", + "source": "Switch:FluffyCoinsSell", + "sourceHandle": "Case 1", + "style": { + "stroke": "rgba(151, 154, 171, 1)", + "strokeWidth": 1 + }, + "target": "YahooFinance:QuickAdsDig", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Switch:FluffyCoinsSellCase 1-Agent:SadDodosRescueend", + "markerEnd": "logo", + "source": "Switch:FluffyCoinsSell", + "sourceHandle": "Case 1", + "style": { + "stroke": "rgba(151, 154, 171, 1)", + "strokeWidth": 1 + }, + "target": "Agent:SadDodosRescue", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Switch:FluffyCoinsSellend_cpn_ids-Message:TwentyBanksLeaveend", + "markerEnd": "logo", + "source": "Switch:FluffyCoinsSell", + "sourceHandle": "end_cpn_ids", + "style": { + "stroke": "rgba(151, 154, 171, 1)", + "strokeWidth": 1 + }, + "target": "Message:TwentyBanksLeave", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__CodeExec:LightSheepTradestart-Message:OliveLawsArgueend", + "markerEnd": "logo", + "source": "CodeExec:LightSheepTrade", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Message:OliveLawsArgue", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:SadDodosRescuetool-Tool:ClearKiwisRollend", + "source": "Agent:SadDodosRescue", + "sourceHandle": "tool", + "target": "Tool:ClearKiwisRoll", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your assistant. What can I do for you?" + }, + "label": "Begin", + "name": "begin" + }, + "dragging": false, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": -250.58492312820874, + "y": 304.13718826989873 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "qwen-turbo-latest@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": " \n\nYour responsibility is to identify and extract the stock name or abbreviation from the user's natural language query and return the corresponding unique stock code.\n\n \n\n\n\n \n\n1. Only one result is allowed: - If a stock is identified \u2192 only return the corresponding stock code; - If no stock is identified \u2192 only return \u201cNot Found\u201d. 2. **Do not** output any additional text, punctuation, explanation, prefixes, or line breaks. 3. The output must strictly adhere to the . \n\n\n\n\n\nOnly output the stock code (e.g., AAPL or 600519)\nOr only output \u201cNot Found\u201d\n\n\n\n\nUser input: \u201cHelp me check the research report of Apple\u201d \u2192 Output: AAPL\nUser input: \u201cHow is Maotai\u2019s financial performance\u201d \u2192 Output: 600519\nUser input: \u201cHow is the Shanghai Composite Index doing today\u201d \u2192 Output: Not Found\n\n\n\n - Tavily Search: Use this tool when you are unsure of the stock code. - If you are confident, you do not need to use the tool. \n\n\n\n\n\nOnly output the result, no explanations, hints, or notes allowed.\nThe output can only be the stock code or \u201cNot Found\u201d, otherwise, it is considered an incorrect answer.\n", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "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", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Extract Stock Code Agent" + }, + "dragging": false, + "id": "Agent:ManyToesBrush", + "measured": { + "height": 76, + "width": 200 + }, + "position": { + "x": 1.784314979916303, + "y": 285.7261182739586 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "dragging": false, + "id": "Tool:AngryRabbitsPlay", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": -1.1174997064789522, + "y": 392.2709327777357 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "content": [ + "Your query is not supported." + ] + }, + "label": "Message", + "name": "Reply to irrelevant message node" + }, + "dragging": false, + "id": "Message:TwentyBanksLeave", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 1274.991898394738, + "y": 540.2215056031129 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "balance_sheet": true, + "cash_flow_statement": false, + "financials": false, + "history": false, + "info": false, + "news": false, + "outputs": { + "report": { + "type": "string", + "value": "" + } + }, + "stock_code": "sys.query" + }, + "label": "YahooFinance", + "name": "YahooFinance" + }, + "dragging": false, + "id": "YahooFinance:QuickAdsDig", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 676.5378050046916, + "y": 74.09222900489664 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "ragNode" + }, + { + "data": { + "form": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "kimi-k2-turbo-preview@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [ + { + "mcp_id": "30d6ef8ea8d511f0828382e3548809fa", + "tools": {} + } + ], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "user's query is {sys.query}\n\n\n{Agent:ManyToesBrush@content}\n", + "role": "user" + } + ], + "sys_prompt": " \n\nYou are the information extraction agent. You understand the user\u2019s query and delegate tasks to investoday and the internal research report retrieval agent. \n\n \n\n\n\n 1. Based on the stock code output by the \"Extract Stock Code\" agent, call investoday's list_news to retrieve the latest authoritative research reports and views, and save all publicly available key information. \n\n2. Call the \"Internal Research Report Retrieval Agent\" and save the full text of the research report output. \n\n3. Output the content retrieved from investoday and the Internal Research Report Retrieval Agent in full. \n\n\n\n\n\nThe output must be divided into two sections:\n#1. Title: \u201cinvestoday\u201d\nDirectly output the content collected from investoday without any additional processing.\n#2. Title: \"Internal Research Report Retrieval Agent\"\nDirectly output the content provided by the Internal Research Report Retrieval Agent.\n", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Information Extraction Agent" + }, + "dragging": false, + "id": "Agent:SadDodosRescue", + "measured": { + "height": 76, + "width": 200 + }, + "position": { + "x": 674.0210917308762, + "y": 154.63747017677127 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "arguments": { + "input_text": "YahooFinance:QuickAdsDig@report" + }, + "lang": "python", + "outputs": { + "md_table": { + "type": "String", + "value": "" + } + }, + "script": "import re\n\ndef format_number(value: str) -> str:\n \"\"\"Convert scientific notation or floating-point numbers to comma-separated numbers\"\"\"\n try:\n num = float(value)\n if num.is_integer():\n return f\"{int(num):,}\" # If it's an integer, format without decimal places\n else:\n return f\"{num:,.2f}\" # Otherwise, keep two decimal places and add commas\n except:\n return value # Return the original value if it's not a number (e.g., \u2014 or empty)\n\ndef extract_md_table_single_column(input_text: str) -> str:\n # Use English indicators directly\n indicators = [\n \"Total Assets\", \"Total Equity\", \"Tangible Book Value\", \"Total Debt\", \n \"Net Debt\", \"Cash And Cash Equivalents\", \"Working Capital\", \n \"Long Term Debt\", \"Common Stock Equity\", \"Ordinary Shares Number\"\n ]\n \n # Core indicators and their corresponding units\n unit_map = {\n \"Total Assets\": \"USD\",\n \"Total Equity\": \"USD\",\n \"Tangible Book Value\": \"USD\",\n \"Total Debt\": \"USD\",\n \"Net Debt\": \"USD\",\n \"Cash And Cash Equivalents\": \"USD\",\n \"Working Capital\": \"USD\",\n \"Long Term Debt\": \"USD\",\n \"Common Stock Equity\": \"USD\",\n \"Ordinary Shares Number\": \"Shares\"\n }\n\n lines = input_text.splitlines()\n\n # Automatically detect the date column, keeping only the first one\n date_pattern = r\"\\d{4}-\\d{2}-\\d{2}\"\n header_line = \"\"\n for line in lines:\n if re.search(date_pattern, line):\n header_line = line\n break\n\n if not header_line:\n raise ValueError(\"Date column header row not found\")\n\n dates = re.findall(date_pattern, header_line)\n first_date = dates[0] # Keep only the first date\n header = f\"| Indicator | {first_date} |\"\n divider = \"|------------------------|------------|\"\n\n rows = []\n for ind in indicators:\n unit = unit_map.get(ind, \"\")\n display_ind = f\"{ind} ({unit})\" if unit else ind\n\n found = False\n for line in lines:\n if ind in line:\n # Match numbers and possible units\n pattern = r\"(nan|[0-9\\.]+(?:[eE][+-]?\\d+)?)\"\n values = re.findall(pattern, line)\n # Replace 'nan' with '\u2014' and format the number\n first_value = values[0].strip() if values and values[0].strip().lower() != \"nan\" else \"\u2014\"\n first_value = format_number(first_value) if first_value != \"\u2014\" else \"\u2014\"\n rows.append(f\"| {display_ind} | {first_value} |\")\n found = True\n break\n if not found:\n rows.append(f\"| {display_ind} | \u2014 |\")\n\n md_table = \"\\n\".join([header, divider] + rows)\n return md_table\n\ndef main(input_text: str):\n return extract_md_table_single_column(input_text)\n" + }, + "label": "CodeExec", + "name": "Code-generated balance sheet" + }, + "dragging": false, + "id": "CodeExec:LightSheepTrade", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 970.444642975358, + "y": 74.04386270784316 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "ragNode" + }, + { + "data": { + "form": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "qwen-turbo-latest@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User query questions:\n\n\n\n{sys.query}\n\n\n\nInformation Extraction Agent:\n\n{Agent:SadDodosRescue@content}", + "role": "user" + } + ], + "sys_prompt": " \n\nYou are a senior investment banking (IB) analyst with years of experience in capital market research. You excel at writing investment research reports covering publicly listed companies, industries, and macroeconomics. You possess strong financial analysis skills and industry insights, combining quantitative and qualitative analysis to provide high-value references for investment decisions. \n\n**You are able to retain and present differentiated viewpoints from various reports and sources in your research, and when discrepancies arise, you do not merge them into a single conclusion. Instead, you compare and analyze the differences.** \n\n\n \n\n\n\n\n \n\nYou will receive financial information extracted by the information extraction agent.\n\n \n\n\n\nBased on the content returned by the information extraction agent (no fabrication of data), write a professional, complete, and structured investment research report. The report must be logically rigorous, clearly organized, and use professional language, suitable for reference by fund managers, institutional investors, and other professional readers.\nWhen there are differences in analysis or forecasts between different reports or institutions, you must list and identify the sources in the report. You should not select only one viewpoint. You need to point out the differences, their possible causes, and their impact on investment judgments.\n\n\n\n\n##1. Summary\nProvide a concise overview of the company\u2019s core business, recent performance, industry positioning, and major investment highlights.\nSummarize key conclusions in 3-5 sentences.\nHighlight any discrepancies in core conclusions and briefly describe the differing viewpoints and areas of disagreement.\n##2. Company Overview\nDescribe the company's main business, core products/services, market share, competitive advantages, and business model.\nHighlight any differences in the description of the company\u2019s market position or competitive advantages from different sources. Present and compare these differences.\n##3. Recent Financial Performance\nSummarize key metrics from the latest financial report (e.g., revenue, net profit, gross margin, EPS).\nHighlight the drivers behind the trends and compare the differential analyses from different reports. Present this comparison in a table.\n##4. Industry Trends & Opportunities\nOverview of industry development trends, market size, and major drivers.\nIf different sources provide differing forecasts for industry growth rates, technological trends, or competitive landscape, list these and provide background information. Present this comparison in a table.\n##5. Investment Recommendation\nProvide a clear investment recommendation based on the analysis above (e.g., \"Buy/Hold/Neutral/Sell\"), presented in a table.\nInclude investment ratings or recommendations from all sources, with the source and date clearly noted.\nIf you provide a combined recommendation based on different viewpoints, clearly explain the reasoning behind this integration.\n##6. Appendix & References\nList the data sources, analysis methods, important formulas, or chart descriptions used.\nAll references must come from the information extraction agent and the company financial data table provided, or publicly noted sources.\nFor differentiated viewpoints, provide full citation information (author, institution, date) and present this in a table.\n\n\n\n\nLanguage Style: Financial, professional, precise, and analytical.\nViewpoint Retention: When there are multiple viewpoints and conclusions, all must be retained and compared. You cannot choose only one.\nCitations: When specific data or viewpoints are referenced, include the source in parentheses (e.g., Source: Morgan Stanley Research, 2024-05-07).\nFacts: All data and conclusions must come from the information extraction agent or their noted legitimate sources. No fabrication is allowed.\nReadability: Use short paragraphs and bullet points to make it easy for professional readers to grasp key information and see the differences in viewpoints.\n\n\n\n\nGenerate a complete investment research report that meets investment banking industry standards, which can be directly used for institutional investment internal reference, while faithfully retaining differentiated viewpoints from various reports and providing the corresponding analysis.\n", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Research report generation agent" + }, + "id": "Agent:SharpSlothsSlide", + "measured": { + "height": 76, + "width": 200 + }, + "position": { + "x": 974.0210917308762, + "y": 154.63747017677127 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "Company financial statements:\n\n{CodeExec:LightSheepTrade@md_table}\n\n\n{Agent:SharpSlothsSlide@content}" + ] + }, + "label": "Message", + "name": "Reply message node" + }, + "dragging": false, + "id": "Message:OliveLawsArgue", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 1279.3354680249918, + "y": 83.53099404318621 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "cite": true, + "delay_after_error": 1, + "description": "You are a senior financial content analyst who can accurately identify the companies, stock codes, industries or topics mentioned in user questions, and completely extract relevant research content from the knowledge base to ensure that data, opinions and conclusions are not lost.", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "kimi-k2-turbo-preview@Moonshot", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": " \n\nRead user input \u2192 Identify the involved company/stock (supports abbreviations, full names, codes, and aliases) \u2192 Retrieve the most relevant research reports from the knowledge base \u2192 Output the full text of the research report, retaining the original format, data, chart descriptions, and risk warnings. \n\n\n\n\n\n \n\n1. Exact Match: Prioritize exact matches of company full names and stock codes. \n\n2. Content Fidelity: Fully retain the research report text stored in the knowledge base without deletion, modification, or omission of paragraphs. \n\n3. Original Data: Retain table data, dates, units, etc., in their original form. \n\n4. Complete Viewpoints: Include investment logic, financial analysis, industry comparisons, earnings forecasts, valuation methods, risk warnings, etc. \n\n5. Merging Multiple Reports: If there are multiple relevant research reports, output them in reverse chronological order. \n\n\n\n6. No Results Feedback: If no matching reports are found, output \u201cNo related research reports available in the knowledge base.\u201d\n\n\n\n ", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "A knowledge base of research reports on stock analysis by senior experts", + "empty_response": "", + "kb_ids": [ + "60c53ed89acc11f0bc1e7a2a6d0b2755" + ], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "This is the order you need to send to the agent.", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Internal Research Report Retrieval Agent" + }, + "dragging": false, + "id": "Agent:MightyIdeasGlow", + "measured": { + "height": 76, + "width": 200 + }, + "position": { + "x": 787.966928431608, + "y": 270.12089782504677 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_1" + }, + "dragging": false, + "id": "Tool:FullIconsStop", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 786.0879409003913, + "y": 373.7912225392144 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "conditions": [ + { + "items": [ + { + "cpn_id": "Agent:ManyToesBrush@content", + "operator": "not contains", + "value": "Not Found" + } + ], + "logical_operator": "and", + "to": [ + "YahooFinance:QuickAdsDig", + "Agent:SadDodosRescue" + ] + } + ], + "end_cpn_ids": [ + "Message:TwentyBanksLeave" + ] + }, + "label": "Switch", + "name": "Switch" + }, + "dragging": false, + "id": "Switch:FluffyCoinsSell", + "measured": { + "height": 146, + "width": 200 + }, + "position": { + "x": 244.5649388872756, + "y": 249.25263304293162 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "switchNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_2" + }, + "id": "Tool:ClearKiwisRoll", + "measured": { + "height": 44, + "width": 200 + }, + "position": { + "x": 592.0210917308762, + "y": 294.6374701767713 + }, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "text": "Regarding the MCP message for the Information Extraction Agent: You must manually add an MCP in MCP Servers before you can use it!" + }, + "label": "Note", + "name": "MCP Note" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 185, + "id": "Note:SadWallsSniff", + "measured": { + "height": 185, + "width": 328 + }, + "position": { + "x": 527.9711365245946, + "y": 448.2236919343899 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 328 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABn4SURBVHgBXZoJkF3nVef/79779rWX16u61Vq6ZVmyJDuObCvYshMlYIIdB5LBhmTGMzW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9FZr1w+DnSc6JkZuJmv4ibuUEZOjTnZ3il1CgScmSIy57UIapcmrxkCBs17z/ULmDgEzrhPhMDObeV87DfXzc9tzO8kDM0L0tJ0OZSDlkOmO9Lp+lMeSjcSXmBX8E7vFo2358YisT9/8/r51/6pvH8PiQBu4M5gvF0AAAAASUVORK5CYII=" +} \ No newline at end of file diff --git a/agent/templates/technical_docs_qa.json b/agent/templates/technical_docs_qa.json new file mode 100644 index 00000000000..37ab9e731c8 --- /dev/null +++ b/agent/templates/technical_docs_qa.json @@ -0,0 +1,336 @@ + +{ + "id": 9, + "title": { + "en": "Technical Docs QA", + "de": "Technische Dokumentation Fragen & Antworten", + "zh": "技术文档问答"}, + "description": { + "en": "This is a document question-and-answer system based on a knowledge base. When a user asks a question, it retrieves relevant document content to provide accurate answers.", + "de": "Dies ist ein dokumentenbasiertes Frage-und-Antwort-System auf Basis einer Wissensdatenbank. Wenn ein Benutzer eine Frage stellt, werden relevante Dokumenteninhalte abgerufen, um genaue Antworten zu liefern.", + "zh": "基于知识库的文档问答系统,当用户提出问题时,会检索相关本地文档并提供准确回答。"}, + "canvas_type": "Customer Support", + "dsl": { + "components": { + "Agent:StalePandasDream": { + "downstream": [ + "Message:BrownPugsStick" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Docs QA Agent**, a specialized knowledge base assistant responsible for providing accurate answers based strictly on the connected documentation repository.\n\n# Core Principles\n\n1. **Knowledge Base Only**: Answer questions EXCLUSIVELY based on information retrieved from the connected knowledge base.\n\n2. **No Content Creation**: Never generate, infer, or create information that is not explicitly present in the retrieved documents.\n\n3. **Source Transparency**: Always indicate when information comes from the knowledge base vs. when it's unavailable.\n\n4. **Accuracy Over Completeness**: Prefer incomplete but accurate answers over complete but potentially inaccurate ones.\n\n# Response Guidelines\n\n## When Information is Available\n\n- Provide direct answers based on retrieved content\n\n- Quote relevant sections when helpful\n\n- Cite the source document/section if available\n\n- Use phrases like: \"According to the documentation...\" or \"Based on the knowledge base...\"\n\n## When Information is Unavailable\n\n- Clearly state: \"I cannot find this information in the current knowledge base.\"\n\n- Do NOT attempt to fill gaps with general knowledge\n\n- Suggest alternative questions that might be covered in the docs\n\n- Use phrases like: \"The documentation does not cover...\" or \"This information is not available in the knowledge base.\"\n\n# Response Format\n\n```markdown\n\n## Answer\n\n[Your response based strictly on knowledge base content]\n\n**Always do these:**\n\n- Use the Retrieval tool for every question\n\n- Be transparent about information availability\n\n- Stick to documented facts only\n\n- Acknowledge knowledge base limitations\n\n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "This is a technical docs knowledge bases.", + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Message:BrownPugsStick": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:StalePandasDream@content}" + ] + } + }, + "upstream": [ + "Agent:StalePandasDream" + ] + }, + "begin": { + "downstream": [ + "Agent:StalePandasDream" + ], + "obj": { + "component_name": "Begin", + "params": {} + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:StalePandasDreamend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:StalePandasDream", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:StalePandasDreamstart-Message:BrownPugsStickend", + "source": "Agent:StalePandasDream", + "sourceHandle": "start", + "target": "Message:BrownPugsStick", + "targetHandle": "end" + }, + { + "id": "xy-edge__Agent:StalePandasDreamtool-Tool:PrettyMasksFloatend", + "source": "Agent:StalePandasDream", + "sourceHandle": "tool", + "target": "Tool:PrettyMasksFloat", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "label": "Begin", + "name": "begin" + }, + "dragging": false, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 47.500000000000014, + "y": 199.5 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "The user query is {sys.query}", + "role": "user" + } + ], + "sys_prompt": "# Role\n\nYou are the **Docs QA Agent**, a specialized knowledge base assistant responsible for providing accurate answers based strictly on the connected documentation repository.\n\n# Core Principles\n\n1. **Knowledge Base Only**: Answer questions EXCLUSIVELY based on information retrieved from the connected knowledge base.\n\n2. **No Content Creation**: Never generate, infer, or create information that is not explicitly present in the retrieved documents.\n\n3. **Source Transparency**: Always indicate when information comes from the knowledge base vs. when it's unavailable.\n\n4. **Accuracy Over Completeness**: Prefer incomplete but accurate answers over complete but potentially inaccurate ones.\n\n# Response Guidelines\n\n## When Information is Available\n\n- Provide direct answers based on retrieved content\n\n- Quote relevant sections when helpful\n\n- Cite the source document/section if available\n\n- Use phrases like: \"According to the documentation...\" or \"Based on the knowledge base...\"\n\n## When Information is Unavailable\n\n- Clearly state: \"I cannot find this information in the current knowledge base.\"\n\n- Do NOT attempt to fill gaps with general knowledge\n\n- Suggest alternative questions that might be covered in the docs\n\n- Use phrases like: \"The documentation does not cover...\" or \"This information is not available in the knowledge base.\"\n\n# Response Format\n\n```markdown\n\n## Answer\n\n[Your response based strictly on knowledge base content]\n\n**Always do these:**\n\n- Use the Retrieval tool for every question\n\n- Be transparent about information availability\n\n- Stick to documented facts only\n\n- Acknowledge knowledge base limitations\n\n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "This is a technical docs knowledge bases.", + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Docs QA Agent" + }, + "dragging": false, + "id": "Agent:StalePandasDream", + "measured": { + "height": 87, + "width": 200 + }, + "position": { + "x": 351.5, + "y": 231 + }, + "selected": true, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:StalePandasDream@content}" + ] + }, + "label": "Message", + "name": "Message_0" + }, + "dragging": false, + "id": "Message:BrownPugsStick", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 671.5, + "y": 192.5 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "dragging": false, + "id": "Tool:PrettyMasksFloat", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 234.5, + "y": 370.5 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "text": "This is a document question-and-answer system based on a knowledge base. When a user asks a question, it retrieves relevant document content to provide accurate answers.\nProcess Steps\n\n#Begin\n\nWorkflow entry: Receive user questions\n\nDocs QA Agent\n\nAI Model: deepseek-chat\n\nFunction: Analyze user questions and understand query intent\n\nRetrieval\n\nFunction: Search for relevant information from connected document knowledge bases\n\nFeature: Ensures answers are based on actual document content\n\nMessage_0 (Output Response)\n\nReturns accurate answers to the user based on the knowledge base\n\n#Core Features\n\nAccuracy: Answers are strictly based on knowledge base content\n\nReliability: Avoid AI illusions and only provide information that is verifiable\n\nSimplicity: Linear process with fast response\n\n#Applicable Scenarios\n\nProduct Documentation Query\n\nTechnical Support Q&A\n\nInternal Enterprise Knowledge Base Search\n\nUser Manual Consultation" + }, + "label": "Note", + "name": "Workflow Overall Description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 154, + "id": "Note:SwiftSuitsFlow", + "measured": { + "height": 154, + "width": 374 + }, + "position": { + "x": 349.65276636527506, + "y": 28.869446726944993 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 374 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABtOSURBVHgBXXoJdF3lee0+050n6UpX82jZ8mzJ84Rt0XgAg7Fxk0CSx4MQSHkNywReVhLaNIau5r1S2oQk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cVRzs+JwIpMsYCQ9jskJzo1/fZiOGy15K4Rl//QiTrz7Ku577CkEfNQNtCrFIoVM1MVxq4BPohBbwF6s+GfYJXVrB5L0wrtfmvuEvYEH350K8QIHs6bZYvATWTG6xUXszmejSKZdg6LuJIUekDCE+d2iQjMEW8zx4rQcTSLIpcFelLIJp270E9c5qfsvIdt7xtYG8xcuBI+z8acpLzyr2zC9sR4rVq6iXZq+pfwsW4eIRjVuUQdD/3Mp3UQf6+YGzki+QNuubQ3R/5zRYhM0WHfqmrUjx4VmechQYKcnKf2SjFpqdBhJeqfZSZpbZKfG1ARLjSxS/M0DFy/4D0gLNq+/HcfPHGbmAjzYjqG0JIJ/+dd/wP+iEWDQVtzw4BcR02huTUaxYSs9V27a1s98iLNjt3ZTRCVyhl3uhvHnoWXeLH8ZL8i6uXPXQ61R3CT3//3Ltek79dnu7p1IjS3gwVaLOGi2aCVCUFdb1mg3lZoMeyoKp9qSbv7RiygoB2nXwuU88fz4CDmaE3KqgKqmaZjPOt/HY6M5SxchwkONQFGIPhGtF2bXYKnYLFZ4rlyRyteE6BIoxHYQvdDDDezm7Xa991Drof+63v8AerY6kofqDVwAAAAASUVORK5CYII=" +} \ No newline at end of file diff --git a/agent/templates/text2sql.json b/agent/templates/text2sql.json deleted file mode 100644 index 9d59d30055f..00000000000 --- a/agent/templates/text2sql.json +++ /dev/null @@ -1,651 +0,0 @@ -{ - "id": 5, - "title": "Text To SQL", - "description": "An agent that converts user queries into SQL statements. You must prepare three knowledge bases: 1: DDL for your database; 2: Examples of user queries converted to SQL statements; 3: A comprehensive description of your database, including but not limited to tables and records.", - "canvas_type": "chatbot", - "dsl": { - "answer": [], - "components": { - "Answer:SocialAdsWonder": { - "downstream": [ - "Retrieval:TrueCornersJam", - "Retrieval:EasyDryersShop", - "Retrieval:LazyChefsWatch" - ], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "begin", - "Generate:CurlyFalconsWorry" - ] - }, - "Generate:CurlyFalconsWorry": { - "downstream": [ - "Answer:SocialAdsWonder" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": false, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 1, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "##The user provides a question and you provide SQL. You will only respond with SQL code and not with any explanations.\n\n##Respond with only SQL code. Do not answer with any explanations -- just the code.\n\n##You may use the following DDL statements as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:TrueCornersJam}.\n\n##You may use the following documentation as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:LazyChefsWatch}.\n\n##You may use the following SQL statements as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:EasyDryersShop}.\n\n", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Retrieval:LazyChefsWatch", - "Retrieval:EasyDryersShop", - "Retrieval:TrueCornersJam" - ] - }, - "Retrieval:EasyDryersShop": { - "downstream": [ - "Generate:CurlyFalconsWorry" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "empty_response": "Nothing found in Q-SQL!", - "inputs": [], - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [], - "rerank_id": "", - "similarity_threshold": 0.2, - "top_k": 1024, - "top_n": 8 - } - }, - "upstream": [ - "Answer:SocialAdsWonder" - ] - }, - "Retrieval:LazyChefsWatch": { - "downstream": [ - "Generate:CurlyFalconsWorry" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "empty_response": "Nothing found in DB-Description!", - "inputs": [], - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [], - "rerank_id": "", - "similarity_threshold": 0.2, - "top_k": 1024, - "top_n": 8 - } - }, - "upstream": [ - "Answer:SocialAdsWonder" - ] - }, - "Retrieval:TrueCornersJam": { - "downstream": [ - "Generate:CurlyFalconsWorry" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "empty_response": "Nothing found in DDL!", - "inputs": [], - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [], - "rerank_id": "", - "similarity_threshold": 0.02, - "top_k": 1024, - "top_n": 8 - } - }, - "upstream": [ - "Answer:SocialAdsWonder" - ] - }, - "begin": { - "downstream": [ - "Answer:SocialAdsWonder" - ], - "obj": { - "component_name": "Begin", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "prologue": "Hi! I'm your smart assistant. What can I do for you?", - "query": [] - } - }, - "upstream": [] - } - }, - "embed_id": "", - "graph": { - "edges": [ - { - "id": "reactflow__edge-begin-Answer:SocialAdsWonderc", - "markerEnd": "logo", - "source": "begin", - "sourceHandle": null, - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:SocialAdsWonder", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Answer:SocialAdsWonderb-Retrieval:TrueCornersJamc", - "markerEnd": "logo", - "source": "Answer:SocialAdsWonder", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:TrueCornersJam", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Answer:SocialAdsWonderb-Retrieval:EasyDryersShopc", - "markerEnd": "logo", - "source": "Answer:SocialAdsWonder", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:EasyDryersShop", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Answer:SocialAdsWonderb-Retrieval:LazyChefsWatchc", - "markerEnd": "logo", - "source": "Answer:SocialAdsWonder", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:LazyChefsWatch", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "xy-edge__Retrieval:LazyChefsWatchb-Generate:CurlyFalconsWorryb", - "markerEnd": "logo", - "source": "Retrieval:LazyChefsWatch", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:CurlyFalconsWorry", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Retrieval:EasyDryersShopb-Generate:CurlyFalconsWorryb", - "markerEnd": "logo", - "source": "Retrieval:EasyDryersShop", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:CurlyFalconsWorry", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Retrieval:TrueCornersJamb-Generate:CurlyFalconsWorryb", - "markerEnd": "logo", - "source": "Retrieval:TrueCornersJam", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:CurlyFalconsWorry", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Generate:CurlyFalconsWorryc-Answer:SocialAdsWonderc", - "markerEnd": "logo", - "source": "Generate:CurlyFalconsWorry", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:SocialAdsWonder", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - } - ], - "nodes": [ - { - "data": { - "label": "Begin", - "name": "begin" - }, - "dragging": false, - "height": 44, - "id": "begin", - "measured": { - "height": 44, - "width": 100 - }, - "position": { - "x": -520.486587527275, - "y": 117.87988995940702 - }, - "positionAbsolute": { - "x": -520.486587527275, - "y": 117.87988995940702 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "beginNode" - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "interface" - }, - "dragging": false, - "height": 44, - "id": "Answer:SocialAdsWonder", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -237.69220760465112, - "y": 119.9282206409824 - }, - "positionAbsolute": { - "x": -284.9289105495367, - "y": 119.9282206409824 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "empty_response": "Nothing found in DDL!", - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "similarity_threshold": 0.02, - "top_n": 8 - }, - "label": "Retrieval", - "name": "DDL" - }, - "dragging": false, - "height": 44, - "id": "Retrieval:TrueCornersJam", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 119.61927071085717, - "y": -40.184181873335746 - }, - "positionAbsolute": { - "x": 119.61927071085717, - "y": -40.184181873335746 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "empty_response": "Nothing found in Q-SQL!", - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "similarity_threshold": 0.2, - "top_n": 8 - }, - "label": "Retrieval", - "name": "Q->SQL" - }, - "dragging": false, - "height": 44, - "id": "Retrieval:EasyDryersShop", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 80.07777425685605, - "y": 120.03075150115158 - }, - "positionAbsolute": { - "x": 81.2024576603057, - "y": 94.16303322180948 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "empty_response": "Nothing found in DB-Description!", - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "similarity_threshold": 0.2, - "top_n": 8 - }, - "label": "Retrieval", - "name": "DB Description" - }, - "dragging": false, - "height": 44, - "id": "Retrieval:LazyChefsWatch", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": 51.228157704293324, - "y": 252.77721891325103 - }, - "positionAbsolute": { - "x": 51.228157704293324, - "y": 252.77721891325103 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "Receives a sentence that the user wants to convert into SQL and displays the result of the large model's SQL conversion." - }, - "label": "Note", - "name": "N: Interface" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 132, - "id": "Note:GentleRabbitsWonder", - "measured": { - "height": 132, - "width": 324 - }, - "position": { - "x": -287.3066094433631, - "y": -30.808189185380513 - }, - "positionAbsolute": { - "x": -287.3066094433631, - "y": -30.808189185380513 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 132, - "width": 324 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 324 - }, - { - "data": { - "form": { - "text": "The large model learns which tables may be available based on the responses from three knowledge bases and converts the user's input into SQL statements." - }, - "label": "Note", - "name": "N: LLM" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 163, - "id": "Note:SixCitiesJoke", - "measured": { - "height": 163, - "width": 334 - }, - "position": { - "x": 19.243366453487255, - "y": 531.9336820600888 - }, - "positionAbsolute": { - "x": 5.12121582244032, - "y": 637.6539219843564 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 147, - "width": 326 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 334 - }, - { - "data": { - "form": { - "text": "Searches for description about meanings of tables and fields." - }, - "label": "Note", - "name": "N: DB description" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:FamousCarpetsTaste", - "measured": { - "height": 128, - "width": 269 - }, - "position": { - "x": 399.9267065852242, - "y": 250.0329701879931 - }, - "positionAbsolute": { - "x": 399.9267065852242, - "y": 250.0329701879931 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 269 - }, - { - "data": { - "form": { - "text": "Searches for samples about question to SQL.\nPlease check this dataset: https://huggingface.co/datasets/InfiniFlow/text2sql" - }, - "label": "Note", - "name": "N: Q->SQL" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 140, - "id": "Note:PoliteBeesArrive", - "measured": { - "height": 140, - "width": 455 - }, - "position": { - "x": 491.0393427986917, - "y": 96.58232093146341 - }, - "positionAbsolute": { - "x": 489.0393427986917, - "y": 96.58232093146341 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 130, - "width": 451 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 455 - }, - { - "data": { - "form": { - "text": "DDL(Data Definition Language).\n\nSearches for relevant database creation statements.\n\nIt should bind with a KB to which DDL is dumped in.\nYou could use 'General' as parsing method and ';' as delimiter." - }, - "label": "Note", - "name": "N: DDL" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 272, - "id": "Note:SmartWingsDouble", - "measured": { - "height": 272, - "width": 288 - }, - "position": { - "x": 406.6930553966363, - "y": -208.84980249039137 - }, - "positionAbsolute": { - "x": 404.1930553966363, - "y": -208.84980249039137 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 258, - "width": 283 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 288 - }, - { - "data": { - "form": { - "cite": false, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 1, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "##The user provides a question and you provide SQL. You will only respond with SQL code and not with any explanations.\n\n##Respond with only SQL code. Do not answer with any explanations -- just the code.\n\n##You may use the following DDL statements as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:TrueCornersJam}.\n\n##You may use the following documentation as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:LazyChefsWatch}.\n\n##You may use the following SQL statements as a reference for what tables might be available. Use responses to past questions also to guide you: {Retrieval:EasyDryersShop}.\n\n", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "GenSQL" - }, - "dragging": false, - "id": "Generate:CurlyFalconsWorry", - "measured": { - "height": 106, - "width": 200 - }, - "position": { - "x": 10.728415797190792, - "y": 410.2569651241076 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - } - ] - }, - "history": [], - "messages": [], - "path": [], - "reference": [] - }, - "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJAAAACoCAYAAAAPb2d4AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsAAAA7AAWrWiQkAADagSURBVHhe7X0JnCVVfe5396Xv7dvLdM++sMywC4ygQUBAcInECFES8SkuRH8viT/3l2di8tREE6MmGpcszyxqXoy4IAhiEhWQRQUGEJBhRrZZYJjpmd5v37Wq7vu+c6q6b/d0z/RM3zu9cL/uc6vq1Kmz/M93/ud/TlWdCtUIEP6mhRYmIRQK+XvTI+xvW2jhqNAiUAtzQotALcwJLQK1MCe0CNTCnNAiUAtzQotALcwJLQK1MCe0CNTCnNAiUAtzQotALcwJLQK1MCcc05upodb92mOK2qHvg84KC+JmqojTIs/SRKsLa2FOaBqBAq3T0jxLGy0N1MKc0CJQC3NC0wikEUDgWli6aGmgFuaEY0KgliZauliiE4mzSGgqq2dL8KlRm+voGWwnQe3zmBX6IDSi0R5uInFpEag+fjOHICFaJdsAWc4OdXmQSE2ZpyVX87FkCNRc4kwpoA7HvVy6GstWhuOOwnXzcJ0SSqUKPKeCqrsPXq1CfweuV4XnOQxXRc1z6W8zLQHKhcNhbsOIhCOIRKJ0EcQiXXQ5RGIRJJNt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CArsPrc6KyqXVk8VIEGS1UM5/PYSzI9tW8Iu4YL7PaqHN7SIC1x+Gs+4qJvaFRQrbioVl12IXZdxqq0g1uDQ+0wRiK4nQlEutMosjZFCI/nXJLRZZdmVqhmNmKs+HQygVg8jHb2nd2xENKZLLo70libqGFFOoZ11ChrOtrQnUqiIxW3X46eBvYb+9J+5Mq4AKQVbXkb2S0dCRYlgY4FVF0OuyetLiYNIsNZIlA9lkioArdlVmCRhoq+ZOg4lmTqhsQe2WCZSBS5VBpJEoNcYdcTQiykj8vNAJMAnco7tcz0Vw3Id/5q4mA87wikagjeydcIRca1gZIwySiETc9WWNDGhXoZBPuz7Tukl2R3aetrE4+souqQX/1K8irvkZZ5vupnURCokVBlGTXCgttlVwLY8k0uJSvSr2D5B7RSdxGEk5/xV7TaGQ9ofsyh8Q/2/T15mbjpURd80eF5R6AWGovDEWiebPsWlgpaBGphTmgRqIU5oUWgFuaEFoFamBNaBGphTmgRqIU5oUWgFuaEFoFamBNaBGphTmgRqIU5oUWgFuaE8ZupLbRwNDAEcl0X5XL5iJ9RaWHpQnpFjwEnEjM9Q2lhCFSpVDA2NtYiUAvjEIFisRgymYzvMz3GNVCpVGoRqIVxiEDSQMlk0veZDsD/B107UcoXqiJgAAAAAElFTkSuQmCC" -} diff --git a/agent/templates/title_chunker.json b/agent/templates/title_chunker.json new file mode 100644 index 00000000000..db7f7311440 --- /dev/null +++ b/agent/templates/title_chunker.json @@ -0,0 +1,371 @@ +{ + "id": 25, + "title": { + "en": "Title Chunker", + "de": "Titel basierte Segmentierung", + "zh": "标题切片" + }, + "description": { + "en": "This template slices the parsed file based on its title structure. It is ideal for documents with well-defined headings, such as product manuals, legal contracts, research reports, and academic papers.", + "de": "Diese Vorlage segmentiert die geparste Datei basierend auf ihrer Titelstruktur. Sie eignet sich ideal für Dokumente mit klar definierten Überschriften, wie Produkthandbücher, Verträge, Forschungsberichte und wissenschaftliche Arbeiten.", + "zh": "此模板将解析后的文件按标题结构进行切片,适用于具有清晰标题层级的文档类型,如产品手册、合同法规、研究报告和学术论文等。" + }, + "canvas_type": "Ingestion Pipeline", + "canvas_category": "dataflow_canvas", + "dsl": { + "components": { + "File": { + "obj": { + "component_name": "File", + "params": {} + }, + "downstream": [ + "Parser:HipSignsRhyme" + ], + "upstream": [] + }, + "Parser:HipSignsRhyme": { + "obj": { + "component_name": "Parser", + "params": { + "outputs": { + "html": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + }, + "markdown": { + "type": "string", + "value": "" + }, + "text": { + "type": "string", + "value": "" + } + }, + "setups": { + "pdf": { + "output_format": "json", + "suffix": [ + "pdf" + ], + "parse_method": "DeepDOC" + }, + "text&markdown": { + "output_format": "text", + "suffix": [ + "md", + "markdown", + "mdx", + "txt" + ] + }, + "word": { + "output_format": "json", + "suffix": [ + "doc", + "docx" + ] + } + } + } + }, + "downstream": [ + "HierarchicalMerger:BusyPoetsSearch" + ], + "upstream": [ + "File" + ] + }, + "Tokenizer:NeatRadiosEnd": { + "obj": { + "component_name": "Tokenizer", + "params": { + "fields": "text", + "filename_embd_weight": 0.1, + "outputs": {}, + "search_method": [ + "embedding", + "full_text" + ] + } + }, + "downstream": [], + "upstream": [ + "HierarchicalMerger:BusyPoetsSearch" + ] + }, + "HierarchicalMerger:BusyPoetsSearch": { + "obj": { + "component_name": "HierarchicalMerger", + "params": { + "hierarchy": 3, + "levels": [ + [ + "^#[^#]" + ], + [ + "^##[^#]" + ], + [ + "^###[^#]" + ], + [ + "^####[^#]" + ] + ], + "outputs": { + "chunks": { + "type": "Array", + "value": [] + } + } + } + }, + "downstream": [ + "Tokenizer:NeatRadiosEnd" + ], + "upstream": [ + "Parser:HipSignsRhyme" + ] + } + }, + "globals": {}, + "graph": { + "nodes": [ + { + "data": { + "label": "File", + "name": "File" + }, + "id": "File", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 50, + "y": 200 + }, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "outputs": { + "html": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + }, + "markdown": { + "type": "string", + "value": "" + }, + "text": { + "type": "string", + "value": "" + } + }, + "setups": [ + { + "fileFormat": "pdf", + "output_format": "json", + "parse_method": "DeepDOC" + }, + { + "fileFormat": "text&markdown", + "output_format": "text" + }, + { + "fileFormat": "word", + "output_format": "json" + } + ] + }, + "label": "Parser", + "name": "Parser" + }, + "dragging": false, + "id": "Parser:HipSignsRhyme", + "measured": { + "height": 204, + "width": 200 + }, + "position": { + "x": 316.99524094206413, + "y": 195.39629819663406 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "parserNode" + }, + { + "data": { + "form": { + "fields": "text", + "filename_embd_weight": 0.1, + "outputs": {}, + "search_method": [ + "embedding", + "full_text" + ] + }, + "label": "Tokenizer", + "name": "Indexer" + }, + "dragging": false, + "id": "Tokenizer:NeatRadiosEnd", + "measured": { + "height": 120, + "width": 200 + }, + "position": { + "x": 855.3572909622682, + "y": 199.08562542263914 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "tokenizerNode" + }, + { + "data": { + "form": { + "hierarchy": "3", + "levels": [ + { + "expressions": [ + { + "expression": "^#[^#]" + } + ] + }, + { + "expressions": [ + { + "expression": "^##[^#]" + } + ] + }, + { + "expressions": [ + { + "expression": "^###[^#]" + } + ] + }, + { + "expressions": [ + { + "expression": "^####[^#]" + } + ] + } + ], + "outputs": { + "chunks": { + "type": "Array", + "value": [] + } + } + }, + "label": "HierarchicalMerger", + "name": "Title Chunker" + }, + "dragging": false, + "id": "HierarchicalMerger:BusyPoetsSearch", + "measured": { + "height": 80, + "width": 200 + }, + "position": { + "x": 587.0312356829183, + "y": 197.9169308584236 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "splitterNode" + }, + { + "data": { + "form": { + "text": "It is ideal for documents with well-defined headings, such as product manuals, legal contracts, research reports, and academic papers." + }, + "label": "Note", + "name": "Chunk by Title" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 159, + "id": "Note:KhakiBerriesPick", + "measured": { + "height": 159, + "width": 323 + }, + "position": { + "x": 623.9675370532708, + "y": 369.74281927307146 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 323 + } + ], + "edges": [ + { + "id": "xy-edge__Filestart-Parser:HipSignsRhymeend", + "source": "File", + "sourceHandle": "start", + "target": "Parser:HipSignsRhyme", + "targetHandle": "end" + }, + { + "id": "xy-edge__Parser:HipSignsRhymestart-HierarchicalMerger:BusyPoetsSearchend", + "source": "Parser:HipSignsRhyme", + "sourceHandle": "start", + "target": "HierarchicalMerger:BusyPoetsSearch", + "targetHandle": "end", + "data": { + "isHovered": false + } + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__HierarchicalMerger:BusyPoetsSearchstart-Tokenizer:NeatRadiosEndend", + "markerEnd": "logo", + "source": "HierarchicalMerger:BusyPoetsSearch", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Tokenizer:NeatRadiosEnd", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [] + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABMaSURBVHgBbVprjF3Vdf72Puc+5s7Lnhm/x/ZgCHWAFLdVKEqogJY2ikIJEUSBhiZFIaVRKZj+KFHa1G7apBS1KlGpkh99EEUgykMiKlFpFCUIyS1pSTFCQLADHmNjjz3jec99nXP27rfW3ufOtZOxru/cc8/Zez2+9a3HHoMLfv7skjuuy/Li4wbmZn6c8t7rdWMMnHOw1kKuyWf56f9dfuSe8rO8y/fyjFyXn/7fy+/llSRJeNbyWW5pZ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/OODmFDGOcXHGn1/Zzngf6jVR2J88Ht2y0OkVbv2EoWeG0CtZEG+wYXBDExEJM45NVhfpxOqLfitDlu6uMYMdBuPIlh4EoZUx0awOyJSXzj1gYh08UCx/gbNzmNof7J4XnHX/Ga+fzOjx2jAlMXnpP1/yTc9PSMxIfFJ+6p4Dfu7HByF4a2RbfQDkkSlMjv4sFGSEZGPSOFn01lEhEn1aTOrF3F6TfqePmpKv7rcYf50w6bthht3vvZr1+W/jPr+PmwuXvqpocZTPdpIpEpQZ+25an6uubkjhWDRTb+W5mdJy9OcNm1wJ4rqdxmh6Ex1u41E6bIjqc8rJvaqyzaWJedOcoDErakM0cSHPsf/n7SabW7YQJ6jlYeHQHnH7/2jz4vPKLl50fNH0zeeB3d+sPeGXHfue3Pw14/A8hkrLPKcrwjR0m836WKnCSOyKUMlya8SkapsdlJGUfVmnRiYVyox6fW9M4lfCwngggmkFyk6PKwvPxrgbC/v0i/vWfq5od5NnBfUSYqH2ecfVr/vL9x6FkG0q8k8ShUYJ7G46UQJjaumejELfxuje0dbocgNnF+2r9vaPZ1vBgR0Qf1rz84/fh+BRu3O0gMH05NEvNgSfP+PDf2w6o/qGTzXIdUIQY4CeIJYhZO2TW7h3O03Mv1XGdCPl5DzOQuFnQlZNEL9aKnzPofkrjDdVQPanzKfy8t/qT94Y17/43pm1Mse3UYnOK8aD8/Ftb/aOPCv4HQQ27JpElpufL0PemdQ2sxF1mqnFgrw8bEmJh+9oFO8kIO0Cz99QHbvvPg9BPrf+zR/7N/6uap3JmD9N2VXHKfFnsuTJh7R1F97/0e6o+Tdag5hY4QRJpUNCsnNhyb2pgvUAQFbYn7+Hyyvs40vfYdDoyffXD6iRf69/p/CbMWUUVYM2EAAAAASUVORK5CYII=" +} \ No newline at end of file diff --git a/agent/templates/trip_planner.json b/agent/templates/trip_planner.json new file mode 100644 index 00000000000..7ca15bc5d80 --- /dev/null +++ b/agent/templates/trip_planner.json @@ -0,0 +1,689 @@ + +{ + "id": 14, + "title": { + "en": "Trip Planner", + "de": "Reiseplaner", + "zh": "旅行规划"}, + "description": { + "en": "This smart trip planner utilizes LLM technology to automatically generate customized travel itineraries, with optional tool integration for enhanced reliability.", + "de": "Dieser intelligente Reiseplaner nutzt LLM-Technologie zur automatischen Generierung maßgeschneiderter Reiserouten mit optionaler Tool-Integration für erhöhte Zuverlässigkeit.", + "zh": "智能旅行规划将利用大模型自动生成定制化的旅行行程,附带可选工具集成,以增强可靠性。"}, + "canvas_type": "Consumer App", + "dsl": { + "components": { + "Agent:OddGuestsPump": { + "downstream": [ + "Agent:RichTermsCamp" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query:\n{sys.query}", + "role": "user" + } + ], + "sys_prompt": "Role: Professional tour guide: Create detailed travel plans per user needs.​\nFirst, specify departure location, destination, and travel duration (for subsequent agents to retrieve).​\nDevelop the plan using tools to get real-time weather, holidays, attraction hours, traffic, etc. Adjust itinerary accordingly (e.g., reschedule outdoor activities on rainy days) to ensure practicality, efficiency, and alignment with user preferences.​\nFor real-time info retrieval, only output tool-returned content and pass it to subsequent agents; never rely on your own knowledge base.​\n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Agent:RichTermsCamp": { + "downstream": [ + "Agent:WeakCarrotsTan" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query:\n{sys.query}\n\nFirst step result:\n{Agent:OddGuestsPump@content}", + "role": "user" + } + ], + "sys_prompt": "You are a Transit & Stay Agent, collaborating with upstream planners.\n\n Use tools to retrieve real-time info for transportation (flights, trains, rentals, etc.) and accommodation (hotels, rentals, etc.) based on the itinerary. Recommend options matching dates, destinations, budgets, and preferences, adjusting for availability or conflicts to align with the overall plan.", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + }, + { + "component_name": "TavilyExtract", + "name": "TavilyExtract", + "params": { + "api_key": "" + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Agent:OddGuestsPump" + ] + }, + "Agent:WeakCarrotsTan": { + "downstream": [ + "Message:ThickEyesUnite" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query:\n{sys.query}\n\nTravel plan:\n{Agent:OddGuestsPump@content}\n\nTransit & Stay plan:\n{Agent:RichTermsCamp@content}", + "role": "user" + } + ], + "sys_prompt": "You are a Result Generator. \nYour task is to produce accurate and reliable travel plans based on integrated information from upstream agents and tool-retrieved data. Ensure the final plan is logically structured, time-efficient, and consistent with all verified details—including clear timelines, confirmed transportation/accommodation arrangements, and practical activity adjustments . Prioritize clarity and feasibility to help users execute the plan smoothly.", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Agent:RichTermsCamp" + ] + }, + "Message:ThickEyesUnite": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:WeakCarrotsTan@content}" + ] + } + }, + "upstream": [ + "Agent:WeakCarrotsTan" + ] + }, + "begin": { + "downstream": [ + "Agent:OddGuestsPump" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I’m here to help plan your trip. Any destination in mind?" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:OddGuestsPumpend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:OddGuestsPump", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:OddGuestsPumpstart-Agent:RichTermsCampend", + "source": "Agent:OddGuestsPump", + "sourceHandle": "start", + "target": "Agent:RichTermsCamp", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:RichTermsCampstart-Agent:WeakCarrotsTanend", + "source": "Agent:RichTermsCamp", + "sourceHandle": "start", + "target": "Agent:WeakCarrotsTan", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:WeakCarrotsTanstart-Message:ThickEyesUniteend", + "source": "Agent:WeakCarrotsTan", + "sourceHandle": "start", + "target": "Message:ThickEyesUnite", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:RichTermsCamptool-Tool:BreezyStreetsHuntend", + "source": "Agent:RichTermsCamp", + "sourceHandle": "tool", + "target": "Tool:BreezyStreetsHunt", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I’m here to help plan your trip. Any destination in mind?" + }, + "label": "Begin", + "name": "begin" + }, + "dragging": false, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 333.3224354104293, + "y": -31.71751112667888 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query:\n{sys.query}", + "role": "user" + } + ], + "sys_prompt": "Role: Professional tour guide: Create detailed travel plans per user needs.​\nFirst, specify departure location, destination, and travel duration (for subsequent agents to retrieve).​\nDevelop the plan using tools to get real-time weather, holidays, attraction hours, traffic, etc. Adjust itinerary accordingly (e.g., reschedule outdoor activities on rainy days) to ensure practicality, efficiency, and alignment with user preferences.​\nFor real-time info retrieval, only output tool-returned content and pass it to subsequent agents; never rely on your own knowledge base.​\n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Travel Planning Agent" + }, + "dragging": false, + "id": "Agent:OddGuestsPump", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 636.3704165924755, + "y": -48.48140762793254 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query:\n{sys.query}\n\nFirst step result:\n{Agent:OddGuestsPump@content}", + "role": "user" + } + ], + "sys_prompt": "You are a Transit & Stay Agent, collaborating with upstream planners.\n\n Use tools to retrieve real-time info for transportation (flights, trains, rentals, etc.) and accommodation (hotels, rentals, etc.) based on the itinerary. Recommend options matching dates, destinations, budgets, and preferences, adjusting for availability or conflicts to align with the overall plan.", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + }, + { + "component_name": "TavilyExtract", + "name": "TavilyExtract", + "params": { + "api_key": "" + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Transit & Stay Agent" + }, + "id": "Agent:RichTermsCamp", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 936.3704165924755, + "y": -48.48140762793254 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 5, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query:\n{sys.query}\n\nTravel plan:\n{Agent:OddGuestsPump@content}\n\nTransit & Stay plan:\n{Agent:RichTermsCamp@content}", + "role": "user" + } + ], + "sys_prompt": "You are a Result Generator. \nYour task is to produce accurate and reliable travel plans based on integrated information from upstream agents and tool-retrieved data. Ensure the final plan is logically structured, time-efficient, and consistent with all verified details—including clear timelines, confirmed transportation/accommodation arrangements, and practical activity adjustments . Prioritize clarity and feasibility to help users execute the plan smoothly.", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Result Generator" + }, + "dragging": false, + "id": "Agent:WeakCarrotsTan", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 1236.3704165924755, + "y": -48.48140762793254 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:WeakCarrotsTan@content}" + ] + }, + "label": "Message", + "name": "Final Plan" + }, + "dragging": false, + "id": "Message:ThickEyesUnite", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1583.2969941480576, + "y": -26.582338101994175 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "The Agent will create detailed travel plans per user needs.\n​Add a map tool(eg. amap MCP) to this Agent for more reliable results." + }, + "label": "Note", + "name": "Note: Travel Planning Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:GentleLlamasShake", + "measured": { + "height": 136, + "width": 244 + }, + "position": { + "x": 628.3550234247459, + "y": -226.23395345704375 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "The Agent will use tools to retrieve real-time info for transportation and accommodation." + }, + "label": "Note", + "name": "Note: Transit & Stay Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:ClearLlamasTell", + "measured": { + "height": 136, + "width": 244 + }, + "position": { + "x": 942.4779236864392, + "y": -224.44816237892894 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "id": "Tool:BreezyStreetsHunt", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 854.3704165924755, + "y": 91.51859237206746 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "text": "The Agent will produce accurate and reliable travel plans based on integrated information from upstream agents and tool-retrieved data. " + }, + "label": "Note", + "name": "Note: Result Generator" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 169, + "id": "Note:LongToysShine", + "measured": { + "height": 169, + "width": 246 + }, + "position": { + "x": 1240.444738031005, + "y": -242.8368862758842 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 246 + }, + { + "data": { + "form": { + "text": "This workflow functions as your smart trip planner, utilizing LLM technology to automatically generate customized travel itineraries and featuring optional tool integration for enhanced reliability.\n" + }, + "label": "Note", + "name": "Workflow Overall Description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 183, + "id": "Note:ProudPlanesMake", + "measured": { + "height": 183, + "width": 284 + }, + "position": { + "x": 197.34345022177064, + "y": -245.57788797841573 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 284 + } + ] + }, + "history": [], + "memory": [], + "messages": [], + "path": [], + "retrieval": [], + "task_id": "abf6ec5e6ddf11f0a28c047c16ec874f" + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABTJSURBVHgBXVprjF3VdV5nn33OPffOnac9HtvYwcQGA+Jh0gQcQsojpCSQBpw+VJQI0VapUqIUaGjUqlI8aZJWaqLQqFLaqP8iVUojlUKbNiqpgBQoARrhEtriB2Cc2PFj3nOf57F3v2/tc8duBq7n3nPP3mc9vrXWt9aeSH7u592PvnBLFMV3R5G/x4nssmKkNCL8LXjhmkRG9JPHKzbhmtHVXiL8JxG+8RH/x1uv1/mNwb8l1/B+7+SyxpC7yblCZM44mcucTFiR/+lbaePz2YHIzpbIeiGHpqw/NNUovvBH9956/EJ5o9GbWx59ZaoTDQ/6KHooViEgCl4Orzgy5283okIaihOpOmJ4L0WMKLRX+Xk9xu+S6tVPCdeDOpneAYFNJVtSKFaWst1Wsu5jmUgieX5FZNx4vZZKLjOpkSksqnz5F1Wj84WHDxxY2VCAwvei/tMSxftsFAUTR0EwJyNFKPt5xWhNbyK1PDehobmUMlrP+314L6JWD94JyvFdO6qk4wy84eSdaSFT+DxtS712Jre66YwpZTbuSWqtNHCpSdfhfhP5Q+0ovvXAgVtX1LRp0j+YmXhfSqgAEhaCWShBAQkRKsJrCaET8xqU4H21J+LaC+EVTE3B+Z4+Sq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of file diff --git a/agent/templates/user_interaction.json b/agent/templates/user_interaction.json new file mode 100644 index 00000000000..57790f9bb27 --- /dev/null +++ b/agent/templates/user_interaction.json @@ -0,0 +1,519 @@ +{ + "id": 27, + "title": { + "en": "Interactive Agent", + "zh": "可交互的 Agent" + }, + "description": { + "en": "During the Agent’s execution, users can actively intervene and interact with the Agent to adjust or guide its output, ensuring the final result aligns with their intentions.", + "zh": "在 Agent 的运行过程中,用户可以随时介入,与 Agent 进行交互,以调整或引导生成结果,使最终输出更符合预期。" + }, + "canvas_type": "Agent", + "dsl": { + "components": { + "Agent:LargeFliesMelt": { + "downstream": [ + "UserFillUp:GoldBroomsRelate" + ], + "obj": { + "component_name": "Agent", + "params": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "qwen-turbo@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + }, + "structured": {} + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User query:{sys.query}", + "role": "user" + } + ], + "sys_prompt": "\nYou are the Planning Agent in a multi-agent RAG workflow.\nYour sole job is to design a crisp, executable Search Plan for the next agent. Do not search or answer the user’s question.\n\n\nUnderstand the user’s task and decompose it into evidence-seeking steps.\nProduce high-quality queries and retrieval settings tailored to the task type (fact lookup, multi-hop reasoning, comparison, statistics, how-to, etc.).\nIdentify missing information that would materially change the plan (≤3 concise questions).\nOptimize for source trustworthiness, diversity, and recency; define stopping criteria to avoid over-searching.\nAnswer in 150 words.\n", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Agent:TangyWordsType": { + "downstream": [ + "Message:FreshWallsStudy" + ], + "obj": { + "component_name": "Agent", + "params": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "qwen-turbo@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + }, + "structured": {} + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "Search Plan: {Agent:LargeFliesMelt@content}\n\n\n\nAwait Response feedback:{UserFillUp:GoldBroomsRelate@instructions}\n", + "role": "user" + } + ], + "sys_prompt": "\nYou are the Search Agent.\nYour job is to execute the approved Search Plan, integrate the Await Response feedback, retrieve evidence, and produce a well-grounded answer.\n\n\nTranslate the plan + feedback into concrete searches.\nCollect diverse, trustworthy, and recent evidence meeting the plan’s evidence bar.\nSynthesize a concise answer; include citations next to claims they support.\nIf evidence is insufficient or conflicting, clearly state limitations and propose next steps.\n\n \nRetrieval: You must use Retrieval to do the search.\n \n", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "", + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "toc_enhance": false, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "UserFillUp:GoldBroomsRelate" + ] + }, + "Message:FreshWallsStudy": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:TangyWordsType@content}" + ] + } + }, + "upstream": [ + "Agent:TangyWordsType" + ] + }, + "UserFillUp:GoldBroomsRelate": { + "downstream": [ + "Agent:TangyWordsType" + ], + "obj": { + "component_name": "UserFillUp", + "params": { + "enable_tips": true, + "inputs": { + "instructions": { + "name": "instructions", + "optional": false, + "options": [], + "type": "paragraph" + } + }, + "outputs": { + "instructions": { + "name": "instructions", + "optional": false, + "options": [], + "type": "paragraph" + } + }, + "tips": "Here is my search plan:\n{Agent:LargeFliesMelt@content}\nAre you okay with it?" + } + }, + "upstream": [ + "Agent:LargeFliesMelt" + ] + }, + "begin": { + "downstream": [ + "Agent:LargeFliesMelt" + ], + "obj": { + "component_name": "Begin", + "params": {} + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 0, + "sys.files": [], + "sys.query": "", + "sys.user_id": "" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:LargeFliesMeltend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:LargeFliesMelt", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:LargeFliesMeltstart-UserFillUp:GoldBroomsRelateend", + "source": "Agent:LargeFliesMelt", + "sourceHandle": "start", + "target": "UserFillUp:GoldBroomsRelate", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__UserFillUp:GoldBroomsRelatestart-Agent:TangyWordsTypeend", + "source": "UserFillUp:GoldBroomsRelate", + "sourceHandle": "start", + "target": "Agent:TangyWordsType", + "targetHandle": "end" + }, + { + "id": "xy-edge__Agent:TangyWordsTypetool-Tool:NastyBatsGoend", + "source": "Agent:TangyWordsType", + "sourceHandle": "tool", + "target": "Tool:NastyBatsGo", + "targetHandle": "end" + }, + { + "id": "xy-edge__Agent:TangyWordsTypestart-Message:FreshWallsStudyend", + "source": "Agent:TangyWordsType", + "sourceHandle": "start", + "target": "Message:FreshWallsStudy", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "label": "Begin", + "name": "begin" + }, + "dragging": false, + "id": "begin", + "measured": { + "height": 50, + "width": 200 + }, + "position": { + "x": 154.9008789064451, + "y": 119.51001744285344 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "qwen-turbo@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + }, + "structured": {} + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User query:{sys.query}", + "role": "user" + } + ], + "sys_prompt": "\nYou are the Planning Agent in a multi-agent RAG workflow.\nYour sole job is to design a crisp, executable Search Plan for the next agent. Do not search or answer the user’s question.\n\n\nUnderstand the user’s task and decompose it into evidence-seeking steps.\nProduce high-quality queries and retrieval settings tailored to the task type (fact lookup, multi-hop reasoning, comparison, statistics, how-to, etc.).\nIdentify missing information that would materially change the plan (≤3 concise questions).\nOptimize for source trustworthiness, diversity, and recency; define stopping criteria to avoid over-searching.\nAnswer in 150 words.\n", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Planning Agent" + }, + "dragging": false, + "id": "Agent:LargeFliesMelt", + "measured": { + "height": 90, + "width": 200 + }, + "position": { + "x": 443.96309330796714, + "y": 104.61370811205677 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "enable_tips": true, + "inputs": { + "instructions": { + "name": "instructions", + "optional": false, + "options": [], + "type": "paragraph" + } + }, + "outputs": { + "instructions": { + "name": "instructions", + "optional": false, + "options": [], + "type": "paragraph" + } + }, + "tips": "Here is my search plan:\n{Agent:LargeFliesMelt@content}\nAre you okay with it?" + }, + "label": "UserFillUp", + "name": "Await Response" + }, + "dragging": false, + "id": "UserFillUp:GoldBroomsRelate", + "measured": { + "height": 50, + "width": 200 + }, + "position": { + "x": 683.3409492927474, + "y": 116.76274137645598 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "ragNode" + }, + { + "data": { + "form": { + "cite": true, + "delay_after_error": 1, + "description": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": "", + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "qwen-turbo@Tongyi-Qianwen", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + }, + "structured": {} + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "Search Plan: {Agent:LargeFliesMelt@content}\n\n\n\nAwait Response feedback:{UserFillUp:GoldBroomsRelate@instructions}\n", + "role": "user" + } + ], + "sys_prompt": "\nYou are the Search Agent.\nYour job is to execute the approved Search Plan, integrate the Await Response feedback, retrieve evidence, and produce a well-grounded answer.\n\n\nTranslate the plan + feedback into concrete searches.\nCollect diverse, trustworthy, and recent evidence meeting the plan’s evidence bar.\nSynthesize a concise answer; include citations next to claims they support.\nIf evidence is insufficient or conflicting, clearly state limitations and propose next steps.\n\n \nRetrieval: You must use Retrieval to do the search.\n \n", + "temperature": 0.1, + "temperatureEnabled": false, + "tools": [ + { + "component_name": "Retrieval", + "name": "Retrieval", + "params": { + "cross_languages": [], + "description": "", + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "rerank_id": "", + "similarity_threshold": 0.2, + "toc_enhance": false, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Search Agent" + }, + "dragging": false, + "id": "Agent:TangyWordsType", + "measured": { + "height": 90, + "width": 200 + }, + "position": { + "x": 944.6411255659472, + "y": 99.84499066368488 + }, + "selected": true, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "id": "Tool:NastyBatsGo", + "measured": { + "height": 50, + "width": 200 + }, + "position": { + "x": 862.6411255659472, + "y": 239.84499066368488 + }, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:TangyWordsType@content}" + ] + }, + "label": "Message", + "name": "Message" + }, + "dragging": false, + "id": "Message:FreshWallsStudy", + "measured": { + "height": 50, + "width": 200 + }, + "position": { + "x": 1216.7057997987163, + "y": 120.48541298149814 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + } + ] + }, + "history": [], + "messages": [], + "path": [], + "retrieval": [], + "variables": {} + }, + "avatar": + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA1FSURBVHgBzVppcFRVFv7e672TTjrprGTrkI1tgFjiAI4TmgEGcEFgVFAHxr2mLFe0cKxyBOeHljVjwVDqzDhVTqksOlOiuCBrCwk7hCAkLAGy70kn3eklvb03571e8rrTCQGi5em6ecu9fe85557znXNuh0EUHTGb5/Ast4TnmXsB3oifBTFVxEsVy7PrZ5lM9RE9oZvTZrPeAe51Gvh85ABGMuonJh6Ra9Mzw2KDm2PXm0ymPoS6ReZ5n5n6p4f45QOsj0ihEXxwdGg9Pta3Ax2R98ErH+wIzMFjFFTlhcwkCMEKT4qE+Nc5np8e5Aa8MAf94UNtm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ED08/CNxgm2HZcCy5XjkGt16Dp/Fms3vUfiyGFtv4KK/ftQWFxEhwEMvFQwyTihWFKIJ4Ie+u6V0+XkUjzcDhvcNJ9ckkxgSN6LoNfzsYA08t3ooTYA1UrjrXD+cAC/mj+X0CYJ/cT8oe++ppQiBf2OfjE5tFD2qzekIk9GdXpGDtRUSMnpN4wByptSUhOhdLVK6gFecu4SfY3Nxo0TbX18qhHujHqkjy9G84WT6GptwZUOC2qqziM7Lx16jRI54/MJwTzgKYdiBSgWYopSQ0edJXB6/NhyslYCo+F8Q5KDYGiUHVTiTYkAn9MGfcks9NFRpnAUqc/MIgY5LF1xH9Ioe1247H5MnjQNxZNvAUMptttuQyYdlrXRaYmccqnaLhvSEjWRFdlozEDK+I0KIVZiAsRSkaSdOBfeumPobWkUS9RcOqZJjtchJbsEjt42eEhQpS5ZFBiETHVX68jnPHR040YGHW1GFjQxXED67mbq2IhpJTvJu21QjZ8BFaXRPnq2kP3rE3RouUBVHsGzlQ4PEhLi4CB/aCLo9dLhmRDFs+k3jEt0GC3sQD01Y2jCoatJb6MGXEOe0QnMUPCyI+OWBdDk/AK1x3ejraFeLJYG6DTE7XIhjiC0z9IFJ9UNOq2AOz4UZ2bD6hyokj22enU+zTETN0LMyO16MliOzEmpVsH4i1lIzy2kn0+14CjAUSYHi80uFj8cOfL4wiJkpKfT4QKHLB37HVNuNs9hWc6MkVU5IiL9GCSccMsVKjrOl5HZuKnWtqKj4TI6as+AcffTkaUKfl6WL9rEoQP7NpAenhvNxEOO92LGjx+BGCGfUkKh0ZIv21Bz9vTGJ59+8XlRALPZrFexvLAL0zEGNNLJ80h910FVmoQkU2lpaeBfDYT/OXBzjIm0uhFjQMwN9o2KOH6jhngVmI853xGz2QgZ1lH2MI3yIXFHeP4nNP7YVE9cfMlw7BezTKbvpR3/Bx465XnKBextAAAAAElFTkSuQmCC" +} \ No newline at end of file diff --git a/agent/templates/web_search_assistant.json b/agent/templates/web_search_assistant.json new file mode 100644 index 00000000000..eaf0dedc800 --- /dev/null +++ b/agent/templates/web_search_assistant.json @@ -0,0 +1,875 @@ + +{ + "id": 16, + "title": { + "en": "WebSearch Assistant", + "de": "Websuche Assistent", + "zh": "网页搜索助手"}, + "description": { + "en": "A chat assistant template that integrates information extracted from a knowledge base and web searches to respond to queries. Let's start by setting up your knowledge base in 'Retrieval'!", + "de": "Eine Chat-Assistenten-Vorlage, die Informationen aus einer Wissensdatenbank und Websuchen integriert, um auf Anfragen zu antworten. Beginnen wir mit der Einrichtung Ihrer Wissensdatenbank unter 'Retrieval'!", + "zh": "集成了从知识库和网络搜索中提取的信息回答用户问题。让我们从设置您的知识库开始检索!"}, + "canvas_type": "Other", + "dsl": { + "components": { + "Agent:SmartSchoolsCross": { + "downstream": [ + "Message:ShaggyRingsCrash" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query:\n{sys.query}\n\nRefined question:\n{Agent:ThreePathsDecide@content}\n\nWeb search result:\n{Agent:WildGoatsRule@content}\n\nRetrieval result:\n{Agent:WildGoatsRule@content}", + "role": "user" + } + ], + "sys_prompt": "Role: You are an Answer Organizer.\nTask: Generate the answer based on the provided content from: User's query, Refined question, Web search result, Retrieval result.\n\nRequirements:\n - Answer should be in markdown format.\n - Answer should include all \n - Do not make thing up when there's no relevant information to user's question. \n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Agent:WildGoatsRule", + "Retrieval:WarmTimesRun" + ] + }, + "Agent:ThreePathsDecide": { + "downstream": [ + "Agent:WildGoatsRule", + "Retrieval:WarmTimesRun" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "Role: You are a Question Refinement Agent. Rewrite ambiguous or incomplete user questions to align with knowledge base terminology using conversation history.\n\nExample:\n\nUser: What's RAGFlow?\nAssistant: RAGFlow is xxx.\n\nUser: How to deloy it?\nRefine it: How to deploy RAGFlow?", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "begin" + ] + }, + "Agent:WildGoatsRule": { + "downstream": [ + "Agent:SmartSchoolsCross" + ], + "obj": { + "component_name": "Agent", + "params": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 2, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query:\n{sys.query}\n\nRefined question:\n{Agent:ThreePathsDecide@content}", + "role": "user" + } + ], + "sys_prompt": "Role: You are a Search-Driven Information Agent that answers questions using web search results.\n\nWorkflow:\nKeyword Extraction:\nExtract exactly 3 keywords from the user's question.\n\nKeywords must be:\n✅ Most specific nouns/proper nouns (e.g., \"iPhone 15 Pro\" not \"phone\")\n✅ Core concepts (e.g., \"quantum entanglement\" not \"science thing\")\n✅ Unbiased (no added opinions)\nNever output keywords to users\n\nSearch & Answer:\nUse search tools (TavilySearch, TavilyExtract, Google, Bing, DuckDuckGo, Wikipedia) with the 3 keywords to retrieve results.\nAnswer solely based on search findings, citing sources.\nIf results conflict, prioritize recent (.gov/.edu > forums)\n\nOutput Rules:\n✖️ Never show keywords in final answers\n✖️ Never guess if search yields no results\n✅ Always cite sources using [Source #] notation", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + }, + { + "component_name": "TavilyExtract", + "name": "TavilyExtract", + "params": { + "api_key": "" + } + }, + { + "component_name": "Google", + "name": "Google", + "params": { + "api_key": "", + "country": "us", + "language": "en" + } + }, + { + "component_name": "Bing", + "name": "Bing", + "params": { + "api_key": "YOUR_API_KEY (obtained from https://www.microsoft.com/en-us/bing/apis/bing-web-search-api)", + "channel": "Webpages", + "country": "CH", + "language": "en", + "top_n": 10 + } + }, + { + "component_name": "DuckDuckGo", + "name": "DuckDuckGo", + "params": { + "channel": "text", + "top_n": 10 + } + }, + { + "component_name": "Wikipedia", + "name": "Wikipedia", + "params": { + "language": "en", + "top_n": 10 + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + } + }, + "upstream": [ + "Agent:ThreePathsDecide" + ] + }, + "Message:ShaggyRingsCrash": { + "downstream": [], + "obj": { + "component_name": "Message", + "params": { + "content": [ + "{Agent:SmartSchoolsCross@content}" + ] + } + }, + "upstream": [ + "Agent:SmartSchoolsCross" + ] + }, + "Retrieval:WarmTimesRun": { + "downstream": [ + "Agent:SmartSchoolsCross" + ], + "obj": { + "component_name": "Retrieval", + "params": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "Agent:ThreePathsDecide@content", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + } + }, + "upstream": [ + "Agent:ThreePathsDecide" + ] + }, + "begin": { + "downstream": [ + "Agent:ThreePathsDecide" + ], + "obj": { + "component_name": "Begin", + "params": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your web search assistant. What do you want to search today?" + } + }, + "upstream": [] + } + }, + "globals": { + "sys.conversation_turns": 1, + "sys.files": [], + "sys.query": "你好", + "sys.user_id": "d6d98fd652f911f0a8fb047c16ec874f" + }, + "graph": { + "edges": [ + { + "data": { + "isHovered": false + }, + "id": "xy-edge__beginstart-Agent:ThreePathsDecideend", + "source": "begin", + "sourceHandle": "start", + "target": "Agent:ThreePathsDecide", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:ThreePathsDecidestart-Agent:WildGoatsRuleend", + "source": "Agent:ThreePathsDecide", + "sourceHandle": "start", + "target": "Agent:WildGoatsRule", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:ThreePathsDecidestart-Retrieval:WarmTimesRunend", + "source": "Agent:ThreePathsDecide", + "sourceHandle": "start", + "target": "Retrieval:WarmTimesRun", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:WildGoatsRulestart-Agent:SmartSchoolsCrossend", + "source": "Agent:WildGoatsRule", + "sourceHandle": "start", + "target": "Agent:SmartSchoolsCross", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:SmartSchoolsCrossstart-Message:ShaggyRingsCrashend", + "source": "Agent:SmartSchoolsCross", + "sourceHandle": "start", + "target": "Message:ShaggyRingsCrash", + "targetHandle": "end" + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Retrieval:WarmTimesRunstart-Agent:SmartSchoolsCrossend", + "markerEnd": "logo", + "source": "Retrieval:WarmTimesRun", + "sourceHandle": "start", + "style": { + "stroke": "rgba(91, 93, 106, 1)", + "strokeWidth": 1 + }, + "target": "Agent:SmartSchoolsCross", + "targetHandle": "end", + "type": "buttonEdge", + "zIndex": 1001 + }, + { + "data": { + "isHovered": false + }, + "id": "xy-edge__Agent:WildGoatsRuletool-Tool:TrueCrewsTakeend", + "source": "Agent:WildGoatsRule", + "sourceHandle": "tool", + "target": "Tool:TrueCrewsTake", + "targetHandle": "end" + } + ], + "nodes": [ + { + "data": { + "form": { + "enablePrologue": true, + "inputs": {}, + "mode": "conversational", + "prologue": "Hi! I'm your web search assistant. What do you want to search today?" + }, + "label": "Begin", + "name": "begin" + }, + "dragging": false, + "id": "begin", + "measured": { + "height": 48, + "width": 200 + }, + "position": { + "x": 32.79251060693639, + "y": 209.67921278359827 + }, + "selected": false, + "sourcePosition": "left", + "targetPosition": "right", + "type": "beginNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "{sys.query}", + "role": "user" + } + ], + "sys_prompt": "Role: You are a Question Refinement Agent. Rewrite ambiguous or incomplete user questions to align with knowledge base terminology using conversation history.\n\nExample:\n\nUser: What's RAGFlow?\nAssistant: RAGFlow is xxx.\n\nUser: How to deloy it?\nRefine it: How to deploy RAGFlow?", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Refine Question" + }, + "dragging": false, + "id": "Agent:ThreePathsDecide", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 309.1322126914739, + "y": 188.16985104226876 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 2, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query:\n{sys.query}\n\nRefined question:\n{Agent:ThreePathsDecide@content}", + "role": "user" + } + ], + "sys_prompt": "Role: You are a Search-Driven Information Agent that answers questions using web search results.\n\nWorkflow:\nKeyword Extraction:\nExtract exactly 3 keywords from the user's question.\n\nKeywords must be:\n✅ Most specific nouns/proper nouns (e.g., \"iPhone 15 Pro\" not \"phone\")\n✅ Core concepts (e.g., \"quantum entanglement\" not \"science thing\")\n✅ Unbiased (no added opinions)\nNever output keywords to users\n\nSearch & Answer:\nUse search tools (TavilySearch, TavilyExtract, Google, Bing, DuckDuckGo, Wikipedia) with the 3 keywords to retrieve results.\nAnswer solely based on search findings, citing sources.\nIf results conflict, prioritize recent (.gov/.edu > forums)\n\nOutput Rules:\n✖️ Never show keywords in final answers\n✖️ Never guess if search yields no results\n✅ Always cite sources using [Source #] notation", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [ + { + "component_name": "TavilySearch", + "name": "TavilySearch", + "params": { + "api_key": "", + "days": 7, + "exclude_domains": [], + "include_answer": false, + "include_domains": [], + "include_image_descriptions": false, + "include_images": false, + "include_raw_content": true, + "max_results": 5, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + }, + "json": { + "type": "Array", + "value": [] + } + }, + "query": "sys.query", + "search_depth": "basic", + "topic": "general" + } + }, + { + "component_name": "TavilyExtract", + "name": "TavilyExtract", + "params": { + "api_key": "" + } + }, + { + "component_name": "Google", + "name": "Google", + "params": { + "api_key": "", + "country": "us", + "language": "en" + } + }, + { + "component_name": "Bing", + "name": "Bing", + "params": { + "api_key": "YOUR_API_KEY (obtained from https://www.microsoft.com/en-us/bing/apis/bing-web-search-api)", + "channel": "Webpages", + "country": "CH", + "language": "en", + "top_n": 10 + } + }, + { + "component_name": "DuckDuckGo", + "name": "DuckDuckGo", + "params": { + "channel": "text", + "top_n": 10 + } + }, + { + "component_name": "Wikipedia", + "name": "Wikipedia", + "params": { + "language": "en", + "top_n": 10 + } + } + ], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Search Agent" + }, + "dragging": false, + "id": "Agent:WildGoatsRule", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 678.5892767651895, + "y": 2.074237779456759 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "cross_languages": [], + "empty_response": "", + "kb_ids": [], + "keywords_similarity_weight": 0.7, + "outputs": { + "formalized_content": { + "type": "string", + "value": "" + } + }, + "query": "Agent:ThreePathsDecide@content", + "rerank_id": "", + "similarity_threshold": 0.2, + "top_k": 1024, + "top_n": 8, + "use_kg": false + }, + "label": "Retrieval", + "name": "Retrieval from knowledge bases " + }, + "dragging": false, + "id": "Retrieval:WarmTimesRun", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 689.0595178434597, + "y": 499.2340890704343 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "retrievalNode" + }, + { + "data": { + "form": { + "delay_after_error": 1, + "description": "", + "exception_comment": "", + "exception_default_value": "", + "exception_goto": [], + "exception_method": null, + "frequencyPenaltyEnabled": false, + "frequency_penalty": 0.7, + "llm_id": "deepseek-chat@DeepSeek", + "maxTokensEnabled": false, + "max_retries": 3, + "max_rounds": 1, + "max_tokens": 256, + "mcp": [], + "message_history_window_size": 12, + "outputs": { + "content": { + "type": "string", + "value": "" + } + }, + "presencePenaltyEnabled": false, + "presence_penalty": 0.4, + "prompts": [ + { + "content": "User's query:\n{sys.query}\n\nRefined question:\n{Agent:ThreePathsDecide@content}\n\nWeb search result:\n{Agent:WildGoatsRule@content}\n\nRetrieval result:\n{Agent:WildGoatsRule@content}", + "role": "user" + } + ], + "sys_prompt": "Role: You are an Answer Organizer.\nTask: Generate the answer based on the provided content from: User's query, Refined question, Web search result, Retrieval result.\n\nRequirements:\n - Answer should be in markdown format.\n - Answer should include all \n - Do not make thing up when there's no relevant information to user's question. \n", + "temperature": 0.1, + "temperatureEnabled": true, + "tools": [], + "topPEnabled": false, + "top_p": 0.3, + "user_prompt": "", + "visual_files_var": "" + }, + "label": "Agent", + "name": "Answer Organizer" + }, + "dragging": false, + "id": "Agent:SmartSchoolsCross", + "measured": { + "height": 84, + "width": 200 + }, + "position": { + "x": 1134.5321493898284, + "y": 221.46972754101765 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "agentNode" + }, + { + "data": { + "form": { + "content": [ + "{Agent:SmartSchoolsCross@content}" + ] + }, + "label": "Message", + "name": "Answer" + }, + "dragging": false, + "id": "Message:ShaggyRingsCrash", + "measured": { + "height": 56, + "width": 200 + }, + "position": { + "x": 1437.758553651028, + "y": 235.45081267288185 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "messageNode" + }, + { + "data": { + "form": { + "text": "This Agent rewrites your question for better search & retrieval results." + }, + "label": "Note", + "name": "Note: Refine Question" + }, + "dragHandle": ".note-drag-handle", + "id": "Note:BetterCupsBow", + "measured": { + "height": 136, + "width": 244 + }, + "position": { + "x": 270, + "y": 390 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "This Agent answers questions using web search results." + }, + "label": "Note", + "name": "Note: Search Agent" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "id": "Note:OddGoatsBeg", + "measured": { + "height": 136, + "width": 244 + }, + "position": { + "x": 689.3401860180043, + "y": -204.46057070562227 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode" + }, + { + "data": { + "form": { + "text": "This Agents generates the answer based on the provided content from: User's query, Refined question, Web search result, Retrieval result." + }, + "label": "Note", + "name": "Note: Answer Organizer" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 188, + "id": "Note:SlowBottlesHope", + "measured": { + "height": 188, + "width": 251 + }, + "position": { + "x": 1152.1929528629184, + "y": 375.08305219772546 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 251 + }, + { + "data": { + "form": { + "description": "This is an agent for a specific task.", + "user_prompt": "This is the order you need to send to the agent." + }, + "label": "Tool", + "name": "flow.tool_0" + }, + "dragging": false, + "id": "Tool:TrueCrewsTake", + "measured": { + "height": 228, + "width": 200 + }, + "position": { + "x": 642.9703031510875, + "y": 144.80253344921545 + }, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "toolNode" + }, + { + "data": { + "form": { + "text": "This is a chat assistant template that integrates information extracted from a knowledge base and web searches to respond to queries. Let's start by setting up your knowledge base in 'Retrieval'!" + }, + "label": "Note", + "name": "Workflow Overall Description" + }, + "dragHandle": ".note-drag-handle", + "dragging": false, + "height": 163, + "id": "Note:BumpySteaksPump", + "measured": { + "height": 163, + "width": 389 + }, + "position": { + "x": -36.59148337976953, + "y": 1.488564577528809 + }, + "resizing": false, + "selected": false, + "sourcePosition": "right", + "targetPosition": "left", + "type": "noteNode", + "width": 389 + } + ] + }, + "history": [ + [ + "user", + "你好" + ] + ], + "memory": [], + "messages": [], + "path": [ + "begin", + "Agent:ThreePathsDecide" + ], + "retrieval": [ + { + "chunks": [], + "doc_aggs": [] + }, + { + "chunks": {}, + "doc_aggs": {} + } + ], + "task_id": "183442fc6dd811f091b1047c16ec874f" + }, + "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABN3SURBVHgBrVlrkBzVdf5ud8/s7My+tdKu9iFp9dYipNUDgQwSTwECC9kYV4HBECeuSnA5BhMIVCgHEWMT25BAUnYqiSEQp0iCQ2ESngYiYkACgcRKCPRC0koIvVZa7XtmZ7r75jv3ds/MChL8ww2reXXfPvec73znO6cVTjt+uUdfEOpwrdLqS1CYprXG7/5wIMsqBfyWy3fTlm6dxL3Xdaie8h9U/Obp/bouX8A90OGtn7+ew78weuW/SqzRCMPPu8Ye5UbLJnxfvtBwXWe8UdERKnu36PyHKhO498sdqr94rjVer+fKXfjcQ27mmhfPC5FMKAznaLwPVKXtirmcvDqfMrZkcMhXFf2uuY5TXDoMNHxHLlfGOLle68hZ/MLjrRMeuvlyoWzCk+t8H/fwty792xgevU2mQhw7CfzHKyEOHYbxfm1G4fJzgaVnOsjmrLHxEQShNdRs3DFel98d/pMPtdm5SnCdRORu/mkTUsW7KiQrAyBP5zAcWz5AV9px7uGP31X0/rRCQe8vmvkpUJYZHh3i+b5BBz9+xEdLs4PLV2hUplz8ZpuP1zcAN39VoWsWDQucoteJX2jPrqZoiM6FYjK9zW8cB7KHdN8epLM7kHczGKhdDsWQJmh3fzbAz/4txJcvcvHkyyEGRjQuP0vh+jXehV5A3JcbLaGVv7AI6Nj4EuaT9NRLb4eoTIe47QaPYbcRuPESF0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baz8aUlWvQNX8epnC41TZxkik8vqhQHSWosjyOaORhBpVR7xBGQ6zPOkxBkl4n9CzceFHBFLYoEkVkOihPruKU0kVH9K3zEP+5BTLgSlbBaZyJ2tmL0DJ3PuZ2dKC5vQXNkyZz6pykLi+YpYJI94flN4oTTMVMEU3otFvmRxuhMJIURl7wbUGeukjx9Ivxiyp65JhYjsCIZcoV/fBPLm651Qj0rlsfXMce5/x0Kt1Vla5ETV0N5XE9amprUFNTQ+mcKE6u/RjlUZsrSViEcVHxCntIhLxiyAVOppuDnaFqGSBwE74S3k+YUh3kMb4HjsYoyups05fLT0z/7oyTX4eyuGDd+v11nKitYwG7JSXNhxs9xuECOWkLyyZlNowRDlUU4phGSwCxqcyBsXai/j5Sk/LeV+XDZ7c0jtQ2OuNXAkoPCsKHM25h3boLO/rHbSA+7t94ZFoQuOv4EGIhvdEVGx0Pl0oPHewwWJcxTfmhtR43WomfE1j4WavMkKB8/CK/qbgHKDUtfN9D7z9D9fqrB1a1v1Z+n/8FOVED2P7bkToAAAAASUVORK5CYII=" +} \ No newline at end of file diff --git a/agent/templates/websearch_assistant.json b/agent/templates/websearch_assistant.json deleted file mode 100644 index 1b6308f6978..00000000000 --- a/agent/templates/websearch_assistant.json +++ /dev/null @@ -1,996 +0,0 @@ -{ - "id": 0, - "title": "WebSearch Assistant", - "description": "A chat assistant template that integrates information extracted from a knowledge base and web searches to respond to queries. Let's begin by setting up your knowledge base in 'Retrieval'!", - "canvas_type": "chatbot", - "dsl": { - "answer": [], - "components": { - "Answer:PoorMapsCover": { - "downstream": [ - "RewriteQuestion:OrangeBottlesSwim" - ], - "obj": { - "component_name": "Answer", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "post_answers": [], - "query": [] - } - }, - "upstream": [ - "begin", - "Generate:ItchyRiversDrum" - ] - }, - "Baidu:OliveAreasCall": { - "downstream": [ - "Generate:ItchyRiversDrum" - ], - "obj": { - "component_name": "Baidu", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "KeywordExtract:BeigeTipsStand", - "type": "reference" - } - ], - "top_n": 2 - } - }, - "upstream": [ - "KeywordExtract:BeigeTipsStand" - ] - }, - "DuckDuckGo:SoftButtonsRefuse": { - "downstream": [ - "Generate:ItchyRiversDrum" - ], - "obj": { - "component_name": "DuckDuckGo", - "inputs": [], - "output": null, - "params": { - "channel": "text", - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "KeywordExtract:BeigeTipsStand", - "type": "reference" - } - ], - "top_n": 2 - } - }, - "upstream": [ - "KeywordExtract:BeigeTipsStand" - ] - }, - "Generate:ItchyRiversDrum": { - "downstream": [ - "Answer:PoorMapsCover" - ], - "obj": { - "component_name": "Generate", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "max_tokens": 0, - "message_history_window_size": 12, - "output": null, - "output_var_name": "output", - "parameters": [], - "presence_penalty": 0.4, - "prompt": "Role: You are an intelligent assistant. \nTask: Chat with user. Answer the question based on the provided content from: Knowledge Base, Wikipedia, Duckduckgo, Baidu.\nRequirements:\n - Answer should be in markdown format.\n - Answer should include all sources(Knowledge Base, Wikipedia, Duckduckgo, Baidu) as long as they are relevant, and label the sources of the cited content separately.\n - Attach URL links to the content which is quoted from Wikipedia, DuckDuckGo or Baidu.\n - Do not make thing up when there's no relevant information to user's question. \n\n## Knowledge base content\n{Retrieval:SilentCamelsStick}\n\n\n## Wikipedia content\n{Wikipedia:WittyRiceLearn}\n\n\n## Duckduckgo content\n{DuckDuckGo:SoftButtonsRefuse}\n\n\n## Baidu content\n{Baidu:OliveAreasCall}\n\n", - "query": [], - "temperature": 0.1, - "top_p": 0.3 - } - }, - "upstream": [ - "Retrieval:SilentCamelsStick", - "Wikipedia:WittyRiceLearn", - "Baidu:OliveAreasCall", - "DuckDuckGo:SoftButtonsRefuse" - ] - }, - "KeywordExtract:BeigeTipsStand": { - "downstream": [ - "Baidu:OliveAreasCall", - "DuckDuckGo:SoftButtonsRefuse", - "Wikipedia:WittyRiceLearn" - ], - "obj": { - "component_name": "KeywordExtract", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "", - "query": [], - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_n": 2, - "top_p": 0.3 - } - }, - "upstream": [ - "RewriteQuestion:OrangeBottlesSwim" - ] - }, - "Retrieval:SilentCamelsStick": { - "downstream": [ - "Generate:ItchyRiversDrum" - ], - "obj": { - "component_name": "Retrieval", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "empty_response": "The answer you want was not found in the knowledge base!", - "inputs": [], - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [], - "rerank_id": "", - "similarity_threshold": 0.2, - "top_k": 1024, - "top_n": 8 - } - }, - "upstream": [ - "RewriteQuestion:OrangeBottlesSwim" - ] - }, - "RewriteQuestion:OrangeBottlesSwim": { - "downstream": [ - "KeywordExtract:BeigeTipsStand", - "Retrieval:SilentCamelsStick" - ], - "obj": { - "component_name": "RewriteQuestion", - "inputs": [], - "output": null, - "params": { - "cite": true, - "debug_inputs": [], - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "inputs": [], - "llm_id": "deepseek-chat@DeepSeek", - "loop": 1, - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 6, - "output": null, - "output_var_name": "output", - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "", - "query": [], - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - } - }, - "upstream": [ - "Answer:PoorMapsCover" - ] - }, - "Wikipedia:WittyRiceLearn": { - "downstream": [ - "Generate:ItchyRiversDrum" - ], - "obj": { - "component_name": "Wikipedia", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "language": "en", - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "query": [ - { - "component_id": "KeywordExtract:BeigeTipsStand", - "type": "reference" - } - ], - "top_n": 2 - } - }, - "upstream": [ - "KeywordExtract:BeigeTipsStand" - ] - }, - "begin": { - "downstream": [ - "Answer:PoorMapsCover" - ], - "obj": { - "component_name": "Begin", - "inputs": [], - "output": null, - "params": { - "debug_inputs": [], - "inputs": [], - "message_history_window_size": 22, - "output": null, - "output_var_name": "output", - "prologue": "Hi! I'm your smart assistant. What can I do for you?", - "query": [] - } - }, - "upstream": [] - } - }, - "embed_id": "", - "graph": { - "edges": [ - { - "id": "reactflow__edge-begin-Answer:PoorMapsCoverc", - "markerEnd": "logo", - "source": "begin", - "sourceHandle": null, - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:PoorMapsCover", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-Answer:PoorMapsCoverb-RewriteQuestion:OrangeBottlesSwimc", - "markerEnd": "logo", - "source": "Answer:PoorMapsCover", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "RewriteQuestion:OrangeBottlesSwim", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-RewriteQuestion:OrangeBottlesSwimb-KeywordExtract:BeigeTipsStandc", - "markerEnd": "logo", - "source": "RewriteQuestion:OrangeBottlesSwim", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "KeywordExtract:BeigeTipsStand", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-KeywordExtract:BeigeTipsStandb-Baidu:OliveAreasCallc", - "markerEnd": "logo", - "source": "KeywordExtract:BeigeTipsStand", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Baidu:OliveAreasCall", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-KeywordExtract:BeigeTipsStandb-DuckDuckGo:SoftButtonsRefusec", - "markerEnd": "logo", - "source": "KeywordExtract:BeigeTipsStand", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "DuckDuckGo:SoftButtonsRefuse", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-KeywordExtract:BeigeTipsStandb-Wikipedia:WittyRiceLearnc", - "markerEnd": "logo", - "source": "KeywordExtract:BeigeTipsStand", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Wikipedia:WittyRiceLearn", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "reactflow__edge-RewriteQuestion:OrangeBottlesSwimb-Retrieval:SilentCamelsStickc", - "markerEnd": "logo", - "source": "RewriteQuestion:OrangeBottlesSwim", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Retrieval:SilentCamelsStick", - "targetHandle": "c", - "type": "buttonEdge" - }, - { - "id": "xy-edge__Generate:ItchyRiversDrumc-Answer:PoorMapsCoverc", - "markerEnd": "logo", - "source": "Generate:ItchyRiversDrum", - "sourceHandle": "c", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Answer:PoorMapsCover", - "targetHandle": "c", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Retrieval:SilentCamelsStickb-Generate:ItchyRiversDrumb", - "markerEnd": "logo", - "source": "Retrieval:SilentCamelsStick", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:ItchyRiversDrum", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Wikipedia:WittyRiceLearnb-Generate:ItchyRiversDrumb", - "markerEnd": "logo", - "source": "Wikipedia:WittyRiceLearn", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:ItchyRiversDrum", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__Baidu:OliveAreasCallb-Generate:ItchyRiversDrumb", - "markerEnd": "logo", - "source": "Baidu:OliveAreasCall", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:ItchyRiversDrum", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - }, - { - "id": "xy-edge__DuckDuckGo:SoftButtonsRefuseb-Generate:ItchyRiversDrumb", - "markerEnd": "logo", - "source": "DuckDuckGo:SoftButtonsRefuse", - "sourceHandle": "b", - "style": { - "stroke": "rgb(202 197 245)", - "strokeWidth": 2 - }, - "target": "Generate:ItchyRiversDrum", - "targetHandle": "b", - "type": "buttonEdge", - "zIndex": 1001 - } - ], - "nodes": [ - { - "data": { - "label": "Begin", - "name": "opening" - }, - "dragging": false, - "height": 44, - "id": "begin", - "measured": { - "height": 44, - "width": 100 - }, - "position": { - "x": -1469.1118402678153, - "y": -138.55389910599428 - }, - "positionAbsolute": { - "x": -1379.627471412851, - "y": -135.63593055637585 - }, - "selected": false, - "sourcePosition": "left", - "targetPosition": "right", - "type": "beginNode" - }, - { - "data": { - "form": {}, - "label": "Answer", - "name": "interface" - }, - "dragging": false, - "height": 44, - "id": "Answer:PoorMapsCover", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -1172.8677760724227, - "y": -134.7856818291531 - }, - "positionAbsolute": { - "x": -1172.8677760724227, - "y": -134.7856818291531 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "logicNode", - "width": 200 - }, - { - "data": { - "form": { - "language": "en", - "query": [ - { - "component_id": "KeywordExtract:BeigeTipsStand", - "type": "reference" - } - ], - "top_n": 2 - }, - "label": "Wikipedia", - "name": "Wikipedia" - }, - "dragging": false, - "height": 44, - "id": "Wikipedia:WittyRiceLearn", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -406.9217458441634, - "y": -54.01023495053805 - }, - "positionAbsolute": { - "x": -406.9217458441634, - "y": -54.01023495053805 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "query": [ - { - "component_id": "KeywordExtract:BeigeTipsStand", - "type": "reference" - } - ], - "top_n": 2 - }, - "label": "Baidu", - "name": "Baidu" - }, - "dragging": false, - "height": 44, - "id": "Baidu:OliveAreasCall", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -334.8102520664264, - "y": -142.4206828864257 - }, - "positionAbsolute": { - "x": -334.8102520664264, - "y": -142.4206828864257 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "channel": "text", - "query": [ - { - "component_id": "KeywordExtract:BeigeTipsStand", - "type": "reference" - } - ], - "top_n": 2 - }, - "label": "DuckDuckGo", - "name": "DuckDuckGo" - }, - "dragging": false, - "height": 44, - "id": "DuckDuckGo:SoftButtonsRefuse", - "measured": { - "height": 44, - "width": 200 - }, - "position": { - "x": -241.42135935727495, - "y": -227.69429585279033 - }, - "positionAbsolute": { - "x": -241.42135935727495, - "y": -227.69429585279033 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "ragNode", - "width": 200 - }, - { - "data": { - "form": { - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "loop": 1, - "maxTokensEnabled": true, - "max_tokens": 256, - "message_history_window_size": 6, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "RewriteQuestion", - "name": "Refine Question" - }, - "dragging": false, - "height": 86, - "id": "RewriteQuestion:OrangeBottlesSwim", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": -926.3250837910092, - "y": -156.41315582042822 - }, - "positionAbsolute": { - "x": -926.3250837910092, - "y": -156.41315582042822 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "rewriteNode", - "width": 200 - }, - { - "data": { - "form": { - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": true, - "max_tokens": 256, - "parameter": "Precise", - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_n": 2, - "top_p": 0.3 - }, - "label": "KeywordExtract", - "name": "Get keywords" - }, - "dragging": false, - "height": 86, - "id": "KeywordExtract:BeigeTipsStand", - "measured": { - "height": 86, - "width": 200 - }, - "position": { - "x": -643.95039088561, - "y": -160.37167955274685 - }, - "positionAbsolute": { - "x": -643.95039088561, - "y": -160.37167955274685 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "keywordNode", - "width": 200 - }, - { - "data": { - "form": { - "empty_response": "The answer you want was not found in the knowledge base!", - "kb_ids": [], - "keywords_similarity_weight": 0.3, - "similarity_threshold": 0.2, - "top_n": 8 - }, - "label": "Retrieval", - "name": "Search KB" - }, - "dragging": false, - "height": 46, - "id": "Retrieval:SilentCamelsStick", - "measured": { - "height": 46, - "width": 200 - }, - "position": { - "x": -641.3113750640641, - "y": -4.669746081545384 - }, - "positionAbsolute": { - "x": -641.3113750640641, - "y": -4.669746081545384 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "retrievalNode", - "width": 200 - }, - { - "data": { - "form": { - "text": "The large model answers the user's query based on the content retrieved from different search engines and knowledge bases, returning an answer to the user's question." - }, - "label": "Note", - "name": "N: LLM" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 144, - "id": "Note:CuteSchoolsWear", - "measured": { - "height": 144, - "width": 443 - }, - "position": { - "x": -628.5256394373041, - "y": 412.60472782016245 - }, - "positionAbsolute": { - "x": -628.5256394373041, - "y": 412.60472782016245 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 144, - "width": 443 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 443 - }, - { - "data": { - "form": { - "text": "Complete questions by conversation history.\nUser: What's RAGFlow?\nAssistant: RAGFlow is xxx.\nUser: How to deloy it?\n\nRefine it: How to deploy RAGFlow?" - }, - "label": "Note", - "name": "N: Refine question" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 209, - "id": "Note:CuteRavensBehave", - "measured": { - "height": 209, - "width": 266 - }, - "position": { - "x": -921.2271023677847, - "y": -381.3182401779728 - }, - "positionAbsolute": { - "x": -921.2271023677847, - "y": -381.3182401779728 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 209, - "width": 266 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 266 - }, - { - "data": { - "form": { - "text": "Based on the user's question, searches the knowledge base and returns the retrieved content." - }, - "label": "Note", - "name": "N: Search KB" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:RudeRulesLeave", - "measured": { - "height": 128, - "width": 269 - }, - "position": { - "x": -917.896611693436, - "y": -3.570404025438563 - }, - "positionAbsolute": { - "x": -917.896611693436, - "y": -3.570404025438563 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 269 - }, - { - "data": { - "form": { - "text": "Based on the keywords, searches on Wikipedia and returns the found content." - }, - "label": "Note", - "name": "N: Wikipedia" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:DryActorsTry", - "measured": { - "height": 128, - "width": 281 - }, - "position": { - "x": 49.68127281474659, - "y": -16.899164744846445 - }, - "positionAbsolute": { - "x": 49.68127281474659, - "y": -16.899164744846445 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 128, - "width": 281 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 281 - }, - { - "data": { - "form": { - "text": "Based on the keywords, searches on Baidu and returns the found content." - }, - "label": "Note", - "name": "N :Baidu" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 128, - "id": "Note:HonestShirtsNail", - "measured": { - "height": 128, - "width": 269 - }, - "position": { - "x": 43.964372149616565, - "y": -151.26282396084338 - }, - "positionAbsolute": { - "x": 43.964372149616565, - "y": -151.26282396084338 - }, - "selected": false, - "sourcePosition": "right", - "targetPosition": "left", - "type": "noteNode", - "width": 269 - }, - { - "data": { - "form": { - "text": "Based on the keywords, searches on DuckDuckGo and returns the found content." - }, - "label": "Note", - "name": "N: DuckduckGo" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 145, - "id": "Note:OddBreadsFix", - "measured": { - "height": 145, - "width": 201 - }, - "position": { - "x": -237.54626926201882, - "y": -381.56637252684175 - }, - "positionAbsolute": { - "x": -237.54626926201882, - "y": -381.56637252684175 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 145, - "width": 201 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 201 - }, - { - "data": { - "form": { - "text": "The large model generates keywords based on the user's question for better retrieval." - }, - "label": "Note", - "name": "N: Get keywords" - }, - "dragHandle": ".note-drag-handle", - "dragging": false, - "height": 162, - "id": "Note:GentleWorldsDesign", - "measured": { - "height": 162, - "width": 201 - }, - "position": { - "x": -646.3211655055846, - "y": -334.10598887579624 - }, - "positionAbsolute": { - "x": -646.3211655055846, - "y": -334.10598887579624 - }, - "resizing": false, - "selected": false, - "sourcePosition": "right", - "style": { - "height": 162, - "width": 201 - }, - "targetPosition": "left", - "type": "noteNode", - "width": 201 - }, - { - "data": { - "form": { - "cite": true, - "frequencyPenaltyEnabled": true, - "frequency_penalty": 0.7, - "llm_id": "deepseek-chat@DeepSeek", - "maxTokensEnabled": false, - "max_tokens": 256, - "message_history_window_size": 12, - "parameter": "Precise", - "parameters": [], - "presencePenaltyEnabled": true, - "presence_penalty": 0.4, - "prompt": "Role: You are an intelligent assistant. \nTask: Chat with user. Answer the question based on the provided content from: Knowledge Base, Wikipedia, Duckduckgo, Baidu.\nRequirements:\n - Answer should be in markdown format.\n - Answer should include all sources(Knowledge Base, Wikipedia, Duckduckgo, Baidu) as long as they are relevant, and label the sources of the cited content separately.\n - Attach URL links to the content which is quoted from Wikipedia, DuckDuckGo or Baidu.\n - Do not make thing up when there's no relevant information to user's question. \n\n## Knowledge base content\n{Retrieval:SilentCamelsStick}\n\n\n## Wikipedia content\n{Wikipedia:WittyRiceLearn}\n\n\n## Duckduckgo content\n{DuckDuckGo:SoftButtonsRefuse}\n\n\n## Baidu content\n{Baidu:OliveAreasCall}\n\n", - "temperature": 0.1, - "temperatureEnabled": true, - "topPEnabled": true, - "top_p": 0.3 - }, - "label": "Generate", - "name": "LLM" - }, - "dragging": false, - "id": "Generate:ItchyRiversDrum", - "measured": { - "height": 108, - "width": 200 - }, - "position": { - "x": -636.2454246475879, - "y": 282.00479262604443 - }, - "selected": true, - "sourcePosition": "right", - "targetPosition": "left", - "type": "generateNode" - } - ] - }, - "history": [], - "messages": [], - "path": [], - "reference": [] - }, - "avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYEAAAGDCAYAAADNkawvAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAGlsSURBVHhe7Z1nmBTV9vVflaBgIqgYMJElM+Scc5acc845JwkKiA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jlRXTcAFqitHdeWorhzVlSPVVRNwgerKUV05qitHdeVIddUEXKC6clRXjurKUV05Ul01AReorhzVlaO6clRXjlRXTcAFqitHdeWorhzVlSPVNSagKIqixCf/j3MQRVEUJR74P/r/T/I0iJMTx7EAAAAASUVORK5CYII=" -} diff --git a/agent/test/client.py b/agent/test/client.py index 1ab4db386ee..26a02b957ec 100644 --- a/agent/test/client.py +++ b/agent/test/client.py @@ -15,9 +15,8 @@ # import argparse import os -from functools import partial from agent.canvas import Canvas -from agent.settings import DEBUG +from common import settings if __name__ == '__main__': parser = argparse.ArgumentParser() @@ -31,19 +30,17 @@ parser.add_argument('-m', '--stream', default=False, help="Stream output", action='store_true', required=False) args = parser.parse_args() + settings.init_settings() canvas = Canvas(open(args.dsl, "r").read(), args.tenant_id) + if canvas.get_prologue(): + print(f"==================== Bot =====================\n> {canvas.get_prologue()}", end='') + query = "" while True: - ans = canvas.run(stream=args.stream) + canvas.reset(True) + query = input("\n==================== User =====================\n> ") + ans = canvas.run(query=query) print("==================== Bot =====================\n> ", end='') - if args.stream and isinstance(ans, partial): - cont = "" - for an in ans(): - print(an["content"][len(cont):], end='', flush=True) - cont = an["content"] - else: - print(ans["content"]) + for ans in canvas.run(query=query): + print(ans, end='\n', flush=True) - if DEBUG: - print(canvas.path) - question = input("\n==================== User =====================\n> ") - canvas.add_user_input(question) + print(canvas.path) diff --git a/agent/test/dsl_examples/baidu_generate_and_switch.json b/agent/test/dsl_examples/baidu_generate_and_switch.json deleted file mode 100644 index 90069cfafc0..00000000000 --- a/agent/test/dsl_examples/baidu_generate_and_switch.json +++ /dev/null @@ -1,129 +0,0 @@ -{ - "components": { - "begin": { - "obj":{ - "component_name": "Begin", - "params": { - "prologue": "Hi there!" - } - }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, - "downstream": ["baidu:0"], - "upstream": ["begin", "message:0","message:1"] - }, - "baidu:0": { - "obj": { - "component_name": "Baidu", - "params": {} - }, - "downstream": ["generate:0"], - "upstream": ["answer:0"] - }, - "generate:0": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are an intelligent assistant. Please answer the user's question based on what Baidu searched. First, please output the user's question and the content searched by Baidu, and then answer yes, no, or i don't know.Here is the user's question:{user_input}The above is the user's question.Here is what Baidu searched for:{baidu}The above is the content searched by Baidu.", - "temperature": 0.2 - }, - "parameters": [ - { - "component_id": "answer:0", - "id": "69415446-49bf-4d4b-8ec9-ac86066f7709", - "key": "user_input" - }, - { - "component_id": "baidu:0", - "id": "83363c2a-00a8-402f-a45c-ddc4097d7d8b", - "key": "baidu" - } - ] - }, - "downstream": ["switch:0"], - "upstream": ["baidu:0"] - }, - "switch:0": { - "obj": { - "component_name": "Switch", - "params": { - "conditions": [ - { - "logical_operator" : "or", - "items" : [ - {"cpn_id": "generate:0", "operator": "contains", "value": "yes"}, - {"cpn_id": "generate:0", "operator": "contains", "value": "yeah"} - ], - "to": "message:0" - }, - { - "logical_operator" : "and", - "items" : [ - {"cpn_id": "generate:0", "operator": "contains", "value": "no"}, - {"cpn_id": "generate:0", "operator": "not contains", "value": "yes"}, - {"cpn_id": "generate:0", "operator": "not contains", "value": "know"} - ], - "to": "message:1" - }, - { - "logical_operator" : "", - "items" : [ - {"cpn_id": "generate:0", "operator": "contains", "value": "know"} - ], - "to": "message:2" - } - ], - "end_cpn_id": "answer:0" - - } - }, - "downstream": ["message:0","message:1"], - "upstream": ["generate:0"] - }, - "message:0": { - "obj": { - "component_name": "Message", - "params": { - "messages": ["YES YES YES YES YES YES YES YES YES YES YES YES"] - } - }, - - "upstream": ["switch:0"], - "downstream": ["answer:0"] - }, - "message:1": { - "obj": { - "component_name": "Message", - "params": { - "messages": ["NO NO NO NO NO NO NO NO NO NO NO NO NO NO"] - } - }, - - "upstream": ["switch:0"], - "downstream": ["answer:0"] - }, - "message:2": { - "obj": { - "component_name": "Message", - "params": { - "messages": ["I DON'T KNOW---------------------------"] - } - }, - - "upstream": ["switch:0"], - "downstream": ["answer:0"] - } - }, - "history": [], - "messages": [], - "reference": {}, - "path": [], - "answer": [] -} diff --git a/agent/test/dsl_examples/categorize.json b/agent/test/dsl_examples/categorize.json deleted file mode 100644 index 600c9bc3fc4..00000000000 --- a/agent/test/dsl_examples/categorize.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "components": { - "begin": { - "obj":{ - "component_name": "Begin", - "params": { - "prologue": "Hi there!" - } - }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, - "downstream": ["categorize:0"], - "upstream": ["begin"] - }, - "categorize:0": { - "obj": { - "component_name": "Categorize", - "params": { - "llm_id": "deepseek-chat", - "category_description": { - "product_related": { - "description": "The question is about the product usage, appearance and how it works.", - "examples": "Why it always beaming?\nHow to install it onto the wall?\nIt leaks, what to do?", - "to": "message:0" - }, - "others": { - "description": "The question is not about the product usage, appearance and how it works.", - "examples": "How are you doing?\nWhat is your name?\nAre you a robot?\nWhat's the weather?\nWill it rain?", - "to": "message:1" - } - } - } - }, - "downstream": ["message:0","message:1"], - "upstream": ["answer:0"] - }, - "message:0": { - "obj": { - "component_name": "Message", - "params": { - "messages": [ - "Message 0!!!!!!!" - ] - } - }, - "downstream": ["answer:0"], - "upstream": ["categorize:0"] - }, - "message:1": { - "obj": { - "component_name": "Message", - "params": { - "messages": [ - "Message 1!!!!!!!" - ] - } - }, - "downstream": ["answer:0"], - "upstream": ["categorize:0"] - } - }, - "history": [], - "messages": [], - "path": [], - "reference": [], - "answer": [] -} diff --git a/agent/test/dsl_examples/categorize_and_agent_with_tavily.json b/agent/test/dsl_examples/categorize_and_agent_with_tavily.json new file mode 100644 index 00000000000..7d956744664 --- /dev/null +++ b/agent/test/dsl_examples/categorize_and_agent_with_tavily.json @@ -0,0 +1,85 @@ +{ + "components": { + "begin": { + "obj":{ + "component_name": "Begin", + "params": { + "prologue": "Hi there!" + } + }, + "downstream": ["categorize:0"], + "upstream": [] + }, + "categorize:0": { + "obj": { + "component_name": "Categorize", + "params": { + "llm_id": "deepseek-chat", + "category_description": { + "product_related": { + "description": "The question is about the product usage, appearance and how it works.", + "to": ["agent:0"] + }, + "others": { + "description": "The question is not about the product usage, appearance and how it works.", + "to": ["message:0"] + } + } + } + }, + "downstream": [], + "upstream": ["begin"] + }, + "message:0": { + "obj":{ + "component_name": "Message", + "params": { + "content": [ + "Sorry, I don't know. I'm an AI bot." + ] + } + }, + "downstream": [], + "upstream": ["categorize:0"] + }, + "agent:0": { + "obj": { + "component_name": "Agent", + "params": { + "llm_id": "deepseek-chat", + "sys_prompt": "You are a smart researcher. You could generate proper queries to search. According to the search results, you could deside next query if the result is not enough.", + "temperature": 0.2, + "llm_enabled_tools": [ + { + "component_name": "TavilySearch", + "params": { + "api_key": "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" + } + } + ] + } + }, + "downstream": ["message:1"], + "upstream": ["categorize:0"] + }, + "message:1": { + "obj": { + "component_name": "Message", + "params": { + "content": ["{agent:0@content}"] + } + }, + "downstream": [], + "upstream": ["agent:0"] + } + }, + "history": [], + "path": [], + "retrival": {"chunks": [], "doc_aggs": []}, + "globals": { + "sys.query": "", + "sys.user_id": "", + "sys.conversation_turns": 0, + "sys.files": [] + } +} \ No newline at end of file diff --git a/agent/test/dsl_examples/concentrator_message.json b/agent/test/dsl_examples/concentrator_message.json deleted file mode 100644 index ee875ae02b9..00000000000 --- a/agent/test/dsl_examples/concentrator_message.json +++ /dev/null @@ -1,113 +0,0 @@ -{ - "components": { - "begin": { - "obj":{ - "component_name": "Begin", - "params": { - "prologue": "Hi there!" - } - }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, - "downstream": ["categorize:0"], - "upstream": ["begin"] - }, - "categorize:0": { - "obj": { - "component_name": "Categorize", - "params": { - "llm_id": "deepseek-chat", - "category_description": { - "product_related": { - "description": "The question is about the product usage, appearance and how it works.", - "examples": "Why it always beaming?\nHow to install it onto the wall?\nIt leaks, what to do?", - "to": "concentrator:0" - }, - "others": { - "description": "The question is not about the product usage, appearance and how it works.", - "examples": "How are you doing?\nWhat is your name?\nAre you a robot?\nWhat's the weather?\nWill it rain?", - "to": "concentrator:1" - } - } - } - }, - "downstream": ["concentrator:0","concentrator:1"], - "upstream": ["answer:0"] - }, - "concentrator:0": { - "obj": { - "component_name": "Concentrator", - "params": {} - }, - "downstream": ["message:0"], - "upstream": ["categorize:0"] - }, - "concentrator:1": { - "obj": { - "component_name": "Concentrator", - "params": {} - }, - "downstream": ["message:1_0","message:1_1","message:1_2"], - "upstream": ["categorize:0"] - }, - "message:0": { - "obj": { - "component_name": "Message", - "params": { - "messages": [ - "Message 0_0!!!!!!!" - ] - } - }, - "downstream": ["answer:0"], - "upstream": ["concentrator:0"] - }, - "message:1_0": { - "obj": { - "component_name": "Message", - "params": { - "messages": [ - "Message 1_0!!!!!!!" - ] - } - }, - "downstream": ["answer:0"], - "upstream": ["concentrator:1"] - }, - "message:1_1": { - "obj": { - "component_name": "Message", - "params": { - "messages": [ - "Message 1_1!!!!!!!" - ] - } - }, - "downstream": ["answer:0"], - "upstream": ["concentrator:1"] - }, - "message:1_2": { - "obj": { - "component_name": "Message", - "params": { - "messages": [ - "Message 1_2!!!!!!!" - ] - } - }, - "downstream": ["answer:0"], - "upstream": ["concentrator:1"] - } - }, - "history": [], - "messages": [], - "path": [], - "reference": [], - "answer": [] -} \ No newline at end of file diff --git a/agent/test/dsl_examples/customer_service.json b/agent/test/dsl_examples/customer_service.json deleted file mode 100644 index 8421e3a26d2..00000000000 --- a/agent/test/dsl_examples/customer_service.json +++ /dev/null @@ -1,157 +0,0 @@ -{ - "components": { - "begin": { - "obj":{ - "component_name": "Begin", - "params": { - "prologue": "Hi! How can I help you?" - } - }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, - "downstream": ["categorize:0"], - "upstream": ["begin", "generate:0", "generate:casual", "generate:answer", "generate:complain", "generate:ask_contact", "message:get_contact"] - }, - "categorize:0": { - "obj": { - "component_name": "Categorize", - "params": { - "llm_id": "deepseek-chat", - "category_description": { - "product_related": { - "description": "The question is about the product usage, appearance and how it works.", - "examples": "Why it always beaming?\nHow to install it onto the wall?\nIt leaks, what to do?\nException: Can't connect to ES cluster\nHow to build the RAGFlow image from scratch", - "to": "retrieval:0" - }, - "casual": { - "description": "The question is not about the product usage, appearance and how it works. Just casual chat.", - "examples": "How are you doing?\nWhat is your name?\nAre you a robot?\nWhat's the weather?\nWill it rain?", - "to": "generate:casual" - }, - "complain": { - "description": "Complain even curse about the product or service you provide. But the comment is not specific enough.", - "examples": "How bad is it.\nIt's really sucks.\nDamn, for God's sake, can it be more steady?\nShit, I just can't use this shit.\nI can't stand it anymore.", - "to": "generate:complain" - }, - "answer": { - "description": "This answer provide a specific contact information, like e-mail, phone number, wechat number, line number, twitter, discord, etc,.", - "examples": "My phone number is 203921\nkevinhu.hk@gmail.com\nThis is my discord number: johndowson_29384", - "to": "message:get_contact" - } - }, - "message_history_window_size": 8 - } - }, - "downstream": ["retrieval:0", "generate:casual", "generate:complain", "message:get_contact"], - "upstream": ["answer:0"] - }, - "generate:casual": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are a customer support. But the customer wants to have a casual chat with you instead of consulting about the product. Be nice, funny, enthusiasm and concern.", - "temperature": 0.9, - "message_history_window_size": 12, - "cite": false - } - }, - "downstream": ["answer:0"], - "upstream": ["categorize:0"] - }, - "generate:complain": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are a customer support. the Customers complain even curse about the products but not specific enough. You need to ask him/her what's the specific problem with the product. Be nice, patient and concern to soothe your customers’ emotions at first place.", - "temperature": 0.9, - "message_history_window_size": 12, - "cite": false - } - }, - "downstream": ["answer:0"], - "upstream": ["categorize:0"] - }, - "retrieval:0": { - "obj": { - "component_name": "Retrieval", - "params": { - "similarity_threshold": 0.2, - "keywords_similarity_weight": 0.3, - "top_n": 6, - "top_k": 1024, - "rerank_id": "BAAI/bge-reranker-v2-m3", - "kb_ids": ["869a236818b811ef91dffa163e197198"] - } - }, - "downstream": ["relevant:0"], - "upstream": ["categorize:0"] - }, - "relevant:0": { - "obj": { - "component_name": "Relevant", - "params": { - "llm_id": "deepseek-chat", - "temperature": 0.02, - "yes": "generate:answer", - "no": "generate:ask_contact" - } - }, - "downstream": ["generate:answer", "generate:ask_contact"], - "upstream": ["retrieval:0"] - }, - "generate:answer": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are an intelligent assistant. Please answer the question based on content of knowledge base. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\". Answers need to consider chat history.\n Knowledge base content is as following:\n {input}\n The above is the content of knowledge base.", - "temperature": 0.02 - } - }, - "downstream": ["answer:0"], - "upstream": ["relevant:0"] - }, - "generate:ask_contact": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are a customer support. But you can't answer to customers' question. You need to request their contact like E-mail, phone number, Wechat number, LINE number, twitter, discord, etc,. Product experts will contact them later. Please do not ask the same question twice.", - "temperature": 0.9, - "message_history_window_size": 12, - "cite": false - } - }, - "downstream": ["answer:0"], - "upstream": ["relevant:0"] - }, - "message:get_contact": { - "obj":{ - "component_name": "Message", - "params": { - "messages": [ - "Okay, I've already write this down. What else I can do for you?", - "Get it. What else I can do for you?", - "Thanks for your trust! Our expert will contact ASAP. So, anything else I can do for you?", - "Thanks! So, anything else I can do for you?" - ] - } - }, - "downstream": ["answer:0"], - "upstream": ["categorize:0"] - } - }, - "history": [], - "messages": [], - "path": [], - "reference": [], - "answer": [] -} \ No newline at end of file diff --git a/agent/test/dsl_examples/intergreper.json b/agent/test/dsl_examples/intergreper.json deleted file mode 100644 index e528b275618..00000000000 --- a/agent/test/dsl_examples/intergreper.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "components": { - "begin": { - "obj":{ - "component_name": "Begin", - "params": { - "prologue": "Hi there! Please enter the text you want to translate in format like: 'text you want to translate' => target language. For an example: 您好! => English" - } - }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, - "downstream": ["generate:0"], - "upstream": ["begin", "generate:0"] - }, - "generate:0": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are an professional interpreter.\n- Role: an professional interpreter.\n- Input format: content need to be translated => target language. \n- Answer format: => translated content in target language. \n- Examples:\n - user: 您好! => English. assistant: => How are you doing!\n - user: You look good today. => Japanese. assistant: => 今日は調子がいいですね 。\n", - "temperature": 0.5 - } - }, - "downstream": ["answer:0"], - "upstream": ["answer:0"] - } - }, - "history": [], - "messages": [], - "reference": {}, - "path": [], - "answer": [] -} \ No newline at end of file diff --git a/agent/test/dsl_examples/interpreter.json b/agent/test/dsl_examples/interpreter.json deleted file mode 100644 index e528b275618..00000000000 --- a/agent/test/dsl_examples/interpreter.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "components": { - "begin": { - "obj":{ - "component_name": "Begin", - "params": { - "prologue": "Hi there! Please enter the text you want to translate in format like: 'text you want to translate' => target language. For an example: 您好! => English" - } - }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, - "downstream": ["generate:0"], - "upstream": ["begin", "generate:0"] - }, - "generate:0": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are an professional interpreter.\n- Role: an professional interpreter.\n- Input format: content need to be translated => target language. \n- Answer format: => translated content in target language. \n- Examples:\n - user: 您好! => English. assistant: => How are you doing!\n - user: You look good today. => Japanese. assistant: => 今日は調子がいいですね 。\n", - "temperature": 0.5 - } - }, - "downstream": ["answer:0"], - "upstream": ["answer:0"] - } - }, - "history": [], - "messages": [], - "reference": {}, - "path": [], - "answer": [] -} \ No newline at end of file diff --git a/agent/test/dsl_examples/iteration.json b/agent/test/dsl_examples/iteration.json new file mode 100644 index 00000000000..dd44484239a --- /dev/null +++ b/agent/test/dsl_examples/iteration.json @@ -0,0 +1,92 @@ +{ + "components": { + "begin": { + "obj":{ + "component_name": "Begin", + "params": { + "prologue": "Hi there!" + } + }, + "downstream": ["generate:0"], + "upstream": [] + }, + "generate:0": { + "obj": { + "component_name": "Agent", + "params": { + "llm_id": "deepseek-chat", + "sys_prompt": "You are an helpful research assistant. \nPlease decompose user's topic: '{sys.query}' into several meaningful sub-topics. \nThe output format MUST be an string array like: [\"sub-topic1\", \"sub-topic2\", ...]. Redundant information is forbidden.", + "temperature": 0.2, + "cite":false, + "output_structure": ["sub-topic1", "sub-topic2", "sub-topic3"] + } + }, + "downstream": ["iteration:0"], + "upstream": ["begin"] + }, + "iteration:0": { + "obj": { + "component_name": "Iteration", + "params": { + "items_ref": "generate:0@structured_content" + } + }, + "downstream": ["message:0"], + "upstream": ["generate:0"] + }, + "iterationitem:0": { + "obj": { + "component_name": "IterationItem", + "params": {} + }, + "parent_id": "iteration:0", + "downstream": ["tavily:0"], + "upstream": [] + }, + "tavily:0": { + "obj": { + "component_name": "TavilySearch", + "params": { + "api_key": "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", + "query": "iterationitem:0@result" + } + }, + "parent_id": "iteration:0", + "downstream": ["generate:1"], + "upstream": ["iterationitem:0"] + }, + "generate:1": { + "obj": { + "component_name": "Agent", + "params": { + "llm_id": "deepseek-chat", + "sys_prompt": "Your goal is to provide answers based on information from the internet. \nYou must use the provided search results to find relevant online information. \nYou should never use your own knowledge to answer questions.\nPlease include relevant url sources in the end of your answers.\n\n \"{tavily:0@formalized_content}\" \nUsing the above information, answer the following question or topic: \"{iterationitem:0@result} \"\nin a detailed report — The report should focus on the answer to the question, should be well structured, informative, in depth, with facts and numbers if available, a minimum of 200 words and with markdown syntax and apa format. Write all source urls at the end of the report in apa format. You should write your report only based on the given information and nothing else.", + "temperature": 0.9, + "cite":false + } + }, + "parent_id": "iteration:0", + "downstream": ["iterationitem:0"], + "upstream": ["tavily:0"] + }, + "message:0": { + "obj": { + "component_name": "Message", + "params": { + "content": ["{iteration:0@generate:1}"] + } + }, + "downstream": [], + "upstream": ["iteration:0"] + } + }, + "history": [], + "path": [], + "retrival": {"chunks": [], "doc_aggs": []}, + "globals": { + "sys.query": "", + "sys.user_id": "", + "sys.conversation_turns": 0, + "sys.files": [] + } +} \ No newline at end of file diff --git a/agent/test/dsl_examples/keyword_wikipedia_and_generate.json b/agent/test/dsl_examples/keyword_wikipedia_and_generate.json deleted file mode 100644 index fa1d62194f1..00000000000 --- a/agent/test/dsl_examples/keyword_wikipedia_and_generate.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "components": { - "begin": { - "obj":{ - "component_name": "Begin", - "params": { - "prologue": "Hi there!" - } - }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, - "downstream": ["keyword:0"], - "upstream": ["begin"] - }, - "keyword:0": { - "obj": { - "component_name": "KeywordExtract", - "params": { - "llm_id": "deepseek-chat", - "prompt": "- Role: You're a question analyzer.\n - Requirements:\n - Summarize user's question, and give top %s important keyword/phrase.\n - Use comma as a delimiter to separate keywords/phrases.\n - Answer format: (in language of user's question)\n - keyword: ", - "temperature": 0.2, - "top_n": 1 - } - }, - "downstream": ["wikipedia:0"], - "upstream": ["answer:0"] - }, - "wikipedia:0": { - "obj":{ - "component_name": "Wikipedia", - "params": { - "top_n": 10 - } - }, - "downstream": ["generate:0"], - "upstream": ["keyword:0"] - }, - "generate:1": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are an intelligent assistant. Please answer the question based on content from Wikipedia. When the answer from Wikipedia is incomplete, you need to output the URL link of the corresponding content as well. When all the content searched from Wikipedia is irrelevant to the question, your answer must include the sentence, \"The answer you are looking for is not found in the Wikipedia!\". Answers need to consider chat history.\n The content of Wikipedia is as follows:\n {input}\n The above is the content of Wikipedia.", - "temperature": 0.2 - } - }, - "downstream": ["answer:0"], - "upstream": ["wikipedia:0"] - } - }, - "history": [], - "path": [], - "messages": [], - "reference": {}, - "answer": [] -} diff --git a/agent/test/dsl_examples/retrieval_and_generate.json b/agent/test/dsl_examples/retrieval_and_generate.json index fbbf076aa7b..9f9f9bac4f4 100644 --- a/agent/test/dsl_examples/retrieval_and_generate.json +++ b/agent/test/dsl_examples/retrieval_and_generate.json @@ -7,16 +7,8 @@ "prologue": "Hi there!" } }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, "downstream": ["retrieval:0"], - "upstream": ["begin", "generate:0"] + "upstream": [] }, "retrieval:0": { "obj": { @@ -26,29 +18,44 @@ "keywords_similarity_weight": 0.3, "top_n": 6, "top_k": 1024, - "rerank_id": "BAAI/bge-reranker-v2-m3", - "kb_ids": ["869a236818b811ef91dffa163e197198"] + "rerank_id": "", + "empty_response": "Nothing found in dataset", + "kb_ids": ["1a3d1d7afb0611ef9866047c16ec874f"] } }, "downstream": ["generate:0"], - "upstream": ["answer:0"] + "upstream": ["begin"] }, "generate:0": { "obj": { - "component_name": "Generate", + "component_name": "LLM", "params": { "llm_id": "deepseek-chat", - "prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n Here is the knowledge base:\n {input}\n The above is the knowledge base.", + "sys_prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n Here is the knowledge base:\n {retrieval:0@formalized_content}\n The above is the knowledge base.", "temperature": 0.2 } }, - "downstream": ["answer:0"], + "downstream": ["message:0"], "upstream": ["retrieval:0"] + }, + "message:0": { + "obj": { + "component_name": "Message", + "params": { + "content": ["{generate:0@content}"] + } + }, + "downstream": [], + "upstream": ["generate:0"] } }, "history": [], - "messages": [], - "reference": {}, "path": [], - "answer": [] + "retrival": {"chunks": [], "doc_aggs": []}, + "globals": { + "sys.query": "", + "sys.user_id": "", + "sys.conversation_turns": 0, + "sys.files": [] + } } \ No newline at end of file diff --git a/agent/test/dsl_examples/retrieval_categorize_and_generate.json b/agent/test/dsl_examples/retrieval_categorize_and_generate.json index 4276b33306f..c506b9a6bfc 100644 --- a/agent/test/dsl_examples/retrieval_categorize_and_generate.json +++ b/agent/test/dsl_examples/retrieval_categorize_and_generate.json @@ -7,16 +7,8 @@ "prologue": "Hi there!" } }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, "downstream": ["categorize:0"], - "upstream": ["begin", "generate:0", "switch:0"] + "upstream": [] }, "categorize:0": { "obj": { @@ -26,30 +18,30 @@ "category_description": { "product_related": { "description": "The question is about the product usage, appearance and how it works.", - "examples": "Why it always beaming?\nHow to install it onto the wall?\nIt leaks, what to do?", - "to": "retrieval:0" + "examples": [], + "to": ["retrieval:0"] }, "others": { "description": "The question is not about the product usage, appearance and how it works.", - "examples": "How are you doing?\nWhat is your name?\nAre you a robot?\nWhat's the weather?\nWill it rain?", - "to": "message:0" + "examples": [], + "to": ["message:0"] } } } }, - "downstream": ["retrieval:0", "message:0"], - "upstream": ["answer:0"] + "downstream": [], + "upstream": ["begin"] }, "message:0": { "obj":{ "component_name": "Message", "params": { - "messages": [ + "content": [ "Sorry, I don't know. I'm an AI bot." ] } }, - "downstream": ["answer:0"], + "downstream": [], "upstream": ["categorize:0"] }, "retrieval:0": { @@ -60,29 +52,44 @@ "keywords_similarity_weight": 0.3, "top_n": 6, "top_k": 1024, - "rerank_id": "BAAI/bge-reranker-v2-m3", - "kb_ids": ["869a236818b811ef91dffa163e197198"] + "rerank_id": "", + "empty_response": "Nothing found in dataset", + "kb_ids": ["1a3d1d7afb0611ef9866047c16ec874f"] } }, "downstream": ["generate:0"], - "upstream": ["switch:0"] + "upstream": ["categorize:0"] }, "generate:0": { "obj": { - "component_name": "Generate", + "component_name": "Agent", "params": { "llm_id": "deepseek-chat", - "prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n Here is the knowledge base:\n {input}\n The above is the knowledge base.", + "sys_prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n Here is the knowledge base:\n {retrieval:0@formalized_content}\n The above is the knowledge base.", "temperature": 0.2 } }, - "downstream": ["answer:0"], + "downstream": ["message:1"], "upstream": ["retrieval:0"] + }, + "message:1": { + "obj": { + "component_name": "Message", + "params": { + "content": ["{generate:0@content}"] + } + }, + "downstream": [], + "upstream": ["generate:0"] } }, "history": [], - "messages": [], - "reference": {}, "path": [], - "answer": [] + "retrival": {"chunks": [], "doc_aggs": []}, + "globals": { + "sys.query": "", + "sys.user_id": "", + "sys.conversation_turns": 0, + "sys.files": [] + } } \ No newline at end of file diff --git a/agent/test/dsl_examples/retrieval_relevant_and_generate.json b/agent/test/dsl_examples/retrieval_relevant_and_generate.json deleted file mode 100644 index 8eeb3237db0..00000000000 --- a/agent/test/dsl_examples/retrieval_relevant_and_generate.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "components": { - "begin": { - "obj":{ - "component_name": "Begin", - "params": { - "prologue": "Hi there!" - } - }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, - "downstream": ["retrieval:0"], - "upstream": ["begin", "generate:0", "switch:0"] - }, - "retrieval:0": { - "obj": { - "component_name": "Retrieval", - "params": { - "similarity_threshold": 0.2, - "keywords_similarity_weight": 0.3, - "top_n": 6, - "top_k": 1024, - "rerank_id": "BAAI/bge-reranker-v2-m3", - "kb_ids": ["869a236818b811ef91dffa163e197198"], - "empty_response": "Sorry, knowledge base has noting related information." - } - }, - "downstream": ["relevant:0"], - "upstream": ["answer:0"] - }, - "relevant:0": { - "obj": { - "component_name": "Relevant", - "params": { - "llm_id": "deepseek-chat", - "temperature": 0.02, - "yes": "generate:0", - "no": "message:0" - } - }, - "downstream": ["message:0", "generate:0"], - "upstream": ["retrieval:0"] - }, - "generate:0": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are an intelligent assistant. Please answer the question based on content of knowledge base. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\". Answers need to consider chat history.\n Knowledge base content is as following:\n {input}\n The above is the content of knowledge base.", - "temperature": 0.2 - } - }, - "downstream": ["answer:0"], - "upstream": ["relevant:0"] - }, - "message:0": { - "obj":{ - "component_name": "Message", - "params": { - "messages": [ - "Sorry, I don't know. Please leave your contact, our experts will contact you later. What's your e-mail/phone/wechat?", - "I'm an AI bot and not quite sure about this question. Please leave your contact, our experts will contact you later. What's your e-mail/phone/wechat?", - "Can't find answer in my knowledge base. Please leave your contact, our experts will contact you later. What's your e-mail/phone/wechat?" - ] - } - }, - "downstream": ["answer:0"], - "upstream": ["relevant:0"] - } - }, - "history": [], - "path": [], - "messages": [], - "reference": {}, - "answer": [] -} \ No newline at end of file diff --git a/agent/test/dsl_examples/retrieval_relevant_keyword_baidu_and_generate.json b/agent/test/dsl_examples/retrieval_relevant_keyword_baidu_and_generate.json deleted file mode 100644 index a34b58a3625..00000000000 --- a/agent/test/dsl_examples/retrieval_relevant_keyword_baidu_and_generate.json +++ /dev/null @@ -1,103 +0,0 @@ -{ - "components": { - "begin": { - "obj":{ - "component_name": "Begin", - "params": { - "prologue": "Hi there!" - } - }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, - "downstream": ["retrieval:0"], - "upstream": ["begin"] - }, - "retrieval:0": { - "obj": { - "component_name": "Retrieval", - "params": { - "similarity_threshold": 0.2, - "keywords_similarity_weight": 0.3, - "top_n": 6, - "top_k": 1024, - "rerank_id": "BAAI/bge-reranker-v2-m3", - "kb_ids": ["21ca4e6a2c8911ef8b1e0242ac120006"], - "empty_response": "Sorry, knowledge base has noting related information." - } - }, - "downstream": ["relevant:0"], - "upstream": ["answer:0"] - }, - "relevant:0": { - "obj": { - "component_name": "Relevant", - "params": { - "llm_id": "deepseek-chat", - "temperature": 0.02, - "yes": "generate:0", - "no": "keyword:0" - } - }, - "downstream": ["keyword:0", "generate:0"], - "upstream": ["retrieval:0"] - }, - "generate:0": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are an intelligent assistant. Please answer the question based on content of knowledge base. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\". Answers need to consider chat history.\n Knowledge base content is as following:\n {input}\n The above is the content of knowledge base.", - "temperature": 0.2 - } - }, - "downstream": ["answer:0"], - "upstream": ["relevant:0"] - }, - "keyword:0": { - "obj": { - "component_name": "KeywordExtract", - "params": { - "llm_id": "deepseek-chat", - "prompt": "- Role: You're a question analyzer.\n - Requirements:\n - Summarize user's question, and give top %s important keyword/phrase.\n - Use comma as a delimiter to separate keywords/phrases.\n - Answer format: (in language of user's question)\n - keyword: ", - "temperature": 0.2, - "top_n": 1 - } - }, - "downstream": ["baidu:0"], - "upstream": ["relevant:0"] - }, - "baidu:0": { - "obj":{ - "component_name": "Baidu", - "params": { - "top_n": 10 - } - }, - "downstream": ["generate:1"], - "upstream": ["keyword:0"] - }, - "generate:1": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are an intelligent assistant. Please answer the question based on content searched from Baidu. When the answer from a Baidu search is incomplete, you need to output the URL link of the corresponding content as well. When all the content searched from Baidu is irrelevant to the question, your answer must include the sentence, \"The answer you are looking for is not found in the Baidu search!\". Answers need to consider chat history.\n The content of Baidu search is as follows:\n {input}\n The above is the content of Baidu search.", - "temperature": 0.2 - } - }, - "downstream": ["answer:0"], - "upstream": ["baidu:0"] - } - }, - "history": [], - "path": [], - "messages": [], - "reference": {}, - "answer": [] -} diff --git a/agent/test/dsl_examples/retrieval_relevant_rewrite_and_generate.json b/agent/test/dsl_examples/retrieval_relevant_rewrite_and_generate.json deleted file mode 100644 index fb290a2ec2f..00000000000 --- a/agent/test/dsl_examples/retrieval_relevant_rewrite_and_generate.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "components": { - "begin": { - "obj":{ - "component_name": "Begin", - "params": { - "prologue": "Hi there!" - } - }, - "downstream": ["answer:0"], - "upstream": [] - }, - "answer:0": { - "obj": { - "component_name": "Answer", - "params": {} - }, - "downstream": ["retrieval:0"], - "upstream": ["begin", "generate:0", "switch:0"] - }, - "retrieval:0": { - "obj": { - "component_name": "Retrieval", - "params": { - "similarity_threshold": 0.2, - "keywords_similarity_weight": 0.3, - "top_n": 6, - "top_k": 1024, - "rerank_id": "BAAI/bge-reranker-v2-m3", - "kb_ids": ["869a236818b811ef91dffa163e197198"], - "empty_response": "Sorry, knowledge base has noting related information." - } - }, - "downstream": ["relevant:0"], - "upstream": ["answer:0", "rewrite:0"] - }, - "relevant:0": { - "obj": { - "component_name": "Relevant", - "params": { - "llm_id": "deepseek-chat", - "temperature": 0.02, - "yes": "generate:0", - "no": "rewrite:0" - } - }, - "downstream": ["generate:0", "rewrite:0"], - "upstream": ["retrieval:0"] - }, - "generate:0": { - "obj": { - "component_name": "Generate", - "params": { - "llm_id": "deepseek-chat", - "prompt": "You are an intelligent assistant. Please answer the question based on content of knowledge base. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\". Answers need to consider chat history.\n Knowledge base content is as following:\n {input}\n The above is the content of knowledge base.", - "temperature": 0.02 - } - }, - "downstream": ["answer:0"], - "upstream": ["relevant:0"] - }, - "rewrite:0": { - "obj":{ - "component_name": "RewriteQuestion", - "params": { - "llm_id": "deepseek-chat", - "temperature": 0.8 - } - }, - "downstream": ["retrieval:0"], - "upstream": ["relevant:0"] - } - }, - "history": [], - "messages": [], - "path": [], - "reference": [], - "answer": [] -} \ No newline at end of file diff --git a/agent/test/dsl_examples/tavily_and_generate.json b/agent/test/dsl_examples/tavily_and_generate.json new file mode 100644 index 00000000000..f2f79b4b73a --- /dev/null +++ b/agent/test/dsl_examples/tavily_and_generate.json @@ -0,0 +1,55 @@ +{ + "components": { + "begin": { + "obj":{ + "component_name": "Begin", + "params": { + "prologue": "Hi there!" + } + }, + "downstream": ["tavily:0"], + "upstream": [] + }, + "tavily:0": { + "obj": { + "component_name": "TavilySearch", + "params": { + "api_key": "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" + } + }, + "downstream": ["generate:0"], + "upstream": ["begin"] + }, + "generate:0": { + "obj": { + "component_name": "LLM", + "params": { + "llm_id": "deepseek-chat", + "sys_prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n Here is the knowledge base:\n {tavily:0@formalized_content}\n The above is the knowledge base.", + "temperature": 0.2 + } + }, + "downstream": ["message:0"], + "upstream": ["tavily:0"] + }, + "message:0": { + "obj": { + "component_name": "Message", + "params": { + "content": ["{generate:0@content}"] + } + }, + "downstream": [], + "upstream": ["generate:0"] + } + }, + "history": [], + "path": [], + "retrival": {"chunks": [], "doc_aggs": []}, + "globals": { + "sys.query": "", + "sys.user_id": "", + "sys.conversation_turns": 0, + "sys.files": [] + } +} \ No newline at end of file diff --git a/agent/tools/__init__.py b/agent/tools/__init__.py new file mode 100644 index 00000000000..e002614c8cf --- /dev/null +++ b/agent/tools/__init__.py @@ -0,0 +1,48 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import importlib +import inspect +from types import ModuleType +from typing import Dict, Type + +_package_path = os.path.dirname(__file__) +__all_classes: Dict[str, Type] = {} + +def _import_submodules() -> None: + for filename in os.listdir(_package_path): # noqa: F821 + if filename.startswith("__") or not filename.endswith(".py") or filename.startswith("base"): + continue + module_name = filename[:-3] + + try: + module = importlib.import_module(f".{module_name}", package=__name__) + _extract_classes_from_module(module) # noqa: F821 + except ImportError as e: + print(f"Warning: Failed to import module {module_name}: {str(e)}") + +def _extract_classes_from_module(module: ModuleType) -> None: + for name, obj in inspect.getmembers(module): + if (inspect.isclass(obj) and + obj.__module__ == module.__name__ and not name.startswith("_")): + __all_classes[name] = obj + globals()[name] = obj + +_import_submodules() + +__all__ = list(__all_classes.keys()) + ["__all_classes"] + +del _package_path, _import_submodules, _extract_classes_from_module \ No newline at end of file diff --git a/agent/component/akshare.py b/agent/tools/akshare.py similarity index 100% rename from agent/component/akshare.py rename to agent/tools/akshare.py diff --git a/agent/tools/arxiv.py b/agent/tools/arxiv.py new file mode 100644 index 00000000000..10d502c56c1 --- /dev/null +++ b/agent/tools/arxiv.py @@ -0,0 +1,116 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import time +from abc import ABC +import arxiv +from agent.tools.base import ToolParamBase, ToolMeta, ToolBase +from common.connection_utils import timeout + + +class ArXivParam(ToolParamBase): + """ + Define the ArXiv component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "arxiv_search", + "description": """arXiv is a free distribution service and an open-access archive for nearly 2.4 million scholarly articles in the fields of physics, mathematics, computer science, quantitative biology, quantitative finance, statistics, electrical engineering and systems science, and economics. Materials on this site are not peer-reviewed by arXiv.""", + "parameters": { + "query": { + "type": "string", + "description": "The search keywords to execute with arXiv. The keywords should be the most important words/terms(includes synonyms) from the original request.", + "default": "{sys.query}", + "required": True + } + } + } + super().__init__() + self.top_n = 12 + self.sort_by = 'submittedDate' + + def check(self): + self.check_positive_integer(self.top_n, "Top N") + self.check_valid_value(self.sort_by, "ArXiv Search Sort_by", + ['submittedDate', 'lastUpdatedDate', 'relevance']) + + def get_input_form(self) -> dict[str, dict]: + return { + "query": { + "name": "Query", + "type": "line" + } + } + + +class ArXiv(ToolBase, ABC): + component_name = "ArXiv" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 12))) + def _invoke(self, **kwargs): + if self.check_if_canceled("ArXiv processing"): + return + + if not kwargs.get("query"): + self.set_output("formalized_content", "") + return "" + + last_e = "" + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("ArXiv processing"): + return + + try: + sort_choices = {"relevance": arxiv.SortCriterion.Relevance, + "lastUpdatedDate": arxiv.SortCriterion.LastUpdatedDate, + 'submittedDate': arxiv.SortCriterion.SubmittedDate} + arxiv_client = arxiv.Client() + search = arxiv.Search( + query=kwargs["query"], + max_results=self._param.top_n, + sort_by=sort_choices[self._param.sort_by] + ) + results = list(arxiv_client.results(search)) + + if self.check_if_canceled("ArXiv processing"): + return + + self._retrieve_chunks(results, + get_title=lambda r: r.title, + get_url=lambda r: r.pdf_url, + get_content=lambda r: r.summary) + return self.output("formalized_content") + except Exception as e: + if self.check_if_canceled("ArXiv processing"): + return + + last_e = e + logging.exception(f"ArXiv error: {e}") + time.sleep(self._param.delay_after_error) + + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"ArXiv error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return """ +Keywords: {} +Looking for the most relevant articles. + """.format(self.get_input().get("query", "-_-!")) diff --git a/agent/tools/base.py b/agent/tools/base.py new file mode 100644 index 00000000000..a3d569694a4 --- /dev/null +++ b/agent/tools/base.py @@ -0,0 +1,176 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import re +import time +from copy import deepcopy +from functools import partial +from typing import TypedDict, List, Any +from agent.component.base import ComponentParamBase, ComponentBase +from common.misc_utils import hash_str2int +from rag.llm.chat_model import ToolCallSession +from rag.prompts.generator import kb_prompt +from rag.utils.mcp_tool_call_conn import MCPToolCallSession +from timeit import default_timer as timer + + +class ToolParameter(TypedDict): + type: str + description: str + displayDescription: str + enum: List[str] + required: bool + + +class ToolMeta(TypedDict): + name: str + displayName: str + description: str + displayDescription: str + parameters: dict[str, ToolParameter] + + +class LLMToolPluginCallSession(ToolCallSession): + def __init__(self, tools_map: dict[str, object], callback: partial): + self.tools_map = tools_map + self.callback = callback + + def tool_call(self, name: str, arguments: dict[str, Any]) -> Any: + assert name in self.tools_map, f"LLM tool {name} does not exist" + st = timer() + if isinstance(self.tools_map[name], MCPToolCallSession): + resp = self.tools_map[name].tool_call(name, arguments, 60) + else: + resp = self.tools_map[name].invoke(**arguments) + + self.callback(name, arguments, resp, elapsed_time=timer()-st) + return resp + + def get_tool_obj(self, name): + return self.tools_map[name] + + +class ToolParamBase(ComponentParamBase): + def __init__(self): + #self.meta:ToolMeta = None + super().__init__() + self._init_inputs() + self._init_attr_by_meta() + + def _init_inputs(self): + self.inputs = {} + for k,p in self.meta["parameters"].items(): + self.inputs[k] = deepcopy(p) + + def _init_attr_by_meta(self): + for k,p in self.meta["parameters"].items(): + if not hasattr(self, k): + setattr(self, k, p.get("default")) + + def get_meta(self): + params = {} + for k, p in self.meta["parameters"].items(): + params[k] = { + "type": p["type"], + "description": p["description"] + } + if "enum" in p: + params[k]["enum"] = p["enum"] + + desc = self.meta["description"] + if hasattr(self, "description"): + desc = self.description + + function_name = self.meta["name"] + if hasattr(self, "function_name"): + function_name = self.function_name + + return { + "type": "function", + "function": { + "name": function_name, + "description": desc, + "parameters": { + "type": "object", + "properties": params, + "required": [k for k, p in self.meta["parameters"].items() if p["required"]] + } + } + } + + +class ToolBase(ComponentBase): + def __init__(self, canvas, id, param: ComponentParamBase): + from agent.canvas import Canvas # Local import to avoid cyclic dependency + assert isinstance(canvas, Canvas), "canvas must be an instance of Canvas" + self._canvas = canvas + self._id = id + self._param = param + self._param.check() + + def get_meta(self) -> dict[str, Any]: + return self._param.get_meta() + + def invoke(self, **kwargs): + if self.check_if_canceled("Tool processing"): + return + + self.set_output("_created_time", time.perf_counter()) + try: + res = self._invoke(**kwargs) + except Exception as e: + self._param.outputs["_ERROR"] = {"value": str(e)} + logging.exception(e) + res = str(e) + self._param.debug_inputs = [] + + self.set_output("_elapsed_time", time.perf_counter() - self.output("_created_time")) + return res + + def _retrieve_chunks(self, res_list: list, get_title, get_url, get_content, get_score=None): + chunks = [] + aggs = [] + for r in res_list: + content = get_content(r) + if not content: + continue + content = re.sub(r"!?\[[a-z]+\]\(data:image/png;base64,[ 0-9A-Za-z/_=+-]+\)", "", content) + content = content[:10000] + if not content: + continue + id = str(hash_str2int(content)) + title = get_title(r) + url = get_url(r) + score = get_score(r) if get_score else 1 + chunks.append({ + "chunk_id": id, + "content": content, + "doc_id": id, + "docnm_kwd": title, + "similarity": score, + "url": url + }) + aggs.append({ + "doc_name": title, + "doc_id": id, + "count": 1, + "url": url + }) + self._canvas.add_reference(chunks, aggs) + self.set_output("formalized_content", "\n".join(kb_prompt({"chunks": chunks, "doc_aggs": aggs}, 200000, True))) + + def thoughts(self) -> str: + return self._canvas.get_component_name(self._id) + " is running..." diff --git a/agent/tools/code_exec.py b/agent/tools/code_exec.py new file mode 100644 index 00000000000..adba4168e28 --- /dev/null +++ b/agent/tools/code_exec.py @@ -0,0 +1,230 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import base64 +import logging +import os +from abc import ABC +from strenum import StrEnum +from typing import Optional +from pydantic import BaseModel, Field, field_validator +from agent.tools.base import ToolParamBase, ToolBase, ToolMeta +from common.connection_utils import timeout +from common import settings + + +class Language(StrEnum): + PYTHON = "python" + NODEJS = "nodejs" + + +class CodeExecutionRequest(BaseModel): + code_b64: str = Field(..., description="Base64 encoded code string") + language: str = Field(default=Language.PYTHON.value, description="Programming language") + arguments: Optional[dict] = Field(default={}, description="Arguments") + + @field_validator("code_b64") + @classmethod + def validate_base64(cls, v: str) -> str: + try: + base64.b64decode(v, validate=True) + return v + except Exception as e: + raise ValueError(f"Invalid base64 encoding: {str(e)}") + + @field_validator("language", mode="before") + @classmethod + def normalize_language(cls, v) -> str: + if isinstance(v, str): + low = v.lower() + if low in ("python", "python3"): + return "python" + elif low in ("javascript", "nodejs"): + return "nodejs" + raise ValueError(f"Unsupported language: {v}") + + +class CodeExecParam(ToolParamBase): + """ + Define the code sandbox component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "execute_code", + "description": """ +This tool has a sandbox that can execute code written in 'Python'/'Javascript'. It recieves a piece of code and return a Json string. +Here's a code example for Python(`main` function MUST be included): +def main() -> dict: + \"\"\" + Generate Fibonacci numbers within 100. + \"\"\" + def fibonacci_recursive(n): + if n <= 1: + return n + else: + return fibonacci_recursive(n-1) + fibonacci_recursive(n-2) + return { + "result": fibonacci_recursive(100), + } + +Here's a code example for Javascript(`main` function MUST be included and exported): +const axios = require('axios'); +async function main(args) { + try { + const response = await axios.get('https://github.com/infiniflow/ragflow'); + console.log('Body:', response.data); + } catch (error) { + console.error('Error:', error.message); + } +} +module.exports = { main }; + """, + "parameters": { + "lang": { + "type": "string", + "description": "The programming language of this piece of code.", + "enum": ["python", "javascript"], + "required": True, + }, + "script": { + "type": "string", + "description": "A piece of code in right format. There MUST be main function.", + "required": True + } + } + } + super().__init__() + self.lang = Language.PYTHON.value + self.script = "def main(arg1: str, arg2: str) -> dict: return {\"result\": arg1 + arg2}" + self.arguments = {} + self.outputs = {"result": {"value": "", "type": "string"}} + + def check(self): + self.check_valid_value(self.lang, "Support languages", ["python", "python3", "nodejs", "javascript"]) + self.check_empty(self.script, "Script") + + def get_input_form(self) -> dict[str, dict]: + res = {} + for k, v in self.arguments.items(): + res[k] = { + "type": "line", + "name": k + } + return res + + +class CodeExec(ToolBase, ABC): + component_name = "CodeExec" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 10*60))) + def _invoke(self, **kwargs): + if self.check_if_canceled("CodeExec processing"): + return + + lang = kwargs.get("lang", self._param.lang) + script = kwargs.get("script", self._param.script) + arguments = {} + for k, v in self._param.arguments.items(): + + if kwargs.get(k): + arguments[k] = kwargs[k] + continue + arguments[k] = self._canvas.get_variable_value(v) if v else None + + self._execute_code( + language=lang, + code=script, + arguments=arguments + ) + + def _execute_code(self, language: str, code: str, arguments: dict): + import requests + + if self.check_if_canceled("CodeExec execution"): + return + + try: + code_b64 = self._encode_code(code) + code_req = CodeExecutionRequest(code_b64=code_b64, language=language, arguments=arguments).model_dump() + except Exception as e: + if self.check_if_canceled("CodeExec execution"): + return + + self.set_output("_ERROR", "construct code request error: " + str(e)) + + try: + if self.check_if_canceled("CodeExec execution"): + return "Task has been canceled" + + resp = requests.post(url=f"http://{settings.SANDBOX_HOST}:9385/run", json=code_req, timeout=int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 10*60))) + logging.info(f"http://{settings.SANDBOX_HOST}:9385/run, code_req: {code_req}, resp.status_code {resp.status_code}:") + + if self.check_if_canceled("CodeExec execution"): + return "Task has been canceled" + + if resp.status_code != 200: + resp.raise_for_status() + body = resp.json() + if body: + stderr = body.get("stderr") + if stderr: + self.set_output("_ERROR", stderr) + return + try: + rt = eval(body.get("stdout", "")) + except Exception: + rt = body.get("stdout", "") + logging.info(f"http://{settings.SANDBOX_HOST}:9385/run -> {rt}") + if isinstance(rt, tuple): + for i, (k, o) in enumerate(self._param.outputs.items()): + if self.check_if_canceled("CodeExec execution"): + return + + if k.find("_") == 0: + continue + o["value"] = rt[i] + elif isinstance(rt, dict): + for i, (k, o) in enumerate(self._param.outputs.items()): + if self.check_if_canceled("CodeExec execution"): + return + + if k not in rt or k.find("_") == 0: + continue + o["value"] = rt[k] + else: + for i, (k, o) in enumerate(self._param.outputs.items()): + if self.check_if_canceled("CodeExec execution"): + return + + if k.find("_") == 0: + continue + o["value"] = rt + else: + self.set_output("_ERROR", "There is no response from sandbox") + + except Exception as e: + if self.check_if_canceled("CodeExec execution"): + return + + self.set_output("_ERROR", "Exception executing code: " + str(e)) + + return self.output() + + def _encode_code(self, code: str) -> str: + return base64.b64encode(code.encode("utf-8")).decode("utf-8") + + def thoughts(self) -> str: + return "Running a short script to process data." diff --git a/agent/component/crawler.py b/agent/tools/crawler.py similarity index 83% rename from agent/component/crawler.py rename to agent/tools/crawler.py index d8c5381b164..e4d049e1bdd 100644 --- a/agent/component/crawler.py +++ b/agent/tools/crawler.py @@ -16,11 +16,11 @@ from abc import ABC import asyncio from crawl4ai import AsyncWebCrawler -from agent.component.base import ComponentBase, ComponentParamBase -from api.utils.web_utils import is_valid_url +from agent.tools.base import ToolParamBase, ToolBase -class CrawlerParam(ComponentParamBase): + +class CrawlerParam(ToolParamBase): """ Define the Crawler component parameters. """ @@ -29,15 +29,16 @@ def __init__(self): super().__init__() self.proxy = None self.extract_type = "markdown" - + def check(self): self.check_valid_value(self.extract_type, "Type of content from the crawler", ['html', 'markdown', 'content']) -class Crawler(ComponentBase, ABC): +class Crawler(ToolBase, ABC): component_name = "Crawler" def _run(self, history, **kwargs): + from api.utils.web_utils import is_valid_url ans = self.get_input() ans = " - ".join(ans["content"]) if "content" in ans else "" if not is_valid_url(ans): @@ -46,22 +47,28 @@ def _run(self, history, **kwargs): result = asyncio.run(self.get_web(ans)) return Crawler.be_output(result) - + except Exception as e: return Crawler.be_output(f"An unexpected error occurred: {str(e)}") async def get_web(self, url): + if self.check_if_canceled("Crawler async operation"): + return + proxy = self._param.proxy if self._param.proxy else None async with AsyncWebCrawler(verbose=True, proxy=proxy) as crawler: result = await crawler.arun( url=url, bypass_cache=True ) - + + if self.check_if_canceled("Crawler async operation"): + return + if self._param.extract_type == 'html': return result.cleaned_html elif self._param.extract_type == 'markdown': return result.markdown elif self._param.extract_type == 'content': - result.extracted_content + return result.extracted_content return result.markdown diff --git a/agent/component/deepl.py b/agent/tools/deepl.py similarity index 90% rename from agent/component/deepl.py rename to agent/tools/deepl.py index 31e92729c37..dc331aafe42 100644 --- a/agent/component/deepl.py +++ b/agent/tools/deepl.py @@ -43,14 +43,19 @@ def check(self): class DeepL(ComponentBase, ABC): - component_name = "GitHub" + component_name = "DeepL" def _run(self, history, **kwargs): + if self.check_if_canceled("DeepL processing"): + return ans = self.get_input() ans = " - ".join(ans["content"]) if "content" in ans else "" if not ans: return DeepL.be_output("") + if self.check_if_canceled("DeepL processing"): + return + try: translator = deepl.Translator(self._param.auth_key) result = translator.translate_text(ans, source_lang=self._param.source_lang, @@ -58,4 +63,6 @@ def _run(self, history, **kwargs): return DeepL.be_output(result.text) except Exception as e: + if self.check_if_canceled("DeepL processing"): + return DeepL.be_output("**Error**:" + str(e)) diff --git a/agent/tools/duckduckgo.py b/agent/tools/duckduckgo.py new file mode 100644 index 00000000000..fd2ec1801b2 --- /dev/null +++ b/agent/tools/duckduckgo.py @@ -0,0 +1,143 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import time +from abc import ABC +from duckduckgo_search import DDGS +from agent.tools.base import ToolMeta, ToolParamBase, ToolBase +from common.connection_utils import timeout + + +class DuckDuckGoParam(ToolParamBase): + """ + Define the DuckDuckGo component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "duckduckgo_search", + "description": "DuckDuckGo is a search engine focused on privacy. It offers search capabilities for web pages, images, and provides translation services. DuckDuckGo also features a private AI chat interface, providing users with an AI assistant that prioritizes data protection.", + "parameters": { + "query": { + "type": "string", + "description": "The search keywords to execute with DuckDuckGo. The keywords should be the most important words/terms(includes synonyms) from the original request.", + "default": "{sys.query}", + "required": True + }, + "channel": { + "type": "string", + "description": "default:general. The category of the search. `news` is useful for retrieving real-time updates, particularly about politics, sports, and major current events covered by mainstream media sources. `general` is for broader, more general-purpose searches that may include a wide range of sources.", + "enum": ["general", "news"], + "default": "general", + "required": False, + }, + } + } + super().__init__() + self.top_n = 10 + self.channel = "text" + + def check(self): + self.check_positive_integer(self.top_n, "Top N") + self.check_valid_value(self.channel, "Web Search or News", ["text", "news"]) + + def get_input_form(self) -> dict[str, dict]: + return { + "query": { + "name": "Query", + "type": "line" + }, + "channel": { + "name": "Channel", + "type": "options", + "value": "general", + "options": ["general", "news"] + } + } + + +class DuckDuckGo(ToolBase, ABC): + component_name = "DuckDuckGo" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 12))) + def _invoke(self, **kwargs): + if self.check_if_canceled("DuckDuckGo processing"): + return + + if not kwargs.get("query"): + self.set_output("formalized_content", "") + return "" + + last_e = "" + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("DuckDuckGo processing"): + return + + try: + if kwargs.get("topic", "general") == "general": + with DDGS() as ddgs: + if self.check_if_canceled("DuckDuckGo processing"): + return + + # {'title': '', 'href': '', 'body': ''} + duck_res = ddgs.text(kwargs["query"], max_results=self._param.top_n) + + if self.check_if_canceled("DuckDuckGo processing"): + return + + self._retrieve_chunks(duck_res, + get_title=lambda r: r["title"], + get_url=lambda r: r.get("href", r.get("url")), + get_content=lambda r: r["body"]) + self.set_output("json", duck_res) + return self.output("formalized_content") + else: + with DDGS() as ddgs: + if self.check_if_canceled("DuckDuckGo processing"): + return + + # {'date': '', 'title': '', 'body': '', 'url': '', 'image': '', 'source': ''} + duck_res = ddgs.news(kwargs["query"], max_results=self._param.top_n) + + if self.check_if_canceled("DuckDuckGo processing"): + return + + self._retrieve_chunks(duck_res, + get_title=lambda r: r["title"], + get_url=lambda r: r.get("href", r.get("url")), + get_content=lambda r: r["body"]) + self.set_output("json", duck_res) + return self.output("formalized_content") + except Exception as e: + if self.check_if_canceled("DuckDuckGo processing"): + return + + last_e = e + logging.exception(f"DuckDuckGo error: {e}") + time.sleep(self._param.delay_after_error) + + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"DuckDuckGo error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return """ +Keywords: {} +Looking for the most relevant articles. + """.format(self.get_input().get("query", "-_-!")) diff --git a/agent/tools/email.py b/agent/tools/email.py new file mode 100644 index 00000000000..e19fd69c668 --- /dev/null +++ b/agent/tools/email.py @@ -0,0 +1,230 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import time +from abc import ABC +import json +import smtplib +import logging +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart +from email.header import Header +from email.utils import formataddr + +from agent.tools.base import ToolParamBase, ToolBase, ToolMeta +from common.connection_utils import timeout + + +class EmailParam(ToolParamBase): + """ + Define the Email component parameters. + """ + def __init__(self): + self.meta:ToolMeta = { + "name": "email", + "description": "The email is a method of electronic communication for sending and receiving information through the Internet. This tool helps users to send emails to one person or to multiple recipients with support for CC, BCC, file attachments, and markdown-to-HTML conversion.", + "parameters": { + "to_email": { + "type": "string", + "description": "The target email address.", + "default": "{sys.query}", + "required": True + }, + "cc_email": { + "type": "string", + "description": "The other email addresses needs to be send to. Comma splited.", + "default": "", + "required": False + }, + "content": { + "type": "string", + "description": "The content of the email.", + "default": "", + "required": False + }, + "subject": { + "type": "string", + "description": "The subject/title of the email.", + "default": "", + "required": False + } + } + } + super().__init__() + # Fixed configuration parameters + self.smtp_server = "" # SMTP server address + self.smtp_port = 465 # SMTP port + self.email = "" # Sender email + self.password = "" # Email authorization code + self.sender_name = "" # Sender name + + def check(self): + # Check required parameters + self.check_empty(self.smtp_server, "SMTP Server") + self.check_empty(self.email, "Email") + self.check_empty(self.password, "Password") + self.check_empty(self.sender_name, "Sender Name") + + def get_input_form(self) -> dict[str, dict]: + return { + "to_email": { + "name": "To ", + "type": "line" + }, + "subject": { + "name": "Subject", + "type": "line", + "optional": True + }, + "cc_email": { + "name": "CC To", + "type": "line", + "optional": True + }, + } + +class Email(ToolBase, ABC): + component_name = "Email" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 60))) + def _invoke(self, **kwargs): + if self.check_if_canceled("Email processing"): + return + + if not kwargs.get("to_email"): + self.set_output("success", False) + return "" + + last_e = "" + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("Email processing"): + return + + try: + # Parse JSON string passed from upstream + email_data = kwargs + + # Validate required fields + if "to_email" not in email_data: + self.set_output("_ERROR", "Missing required field: to_email") + self.set_output("success", False) + return False + + # Create email object + msg = MIMEMultipart('alternative') + + # Properly handle sender name encoding + msg['From'] = formataddr((str(Header(self._param.sender_name,'utf-8')), self._param.email)) + msg['To'] = email_data["to_email"] + if email_data.get("cc_email"): + msg['Cc'] = email_data["cc_email"] + msg['Subject'] = Header(email_data.get("subject", "No Subject"), 'utf-8').encode() + + # Use content from email_data or default content + email_content = email_data.get("content", "No content provided") + # msg.attach(MIMEText(email_content, 'plain', 'utf-8')) + msg.attach(MIMEText(email_content, 'html', 'utf-8')) + + # Connect to SMTP server and send + logging.info(f"Connecting to SMTP server {self._param.smtp_server}:{self._param.smtp_port}") + + if self.check_if_canceled("Email processing"): + return + + context = smtplib.ssl.create_default_context() + with smtplib.SMTP(self._param.smtp_server, self._param.smtp_port) as server: + server.ehlo() + server.starttls(context=context) + server.ehlo() + # Login + logging.info(f"Attempting to login with email: {self._param.email}") + server.login(self._param.email, self._param.password) + + # Get all recipient list + recipients = [email_data["to_email"]] + if email_data.get("cc_email"): + recipients.extend(email_data["cc_email"].split(',')) + + # Send email + logging.info(f"Sending email to recipients: {recipients}") + + if self.check_if_canceled("Email processing"): + return + + try: + server.send_message(msg, self._param.email, recipients) + success = True + except Exception as e: + logging.error(f"Error during send_message: {str(e)}") + # Try alternative method + server.sendmail(self._param.email, recipients, msg.as_string()) + success = True + + try: + server.quit() + except Exception as e: + # Ignore errors when closing connection + logging.warning(f"Non-fatal error during connection close: {str(e)}") + + self.set_output("success", success) + return success + + except json.JSONDecodeError: + error_msg = "Invalid JSON format in input" + logging.error(error_msg) + self.set_output("_ERROR", error_msg) + self.set_output("success", False) + return False + + except smtplib.SMTPAuthenticationError: + error_msg = "SMTP Authentication failed. Please check your email and authorization code." + logging.error(error_msg) + self.set_output("_ERROR", error_msg) + self.set_output("success", False) + return False + + except smtplib.SMTPConnectError: + error_msg = f"Failed to connect to SMTP server {self._param.smtp_server}:{self._param.smtp_port}" + logging.error(error_msg) + last_e = error_msg + time.sleep(self._param.delay_after_error) + + except smtplib.SMTPException as e: + error_msg = f"SMTP error occurred: {str(e)}" + logging.error(error_msg) + last_e = error_msg + time.sleep(self._param.delay_after_error) + + except Exception as e: + error_msg = f"Unexpected error: {str(e)}" + logging.error(error_msg) + self.set_output("_ERROR", error_msg) + self.set_output("success", False) + return False + + if last_e: + self.set_output("_ERROR", str(last_e)) + return False + + assert False, self.output() + + def thoughts(self) -> str: + inputs = self.get_input() + return """ +To: {} +Subject: {} +Your email is on its way—sit tight! +""".format(inputs.get("to_email", "-_-!"), inputs.get("subject", "-_-!")) diff --git a/agent/tools/exesql.py b/agent/tools/exesql.py new file mode 100644 index 00000000000..012b00d84e2 --- /dev/null +++ b/agent/tools/exesql.py @@ -0,0 +1,275 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json +import os +import re +from abc import ABC +import pandas as pd +import pymysql +import psycopg2 +import pyodbc +from agent.tools.base import ToolParamBase, ToolBase, ToolMeta +from common.connection_utils import timeout + + +class ExeSQLParam(ToolParamBase): + """ + Define the ExeSQL component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "execute_sql", + "description": "This is a tool that can execute SQL.", + "parameters": { + "sql": { + "type": "string", + "description": "The SQL needs to be executed.", + "default": "{sys.query}", + "required": True + } + } + } + super().__init__() + self.db_type = "mysql" + self.database = "" + self.username = "" + self.host = "" + self.port = 3306 + self.password = "" + self.max_records = 1024 + + def check(self): + self.check_valid_value(self.db_type, "Choose DB type", ['mysql', 'postgres', 'mariadb', 'mssql', 'IBM DB2', 'trino']) + self.check_empty(self.database, "Database name") + self.check_empty(self.username, "database username") + self.check_empty(self.host, "IP Address") + self.check_positive_integer(self.port, "IP Port") + if self.db_type != "trino": + self.check_empty(self.password, "Database password") + self.check_positive_integer(self.max_records, "Maximum number of records") + if self.database == "rag_flow": + if self.host == "ragflow-mysql": + raise ValueError("For the security reason, it dose not support database named rag_flow.") + if self.password == "infini_rag_flow": + raise ValueError("For the security reason, it dose not support database named rag_flow.") + + def get_input_form(self) -> dict[str, dict]: + return { + "sql": { + "name": "SQL", + "type": "line" + } + } + + +class ExeSQL(ToolBase, ABC): + component_name = "ExeSQL" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 60))) + def _invoke(self, **kwargs): + if self.check_if_canceled("ExeSQL processing"): + return + + def convert_decimals(obj): + from decimal import Decimal + if isinstance(obj, Decimal): + return float(obj) # 或 str(obj) + elif isinstance(obj, dict): + return {k: convert_decimals(v) for k, v in obj.items()} + elif isinstance(obj, list): + return [convert_decimals(item) for item in obj] + return obj + + sql = kwargs.get("sql") + if not sql: + raise Exception("SQL for `ExeSQL` MUST not be empty.") + + if self.check_if_canceled("ExeSQL processing"): + return + + vars = self.get_input_elements_from_text(sql) + args = {} + for k, o in vars.items(): + args[k] = o["value"] + if not isinstance(args[k], str): + try: + args[k] = json.dumps(args[k], ensure_ascii=False) + except Exception: + args[k] = str(args[k]) + self.set_input_value(k, args[k]) + sql = self.string_format(sql, args) + + if self.check_if_canceled("ExeSQL processing"): + return + + sqls = sql.split(";") + if self._param.db_type in ["mysql", "mariadb"]: + db = pymysql.connect(db=self._param.database, user=self._param.username, host=self._param.host, + port=self._param.port, password=self._param.password) + elif self._param.db_type == 'postgres': + db = psycopg2.connect(dbname=self._param.database, user=self._param.username, host=self._param.host, + port=self._param.port, password=self._param.password) + elif self._param.db_type == 'mssql': + conn_str = ( + r'DRIVER={ODBC Driver 17 for SQL Server};' + r'SERVER=' + self._param.host + ',' + str(self._param.port) + ';' + r'DATABASE=' + self._param.database + ';' + r'UID=' + self._param.username + ';' + r'PWD=' + self._param.password + ) + db = pyodbc.connect(conn_str) + elif self._param.db_type == 'trino': + try: + import trino + from trino.auth import BasicAuthentication + except Exception: + raise Exception("Missing dependency 'trino'. Please install: pip install trino") + + def _parse_catalog_schema(db: str): + if not db: + return None, None + if "." in db: + c, s = db.split(".", 1) + elif "/" in db: + c, s = db.split("/", 1) + else: + c, s = db, "default" + return c, s + + catalog, schema = _parse_catalog_schema(self._param.database) + if not catalog: + raise Exception("For Trino, `database` must be 'catalog.schema' or at least 'catalog'.") + + http_scheme = "https" if os.environ.get("TRINO_USE_TLS", "0") == "1" else "http" + auth = None + if http_scheme == "https" and self._param.password: + auth = BasicAuthentication(self._param.username, self._param.password) + + try: + db = trino.dbapi.connect( + host=self._param.host, + port=int(self._param.port or 8080), + user=self._param.username or "ragflow", + catalog=catalog, + schema=schema or "default", + http_scheme=http_scheme, + auth=auth + ) + except Exception as e: + raise Exception("Database Connection Failed! \n" + str(e)) + elif self._param.db_type == 'IBM DB2': + import ibm_db + conn_str = ( + f"DATABASE={self._param.database};" + f"HOSTNAME={self._param.host};" + f"PORT={self._param.port};" + f"PROTOCOL=TCPIP;" + f"UID={self._param.username};" + f"PWD={self._param.password};" + ) + try: + conn = ibm_db.connect(conn_str, "", "") + except Exception as e: + raise Exception("Database Connection Failed! \n" + str(e)) + + sql_res = [] + formalized_content = [] + for single_sql in sqls: + if self.check_if_canceled("ExeSQL processing"): + ibm_db.close(conn) + return + + single_sql = single_sql.replace("```", "").strip() + if not single_sql: + continue + single_sql = re.sub(r"\[ID:[0-9]+\]", "", single_sql) + + stmt = ibm_db.exec_immediate(conn, single_sql) + rows = [] + row = ibm_db.fetch_assoc(stmt) + while row and len(rows) < self._param.max_records: + if self.check_if_canceled("ExeSQL processing"): + ibm_db.close(conn) + return + rows.append(row) + row = ibm_db.fetch_assoc(stmt) + + if not rows: + sql_res.append({"content": "No record in the database!"}) + continue + + df = pd.DataFrame(rows) + for col in df.columns: + if pd.api.types.is_datetime64_any_dtype(df[col]): + df[col] = df[col].dt.strftime("%Y-%m-%d") + + df = df.where(pd.notnull(df), None) + + sql_res.append(convert_decimals(df.to_dict(orient="records"))) + formalized_content.append(df.to_markdown(index=False, floatfmt=".6f")) + + ibm_db.close(conn) + + self.set_output("json", sql_res) + self.set_output("formalized_content", "\n\n".join(formalized_content)) + return self.output("formalized_content") + try: + cursor = db.cursor() + except Exception as e: + raise Exception("Database Connection Failed! \n" + str(e)) + + sql_res = [] + formalized_content = [] + for single_sql in sqls: + if self.check_if_canceled("ExeSQL processing"): + cursor.close() + db.close() + return + + single_sql = single_sql.replace('```','') + if not single_sql: + continue + single_sql = re.sub(r"\[ID:[0-9]+\]", "", single_sql) + cursor.execute(single_sql) + if cursor.rowcount == 0: + sql_res.append({"content": "No record in the database!"}) + break + if self._param.db_type == 'mssql': + single_res = pd.DataFrame.from_records(cursor.fetchmany(self._param.max_records), + columns=[desc[0] for desc in cursor.description]) + else: + single_res = pd.DataFrame([i for i in cursor.fetchmany(self._param.max_records)]) + single_res.columns = [i[0] for i in cursor.description] + + for col in single_res.columns: + if pd.api.types.is_datetime64_any_dtype(single_res[col]): + single_res[col] = single_res[col].dt.strftime('%Y-%m-%d') + + single_res = single_res.where(pd.notnull(single_res), None) + + sql_res.append(convert_decimals(single_res.to_dict(orient='records'))) + formalized_content.append(single_res.to_markdown(index=False, floatfmt=".6f")) + + cursor.close() + db.close() + + self.set_output("json", sql_res) + self.set_output("formalized_content", "\n\n".join(formalized_content)) + return self.output("formalized_content") + + def thoughts(self) -> str: + return "Query sent—waiting for the data." diff --git a/agent/tools/github.py b/agent/tools/github.py new file mode 100644 index 00000000000..f48ab0a2d69 --- /dev/null +++ b/agent/tools/github.py @@ -0,0 +1,104 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import time +from abc import ABC +import requests +from agent.tools.base import ToolParamBase, ToolMeta, ToolBase +from common.connection_utils import timeout + + +class GitHubParam(ToolParamBase): + """ + Define the GitHub component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "github_search", + "description": """GitHub repository search is a feature that enables users to find specific repositories on the GitHub platform. This search functionality allows users to locate projects, codebases, and other content hosted on GitHub based on various criteria.""", + "parameters": { + "query": { + "type": "string", + "description": "The search keywords to execute with GitHub. The keywords should be the most important words/terms(includes synonyms) from the original request.", + "default": "{sys.query}", + "required": True + } + } + } + super().__init__() + self.top_n = 10 + + def check(self): + self.check_positive_integer(self.top_n, "Top N") + + def get_input_form(self) -> dict[str, dict]: + return { + "query": { + "name": "Query", + "type": "line" + } + } + +class GitHub(ToolBase, ABC): + component_name = "GitHub" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 12))) + def _invoke(self, **kwargs): + if self.check_if_canceled("GitHub processing"): + return + + if not kwargs.get("query"): + self.set_output("formalized_content", "") + return "" + + last_e = "" + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("GitHub processing"): + return + + try: + url = 'https://api.github.com/search/repositories?q=' + kwargs["query"] + '&sort=stars&order=desc&per_page=' + str( + self._param.top_n) + headers = {"Content-Type": "application/vnd.github+json", "X-GitHub-Api-Version": '2022-11-28'} + response = requests.get(url=url, headers=headers).json() + + if self.check_if_canceled("GitHub processing"): + return + + self._retrieve_chunks(response['items'], + get_title=lambda r: r["name"], + get_url=lambda r: r["html_url"], + get_content=lambda r: str(r["description"]) + '\n stars:' + str(r['watchers'])) + self.set_output("json", response['items']) + return self.output("formalized_content") + except Exception as e: + if self.check_if_canceled("GitHub processing"): + return + + last_e = e + logging.exception(f"GitHub error: {e}") + time.sleep(self._param.delay_after_error) + + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"GitHub error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return "Scanning GitHub repos related to `{}`.".format(self.get_input().get("query", "-_-!")) diff --git a/agent/tools/google.py b/agent/tools/google.py new file mode 100644 index 00000000000..312b5a1fe33 --- /dev/null +++ b/agent/tools/google.py @@ -0,0 +1,172 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import time +from abc import ABC +from serpapi import GoogleSearch +from agent.tools.base import ToolParamBase, ToolMeta, ToolBase +from common.connection_utils import timeout + + +class GoogleParam(ToolParamBase): + """ + Define the Google component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "google_search", + "description": """Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking ...""", + "parameters": { + "q": { + "type": "string", + "description": "The search keywords to execute with Google. The keywords should be the most important words/terms(includes synonyms) from the original request.", + "default": "{sys.query}", + "required": True + }, + "start": { + "type": "integer", + "description": "Parameter defines the result offset. It skips the given number of results. It's used for pagination. (e.g., 0 (default) is the first page of results, 10 is the 2nd page of results, 20 is the 3rd page of results, etc.). Google Local Results only accepts multiples of 20(e.g. 20 for the second page results, 40 for the third page results, etc.) as the `start` value.", + "default": "0", + "required": False, + }, + "num": { + "type": "integer", + "description": "Parameter defines the maximum number of results to return. (e.g., 10 (default) returns 10 results, 40 returns 40 results, and 100 returns 100 results). The use of num may introduce latency, and/or prevent the inclusion of specialized result types. It is better to omit this parameter unless it is strictly necessary to increase the number of results per page. Results are not guaranteed to have the number of results specified in num.", + "default": "6", + "required": False, + } + } + } + super().__init__() + self.start = 0 + self.num = 6 + self.api_key = "" + self.country = "cn" + self.language = "en" + + def check(self): + self.check_empty(self.api_key, "SerpApi API key") + self.check_valid_value(self.country, "Google Country", + ['af', 'al', 'dz', 'as', 'ad', 'ao', 'ai', 'aq', 'ag', 'ar', 'am', 'aw', 'au', 'at', + 'az', 'bs', 'bh', 'bd', 'bb', 'by', 'be', 'bz', 'bj', 'bm', 'bt', 'bo', 'ba', 'bw', + 'bv', 'br', 'io', 'bn', 'bg', 'bf', 'bi', 'kh', 'cm', 'ca', 'cv', 'ky', 'cf', 'td', + 'cl', 'cn', 'cx', 'cc', 'co', 'km', 'cg', 'cd', 'ck', 'cr', 'ci', 'hr', 'cu', 'cy', + 'cz', 'dk', 'dj', 'dm', 'do', 'ec', 'eg', 'sv', 'gq', 'er', 'ee', 'et', 'fk', 'fo', + 'fj', 'fi', 'fr', 'gf', 'pf', 'tf', 'ga', 'gm', 'ge', 'de', 'gh', 'gi', 'gr', 'gl', + 'gd', 'gp', 'gu', 'gt', 'gn', 'gw', 'gy', 'ht', 'hm', 'va', 'hn', 'hk', 'hu', 'is', + 'in', 'id', 'ir', 'iq', 'ie', 'il', 'it', 'jm', 'jp', 'jo', 'kz', 'ke', 'ki', 'kp', + 'kr', 'kw', 'kg', 'la', 'lv', 'lb', 'ls', 'lr', 'ly', 'li', 'lt', 'lu', 'mo', 'mk', + 'mg', 'mw', 'my', 'mv', 'ml', 'mt', 'mh', 'mq', 'mr', 'mu', 'yt', 'mx', 'fm', 'md', + 'mc', 'mn', 'ms', 'ma', 'mz', 'mm', 'na', 'nr', 'np', 'nl', 'an', 'nc', 'nz', 'ni', + 'ne', 'ng', 'nu', 'nf', 'mp', 'no', 'om', 'pk', 'pw', 'ps', 'pa', 'pg', 'py', 'pe', + 'ph', 'pn', 'pl', 'pt', 'pr', 'qa', 're', 'ro', 'ru', 'rw', 'sh', 'kn', 'lc', 'pm', + 'vc', 'ws', 'sm', 'st', 'sa', 'sn', 'rs', 'sc', 'sl', 'sg', 'sk', 'si', 'sb', 'so', + 'za', 'gs', 'es', 'lk', 'sd', 'sr', 'sj', 'sz', 'se', 'ch', 'sy', 'tw', 'tj', 'tz', + 'th', 'tl', 'tg', 'tk', 'to', 'tt', 'tn', 'tr', 'tm', 'tc', 'tv', 'ug', 'ua', 'ae', + 'uk', 'gb', 'us', 'um', 'uy', 'uz', 'vu', 've', 'vn', 'vg', 'vi', 'wf', 'eh', 'ye', + 'zm', 'zw']) + self.check_valid_value(self.language, "Google languages", + ['af', 'ak', 'sq', 'ws', 'am', 'ar', 'hy', 'az', 'eu', 'be', 'bem', 'bn', 'bh', + 'xx-bork', 'bs', 'br', 'bg', 'bt', 'km', 'ca', 'chr', 'ny', 'zh-cn', 'zh-tw', 'co', + 'hr', 'cs', 'da', 'nl', 'xx-elmer', 'en', 'eo', 'et', 'ee', 'fo', 'tl', 'fi', 'fr', + 'fy', 'gaa', 'gl', 'ka', 'de', 'el', 'kl', 'gn', 'gu', 'xx-hacker', 'ht', 'ha', 'haw', + 'iw', 'hi', 'hu', 'is', 'ig', 'id', 'ia', 'ga', 'it', 'ja', 'jw', 'kn', 'kk', 'rw', + 'rn', 'xx-klingon', 'kg', 'ko', 'kri', 'ku', 'ckb', 'ky', 'lo', 'la', 'lv', 'ln', 'lt', + 'loz', 'lg', 'ach', 'mk', 'mg', 'ms', 'ml', 'mt', 'mv', 'mi', 'mr', 'mfe', 'mo', 'mn', + 'sr-me', 'my', 'ne', 'pcm', 'nso', 'no', 'nn', 'oc', 'or', 'om', 'ps', 'fa', + 'xx-pirate', 'pl', 'pt', 'pt-br', 'pt-pt', 'pa', 'qu', 'ro', 'rm', 'nyn', 'ru', 'gd', + 'sr', 'sh', 'st', 'tn', 'crs', 'sn', 'sd', 'si', 'sk', 'sl', 'so', 'es', 'es-419', 'su', + 'sw', 'sv', 'tg', 'ta', 'tt', 'te', 'th', 'ti', 'to', 'lua', 'tum', 'tr', 'tk', 'tw', + 'ug', 'uk', 'ur', 'uz', 'vu', 'vi', 'cy', 'wo', 'xh', 'yi', 'yo', 'zu'] + ) + + def get_input_form(self) -> dict[str, dict]: + return { + "q": { + "name": "Query", + "type": "line" + }, + "start": { + "name": "From", + "type": "integer", + "value": 0 + }, + "num": { + "name": "Limit", + "type": "integer", + "value": 12 + } + } + +class Google(ToolBase, ABC): + component_name = "Google" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 12))) + def _invoke(self, **kwargs): + if self.check_if_canceled("Google processing"): + return + + if not kwargs.get("q"): + self.set_output("formalized_content", "") + return "" + + params = { + "api_key": self._param.api_key, + "engine": "google", + "q": kwargs["q"], + "google_domain": "google.com", + "gl": self._param.country, + "hl": self._param.language + } + last_e = "" + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("Google processing"): + return + + try: + search = GoogleSearch(params).get_dict() + + if self.check_if_canceled("Google processing"): + return + + self._retrieve_chunks(search["organic_results"], + get_title=lambda r: r["title"], + get_url=lambda r: r["link"], + get_content=lambda r: r.get("about_this_result", {}).get("source", {}).get("description", r["snippet"]) + ) + self.set_output("json", search["organic_results"]) + return self.output("formalized_content") + except Exception as e: + if self.check_if_canceled("Google processing"): + return + + last_e = e + logging.exception(f"Google error: {e}") + time.sleep(self._param.delay_after_error) + + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"Google error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return """ +Keywords: {} +Looking for the most relevant articles. + """.format(self.get_input().get("query", "-_-!")) diff --git a/agent/tools/googlescholar.py b/agent/tools/googlescholar.py new file mode 100644 index 00000000000..b5c4eb395dd --- /dev/null +++ b/agent/tools/googlescholar.py @@ -0,0 +1,109 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import time +from abc import ABC +from scholarly import scholarly +from agent.tools.base import ToolMeta, ToolParamBase, ToolBase +from common.connection_utils import timeout + + +class GoogleScholarParam(ToolParamBase): + """ + Define the GoogleScholar component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "google_scholar_search", + "description": """Google Scholar provides a simple way to broadly search for scholarly literature. From one place, you can search across many disciplines and sources: articles, theses, books, abstracts and court opinions, from academic publishers, professional societies, online repositories, universities and other web sites. Google Scholar helps you find relevant work across the world of scholarly research.""", + "parameters": { + "query": { + "type": "string", + "description": "The search keyword to execute with Google Scholar. The keywords should be the most important words/terms(includes synonyms) from the original request.", + "default": "{sys.query}", + "required": True + } + } + } + super().__init__() + self.top_n = 12 + self.sort_by = 'relevance' + self.year_low = None + self.year_high = None + self.patents = True + + def check(self): + self.check_positive_integer(self.top_n, "Top N") + self.check_valid_value(self.sort_by, "GoogleScholar Sort_by", ['date', 'relevance']) + self.check_boolean(self.patents, "Whether or not to include patents, defaults to True") + + def get_input_form(self) -> dict[str, dict]: + return { + "query": { + "name": "Query", + "type": "line" + } + } + +class GoogleScholar(ToolBase, ABC): + component_name = "GoogleScholar" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 12))) + def _invoke(self, **kwargs): + if self.check_if_canceled("GoogleScholar processing"): + return + + if not kwargs.get("query"): + self.set_output("formalized_content", "") + return "" + + last_e = "" + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("GoogleScholar processing"): + return + + try: + scholar_client = scholarly.search_pubs(kwargs["query"], patents=self._param.patents, year_low=self._param.year_low, + year_high=self._param.year_high, sort_by=self._param.sort_by) + + if self.check_if_canceled("GoogleScholar processing"): + return + + self._retrieve_chunks(scholar_client, + get_title=lambda r: r['bib']['title'], + get_url=lambda r: r["pub_url"], + get_content=lambda r: "\n author: " + ",".join(r['bib']['author']) + '\n Abstract: ' + r['bib'].get('abstract', 'no abstract') + ) + self.set_output("json", list(scholar_client)) + return self.output("formalized_content") + except Exception as e: + if self.check_if_canceled("GoogleScholar processing"): + return + + last_e = e + logging.exception(f"GoogleScholar error: {e}") + time.sleep(self._param.delay_after_error) + + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"GoogleScholar error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return "Looking for scholarly papers on `{}`,” prioritising reputable sources.".format(self.get_input().get("query", "-_-!")) diff --git a/agent/component/jin10.py b/agent/tools/jin10.py similarity index 87% rename from agent/component/jin10.py rename to agent/tools/jin10.py index 583a1828653..b477dba81ed 100644 --- a/agent/component/jin10.py +++ b/agent/tools/jin10.py @@ -50,6 +50,9 @@ class Jin10(ComponentBase, ABC): component_name = "Jin10" def _run(self, history, **kwargs): + if self.check_if_canceled("Jin10 processing"): + return + ans = self.get_input() ans = " - ".join(ans["content"]) if "content" in ans else "" if not ans: @@ -58,6 +61,9 @@ def _run(self, history, **kwargs): jin10_res = [] headers = {'secret-key': self._param.secret_key} try: + if self.check_if_canceled("Jin10 processing"): + return + if self._param.type == "flash": params = { 'category': self._param.flash_type, @@ -69,6 +75,8 @@ def _run(self, history, **kwargs): headers=headers, data=json.dumps(params)) response = response.json() for i in response['data']: + if self.check_if_canceled("Jin10 processing"): + return jin10_res.append({"content": i['data']['content']}) if self._param.type == "calendar": params = { @@ -79,6 +87,8 @@ def _run(self, history, **kwargs): headers=headers, data=json.dumps(params)) response = response.json() + if self.check_if_canceled("Jin10 processing"): + return jin10_res.append({"content": pd.DataFrame(response['data']).to_markdown()}) if self._param.type == "symbols": params = { @@ -90,8 +100,12 @@ def _run(self, history, **kwargs): url='https://open-data-api.jin10.com/data-api/' + self._param.symbols_datatype + '?type=' + self._param.symbols_type, headers=headers, data=json.dumps(params)) response = response.json() + if self.check_if_canceled("Jin10 processing"): + return if self._param.symbols_datatype == "symbols": for i in response['data']: + if self.check_if_canceled("Jin10 processing"): + return i['Commodity Code'] = i['c'] i['Stock Exchange'] = i['e'] i['Commodity Name'] = i['n'] @@ -99,6 +113,8 @@ def _run(self, history, **kwargs): del i['c'], i['e'], i['n'], i['t'] if self._param.symbols_datatype == "quotes": for i in response['data']: + if self.check_if_canceled("Jin10 processing"): + return i['Selling Price'] = i['a'] i['Buying Price'] = i['b'] i['Commodity Code'] = i['c'] @@ -120,8 +136,12 @@ def _run(self, history, **kwargs): url='https://open-data-api.jin10.com/data-api/news', headers=headers, data=json.dumps(params)) response = response.json() + if self.check_if_canceled("Jin10 processing"): + return jin10_res.append({"content": pd.DataFrame(response['data']).to_markdown()}) except Exception as e: + if self.check_if_canceled("Jin10 processing"): + return return Jin10.be_output("**ERROR**: " + str(e)) if not jin10_res: diff --git a/agent/tools/pubmed.py b/agent/tools/pubmed.py new file mode 100644 index 00000000000..05c222810b0 --- /dev/null +++ b/agent/tools/pubmed.py @@ -0,0 +1,164 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import time +from abc import ABC +from Bio import Entrez +import re +import xml.etree.ElementTree as ET +from agent.tools.base import ToolParamBase, ToolMeta, ToolBase +from common.connection_utils import timeout + + +class PubMedParam(ToolParamBase): + """ + Define the PubMed component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "pubmed_search", + "description": """ +PubMed is an openly accessible, free database which includes primarily the MEDLINE database of references and abstracts on life sciences and biomedical topics. +In addition to MEDLINE, PubMed provides access to: + - older references from the print version of Index Medicus, back to 1951 and earlier + - references to some journals before they were indexed in Index Medicus and MEDLINE, for instance Science, BMJ, and Annals of Surgery + - very recent entries to records for an article before it is indexed with Medical Subject Headings (MeSH) and added to MEDLINE + - a collection of books available full-text and other subsets of NLM records[4] + - PMC citations + - NCBI Bookshelf + """, + "parameters": { + "query": { + "type": "string", + "description": "The search keywords to execute with PubMed. The keywords should be the most important words/terms(includes synonyms) from the original request.", + "default": "{sys.query}", + "required": True + } + } + } + super().__init__() + self.top_n = 12 + self.email = "A.N.Other@example.com" + + def check(self): + self.check_positive_integer(self.top_n, "Top N") + + def get_input_form(self) -> dict[str, dict]: + return { + "query": { + "name": "Query", + "type": "line" + } + } + +class PubMed(ToolBase, ABC): + component_name = "PubMed" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 12))) + def _invoke(self, **kwargs): + if self.check_if_canceled("PubMed processing"): + return + + if not kwargs.get("query"): + self.set_output("formalized_content", "") + return "" + + last_e = "" + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("PubMed processing"): + return + + try: + Entrez.email = self._param.email + pubmedids = Entrez.read(Entrez.esearch(db='pubmed', retmax=self._param.top_n, term=kwargs["query"]))['IdList'] + + if self.check_if_canceled("PubMed processing"): + return + + pubmedcnt = ET.fromstring(re.sub(r'<(/?)b>|<(/?)i>', '', Entrez.efetch(db='pubmed', id=",".join(pubmedids), + retmode="xml").read().decode("utf-8"))) + + if self.check_if_canceled("PubMed processing"): + return + + self._retrieve_chunks(pubmedcnt.findall("PubmedArticle"), + get_title=lambda child: child.find("MedlineCitation").find("Article").find("ArticleTitle").text, + get_url=lambda child: "https://pubmed.ncbi.nlm.nih.gov/" + child.find("MedlineCitation").find("PMID").text, + get_content=lambda child: self._format_pubmed_content(child),) + return self.output("formalized_content") + except Exception as e: + if self.check_if_canceled("PubMed processing"): + return + + last_e = e + logging.exception(f"PubMed error: {e}") + time.sleep(self._param.delay_after_error) + + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"PubMed error: {last_e}" + + assert False, self.output() + + def _format_pubmed_content(self, child): + """Extract structured reference info from PubMed XML""" + def safe_find(path): + node = child + for p in path.split("/"): + if node is None: + return None + node = node.find(p) + return node.text if node is not None and node.text else None + + title = safe_find("MedlineCitation/Article/ArticleTitle") or "No title" + abstract = safe_find("MedlineCitation/Article/Abstract/AbstractText") or "No abstract available" + journal = safe_find("MedlineCitation/Article/Journal/Title") or "Unknown Journal" + volume = safe_find("MedlineCitation/Article/Journal/JournalIssue/Volume") or "-" + issue = safe_find("MedlineCitation/Article/Journal/JournalIssue/Issue") or "-" + pages = safe_find("MedlineCitation/Article/Pagination/MedlinePgn") or "-" + + # Authors + authors = [] + for author in child.findall(".//AuthorList/Author"): + lastname = safe_find("LastName") or "" + forename = safe_find("ForeName") or "" + fullname = f"{forename} {lastname}".strip() + if fullname: + authors.append(fullname) + authors_str = ", ".join(authors) if authors else "Unknown Authors" + + # DOI + doi = None + for eid in child.findall(".//ArticleId"): + if eid.attrib.get("IdType") == "doi": + doi = eid.text + break + + return ( + f"Title: {title}\n" + f"Authors: {authors_str}\n" + f"Journal: {journal}\n" + f"Volume: {volume}\n" + f"Issue: {issue}\n" + f"Pages: {pages}\n" + f"DOI: {doi or '-'}\n" + f"Abstract: {abstract.strip()}" + ) + + def thoughts(self) -> str: + return "Looking for scholarly papers on `{}`,” prioritising reputable sources.".format(self.get_input().get("query", "-_-!")) diff --git a/agent/component/qweather.py b/agent/tools/qweather.py similarity index 88% rename from agent/component/qweather.py rename to agent/tools/qweather.py index 2c38a8b7e15..a597c2c5b88 100644 --- a/agent/component/qweather.py +++ b/agent/tools/qweather.py @@ -58,12 +58,18 @@ class QWeather(ComponentBase, ABC): component_name = "QWeather" def _run(self, history, **kwargs): + if self.check_if_canceled("Qweather processing"): + return + ans = self.get_input() ans = "".join(ans["content"]) if "content" in ans else "" if not ans: return QWeather.be_output("") try: + if self.check_if_canceled("Qweather processing"): + return + response = requests.get( url="https://geoapi.qweather.com/v2/city/lookup?location=" + ans + "&key=" + self._param.web_apikey).json() if response["code"] == "200": @@ -71,16 +77,23 @@ def _run(self, history, **kwargs): else: return QWeather.be_output("**Error**" + self._param.error_code[response["code"]]) + if self.check_if_canceled("Qweather processing"): + return + base_url = "https://api.qweather.com/v7/" if self._param.user_type == 'paid' else "https://devapi.qweather.com/v7/" if self._param.type == "weather": url = base_url + "weather/" + self._param.time_period + "?location=" + location_id + "&key=" + self._param.web_apikey + "&lang=" + self._param.lang response = requests.get(url=url).json() + if self.check_if_canceled("Qweather processing"): + return if response["code"] == "200": if self._param.time_period == "now": return QWeather.be_output(str(response["now"])) else: qweather_res = [{"content": str(i) + "\n"} for i in response["daily"]] + if self.check_if_canceled("Qweather processing"): + return if not qweather_res: return QWeather.be_output("") @@ -92,6 +105,8 @@ def _run(self, history, **kwargs): elif self._param.type == "indices": url = base_url + "indices/1d?type=0&location=" + location_id + "&key=" + self._param.web_apikey + "&lang=" + self._param.lang response = requests.get(url=url).json() + if self.check_if_canceled("Qweather processing"): + return if response["code"] == "200": indices_res = response["daily"][0]["date"] + "\n" + "\n".join( [i["name"] + ": " + i["category"] + ", " + i["text"] for i in response["daily"]]) @@ -103,9 +118,13 @@ def _run(self, history, **kwargs): elif self._param.type == "airquality": url = base_url + "air/now?location=" + location_id + "&key=" + self._param.web_apikey + "&lang=" + self._param.lang response = requests.get(url=url).json() + if self.check_if_canceled("Qweather processing"): + return if response["code"] == "200": return QWeather.be_output(str(response["now"])) else: return QWeather.be_output("**Error**" + self._param.error_code[response["code"]]) except Exception as e: + if self.check_if_canceled("Qweather processing"): + return return QWeather.be_output("**Error**" + str(e)) diff --git a/agent/tools/retrieval.py b/agent/tools/retrieval.py new file mode 100644 index 00000000000..ab388a08ee3 --- /dev/null +++ b/agent/tools/retrieval.py @@ -0,0 +1,249 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from functools import partial +import json +import os +import re +from abc import ABC +from agent.tools.base import ToolParamBase, ToolBase, ToolMeta +from common.constants import LLMType +from api.db.services.document_service import DocumentService +from api.db.services.dialog_service import meta_filter +from api.db.services.knowledgebase_service import KnowledgebaseService +from api.db.services.llm_service import LLMBundle +from common import settings +from common.connection_utils import timeout +from rag.app.tag import label_question +from rag.prompts.generator import cross_languages, kb_prompt, gen_meta_filter + + +class RetrievalParam(ToolParamBase): + """ + Define the Retrieval component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "search_my_dateset", + "description": "This tool can be utilized for relevant content searching in the datasets.", + "parameters": { + "query": { + "type": "string", + "description": "The keywords to search the dataset. The keywords should be the most important words/terms(includes synonyms) from the original request.", + "default": "", + "required": True + } + } + } + super().__init__() + self.function_name = "search_my_dateset" + self.description = "This tool can be utilized for relevant content searching in the datasets." + self.similarity_threshold = 0.2 + self.keywords_similarity_weight = 0.5 + self.top_n = 8 + self.top_k = 1024 + self.kb_ids = [] + self.kb_vars = [] + self.rerank_id = "" + self.empty_response = "" + self.use_kg = False + self.cross_languages = [] + self.toc_enhance = False + self.meta_data_filter={} + + def check(self): + self.check_decimal_float(self.similarity_threshold, "[Retrieval] Similarity threshold") + self.check_decimal_float(self.keywords_similarity_weight, "[Retrieval] Keyword similarity weight") + self.check_positive_number(self.top_n, "[Retrieval] Top N") + + def get_input_form(self) -> dict[str, dict]: + return { + "query": { + "name": "Query", + "type": "line" + } + } + +class Retrieval(ToolBase, ABC): + component_name = "Retrieval" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 12))) + def _invoke(self, **kwargs): + if self.check_if_canceled("Retrieval processing"): + return + + if not kwargs.get("query"): + self.set_output("formalized_content", self._param.empty_response) + return + + kb_ids: list[str] = [] + for id in self._param.kb_ids: + if id.find("@") < 0: + kb_ids.append(id) + continue + kb_nm = self._canvas.get_variable_value(id) + # if kb_nm is a list + kb_nm_list = kb_nm if isinstance(kb_nm, list) else [kb_nm] + for nm_or_id in kb_nm_list: + e, kb = KnowledgebaseService.get_by_name(nm_or_id, + self._canvas._tenant_id) + if not e: + e, kb = KnowledgebaseService.get_by_id(nm_or_id) + if not e: + raise Exception(f"Dataset({nm_or_id}) does not exist.") + kb_ids.append(kb.id) + + filtered_kb_ids: list[str] = list(set([kb_id for kb_id in kb_ids if kb_id])) + + kbs = KnowledgebaseService.get_by_ids(filtered_kb_ids) + if not kbs: + raise Exception("No dataset is selected.") + + embd_nms = list(set([kb.embd_id for kb in kbs])) + assert len(embd_nms) == 1, "Knowledge bases use different embedding models." + + embd_mdl = None + if embd_nms: + embd_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.EMBEDDING, embd_nms[0]) + + rerank_mdl = None + if self._param.rerank_id: + rerank_mdl = LLMBundle(kbs[0].tenant_id, LLMType.RERANK, self._param.rerank_id) + + vars = self.get_input_elements_from_text(kwargs["query"]) + vars = {k:o["value"] for k,o in vars.items()} + query = self.string_format(kwargs["query"], vars) + + doc_ids=[] + if self._param.meta_data_filter!={}: + metas = DocumentService.get_meta_by_kbs(kb_ids) + if self._param.meta_data_filter.get("method") == "auto": + chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT) + filters = gen_meta_filter(chat_mdl, metas, query) + doc_ids.extend(meta_filter(metas, filters)) + if not doc_ids: + doc_ids = None + elif self._param.meta_data_filter.get("method") == "manual": + filters=self._param.meta_data_filter["manual"] + for flt in filters: + pat = re.compile(self.variable_ref_patt) + s = flt["value"] + out_parts = [] + last = 0 + + for m in pat.finditer(s): + out_parts.append(s[last:m.start()]) + key = m.group(1) + v = self._canvas.get_variable_value(key) + if v is None: + rep = "" + elif isinstance(v, partial): + buf = [] + for chunk in v(): + buf.append(chunk) + rep = "".join(buf) + elif isinstance(v, str): + rep = v + else: + rep = json.dumps(v, ensure_ascii=False) + + out_parts.append(rep) + last = m.end() + + out_parts.append(s[last:]) + flt["value"] = "".join(out_parts) + doc_ids.extend(meta_filter(metas, filters)) + if not doc_ids: + doc_ids = None + + if self._param.cross_languages: + query = cross_languages(kbs[0].tenant_id, None, query, self._param.cross_languages) + + if kbs: + query = re.sub(r"^user[::\s]*", "", query, flags=re.IGNORECASE) + kbinfos = settings.retriever.retrieval( + query, + embd_mdl, + [kb.tenant_id for kb in kbs], + filtered_kb_ids, + 1, + self._param.top_n, + self._param.similarity_threshold, + 1 - self._param.keywords_similarity_weight, + doc_ids=doc_ids, + aggs=False, + rerank_mdl=rerank_mdl, + rank_feature=label_question(query, kbs), + ) + if self.check_if_canceled("Retrieval processing"): + return + + if self._param.toc_enhance: + chat_mdl = LLMBundle(self._canvas._tenant_id, LLMType.CHAT) + cks = settings.retriever.retrieval_by_toc(query, kbinfos["chunks"], [kb.tenant_id for kb in kbs], chat_mdl, self._param.top_n) + if self.check_if_canceled("Retrieval processing"): + return + if cks: + kbinfos["chunks"] = cks + if self._param.use_kg: + ck = settings.kg_retriever.retrieval(query, + [kb.tenant_id for kb in kbs], + kb_ids, + embd_mdl, + LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT)) + if self.check_if_canceled("Retrieval processing"): + return + if ck["content_with_weight"]: + kbinfos["chunks"].insert(0, ck) + else: + kbinfos = {"chunks": [], "doc_aggs": []} + + if self._param.use_kg and kbs: + ck = settings.kg_retriever.retrieval(query, [kb.tenant_id for kb in kbs], filtered_kb_ids, embd_mdl, LLMBundle(kbs[0].tenant_id, LLMType.CHAT)) + if self.check_if_canceled("Retrieval processing"): + return + if ck["content_with_weight"]: + ck["content"] = ck["content_with_weight"] + del ck["content_with_weight"] + kbinfos["chunks"].insert(0, ck) + + for ck in kbinfos["chunks"]: + if "vector" in ck: + del ck["vector"] + if "content_ltks" in ck: + del ck["content_ltks"] + + if not kbinfos["chunks"]: + self.set_output("formalized_content", self._param.empty_response) + return + + # Format the chunks for JSON output (similar to how other tools do it) + json_output = kbinfos["chunks"].copy() + + self._canvas.add_reference(kbinfos["chunks"], kbinfos["doc_aggs"]) + form_cnt = "\n".join(kb_prompt(kbinfos, 200000, True)) + + # Set both formalized content and JSON output + self.set_output("formalized_content", form_cnt) + self.set_output("json", json_output) + + return form_cnt + + def thoughts(self) -> str: + return """ +Keywords: {} +Looking for the most relevant articles. + """.format(self.get_input().get("query", "-_-!")) diff --git a/agent/tools/searxng.py b/agent/tools/searxng.py new file mode 100644 index 00000000000..fdc7bea525c --- /dev/null +++ b/agent/tools/searxng.py @@ -0,0 +1,169 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import time +from abc import ABC +import requests +from agent.tools.base import ToolMeta, ToolParamBase, ToolBase +from common.connection_utils import timeout + + +class SearXNGParam(ToolParamBase): + """ + Define the SearXNG component parameters. + """ + + def __init__(self): + self.meta: ToolMeta = { + "name": "searxng_search", + "description": "SearXNG is a privacy-focused metasearch engine that aggregates results from multiple search engines without tracking users. It provides comprehensive web search capabilities.", + "parameters": { + "query": { + "type": "string", + "description": "The search keywords to execute with SearXNG. The keywords should be the most important words/terms(includes synonyms) from the original request.", + "default": "{sys.query}", + "required": True + }, + "searxng_url": { + "type": "string", + "description": "The base URL of your SearXNG instance (e.g., http://localhost:4000). This is required to connect to your SearXNG server.", + "required": False, + "default": "" + } + } + } + super().__init__() + self.top_n = 10 + self.searxng_url = "" + + def check(self): + # Keep validation lenient so opening try-run panel won't fail without URL. + # Coerce top_n to int if it comes as string from UI. + try: + if isinstance(self.top_n, str): + self.top_n = int(self.top_n.strip()) + except Exception: + pass + self.check_positive_integer(self.top_n, "Top N") + + def get_input_form(self) -> dict[str, dict]: + return { + "query": { + "name": "Query", + "type": "line" + }, + "searxng_url": { + "name": "SearXNG URL", + "type": "line", + "placeholder": "http://localhost:4000" + } + } + + +class SearXNG(ToolBase, ABC): + component_name = "SearXNG" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 12))) + def _invoke(self, **kwargs): + if self.check_if_canceled("SearXNG processing"): + return + + # Gracefully handle try-run without inputs + query = kwargs.get("query") + if not query or not isinstance(query, str) or not query.strip(): + self.set_output("formalized_content", "") + return "" + + searxng_url = (getattr(self._param, "searxng_url", "") or kwargs.get("searxng_url") or "").strip() + # In try-run, if no URL configured, just return empty instead of raising + if not searxng_url: + self.set_output("formalized_content", "") + return "" + + last_e = "" + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("SearXNG processing"): + return + + try: + search_params = { + 'q': query, + 'format': 'json', + 'categories': 'general', + 'language': 'auto', + 'safesearch': 1, + 'pageno': 1 + } + + response = requests.get( + f"{searxng_url}/search", + params=search_params, + timeout=10 + ) + response.raise_for_status() + + if self.check_if_canceled("SearXNG processing"): + return + + data = response.json() + + if not data or not isinstance(data, dict): + raise ValueError("Invalid response from SearXNG") + + results = data.get("results", []) + if not isinstance(results, list): + raise ValueError("Invalid results format from SearXNG") + + results = results[:self._param.top_n] + + if self.check_if_canceled("SearXNG processing"): + return + + self._retrieve_chunks(results, + get_title=lambda r: r.get("title", ""), + get_url=lambda r: r.get("url", ""), + get_content=lambda r: r.get("content", "")) + + self.set_output("json", results) + return self.output("formalized_content") + + except requests.RequestException as e: + if self.check_if_canceled("SearXNG processing"): + return + + last_e = f"Network error: {e}" + logging.exception(f"SearXNG network error: {e}") + time.sleep(self._param.delay_after_error) + except Exception as e: + if self.check_if_canceled("SearXNG processing"): + return + + last_e = str(e) + logging.exception(f"SearXNG error: {e}") + time.sleep(self._param.delay_after_error) + + if last_e: + self.set_output("_ERROR", last_e) + return f"SearXNG error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return """ +Keywords: {} +Searching with SearXNG for relevant results... + """.format(self.get_input().get("query", "-_-!")) diff --git a/agent/tools/tavily.py b/agent/tools/tavily.py new file mode 100644 index 00000000000..1f1fa013754 --- /dev/null +++ b/agent/tools/tavily.py @@ -0,0 +1,251 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import time +from abc import ABC +from tavily import TavilyClient +from agent.tools.base import ToolParamBase, ToolBase, ToolMeta +from common.connection_utils import timeout + + +class TavilySearchParam(ToolParamBase): + """ + Define the Retrieval component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "tavily_search", + "description": """ +Tavily is a search engine optimized for LLMs, aimed at efficient, quick and persistent search results. +When searching: + - Start with specific query which should focus on just a single aspect. + - Number of keywords in query should be less than 5. + - Broaden search terms if needed + - Cross-reference information from multiple sources + """, + "parameters": { + "query": { + "type": "string", + "description": "The search keywords to execute with Tavily. The keywords should be the most important words/terms(includes synonyms) from the original request.", + "default": "{sys.query}", + "required": True + }, + "topic": { + "type": "string", + "description": "default:general. The category of the search.news is useful for retrieving real-time updates, particularly about politics, sports, and major current events covered by mainstream media sources. general is for broader, more general-purpose searches that may include a wide range of sources.", + "enum": ["general", "news"], + "default": "general", + "required": False, + }, + "include_domains": { + "type": "array", + "description": "default:[]. A list of domains only from which the search results can be included.", + "default": [], + "items": { + "type": "string", + "description": "Domain name that must be included, e.g. www.yahoo.com" + }, + "required": False + }, + "exclude_domains": { + "type": "array", + "description": "default:[]. A list of domains from which the search results can not be included", + "default": [], + "items": { + "type": "string", + "description": "Domain name that must be excluded, e.g. www.yahoo.com" + }, + "required": False + }, + } + } + super().__init__() + self.api_key = "" + self.search_depth = "basic" # basic/advanced + self.max_results = 6 + self.days = 14 + self.include_answer = False + self.include_raw_content = False + self.include_images = False + self.include_image_descriptions = False + + def check(self): + self.check_valid_value(self.topic, "Tavily topic: should be in 'general/news'", ["general", "news"]) + self.check_valid_value(self.search_depth, "Tavily search depth should be in 'basic/advanced'", ["basic", "advanced"]) + self.check_positive_integer(self.max_results, "Tavily max result number should be within [1, 20]") + self.check_positive_integer(self.days, "Tavily days should be greater than 1") + + def get_input_form(self) -> dict[str, dict]: + return { + "query": { + "name": "Query", + "type": "line" + } + } + +class TavilySearch(ToolBase, ABC): + component_name = "TavilySearch" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 12))) + def _invoke(self, **kwargs): + if self.check_if_canceled("TavilySearch processing"): + return + + if not kwargs.get("query"): + self.set_output("formalized_content", "") + return "" + + self.tavily_client = TavilyClient(api_key=self._param.api_key) + last_e = None + for fld in ["search_depth", "topic", "max_results", "days", "include_answer", "include_raw_content", "include_images", "include_image_descriptions", "include_domains", "exclude_domains"]: + if fld not in kwargs: + kwargs[fld] = getattr(self._param, fld) + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("TavilySearch processing"): + return + + try: + kwargs["include_images"] = False + kwargs["include_raw_content"] = False + res = self.tavily_client.search(**kwargs) + if self.check_if_canceled("TavilySearch processing"): + return + + self._retrieve_chunks(res["results"], + get_title=lambda r: r["title"], + get_url=lambda r: r["url"], + get_content=lambda r: r["raw_content"] if r["raw_content"] else r["content"], + get_score=lambda r: r["score"]) + self.set_output("json", res["results"]) + return self.output("formalized_content") + except Exception as e: + if self.check_if_canceled("TavilySearch processing"): + return + + last_e = e + logging.exception(f"Tavily error: {e}") + time.sleep(self._param.delay_after_error) + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"Tavily error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return """ +Keywords: {} +Looking for the most relevant articles. + """.format(self.get_input().get("query", "-_-!")) + + +class TavilyExtractParam(ToolParamBase): + """ + Define the Retrieval component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "tavily_extract", + "description": "Extract web page content from one or more specified URLs using Tavily Extract.", + "parameters": { + "urls": { + "type": "array", + "description": "The URLs to extract content from.", + "default": "", + "items": { + "type": "string", + "description": "The URL to extract content from, e.g. www.yahoo.com" + }, + "required": True + }, + "extract_depth": { + "type": "string", + "description": "The depth of the extraction process. advanced extraction retrieves more data, including tables and embedded content, with higher success but may increase latency.basic extraction costs 1 credit per 5 successful URL extractions, while advanced extraction costs 2 credits per 5 successful URL extractions.", + "enum": ["basic", "advanced"], + "default": "basic", + "required": False, + }, + "format": { + "type": "string", + "description": "The format of the extracted web page content. markdown returns content in markdown format. text returns plain text and may increase latency.", + "enum": ["markdown", "text"], + "default": "markdown", + "required": False, + } + } + } + super().__init__() + self.api_key = "" + self.extract_depth = "basic" # basic/advanced + self.urls = [] + self.format = "markdown" + self.include_images = False + + def check(self): + self.check_valid_value(self.extract_depth, "Tavily extract depth should be in 'basic/advanced'", ["basic", "advanced"]) + self.check_valid_value(self.format, "Tavily extract format should be in 'markdown/text'", ["markdown", "text"]) + + def get_input_form(self) -> dict[str, dict]: + return { + "urls": { + "name": "URLs", + "type": "line" + } + } + +class TavilyExtract(ToolBase, ABC): + component_name = "TavilyExtract" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 10*60))) + def _invoke(self, **kwargs): + if self.check_if_canceled("TavilyExtract processing"): + return + + self.tavily_client = TavilyClient(api_key=self._param.api_key) + last_e = None + for fld in ["urls", "extract_depth", "format"]: + if fld not in kwargs: + kwargs[fld] = getattr(self._param, fld) + if kwargs.get("urls") and isinstance(kwargs["urls"], str): + kwargs["urls"] = kwargs["urls"].split(",") + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("TavilyExtract processing"): + return + + try: + kwargs["include_images"] = False + res = self.tavily_client.extract(**kwargs) + if self.check_if_canceled("TavilyExtract processing"): + return + + self.set_output("json", res["results"]) + return self.output("json") + except Exception as e: + if self.check_if_canceled("TavilyExtract processing"): + return + + last_e = e + logging.exception(f"Tavily error: {e}") + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"Tavily error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return "Opened {}—pulling out the main text…".format(self.get_input().get("urls", "-_-!")) diff --git a/agent/component/tushare.py b/agent/tools/tushare.py similarity index 86% rename from agent/component/tushare.py rename to agent/tools/tushare.py index bb9d34fe9f1..6a0d0c2a349 100644 --- a/agent/component/tushare.py +++ b/agent/tools/tushare.py @@ -43,12 +43,18 @@ class TuShare(ComponentBase, ABC): component_name = "TuShare" def _run(self, history, **kwargs): + if self.check_if_canceled("TuShare processing"): + return + ans = self.get_input() ans = ",".join(ans["content"]) if "content" in ans else "" if not ans: return TuShare.be_output("") try: + if self.check_if_canceled("TuShare processing"): + return + tus_res = [] params = { "api_name": "news", @@ -58,12 +64,18 @@ def _run(self, history, **kwargs): } response = requests.post(url="http://api.tushare.pro", data=json.dumps(params).encode('utf-8')) response = response.json() + if self.check_if_canceled("TuShare processing"): + return if response['code'] != 0: return TuShare.be_output(response['msg']) df = pd.DataFrame(response['data']['items']) df.columns = response['data']['fields'] + if self.check_if_canceled("TuShare processing"): + return tus_res.append({"content": (df[df['content'].str.contains(self._param.keyword, case=False)]).to_markdown()}) except Exception as e: + if self.check_if_canceled("TuShare processing"): + return return TuShare.be_output("**ERROR**: " + str(e)) if not tus_res: diff --git a/agent/tools/wencai.py b/agent/tools/wencai.py new file mode 100644 index 00000000000..998e27a1d01 --- /dev/null +++ b/agent/tools/wencai.py @@ -0,0 +1,129 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import time +from abc import ABC +import pandas as pd +import pywencai + +from agent.tools.base import ToolParamBase, ToolMeta, ToolBase +from common.connection_utils import timeout + + +class WenCaiParam(ToolParamBase): + """ + Define the WenCai component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "iwencai", + "description": """ +iwencai search: search platform is committed to providing hundreds of millions of investors with the most timely, accurate and comprehensive information, covering news, announcements, research reports, blogs, forums, Weibo, characters, etc. +robo-advisor intelligent stock selection platform: through AI technology, is committed to providing investors with intelligent stock selection, quantitative investment, main force tracking, value investment, technical analysis and other types of stock selection technologies. +fund selection platform: through AI technology, is committed to providing excellent fund, value investment, quantitative analysis and other fund selection technologies for foundation citizens. +""", + "parameters": { + "query": { + "type": "string", + "description": "The question/conditions to select stocks.", + "default": "{sys.query}", + "required": True + } + } + } + super().__init__() + self.top_n = 10 + self.query_type = "stock" + + def check(self): + self.check_positive_integer(self.top_n, "Top N") + self.check_valid_value(self.query_type, "Query type", + ['stock', 'zhishu', 'fund', 'hkstock', 'usstock', 'threeboard', 'conbond', 'insurance', + 'futures', 'lccp', + 'foreign_exchange']) + + def get_input_form(self) -> dict[str, dict]: + return { + "query": { + "name": "Query", + "type": "line" + } + } + +class WenCai(ToolBase, ABC): + component_name = "WenCai" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 12))) + def _invoke(self, **kwargs): + if self.check_if_canceled("WenCai processing"): + return + + if not kwargs.get("query"): + self.set_output("report", "") + return "" + + last_e = "" + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("WenCai processing"): + return + + try: + wencai_res = [] + res = pywencai.get(query=kwargs["query"], query_type=self._param.query_type, perpage=self._param.top_n) + if self.check_if_canceled("WenCai processing"): + return + + if isinstance(res, pd.DataFrame): + wencai_res.append(res.to_markdown()) + elif isinstance(res, dict): + for item in res.items(): + if self.check_if_canceled("WenCai processing"): + return + + if isinstance(item[1], list): + wencai_res.append(item[0] + "\n" + pd.DataFrame(item[1]).to_markdown()) + elif isinstance(item[1], str): + wencai_res.append(item[0] + "\n" + item[1]) + elif isinstance(item[1], dict): + if "meta" in item[1].keys(): + continue + wencai_res.append(pd.DataFrame.from_dict(item[1], orient='index').to_markdown()) + elif isinstance(item[1], pd.DataFrame): + if "image_url" in item[1].columns: + continue + wencai_res.append(item[1].to_markdown()) + else: + wencai_res.append(item[0] + "\n" + str(item[1])) + self.set_output("report", "\n\n".join(wencai_res)) + return self.output("report") + except Exception as e: + if self.check_if_canceled("WenCai processing"): + return + + last_e = e + logging.exception(f"WenCai error: {e}") + time.sleep(self._param.delay_after_error) + + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"WenCai error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return "Pulling live financial data for `{}`.".format(self.get_input().get("query", "-_-!")) diff --git a/agent/tools/wikipedia.py b/agent/tools/wikipedia.py new file mode 100644 index 00000000000..8e0b9c3fe62 --- /dev/null +++ b/agent/tools/wikipedia.py @@ -0,0 +1,116 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import time +from abc import ABC +import wikipedia +from agent.tools.base import ToolMeta, ToolParamBase, ToolBase +from common.connection_utils import timeout + + +class WikipediaParam(ToolParamBase): + """ + Define the Wikipedia component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "wikipedia_search", + "description": """A wide range of how-to and information pages are made available in wikipedia. Since 2001, it has grown rapidly to become the world's largest reference website. From Wikipedia, the free encyclopedia.""", + "parameters": { + "query": { + "type": "string", + "description": "The search keyword to execute with wikipedia. The keyword MUST be a specific subject that can match the title.", + "default": "{sys.query}", + "required": True + } + } + } + super().__init__() + self.top_n = 10 + self.language = "en" + + def check(self): + self.check_positive_integer(self.top_n, "Top N") + self.check_valid_value(self.language, "Wikipedia languages", + ['af', 'pl', 'ar', 'ast', 'az', 'bg', 'nan', 'bn', 'be', 'ca', 'cs', 'cy', 'da', 'de', + 'et', 'el', 'en', 'es', 'eo', 'eu', 'fa', 'fr', 'gl', 'ko', 'hy', 'hi', 'hr', 'id', + 'it', 'he', 'ka', 'lld', 'la', 'lv', 'lt', 'hu', 'mk', 'arz', 'ms', 'min', 'my', 'nl', + 'ja', 'nb', 'nn', 'ce', 'uz', 'pt', 'kk', 'ro', 'ru', 'ceb', 'sk', 'sl', 'sr', 'sh', + 'fi', 'sv', 'ta', 'tt', 'th', 'tg', 'azb', 'tr', 'uk', 'ur', 'vi', 'war', 'zh', 'yue']) + + def get_input_form(self) -> dict[str, dict]: + return { + "query": { + "name": "Query", + "type": "line" + } + } + +class Wikipedia(ToolBase, ABC): + component_name = "Wikipedia" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 60))) + def _invoke(self, **kwargs): + if self.check_if_canceled("Wikipedia processing"): + return + + if not kwargs.get("query"): + self.set_output("formalized_content", "") + return "" + + last_e = "" + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("Wikipedia processing"): + return + + try: + wikipedia.set_lang(self._param.language) + wiki_engine = wikipedia + pages = [] + for p in wiki_engine.search(kwargs["query"], results=self._param.top_n): + if self.check_if_canceled("Wikipedia processing"): + return + + try: + pages.append(wikipedia.page(p)) + except Exception: + pass + self._retrieve_chunks(pages, + get_title=lambda r: r.title, + get_url=lambda r: r.url, + get_content=lambda r: r.summary) + return self.output("formalized_content") + except Exception as e: + if self.check_if_canceled("Wikipedia processing"): + return + + last_e = e + logging.exception(f"Wikipedia error: {e}") + time.sleep(self._param.delay_after_error) + + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"Wikipedia error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return """ +Keywords: {} +Looking for the most relevant articles. + """.format(self.get_input().get("query", "-_-!")) diff --git a/agent/tools/yahoofinance.py b/agent/tools/yahoofinance.py new file mode 100644 index 00000000000..324dfb64308 --- /dev/null +++ b/agent/tools/yahoofinance.py @@ -0,0 +1,126 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import os +import time +from abc import ABC +import pandas as pd +import yfinance as yf +from agent.tools.base import ToolMeta, ToolParamBase, ToolBase +from common.connection_utils import timeout + + +class YahooFinanceParam(ToolParamBase): + """ + Define the YahooFinance component parameters. + """ + + def __init__(self): + self.meta:ToolMeta = { + "name": "yahoo_finance", + "description": "The Yahoo Finance is a service that provides access to real-time and historical stock market data. It enables users to fetch various types of stock information, such as price quotes, historical prices, company profiles, and financial news. The API offers structured data, allowing developers to integrate market data into their applications and analysis tools.", + "parameters": { + "stock_code": { + "type": "string", + "description": "The stock code or company name.", + "default": "{sys.query}", + "required": True + } + } + } + super().__init__() + self.info = True + self.history = False + self.count = False + self.financials = False + self.income_stmt = False + self.balance_sheet = False + self.cash_flow_statement = False + self.news = True + + def check(self): + self.check_boolean(self.info, "get all stock info") + self.check_boolean(self.history, "get historical market data") + self.check_boolean(self.count, "show share count") + self.check_boolean(self.financials, "show financials") + self.check_boolean(self.income_stmt, "income statement") + self.check_boolean(self.balance_sheet, "balance sheet") + self.check_boolean(self.cash_flow_statement, "cash flow statement") + self.check_boolean(self.news, "show news") + + def get_input_form(self) -> dict[str, dict]: + return { + "stock_code": { + "name": "Stock code/Company name", + "type": "line" + } + } + +class YahooFinance(ToolBase, ABC): + component_name = "YahooFinance" + + @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 60))) + def _invoke(self, **kwargs): + if self.check_if_canceled("YahooFinance processing"): + return + + if not kwargs.get("stock_code"): + self.set_output("report", "") + return "" + + last_e = "" + for _ in range(self._param.max_retries+1): + if self.check_if_canceled("YahooFinance processing"): + return + + yohoo_res = [] + try: + msft = yf.Ticker(kwargs["stock_code"]) + if self.check_if_canceled("YahooFinance processing"): + return + + if self._param.info: + yohoo_res.append("# Information:\n" + pd.Series(msft.info).to_markdown() + "\n") + if self._param.history: + yohoo_res.append("# History:\n" + msft.history().to_markdown() + "\n") + if self._param.financials: + yohoo_res.append("# Calendar:\n" + pd.DataFrame(msft.calendar).to_markdown() + "\n") + if self._param.balance_sheet: + yohoo_res.append("# Balance sheet:\n" + msft.balance_sheet.to_markdown() + "\n") + yohoo_res.append("# Quarterly balance sheet:\n" + msft.quarterly_balance_sheet.to_markdown() + "\n") + if self._param.cash_flow_statement: + yohoo_res.append("# Cash flow statement:\n" + msft.cashflow.to_markdown() + "\n") + yohoo_res.append("# Quarterly cash flow statement:\n" + msft.quarterly_cashflow.to_markdown() + "\n") + if self._param.news: + yohoo_res.append("# News:\n" + pd.DataFrame(msft.news).to_markdown() + "\n") + self.set_output("report", "\n\n".join(yohoo_res)) + return self.output("report") + except Exception as e: + if self.check_if_canceled("YahooFinance processing"): + return + + last_e = e + logging.exception(f"YahooFinance error: {e}") + time.sleep(self._param.delay_after_error) + + if last_e: + self.set_output("_ERROR", str(last_e)) + return f"YahooFinance error: {last_e}" + + assert False, self.output() + + def thoughts(self) -> str: + return "Pulling live financial data for `{}`.".format(self.get_input().get("stock_code", "-_-!")) diff --git a/agentic_reasoning/prompts.py b/agentic_reasoning/prompts.py index 715896b86f8..8bf101b291a 100644 --- a/agentic_reasoning/prompts.py +++ b/agentic_reasoning/prompts.py @@ -20,94 +20,128 @@ END_SEARCH_RESULT = "<|end_search_result|>" MAX_SEARCH_LIMIT = 6 -REASON_PROMPT = ( - "You are a reasoning assistant with the ability to perform dataset searches to help " - "you answer the user's question accurately. You have special tools:\n\n" - f"- To perform a search: write {BEGIN_SEARCH_QUERY} your query here {END_SEARCH_QUERY}.\n" - f"Then, the system will search and analyze relevant content, then provide you with helpful information in the format {BEGIN_SEARCH_RESULT} ...search results... {END_SEARCH_RESULT}.\n\n" - f"You can repeat the search process multiple times if necessary. The maximum number of search attempts is limited to {MAX_SEARCH_LIMIT}.\n\n" - "Once you have all the information you need, continue your reasoning.\n\n" - "-- Example 1 --\n" ######################################## - "Question: \"Are both the directors of Jaws and Casino Royale from the same country?\"\n" - "Assistant:\n" - f" {BEGIN_SEARCH_QUERY}Who is the director of Jaws?{END_SEARCH_QUERY}\n\n" - "User:\n" - f" {BEGIN_SEARCH_RESULT}\nThe director of Jaws is Steven Spielberg...\n{END_SEARCH_RESULT}\n\n" - "Continues reasoning with the new information.\n" - "Assistant:\n" - f" {BEGIN_SEARCH_QUERY}Where is Steven Spielberg from?{END_SEARCH_QUERY}\n\n" - "User:\n" - f" {BEGIN_SEARCH_RESULT}\nSteven Allan Spielberg is an American filmmaker...\n{END_SEARCH_RESULT}\n\n" - "Continues reasoning with the new information...\n\n" - "Assistant:\n" - f" {BEGIN_SEARCH_QUERY}Who is the director of Casino Royale?{END_SEARCH_QUERY}\n\n" - "User:\n" - f" {BEGIN_SEARCH_RESULT}\nCasino Royale is a 2006 spy film directed by Martin Campbell...\n{END_SEARCH_RESULT}\n\n" - "Continues reasoning with the new information...\n\n" - "Assistant:\n" - f" {BEGIN_SEARCH_QUERY}Where is Martin Campbell from?{END_SEARCH_QUERY}\n\n" - "User:\n" - f" {BEGIN_SEARCH_RESULT}\nMartin Campbell (born 24 October 1943) is a New Zealand film and television director...\n{END_SEARCH_RESULT}\n\n" - "Continues reasoning with the new information...\n\n" - "Assistant:\nIt's enough to answer the question\n" - - "-- Example 2 --\n" ######################################### - "Question: \"When was the founder of craigslist born?\"\n" - "Assistant:\n" - f" {BEGIN_SEARCH_QUERY}Who was the founder of craigslist?{END_SEARCH_QUERY}\n\n" - "User:\n" - f" {BEGIN_SEARCH_RESULT}\nCraigslist was founded by Craig Newmark...\n{END_SEARCH_RESULT}\n\n" - "Continues reasoning with the new information.\n" - "Assistant:\n" - f" {BEGIN_SEARCH_QUERY} When was Craig Newmark born?{END_SEARCH_QUERY}\n\n" - "User:\n" - f" {BEGIN_SEARCH_RESULT}\nCraig Newmark was born on December 6, 1952...\n{END_SEARCH_RESULT}\n\n" - "Continues reasoning with the new information...\n\n" - "Assistant:\nIt's enough to answer the question\n" - "**Remember**:\n" - f"- You have a dataset to search, so you just provide a proper search query.\n" - f"- Use {BEGIN_SEARCH_QUERY} to request a dataset search and end with {END_SEARCH_QUERY}.\n" - "- The language of query MUST be as the same as 'Question' or 'search result'.\n" - "- If no helpful information can be found, rewrite the search query to be less and precise keywords.\n" - "- When done searching, continue your reasoning.\n\n" - 'Please answer the following question. You should think step by step to solve it.\n\n' - ) - -RELEVANT_EXTRACTION_PROMPT = """**Task Instruction:** - - You are tasked with reading and analyzing web pages based on the following inputs: **Previous Reasoning Steps**, **Current Search Query**, and **Searched Web Pages**. Your objective is to extract relevant and helpful information for **Current Search Query** from the **Searched Web Pages** and seamlessly integrate this information into the **Previous Reasoning Steps** to continue reasoning for the original question. - - **Guidelines:** - - 1. **Analyze the Searched Web Pages:** - - Carefully review the content of each searched web page. - - Identify factual information that is relevant to the **Current Search Query** and can aid in the reasoning process for the original question. - - 2. **Extract Relevant Information:** - - Select the information from the Searched Web Pages that directly contributes to advancing the **Previous Reasoning Steps**. - - Ensure that the extracted information is accurate and relevant. - - 3. **Output Format:** - - **If the web pages provide helpful information for current search query:** Present the information beginning with `**Final Information**` as shown below. - - The language of query **MUST BE** as the same as 'Search Query' or 'Web Pages'.\n" - **Final Information** - - [Helpful information] - - - **If the web pages do not provide any helpful information for current search query:** Output the following text. - - **Final Information** - - No helpful information found. - - **Inputs:** - - **Previous Reasoning Steps:** - {prev_reasoning} - - - **Current Search Query:** - {search_query} - - - **Searched Web Pages:** - {document} - - """ +REASON_PROMPT = f"""You are an advanced reasoning agent. Your goal is to answer the user's question by breaking it down into a series of verifiable steps. + +You have access to a powerful search tool to find information. + +**Your Task:** +1. Analyze the user's question. +2. If you need information, issue a search query to find a specific fact. +3. Review the search results. +4. Repeat the search process until you have all the facts needed to answer the question. +5. Once you have gathered sufficient information, synthesize the facts and provide the final answer directly. + +**Tool Usage:** +- To search, you MUST write your query between the special tokens: {BEGIN_SEARCH_QUERY}your query{END_SEARCH_QUERY}. +- The system will provide results between {BEGIN_SEARCH_RESULT}search results{END_SEARCH_RESULT}. +- You have a maximum of {MAX_SEARCH_LIMIT} search attempts. + +--- +**Example 1: Multi-hop Question** + +**Question:** "Are both the directors of Jaws and Casino Royale from the same country?" + +**Your Thought Process & Actions:** +First, I need to identify the director of Jaws. +{BEGIN_SEARCH_QUERY}who is the director of Jaws?{END_SEARCH_QUERY} +[System returns search results] +{BEGIN_SEARCH_RESULT} +Jaws is a 1975 American thriller film directed by Steven Spielberg. +{END_SEARCH_RESULT} +Okay, the director of Jaws is Steven Spielberg. Now I need to find out his nationality. +{BEGIN_SEARCH_QUERY}where is Steven Spielberg from?{END_SEARCH_QUERY} +[System returns search results] +{BEGIN_SEARCH_RESULT} +Steven Allan Spielberg is an American filmmaker. Born in Cincinnati, Ohio... +{END_SEARCH_RESULT} +So, Steven Spielberg is from the USA. Next, I need to find the director of Casino Royale. +{BEGIN_SEARCH_QUERY}who is the director of Casino Royale 2006?{END_SEARCH_QUERY} +[System returns search results] +{BEGIN_SEARCH_RESULT} +Casino Royale is a 2006 spy film directed by Martin Campbell. +{END_SEARCH_RESULT} +The director of Casino Royale is Martin Campbell. Now I need his nationality. +{BEGIN_SEARCH_QUERY}where is Martin Campbell from?{END_SEARCH_QUERY} +[System returns search results] +{BEGIN_SEARCH_RESULT} +Martin Campbell (born 24 October 1943) is a New Zealand film and television director. +{END_SEARCH_RESULT} +I have all the information. Steven Spielberg is from the USA, and Martin Campbell is from New Zealand. They are not from the same country. + +Final Answer: No, the directors of Jaws and Casino Royale are not from the same country. Steven Spielberg is from the USA, and Martin Campbell is from New Zealand. + +--- +**Example 2: Simple Fact Retrieval** + +**Question:** "When was the founder of craigslist born?" + +**Your Thought Process & Actions:** +First, I need to know who founded craigslist. +{BEGIN_SEARCH_QUERY}who founded craigslist?{END_SEARCH_QUERY} +[System returns search results] +{BEGIN_SEARCH_RESULT} +Craigslist was founded in 1995 by Craig Newmark. +{END_SEARCH_RESULT} +The founder is Craig Newmark. Now I need his birth date. +{BEGIN_SEARCH_QUERY}when was Craig Newmark born?{END_SEARCH_QUERY} +[System returns search results] +{BEGIN_SEARCH_RESULT} +Craig Newmark was born on December 6, 1952. +{END_SEARCH_RESULT} +I have found the answer. + +Final Answer: The founder of craigslist, Craig Newmark, was born on December 6, 1952. + +--- +**Important Rules:** +- **One Fact at a Time:** Decompose the problem and issue one search query at a time to find a single, specific piece of information. +- **Be Precise:** Formulate clear and precise search queries. If a search fails, rephrase it. +- **Synthesize at the End:** Do not provide the final answer until you have completed all necessary searches. +- **Language Consistency:** Your search queries should be in the same language as the user's question. + +Now, begin your work. Please answer the following question by thinking step-by-step. +""" + +RELEVANT_EXTRACTION_PROMPT = """You are a highly efficient information extraction module. Your sole purpose is to extract the single most relevant piece of information from the provided `Searched Web Pages` that directly answers the `Current Search Query`. + +**Your Task:** +1. Read the `Current Search Query` to understand what specific information is needed. +2. Scan the `Searched Web Pages` to find the answer to that query. +3. Extract only the essential, factual information that answers the query. Be concise. + +**Context (For Your Information Only):** +The `Previous Reasoning Steps` are provided to give you context on the overall goal, but your primary focus MUST be on answering the `Current Search Query`. Do not use information from the previous steps in your output. + +**Output Format:** +Your response must follow one of two formats precisely. + +1. **If a direct and relevant answer is found:** + - Start your response immediately with `Final Information`. + - Provide only the extracted fact(s). Do not add any extra conversational text. + + *Example:* + `Current Search Query`: Where is Martin Campbell from? + `Searched Web Pages`: [Long article snippet about Martin Campbell's career, which includes the sentence "Martin Campbell (born 24 October 1943) is a New Zealand film and television director..."] + + *Your Output:* + Final Information + Martin Campbell is a New Zealand film and television director. + +2. **If no relevant answer that directly addresses the query is found in the web pages:** + - Start your response immediately with `Final Information`. + - Write the exact phrase: `No helpful information found.` + +--- +**BEGIN TASK** + +**Inputs:** + +- **Previous Reasoning Steps:** +{prev_reasoning} + +- **Current Search Query:** +{search_query} + +- **Searched Web Pages:** +{document} +""" \ No newline at end of file diff --git a/api/apps/__init__.py b/api/apps/__init__.py index 007e37430e4..f2009db2c16 100644 --- a/api/apps/__init__.py +++ b/api/apps/__init__.py @@ -24,14 +24,16 @@ from flasgger import Swagger from itsdangerous.url_safe import URLSafeTimedSerializer as Serializer -from api.db import StatusEnum +from common.constants import StatusEnum from api.db.db_models import close_connection from api.db.services import UserService -from api.utils import CustomJSONEncoder, commands +from api.utils.json_encode import CustomJSONEncoder +from api.utils import commands +from flask_mail import Mail from flask_session import Session from flask_login import LoginManager -from api import settings +from common import settings from api.utils.api_utils import server_error_response from api.constants import API_VERSION @@ -40,6 +42,7 @@ Request.json = property(lambda self: self.get_json(force=True, silent=True)) app = Flask(__name__) +smtp_mail_server = Mail() # Add this at the beginning of your file to configure Swagger UI swagger_config = { @@ -146,16 +149,16 @@ def load_user(web_request): if authorization: try: access_token = str(jwt.loads(authorization)) - + if not access_token or not access_token.strip(): logging.warning("Authentication attempt with empty access token") return None - + # Access tokens should be UUIDs (32 hex characters) if len(access_token.strip()) < 32: logging.warning(f"Authentication attempt with invalid token format: {len(access_token)} chars") return None - + user = UserService.query( access_token=access_token, status=StatusEnum.VALID.value ) diff --git a/api/apps/api_app.py b/api/apps/api_app.py index f66eb8067b5..1ab1c462ac8 100644 --- a/api/apps/api_app.py +++ b/api/apps/api_app.py @@ -21,7 +21,7 @@ from api.db.services.llm_service import LLMBundle from flask_login import login_required, current_user -from api.db import VALID_FILE_TYPES, VALID_TASK_STATUS, FileType, LLMType, ParserType, FileSource +from api.db import VALID_FILE_TYPES, FileType from api.db.db_models import APIToken, Task, File from api.db.services import duplicate_name from api.db.services.api_service import APITokenService, API4ConversationService @@ -32,19 +32,21 @@ from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.task_service import queue_tasks, TaskService from api.db.services.user_service import UserTenantService -from api import settings -from api.utils import get_uuid, current_timestamp, datetime_format +from common.misc_utils import get_uuid +from common.constants import RetCode, VALID_TASK_STATUS, LLMType, ParserType, FileSource from api.utils.api_utils import server_error_response, get_data_error_result, get_json_result, validate_request, \ generate_confirmation_token from api.utils.file_utils import filename_type, thumbnail from rag.app.tag import label_question -from rag.prompts import keyword_extraction -from rag.utils.storage_factory import STORAGE_IMPL +from rag.prompts.generator import keyword_extraction +from common.time_utils import current_timestamp, datetime_format from api.db.services.canvas_service import UserCanvasService from agent.canvas import Canvas from functools import partial +from pathlib import Path +from common import settings @manager.route('/new_token', methods=['POST']) # noqa: F821 @@ -57,7 +59,7 @@ def new_token(): return get_data_error_result(message="Tenant not found!") tenant_id = tenants[0].tenant_id - obj = {"tenant_id": tenant_id, "token": generate_confirmation_token(tenant_id), + obj = {"tenant_id": tenant_id, "token": generate_confirmation_token(), "create_time": current_timestamp(), "create_date": datetime_format(datetime.now()), "update_time": None, @@ -143,7 +145,7 @@ def set_conversation(): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) try: if objs[0].source == "agent": e, cvs = UserCanvasService.get_by_id(objs[0].dialog_id) @@ -184,7 +186,7 @@ def completion(): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) req = request.json e, conv = API4ConversationService.get_by_id(req["conversation_id"]) if not e: @@ -350,7 +352,7 @@ def get_conversation(conversation_id): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) try: e, conv = API4ConversationService.get_by_id(conversation_id) @@ -360,7 +362,7 @@ def get_conversation(conversation_id): conv = conv.to_dict() if token != APIToken.query(dialog_id=conv['dialog_id'])[0].token: return get_json_result(data=False, message='Authentication error: API key is invalid for this conversation_id!"', - code=settings.RetCode.AUTHENTICATION_ERROR) + code=RetCode.AUTHENTICATION_ERROR) for referenct_i in conv['reference']: if referenct_i is None or len(referenct_i) == 0: @@ -381,7 +383,7 @@ def upload(): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) kb_name = request.form.get("kb_name").strip() tenant_id = objs[0].tenant_id @@ -397,12 +399,12 @@ def upload(): if 'file' not in request.files: return get_json_result( - data=False, message='No file part!', code=settings.RetCode.ARGUMENT_ERROR) + data=False, message='No file part!', code=RetCode.ARGUMENT_ERROR) file = request.files['file'] if file.filename == '': return get_json_result( - data=False, message='No file selected!', code=settings.RetCode.ARGUMENT_ERROR) + data=False, message='No file selected!', code=RetCode.ARGUMENT_ERROR) root_folder = FileService.get_root_folder(tenant_id) pf_id = root_folder["id"] @@ -425,10 +427,10 @@ def upload(): message="This type of file has not been supported yet!") location = filename - while STORAGE_IMPL.obj_exist(kb_id, location): + while settings.STORAGE_IMPL.obj_exist(kb_id, location): location += "_" blob = request.files['file'].read() - STORAGE_IMPL.put(kb_id, location, blob) + settings.STORAGE_IMPL.put(kb_id, location, blob) doc = { "id": get_uuid(), "kb_id": kb.id, @@ -439,7 +441,8 @@ def upload(): "name": filename, "location": location, "size": len(blob), - "thumbnail": thumbnail(filename, blob) + "thumbnail": thumbnail(filename, blob), + "suffix": Path(filename).suffix.lstrip("."), } form_data = request.form @@ -463,10 +466,7 @@ def upload(): if "run" in form_data.keys(): if request.form.get("run").strip() == "1": try: - info = {"run": 1, "progress": 0} - info["progress_msg"] = "" - info["chunk_num"] = 0 - info["token_num"] = 0 + info = {"run": 1, "progress": 0, "progress_msg": "", "chunk_num": 0, "token_num": 0} DocumentService.update_by_id(doc["id"], info) # if str(req["run"]) == TaskStatus.CANCEL.value: tenant_id = DocumentService.get_tenant_id(doc["id"]) @@ -493,17 +493,17 @@ def upload_parse(): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) if 'file' not in request.files: return get_json_result( - data=False, message='No file part!', code=settings.RetCode.ARGUMENT_ERROR) + data=False, message='No file part!', code=RetCode.ARGUMENT_ERROR) file_objs = request.files.getlist('file') for file_obj in file_objs: if file_obj.filename == '': return get_json_result( - data=False, message='No file selected!', code=settings.RetCode.ARGUMENT_ERROR) + data=False, message='No file selected!', code=RetCode.ARGUMENT_ERROR) doc_ids = doc_upload_and_parse(request.form.get("conversation_id"), file_objs, objs[0].tenant_id) return get_json_result(data=doc_ids) @@ -516,7 +516,7 @@ def list_chunks(): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) req = request.json @@ -534,7 +534,7 @@ def list_chunks(): ) kb_ids = KnowledgebaseService.get_kb_ids(tenant_id) - res = settings.retrievaler.chunk_list(doc_id, tenant_id, kb_ids) + res = settings.retriever.chunk_list(doc_id, tenant_id, kb_ids) res = [ { "content": res_item["content_with_weight"], @@ -556,7 +556,7 @@ def get_chunk(chunk_id): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) try: tenant_id = objs[0].tenant_id kb_ids = KnowledgebaseService.get_kb_ids(tenant_id) @@ -581,7 +581,7 @@ def list_kb_docs(): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) req = request.json tenant_id = objs[0].tenant_id @@ -634,7 +634,7 @@ def docinfos(): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) req = request.json doc_ids = req["doc_ids"] docs = DocumentService.get_by_ids(doc_ids) @@ -648,7 +648,7 @@ def document_rm(): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) tenant_id = objs[0].tenant_id req = request.json @@ -695,12 +695,12 @@ def document_rm(): FileService.filter_delete([File.source_type == FileSource.KNOWLEDGEBASE, File.id == f2d[0].file_id]) File2DocumentService.delete_by_document_id(doc_id) - STORAGE_IMPL.rm(b, n) + settings.STORAGE_IMPL.rm(b, n) except Exception as e: errors += str(e) if errors: - return get_json_result(data=False, message=errors, code=settings.RetCode.SERVER_ERROR) + return get_json_result(data=False, message=errors, code=RetCode.SERVER_ERROR) return get_json_result(data=True) @@ -715,7 +715,7 @@ def completion_faq(): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) e, conv = API4ConversationService.get_by_id(req["conversation_id"]) if not e: @@ -723,8 +723,7 @@ def completion_faq(): if "quote" not in req: req["quote"] = True - msg = [] - msg.append({"role": "user", "content": req["word"]}) + msg = [{"role": "user", "content": req["word"]}] if not msg[-1].get("id"): msg[-1]["id"] = get_uuid() message_id = msg[-1]["id"] @@ -788,7 +787,7 @@ def fillin_conv(ans): if ans["reference"]["chunks"][chunk_idx]["img_id"]: try: bkt, nm = ans["reference"]["chunks"][chunk_idx]["img_id"].split("-") - response = STORAGE_IMPL.get(bkt, nm) + response = settings.STORAGE_IMPL.get(bkt, nm) data_type_picture["url"] = base64.b64encode(response).decode('utf-8') data.append(data_type_picture) break @@ -833,7 +832,7 @@ def fillin_conv(ans): if ans["reference"]["chunks"][chunk_idx]["img_id"]: try: bkt, nm = ans["reference"]["chunks"][chunk_idx]["img_id"].split("-") - response = STORAGE_IMPL.get(bkt, nm) + response = settings.STORAGE_IMPL.get(bkt, nm) data_type_picture["url"] = base64.b64encode(response).decode('utf-8') data.append(data_type_picture) break @@ -854,7 +853,7 @@ def retrieval(): objs = APIToken.query(token=token) if not objs: return get_json_result( - data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + data=False, message='Authentication error: API key is invalid!"', code=RetCode.AUTHENTICATION_ERROR) req = request.json kb_ids = req.get("kb_id", []) @@ -865,7 +864,7 @@ def retrieval(): similarity_threshold = float(req.get("similarity_threshold", 0.2)) vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3)) top = int(req.get("top_k", 1024)) - highlight = bool(req.get("highlight", False)) + highlight = bool(req.get("highlight", False)) try: kbs = KnowledgebaseService.get_by_ids(kb_ids) @@ -873,7 +872,7 @@ def retrieval(): if len(embd_nms) != 1: return get_json_result( data=False, message='Knowledge bases use different embedding models or does not exist."', - code=settings.RetCode.AUTHENTICATION_ERROR) + code=RetCode.AUTHENTICATION_ERROR) embd_mdl = LLMBundle(kbs[0].tenant_id, LLMType.EMBEDDING, llm_name=kbs[0].embd_id) rerank_mdl = None @@ -882,7 +881,7 @@ def retrieval(): if req.get("keyword", False): chat_mdl = LLMBundle(kbs[0].tenant_id, LLMType.CHAT) question += keyword_extraction(chat_mdl, question) - ranks = settings.retrievaler.retrieval(question, embd_mdl, kbs[0].tenant_id, kb_ids, page, size, + ranks = settings.retriever.retrieval(question, embd_mdl, kbs[0].tenant_id, kb_ids, page, size, similarity_threshold, vector_similarity_weight, top, doc_ids, rerank_mdl=rerank_mdl, highlight= highlight, rank_feature=label_question(question, kbs)) @@ -892,5 +891,5 @@ def retrieval(): except Exception as e: if str(e).find("not_found") > 0: return get_json_result(data=False, message='No chunk found! Check the chunk status please!', - code=settings.RetCode.DATA_ERROR) + code=RetCode.DATA_ERROR) return server_error_response(e) diff --git a/api/apps/auth/github.py b/api/apps/auth/github.py index 5d46b277d5e..f48d4a5fc27 100644 --- a/api/apps/auth/github.py +++ b/api/apps/auth/github.py @@ -34,7 +34,7 @@ def __init__(self, config): def fetch_user_info(self, access_token, **kwargs): """ - Fetch github user info. + Fetch GitHub user info. """ user_info = {} try: diff --git a/api/apps/auth/oidc.py b/api/apps/auth/oidc.py index 9c59ffaebaa..cafcaadfdfd 100644 --- a/api/apps/auth/oidc.py +++ b/api/apps/auth/oidc.py @@ -43,7 +43,8 @@ def __init__(self, config): self.jwks_uri = config['jwks_uri'] - def _load_oidc_metadata(self, issuer): + @staticmethod + def _load_oidc_metadata(issuer): """ Load OIDC metadata from `/.well-known/openid-configuration`. """ diff --git a/api/apps/canvas_app.py b/api/apps/canvas_app.py index d80eb093c94..0ac2951ae5f 100644 --- a/api/apps/canvas_app.py +++ b/api/apps/canvas_app.py @@ -14,40 +14,52 @@ # limitations under the License. # import json -import traceback +import logging +import re +import sys +from functools import partial + +import flask +import trio from flask import request, Response from flask_login import login_required, current_user -from api.db.services.canvas_service import CanvasTemplateService, UserCanvasService + +from agent.component import LLM +from api.db import CanvasCategory, FileType +from api.db.services.canvas_service import CanvasTemplateService, UserCanvasService, API4ConversationService +from api.db.services.document_service import DocumentService +from api.db.services.file_service import FileService +from api.db.services.pipeline_operation_log_service import PipelineOperationLogService +from api.db.services.task_service import queue_dataflow, CANVAS_DEBUG_DOC_ID, TaskService from api.db.services.user_service import TenantService from api.db.services.user_canvas_version import UserCanvasVersionService -from api.settings import RetCode -from api.utils import get_uuid +from common.constants import RetCode +from common.misc_utils import get_uuid from api.utils.api_utils import get_json_result, server_error_response, validate_request, get_data_error_result from agent.canvas import Canvas from peewee import MySQLDatabase, PostgresqlDatabase -from api.db.db_models import APIToken +from api.db.db_models import APIToken, Task import time +from api.utils.file_utils import filename_type, read_potential_broken_pdf +from rag.flow.pipeline import Pipeline +from rag.nlp import search +from rag.utils.redis_conn import REDIS_CONN +from common import settings + + @manager.route('/templates', methods=['GET']) # noqa: F821 @login_required def templates(): return get_json_result(data=[c.to_dict() for c in CanvasTemplateService.get_all()]) -@manager.route('/list', methods=['GET']) # noqa: F821 -@login_required -def canvas_list(): - return get_json_result(data=sorted([c.to_dict() for c in \ - UserCanvasService.query(user_id=current_user.id)], key=lambda x: x["update_time"]*-1) - ) - - @manager.route('/rm', methods=['POST']) # noqa: F821 @validate_request("canvas_ids") @login_required def rm(): for i in request.json["canvas_ids"]: - if not UserCanvasService.query(user_id=current_user.id,id=i): + if not UserCanvasService.accessible(i, current_user.id): return get_json_result( data=False, message='Only owner of canvas authorized for this operation.', code=RetCode.OPERATING_ERROR) @@ -60,38 +72,38 @@ def rm(): @login_required def save(): req = request.json - req["user_id"] = current_user.id if not isinstance(req["dsl"], str): req["dsl"] = json.dumps(req["dsl"], ensure_ascii=False) req["dsl"] = json.loads(req["dsl"]) + cate = req.get("canvas_category", CanvasCategory.Agent) if "id" not in req: - if UserCanvasService.query(user_id=current_user.id, title=req["title"].strip()): + req["user_id"] = current_user.id + if UserCanvasService.query(user_id=current_user.id, title=req["title"].strip(), canvas_category=cate): return get_data_error_result(message=f"{req['title'].strip()} already exists.") req["id"] = get_uuid() if not UserCanvasService.save(**req): return get_data_error_result(message="Fail to save canvas.") else: - if not UserCanvasService.query(user_id=current_user.id, id=req["id"]): + if not UserCanvasService.accessible(req["id"], current_user.id): return get_json_result( data=False, message='Only owner of canvas authorized for this operation.', code=RetCode.OPERATING_ERROR) UserCanvasService.update_by_id(req["id"], req) - # save version - UserCanvasVersionService.insert( user_canvas_id=req["id"], dsl=req["dsl"], title="{0}_{1}".format(req["title"], time.strftime("%Y_%m_%d_%H_%M_%S"))) + # save version + UserCanvasVersionService.insert(user_canvas_id=req["id"], dsl=req["dsl"], title="{0}_{1}".format(req["title"], time.strftime("%Y_%m_%d_%H_%M_%S"))) UserCanvasVersionService.delete_all_versions(req["id"]) return get_json_result(data=req) - - @manager.route('/get/', methods=['GET']) # noqa: F821 @login_required def get(canvas_id): - e, c = UserCanvasService.get_by_tenant_id(canvas_id) - if not e: + if not UserCanvasService.accessible(canvas_id, current_user.id): return get_data_error_result(message="canvas not found.") + e, c = UserCanvasService.get_by_canvas_id(canvas_id) return get_json_result(data=c) + @manager.route('/getsse/', methods=['GET']) # type: ignore # noqa: F821 def getsse(canvas_id): token = request.headers.get('Authorization').split() @@ -101,8 +113,15 @@ def getsse(canvas_id): objs = APIToken.query(beta=token) if not objs: return get_data_error_result(message='Authentication error: API key is invalid!"') + tenant_id = objs[0].tenant_id + if not UserCanvasService.query(user_id=tenant_id, id=canvas_id): + return get_json_result( + data=False, + message='Only owner of canvas authorized for this operation.', + code=RetCode.OPERATING_ERROR + ) e, c = UserCanvasService.get_by_id(canvas_id) - if not e: + if not e or c.user_id != tenant_id: return get_data_error_result(message="canvas not found.") return get_json_result(data=c.to_dict()) @@ -112,81 +131,94 @@ def getsse(canvas_id): @login_required def run(): req = request.json - stream = req.get("stream", True) - running_hint_text = req.get("running_hint_text", "") - e, cvs = UserCanvasService.get_by_id(req["id"]) - if not e: - return get_data_error_result(message="canvas not found.") - if not UserCanvasService.query(user_id=current_user.id, id=req["id"]): + query = req.get("query", "") + files = req.get("files", []) + inputs = req.get("inputs", {}) + user_id = req.get("user_id", current_user.id) + if not UserCanvasService.accessible(req["id"], current_user.id): return get_json_result( data=False, message='Only owner of canvas authorized for this operation.', code=RetCode.OPERATING_ERROR) + e, cvs = UserCanvasService.get_by_id(req["id"]) + if not e: + return get_data_error_result(message="canvas not found.") + if not isinstance(cvs.dsl, str): cvs.dsl = json.dumps(cvs.dsl, ensure_ascii=False) - final_ans = {"reference": [], "content": ""} - message_id = req.get("message_id", get_uuid()) + if cvs.canvas_category == CanvasCategory.DataFlow: + task_id = get_uuid() + Pipeline(cvs.dsl, tenant_id=current_user.id, doc_id=CANVAS_DEBUG_DOC_ID, task_id=task_id, flow_id=req["id"]) + ok, error_message = queue_dataflow(tenant_id=user_id, flow_id=req["id"], task_id=task_id, file=files[0], priority=0) + if not ok: + return get_data_error_result(message=error_message) + return get_json_result(data={"message_id": task_id}) + try: canvas = Canvas(cvs.dsl, current_user.id) - if "message" in req: - canvas.messages.append({"role": "user", "content": req["message"], "id": message_id}) - canvas.add_user_input(req["message"]) except Exception as e: return server_error_response(e) - if stream: - def sse(): - nonlocal answer, cvs - try: - for ans in canvas.run(running_hint_text = running_hint_text, stream=True): - if ans.get("running_status"): - yield "data:" + json.dumps({"code": 0, "message": "", - "data": {"answer": ans["content"], - "running_status": True}}, - ensure_ascii=False) + "\n\n" - continue - for k in ans.keys(): - final_ans[k] = ans[k] - ans = {"answer": ans["content"], "reference": ans.get("reference", [])} - yield "data:" + json.dumps({"code": 0, "message": "", "data": ans}, ensure_ascii=False) + "\n\n" - - canvas.messages.append({"role": "assistant", "content": final_ans["content"], "id": message_id}) - canvas.history.append(("assistant", final_ans["content"])) - if not canvas.path[-1]: - canvas.path.pop(-1) - if final_ans.get("reference"): - canvas.reference.append(final_ans["reference"]) - cvs.dsl = json.loads(str(canvas)) - UserCanvasService.update_by_id(req["id"], cvs.to_dict()) - except Exception as e: - cvs.dsl = json.loads(str(canvas)) - if not canvas.path[-1]: - canvas.path.pop(-1) - UserCanvasService.update_by_id(req["id"], cvs.to_dict()) - traceback.print_exc() - yield "data:" + json.dumps({"code": 500, "message": str(e), - "data": {"answer": "**ERROR**: " + str(e), "reference": []}}, - ensure_ascii=False) + "\n\n" - yield "data:" + json.dumps({"code": 0, "message": "", "data": True}, ensure_ascii=False) + "\n\n" - - resp = Response(sse(), mimetype="text/event-stream") - resp.headers.add_header("Cache-control", "no-cache") - resp.headers.add_header("Connection", "keep-alive") - resp.headers.add_header("X-Accel-Buffering", "no") - resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8") - return resp - - for answer in canvas.run(running_hint_text = running_hint_text, stream=False): - if answer.get("running_status"): - continue - final_ans["content"] = "\n".join(answer["content"]) if "content" in answer else "" - canvas.messages.append({"role": "assistant", "content": final_ans["content"], "id": message_id}) - if final_ans.get("reference"): - canvas.reference.append(final_ans["reference"]) - cvs.dsl = json.loads(str(canvas)) - UserCanvasService.update_by_id(req["id"], cvs.to_dict()) - return get_json_result(data={"answer": final_ans["content"], "reference": final_ans.get("reference", [])}) + def sse(): + nonlocal canvas, user_id + try: + for ans in canvas.run(query=query, files=files, user_id=user_id, inputs=inputs): + yield "data:" + json.dumps(ans, ensure_ascii=False) + "\n\n" + + cvs.dsl = json.loads(str(canvas)) + UserCanvasService.update_by_id(req["id"], cvs.to_dict()) + + except Exception as e: + logging.exception(e) + canvas.cancel_task() + yield "data:" + json.dumps({"code": 500, "message": str(e), "data": False}, ensure_ascii=False) + "\n\n" + + resp = Response(sse(), mimetype="text/event-stream") + resp.headers.add_header("Cache-control", "no-cache") + resp.headers.add_header("Connection", "keep-alive") + resp.headers.add_header("X-Accel-Buffering", "no") + resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8") + resp.call_on_close(lambda: canvas.cancel_task()) + return resp + + +@manager.route('/rerun', methods=['POST']) # noqa: F821 +@validate_request("id", "dsl", "component_id") +@login_required +def rerun(): + req = request.json + doc = PipelineOperationLogService.get_documents_info(req["id"]) + if not doc: + return get_data_error_result(message="Document not found.") + doc = doc[0] + if 0 < doc["progress"] < 1: + return get_data_error_result(message=f"`{doc['name']}` is processing...") + + if settings.docStoreConn.indexExist(search.index_name(current_user.id), doc["kb_id"]): + settings.docStoreConn.delete({"doc_id": doc["id"]}, search.index_name(current_user.id), doc["kb_id"]) + doc["progress_msg"] = "" + doc["chunk_num"] = 0 + doc["token_num"] = 0 + DocumentService.clear_chunk_num_when_rerun(doc["id"]) + DocumentService.update_by_id(id, doc) + TaskService.filter_delete([Task.doc_id == id]) + + dsl = req["dsl"] + dsl["path"] = [req["component_id"]] + PipelineOperationLogService.update_by_id(req["id"], {"dsl": dsl}) + queue_dataflow(tenant_id=current_user.id, flow_id=req["id"], task_id=get_uuid(), doc_id=doc["id"], priority=0, rerun=True) + return get_json_result(data=True) + + +@manager.route('/cancel/', methods=['PUT']) # noqa: F821 +@login_required +def cancel(task_id): + try: + REDIS_CONN.set(f"{task_id}-cancel", "x") + except Exception as e: + logging.exception(e) + return get_json_result(data=True) @manager.route('/reset', methods=['POST']) # noqa: F821 @@ -194,14 +226,14 @@ def sse(): @login_required def reset(): req = request.json + if not UserCanvasService.accessible(req["id"], current_user.id): + return get_json_result( + data=False, message='Only owner of canvas authorized for this operation.', + code=RetCode.OPERATING_ERROR) try: e, user_canvas = UserCanvasService.get_by_id(req["id"]) if not e: return get_data_error_result(message="canvas not found.") - if not UserCanvasService.query(user_id=current_user.id, id=req["id"]): - return get_json_result( - data=False, message='Only owner of canvas authorized for this operation.', - code=RetCode.OPERATING_ERROR) canvas = Canvas(json.dumps(user_canvas.dsl), current_user.id) canvas.reset() @@ -212,9 +244,84 @@ def reset(): return server_error_response(e) -@manager.route('/input_elements', methods=['GET']) # noqa: F821 +@manager.route("/upload/", methods=["POST"]) # noqa: F821 +def upload(canvas_id): + e, cvs = UserCanvasService.get_by_canvas_id(canvas_id) + if not e: + return get_data_error_result(message="canvas not found.") + + user_id = cvs["user_id"] + def structured(filename, filetype, blob, content_type): + nonlocal user_id + if filetype == FileType.PDF.value: + blob = read_potential_broken_pdf(blob) + + location = get_uuid() + FileService.put_blob(user_id, location, blob) + + return { + "id": location, + "name": filename, + "size": sys.getsizeof(blob), + "extension": filename.split(".")[-1].lower(), + "mime_type": content_type, + "created_by": user_id, + "created_at": time.time(), + "preview_url": None + } + + if request.args.get("url"): + from crawl4ai import ( + AsyncWebCrawler, + BrowserConfig, + CrawlerRunConfig, + DefaultMarkdownGenerator, + PruningContentFilter, + CrawlResult + ) + try: + url = request.args.get("url") + filename = re.sub(r"\?.*", "", url.split("/")[-1]) + async def adownload(): + browser_config = BrowserConfig( + headless=True, + verbose=False, + ) + async with AsyncWebCrawler(config=browser_config) as crawler: + crawler_config = CrawlerRunConfig( + markdown_generator=DefaultMarkdownGenerator( + content_filter=PruningContentFilter() + ), + pdf=True, + screenshot=False + ) + result: CrawlResult = await crawler.arun( + url=url, + config=crawler_config + ) + return result + page = trio.run(adownload()) + if page.pdf: + if filename.split(".")[-1].lower() != "pdf": + filename += ".pdf" + return get_json_result(data=structured(filename, "pdf", page.pdf, page.response_headers["content-type"])) + + return get_json_result(data=structured(filename, "html", str(page.markdown).encode("utf-8"), page.response_headers["content-type"], user_id)) + + except Exception as e: + return server_error_response(e) + + file = request.files['file'] + try: + DocumentService.check_doc_health(user_id, file.filename) + return get_json_result(data=structured(file.filename, filename_type(file.filename), file.read(), file.content_type)) + except Exception as e: + return server_error_response(e) + + +@manager.route('/input_form', methods=['GET']) # noqa: F821 @login_required -def input_elements(): +def input_form(): cvs_id = request.args.get("id") cpn_id = request.args.get("component_id") try: @@ -227,7 +334,7 @@ def input_elements(): code=RetCode.OPERATING_ERROR) canvas = Canvas(json.dumps(user_canvas.dsl), current_user.id) - return get_json_result(data=canvas.get_component_input_elements(cpn_id)) + return get_json_result(data=canvas.get_component_input_form(cpn_id)) except Exception as e: return server_error_response(e) @@ -237,23 +344,29 @@ def input_elements(): @login_required def debug(): req = request.json - for p in req["params"]: - assert p.get("key") + if not UserCanvasService.accessible(req["id"], current_user.id): + return get_json_result( + data=False, message='Only owner of canvas authorized for this operation.', + code=RetCode.OPERATING_ERROR) try: e, user_canvas = UserCanvasService.get_by_id(req["id"]) - if not e: - return get_data_error_result(message="canvas not found.") - if not UserCanvasService.query(user_id=current_user.id, id=req["id"]): - return get_json_result( - data=False, message='Only owner of canvas authorized for this operation.', - code=RetCode.OPERATING_ERROR) - canvas = Canvas(json.dumps(user_canvas.dsl), current_user.id) - componant = canvas.get_component(req["component_id"])["obj"] - componant.reset() - componant._param.debug_inputs = req["params"] - df = canvas.get_component(req["component_id"])["obj"].debug() - return get_json_result(data=df.to_dict(orient="records")) + canvas.reset() + canvas.message_id = get_uuid() + component = canvas.get_component(req["component_id"])["obj"] + component.reset() + + if isinstance(component, LLM): + component.set_debug_inputs(req["params"]) + component.invoke(**{k: o["value"] for k,o in req["params"].items()}) + outputs = component.output() + for k in outputs.keys(): + if isinstance(outputs[k], partial): + txt = "" + for c in outputs[k](): + txt += c + outputs[k] = txt + return get_json_result(data=outputs) except Exception as e: return server_error_response(e) @@ -267,7 +380,7 @@ def test_db_connect(): if req["db_type"] in ["mysql", "mariadb"]: db = MySQLDatabase(req["database"], user=req["username"], host=req["host"], port=req["port"], password=req["password"]) - elif req["db_type"] == 'postgresql': + elif req["db_type"] == 'postgres': db = PostgresqlDatabase(req["database"], user=req["username"], host=req["host"], port=req["port"], password=req["password"]) elif req["db_type"] == 'mssql': @@ -283,15 +396,76 @@ def test_db_connect(): cursor = db.cursor() cursor.execute("SELECT 1") cursor.close() + elif req["db_type"] == 'IBM DB2': + import ibm_db + conn_str = ( + f"DATABASE={req['database']};" + f"HOSTNAME={req['host']};" + f"PORT={req['port']};" + f"PROTOCOL=TCPIP;" + f"UID={req['username']};" + f"PWD={req['password']};" + ) + logging.info(conn_str) + conn = ibm_db.connect(conn_str, "", "") + stmt = ibm_db.exec_immediate(conn, "SELECT 1 FROM sysibm.sysdummy1") + ibm_db.fetch_assoc(stmt) + ibm_db.close(conn) + return get_json_result(data="Database Connection Successful!") + elif req["db_type"] == 'trino': + def _parse_catalog_schema(db_name: str): + if not db_name: + return None, None + if "." in db_name: + catalog_name, schema_name = db_name.split(".", 1) + elif "/" in db_name: + catalog_name, schema_name = db_name.split("/", 1) + else: + catalog_name, schema_name = db_name, "default" + return catalog_name, schema_name + try: + import trino + import os + from trino.auth import BasicAuthentication + except Exception as e: + return server_error_response(f"Missing dependency 'trino'. Please install: pip install trino, detail: {e}") + + catalog, schema = _parse_catalog_schema(req["database"]) + if not catalog: + return server_error_response("For Trino, 'database' must be 'catalog.schema' or at least 'catalog'.") + + http_scheme = "https" if os.environ.get("TRINO_USE_TLS", "0") == "1" else "http" + + auth = None + if http_scheme == "https" and req.get("password"): + auth = BasicAuthentication(req.get("username") or "ragflow", req["password"]) + + conn = trino.dbapi.connect( + host=req["host"], + port=int(req["port"] or 8080), + user=req["username"] or "ragflow", + catalog=catalog, + schema=schema or "default", + http_scheme=http_scheme, + auth=auth + ) + cur = conn.cursor() + cur.execute("SELECT 1") + cur.fetchall() + cur.close() + conn.close() + return get_json_result(data="Database Connection Successful!") else: return server_error_response("Unsupported database type.") if req["db_type"] != 'mssql': db.connect() db.close() - + return get_json_result(data="Database Connection Successful!") except Exception as e: return server_error_response(e) + + #api get list version dsl of canvas @manager.route('/getlistversion/', methods=['GET']) # noqa: F821 @login_required @@ -301,53 +475,135 @@ def getlistversion(canvas_id): return get_json_result(data=list) except Exception as e: return get_data_error_result(message=f"Error getting history files: {e}") + + #api get version dsl of canvas @manager.route('/getversion/', methods=['GET']) # noqa: F821 @login_required def getversion( version_id): try: - e, version = UserCanvasVersionService.get_by_id(version_id) if version: return get_json_result(data=version.to_dict()) except Exception as e: return get_json_result(data=f"Error getting history file: {e}") -@manager.route('/listteam', methods=['GET']) # noqa: F821 + + +@manager.route('/list', methods=['GET']) # noqa: F821 @login_required -def list_kbs(): +def list_canvas(): keywords = request.args.get("keywords", "") - page_number = int(request.args.get("page", 1)) - items_per_page = int(request.args.get("page_size", 150)) + page_number = int(request.args.get("page", 0)) + items_per_page = int(request.args.get("page_size", 0)) orderby = request.args.get("orderby", "create_time") - desc = request.args.get("desc", True) - try: + canvas_category = request.args.get("canvas_category") + if request.args.get("desc", "true").lower() == "false": + desc = False + else: + desc = True + owner_ids = [id for id in request.args.get("owner_ids", "").strip().split(",") if id] + if not owner_ids: tenants = TenantService.get_joined_tenants_by_user_id(current_user.id) - kbs, total = UserCanvasService.get_by_tenant_ids( - [m["tenant_id"] for m in tenants], current_user.id, page_number, - items_per_page, orderby, desc, keywords) - return get_json_result(data={"kbs": kbs, "total": total}) - except Exception as e: - return server_error_response(e) + tenants = [m["tenant_id"] for m in tenants] + tenants.append(current_user.id) + canvas, total = UserCanvasService.get_by_tenant_ids( + tenants, current_user.id, page_number, + items_per_page, orderby, desc, keywords, canvas_category) + else: + tenants = owner_ids + canvas, total = UserCanvasService.get_by_tenant_ids( + tenants, current_user.id, 0, + 0, orderby, desc, keywords, canvas_category) + return get_json_result(data={"canvas": canvas, "total": total}) + + @manager.route('/setting', methods=['POST']) # noqa: F821 @validate_request("id", "title", "permission") @login_required def setting(): req = request.json req["user_id"] = current_user.id + + if not UserCanvasService.accessible(req["id"], current_user.id): + return get_json_result( + data=False, message='Only owner of canvas authorized for this operation.', + code=RetCode.OPERATING_ERROR) + e,flow = UserCanvasService.get_by_id(req["id"]) if not e: return get_data_error_result(message="canvas not found.") flow = flow.to_dict() flow["title"] = req["title"] - if req["description"]: - flow["description"] = req["description"] - if req["permission"]: - flow["permission"] = req["permission"] - if req["avatar"]: - flow["avatar"] = req["avatar"] - if not UserCanvasService.query(user_id=current_user.id, id=req["id"]): + + for key in ["description", "permission", "avatar"]: + if value := req.get(key): + flow[key] = value + + num= UserCanvasService.update_by_id(req["id"], flow) + return get_json_result(data=num) + + +@manager.route('/trace', methods=['GET']) # noqa: F821 +def trace(): + cvs_id = request.args.get("canvas_id") + msg_id = request.args.get("message_id") + try: + binary = REDIS_CONN.get(f"{cvs_id}-{msg_id}-logs") + if not binary: + return get_json_result(data={}) + + return get_json_result(data=json.loads(binary.encode("utf-8"))) + except Exception as e: + logging.exception(e) + + +@manager.route('//sessions', methods=['GET']) # noqa: F821 +@login_required +def sessions(canvas_id): + tenant_id = current_user.id + if not UserCanvasService.accessible(canvas_id, tenant_id): return get_json_result( data=False, message='Only owner of canvas authorized for this operation.', code=RetCode.OPERATING_ERROR) - num= UserCanvasService.update_by_id(req["id"], flow) - return get_json_result(data=num) + + user_id = request.args.get("user_id") + page_number = int(request.args.get("page", 1)) + items_per_page = int(request.args.get("page_size", 30)) + keywords = request.args.get("keywords") + from_date = request.args.get("from_date") + to_date = request.args.get("to_date") + orderby = request.args.get("orderby", "update_time") + if request.args.get("desc") == "False" or request.args.get("desc") == "false": + desc = False + else: + desc = True + # dsl defaults to True in all cases except for False and false + include_dsl = request.args.get("dsl") != "False" and request.args.get("dsl") != "false" + total, sess = API4ConversationService.get_list(canvas_id, tenant_id, page_number, items_per_page, orderby, desc, + None, user_id, include_dsl, keywords, from_date, to_date) + try: + return get_json_result(data={"total": total, "sessions": sess}) + except Exception as e: + return server_error_response(e) + + +@manager.route('/prompts', methods=['GET']) # noqa: F821 +@login_required +def prompts(): + from rag.prompts.generator import ANALYZE_TASK_SYSTEM, ANALYZE_TASK_USER, NEXT_STEP, REFLECT, CITATION_PROMPT_TEMPLATE + return get_json_result(data={ + "task_analysis": ANALYZE_TASK_SYSTEM +"\n\n"+ ANALYZE_TASK_USER, + "plan_generation": NEXT_STEP, + "reflection": REFLECT, + #"context_summary": SUMMARY4MEMORY, + #"context_ranking": RANK_MEMORY, + "citation_guidelines": CITATION_PROMPT_TEMPLATE + }) + + +@manager.route('/download', methods=['GET']) # noqa: F821 +def download(): + id = request.args.get("id") + created_by = request.args.get("created_by") + blob = FileService.get_blob(created_by, id) + return flask.make_response(blob) diff --git a/api/apps/chunk_app.py b/api/apps/chunk_app.py index 69b03b9ae69..78a614ddf7c 100644 --- a/api/apps/chunk_app.py +++ b/api/apps/chunk_app.py @@ -15,27 +15,26 @@ # import datetime import json +import re +import xxhash from flask import request -from flask_login import login_required, current_user +from flask_login import current_user, login_required -from rag.app.qa import rmPrefix, beAdoc -from rag.app.tag import label_question -from rag.nlp import search, rag_tokenizer -from rag.prompts import keyword_extraction, cross_languages -from rag.settings import PAGERANK_FLD -from rag.utils import rmSpace -from api.db import LLMType, ParserType +from api.db.services.dialog_service import meta_filter +from api.db.services.document_service import DocumentService from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.llm_service import LLMBundle +from api.db.services.search_service import SearchService from api.db.services.user_service import UserTenantService -from api.utils.api_utils import server_error_response, get_data_error_result, validate_request -from api.db.services.document_service import DocumentService -from api import settings -from api.utils.api_utils import get_json_result -import xxhash -import re - +from api.utils.api_utils import get_data_error_result, get_json_result, server_error_response, validate_request +from rag.app.qa import beAdoc, rmPrefix +from rag.app.tag import label_question +from rag.nlp import rag_tokenizer, search +from rag.prompts.generator import gen_meta_filter, cross_languages, keyword_extraction +from common.string_utils import remove_redundant_spaces +from common.constants import RetCode, LLMType, ParserType, PAGERANK_FLD +from common import settings @manager.route('/list', methods=['POST']) # noqa: F821 @@ -60,12 +59,12 @@ def list_chunk(): } if "available_int" in req: query["available_int"] = int(req["available_int"]) - sres = settings.retrievaler.search(query, search.index_name(tenant_id), kb_ids, highlight=True) + sres = settings.retriever.search(query, search.index_name(tenant_id), kb_ids, highlight=["content_ltks"]) res = {"total": sres.total, "chunks": [], "doc": doc.to_dict()} for id in sres.ids: d = { "chunk_id": id, - "content_with_weight": rmSpace(sres.highlight[id]) if question and id in sres.highlight else sres.field[ + "content_with_weight": remove_redundant_spaces(sres.highlight[id]) if question and id in sres.highlight else sres.field[ id].get( "content_with_weight", ""), "doc_id": sres.field[id]["doc_id"], @@ -83,7 +82,7 @@ def list_chunk(): except Exception as e: if str(e).find("not_found") > 0: return get_json_result(data=False, message='No chunk found!', - code=settings.RetCode.DATA_ERROR) + code=RetCode.DATA_ERROR) return server_error_response(e) @@ -92,6 +91,7 @@ def list_chunk(): def get(): chunk_id = request.args["chunk_id"] try: + chunk = None tenants = UserTenantService.query(user_id=current_user.id) if not tenants: return get_data_error_result(message="Tenant not found!") @@ -114,7 +114,7 @@ def get(): except Exception as e: if str(e).find("NotFoundError") >= 0: return get_json_result(data=False, message='Chunk not found!', - code=settings.RetCode.DATA_ERROR) + code=RetCode.DATA_ERROR) return server_error_response(e) @@ -129,9 +129,13 @@ def set(): d["content_ltks"] = rag_tokenizer.tokenize(req["content_with_weight"]) d["content_sm_ltks"] = rag_tokenizer.fine_grained_tokenize(d["content_ltks"]) if "important_kwd" in req: + if not isinstance(req["important_kwd"], list): + return get_data_error_result(message="`important_kwd` should be a list") d["important_kwd"] = req["important_kwd"] d["important_tks"] = rag_tokenizer.tokenize(" ".join(req["important_kwd"])) if "question_kwd" in req: + if not isinstance(req["question_kwd"], list): + return get_data_error_result(message="`question_kwd` should be a list") d["question_kwd"] = req["question_kwd"] d["question_tks"] = rag_tokenizer.tokenize("\n".join(req["question_kwd"])) if "tag_kwd" in req: @@ -195,20 +199,21 @@ def switch(): @login_required @validate_request("chunk_ids", "doc_id") def rm(): - from rag.utils.storage_factory import STORAGE_IMPL req = request.json try: e, doc = DocumentService.get_by_id(req["doc_id"]) if not e: return get_data_error_result(message="Document not found!") - if not settings.docStoreConn.delete({"id": req["chunk_ids"]}, search.index_name(current_user.id), doc.kb_id): - return get_data_error_result(message="Index updating failure") + if not settings.docStoreConn.delete({"id": req["chunk_ids"]}, + search.index_name(DocumentService.get_tenant_id(req["doc_id"])), + doc.kb_id): + return get_data_error_result(message="Chunk deleting failure") deleted_chunk_ids = req["chunk_ids"] chunk_number = len(deleted_chunk_ids) DocumentService.decrement_chunk_num(doc.id, doc.kb_id, 1, chunk_number, 0) for cid in deleted_chunk_ids: - if STORAGE_IMPL.obj_exist(doc.kb_id, cid): - STORAGE_IMPL.rm(doc.kb_id, cid) + if settings.STORAGE_IMPL.obj_exist(doc.kb_id, cid): + settings.STORAGE_IMPL.rm(doc.kb_id, cid) return get_json_result(data=True) except Exception as e: return server_error_response(e) @@ -224,11 +229,19 @@ def create(): "content_with_weight": req["content_with_weight"]} d["content_sm_ltks"] = rag_tokenizer.fine_grained_tokenize(d["content_ltks"]) d["important_kwd"] = req.get("important_kwd", []) - d["important_tks"] = rag_tokenizer.tokenize(" ".join(req.get("important_kwd", []))) + if not isinstance(d["important_kwd"], list): + return get_data_error_result(message="`important_kwd` is required to be a list") + d["important_tks"] = rag_tokenizer.tokenize(" ".join(d["important_kwd"])) d["question_kwd"] = req.get("question_kwd", []) - d["question_tks"] = rag_tokenizer.tokenize("\n".join(req.get("question_kwd", []))) + if not isinstance(d["question_kwd"], list): + return get_data_error_result(message="`question_kwd` is required to be a list") + d["question_tks"] = rag_tokenizer.tokenize("\n".join(d["question_kwd"])) d["create_time"] = str(datetime.datetime.now()).replace("T", " ")[:19] d["create_timestamp_flt"] = datetime.datetime.now().timestamp() + if "tag_feas" in req: + d["tag_feas"] = req["tag_feas"] + if "tag_feas" in req: + d["tag_feas"] = req["tag_feas"] try: e, doc = DocumentService.get_by_id(req["doc_id"]) @@ -275,14 +288,31 @@ def retrieval_test(): kb_ids = req["kb_id"] if isinstance(kb_ids, str): kb_ids = [kb_ids] + if not kb_ids: + return get_json_result(data=False, message='Please specify dataset firstly.', + code=RetCode.DATA_ERROR) + doc_ids = req.get("doc_ids", []) - similarity_threshold = float(req.get("similarity_threshold", 0.0)) - vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3)) use_kg = req.get("use_kg", False) top = int(req.get("top_k", 1024)) langs = req.get("cross_languages", []) tenant_ids = [] + if req.get("search_id", ""): + search_config = SearchService.get_detail(req.get("search_id", "")).get("search_config", {}) + meta_data_filter = search_config.get("meta_data_filter", {}) + metas = DocumentService.get_meta_by_kbs(kb_ids) + if meta_data_filter.get("method") == "auto": + chat_mdl = LLMBundle(current_user.id, LLMType.CHAT, llm_name=search_config.get("chat_id", "")) + filters = gen_meta_filter(chat_mdl, metas, question) + doc_ids.extend(meta_filter(metas, filters)) + if not doc_ids: + doc_ids = None + elif meta_data_filter.get("method") == "manual": + doc_ids.extend(meta_filter(metas, meta_data_filter["manual"])) + if not doc_ids: + doc_ids = None + try: tenants = UserTenantService.query(user_id=current_user.id) for kb_id in kb_ids: @@ -294,7 +324,7 @@ def retrieval_test(): else: return get_json_result( data=False, message='Only owner of knowledgebase authorized for this operation.', - code=settings.RetCode.OPERATING_ERROR) + code=RetCode.OPERATING_ERROR) e, kb = KnowledgebaseService.get_by_id(kb_ids[0]) if not e: @@ -314,13 +344,16 @@ def retrieval_test(): question += keyword_extraction(chat_mdl, question) labels = label_question(question, [kb]) - ranks = settings.retrievaler.retrieval(question, embd_mdl, tenant_ids, kb_ids, page, size, - similarity_threshold, vector_similarity_weight, top, - doc_ids, rerank_mdl=rerank_mdl, highlight=req.get("highlight"), + ranks = settings.retriever.retrieval(question, embd_mdl, tenant_ids, kb_ids, page, size, + float(req.get("similarity_threshold", 0.0)), + float(req.get("vector_similarity_weight", 0.3)), + top, + doc_ids, rerank_mdl=rerank_mdl, + highlight=req.get("highlight", False), rank_feature=labels ) if use_kg: - ck = settings.kg_retrievaler.retrieval(question, + ck = settings.kg_retriever.retrieval(question, tenant_ids, kb_ids, embd_mdl, @@ -336,7 +369,7 @@ def retrieval_test(): except Exception as e: if str(e).find("not_found") > 0: return get_json_result(data=False, message='No chunk found! Check the chunk status please!', - code=settings.RetCode.DATA_ERROR) + code=RetCode.DATA_ERROR) return server_error_response(e) @@ -350,7 +383,7 @@ def knowledge_graph(): "doc_ids": [doc_id], "knowledge_graph_kwd": ["graph", "mind_map"] } - sres = settings.retrievaler.search(req, search.index_name(tenant_id), kb_ids) + sres = settings.retriever.search(req, search.index_name(tenant_id), kb_ids) obj = {"graph": {}, "mind_map": {}} for id in sres.ids[:2]: ty = sres.field[id]["knowledge_graph_kwd"] diff --git a/api/apps/connector_app.py b/api/apps/connector_app.py new file mode 100644 index 00000000000..23965e617a2 --- /dev/null +++ b/api/apps/connector_app.py @@ -0,0 +1,295 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json +import logging +import time +import uuid +from html import escape +from typing import Any + +from flask import make_response, request +from flask_login import current_user, login_required +from google_auth_oauthlib.flow import Flow + +from api.db import InputType +from api.db.services.connector_service import ConnectorService, SyncLogsService +from api.utils.api_utils import get_data_error_result, get_json_result, validate_request +from common.constants import RetCode, TaskStatus +from common.data_source.config import GOOGLE_DRIVE_WEB_OAUTH_REDIRECT_URI, DocumentSource +from common.data_source.google_util.constant import GOOGLE_DRIVE_WEB_OAUTH_POPUP_TEMPLATE, GOOGLE_SCOPES +from common.misc_utils import get_uuid +from rag.utils.redis_conn import REDIS_CONN + + +@manager.route("/set", methods=["POST"]) # noqa: F821 +@login_required +def set_connector(): + req = request.json + if req.get("id"): + conn = {fld: req[fld] for fld in ["prune_freq", "refresh_freq", "config", "timeout_secs"] if fld in req} + ConnectorService.update_by_id(req["id"], conn) + else: + req["id"] = get_uuid() + conn = { + "id": req["id"], + "tenant_id": current_user.id, + "name": req["name"], + "source": req["source"], + "input_type": InputType.POLL, + "config": req["config"], + "refresh_freq": int(req.get("refresh_freq", 30)), + "prune_freq": int(req.get("prune_freq", 720)), + "timeout_secs": int(req.get("timeout_secs", 60 * 29)), + "status": TaskStatus.SCHEDULE, + } + conn["status"] = TaskStatus.SCHEDULE + ConnectorService.save(**conn) + + time.sleep(1) + e, conn = ConnectorService.get_by_id(req["id"]) + + return get_json_result(data=conn.to_dict()) + + +@manager.route("/list", methods=["GET"]) # noqa: F821 +@login_required +def list_connector(): + return get_json_result(data=ConnectorService.list(current_user.id)) + + +@manager.route("/", methods=["GET"]) # noqa: F821 +@login_required +def get_connector(connector_id): + e, conn = ConnectorService.get_by_id(connector_id) + if not e: + return get_data_error_result(message="Can't find this Connector!") + return get_json_result(data=conn.to_dict()) + + +@manager.route("//logs", methods=["GET"]) # noqa: F821 +@login_required +def list_logs(connector_id): + req = request.args.to_dict(flat=True) + arr, total = SyncLogsService.list_sync_tasks(connector_id, int(req.get("page", 1)), int(req.get("page_size", 15))) + return get_json_result(data={"total": total, "logs": arr}) + + +@manager.route("//resume", methods=["PUT"]) # noqa: F821 +@login_required +def resume(connector_id): + req = request.json + if req.get("resume"): + ConnectorService.resume(connector_id, TaskStatus.SCHEDULE) + else: + ConnectorService.resume(connector_id, TaskStatus.CANCEL) + return get_json_result(data=True) + + +@manager.route("//rebuild", methods=["PUT"]) # noqa: F821 +@login_required +@validate_request("kb_id") +def rebuild(connector_id): + req = request.json + err = ConnectorService.rebuild(req["kb_id"], connector_id, current_user.id) + if err: + return get_json_result(data=False, message=err, code=RetCode.SERVER_ERROR) + return get_json_result(data=True) + + +@manager.route("//rm", methods=["POST"]) # noqa: F821 +@login_required +def rm_connector(connector_id): + ConnectorService.resume(connector_id, TaskStatus.CANCEL) + ConnectorService.delete_by_id(connector_id) + return get_json_result(data=True) + + +GOOGLE_WEB_FLOW_STATE_PREFIX = "google_drive_web_flow_state" +GOOGLE_WEB_FLOW_RESULT_PREFIX = "google_drive_web_flow_result" +WEB_FLOW_TTL_SECS = 15 * 60 + + +def _web_state_cache_key(flow_id: str) -> str: + return f"{GOOGLE_WEB_FLOW_STATE_PREFIX}:{flow_id}" + + +def _web_result_cache_key(flow_id: str) -> str: + return f"{GOOGLE_WEB_FLOW_RESULT_PREFIX}:{flow_id}" + + +def _load_credentials(payload: str | dict[str, Any]) -> dict[str, Any]: + if isinstance(payload, dict): + return payload + try: + return json.loads(payload) + except json.JSONDecodeError as exc: # pragma: no cover - defensive + raise ValueError("Invalid Google credentials JSON.") from exc + + +def _get_web_client_config(credentials: dict[str, Any]) -> dict[str, Any]: + web_section = credentials.get("web") + if not isinstance(web_section, dict): + raise ValueError("Google OAuth JSON must include a 'web' client configuration to use browser-based authorization.") + return {"web": web_section} + + +def _render_web_oauth_popup(flow_id: str, success: bool, message: str): + status = "success" if success else "error" + auto_close = "window.close();" if success else "" + escaped_message = escape(message) + payload_json = json.dumps( + { + "type": "ragflow-google-drive-oauth", + "status": status, + "flowId": flow_id or "", + "message": message, + } + ) + html = GOOGLE_DRIVE_WEB_OAUTH_POPUP_TEMPLATE.format( + heading="Authorization complete" if success else "Authorization failed", + message=escaped_message, + payload_json=payload_json, + auto_close=auto_close, + ) + response = make_response(html, 200) + response.headers["Content-Type"] = "text/html; charset=utf-8" + return response + + +@manager.route("/google-drive/oauth/web/start", methods=["POST"]) # noqa: F821 +@login_required +@validate_request("credentials") +def start_google_drive_web_oauth(): + if not GOOGLE_DRIVE_WEB_OAUTH_REDIRECT_URI: + return get_json_result( + code=RetCode.SERVER_ERROR, + message="Google Drive OAuth redirect URI is not configured on the server.", + ) + + req = request.json or {} + raw_credentials = req.get("credentials", "") + try: + credentials = _load_credentials(raw_credentials) + except ValueError as exc: + return get_json_result(code=RetCode.ARGUMENT_ERROR, message=str(exc)) + + if credentials.get("refresh_token"): + return get_json_result( + code=RetCode.ARGUMENT_ERROR, + message="Uploaded credentials already include a refresh token.", + ) + + try: + client_config = _get_web_client_config(credentials) + except ValueError as exc: + return get_json_result(code=RetCode.ARGUMENT_ERROR, message=str(exc)) + + flow_id = str(uuid.uuid4()) + try: + flow = Flow.from_client_config(client_config, scopes=GOOGLE_SCOPES[DocumentSource.GOOGLE_DRIVE]) + flow.redirect_uri = GOOGLE_DRIVE_WEB_OAUTH_REDIRECT_URI + authorization_url, _ = flow.authorization_url( + access_type="offline", + include_granted_scopes="true", + prompt="consent", + state=flow_id, + ) + except Exception as exc: # pragma: no cover - defensive + logging.exception("Failed to create Google OAuth flow: %s", exc) + return get_json_result( + code=RetCode.SERVER_ERROR, + message="Failed to initialize Google OAuth flow. Please verify the uploaded client configuration.", + ) + + cache_payload = { + "user_id": current_user.id, + "client_config": client_config, + "created_at": int(time.time()), + } + REDIS_CONN.set_obj(_web_state_cache_key(flow_id), cache_payload, WEB_FLOW_TTL_SECS) + + return get_json_result( + data={ + "flow_id": flow_id, + "authorization_url": authorization_url, + "expires_in": WEB_FLOW_TTL_SECS, + } + ) + + +@manager.route("/google-drive/oauth/web/callback", methods=["GET"]) # noqa: F821 +def google_drive_web_oauth_callback(): + state_id = request.args.get("state") + error = request.args.get("error") + error_description = request.args.get("error_description") or error + + if not state_id: + return _render_web_oauth_popup("", False, "Missing OAuth state parameter.") + + state_cache = REDIS_CONN.get(_web_state_cache_key(state_id)) + if not state_cache: + return _render_web_oauth_popup(state_id, False, "Authorization session expired. Please restart from the main window.") + + state_obj = json.loads(state_cache) + client_config = state_obj.get("client_config") + if not client_config: + REDIS_CONN.delete(_web_state_cache_key(state_id)) + return _render_web_oauth_popup(state_id, False, "Authorization session was invalid. Please retry.") + + if error: + REDIS_CONN.delete(_web_state_cache_key(state_id)) + return _render_web_oauth_popup(state_id, False, error_description or "Authorization was cancelled.") + + code = request.args.get("code") + if not code: + return _render_web_oauth_popup(state_id, False, "Missing authorization code from Google.") + + try: + flow = Flow.from_client_config(client_config, scopes=GOOGLE_SCOPES[DocumentSource.GOOGLE_DRIVE]) + flow.redirect_uri = GOOGLE_DRIVE_WEB_OAUTH_REDIRECT_URI + flow.fetch_token(code=code) + except Exception as exc: # pragma: no cover - defensive + logging.exception("Failed to exchange Google OAuth code: %s", exc) + REDIS_CONN.delete(_web_state_cache_key(state_id)) + return _render_web_oauth_popup(state_id, False, "Failed to exchange tokens with Google. Please retry.") + + creds_json = flow.credentials.to_json() + result_payload = { + "user_id": state_obj.get("user_id"), + "credentials": creds_json, + } + REDIS_CONN.set_obj(_web_result_cache_key(state_id), result_payload, WEB_FLOW_TTL_SECS) + REDIS_CONN.delete(_web_state_cache_key(state_id)) + + return _render_web_oauth_popup(state_id, True, "Authorization completed successfully.") + + +@manager.route("/google-drive/oauth/web/result", methods=["POST"]) # noqa: F821 +@login_required +@validate_request("flow_id") +def poll_google_drive_web_result(): + req = request.json or {} + flow_id = req.get("flow_id") + cache_raw = REDIS_CONN.get(_web_result_cache_key(flow_id)) + if not cache_raw: + return get_json_result(code=RetCode.RUNNING, message="Authorization is still pending.") + + result = json.loads(cache_raw) + if result.get("user_id") != current_user.id: + return get_json_result(code=RetCode.PERMISSION_ERROR, message="You are not allowed to access this authorization result.") + + REDIS_CONN.delete(_web_result_cache_key(flow_id)) + return get_json_result(data={"credentials": result.get("credentials")}) diff --git a/api/apps/conversation_app.py b/api/apps/conversation_app.py index 5ba39716f8b..984e57caccd 100644 --- a/api/apps/conversation_app.py +++ b/api/apps/conversation_app.py @@ -15,24 +15,21 @@ # import json import re -import traceback +import logging from copy import deepcopy - -import trio from flask import Response, request from flask_login import current_user, login_required - -from api import settings -from api.db import LLMType from api.db.db_models import APIToken from api.db.services.conversation_service import ConversationService, structure_answer -from api.db.services.dialog_service import DialogService, ask, chat -from api.db.services.knowledgebase_service import KnowledgebaseService -from api.db.services.llm_service import LLMBundle, TenantService -from api.db.services.user_service import UserTenantService +from api.db.services.dialog_service import DialogService, ask, chat, gen_mindmap +from api.db.services.llm_service import LLMBundle +from api.db.services.search_service import SearchService +from api.db.services.tenant_llm_service import TenantLLMService +from api.db.services.user_service import TenantService, UserTenantService from api.utils.api_utils import get_data_error_result, get_json_result, server_error_response, validate_request -from graphrag.general.mind_map_extractor import MindMapExtractor -from rag.app.tag import label_question +from rag.prompts.template import load_prompt +from rag.prompts.generator import chunks_format +from common.constants import RetCode, LLMType @manager.route("/set", methods=["POST"]) # noqa: F821 @@ -65,7 +62,14 @@ def set_conversation(): e, dia = DialogService.get_by_id(req["dialog_id"]) if not e: return get_data_error_result(message="Dialog not found") - conv = {"id": conv_id, "dialog_id": req["dialog_id"], "name": name, "message": [{"role": "assistant", "content": dia.prompt_config["prologue"]}],"user_id": current_user.id} + conv = { + "id": conv_id, + "dialog_id": req["dialog_id"], + "name": name, + "message": [{"role": "assistant", "content": dia.prompt_config["prologue"]}], + "user_id": current_user.id, + "reference": [], + } ConversationService.save(**conv) return get_json_result(data=conv) except Exception as e: @@ -88,27 +92,12 @@ def get(): avatar = dialog[0].icon break else: - return get_json_result(data=False, message="Only owner of conversation authorized for this operation.", code=settings.RetCode.OPERATING_ERROR) - - def get_value(d, k1, k2): - return d.get(k1, d.get(k2)) + return get_json_result(data=False, message="Only owner of conversation authorized for this operation.", code=RetCode.OPERATING_ERROR) for ref in conv.reference: if isinstance(ref, list): continue - ref["chunks"] = [ - { - "id": get_value(ck, "chunk_id", "id"), - "content": get_value(ck, "content", "content_with_weight"), - "document_id": get_value(ck, "doc_id", "document_id"), - "document_name": get_value(ck, "docnm_kwd", "document_name"), - "dataset_id": get_value(ck, "kb_id", "dataset_id"), - "image_id": get_value(ck, "image_id", "img_id"), - "positions": get_value(ck, "positions", "position_int"), - "doc_type": get_value(ck, "doc_type", "doc_type_kwd"), - } - for ck in ref.get("chunks", []) - ] + ref["chunks"] = chunks_format(ref) conv = conv.to_dict() conv["avatar"] = avatar @@ -152,7 +141,7 @@ def rm(): if DialogService.query(tenant_id=tenant.tenant_id, id=conv.dialog_id): break else: - return get_json_result(data=False, message="Only owner of conversation authorized for this operation.", code=settings.RetCode.OPERATING_ERROR) + return get_json_result(data=False, message="Only owner of conversation authorized for this operation.", code=RetCode.OPERATING_ERROR) ConversationService.delete_by_id(cid) return get_json_result(data=True) except Exception as e: @@ -161,11 +150,11 @@ def rm(): @manager.route("/list", methods=["GET"]) # noqa: F821 @login_required -def list_convsersation(): +def list_conversation(): dialog_id = request.args["dialog_id"] try: if not DialogService.query(tenant_id=current_user.id, id=dialog_id): - return get_json_result(data=False, message="Only owner of dialog authorized for this operation.", code=settings.RetCode.OPERATING_ERROR) + return get_json_result(data=False, message="Only owner of dialog authorized for this operation.", code=RetCode.OPERATING_ERROR) convs = ConversationService.query(dialog_id=dialog_id, order_by=ConversationService.model.create_time, reverse=True) convs = [d.to_dict() for d in convs] @@ -187,6 +176,21 @@ def completion(): continue msg.append(m) message_id = msg[-1].get("id") + chat_model_id = req.get("llm_id", "") + req.pop("llm_id", None) + + chat_model_config = {} + for model_config in [ + "temperature", + "top_p", + "frequency_penalty", + "presence_penalty", + "max_tokens", + ]: + config = req.get(model_config) + if config: + chat_model_config[model_config] = config + try: e, conv = ConversationService.get_by_id(req["conversation_id"]) if not e: @@ -200,41 +204,28 @@ def completion(): if not conv.reference: conv.reference = [] - else: - - def get_value(d, k1, k2): - return d.get(k1, d.get(k2)) - - for ref in conv.reference: - if isinstance(ref, list): - continue - ref["chunks"] = [ - { - "id": get_value(ck, "chunk_id", "id"), - "content": get_value(ck, "content", "content_with_weight"), - "document_id": get_value(ck, "doc_id", "document_id"), - "document_name": get_value(ck, "docnm_kwd", "document_name"), - "dataset_id": get_value(ck, "kb_id", "dataset_id"), - "image_id": get_value(ck, "image_id", "img_id"), - "positions": get_value(ck, "positions", "position_int"), - "doc_type": get_value(ck, "doc_type_kwd", "doc_type_kwd"), - } - for ck in ref.get("chunks", []) - ] - - if not conv.reference: - conv.reference = [] + conv.reference = [r for r in conv.reference if r] conv.reference.append({"chunks": [], "doc_aggs": []}) + if chat_model_id: + if not TenantLLMService.get_api_key(tenant_id=dia.tenant_id, model_name=chat_model_id): + req.pop("chat_model_id", None) + req.pop("chat_model_config", None) + return get_data_error_result(message=f"Cannot use specified model {chat_model_id}.") + dia.llm_id = chat_model_id + dia.llm_setting = chat_model_config + + is_embedded = bool(chat_model_id) def stream(): nonlocal dia, msg, req, conv try: for ans in chat(dia, msg, True, **req): ans = structure_answer(conv, ans, message_id, conv.id) yield "data:" + json.dumps({"code": 0, "message": "", "data": ans}, ensure_ascii=False) + "\n\n" - ConversationService.update_by_id(conv.id, conv.to_dict()) + if not is_embedded: + ConversationService.update_by_id(conv.id, conv.to_dict()) except Exception as e: - traceback.print_exc() + logging.exception(e) yield "data:" + json.dumps({"code": 500, "message": str(e), "data": {"answer": "**ERROR**: " + str(e), "reference": []}}, ensure_ascii=False) + "\n\n" yield "data:" + json.dumps({"code": 0, "message": "", "data": True}, ensure_ascii=False) + "\n\n" @@ -250,7 +241,8 @@ def stream(): answer = None for ans in chat(dia, msg, **req): answer = structure_answer(conv, ans, message_id, conv.id) - ConversationService.update_by_id(conv.id, conv.to_dict()) + if not is_embedded: + ConversationService.update_by_id(conv.id, conv.to_dict()) break return get_json_result(data=answer) except Exception as e: @@ -346,10 +338,18 @@ def ask_about(): req = request.json uid = current_user.id + search_id = req.get("search_id", "") + search_app = None + search_config = {} + if search_id: + search_app = SearchService.get_detail(search_id) + if search_app: + search_config = search_app.get("search_config", {}) + def stream(): nonlocal req, uid try: - for ans in ask(req["question"], req["kb_ids"], uid): + for ans in ask(req["question"], req["kb_ids"], uid, search_config=search_config): yield "data:" + json.dumps({"code": 0, "message": "", "data": ans}, ensure_ascii=False) + "\n\n" except Exception as e: yield "data:" + json.dumps({"code": 500, "message": str(e), "data": {"answer": "**ERROR**: " + str(e), "reference": []}}, ensure_ascii=False) + "\n\n" @@ -368,18 +368,14 @@ def stream(): @validate_request("question", "kb_ids") def mindmap(): req = request.json - kb_ids = req["kb_ids"] - e, kb = KnowledgebaseService.get_by_id(kb_ids[0]) - if not e: - return get_data_error_result(message="Knowledgebase not found!") - - embd_mdl = LLMBundle(kb.tenant_id, LLMType.EMBEDDING, llm_name=kb.embd_id) - chat_mdl = LLMBundle(current_user.id, LLMType.CHAT) - question = req["question"] - ranks = settings.retrievaler.retrieval(question, embd_mdl, kb.tenant_id, kb_ids, 1, 12, 0.3, 0.3, aggs=False, rank_feature=label_question(question, [kb])) - mindmap = MindMapExtractor(chat_mdl) - mind_map = trio.run(mindmap, [c["content_with_weight"] for c in ranks["chunks"]]) - mind_map = mind_map.output + search_id = req.get("search_id", "") + search_app = SearchService.get_detail(search_id) if search_id else {} + search_config = search_app.get("search_config", {}) if search_app else {} + kb_ids = search_config.get("kb_ids", []) + kb_ids.extend(req["kb_ids"]) + kb_ids = list(set(kb_ids)) + + mind_map = gen_mindmap(req["question"], kb_ids, search_app.get("tenant_id", current_user.id), search_config) if "error" in mind_map: return server_error_response(Exception(mind_map["error"])) return get_json_result(data=mind_map) @@ -390,41 +386,22 @@ def mindmap(): @validate_request("question") def related_questions(): req = request.json + + search_id = req.get("search_id", "") + search_config = {} + if search_id: + if search_app := SearchService.get_detail(search_id): + search_config = search_app.get("search_config", {}) + question = req["question"] - chat_mdl = LLMBundle(current_user.id, LLMType.CHAT) - prompt = """ -Role: You are an AI language model assistant tasked with generating 5-10 related questions based on a user’s original query. These questions should help expand the search query scope and improve search relevance. - -Instructions: - Input: You are provided with a user’s question. - Output: Generate 5-10 alternative questions that are related to the original user question. These alternatives should help retrieve a broader range of relevant documents from a vector database. - Context: Focus on rephrasing the original question in different ways, making sure the alternative questions are diverse but still connected to the topic of the original query. Do not create overly obscure, irrelevant, or unrelated questions. - Fallback: If you cannot generate any relevant alternatives, do not return any questions. - Guidance: - 1. Each alternative should be unique but still relevant to the original query. - 2. Keep the phrasing clear, concise, and easy to understand. - 3. Avoid overly technical jargon or specialized terms unless directly relevant. - 4. Ensure that each question contributes towards improving search results by broadening the search angle, not narrowing it. - -Example: -Original Question: What are the benefits of electric vehicles? - -Alternative Questions: - 1. How do electric vehicles impact the environment? - 2. What are the advantages of owning an electric car? - 3. What is the cost-effectiveness of electric vehicles? - 4. How do electric vehicles compare to traditional cars in terms of fuel efficiency? - 5. What are the environmental benefits of switching to electric cars? - 6. How do electric vehicles help reduce carbon emissions? - 7. Why are electric vehicles becoming more popular? - 8. What are the long-term savings of using electric vehicles? - 9. How do electric vehicles contribute to sustainability? - 10. What are the key benefits of electric vehicles for consumers? - -Reason: - Rephrasing the original query into multiple alternative questions helps the user explore different aspects of their search topic, improving the quality of search results. - These questions guide the search engine to provide a more comprehensive set of relevant documents. -""" + + chat_id = search_config.get("chat_id", "") + chat_mdl = LLMBundle(current_user.id, LLMType.CHAT, chat_id) + + gen_conf = search_config.get("llm_setting", {"temperature": 0.9}) + if "parameter" in gen_conf: + del gen_conf["parameter"] + prompt = load_prompt("related_question") ans = chat_mdl.chat( prompt, [ @@ -436,6 +413,6 @@ def related_questions(): """, } ], - {"temperature": 0.9}, + gen_conf, ) return get_json_result(data=[re.sub(r"^[0-9]\. ", "", a) for a in ans.split("\n") if re.match(r"^[0-9]\. ", a)]) diff --git a/api/apps/dialog_app.py b/api/apps/dialog_app.py index 2c4bd725c47..99f70056891 100644 --- a/api/apps/dialog_app.py +++ b/api/apps/dialog_app.py @@ -16,14 +16,15 @@ from flask import request from flask_login import login_required, current_user +from api.db.services import duplicate_name from api.db.services.dialog_service import DialogService -from api.db import StatusEnum -from api.db.services.llm_service import TenantLLMService +from common.constants import StatusEnum +from api.db.services.tenant_llm_service import TenantLLMService from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.user_service import TenantService, UserTenantService -from api import settings from api.utils.api_utils import server_error_response, get_data_error_result, validate_request -from api.utils import get_uuid +from common.misc_utils import get_uuid +from common.constants import RetCode from api.utils.api_utils import get_json_result @@ -32,8 +33,24 @@ @login_required def set_dialog(): req = request.json - dialog_id = req.get("dialog_id") + dialog_id = req.get("dialog_id", "") + is_create = not dialog_id name = req.get("name", "New Dialog") + if not isinstance(name, str): + return get_data_error_result(message="Dialog name must be string.") + if name.strip() == "": + return get_data_error_result(message="Dialog name can't be empty.") + if len(name.encode("utf-8")) > 255: + return get_data_error_result(message=f"Dialog name length is {len(name)} which is larger than 255") + + if is_create and DialogService.query(tenant_id=current_user.id, name=name.strip()): + name = name.strip() + name = duplicate_name( + DialogService.query, + name=name, + tenant_id=current_user.id, + status=StatusEnum.VALID.value) + description = req.get("description", "A helpful dialog") icon = req.get("icon", "") top_n = req.get("top_n", 6) @@ -44,17 +61,19 @@ def set_dialog(): similarity_threshold = req.get("similarity_threshold", 0.1) vector_similarity_weight = req.get("vector_similarity_weight", 0.3) llm_setting = req.get("llm_setting", {}) + meta_data_filter = req.get("meta_data_filter", {}) prompt_config = req["prompt_config"] - - if not req.get("kb_ids", []) and not prompt_config.get("tavily_api_key") and "{knowledge}" in prompt_config['system']: - return get_data_error_result(message="Please remove `{knowledge}` in system prompt since no knowledge base/Tavily used here.") - for p in prompt_config["parameters"]: - if p["optional"]: - continue - if prompt_config["system"].find("{%s}" % p["key"]) < 0: - return get_data_error_result( - message="Parameter '{}' is not used".format(p["key"])) + if not is_create: + if not req.get("kb_ids", []) and not prompt_config.get("tavily_api_key") and "{knowledge}" in prompt_config['system']: + return get_data_error_result(message="Please remove `{knowledge}` in system prompt since no knowledge base / Tavily used here.") + + for p in prompt_config["parameters"]: + if p["optional"]: + continue + if prompt_config["system"].find("{%s}" % p["key"]) < 0: + return get_data_error_result( + message="Parameter '{}' is not used".format(p["key"])) try: e, tenant = TenantService.get_by_id(current_user.id) @@ -77,6 +96,7 @@ def set_dialog(): "llm_id": llm_id, "llm_setting": llm_setting, "prompt_config": prompt_config, + "meta_data_filter": meta_data_filter, "top_n": top_n, "top_k": top_k, "rerank_id": rerank_id, @@ -147,6 +167,43 @@ def list_dialogs(): return server_error_response(e) +@manager.route('/next', methods=['POST']) # noqa: F821 +@login_required +def list_dialogs_next(): + keywords = request.args.get("keywords", "") + page_number = int(request.args.get("page", 0)) + items_per_page = int(request.args.get("page_size", 0)) + parser_id = request.args.get("parser_id") + orderby = request.args.get("orderby", "create_time") + if request.args.get("desc", "true").lower() == "false": + desc = False + else: + desc = True + + req = request.get_json() + owner_ids = req.get("owner_ids", []) + try: + if not owner_ids: + # tenants = TenantService.get_joined_tenants_by_user_id(current_user.id) + # tenants = [tenant["tenant_id"] for tenant in tenants] + tenants = [] # keep it here + dialogs, total = DialogService.get_by_tenant_ids( + tenants, current_user.id, page_number, + items_per_page, orderby, desc, keywords, parser_id) + else: + tenants = owner_ids + dialogs, total = DialogService.get_by_tenant_ids( + tenants, current_user.id, 0, + 0, orderby, desc, keywords, parser_id) + dialogs = [dialog for dialog in dialogs if dialog["tenant_id"] in tenants] + total = len(dialogs) + if page_number and items_per_page: + dialogs = dialogs[(page_number-1)*items_per_page:page_number*items_per_page] + return get_json_result(data={"dialogs": dialogs, "total": total}) + except Exception as e: + return server_error_response(e) + + @manager.route('/rm', methods=['POST']) # noqa: F821 @login_required @validate_request("dialog_ids") @@ -162,7 +219,7 @@ def rm(): else: return get_json_result( data=False, message='Only owner of dialog authorized for this operation.', - code=settings.RetCode.OPERATING_ERROR) + code=RetCode.OPERATING_ERROR) dialog_list.append({"id": id,"status":StatusEnum.INVALID.value}) DialogService.update_many_by_id(dialog_list) return get_json_result(data=True) diff --git a/api/apps/document_app.py b/api/apps/document_app.py index 68a76394f54..c2e37598e92 100644 --- a/api/apps/document_app.py +++ b/api/apps/document_app.py @@ -17,34 +17,37 @@ import os.path import pathlib import re +from pathlib import Path import flask from flask import request from flask_login import current_user, login_required -from api import settings +from api.common.check_team_permission import check_kb_team_permission from api.constants import FILE_NAME_LEN_LIMIT, IMG_BASE64_PREFIX -from api.db import VALID_FILE_TYPES, VALID_TASK_STATUS, FileSource, FileType, ParserType, TaskStatus -from api.db.db_models import File, Task +from api.db import VALID_FILE_TYPES, FileType +from api.db.db_models import Task from api.db.services import duplicate_name from api.db.services.document_service import DocumentService, doc_upload_and_parse from api.db.services.file2document_service import File2DocumentService from api.db.services.file_service import FileService from api.db.services.knowledgebase_service import KnowledgebaseService -from api.db.services.task_service import TaskService, queue_tasks +from api.db.services.task_service import TaskService, cancel_all_task_of from api.db.services.user_service import UserTenantService -from api.utils import get_uuid +from common.misc_utils import get_uuid from api.utils.api_utils import ( get_data_error_result, get_json_result, server_error_response, validate_request, ) -from api.utils.file_utils import filename_type, get_project_base_directory, thumbnail -from api.utils.web_utils import html2pdf, is_valid_url +from api.utils.file_utils import filename_type, thumbnail +from common.file_utils import get_project_base_directory +from common.constants import RetCode, VALID_TASK_STATUS, ParserType, TaskStatus +from api.utils.web_utils import CONTENT_TYPE_MAP, html2pdf, is_valid_url from deepdoc.parser.html_parser import RAGFlowHtmlParser -from rag.nlp import search -from rag.utils.storage_factory import STORAGE_IMPL +from rag.nlp import search, rag_tokenizer +from common import settings @manager.route("/upload", methods=["POST"]) # noqa: F821 @@ -53,27 +56,29 @@ def upload(): kb_id = request.form.get("kb_id") if not kb_id: - return get_json_result(data=False, message='Lack of "KB ID"', code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message='Lack of "KB ID"', code=RetCode.ARGUMENT_ERROR) if "file" not in request.files: - return get_json_result(data=False, message="No file part!", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message="No file part!", code=RetCode.ARGUMENT_ERROR) file_objs = request.files.getlist("file") for file_obj in file_objs: if file_obj.filename == "": - return get_json_result(data=False, message="No file selected!", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message="No file selected!", code=RetCode.ARGUMENT_ERROR) if len(file_obj.filename.encode("utf-8")) > FILE_NAME_LEN_LIMIT: - return get_json_result(data=False, message=f"File name must be {FILE_NAME_LEN_LIMIT} bytes or less.", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message=f"File name must be {FILE_NAME_LEN_LIMIT} bytes or less.", code=RetCode.ARGUMENT_ERROR) e, kb = KnowledgebaseService.get_by_id(kb_id) if not e: raise LookupError("Can't find this knowledgebase!") - err, files = FileService.upload_document(kb, file_objs, current_user.id) + if not check_kb_team_permission(kb, current_user.id): + return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) + err, files = FileService.upload_document(kb, file_objs, current_user.id) if err: - return get_json_result(data=files, message="\n".join(err), code=settings.RetCode.SERVER_ERROR) + return get_json_result(data=files, message="\n".join(err), code=RetCode.SERVER_ERROR) if not files: - return get_json_result(data=files, message="There seems to be an issue with your file format. Please verify it is correct and not corrupted.", code=settings.RetCode.DATA_ERROR) + return get_json_result(data=files, message="There seems to be an issue with your file format. Please verify it is correct and not corrupted.", code=RetCode.DATA_ERROR) files = [f[0] for f in files] # remove the blob return get_json_result(data=files) @@ -85,14 +90,16 @@ def upload(): def web_crawl(): kb_id = request.form.get("kb_id") if not kb_id: - return get_json_result(data=False, message='Lack of "KB ID"', code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message='Lack of "KB ID"', code=RetCode.ARGUMENT_ERROR) name = request.form.get("name") url = request.form.get("url") if not is_valid_url(url): - return get_json_result(data=False, message="The URL format is invalid", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message="The URL format is invalid", code=RetCode.ARGUMENT_ERROR) e, kb = KnowledgebaseService.get_by_id(kb_id) if not e: raise LookupError("Can't find this knowledgebase!") + if check_kb_team_permission(kb, current_user.id): + return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) blob = html2pdf(url) if not blob: @@ -111,9 +118,9 @@ def web_crawl(): raise RuntimeError("This type of file has not been supported yet!") location = filename - while STORAGE_IMPL.obj_exist(kb_id, location): + while settings.STORAGE_IMPL.obj_exist(kb_id, location): location += "_" - STORAGE_IMPL.put(kb_id, location, blob) + settings.STORAGE_IMPL.put(kb_id, location, blob) doc = { "id": get_uuid(), "kb_id": kb.id, @@ -125,6 +132,7 @@ def web_crawl(): "location": location, "size": len(blob), "thumbnail": thumbnail(filename, blob), + "suffix": Path(filename).suffix.lstrip("."), } if doc["type"] == FileType.VISUAL: doc["parser_id"] = ParserType.PICTURE.value @@ -148,12 +156,12 @@ def create(): req = request.json kb_id = req["kb_id"] if not kb_id: - return get_json_result(data=False, message='Lack of "KB ID"', code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message='Lack of "KB ID"', code=RetCode.ARGUMENT_ERROR) if len(req["name"].encode("utf-8")) > FILE_NAME_LEN_LIMIT: - return get_json_result(data=False, message=f"File name must be {FILE_NAME_LEN_LIMIT} bytes or less.", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message=f"File name must be {FILE_NAME_LEN_LIMIT} bytes or less.", code=RetCode.ARGUMENT_ERROR) if req["name"].strip() == "": - return get_json_result(data=False, message="File name can't be empty.", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message="File name can't be empty.", code=RetCode.ARGUMENT_ERROR) req["name"] = req["name"].strip() try: @@ -164,19 +172,35 @@ def create(): if DocumentService.query(name=req["name"], kb_id=kb_id): return get_data_error_result(message="Duplicated document name in the same knowledgebase.") + kb_root_folder = FileService.get_kb_folder(kb.tenant_id) + if not kb_root_folder: + return get_data_error_result(message="Cannot find the root folder.") + kb_folder = FileService.new_a_file_from_kb( + kb.tenant_id, + kb.name, + kb_root_folder["id"], + ) + if not kb_folder: + return get_data_error_result(message="Cannot find the kb folder for this file.") + doc = DocumentService.insert( { "id": get_uuid(), "kb_id": kb.id, "parser_id": kb.parser_id, + "pipeline_id": kb.pipeline_id, "parser_config": kb.parser_config, "created_by": current_user.id, "type": FileType.VIRTUAL, "name": req["name"], + "suffix": Path(req["name"]).suffix.lstrip("."), "location": "", "size": 0, } ) + + FileService.add_file_from_kb(doc.to_dict(), kb_folder["id"], kb.tenant_id) + return get_json_result(data=doc.to_json()) except Exception as e: return server_error_response(e) @@ -187,13 +211,13 @@ def create(): def list_docs(): kb_id = request.args.get("kb_id") if not kb_id: - return get_json_result(data=False, message='Lack of "KB ID"', code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message='Lack of "KB ID"', code=RetCode.ARGUMENT_ERROR) tenants = UserTenantService.query(user_id=current_user.id) for tenant in tenants: if KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id): break else: - return get_json_result(data=False, message="Only owner of knowledgebase authorized for this operation.", code=settings.RetCode.OPERATING_ERROR) + return get_json_result(data=False, message="Only owner of knowledgebase authorized for this operation.", code=RetCode.OPERATING_ERROR) keywords = request.args.get("keywords", "") page_number = int(request.args.get("page", 0)) @@ -203,6 +227,8 @@ def list_docs(): desc = False else: desc = True + create_time_from = int(request.args.get("create_time_from", 0)) + create_time_to = int(request.args.get("create_time_to", 0)) req = request.get_json() @@ -218,18 +244,68 @@ def list_docs(): if invalid_types: return get_data_error_result(message=f"Invalid filter conditions: {', '.join(invalid_types)} type{'s' if len(invalid_types) > 1 else ''}") + suffix = req.get("suffix", []) + try: - docs, tol = DocumentService.get_by_kb_id(kb_id, page_number, items_per_page, orderby, desc, keywords, run_status, types) + docs, tol = DocumentService.get_by_kb_id(kb_id, page_number, items_per_page, orderby, desc, keywords, run_status, types, suffix) + + if create_time_from or create_time_to: + filtered_docs = [] + for doc in docs: + doc_create_time = doc.get("create_time", 0) + if (create_time_from == 0 or doc_create_time >= create_time_from) and (create_time_to == 0 or doc_create_time <= create_time_to): + filtered_docs.append(doc) + docs = filtered_docs for doc_item in docs: if doc_item["thumbnail"] and not doc_item["thumbnail"].startswith(IMG_BASE64_PREFIX): doc_item["thumbnail"] = f"/v1/document/image/{kb_id}-{doc_item['thumbnail']}" + if doc_item.get("source_type"): + doc_item["source_type"] = doc_item["source_type"].split("/")[0] return get_json_result(data={"total": tol, "docs": docs}) except Exception as e: return server_error_response(e) +@manager.route("/filter", methods=["POST"]) # noqa: F821 +@login_required +def get_filter(): + req = request.get_json() + + kb_id = req.get("kb_id") + if not kb_id: + return get_json_result(data=False, message='Lack of "KB ID"', code=RetCode.ARGUMENT_ERROR) + tenants = UserTenantService.query(user_id=current_user.id) + for tenant in tenants: + if KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id): + break + else: + return get_json_result(data=False, message="Only owner of knowledgebase authorized for this operation.", code=RetCode.OPERATING_ERROR) + + keywords = req.get("keywords", "") + + suffix = req.get("suffix", []) + + run_status = req.get("run_status", []) + if run_status: + invalid_status = {s for s in run_status if s not in VALID_TASK_STATUS} + if invalid_status: + return get_data_error_result(message=f"Invalid filter run status conditions: {', '.join(invalid_status)}") + + types = req.get("types", []) + if types: + invalid_types = {t for t in types if t not in VALID_FILE_TYPES} + if invalid_types: + return get_data_error_result(message=f"Invalid filter conditions: {', '.join(invalid_types)} type{'s' if len(invalid_types) > 1 else ''}") + + try: + filter, total = DocumentService.get_filter_by_kb_id(kb_id, keywords, run_status, types, suffix) + return get_json_result(data={"total": total, "filter": filter}) + except Exception as e: + return server_error_response(e) + + @manager.route("/infos", methods=["POST"]) # noqa: F821 @login_required def docinfos(): @@ -237,7 +313,7 @@ def docinfos(): doc_ids = req["doc_ids"] for doc_id in doc_ids: if not DocumentService.accessible(doc_id, current_user.id): - return get_json_result(data=False, message="No authorization.", code=settings.RetCode.AUTHENTICATION_ERROR) + return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) docs = DocumentService.get_by_ids(doc_ids) return get_json_result(data=list(docs.dicts())) @@ -245,9 +321,9 @@ def docinfos(): @manager.route("/thumbnails", methods=["GET"]) # noqa: F821 # @login_required def thumbnails(): - doc_ids = request.args.get("doc_ids").split(",") + doc_ids = request.args.getlist("doc_ids") if not doc_ids: - return get_json_result(data=False, message='Lack of "Document ID"', code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message='Lack of "Document ID"', code=RetCode.ARGUMENT_ERROR) try: docs = DocumentService.get_thumbnails(doc_ids) @@ -263,31 +339,42 @@ def thumbnails(): @manager.route("/change_status", methods=["POST"]) # noqa: F821 @login_required -@validate_request("doc_id", "status") +@validate_request("doc_ids", "status") def change_status(): - req = request.json - if str(req["status"]) not in ["0", "1"]: - return get_json_result(data=False, message='"Status" must be either 0 or 1!', code=settings.RetCode.ARGUMENT_ERROR) + req = request.get_json() + doc_ids = req.get("doc_ids", []) + status = str(req.get("status", "")) - if not DocumentService.accessible(req["doc_id"], current_user.id): - return get_json_result(data=False, message="No authorization.", code=settings.RetCode.AUTHENTICATION_ERROR) + if status not in ["0", "1"]: + return get_json_result(data=False, message='"Status" must be either 0 or 1!', code=RetCode.ARGUMENT_ERROR) - try: - e, doc = DocumentService.get_by_id(req["doc_id"]) - if not e: - return get_data_error_result(message="Document not found!") - e, kb = KnowledgebaseService.get_by_id(doc.kb_id) - if not e: - return get_data_error_result(message="Can't find this knowledgebase!") + result = {} + for doc_id in doc_ids: + if not DocumentService.accessible(doc_id, current_user.id): + result[doc_id] = {"error": "No authorization."} + continue - if not DocumentService.update_by_id(req["doc_id"], {"status": str(req["status"])}): - return get_data_error_result(message="Database error (Document update)!") + try: + e, doc = DocumentService.get_by_id(doc_id) + if not e: + result[doc_id] = {"error": "No authorization."} + continue + e, kb = KnowledgebaseService.get_by_id(doc.kb_id) + if not e: + result[doc_id] = {"error": "Can't find this knowledgebase!"} + continue + if not DocumentService.update_by_id(doc_id, {"status": str(status)}): + result[doc_id] = {"error": "Database error (Document update)!"} + continue + + status_int = int(status) + if not settings.docStoreConn.update({"doc_id": doc_id}, {"available_int": status_int}, search.index_name(kb.tenant_id), doc.kb_id): + result[doc_id] = {"error": "Database error (docStore update)!"} + result[doc_id] = {"status": status} + except Exception as e: + result[doc_id] = {"error": f"Internal server error: {str(e)}"} - status = int(req["status"]) - settings.docStoreConn.update({"doc_id": req["doc_id"]}, {"available_int": status}, search.index_name(kb.tenant_id), doc.kb_id) - return get_json_result(data=True) - except Exception as e: - return server_error_response(e) + return get_json_result(data=result) @manager.route("/rm", methods=["POST"]) # noqa: F821 @@ -301,50 +388,12 @@ def rm(): for doc_id in doc_ids: if not DocumentService.accessible4deletion(doc_id, current_user.id): - return get_json_result(data=False, message="No authorization.", code=settings.RetCode.AUTHENTICATION_ERROR) - - root_folder = FileService.get_root_folder(current_user.id) - pf_id = root_folder["id"] - FileService.init_knowledgebase_docs(pf_id, current_user.id) - errors = "" - kb_table_num_map = {} - for doc_id in doc_ids: - try: - e, doc = DocumentService.get_by_id(doc_id) - if not e: - return get_data_error_result(message="Document not found!") - tenant_id = DocumentService.get_tenant_id(doc_id) - if not tenant_id: - return get_data_error_result(message="Tenant not found!") + return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) - b, n = File2DocumentService.get_storage_address(doc_id=doc_id) - - TaskService.filter_delete([Task.doc_id == doc_id]) - if not DocumentService.remove_document(doc, tenant_id): - return get_data_error_result(message="Database error (Document removal)!") - - f2d = File2DocumentService.get_by_document_id(doc_id) - deleted_file_count = 0 - if f2d: - deleted_file_count = FileService.filter_delete([File.source_type == FileSource.KNOWLEDGEBASE, File.id == f2d[0].file_id]) - File2DocumentService.delete_by_document_id(doc_id) - if deleted_file_count > 0: - STORAGE_IMPL.rm(b, n) - - doc_parser = doc.parser_id - if doc_parser == ParserType.TABLE: - kb_id = doc.kb_id - if kb_id not in kb_table_num_map: - counts = DocumentService.count_by_kb_id(kb_id=kb_id, keywords="", run_status=[TaskStatus.DONE], types=[]) - kb_table_num_map[kb_id] = counts - kb_table_num_map[kb_id] -= 1 - if kb_table_num_map[kb_id] <= 0: - KnowledgebaseService.delete_field_map(kb_id) - except Exception as e: - errors += str(e) + errors = FileService.delete_docs(doc_ids, current_user.id) if errors: - return get_json_result(data=False, message=errors, code=settings.RetCode.SERVER_ERROR) + return get_json_result(data=False, message=errors, code=RetCode.SERVER_ERROR) return get_json_result(data=True) @@ -356,7 +405,7 @@ def run(): req = request.json for doc_id in req["doc_ids"]: if not DocumentService.accessible(doc_id, current_user.id): - return get_json_result(data=False, message="No authorization.", code=settings.RetCode.AUTHENTICATION_ERROR) + return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) try: kb_table_num_map = {} for id in req["doc_ids"]: @@ -365,35 +414,31 @@ def run(): info["progress_msg"] = "" info["chunk_num"] = 0 info["token_num"] = 0 - DocumentService.update_by_id(id, info) + tenant_id = DocumentService.get_tenant_id(id) if not tenant_id: return get_data_error_result(message="Tenant not found!") e, doc = DocumentService.get_by_id(id) if not e: return get_data_error_result(message="Document not found!") + + if str(req["run"]) == TaskStatus.CANCEL.value: + if str(doc.run) == TaskStatus.RUNNING.value: + cancel_all_task_of(id) + else: + return get_data_error_result(message="Cannot cancel a task that is not in RUNNING status") + if all([("delete" not in req or req["delete"]), str(req["run"]) == TaskStatus.RUNNING.value, str(doc.run) == TaskStatus.DONE.value]): + DocumentService.clear_chunk_num_when_rerun(doc.id) + + DocumentService.update_by_id(id, info) if req.get("delete", False): TaskService.filter_delete([Task.doc_id == id]) if settings.docStoreConn.indexExist(search.index_name(tenant_id), doc.kb_id): settings.docStoreConn.delete({"doc_id": id}, search.index_name(tenant_id), doc.kb_id) if str(req["run"]) == TaskStatus.RUNNING.value: - e, doc = DocumentService.get_by_id(id) doc = doc.to_dict() - doc["tenant_id"] = tenant_id - - doc_parser = doc.get("parser_id", ParserType.NAIVE) - if doc_parser == ParserType.TABLE: - kb_id = doc.get("kb_id") - if not kb_id: - continue - if kb_id not in kb_table_num_map: - count = DocumentService.count_by_kb_id(kb_id=kb_id, keywords="", run_status=[TaskStatus.DONE], types=[]) - kb_table_num_map[kb_id] = count - if kb_table_num_map[kb_id] <= 0: - KnowledgebaseService.delete_field_map(kb_id) - bucket, name = File2DocumentService.get_storage_address(doc_id=doc["id"]) - queue_tasks(doc, bucket, name, 0) + DocumentService.run(tenant_id, doc, kb_table_num_map) return get_json_result(data=True) except Exception as e: @@ -406,15 +451,15 @@ def run(): def rename(): req = request.json if not DocumentService.accessible(req["doc_id"], current_user.id): - return get_json_result(data=False, message="No authorization.", code=settings.RetCode.AUTHENTICATION_ERROR) + return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) try: e, doc = DocumentService.get_by_id(req["doc_id"]) if not e: return get_data_error_result(message="Document not found!") if pathlib.Path(req["name"].lower()).suffix != pathlib.Path(doc.name.lower()).suffix: - return get_json_result(data=False, message="The extension of file can't be changed", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message="The extension of file can't be changed", code=RetCode.ARGUMENT_ERROR) if len(req["name"].encode("utf-8")) > FILE_NAME_LEN_LIMIT: - return get_json_result(data=False, message=f"File name must be {FILE_NAME_LEN_LIMIT} bytes or less.", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message=f"File name must be {FILE_NAME_LEN_LIMIT} bytes or less.", code=RetCode.ARGUMENT_ERROR) for d in DocumentService.query(name=req["name"], kb_id=doc.kb_id): if d.name == req["name"]: @@ -428,6 +473,21 @@ def rename(): e, file = FileService.get_by_id(informs[0].file_id) FileService.update_by_id(file.id, {"name": req["name"]}) + tenant_id = DocumentService.get_tenant_id(req["doc_id"]) + title_tks = rag_tokenizer.tokenize(req["name"]) + es_body = { + "docnm_kwd": req["name"], + "title_tks": title_tks, + "title_sm_tks": rag_tokenizer.fine_grained_tokenize(title_tks), + } + if settings.docStoreConn.indexExist(search.index_name(tenant_id), doc.kb_id): + settings.docStoreConn.update( + {"doc_id": req["doc_id"]}, + es_body, + search.index_name(tenant_id), + doc.kb_id, + ) + return get_json_result(data=True) except Exception as e: return server_error_response(e) @@ -442,14 +502,16 @@ def get(doc_id): return get_data_error_result(message="Document not found!") b, n = File2DocumentService.get_storage_address(doc_id=doc_id) - response = flask.make_response(STORAGE_IMPL.get(b, n)) + response = flask.make_response(settings.STORAGE_IMPL.get(b, n)) - ext = re.search(r"\.([^.]+)$", doc.name) + ext = re.search(r"\.([^.]+)$", doc.name.lower()) + ext = ext.group(1) if ext else None if ext: if doc.type == FileType.VISUAL.value: - response.headers.set("Content-Type", "image/%s" % ext.group(1)) + content_type = CONTENT_TYPE_MAP.get(ext, f"image/{ext}") else: - response.headers.set("Content-Type", "application/%s" % ext.group(1)) + content_type = CONTENT_TYPE_MAP.get(ext, f"application/{ext}") + response.headers.set("Content-Type", content_type) return response except Exception as e: return server_error_response(e) @@ -457,33 +519,24 @@ def get(doc_id): @manager.route("/change_parser", methods=["POST"]) # noqa: F821 @login_required -@validate_request("doc_id", "parser_id") +@validate_request("doc_id") def change_parser(): - req = request.json + req = request.json if not DocumentService.accessible(req["doc_id"], current_user.id): - return get_json_result(data=False, message="No authorization.", code=settings.RetCode.AUTHENTICATION_ERROR) - try: - e, doc = DocumentService.get_by_id(req["doc_id"]) - if not e: - return get_data_error_result(message="Document not found!") - if doc.parser_id.lower() == req["parser_id"].lower(): - if "parser_config" in req: - if req["parser_config"] == doc.parser_config: - return get_json_result(data=True) - else: - return get_json_result(data=True) + return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) - if (doc.type == FileType.VISUAL and req["parser_id"] != "picture") or (re.search(r"\.(ppt|pptx|pages)$", doc.name) and req["parser_id"] != "presentation"): - return get_data_error_result(message="Not supported yet!") + e, doc = DocumentService.get_by_id(req["doc_id"]) + if not e: + return get_data_error_result(message="Document not found!") - e = DocumentService.update_by_id(doc.id, {"parser_id": req["parser_id"], "progress": 0, "progress_msg": "", "run": TaskStatus.UNSTART.value}) + def reset_doc(): + nonlocal doc + e = DocumentService.update_by_id(doc.id, {"pipeline_id": req["pipeline_id"], "parser_id": req["parser_id"], "progress": 0, "progress_msg": "", "run": TaskStatus.UNSTART.value}) if not e: return get_data_error_result(message="Document not found!") - if "parser_config" in req: - DocumentService.update_parser_config(doc.id, req["parser_config"]) if doc.token_num > 0: - e = DocumentService.increment_chunk_num(doc.id, doc.kb_id, doc.token_num * -1, doc.chunk_num * -1, doc.process_duation * -1) + e = DocumentService.increment_chunk_num(doc.id, doc.kb_id, doc.token_num * -1, doc.chunk_num * -1, doc.process_duration * -1) if not e: return get_data_error_result(message="Document not found!") tenant_id = DocumentService.get_tenant_id(req["doc_id"]) @@ -492,6 +545,26 @@ def change_parser(): if settings.docStoreConn.indexExist(search.index_name(tenant_id), doc.kb_id): settings.docStoreConn.delete({"doc_id": doc.id}, search.index_name(tenant_id), doc.kb_id) + try: + if "pipeline_id" in req and req["pipeline_id"] != "": + if doc.pipeline_id == req["pipeline_id"]: + return get_json_result(data=True) + DocumentService.update_by_id(doc.id, {"pipeline_id": req["pipeline_id"]}) + reset_doc() + return get_json_result(data=True) + + if doc.parser_id.lower() == req["parser_id"].lower(): + if "parser_config" in req: + if req["parser_config"] == doc.parser_config: + return get_json_result(data=True) + else: + return get_json_result(data=True) + + if (doc.type == FileType.VISUAL and req["parser_id"] != "picture") or (re.search(r"\.(ppt|pptx|pages)$", doc.name) and req["parser_id"] != "presentation"): + return get_data_error_result(message="Not supported yet!") + if "parser_config" in req: + DocumentService.update_parser_config(doc.id, req["parser_config"]) + reset_doc() return get_json_result(data=True) except Exception as e: return server_error_response(e) @@ -505,7 +578,7 @@ def get_image(image_id): if len(arr) != 2: return get_data_error_result(message="Image not found.") bkt, nm = image_id.split("-") - response = flask.make_response(STORAGE_IMPL.get(bkt, nm)) + response = flask.make_response(settings.STORAGE_IMPL.get(bkt, nm)) response.headers.set("Content-Type", "image/JPEG") return response except Exception as e: @@ -517,12 +590,12 @@ def get_image(image_id): @validate_request("conversation_id") def upload_and_parse(): if "file" not in request.files: - return get_json_result(data=False, message="No file part!", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message="No file part!", code=RetCode.ARGUMENT_ERROR) file_objs = request.files.getlist("file") for file_obj in file_objs: if file_obj.filename == "": - return get_json_result(data=False, message="No file selected!", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message="No file selected!", code=RetCode.ARGUMENT_ERROR) doc_ids = doc_upload_and_parse(request.form.get("conversation_id"), file_objs, current_user.id) @@ -535,7 +608,7 @@ def parse(): url = request.json.get("url") if request.json else "" if url: if not is_valid_url(url): - return get_json_result(data=False, message="The URL format is invalid", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message="The URL format is invalid", code=RetCode.ARGUMENT_ERROR) download_path = os.path.join(get_project_base_directory(), "logs/downloads") os.makedirs(download_path, exist_ok=True) from seleniumwire.webdriver import Chrome, ChromeOptions @@ -568,13 +641,13 @@ def read(self): r = re.search(r"filename=\"([^\"]+)\"", str(res_headers)) if not r or not r.group(1): - return get_json_result(data=False, message="Can't not identify downloaded file", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message="Can't not identify downloaded file", code=RetCode.ARGUMENT_ERROR) f = File(r.group(1), os.path.join(download_path, r.group(1))) txt = FileService.parse_docs([f], current_user.id) return get_json_result(data=txt) if "file" not in request.files: - return get_json_result(data=False, message="No file part!", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message="No file part!", code=RetCode.ARGUMENT_ERROR) file_objs = request.files.getlist("file") txt = FileService.parse_docs(file_objs, current_user.id) @@ -588,13 +661,18 @@ def read(self): def set_meta(): req = request.json if not DocumentService.accessible(req["doc_id"], current_user.id): - return get_json_result(data=False, message="No authorization.", code=settings.RetCode.AUTHENTICATION_ERROR) + return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) try: meta = json.loads(req["meta"]) + if not isinstance(meta, dict): + return get_json_result(data=False, message="Only dictionary type supported.", code=RetCode.ARGUMENT_ERROR) + for k, v in meta.items(): + if not isinstance(v, str) and not isinstance(v, int) and not isinstance(v, float): + return get_json_result(data=False, message=f"The type is not supported: {v}", code=RetCode.ARGUMENT_ERROR) except Exception as e: - return get_json_result(data=False, message=f"Json syntax error: {e}", code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message=f"Json syntax error: {e}", code=RetCode.ARGUMENT_ERROR) if not isinstance(meta, dict): - return get_json_result(data=False, message='Meta data should be in Json map format, like {"key": "value"}', code=settings.RetCode.ARGUMENT_ERROR) + return get_json_result(data=False, message='Meta data should be in Json map format, like {"key": "value"}', code=RetCode.ARGUMENT_ERROR) try: e, doc = DocumentService.get_by_id(req["doc_id"]) diff --git a/api/apps/file2document_app.py b/api/apps/file2document_app.py index 0f19a54b46a..ca1e6b096d5 100644 --- a/api/apps/file2document_app.py +++ b/api/apps/file2document_app.py @@ -14,6 +14,8 @@ # limitations under the License # +from pathlib import Path + from api.db.services.file2document_service import File2DocumentService from api.db.services.file_service import FileService @@ -21,10 +23,10 @@ from flask_login import login_required, current_user from api.db.services.knowledgebase_service import KnowledgebaseService from api.utils.api_utils import server_error_response, get_data_error_result, validate_request -from api.utils import get_uuid +from common.misc_utils import get_uuid +from common.constants import RetCode from api.db import FileType from api.db.services.document_service import DocumentService -from api import settings from api.utils.api_utils import get_json_result @@ -82,6 +84,7 @@ def convert(): "created_by": current_user.id, "type": file.type, "name": file.name, + "suffix": Path(file.name).suffix.lstrip("."), "location": file.location, "size": file.size }) @@ -105,7 +108,7 @@ def rm(): file_ids = req["file_ids"] if not file_ids: return get_json_result( - data=False, message='Lack of "Files ID"', code=settings.RetCode.ARGUMENT_ERROR) + data=False, message='Lack of "Files ID"', code=RetCode.ARGUMENT_ERROR) try: for file_id in file_ids: informs = File2DocumentService.get_by_file_id(file_id) diff --git a/api/apps/file_app.py b/api/apps/file_app.py index e06c9650cdd..279e32525bb 100644 --- a/api/apps/file_app.py +++ b/api/apps/file_app.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License # +import logging import os import pathlib import re @@ -21,17 +22,19 @@ from flask import request from flask_login import login_required, current_user +from api.common.check_team_permission import check_file_team_permission from api.db.services.document_service import DocumentService from api.db.services.file2document_service import File2DocumentService from api.utils.api_utils import server_error_response, get_data_error_result, validate_request -from api.utils import get_uuid -from api.db import FileType, FileSource +from common.misc_utils import get_uuid +from common.constants import RetCode, FileSource +from api.db import FileType from api.db.services import duplicate_name from api.db.services.file_service import FileService -from api import settings from api.utils.api_utils import get_json_result from api.utils.file_utils import filename_type -from rag.utils.storage_factory import STORAGE_IMPL +from api.utils.web_utils import CONTENT_TYPE_MAP +from common import settings @manager.route('/upload', methods=['POST']) # noqa: F821 @@ -46,21 +49,21 @@ def upload(): if 'file' not in request.files: return get_json_result( - data=False, message='No file part!', code=settings.RetCode.ARGUMENT_ERROR) + data=False, message='No file part!', code=RetCode.ARGUMENT_ERROR) file_objs = request.files.getlist('file') for file_obj in file_objs: if file_obj.filename == '': return get_json_result( - data=False, message='No file selected!', code=settings.RetCode.ARGUMENT_ERROR) + data=False, message='No file selected!', code=RetCode.ARGUMENT_ERROR) file_res = [] try: e, pf_folder = FileService.get_by_id(pf_id) if not e: return get_data_error_result( message="Can't find this folder!") for file_obj in file_objs: - MAX_FILE_NUM_PER_USER = int(os.environ.get('MAX_FILE_NUM_PER_USER', 0)) - if MAX_FILE_NUM_PER_USER > 0 and DocumentService.get_doc_count(current_user.id) >= MAX_FILE_NUM_PER_USER: + MAX_FILE_NUM_PER_USER: int = int(os.environ.get('MAX_FILE_NUM_PER_USER', 0)) + if 0 < MAX_FILE_NUM_PER_USER <= DocumentService.get_doc_count(current_user.id): return get_data_error_result( message="Exceed the maximum file number of a free user!") # split file name path @@ -92,13 +95,14 @@ def upload(): # file type filetype = filename_type(file_obj_names[file_len - 1]) location = file_obj_names[file_len - 1] - while STORAGE_IMPL.obj_exist(last_folder.id, location): + while settings.STORAGE_IMPL.obj_exist(last_folder.id, location): location += "_" blob = file_obj.read() filename = duplicate_name( FileService.query, name=file_obj_names[file_len - 1], parent_id=last_folder.id) + settings.STORAGE_IMPL.put(last_folder.id, location, blob) file = { "id": get_uuid(), "parent_id": last_folder.id, @@ -110,7 +114,6 @@ def upload(): "size": len(blob), } file = FileService.insert(file) - STORAGE_IMPL.put(last_folder.id, location, blob) file_res.append(file.to_json()) return get_json_result(data=file_res) except Exception as e: @@ -131,7 +134,7 @@ def create(): try: if not FileService.is_parent_folder_exist(pf_id): return get_json_result( - data=False, message="Parent Folder Doesn't Exist!", code=settings.RetCode.OPERATING_ERROR) + data=False, message="Parent Folder Doesn't Exist!", code=RetCode.OPERATING_ERROR) if FileService.query(name=req["name"], parent_id=pf_id): return get_data_error_result( message="Duplicated folder name in the same folder.") @@ -232,52 +235,63 @@ def get_all_parent_folders(): return server_error_response(e) -@manager.route('/rm', methods=['POST']) # noqa: F821 +@manager.route("/rm", methods=["POST"]) # noqa: F821 @login_required @validate_request("file_ids") def rm(): req = request.json file_ids = req["file_ids"] + + def _delete_single_file(file): + try: + if file.location: + settings.STORAGE_IMPL.rm(file.parent_id, file.location) + except Exception: + logging.exception(f"Fail to remove object: {file.parent_id}/{file.location}") + + informs = File2DocumentService.get_by_file_id(file.id) + for inform in informs: + doc_id = inform.document_id + e, doc = DocumentService.get_by_id(doc_id) + if e and doc: + tenant_id = DocumentService.get_tenant_id(doc_id) + if tenant_id: + DocumentService.remove_document(doc, tenant_id) + File2DocumentService.delete_by_file_id(file.id) + + FileService.delete(file) + + def _delete_folder_recursive(folder, tenant_id): + sub_files = FileService.list_all_files_by_parent_id(folder.id) + for sub_file in sub_files: + if sub_file.type == FileType.FOLDER.value: + _delete_folder_recursive(sub_file, tenant_id) + else: + _delete_single_file(sub_file) + + FileService.delete(folder) + try: for file_id in file_ids: e, file = FileService.get_by_id(file_id) - if not e: + if not e or not file: return get_data_error_result(message="File or Folder not found!") if not file.tenant_id: return get_data_error_result(message="Tenant not found!") + if not check_file_team_permission(file, current_user.id): + return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) + if file.source_type == FileSource.KNOWLEDGEBASE: continue if file.type == FileType.FOLDER.value: - file_id_list = FileService.get_all_innermost_file_ids(file_id, []) - for inner_file_id in file_id_list: - e, file = FileService.get_by_id(inner_file_id) - if not e: - return get_data_error_result(message="File not found!") - STORAGE_IMPL.rm(file.parent_id, file.location) - FileService.delete_folder_by_pf_id(current_user.id, file_id) - else: - STORAGE_IMPL.rm(file.parent_id, file.location) - if not FileService.delete(file): - return get_data_error_result( - message="Database error (File removal)!") - - # delete file2document - informs = File2DocumentService.get_by_file_id(file_id) - for inform in informs: - doc_id = inform.document_id - e, doc = DocumentService.get_by_id(doc_id) - if not e: - return get_data_error_result(message="Document not found!") - tenant_id = DocumentService.get_tenant_id(doc_id) - if not tenant_id: - return get_data_error_result(message="Tenant not found!") - if not DocumentService.remove_document(doc, tenant_id): - return get_data_error_result( - message="Database error (Document removal)!") - File2DocumentService.delete_by_file_id(file_id) + _delete_folder_recursive(file, current_user.id) + continue + + _delete_single_file(file) return get_json_result(data=True) + except Exception as e: return server_error_response(e) @@ -291,13 +305,15 @@ def rename(): e, file = FileService.get_by_id(req["file_id"]) if not e: return get_data_error_result(message="File not found!") + if not check_file_team_permission(file, current_user.id): + return get_json_result(data=False, message='No authorization.', code=RetCode.AUTHENTICATION_ERROR) if file.type != FileType.FOLDER.value \ and pathlib.Path(req["name"].lower()).suffix != pathlib.Path( file.name.lower()).suffix: return get_json_result( data=False, message="The extension of file can't be changed", - code=settings.RetCode.ARGUMENT_ERROR) + code=RetCode.ARGUMENT_ERROR) for file in FileService.query(name=req["name"], pf_id=file.parent_id): if file.name == req["name"]: return get_data_error_result( @@ -327,50 +343,111 @@ def get(file_id): e, file = FileService.get_by_id(file_id) if not e: return get_data_error_result(message="Document not found!") + if not check_file_team_permission(file, current_user.id): + return get_json_result(data=False, message='No authorization.', code=RetCode.AUTHENTICATION_ERROR) - blob = STORAGE_IMPL.get(file.parent_id, file.location) + blob = settings.STORAGE_IMPL.get(file.parent_id, file.location) if not blob: b, n = File2DocumentService.get_storage_address(file_id=file_id) - blob = STORAGE_IMPL.get(b, n) + blob = settings.STORAGE_IMPL.get(b, n) response = flask.make_response(blob) - ext = re.search(r"\.([^.]+)$", file.name) + ext = re.search(r"\.([^.]+)$", file.name.lower()) + ext = ext.group(1) if ext else None if ext: if file.type == FileType.VISUAL.value: - response.headers.set('Content-Type', 'image/%s' % ext.group(1)) + content_type = CONTENT_TYPE_MAP.get(ext, f"image/{ext}") else: - response.headers.set( - 'Content-Type', - 'application/%s' % - ext.group(1)) + content_type = CONTENT_TYPE_MAP.get(ext, f"application/{ext}") + response.headers.set("Content-Type", content_type) return response except Exception as e: return server_error_response(e) -@manager.route('/mv', methods=['POST']) # noqa: F821 +@manager.route("/mv", methods=["POST"]) # noqa: F821 @login_required @validate_request("src_file_ids", "dest_file_id") def move(): req = request.json try: file_ids = req["src_file_ids"] - parent_id = req["dest_file_id"] + dest_parent_id = req["dest_file_id"] + + ok, dest_folder = FileService.get_by_id(dest_parent_id) + if not ok or not dest_folder: + return get_data_error_result(message="Parent folder not found!") + files = FileService.get_by_ids(file_ids) - files_dict = {} - for file in files: - files_dict[file.id] = file + if not files: + return get_data_error_result(message="Source files not found!") + + files_dict = {f.id: f for f in files} for file_id in file_ids: - file = files_dict[file_id] + file = files_dict.get(file_id) if not file: - return get_data_error_result(message="File or Folder not found!") + return get_data_error_result(message="File or folder not found!") if not file.tenant_id: return get_data_error_result(message="Tenant not found!") - fe, _ = FileService.get_by_id(parent_id) - if not fe: - return get_data_error_result(message="Parent Folder not found!") - FileService.move_file(file_ids, parent_id) + if not check_file_team_permission(file, current_user.id): + return get_json_result( + data=False, + message="No authorization.", + code=RetCode.AUTHENTICATION_ERROR, + ) + + def _move_entry_recursive(source_file_entry, dest_folder): + if source_file_entry.type == FileType.FOLDER.value: + existing_folder = FileService.query(name=source_file_entry.name, parent_id=dest_folder.id) + if existing_folder: + new_folder = existing_folder[0] + else: + new_folder = FileService.insert( + { + "id": get_uuid(), + "parent_id": dest_folder.id, + "tenant_id": source_file_entry.tenant_id, + "created_by": current_user.id, + "name": source_file_entry.name, + "location": "", + "size": 0, + "type": FileType.FOLDER.value, + } + ) + + sub_files = FileService.list_all_files_by_parent_id(source_file_entry.id) + for sub_file in sub_files: + _move_entry_recursive(sub_file, new_folder) + + FileService.delete_by_id(source_file_entry.id) + return + + old_parent_id = source_file_entry.parent_id + old_location = source_file_entry.location + filename = source_file_entry.name + + new_location = filename + while settings.STORAGE_IMPL.obj_exist(dest_folder.id, new_location): + new_location += "_" + + try: + settings.STORAGE_IMPL.move(old_parent_id, old_location, dest_folder.id, new_location) + except Exception as storage_err: + raise RuntimeError(f"Move file failed at storage layer: {str(storage_err)}") + + FileService.update_by_id( + source_file_entry.id, + { + "parent_id": dest_folder.id, + "location": new_location, + }, + ) + + for file in files: + _move_entry_recursive(file, dest_folder) + return get_json_result(data=True) + except Exception as e: - return server_error_response(e) \ No newline at end of file + return server_error_response(e) diff --git a/api/apps/kb_app.py b/api/apps/kb_app.py index 43e6e4eac3e..7094c28d705 100644 --- a/api/apps/kb_app.py +++ b/api/apps/kb_app.py @@ -14,61 +14,50 @@ # limitations under the License. # import json -import os +import logging +import random from flask import request from flask_login import login_required, current_user +import numpy as np -from api.db.services import duplicate_name -from api.db.services.document_service import DocumentService + +from api.db.services.connector_service import Connector2KbService +from api.db.services.llm_service import LLMBundle +from api.db.services.document_service import DocumentService, queue_raptor_o_graphrag_tasks from api.db.services.file2document_service import File2DocumentService from api.db.services.file_service import FileService +from api.db.services.pipeline_operation_log_service import PipelineOperationLogService +from api.db.services.task_service import TaskService, GRAPH_RAPTOR_FAKE_DOC_ID from api.db.services.user_service import TenantService, UserTenantService -from api.utils.api_utils import server_error_response, get_data_error_result, validate_request, not_allowed_parameters -from api.utils import get_uuid -from api.db import StatusEnum, FileSource +from api.utils.api_utils import get_error_data_result, server_error_response, get_data_error_result, validate_request, not_allowed_parameters +from api.db import VALID_FILE_TYPES from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.db_models import File from api.utils.api_utils import get_json_result -from api import settings from rag.nlp import search from api.constants import DATASET_NAME_LIMIT -from rag.settings import PAGERANK_FLD -from rag.utils.storage_factory import STORAGE_IMPL - +from rag.utils.redis_conn import REDIS_CONN +from rag.utils.doc_store_conn import OrderByExpr +from common.constants import RetCode, PipelineTaskType, StatusEnum, VALID_TASK_STATUS, FileSource, LLMType, PAGERANK_FLD +from common import settings @manager.route('/create', methods=['post']) # noqa: F821 @login_required @validate_request("name") def create(): req = request.json - dataset_name = req["name"] - if not isinstance(dataset_name, str): - return get_data_error_result(message="Dataset name must be string.") - if dataset_name.strip() == "": - return get_data_error_result(message="Dataset name can't be empty.") - if len(dataset_name.encode("utf-8")) > DATASET_NAME_LIMIT: - return get_data_error_result( - message=f"Dataset name length is {len(dataset_name)} which is larger than {DATASET_NAME_LIMIT}") - - dataset_name = dataset_name.strip() - dataset_name = duplicate_name( - KnowledgebaseService.query, - name=dataset_name, - tenant_id=current_user.id, - status=StatusEnum.VALID.value) + req = KnowledgebaseService.create_with_name( + name = req.pop("name", None), + tenant_id = current_user.id, + parser_id = req.pop("parser_id", None), + **req + ) + try: - req["id"] = get_uuid() - req["name"] = dataset_name - req["tenant_id"] = current_user.id - req["created_by"] = current_user.id - e, t = TenantService.get_by_id(current_user.id) - if not e: - return get_data_error_result(message="Tenant not found.") - req["embd_id"] = t.embd_id if not KnowledgebaseService.save(**req): return get_data_error_result() - return get_json_result(data={"kb_id": req["id"]}) + return get_json_result(data={"kb_id":req["id"]}) except Exception as e: return server_error_response(e) @@ -92,27 +81,20 @@ def update(): return get_json_result( data=False, message='No authorization.', - code=settings.RetCode.AUTHENTICATION_ERROR + code=RetCode.AUTHENTICATION_ERROR ) try: if not KnowledgebaseService.query( created_by=current_user.id, id=req["kb_id"]): return get_json_result( data=False, message='Only owner of knowledgebase authorized for this operation.', - code=settings.RetCode.OPERATING_ERROR) + code=RetCode.OPERATING_ERROR) e, kb = KnowledgebaseService.get_by_id(req["kb_id"]) if not e: return get_data_error_result( message="Can't find this knowledgebase!") - if req.get("parser_id", "") == "tag" and os.environ.get('DOC_ENGINE', "elasticsearch") == "infinity": - return get_json_result( - data=False, - message='The chunking method Tag has not been supported by Infinity yet.', - code=settings.RetCode.OPERATING_ERROR - ) - if req["name"].lower() != kb.name.lower() \ and len( KnowledgebaseService.query(name=req["name"], tenant_id=current_user.id, status=StatusEnum.VALID.value)) >= 1: @@ -120,13 +102,14 @@ def update(): message="Duplicated knowledgebase name.") del req["kb_id"] + connectors = [] + if "connectors" in req: + connectors = req["connectors"] + del req["connectors"] if not KnowledgebaseService.update_by_id(kb.id, req): return get_data_error_result() if kb.pagerank != req.get("pagerank", 0): - if os.environ.get("DOC_ENGINE", "elasticsearch") != "elasticsearch": - return get_data_error_result(message="'pagerank' can only be set when doc_engine is elasticsearch") - if req.get("pagerank", 0) > 0: settings.docStoreConn.update({"kb_id": kb.id}, {PAGERANK_FLD: req["pagerank"]}, search.index_name(kb.tenant_id), kb.id) @@ -139,8 +122,12 @@ def update(): if not e: return get_data_error_result( message="Database error (Knowledgebase rename)!") + errors = Connector2KbService.link_connectors(kb.id, [conn for conn in connectors], current_user.id) + if errors: + logging.error("Link KB errors: ", errors) kb = kb.to_dict() kb.update(req) + kb["connectors"] = connectors return get_json_result(data=kb) except Exception as e: @@ -160,12 +147,17 @@ def detail(): else: return get_json_result( data=False, message='Only owner of knowledgebase authorized for this operation.', - code=settings.RetCode.OPERATING_ERROR) + code=RetCode.OPERATING_ERROR) kb = KnowledgebaseService.get_detail(kb_id) if not kb: return get_data_error_result( message="Can't find this knowledgebase!") kb["size"] = DocumentService.get_total_size_by_kb_id(kb_id=kb["id"],keywords="", run_status=[], types=[]) + kb["connectors"] = Connector2KbService.list_connectors(kb_id) + + for key in ["graphrag_task_finish_at", "raptor_task_finish_at", "mindmap_task_finish_at"]: + if finish_at := kb.get(key): + kb[key] = finish_at.strftime("%Y-%m-%d %H:%M:%S") return get_json_result(data=kb) except Exception as e: return server_error_response(e) @@ -215,7 +207,7 @@ def rm(): return get_json_result( data=False, message='No authorization.', - code=settings.RetCode.AUTHENTICATION_ERROR + code=RetCode.AUTHENTICATION_ERROR ) try: kbs = KnowledgebaseService.query( @@ -223,7 +215,7 @@ def rm(): if not kbs: return get_json_result( data=False, message='Only owner of knowledgebase authorized for this operation.', - code=settings.RetCode.OPERATING_ERROR) + code=RetCode.OPERATING_ERROR) for doc in DocumentService.query(kb_id=req["kb_id"]): if not DocumentService.remove_document(doc, kbs[0].tenant_id): @@ -241,8 +233,8 @@ def rm(): for kb in kbs: settings.docStoreConn.delete({"kb_id": kb.id}, search.index_name(kb.tenant_id), kb.id) settings.docStoreConn.deleteIdx(search.index_name(kb.tenant_id), kb.id) - if hasattr(STORAGE_IMPL, 'remove_bucket'): - STORAGE_IMPL.remove_bucket(kb.id) + if hasattr(settings.STORAGE_IMPL, 'remove_bucket'): + settings.STORAGE_IMPL.remove_bucket(kb.id) return get_json_result(data=True) except Exception as e: return server_error_response(e) @@ -255,10 +247,13 @@ def list_tags(kb_id): return get_json_result( data=False, message='No authorization.', - code=settings.RetCode.AUTHENTICATION_ERROR + code=RetCode.AUTHENTICATION_ERROR ) - tags = settings.retrievaler.all_tags(current_user.id, [kb_id]) + tenants = UserTenantService.get_tenants_by_user_id(current_user.id) + tags = [] + for tenant in tenants: + tags += settings.retriever.all_tags(tenant["tenant_id"], [kb_id]) return get_json_result(data=tags) @@ -271,10 +266,13 @@ def list_tags_from_kbs(): return get_json_result( data=False, message='No authorization.', - code=settings.RetCode.AUTHENTICATION_ERROR + code=RetCode.AUTHENTICATION_ERROR ) - tags = settings.retrievaler.all_tags(current_user.id, kb_ids) + tenants = UserTenantService.get_tenants_by_user_id(current_user.id) + tags = [] + for tenant in tenants: + tags += settings.retriever.all_tags(tenant["tenant_id"], kb_ids) return get_json_result(data=tags) @@ -286,7 +284,7 @@ def rm_tags(kb_id): return get_json_result( data=False, message='No authorization.', - code=settings.RetCode.AUTHENTICATION_ERROR + code=RetCode.AUTHENTICATION_ERROR ) e, kb = KnowledgebaseService.get_by_id(kb_id) @@ -306,7 +304,7 @@ def rename_tags(kb_id): return get_json_result( data=False, message='No authorization.', - code=settings.RetCode.AUTHENTICATION_ERROR + code=RetCode.AUTHENTICATION_ERROR ) e, kb = KnowledgebaseService.get_by_id(kb_id) @@ -324,7 +322,7 @@ def knowledge_graph(kb_id): return get_json_result( data=False, message='No authorization.', - code=settings.RetCode.AUTHENTICATION_ERROR + code=RetCode.AUTHENTICATION_ERROR ) _, kb = KnowledgebaseService.get_by_id(kb_id) req = { @@ -335,7 +333,7 @@ def knowledge_graph(kb_id): obj = {"graph": {}, "mind_map": {}} if not settings.docStoreConn.indexExist(search.index_name(kb.tenant_id), kb_id): return get_json_result(data=obj) - sres = settings.retrievaler.search(req, search.index_name(kb.tenant_id), [kb_id]) + sres = settings.retriever.search(req, search.index_name(kb.tenant_id), [kb_id]) if not len(sres.ids): return get_json_result(data=obj) @@ -356,6 +354,7 @@ def knowledge_graph(kb_id): obj["graph"]["edges"] = sorted(filtered_edges, key=lambda x: x.get("weight", 0), reverse=True)[:128] return get_json_result(data=obj) + @manager.route('//knowledge_graph', methods=['DELETE']) # noqa: F821 @login_required def delete_knowledge_graph(kb_id): @@ -363,9 +362,539 @@ def delete_knowledge_graph(kb_id): return get_json_result( data=False, message='No authorization.', - code=settings.RetCode.AUTHENTICATION_ERROR + code=RetCode.AUTHENTICATION_ERROR ) _, kb = KnowledgebaseService.get_by_id(kb_id) settings.docStoreConn.delete({"knowledge_graph_kwd": ["graph", "subgraph", "entity", "relation"]}, search.index_name(kb.tenant_id), kb_id) return get_json_result(data=True) + + +@manager.route("/get_meta", methods=["GET"]) # noqa: F821 +@login_required +def get_meta(): + kb_ids = request.args.get("kb_ids", "").split(",") + for kb_id in kb_ids: + if not KnowledgebaseService.accessible(kb_id, current_user.id): + return get_json_result( + data=False, + message='No authorization.', + code=RetCode.AUTHENTICATION_ERROR + ) + return get_json_result(data=DocumentService.get_meta_by_kbs(kb_ids)) + + +@manager.route("/basic_info", methods=["GET"]) # noqa: F821 +@login_required +def get_basic_info(): + kb_id = request.args.get("kb_id", "") + if not KnowledgebaseService.accessible(kb_id, current_user.id): + return get_json_result( + data=False, + message='No authorization.', + code=RetCode.AUTHENTICATION_ERROR + ) + + basic_info = DocumentService.knowledgebase_basic_info(kb_id) + + return get_json_result(data=basic_info) + + +@manager.route("/list_pipeline_logs", methods=["POST"]) # noqa: F821 +@login_required +def list_pipeline_logs(): + kb_id = request.args.get("kb_id") + if not kb_id: + return get_json_result(data=False, message='Lack of "KB ID"', code=RetCode.ARGUMENT_ERROR) + + keywords = request.args.get("keywords", "") + + page_number = int(request.args.get("page", 0)) + items_per_page = int(request.args.get("page_size", 0)) + orderby = request.args.get("orderby", "create_time") + if request.args.get("desc", "true").lower() == "false": + desc = False + else: + desc = True + create_date_from = request.args.get("create_date_from", "") + create_date_to = request.args.get("create_date_to", "") + if create_date_to > create_date_from: + return get_data_error_result(message="Create data filter is abnormal.") + + req = request.get_json() + + operation_status = req.get("operation_status", []) + if operation_status: + invalid_status = {s for s in operation_status if s not in VALID_TASK_STATUS} + if invalid_status: + return get_data_error_result(message=f"Invalid filter operation_status status conditions: {', '.join(invalid_status)}") + + types = req.get("types", []) + if types: + invalid_types = {t for t in types if t not in VALID_FILE_TYPES} + if invalid_types: + return get_data_error_result(message=f"Invalid filter conditions: {', '.join(invalid_types)} type{'s' if len(invalid_types) > 1 else ''}") + + suffix = req.get("suffix", []) + + try: + logs, tol = PipelineOperationLogService.get_file_logs_by_kb_id(kb_id, page_number, items_per_page, orderby, desc, keywords, operation_status, types, suffix, create_date_from, create_date_to) + return get_json_result(data={"total": tol, "logs": logs}) + except Exception as e: + return server_error_response(e) + + +@manager.route("/list_pipeline_dataset_logs", methods=["POST"]) # noqa: F821 +@login_required +def list_pipeline_dataset_logs(): + kb_id = request.args.get("kb_id") + if not kb_id: + return get_json_result(data=False, message='Lack of "KB ID"', code=RetCode.ARGUMENT_ERROR) + + page_number = int(request.args.get("page", 0)) + items_per_page = int(request.args.get("page_size", 0)) + orderby = request.args.get("orderby", "create_time") + if request.args.get("desc", "true").lower() == "false": + desc = False + else: + desc = True + create_date_from = request.args.get("create_date_from", "") + create_date_to = request.args.get("create_date_to", "") + if create_date_to > create_date_from: + return get_data_error_result(message="Create data filter is abnormal.") + + req = request.get_json() + + operation_status = req.get("operation_status", []) + if operation_status: + invalid_status = {s for s in operation_status if s not in VALID_TASK_STATUS} + if invalid_status: + return get_data_error_result(message=f"Invalid filter operation_status status conditions: {', '.join(invalid_status)}") + + try: + logs, tol = PipelineOperationLogService.get_dataset_logs_by_kb_id(kb_id, page_number, items_per_page, orderby, desc, operation_status, create_date_from, create_date_to) + return get_json_result(data={"total": tol, "logs": logs}) + except Exception as e: + return server_error_response(e) + + +@manager.route("/delete_pipeline_logs", methods=["POST"]) # noqa: F821 +@login_required +def delete_pipeline_logs(): + kb_id = request.args.get("kb_id") + if not kb_id: + return get_json_result(data=False, message='Lack of "KB ID"', code=RetCode.ARGUMENT_ERROR) + + req = request.get_json() + log_ids = req.get("log_ids", []) + + PipelineOperationLogService.delete_by_ids(log_ids) + + return get_json_result(data=True) + + +@manager.route("/pipeline_log_detail", methods=["GET"]) # noqa: F821 +@login_required +def pipeline_log_detail(): + log_id = request.args.get("log_id") + if not log_id: + return get_json_result(data=False, message='Lack of "Pipeline log ID"', code=RetCode.ARGUMENT_ERROR) + + ok, log = PipelineOperationLogService.get_by_id(log_id) + if not ok: + return get_data_error_result(message="Invalid pipeline log ID") + + return get_json_result(data=log.to_dict()) + + +@manager.route("/run_graphrag", methods=["POST"]) # noqa: F821 +@login_required +def run_graphrag(): + req = request.json + + kb_id = req.get("kb_id", "") + if not kb_id: + return get_error_data_result(message='Lack of "KB ID"') + + ok, kb = KnowledgebaseService.get_by_id(kb_id) + if not ok: + return get_error_data_result(message="Invalid Knowledgebase ID") + + task_id = kb.graphrag_task_id + if task_id: + ok, task = TaskService.get_by_id(task_id) + if not ok: + logging.warning(f"A valid GraphRAG task id is expected for kb {kb_id}") + + if task and task.progress not in [-1, 1]: + return get_error_data_result(message=f"Task {task_id} in progress with status {task.progress}. A Graph Task is already running.") + + documents, _ = DocumentService.get_by_kb_id( + kb_id=kb_id, + page_number=0, + items_per_page=0, + orderby="create_time", + desc=False, + keywords="", + run_status=[], + types=[], + suffix=[], + ) + if not documents: + return get_error_data_result(message=f"No documents in Knowledgebase {kb_id}") + + sample_document = documents[0] + document_ids = [document["id"] for document in documents] + + task_id = queue_raptor_o_graphrag_tasks(sample_doc_id=sample_document, ty="graphrag", priority=0, fake_doc_id=GRAPH_RAPTOR_FAKE_DOC_ID, doc_ids=list(document_ids)) + + if not KnowledgebaseService.update_by_id(kb.id, {"graphrag_task_id": task_id}): + logging.warning(f"Cannot save graphrag_task_id for kb {kb_id}") + + return get_json_result(data={"graphrag_task_id": task_id}) + + +@manager.route("/trace_graphrag", methods=["GET"]) # noqa: F821 +@login_required +def trace_graphrag(): + kb_id = request.args.get("kb_id", "") + if not kb_id: + return get_error_data_result(message='Lack of "KB ID"') + + ok, kb = KnowledgebaseService.get_by_id(kb_id) + if not ok: + return get_error_data_result(message="Invalid Knowledgebase ID") + + task_id = kb.graphrag_task_id + if not task_id: + return get_json_result(data={}) + + ok, task = TaskService.get_by_id(task_id) + if not ok: + return get_json_result(data={}) + + return get_json_result(data=task.to_dict()) + + +@manager.route("/run_raptor", methods=["POST"]) # noqa: F821 +@login_required +def run_raptor(): + req = request.json + + kb_id = req.get("kb_id", "") + if not kb_id: + return get_error_data_result(message='Lack of "KB ID"') + + ok, kb = KnowledgebaseService.get_by_id(kb_id) + if not ok: + return get_error_data_result(message="Invalid Knowledgebase ID") + + task_id = kb.raptor_task_id + if task_id: + ok, task = TaskService.get_by_id(task_id) + if not ok: + logging.warning(f"A valid RAPTOR task id is expected for kb {kb_id}") + + if task and task.progress not in [-1, 1]: + return get_error_data_result(message=f"Task {task_id} in progress with status {task.progress}. A RAPTOR Task is already running.") + + documents, _ = DocumentService.get_by_kb_id( + kb_id=kb_id, + page_number=0, + items_per_page=0, + orderby="create_time", + desc=False, + keywords="", + run_status=[], + types=[], + suffix=[], + ) + if not documents: + return get_error_data_result(message=f"No documents in Knowledgebase {kb_id}") + + sample_document = documents[0] + document_ids = [document["id"] for document in documents] + + task_id = queue_raptor_o_graphrag_tasks(sample_doc_id=sample_document, ty="raptor", priority=0, fake_doc_id=GRAPH_RAPTOR_FAKE_DOC_ID, doc_ids=list(document_ids)) + + if not KnowledgebaseService.update_by_id(kb.id, {"raptor_task_id": task_id}): + logging.warning(f"Cannot save raptor_task_id for kb {kb_id}") + + return get_json_result(data={"raptor_task_id": task_id}) + + +@manager.route("/trace_raptor", methods=["GET"]) # noqa: F821 +@login_required +def trace_raptor(): + kb_id = request.args.get("kb_id", "") + if not kb_id: + return get_error_data_result(message='Lack of "KB ID"') + + ok, kb = KnowledgebaseService.get_by_id(kb_id) + if not ok: + return get_error_data_result(message="Invalid Knowledgebase ID") + + task_id = kb.raptor_task_id + if not task_id: + return get_json_result(data={}) + + ok, task = TaskService.get_by_id(task_id) + if not ok: + return get_error_data_result(message="RAPTOR Task Not Found or Error Occurred") + + return get_json_result(data=task.to_dict()) + + +@manager.route("/run_mindmap", methods=["POST"]) # noqa: F821 +@login_required +def run_mindmap(): + req = request.json + + kb_id = req.get("kb_id", "") + if not kb_id: + return get_error_data_result(message='Lack of "KB ID"') + + ok, kb = KnowledgebaseService.get_by_id(kb_id) + if not ok: + return get_error_data_result(message="Invalid Knowledgebase ID") + + task_id = kb.mindmap_task_id + if task_id: + ok, task = TaskService.get_by_id(task_id) + if not ok: + logging.warning(f"A valid Mindmap task id is expected for kb {kb_id}") + + if task and task.progress not in [-1, 1]: + return get_error_data_result(message=f"Task {task_id} in progress with status {task.progress}. A Mindmap Task is already running.") + + documents, _ = DocumentService.get_by_kb_id( + kb_id=kb_id, + page_number=0, + items_per_page=0, + orderby="create_time", + desc=False, + keywords="", + run_status=[], + types=[], + suffix=[], + ) + if not documents: + return get_error_data_result(message=f"No documents in Knowledgebase {kb_id}") + + sample_document = documents[0] + document_ids = [document["id"] for document in documents] + + task_id = queue_raptor_o_graphrag_tasks(sample_doc_id=sample_document, ty="mindmap", priority=0, fake_doc_id=GRAPH_RAPTOR_FAKE_DOC_ID, doc_ids=list(document_ids)) + + if not KnowledgebaseService.update_by_id(kb.id, {"mindmap_task_id": task_id}): + logging.warning(f"Cannot save mindmap_task_id for kb {kb_id}") + + return get_json_result(data={"mindmap_task_id": task_id}) + + +@manager.route("/trace_mindmap", methods=["GET"]) # noqa: F821 +@login_required +def trace_mindmap(): + kb_id = request.args.get("kb_id", "") + if not kb_id: + return get_error_data_result(message='Lack of "KB ID"') + + ok, kb = KnowledgebaseService.get_by_id(kb_id) + if not ok: + return get_error_data_result(message="Invalid Knowledgebase ID") + + task_id = kb.mindmap_task_id + if not task_id: + return get_json_result(data={}) + + ok, task = TaskService.get_by_id(task_id) + if not ok: + return get_error_data_result(message="Mindmap Task Not Found or Error Occurred") + + return get_json_result(data=task.to_dict()) + + +@manager.route("/unbind_task", methods=["DELETE"]) # noqa: F821 +@login_required +def delete_kb_task(): + kb_id = request.args.get("kb_id", "") + if not kb_id: + return get_error_data_result(message='Lack of "KB ID"') + ok, kb = KnowledgebaseService.get_by_id(kb_id) + if not ok: + return get_json_result(data=True) + + pipeline_task_type = request.args.get("pipeline_task_type", "") + if not pipeline_task_type or pipeline_task_type not in [PipelineTaskType.GRAPH_RAG, PipelineTaskType.RAPTOR, PipelineTaskType.MINDMAP]: + return get_error_data_result(message="Invalid task type") + + def cancel_task(task_id): + REDIS_CONN.set(f"{task_id}-cancel", "x") + + match pipeline_task_type: + case PipelineTaskType.GRAPH_RAG: + kb_task_id_field = "graphrag_task_id" + task_id = kb.graphrag_task_id + kb_task_finish_at = "graphrag_task_finish_at" + cancel_task(task_id) + settings.docStoreConn.delete({"knowledge_graph_kwd": ["graph", "subgraph", "entity", "relation"]}, search.index_name(kb.tenant_id), kb_id) + case PipelineTaskType.RAPTOR: + kb_task_id_field = "raptor_task_id" + task_id = kb.raptor_task_id + kb_task_finish_at = "raptor_task_finish_at" + cancel_task(task_id) + settings.docStoreConn.delete({"raptor_kwd": ["raptor"]}, search.index_name(kb.tenant_id), kb_id) + case PipelineTaskType.MINDMAP: + kb_task_id_field = "mindmap_task_id" + task_id = kb.mindmap_task_id + kb_task_finish_at = "mindmap_task_finish_at" + cancel_task(task_id) + case _: + return get_error_data_result(message="Internal Error: Invalid task type") + + + ok = KnowledgebaseService.update_by_id(kb_id, {kb_task_id_field: "", kb_task_finish_at: None}) + if not ok: + return server_error_response(f"Internal error: cannot delete task {pipeline_task_type}") + + return get_json_result(data=True) + +@manager.route("/check_embedding", methods=["post"]) # noqa: F821 +@login_required +def check_embedding(): + + def _guess_vec_field(src: dict) -> str | None: + for k in src or {}: + if k.endswith("_vec"): + return k + return None + + def _as_float_vec(v): + if v is None: + return [] + if isinstance(v, str): + return [float(x) for x in v.split("\t") if x != ""] + if isinstance(v, (list, tuple, np.ndarray)): + return [float(x) for x in v] + return [] + + def _to_1d(x): + a = np.asarray(x, dtype=np.float32) + return a.reshape(-1) + + def _cos_sim(a, b, eps=1e-12): + a = _to_1d(a) + b = _to_1d(b) + na = np.linalg.norm(a) + nb = np.linalg.norm(b) + if na < eps or nb < eps: + return 0.0 + return float(np.dot(a, b) / (na * nb)) + + def sample_random_chunks_with_vectors( + docStoreConn, + tenant_id: str, + kb_id: str, + n: int = 5, + base_fields=("docnm_kwd","doc_id","content_with_weight","page_num_int","position_int","top_int"), + ): + index_nm = search.index_name(tenant_id) + + res0 = docStoreConn.search( + selectFields=[], highlightFields=[], + condition={"kb_id": kb_id, "available_int": 1}, + matchExprs=[], orderBy=OrderByExpr(), + offset=0, limit=1, + indexNames=index_nm, knowledgebaseIds=[kb_id] + ) + total = docStoreConn.getTotal(res0) + if total <= 0: + return [] + + n = min(n, total) + offsets = sorted(random.sample(range(total), n)) + out = [] + + for off in offsets: + res1 = docStoreConn.search( + selectFields=list(base_fields), + highlightFields=[], + condition={"kb_id": kb_id, "available_int": 1}, + matchExprs=[], orderBy=OrderByExpr(), + offset=off, limit=1, + indexNames=index_nm, knowledgebaseIds=[kb_id] + ) + ids = docStoreConn.getChunkIds(res1) + if not ids: + continue + + cid = ids[0] + full_doc = docStoreConn.get(cid, index_nm, [kb_id]) or {} + vec_field = _guess_vec_field(full_doc) + vec = _as_float_vec(full_doc.get(vec_field)) + + out.append({ + "chunk_id": cid, + "kb_id": kb_id, + "doc_id": full_doc.get("doc_id"), + "doc_name": full_doc.get("docnm_kwd"), + "vector_field": vec_field, + "vector_dim": len(vec), + "vector": vec, + "page_num_int": full_doc.get("page_num_int"), + "position_int": full_doc.get("position_int"), + "top_int": full_doc.get("top_int"), + "content_with_weight": full_doc.get("content_with_weight") or "", + }) + return out + req = request.json + kb_id = req.get("kb_id", "") + embd_id = req.get("embd_id", "") + n = int(req.get("check_num", 5)) + _, kb = KnowledgebaseService.get_by_id(kb_id) + tenant_id = kb.tenant_id + + emb_mdl = LLMBundle(tenant_id, LLMType.EMBEDDING, embd_id) + samples = sample_random_chunks_with_vectors(settings.docStoreConn, tenant_id=tenant_id, kb_id=kb_id, n=n) + + results, eff_sims = [], [] + for ck in samples: + txt = (ck.get("content_with_weight") or "").strip() + if not txt: + results.append({"chunk_id": ck["chunk_id"], "reason": "no_text"}) + continue + + if not ck.get("vector"): + results.append({"chunk_id": ck["chunk_id"], "reason": "no_stored_vector"}) + continue + + try: + qv, _ = emb_mdl.encode_queries(txt) + sim = _cos_sim(qv, ck["vector"]) + except Exception: + return get_error_data_result(message="embedding failure") + + eff_sims.append(sim) + results.append({ + "chunk_id": ck["chunk_id"], + "doc_id": ck["doc_id"], + "doc_name": ck["doc_name"], + "vector_field": ck["vector_field"], + "vector_dim": ck["vector_dim"], + "cos_sim": round(sim, 6), + }) + + summary = { + "kb_id": kb_id, + "model": embd_id, + "sampled": len(samples), + "valid": len(eff_sims), + "avg_cos_sim": round(float(np.mean(eff_sims)) if eff_sims else 0.0, 6), + "min_cos_sim": round(float(np.min(eff_sims)) if eff_sims else 0.0, 6), + "max_cos_sim": round(float(np.max(eff_sims)) if eff_sims else 0.0, 6), + } + if summary["avg_cos_sim"] > 0.99: + return get_json_result(data={"summary": summary, "results": results}) + return get_json_result(code=RetCode.NOT_EFFECTIVE, message="failed", data={"summary": summary, "results": results}) + + diff --git a/api/apps/llm_app.py b/api/apps/llm_app.py index 771418e424a..c34d71cc06a 100644 --- a/api/apps/llm_app.py +++ b/api/apps/llm_app.py @@ -18,22 +18,22 @@ import os from flask import request from flask_login import login_required, current_user -from api.db.services.llm_service import LLMFactoriesService, TenantLLMService, LLMService -from api import settings +from api.db.services.tenant_llm_service import LLMFactoriesService, TenantLLMService +from api.db.services.llm_service import LLMService from api.utils.api_utils import server_error_response, get_data_error_result, validate_request -from api.db import StatusEnum, LLMType +from common.constants import StatusEnum, LLMType from api.db.db_models import TenantLLM -from api.utils.api_utils import get_json_result -from api.utils.file_utils import get_project_base_directory +from api.utils.api_utils import get_json_result, get_allowed_llm_factories +from rag.utils.base64_image import test_image from rag.llm import EmbeddingModel, ChatModel, RerankModel, CvModel, TTSModel -@manager.route('/factories', methods=['GET']) # noqa: F821 +@manager.route("/factories", methods=["GET"]) # noqa: F821 @login_required def factories(): try: - fac = LLMFactoriesService.get_all() - fac = [f.to_dict() for f in fac if f.name not in ["Youdao", "FastEmbed", "BAAI"]] + fac = get_allowed_llm_factories() + fac = [f.to_dict() for f in fac if f.name not in ["Youdao", "FastEmbed", "BAAI", "Builtin"]] llms = LLMService.get_all() mdl_types = {} for m in llms: @@ -43,14 +43,13 @@ def factories(): mdl_types[m.fid] = set([]) mdl_types[m.fid].add(m.model_type) for f in fac: - f["model_types"] = list(mdl_types.get(f["name"], [LLMType.CHAT, LLMType.EMBEDDING, LLMType.RERANK, - LLMType.IMAGE2TEXT, LLMType.SPEECH2TEXT, LLMType.TTS])) + f["model_types"] = list(mdl_types.get(f["name"], [LLMType.CHAT, LLMType.EMBEDDING, LLMType.RERANK, LLMType.IMAGE2TEXT, LLMType.SPEECH2TEXT, LLMType.TTS])) return get_json_result(data=fac) except Exception as e: return server_error_response(e) -@manager.route('/set_api_key', methods=['POST']) # noqa: F821 +@manager.route("/set_api_key", methods=["POST"]) # noqa: F821 @login_required @validate_request("llm_factory", "api_key") def set_api_key(): @@ -58,12 +57,12 @@ def set_api_key(): # test if api key works chat_passed, embd_passed, rerank_passed = False, False, False factory = req["llm_factory"] + extra = {"provider": factory} msg = "" for llm in LLMService.query(fid=factory): if not embd_passed and llm.model_type == LLMType.EMBEDDING.value: assert factory in EmbeddingModel, f"Embedding model from {factory} is not supported yet." - mdl = EmbeddingModel[factory]( - req["api_key"], llm.llm_name, base_url=req.get("base_url")) + mdl = EmbeddingModel[factory](req["api_key"], llm.llm_name, base_url=req.get("base_url")) try: arr, tc = mdl.encode(["Test if the api key is available"]) if len(arr[0]) == 0: @@ -73,52 +72,40 @@ def set_api_key(): msg += f"\nFail to access embedding model({llm.llm_name}) using this api key." + str(e) elif not chat_passed and llm.model_type == LLMType.CHAT.value: assert factory in ChatModel, f"Chat model from {factory} is not supported yet." - mdl = ChatModel[factory]( - req["api_key"], llm.llm_name, base_url=req.get("base_url")) + mdl = ChatModel[factory](req["api_key"], llm.llm_name, base_url=req.get("base_url"), **extra) try: - m, tc = mdl.chat(None, [{"role": "user", "content": "Hello! How are you doing!"}], - {"temperature": 0.9, 'max_tokens': 50}) + m, tc = mdl.chat(None, [{"role": "user", "content": "Hello! How are you doing!"}], {"temperature": 0.9, "max_tokens": 50}) if m.find("**ERROR**") >= 0: raise Exception(m) chat_passed = True except Exception as e: - msg += f"\nFail to access model({llm.llm_name}) using this api key." + str( - e) + msg += f"\nFail to access model({llm.fid}/{llm.llm_name}) using this api key." + str(e) elif not rerank_passed and llm.model_type == LLMType.RERANK: assert factory in RerankModel, f"Re-rank model from {factory} is not supported yet." - mdl = RerankModel[factory]( - req["api_key"], llm.llm_name, base_url=req.get("base_url")) + mdl = RerankModel[factory](req["api_key"], llm.llm_name, base_url=req.get("base_url")) try: arr, tc = mdl.similarity("What's the weather?", ["Is it sunny today?"]) if len(arr) == 0 or tc == 0: raise Exception("Fail") rerank_passed = True - logging.debug(f'passed model rerank {llm.llm_name}') + logging.debug(f"passed model rerank {llm.llm_name}") except Exception as e: - msg += f"\nFail to access model({llm.llm_name}) using this api key." + str( - e) + msg += f"\nFail to access model({llm.fid}/{llm.llm_name}) using this api key." + str(e) if any([embd_passed, chat_passed, rerank_passed]): - msg = '' + msg = "" break if msg: return get_data_error_result(message=msg) - llm_config = { - "api_key": req["api_key"], - "api_base": req.get("base_url", "") - } + llm_config = {"api_key": req["api_key"], "api_base": req.get("base_url", "")} for n in ["model_type", "llm_name"]: if n in req: llm_config[n] = req[n] for llm in LLMService.query(fid=factory): - llm_config["max_tokens"]=llm.max_tokens - if not TenantLLMService.filter_update( - [TenantLLM.tenant_id == current_user.id, - TenantLLM.llm_factory == factory, - TenantLLM.llm_name == llm.llm_name], - llm_config): + llm_config["max_tokens"] = llm.max_tokens + if not TenantLLMService.filter_update([TenantLLM.tenant_id == current_user.id, TenantLLM.llm_factory == factory, TenantLLM.llm_name == llm.llm_name], llm_config): TenantLLMService.save( tenant_id=current_user.id, llm_factory=factory, @@ -126,13 +113,13 @@ def set_api_key(): model_type=llm.model_type, api_key=llm_config["api_key"], api_base=llm_config["api_base"], - max_tokens=llm_config["max_tokens"] + max_tokens=llm_config["max_tokens"], ) return get_json_result(data=True) -@manager.route('/add_llm', methods=['POST']) # noqa: F821 +@manager.route("/add_llm", methods=["POST"]) # noqa: F821 @login_required @validate_request("llm_factory") def add_llm(): @@ -141,6 +128,9 @@ def add_llm(): api_key = req.get("api_key", "x") llm_name = req.get("llm_name") + if factory not in [f.name for f in get_allowed_llm_factories()]: + return get_data_error_result(message=f"LLM factory {factory} is not allowed") + def apikey_json(keys): nonlocal req return json.dumps({k: req.get(k, "") for k in keys}) @@ -193,6 +183,9 @@ def apikey_json(keys): elif factory == "Azure-OpenAI": api_key = apikey_json(["api_key", "api_version"]) + elif factory == "OpenRouter": + api_key = apikey_json(["api_key", "provider_order"]) + llm = { "tenant_id": current_user.id, "llm_factory": factory, @@ -200,17 +193,15 @@ def apikey_json(keys): "llm_name": llm_name, "api_base": req.get("api_base", ""), "api_key": api_key, - "max_tokens": req.get("max_tokens") + "max_tokens": req.get("max_tokens"), } msg = "" mdl_nm = llm["llm_name"].split("___")[0] + extra = {"provider": factory} if llm["model_type"] == LLMType.EMBEDDING.value: assert factory in EmbeddingModel, f"Embedding model from {factory} is not supported yet." - mdl = EmbeddingModel[factory]( - key=llm['api_key'], - model_name=mdl_nm, - base_url=llm["api_base"]) + mdl = EmbeddingModel[factory](key=llm["api_key"], model_name=mdl_nm, base_url=llm["api_base"]) try: arr, tc = mdl.encode(["Test if the api key is available"]) if len(arr[0]) == 0: @@ -220,58 +211,46 @@ def apikey_json(keys): elif llm["model_type"] == LLMType.CHAT.value: assert factory in ChatModel, f"Chat model from {factory} is not supported yet." mdl = ChatModel[factory]( - key=llm['api_key'], + key=llm["api_key"], model_name=mdl_nm, - base_url=llm["api_base"] + base_url=llm["api_base"], + **extra, ) try: - m, tc = mdl.chat(None, [{"role": "user", "content": "Hello! How are you doing!"}], { - "temperature": 0.9}) + m, tc = mdl.chat(None, [{"role": "user", "content": "Hello! How are you doing!"}], {"temperature": 0.9}) if not tc and m.find("**ERROR**:") >= 0: raise Exception(m) except Exception as e: - msg += f"\nFail to access model({mdl_nm})." + str( - e) + msg += f"\nFail to access model({factory}/{mdl_nm})." + str(e) elif llm["model_type"] == LLMType.RERANK: assert factory in RerankModel, f"RE-rank model from {factory} is not supported yet." try: - mdl = RerankModel[factory]( - key=llm["api_key"], - model_name=mdl_nm, - base_url=llm["api_base"] - ) - arr, tc = mdl.similarity("Hello~ Ragflower!", ["Hi, there!", "Ohh, my friend!"]) + mdl = RerankModel[factory](key=llm["api_key"], model_name=mdl_nm, base_url=llm["api_base"]) + arr, tc = mdl.similarity("Hello~ RAGFlower!", ["Hi, there!", "Ohh, my friend!"]) if len(arr) == 0: raise Exception("Not known.") except KeyError: - msg += f"{factory} dose not support this model({mdl_nm})" + msg += f"{factory} dose not support this model({factory}/{mdl_nm})" except Exception as e: - msg += f"\nFail to access model({mdl_nm})." + str( - e) + msg += f"\nFail to access model({factory}/{mdl_nm})." + str(e) elif llm["model_type"] == LLMType.IMAGE2TEXT.value: assert factory in CvModel, f"Image to text model from {factory} is not supported yet." - mdl = CvModel[factory]( - key=llm["api_key"], - model_name=mdl_nm, - base_url=llm["api_base"] - ) + mdl = CvModel[factory](key=llm["api_key"], model_name=mdl_nm, base_url=llm["api_base"]) try: - with open(os.path.join(get_project_base_directory(), "web/src/assets/yay.jpg"), "rb") as f: - m, tc = mdl.describe(f.read()) - if not m and not tc: - raise Exception(m) + image_data = test_image + m, tc = mdl.describe(image_data) + if not tc and m.find("**ERROR**:") >= 0: + raise Exception(m) except Exception as e: - msg += f"\nFail to access model({mdl_nm})." + str(e) + msg += f"\nFail to access model({factory}/{mdl_nm})." + str(e) elif llm["model_type"] == LLMType.TTS: assert factory in TTSModel, f"TTS model from {factory} is not supported yet." - mdl = TTSModel[factory]( - key=llm["api_key"], model_name=mdl_nm, base_url=llm["api_base"] - ) + mdl = TTSModel[factory](key=llm["api_key"], model_name=mdl_nm, base_url=llm["api_base"]) try: - for resp in mdl.tts("Hello~ Ragflower!"): + for resp in mdl.tts("Hello~ RAGFlower!"): pass except RuntimeError as e: - msg += f"\nFail to access model({mdl_nm})." + str(e) + msg += f"\nFail to access model({factory}/{mdl_nm})." + str(e) else: # TODO: check other type of models pass @@ -279,76 +258,107 @@ def apikey_json(keys): if msg: return get_data_error_result(message=msg) - if not TenantLLMService.filter_update( - [TenantLLM.tenant_id == current_user.id, TenantLLM.llm_factory == factory, - TenantLLM.llm_name == llm["llm_name"]], llm): + if not TenantLLMService.filter_update([TenantLLM.tenant_id == current_user.id, TenantLLM.llm_factory == factory, TenantLLM.llm_name == llm["llm_name"]], llm): TenantLLMService.save(**llm) return get_json_result(data=True) -@manager.route('/delete_llm', methods=['POST']) # noqa: F821 +@manager.route("/delete_llm", methods=["POST"]) # noqa: F821 @login_required @validate_request("llm_factory", "llm_name") def delete_llm(): req = request.json - TenantLLMService.filter_delete( - [TenantLLM.tenant_id == current_user.id, TenantLLM.llm_factory == req["llm_factory"], - TenantLLM.llm_name == req["llm_name"]]) + TenantLLMService.filter_delete([TenantLLM.tenant_id == current_user.id, TenantLLM.llm_factory == req["llm_factory"], TenantLLM.llm_name == req["llm_name"]]) + return get_json_result(data=True) + + +@manager.route("/enable_llm", methods=["POST"]) # noqa: F821 +@login_required +@validate_request("llm_factory", "llm_name") +def enable_llm(): + req = request.json + TenantLLMService.filter_update( + [TenantLLM.tenant_id == current_user.id, TenantLLM.llm_factory == req["llm_factory"], TenantLLM.llm_name == req["llm_name"]], {"status": str(req.get("status", "1"))} + ) return get_json_result(data=True) -@manager.route('/delete_factory', methods=['POST']) # noqa: F821 +@manager.route("/delete_factory", methods=["POST"]) # noqa: F821 @login_required @validate_request("llm_factory") def delete_factory(): req = request.json - TenantLLMService.filter_delete( - [TenantLLM.tenant_id == current_user.id, TenantLLM.llm_factory == req["llm_factory"]]) + TenantLLMService.filter_delete([TenantLLM.tenant_id == current_user.id, TenantLLM.llm_factory == req["llm_factory"]]) return get_json_result(data=True) -@manager.route('/my_llms', methods=['GET']) # noqa: F821 +@manager.route("/my_llms", methods=["GET"]) # noqa: F821 @login_required def my_llms(): try: - res = {} - for o in TenantLLMService.get_my_llms(current_user.id): - if o["llm_factory"] not in res: - res[o["llm_factory"]] = { - "tags": o["tags"], - "llm": [] - } - res[o["llm_factory"]]["llm"].append({ - "type": o["model_type"], - "name": o["llm_name"], - "used_token": o["used_tokens"] - }) + include_details = request.args.get("include_details", "false").lower() == "true" + + if include_details: + res = {} + objs = TenantLLMService.query(tenant_id=current_user.id) + factories = LLMFactoriesService.query(status=StatusEnum.VALID.value) + + for o in objs: + o_dict = o.to_dict() + factory_tags = None + for f in factories: + if f.name == o_dict["llm_factory"]: + factory_tags = f.tags + break + + if o_dict["llm_factory"] not in res: + res[o_dict["llm_factory"]] = {"tags": factory_tags, "llm": []} + + res[o_dict["llm_factory"]]["llm"].append( + { + "type": o_dict["model_type"], + "name": o_dict["llm_name"], + "used_token": o_dict["used_tokens"], + "api_base": o_dict["api_base"] or "", + "max_tokens": o_dict["max_tokens"] or 8192, + "status": o_dict["status"] or "1", + } + ) + else: + res = {} + for o in TenantLLMService.get_my_llms(current_user.id): + if o["llm_factory"] not in res: + res[o["llm_factory"]] = {"tags": o["tags"], "llm": []} + res[o["llm_factory"]]["llm"].append({"type": o["model_type"], "name": o["llm_name"], "used_token": o["used_tokens"], "status": o["status"]}) + return get_json_result(data=res) except Exception as e: return server_error_response(e) -@manager.route('/list', methods=['GET']) # noqa: F821 +@manager.route("/list", methods=["GET"]) # noqa: F821 @login_required def list_app(): - self_deployed = ["Youdao", "FastEmbed", "BAAI", "Ollama", "Xinference", "LocalAI", "LM-Studio", "GPUStack"] - weighted = ["Youdao", "FastEmbed", "BAAI"] if settings.LIGHTEN != 0 else [] + self_deployed = ["FastEmbed", "Ollama", "Xinference", "LocalAI", "LM-Studio", "GPUStack"] + weighted = [] model_type = request.args.get("model_type") try: objs = TenantLLMService.query(tenant_id=current_user.id) - facts = set([o.to_dict()["llm_factory"] for o in objs if o.api_key]) + facts = set([o.to_dict()["llm_factory"] for o in objs if o.api_key and o.status == StatusEnum.VALID.value]) + status = {(o.llm_name + "@" + o.llm_factory) for o in objs if o.status == StatusEnum.VALID.value} llms = LLMService.get_all() - llms = [m.to_dict() - for m in llms if m.status == StatusEnum.VALID.value and m.fid not in weighted] + llms = [m.to_dict() for m in llms if m.status == StatusEnum.VALID.value and m.fid not in weighted and (m.fid == 'Builtin' or (m.llm_name + "@" + m.fid) in status)] for m in llms: m["available"] = m["fid"] in facts or m["llm_name"].lower() == "flag-embedding" or m["fid"] in self_deployed + if "tei-" in os.getenv("COMPOSE_PROFILES", "") and m["model_type"] == LLMType.EMBEDDING and m["fid"] == "Builtin" and m["llm_name"] == os.getenv("TEI_MODEL", ""): + m["available"] = True llm_set = set([m["llm_name"] + "@" + m["fid"] for m in llms]) for o in objs: if o.llm_name + "@" + o.llm_factory in llm_set: continue - llms.append({"llm_name": o.llm_name, "model_type": o.model_type, "fid": o.llm_factory, "available": True}) + llms.append({"llm_name": o.llm_name, "model_type": o.model_type, "fid": o.llm_factory, "available": True, "status": StatusEnum.VALID.value}) res = {} for m in llms: diff --git a/api/apps/mcp_server_app.py b/api/apps/mcp_server_app.py new file mode 100644 index 00000000000..66d4474915e --- /dev/null +++ b/api/apps/mcp_server_app.py @@ -0,0 +1,443 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from flask import Response, request +from flask_login import current_user, login_required + +from api.db.db_models import MCPServer +from api.db.services.mcp_server_service import MCPServerService +from api.db.services.user_service import TenantService +from common.constants import RetCode, VALID_MCP_SERVER_TYPES + +from common.misc_utils import get_uuid +from api.utils.api_utils import get_data_error_result, get_json_result, server_error_response, validate_request, \ + get_mcp_tools +from api.utils.web_utils import get_float, safe_json_parse +from rag.utils.mcp_tool_call_conn import MCPToolCallSession, close_multiple_mcp_toolcall_sessions + + +@manager.route("/list", methods=["POST"]) # noqa: F821 +@login_required +def list_mcp() -> Response: + keywords = request.args.get("keywords", "") + page_number = int(request.args.get("page", 0)) + items_per_page = int(request.args.get("page_size", 0)) + orderby = request.args.get("orderby", "create_time") + if request.args.get("desc", "true").lower() == "false": + desc = False + else: + desc = True + + req = request.get_json() + mcp_ids = req.get("mcp_ids", []) + try: + servers = MCPServerService.get_servers(current_user.id, mcp_ids, 0, 0, orderby, desc, keywords) or [] + total = len(servers) + + if page_number and items_per_page: + servers = servers[(page_number - 1) * items_per_page : page_number * items_per_page] + + return get_json_result(data={"mcp_servers": servers, "total": total}) + except Exception as e: + return server_error_response(e) + + +@manager.route("/detail", methods=["GET"]) # noqa: F821 +@login_required +def detail() -> Response: + mcp_id = request.args["mcp_id"] + try: + mcp_server = MCPServerService.get_or_none(id=mcp_id, tenant_id=current_user.id) + + if mcp_server is None: + return get_json_result(code=RetCode.NOT_FOUND, data=None) + + return get_json_result(data=mcp_server.to_dict()) + except Exception as e: + return server_error_response(e) + + +@manager.route("/create", methods=["POST"]) # noqa: F821 +@login_required +@validate_request("name", "url", "server_type") +def create() -> Response: + req = request.get_json() + + server_type = req.get("server_type", "") + if server_type not in VALID_MCP_SERVER_TYPES: + return get_data_error_result(message="Unsupported MCP server type.") + + server_name = req.get("name", "") + if not server_name or len(server_name.encode("utf-8")) > 255: + return get_data_error_result(message=f"Invalid MCP name or length is {len(server_name)} which is large than 255.") + + e, _ = MCPServerService.get_by_name_and_tenant(name=server_name, tenant_id=current_user.id) + if e: + return get_data_error_result(message="Duplicated MCP server name.") + + url = req.get("url", "") + if not url: + return get_data_error_result(message="Invalid url.") + + headers = safe_json_parse(req.get("headers", {})) + req["headers"] = headers + variables = safe_json_parse(req.get("variables", {})) + variables.pop("tools", None) + + timeout = get_float(req, "timeout", 10) + + try: + req["id"] = get_uuid() + req["tenant_id"] = current_user.id + + e, _ = TenantService.get_by_id(current_user.id) + if not e: + return get_data_error_result(message="Tenant not found.") + + mcp_server = MCPServer(id=server_name, name=server_name, url=url, server_type=server_type, variables=variables, headers=headers) + server_tools, err_message = get_mcp_tools([mcp_server], timeout) + if err_message: + return get_data_error_result(err_message) + + tools = server_tools[server_name] + tools = {tool["name"]: tool for tool in tools if isinstance(tool, dict) and "name" in tool} + variables["tools"] = tools + req["variables"] = variables + + if not MCPServerService.insert(**req): + return get_data_error_result("Failed to create MCP server.") + + return get_json_result(data=req) + except Exception as e: + return server_error_response(e) + + +@manager.route("/update", methods=["POST"]) # noqa: F821 +@login_required +@validate_request("mcp_id") +def update() -> Response: + req = request.get_json() + + mcp_id = req.get("mcp_id", "") + e, mcp_server = MCPServerService.get_by_id(mcp_id) + if not e or mcp_server.tenant_id != current_user.id: + return get_data_error_result(message=f"Cannot find MCP server {mcp_id} for user {current_user.id}") + + server_type = req.get("server_type", mcp_server.server_type) + if server_type and server_type not in VALID_MCP_SERVER_TYPES: + return get_data_error_result(message="Unsupported MCP server type.") + server_name = req.get("name", mcp_server.name) + if server_name and len(server_name.encode("utf-8")) > 255: + return get_data_error_result(message=f"Invalid MCP name or length is {len(server_name)} which is large than 255.") + url = req.get("url", mcp_server.url) + if not url: + return get_data_error_result(message="Invalid url.") + + headers = safe_json_parse(req.get("headers", mcp_server.headers)) + req["headers"] = headers + + variables = safe_json_parse(req.get("variables", mcp_server.variables)) + variables.pop("tools", None) + + timeout = get_float(req, "timeout", 10) + + try: + req["tenant_id"] = current_user.id + req.pop("mcp_id", None) + req["id"] = mcp_id + + mcp_server = MCPServer(id=server_name, name=server_name, url=url, server_type=server_type, variables=variables, headers=headers) + server_tools, err_message = get_mcp_tools([mcp_server], timeout) + if err_message: + return get_data_error_result(err_message) + + tools = server_tools[server_name] + tools = {tool["name"]: tool for tool in tools if isinstance(tool, dict) and "name" in tool} + variables["tools"] = tools + req["variables"] = variables + + if not MCPServerService.filter_update([MCPServer.id == mcp_id, MCPServer.tenant_id == current_user.id], req): + return get_data_error_result(message="Failed to updated MCP server.") + + e, updated_mcp = MCPServerService.get_by_id(req["id"]) + if not e: + return get_data_error_result(message="Failed to fetch updated MCP server.") + + return get_json_result(data=updated_mcp.to_dict()) + except Exception as e: + return server_error_response(e) + + +@manager.route("/rm", methods=["POST"]) # noqa: F821 +@login_required +@validate_request("mcp_ids") +def rm() -> Response: + req = request.get_json() + mcp_ids = req.get("mcp_ids", []) + + try: + req["tenant_id"] = current_user.id + + if not MCPServerService.delete_by_ids(mcp_ids): + return get_data_error_result(message=f"Failed to delete MCP servers {mcp_ids}") + + return get_json_result(data=True) + except Exception as e: + return server_error_response(e) + + +@manager.route("/import", methods=["POST"]) # noqa: F821 +@login_required +@validate_request("mcpServers") +def import_multiple() -> Response: + req = request.get_json() + servers = req.get("mcpServers", {}) + if not servers: + return get_data_error_result(message="No MCP servers provided.") + + timeout = get_float(req, "timeout", 10) + + results = [] + try: + for server_name, config in servers.items(): + if not all(key in config for key in {"type", "url"}): + results.append({"server": server_name, "success": False, "message": "Missing required fields (type or url)"}) + continue + + if not server_name or len(server_name.encode("utf-8")) > 255: + results.append({"server": server_name, "success": False, "message": f"Invalid MCP name or length is {len(server_name)} which is large than 255."}) + continue + + base_name = server_name + new_name = base_name + counter = 0 + + while True: + e, _ = MCPServerService.get_by_name_and_tenant(name=new_name, tenant_id=current_user.id) + if not e: + break + new_name = f"{base_name}_{counter}" + counter += 1 + + create_data = { + "id": get_uuid(), + "tenant_id": current_user.id, + "name": new_name, + "url": config["url"], + "server_type": config["type"], + "variables": {"authorization_token": config.get("authorization_token", "")}, + } + + headers = {"authorization_token": config["authorization_token"]} if "authorization_token" in config else {} + variables = {k: v for k, v in config.items() if k not in {"type", "url", "headers"}} + mcp_server = MCPServer(id=new_name, name=new_name, url=config["url"], server_type=config["type"], variables=variables, headers=headers) + server_tools, err_message = get_mcp_tools([mcp_server], timeout) + if err_message: + results.append({"server": base_name, "success": False, "message": err_message}) + continue + + tools = server_tools[new_name] + tools = {tool["name"]: tool for tool in tools if isinstance(tool, dict) and "name" in tool} + create_data["variables"]["tools"] = tools + + if MCPServerService.insert(**create_data): + result = {"server": server_name, "success": True, "action": "created", "id": create_data["id"], "new_name": new_name} + if new_name != base_name: + result["message"] = f"Renamed from '{base_name}' to '{new_name}' avoid duplication" + results.append(result) + else: + results.append({"server": server_name, "success": False, "message": "Failed to create MCP server."}) + + return get_json_result(data={"results": results}) + except Exception as e: + return server_error_response(e) + + +@manager.route("/export", methods=["POST"]) # noqa: F821 +@login_required +@validate_request("mcp_ids") +def export_multiple() -> Response: + req = request.get_json() + mcp_ids = req.get("mcp_ids", []) + + if not mcp_ids: + return get_data_error_result(message="No MCP server IDs provided.") + + try: + exported_servers = {} + + for mcp_id in mcp_ids: + e, mcp_server = MCPServerService.get_by_id(mcp_id) + + if e and mcp_server.tenant_id == current_user.id: + server_key = mcp_server.name + + exported_servers[server_key] = { + "type": mcp_server.server_type, + "url": mcp_server.url, + "name": mcp_server.name, + "authorization_token": mcp_server.variables.get("authorization_token", ""), + "tools": mcp_server.variables.get("tools", {}), + } + + return get_json_result(data={"mcpServers": exported_servers}) + except Exception as e: + return server_error_response(e) + + +@manager.route("/list_tools", methods=["POST"]) # noqa: F821 +@login_required +@validate_request("mcp_ids") +def list_tools() -> Response: + req = request.get_json() + mcp_ids = req.get("mcp_ids", []) + if not mcp_ids: + return get_data_error_result(message="No MCP server IDs provided.") + + timeout = get_float(req, "timeout", 10) + + results = {} + tool_call_sessions = [] + try: + for mcp_id in mcp_ids: + e, mcp_server = MCPServerService.get_by_id(mcp_id) + + if e and mcp_server.tenant_id == current_user.id: + server_key = mcp_server.id + + cached_tools = mcp_server.variables.get("tools", {}) + + tool_call_session = MCPToolCallSession(mcp_server, mcp_server.variables) + tool_call_sessions.append(tool_call_session) + + try: + tools = tool_call_session.get_tools(timeout) + except Exception as e: + tools = [] + return get_data_error_result(message=f"MCP list tools error: {e}") + + results[server_key] = [] + for tool in tools: + tool_dict = tool.model_dump() + cached_tool = cached_tools.get(tool_dict["name"], {}) + + tool_dict["enabled"] = cached_tool.get("enabled", True) + results[server_key].append(tool_dict) + + return get_json_result(data=results) + except Exception as e: + return server_error_response(e) + finally: + # PERF: blocking call to close sessions — consider moving to background thread or task queue + close_multiple_mcp_toolcall_sessions(tool_call_sessions) + + +@manager.route("/test_tool", methods=["POST"]) # noqa: F821 +@login_required +@validate_request("mcp_id", "tool_name", "arguments") +def test_tool() -> Response: + req = request.get_json() + mcp_id = req.get("mcp_id", "") + if not mcp_id: + return get_data_error_result(message="No MCP server ID provided.") + + timeout = get_float(req, "timeout", 10) + + tool_name = req.get("tool_name", "") + arguments = req.get("arguments", {}) + if not all([tool_name, arguments]): + return get_data_error_result(message="Require provide tool name and arguments.") + + tool_call_sessions = [] + try: + e, mcp_server = MCPServerService.get_by_id(mcp_id) + if not e or mcp_server.tenant_id != current_user.id: + return get_data_error_result(message=f"Cannot find MCP server {mcp_id} for user {current_user.id}") + + tool_call_session = MCPToolCallSession(mcp_server, mcp_server.variables) + tool_call_sessions.append(tool_call_session) + result = tool_call_session.tool_call(tool_name, arguments, timeout) + + # PERF: blocking call to close sessions — consider moving to background thread or task queue + close_multiple_mcp_toolcall_sessions(tool_call_sessions) + return get_json_result(data=result) + except Exception as e: + return server_error_response(e) + + +@manager.route("/cache_tools", methods=["POST"]) # noqa: F821 +@login_required +@validate_request("mcp_id", "tools") +def cache_tool() -> Response: + req = request.get_json() + mcp_id = req.get("mcp_id", "") + if not mcp_id: + return get_data_error_result(message="No MCP server ID provided.") + tools = req.get("tools", []) + + e, mcp_server = MCPServerService.get_by_id(mcp_id) + if not e or mcp_server.tenant_id != current_user.id: + return get_data_error_result(message=f"Cannot find MCP server {mcp_id} for user {current_user.id}") + + variables = mcp_server.variables + tools = {tool["name"]: tool for tool in tools if isinstance(tool, dict) and "name" in tool} + variables["tools"] = tools + + if not MCPServerService.filter_update([MCPServer.id == mcp_id, MCPServer.tenant_id == current_user.id], {"variables": variables}): + return get_data_error_result(message="Failed to updated MCP server.") + + return get_json_result(data=tools) + + +@manager.route("/test_mcp", methods=["POST"]) # noqa: F821 +@validate_request("url", "server_type") +def test_mcp() -> Response: + req = request.get_json() + + url = req.get("url", "") + if not url: + return get_data_error_result(message="Invalid MCP url.") + + server_type = req.get("server_type", "") + if server_type not in VALID_MCP_SERVER_TYPES: + return get_data_error_result(message="Unsupported MCP server type.") + + timeout = get_float(req, "timeout", 10) + headers = safe_json_parse(req.get("headers", {})) + variables = safe_json_parse(req.get("variables", {})) + + mcp_server = MCPServer(id=f"{server_type}: {url}", server_type=server_type, url=url, headers=headers, variables=variables) + + result = [] + try: + tool_call_session = MCPToolCallSession(mcp_server, mcp_server.variables) + + try: + tools = tool_call_session.get_tools(timeout) + except Exception as e: + tools = [] + return get_data_error_result(message=f"Test MCP error: {e}") + finally: + # PERF: blocking call to close sessions — consider moving to background thread or task queue + close_multiple_mcp_toolcall_sessions([tool_call_session]) + + for tool in tools: + tool_dict = tool.model_dump() + tool_dict["enabled"] = True + result.append(tool_dict) + + return get_json_result(data=result) + except Exception as e: + return server_error_response(e) diff --git a/api/apps/plugin_app.py b/api/apps/plugin_app.py index dcd209daaac..9ca04416db0 100644 --- a/api/apps/plugin_app.py +++ b/api/apps/plugin_app.py @@ -1,8 +1,26 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + from flask import Response from flask_login import login_required from api.utils.api_utils import get_json_result from plugin import GlobalPluginManager + @manager.route('/llm_tools', methods=['GET']) # noqa: F821 @login_required def llm_tools() -> Response: diff --git a/api/apps/sdk/agent.py b/api/apps/sdk/agent.py deleted file mode 100644 index 704a3ffcf32..00000000000 --- a/api/apps/sdk/agent.py +++ /dev/null @@ -1,128 +0,0 @@ -# -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import json -import time -from typing import Any, cast -from api.db.services.canvas_service import UserCanvasService -from api.db.services.user_canvas_version import UserCanvasVersionService -from api.settings import RetCode -from api.utils import get_uuid -from api.utils.api_utils import get_data_error_result, get_error_data_result, get_json_result, token_required -from api.utils.api_utils import get_result -from flask import request - -@manager.route('/agents', methods=['GET']) # noqa: F821 -@token_required -def list_agents(tenant_id): - id = request.args.get("id") - title = request.args.get("title") - if id or title: - canvas = UserCanvasService.query(id=id, title=title, user_id=tenant_id) - if not canvas: - return get_error_data_result("The agent doesn't exist.") - page_number = int(request.args.get("page", 1)) - items_per_page = int(request.args.get("page_size", 30)) - orderby = request.args.get("orderby", "update_time") - if request.args.get("desc") == "False" or request.args.get("desc") == "false": - desc = False - else: - desc = True - canvas = UserCanvasService.get_list(tenant_id,page_number,items_per_page,orderby,desc,id,title) - return get_result(data=canvas) - - -@manager.route("/agents", methods=["POST"]) # noqa: F821 -@token_required -def create_agent(tenant_id: str): - req: dict[str, Any] = cast(dict[str, Any], request.json) - req["user_id"] = tenant_id - - if req.get("dsl") is not None: - if not isinstance(req["dsl"], str): - req["dsl"] = json.dumps(req["dsl"], ensure_ascii=False) - - req["dsl"] = json.loads(req["dsl"]) - else: - return get_json_result(data=False, message="No DSL data in request.", code=RetCode.ARGUMENT_ERROR) - - if req.get("title") is not None: - req["title"] = req["title"].strip() - else: - return get_json_result(data=False, message="No title in request.", code=RetCode.ARGUMENT_ERROR) - - if UserCanvasService.query(user_id=tenant_id, title=req["title"]): - return get_data_error_result(message=f"Agent with title {req['title']} already exists.") - - agent_id = get_uuid() - req["id"] = agent_id - - if not UserCanvasService.save(**req): - return get_data_error_result(message="Fail to create agent.") - - UserCanvasVersionService.insert( - user_canvas_id=agent_id, - title="{0}_{1}".format(req["title"], time.strftime("%Y_%m_%d_%H_%M_%S")), - dsl=req["dsl"] - ) - - return get_json_result(data=True) - - -@manager.route("/agents/", methods=["PUT"]) # noqa: F821 -@token_required -def update_agent(tenant_id: str, agent_id: str): - req: dict[str, Any] = {k: v for k, v in cast(dict[str, Any], request.json).items() if v is not None} - req["user_id"] = tenant_id - - if req.get("dsl") is not None: - if not isinstance(req["dsl"], str): - req["dsl"] = json.dumps(req["dsl"], ensure_ascii=False) - - req["dsl"] = json.loads(req["dsl"]) - - if req.get("title") is not None: - req["title"] = req["title"].strip() - - if not UserCanvasService.query(user_id=tenant_id, id=agent_id): - return get_json_result( - data=False, message="Only owner of canvas authorized for this operation.", - code=RetCode.OPERATING_ERROR) - - UserCanvasService.update_by_id(agent_id, req) - - if req.get("dsl") is not None: - UserCanvasVersionService.insert( - user_canvas_id=agent_id, - title="{0}_{1}".format(req["title"], time.strftime("%Y_%m_%d_%H_%M_%S")), - dsl=req["dsl"] - ) - - UserCanvasVersionService.delete_all_versions(agent_id) - - return get_json_result(data=True) - - -@manager.route("/agents/", methods=["DELETE"]) # noqa: F821 -@token_required -def delete_agent(tenant_id: str, agent_id: str): - if not UserCanvasService.query(user_id=tenant_id, id=agent_id): - return get_json_result( - data=False, message="Only owner of canvas authorized for this operation.", - code=RetCode.OPERATING_ERROR) - - UserCanvasService.delete_by_id(agent_id) - return get_json_result(data=True) diff --git a/api/apps/sdk/agents.py b/api/apps/sdk/agents.py new file mode 100644 index 00000000000..208b7a1bef7 --- /dev/null +++ b/api/apps/sdk/agents.py @@ -0,0 +1,179 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import json +import logging +import time +from typing import Any, cast + +from agent.canvas import Canvas +from api.db import CanvasCategory +from api.db.services.canvas_service import UserCanvasService +from api.db.services.user_canvas_version import UserCanvasVersionService +from common.constants import RetCode +from common.misc_utils import get_uuid +from api.utils.api_utils import get_data_error_result, get_error_data_result, get_json_result, token_required +from api.utils.api_utils import get_result +from flask import request, Response + + +@manager.route('/agents', methods=['GET']) # noqa: F821 +@token_required +def list_agents(tenant_id): + id = request.args.get("id") + title = request.args.get("title") + if id or title: + canvas = UserCanvasService.query(id=id, title=title, user_id=tenant_id) + if not canvas: + return get_error_data_result("The agent doesn't exist.") + page_number = int(request.args.get("page", 1)) + items_per_page = int(request.args.get("page_size", 30)) + orderby = request.args.get("orderby", "update_time") + if request.args.get("desc") == "False" or request.args.get("desc") == "false": + desc = False + else: + desc = True + canvas = UserCanvasService.get_list(tenant_id, page_number, items_per_page, orderby, desc, id, title) + return get_result(data=canvas) + + +@manager.route("/agents", methods=["POST"]) # noqa: F821 +@token_required +def create_agent(tenant_id: str): + req: dict[str, Any] = cast(dict[str, Any], request.json) + req["user_id"] = tenant_id + + if req.get("dsl") is not None: + if not isinstance(req["dsl"], str): + req["dsl"] = json.dumps(req["dsl"], ensure_ascii=False) + + req["dsl"] = json.loads(req["dsl"]) + else: + return get_json_result(data=False, message="No DSL data in request.", code=RetCode.ARGUMENT_ERROR) + + if req.get("title") is not None: + req["title"] = req["title"].strip() + else: + return get_json_result(data=False, message="No title in request.", code=RetCode.ARGUMENT_ERROR) + + if UserCanvasService.query(user_id=tenant_id, title=req["title"]): + return get_data_error_result(message=f"Agent with title {req['title']} already exists.") + + agent_id = get_uuid() + req["id"] = agent_id + + if not UserCanvasService.save(**req): + return get_data_error_result(message="Fail to create agent.") + + UserCanvasVersionService.insert( + user_canvas_id=agent_id, + title="{0}_{1}".format(req["title"], time.strftime("%Y_%m_%d_%H_%M_%S")), + dsl=req["dsl"] + ) + + return get_json_result(data=True) + + +@manager.route("/agents/", methods=["PUT"]) # noqa: F821 +@token_required +def update_agent(tenant_id: str, agent_id: str): + req: dict[str, Any] = {k: v for k, v in cast(dict[str, Any], request.json).items() if v is not None} + req["user_id"] = tenant_id + + if req.get("dsl") is not None: + if not isinstance(req["dsl"], str): + req["dsl"] = json.dumps(req["dsl"], ensure_ascii=False) + + req["dsl"] = json.loads(req["dsl"]) + + if req.get("title") is not None: + req["title"] = req["title"].strip() + + if not UserCanvasService.query(user_id=tenant_id, id=agent_id): + return get_json_result( + data=False, message="Only owner of canvas authorized for this operation.", + code=RetCode.OPERATING_ERROR) + + UserCanvasService.update_by_id(agent_id, req) + + if req.get("dsl") is not None: + UserCanvasVersionService.insert( + user_canvas_id=agent_id, + title="{0}_{1}".format(req["title"], time.strftime("%Y_%m_%d_%H_%M_%S")), + dsl=req["dsl"] + ) + + UserCanvasVersionService.delete_all_versions(agent_id) + + return get_json_result(data=True) + + +@manager.route("/agents/", methods=["DELETE"]) # noqa: F821 +@token_required +def delete_agent(tenant_id: str, agent_id: str): + if not UserCanvasService.query(user_id=tenant_id, id=agent_id): + return get_json_result( + data=False, message="Only owner of canvas authorized for this operation.", + code=RetCode.OPERATING_ERROR) + + UserCanvasService.delete_by_id(agent_id) + return get_json_result(data=True) + + +@manager.route('/webhook/', methods=['POST']) # noqa: F821 +@token_required +def webhook(tenant_id: str, agent_id: str): + req = request.json + if not UserCanvasService.accessible(req["id"], tenant_id): + return get_json_result( + data=False, message='Only owner of canvas authorized for this operation.', + code=RetCode.OPERATING_ERROR) + + e, cvs = UserCanvasService.get_by_id(req["id"]) + if not e: + return get_data_error_result(message="canvas not found.") + + if not isinstance(cvs.dsl, str): + cvs.dsl = json.dumps(cvs.dsl, ensure_ascii=False) + + if cvs.canvas_category == CanvasCategory.DataFlow: + return get_data_error_result(message="Dataflow can not be triggered by webhook.") + + try: + canvas = Canvas(cvs.dsl, tenant_id, agent_id) + except Exception as e: + return get_json_result( + data=False, message=str(e), + code=RetCode.EXCEPTION_ERROR) + + def sse(): + nonlocal canvas + try: + for ans in canvas.run(query=req.get("query", ""), files=req.get("files", []), user_id=req.get("user_id", tenant_id), webhook_payload=req): + yield "data:" + json.dumps(ans, ensure_ascii=False) + "\n\n" + + cvs.dsl = json.loads(str(canvas)) + UserCanvasService.update_by_id(req["id"], cvs.to_dict()) + except Exception as e: + logging.exception(e) + yield "data:" + json.dumps({"code": 500, "message": str(e), "data": False}, ensure_ascii=False) + "\n\n" + + resp = Response(sse(), mimetype="text/event-stream") + resp.headers.add_header("Cache-control", "no-cache") + resp.headers.add_header("Connection", "keep-alive") + resp.headers.add_header("X-Accel-Buffering", "no") + resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8") + return resp diff --git a/api/apps/sdk/chat.py b/api/apps/sdk/chat.py index 3667dab548f..a3f03b4484f 100644 --- a/api/apps/sdk/chat.py +++ b/api/apps/sdk/chat.py @@ -17,13 +17,12 @@ from flask import request -from api import settings -from api.db import StatusEnum from api.db.services.dialog_service import DialogService from api.db.services.knowledgebase_service import KnowledgebaseService -from api.db.services.llm_service import TenantLLMService +from api.db.services.tenant_llm_service import TenantLLMService from api.db.services.user_service import TenantService -from api.utils import get_uuid +from common.misc_utils import get_uuid +from common.constants import RetCode, StatusEnum from api.utils.api_utils import check_duplicate_ids, get_error_data_result, get_result, token_required @@ -45,7 +44,7 @@ def create(tenant_id): embd_ids = [TenantLLMService.split_model_name_and_factory(kb.embd_id)[0] for kb in kbs] # remove vendor suffix for comparison embd_count = list(set(embd_ids)) if len(embd_count) > 1: - return get_result(message='Datasets use different embedding models."', code=settings.RetCode.AUTHENTICATION_ERROR) + return get_result(message='Datasets use different embedding models."', code=RetCode.AUTHENTICATION_ERROR) req["kb_ids"] = ids # llm llm = req.get("llm") @@ -99,7 +98,7 @@ def create(tenant_id): Here is the knowledge base: {knowledge} The above is the knowledge base.""", - "prologue": "Hi! I'm your assistant, what can I do for you?", + "prologue": "Hi! I'm your assistant. What can I do for you?", "parameters": [{"key": "knowledge", "optional": False}], "empty_response": "Sorry! No relevant content was found in the knowledge base!", "quote": True, @@ -139,7 +138,7 @@ def create(tenant_id): res["llm"] = res.pop("llm_setting") res["llm"]["model_name"] = res.pop("llm_id") del res["kb_ids"] - res["dataset_ids"] = req["dataset_ids"] + res["dataset_ids"] = req.get("dataset_ids", []) res["avatar"] = res.pop("icon") return get_result(data=res) @@ -150,10 +149,10 @@ def update(tenant_id, chat_id): if not DialogService.query(tenant_id=tenant_id, id=chat_id, status=StatusEnum.VALID.value): return get_error_data_result(message="You do not own the chat") req = request.json - ids = req.get("dataset_ids") + ids = req.get("dataset_ids", []) if "show_quotation" in req: req["do_refer"] = req.pop("show_quotation") - if ids is not None: + if ids: for kb_id in ids: kbs = KnowledgebaseService.accessible(kb_id=kb_id, user_id=tenant_id) if not kbs: @@ -166,9 +165,11 @@ def update(tenant_id, chat_id): kbs = KnowledgebaseService.get_by_ids(ids) embd_ids = [TenantLLMService.split_model_name_and_factory(kb.embd_id)[0] for kb in kbs] # remove vendor suffix for comparison embd_count = list(set(embd_ids)) - if len(embd_count) != 1: - return get_result(message='Datasets use different embedding models."', code=settings.RetCode.AUTHENTICATION_ERROR) + if len(embd_count) > 1: + return get_result(message='Datasets use different embedding models."', code=RetCode.AUTHENTICATION_ERROR) req["kb_ids"] = ids + else: + req["kb_ids"] = [] llm = req.get("llm") if llm: if "model_name" in llm: diff --git a/api/apps/sdk/dataset.py b/api/apps/sdk/dataset.py index e3675b8cd00..8a315ce69d1 100644 --- a/api/apps/sdk/dataset.py +++ b/api/apps/sdk/dataset.py @@ -17,24 +17,20 @@ import logging import os - +import json from flask import request from peewee import OperationalError - -from api import settings -from api.db import FileSource, StatusEnum from api.db.db_models import File from api.db.services.document_service import DocumentService from api.db.services.file2document_service import File2DocumentService from api.db.services.file_service import FileService from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.user_service import TenantService -from api.utils import get_uuid +from common.constants import RetCode, FileSource, StatusEnum from api.utils.api_utils import ( deep_merge, get_error_argument_result, get_error_data_result, - get_error_operating_result, get_error_permission_result, get_parser_config, get_result, @@ -51,7 +47,8 @@ validate_and_parse_request_args, ) from rag.nlp import search -from rag.settings import PAGERANK_FLD +from common.constants import PAGERANK_FLD +from common import settings @manager.route("/datasets", methods=["POST"]) # noqa: F821 @@ -81,29 +78,28 @@ def create(tenant_id): properties: name: type: string - description: Name of the dataset. + description: Dataset name (required). avatar: type: string - description: Base64 encoding of the avatar. + description: Optional base64-encoded avatar image. description: type: string - description: Description of the dataset. + description: Optional dataset description. embedding_model: type: string - description: Embedding model Name. + description: Optional embedding model name; if omitted, the tenant's default embedding model is used. permission: type: string enum: ['me', 'team'] - description: Dataset permission. + description: Visibility of the dataset (private to me or shared with team). chunk_method: type: string enum: ["naive", "book", "email", "laws", "manual", "one", "paper", - "picture", "presentation", "qa", "table", "tag" - ] - description: Chunking method. + "picture", "presentation", "qa", "table", "tag"] + description: Chunking method; if omitted, defaults to "naive". parser_config: type: object - description: Parser configuration. + description: Optional parser configuration; server-side defaults will be applied. responses: 200: description: Successful operation. @@ -118,44 +114,43 @@ def create(tenant_id): # |----------------|-------------| # | embedding_model| embd_id | # | chunk_method | parser_id | + req, err = validate_and_parse_json_request(request, CreateDatasetReq) if err is not None: return get_error_argument_result(err) - - try: - if KnowledgebaseService.get_or_none(name=req["name"], tenant_id=tenant_id, status=StatusEnum.VALID.value): - return get_error_operating_result(message=f"Dataset name '{req['name']}' already exists") - - req["parser_config"] = get_parser_config(req["parser_id"], req["parser_config"]) - req["id"] = get_uuid() - req["tenant_id"] = tenant_id - req["created_by"] = tenant_id - - ok, t = TenantService.get_by_id(tenant_id) + + req = KnowledgebaseService.create_with_name( + name = req.pop("name", None), + tenant_id = tenant_id, + parser_id = req.pop("parser_id", None), + **req + ) + + # Insert embedding model(embd id) + ok, t = TenantService.get_by_id(tenant_id) + if not ok: + return get_error_permission_result(message="Tenant not found") + if not req.get("embd_id"): + req["embd_id"] = t.embd_id + else: + ok, err = verify_embedding_availability(req["embd_id"], tenant_id) if not ok: - return get_error_permission_result(message="Tenant not found") + return err - if not req.get("embd_id"): - req["embd_id"] = t.embd_id - else: - ok, err = verify_embedding_availability(req["embd_id"], tenant_id) - if not ok: - return err - - if not KnowledgebaseService.save(**req): - return get_error_data_result(message="Create dataset error.(Database error)") - ok, k = KnowledgebaseService.get_by_id(req["id"]) - if not ok: - return get_error_data_result(message="Dataset created failed") - - response_data = remap_dictionary_keys(k.to_dict()) - return get_result(data=response_data) - except OperationalError as e: + try: + if not KnowledgebaseService.save(**req): + return get_error_data_result() + ok, k = KnowledgebaseService.get_by_id(req["id"]) + if not ok: + return get_error_data_result(message="Dataset created failed") + + response_data = remap_dictionary_keys(k.to_dict()) + return get_result(data=response_data) + except Exception as e: logging.exception(e) return get_error_data_result(message="Database operation failed") - @manager.route("/datasets", methods=["DELETE"]) # noqa: F821 @token_required def delete(tenant_id): @@ -216,7 +211,8 @@ def delete(tenant_id): continue kb_id_instance_pairs.append((kb_id, kb)) if len(error_kb_ids) > 0: - return get_error_permission_result(message=f"""User '{tenant_id}' lacks permission for datasets: '{", ".join(error_kb_ids)}'""") + return get_error_permission_result( + message=f"""User '{tenant_id}' lacks permission for datasets: '{", ".join(error_kb_ids)}'""") errors = [] success_count = 0 @@ -233,7 +229,8 @@ def delete(tenant_id): ] ) File2DocumentService.delete_by_document_id(doc.id) - FileService.filter_delete([File.source_type == FileSource.KNOWLEDGEBASE, File.type == "folder", File.name == kb.name]) + FileService.filter_delete( + [File.source_type == FileSource.KNOWLEDGEBASE, File.type == "folder", File.name == kb.name]) if not KnowledgebaseService.delete_by_id(kb_id): errors.append(f"Delete dataset error for {kb_id}") continue @@ -330,7 +327,8 @@ def update(tenant_id, dataset_id): try: kb = KnowledgebaseService.get_or_none(id=dataset_id, tenant_id=tenant_id) if kb is None: - return get_error_permission_result(message=f"User '{tenant_id}' lacks permission for dataset '{dataset_id}'") + return get_error_permission_result( + message=f"User '{tenant_id}' lacks permission for dataset '{dataset_id}'") if req.get("parser_config"): req["parser_config"] = deep_merge(kb.parser_config, req["parser_config"]) @@ -342,13 +340,17 @@ def update(tenant_id, dataset_id): del req["parser_config"] if "name" in req and req["name"].lower() != kb.name.lower(): - exists = KnowledgebaseService.get_or_none(name=req["name"], tenant_id=tenant_id, status=StatusEnum.VALID.value) + exists = KnowledgebaseService.get_or_none(name=req["name"], tenant_id=tenant_id, + status=StatusEnum.VALID.value) if exists: return get_error_data_result(message=f"Dataset name '{req['name']}' already exists") if "embd_id" in req: + if not req["embd_id"]: + req["embd_id"] = kb.embd_id if kb.chunk_num != 0 and req["embd_id"] != kb.embd_id: - return get_error_data_result(message=f"When chunk_num ({kb.chunk_num}) > 0, embedding_model must remain {kb.embd_id}") + return get_error_data_result( + message=f"When chunk_num ({kb.chunk_num}) > 0, embedding_model must remain {kb.embd_id}") ok, err = verify_embedding_availability(req["embd_id"], tenant_id) if not ok: return err @@ -358,10 +360,12 @@ def update(tenant_id, dataset_id): return get_error_argument_result(message="'pagerank' can only be set when doc_engine is elasticsearch") if req["pagerank"] > 0: - settings.docStoreConn.update({"kb_id": kb.id}, {PAGERANK_FLD: req["pagerank"]}, search.index_name(kb.tenant_id), kb.id) + settings.docStoreConn.update({"kb_id": kb.id}, {PAGERANK_FLD: req["pagerank"]}, + search.index_name(kb.tenant_id), kb.id) else: # Elasticsearch requires PAGERANK_FLD be non-zero! - settings.docStoreConn.update({"exists": PAGERANK_FLD}, {"remove": PAGERANK_FLD}, search.index_name(kb.tenant_id), kb.id) + settings.docStoreConn.update({"exists": PAGERANK_FLD}, {"remove": PAGERANK_FLD}, + search.index_name(kb.tenant_id), kb.id) if not KnowledgebaseService.update_by_id(kb.id, req): return get_error_data_result(message="Update dataset error.(Database error)") @@ -453,7 +457,7 @@ def list_datasets(tenant_id): return get_error_permission_result(message=f"User '{tenant_id}' lacks permission for dataset '{name}'") tenants = TenantService.get_joined_tenants_by_user_id(tenant_id) - kbs = KnowledgebaseService.get_list( + kbs, total = KnowledgebaseService.get_list( [m["tenant_id"] for m in tenants], tenant_id, args["page"], @@ -467,7 +471,64 @@ def list_datasets(tenant_id): response_data_list = [] for kb in kbs: response_data_list.append(remap_dictionary_keys(kb)) - return get_result(data=response_data_list) + return get_result(data=response_data_list, total=total) except OperationalError as e: logging.exception(e) return get_error_data_result(message="Database operation failed") + + +@manager.route('/datasets//knowledge_graph', methods=['GET']) # noqa: F821 +@token_required +def knowledge_graph(tenant_id, dataset_id): + if not KnowledgebaseService.accessible(dataset_id, tenant_id): + return get_result( + data=False, + message='No authorization.', + code=RetCode.AUTHENTICATION_ERROR + ) + _, kb = KnowledgebaseService.get_by_id(dataset_id) + req = { + "kb_id": [dataset_id], + "knowledge_graph_kwd": ["graph"] + } + + obj = {"graph": {}, "mind_map": {}} + if not settings.docStoreConn.indexExist(search.index_name(kb.tenant_id), dataset_id): + return get_result(data=obj) + sres = settings.retriever.search(req, search.index_name(kb.tenant_id), [dataset_id]) + if not len(sres.ids): + return get_result(data=obj) + + for id in sres.ids[:1]: + ty = sres.field[id]["knowledge_graph_kwd"] + try: + content_json = json.loads(sres.field[id]["content_with_weight"]) + except Exception: + continue + + obj[ty] = content_json + + if "nodes" in obj["graph"]: + obj["graph"]["nodes"] = sorted(obj["graph"]["nodes"], key=lambda x: x.get("pagerank", 0), reverse=True)[:256] + if "edges" in obj["graph"]: + node_id_set = {o["id"] for o in obj["graph"]["nodes"]} + filtered_edges = [o for o in obj["graph"]["edges"] if + o["source"] != o["target"] and o["source"] in node_id_set and o["target"] in node_id_set] + obj["graph"]["edges"] = sorted(filtered_edges, key=lambda x: x.get("weight", 0), reverse=True)[:128] + return get_result(data=obj) + + +@manager.route('/datasets//knowledge_graph', methods=['DELETE']) # noqa: F821 +@token_required +def delete_knowledge_graph(tenant_id, dataset_id): + if not KnowledgebaseService.accessible(dataset_id, tenant_id): + return get_result( + data=False, + message='No authorization.', + code=RetCode.AUTHENTICATION_ERROR + ) + _, kb = KnowledgebaseService.get_by_id(dataset_id) + settings.docStoreConn.delete({"knowledge_graph_kwd": ["graph", "subgraph", "entity", "relation"]}, + search.index_name(kb.tenant_id), dataset_id) + + return get_result(data=True) diff --git a/api/apps/sdk/dify_retrieval.py b/api/apps/sdk/dify_retrieval.py index f15eb2396d0..d2c3485a940 100644 --- a/api/apps/sdk/dify_retrieval.py +++ b/api/apps/sdk/dify_retrieval.py @@ -13,21 +13,106 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import logging + from flask import request, jsonify -from api.db import LLMType from api.db.services.document_service import DocumentService from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.llm_service import LLMBundle -from api import settings from api.utils.api_utils import validate_request, build_error_result, apikey_required from rag.app.tag import label_question - +from api.db.services.dialog_service import meta_filter, convert_conditions +from common.constants import RetCode, LLMType +from common import settings @manager.route('/dify/retrieval', methods=['POST']) # noqa: F821 @apikey_required @validate_request("knowledge_id", "query") def retrieval(tenant_id): + """ + Dify-compatible retrieval API + --- + tags: + - SDK + security: + - ApiKeyAuth: [] + parameters: + - in: body + name: body + required: true + schema: + type: object + required: + - knowledge_id + - query + properties: + knowledge_id: + type: string + description: Knowledge base ID + query: + type: string + description: Query text + use_kg: + type: boolean + description: Whether to use knowledge graph + default: false + retrieval_setting: + type: object + description: Retrieval configuration + properties: + score_threshold: + type: number + description: Similarity threshold + default: 0.0 + top_k: + type: integer + description: Number of results to return + default: 1024 + metadata_condition: + type: object + description: Metadata filter condition + properties: + conditions: + type: array + items: + type: object + properties: + name: + type: string + description: Field name + comparison_operator: + type: string + description: Comparison operator + value: + type: string + description: Field value + responses: + 200: + description: Retrieval succeeded + schema: + type: object + properties: + records: + type: array + items: + type: object + properties: + content: + type: string + description: Content text + score: + type: number + description: Similarity score + title: + type: string + description: Document title + metadata: + type: object + description: Metadata info + 404: + description: Knowledge base or document not found + """ req = request.json question = req["query"] kb_id = req["knowledge_id"] @@ -35,19 +120,24 @@ def retrieval(tenant_id): retrieval_setting = req.get("retrieval_setting", {}) similarity_threshold = float(retrieval_setting.get("score_threshold", 0.0)) top = int(retrieval_setting.get("top_k", 1024)) + metadata_condition = req.get("metadata_condition", {}) + metas = DocumentService.get_meta_by_kbs([kb_id]) + doc_ids = [] try: e, kb = KnowledgebaseService.get_by_id(kb_id) if not e: - return build_error_result(message="Knowledgebase not found!", code=settings.RetCode.NOT_FOUND) - - if kb.tenant_id != tenant_id: - return build_error_result(message="Knowledgebase not found!", code=settings.RetCode.NOT_FOUND) + return build_error_result(message="Knowledgebase not found!", code=RetCode.NOT_FOUND) embd_mdl = LLMBundle(kb.tenant_id, LLMType.EMBEDDING.value, llm_name=kb.embd_id) - - ranks = settings.retrievaler.retrieval( + print(metadata_condition) + # print("after", convert_conditions(metadata_condition)) + doc_ids.extend(meta_filter(metas, convert_conditions(metadata_condition))) + # print("doc_ids", doc_ids) + if not doc_ids and metadata_condition is not None: + doc_ids = ['-999'] + ranks = settings.retriever.retrieval( question, embd_mdl, kb.tenant_id, @@ -57,27 +147,30 @@ def retrieval(tenant_id): similarity_threshold=similarity_threshold, vector_similarity_weight=0.3, top=top, + doc_ids=doc_ids, rank_feature=label_question(question, [kb]) ) if use_kg: - ck = settings.kg_retrievaler.retrieval(question, - [tenant_id], - [kb_id], - embd_mdl, - LLMBundle(kb.tenant_id, LLMType.CHAT)) + ck = settings.kg_retriever.retrieval(question, + [tenant_id], + [kb_id], + embd_mdl, + LLMBundle(kb.tenant_id, LLMType.CHAT)) if ck["content_with_weight"]: ranks["chunks"].insert(0, ck) records = [] for c in ranks["chunks"]: - e, doc = DocumentService.get_by_id( c["doc_id"]) + e, doc = DocumentService.get_by_id(c["doc_id"]) c.pop("vector", None) + meta = getattr(doc, 'meta_fields', {}) + meta["doc_id"] = c["doc_id"] records.append({ "content": c["content_with_weight"], "score": c["similarity"], "title": c["docnm_kwd"], - "metadata": doc.meta_fields + "metadata": meta }) return jsonify({"records": records}) @@ -85,6 +178,7 @@ def retrieval(tenant_id): if str(e).find("not_found") > 0: return build_error_result( message='No chunk found! Check the chunk status please!', - code=settings.RetCode.NOT_FOUND + code=RetCode.NOT_FOUND ) - return build_error_result(message=str(e), code=settings.RetCode.SERVER_ERROR) + logging.exception(e) + return build_error_result(message=str(e), code=RetCode.SERVER_ERROR) diff --git a/api/apps/sdk/doc.py b/api/apps/sdk/doc.py index e0f77c985e9..4caf2cc8dfb 100644 --- a/api/apps/sdk/doc.py +++ b/api/apps/sdk/doc.py @@ -24,23 +24,25 @@ from peewee import OperationalError from pydantic import BaseModel, Field, validator -from api import settings from api.constants import FILE_NAME_LEN_LIMIT -from api.db import FileSource, FileType, LLMType, ParserType, TaskStatus +from api.db import FileType from api.db.db_models import File, Task from api.db.services.document_service import DocumentService from api.db.services.file2document_service import File2DocumentService from api.db.services.file_service import FileService from api.db.services.knowledgebase_service import KnowledgebaseService -from api.db.services.llm_service import LLMBundle, TenantLLMService +from api.db.services.llm_service import LLMBundle +from api.db.services.tenant_llm_service import TenantLLMService from api.db.services.task_service import TaskService, queue_tasks +from api.db.services.dialog_service import meta_filter, convert_conditions from api.utils.api_utils import check_duplicate_ids, construct_json_result, get_error_data_result, get_parser_config, get_result, server_error_response, token_required from rag.app.qa import beAdoc, rmPrefix from rag.app.tag import label_question from rag.nlp import rag_tokenizer, search -from rag.prompts import keyword_extraction -from rag.utils import rmSpace -from rag.utils.storage_factory import STORAGE_IMPL +from rag.prompts.generator import cross_languages, keyword_extraction +from common.string_utils import remove_redundant_spaces +from common.constants import RetCode, LLMType, ParserType, TaskStatus, FileSource +from common import settings MAXIMUM_OF_UPLOADING_FILES = 256 @@ -125,13 +127,13 @@ def upload(dataset_id, tenant_id): description: Processing status. """ if "file" not in request.files: - return get_error_data_result(message="No file part!", code=settings.RetCode.ARGUMENT_ERROR) + return get_error_data_result(message="No file part!", code=RetCode.ARGUMENT_ERROR) file_objs = request.files.getlist("file") for file_obj in file_objs: if file_obj.filename == "": - return get_result(message="No file selected!", code=settings.RetCode.ARGUMENT_ERROR) + return get_result(message="No file selected!", code=RetCode.ARGUMENT_ERROR) if len(file_obj.filename.encode("utf-8")) > FILE_NAME_LEN_LIMIT: - return get_result(message=f"File name must be {FILE_NAME_LEN_LIMIT} bytes or less.", code=settings.RetCode.ARGUMENT_ERROR) + return get_result(message=f"File name must be {FILE_NAME_LEN_LIMIT} bytes or less.", code=RetCode.ARGUMENT_ERROR) """ # total size total_size = 0 @@ -143,7 +145,7 @@ def upload(dataset_id, tenant_id): if total_size > MAX_TOTAL_FILE_SIZE: return get_result( message=f"Total file size exceeds 10MB limit! ({total_size / (1024 * 1024):.2f} MB)", - code=settings.RetCode.ARGUMENT_ERROR, + code=RetCode.ARGUMENT_ERROR, ) """ e, kb = KnowledgebaseService.get_by_id(dataset_id) @@ -151,7 +153,7 @@ def upload(dataset_id, tenant_id): raise LookupError(f"Can't find the dataset with ID {dataset_id}!") err, files = FileService.upload_document(kb, file_objs, tenant_id) if err: - return get_result(message="\n".join(err), code=settings.RetCode.SERVER_ERROR) + return get_result(message="\n".join(err), code=RetCode.SERVER_ERROR) # rename key's name renamed_doc_list = [] for file in files: @@ -251,12 +253,12 @@ def update_doc(tenant_id, dataset_id, document_id): if len(req["name"].encode("utf-8")) > FILE_NAME_LEN_LIMIT: return get_result( message=f"File name must be {FILE_NAME_LEN_LIMIT} bytes or less.", - code=settings.RetCode.ARGUMENT_ERROR, + code=RetCode.ARGUMENT_ERROR, ) if pathlib.Path(req["name"].lower()).suffix != pathlib.Path(doc.name.lower()).suffix: return get_result( message="The extension of file can't be changed", - code=settings.RetCode.ARGUMENT_ERROR, + code=RetCode.ARGUMENT_ERROR, ) for d in DocumentService.query(name=req["name"], kb_id=doc.kb_id): if d.name == req["name"]: @@ -300,7 +302,7 @@ def update_doc(tenant_id, dataset_id, document_id): doc.kb_id, doc.token_num * -1, doc.chunk_num * -1, - doc.process_duation * -1, + doc.process_duration * -1, ) if not e: return get_error_data_result(message="Document not found!") @@ -398,9 +400,9 @@ def download(tenant_id, dataset_id, document_id): return get_error_data_result(message=f"The dataset not own the document {document_id}.") # The process of downloading doc_id, doc_location = File2DocumentService.get_storage_address(doc_id=document_id) # minio address - file_stream = STORAGE_IMPL.get(doc_id, doc_location) + file_stream = settings.STORAGE_IMPL.get(doc_id, doc_location) if not file_stream: - return construct_json_result(message="This file is empty.", code=settings.RetCode.DATA_ERROR) + return construct_json_result(message="This file is empty.", code=RetCode.DATA_ERROR) file = BytesIO(file_stream) # Use send_file with a proper filename and MIME type return send_file( @@ -456,6 +458,32 @@ def list_docs(dataset_id, tenant_id): required: false default: true description: Order in descending. + - in: query + name: create_time_from + type: integer + required: false + default: 0 + description: Unix timestamp for filtering documents created after this time. 0 means no filter. + - in: query + name: create_time_to + type: integer + required: false + default: 0 + description: Unix timestamp for filtering documents created before this time. 0 means no filter. + - in: query + name: suffix + type: array + items: + type: string + required: false + description: Filter by file suffix (e.g., ["pdf", "txt", "docx"]). + - in: query + name: run + type: array + items: + type: string + required: false + description: Filter by document run status. Supports both numeric ("0", "1", "2", "3", "4") and text formats ("UNSTART", "RUNNING", "CANCEL", "DONE", "FAIL"). - in: header name: Authorization type: string @@ -498,52 +526,62 @@ def list_docs(dataset_id, tenant_id): description: Processing status. """ if not KnowledgebaseService.accessible(kb_id=dataset_id, user_id=tenant_id): - return get_error_data_result(message=f"You don't own the dataset {dataset_id}. ") - id = request.args.get("id") - name = request.args.get("name") + return get_error_data_result(message=f"You don't own the dataset {dataset_id}. ") - if id and not DocumentService.query(id=id, kb_id=dataset_id): - return get_error_data_result(message=f"You don't own the document {id}.") + q = request.args + document_id = q.get("id") + name = q.get("name") + + if document_id and not DocumentService.query(id=document_id, kb_id=dataset_id): + return get_error_data_result(message=f"You don't own the document {document_id}.") if name and not DocumentService.query(name=name, kb_id=dataset_id): return get_error_data_result(message=f"You don't own the document {name}.") - page = int(request.args.get("page", 1)) - keywords = request.args.get("keywords", "") - page_size = int(request.args.get("page_size", 30)) - orderby = request.args.get("orderby", "create_time") - if request.args.get("desc") == "False": - desc = False - else: - desc = True - docs, tol = DocumentService.get_list(dataset_id, page, page_size, orderby, desc, keywords, id, name) + page = int(q.get("page", 1)) + page_size = int(q.get("page_size", 30)) + orderby = q.get("orderby", "create_time") + desc = str(q.get("desc", "true")).strip().lower() != "false" + keywords = q.get("keywords", "") - # rename key's name - renamed_doc_list = [] - for doc in docs: - key_mapping = { - "chunk_num": "chunk_count", - "kb_id": "dataset_id", - "token_num": "token_count", - "parser_id": "chunk_method", - } - run_mapping = { - "0": "UNSTART", - "1": "RUNNING", - "2": "CANCEL", - "3": "DONE", - "4": "FAIL", - } - renamed_doc = {} - for key, value in doc.items(): - if key == "run": - renamed_doc["run"] = run_mapping.get(str(value)) - new_key = key_mapping.get(key, key) - renamed_doc[new_key] = value - if key == "run": - renamed_doc["run"] = run_mapping.get(value) - renamed_doc_list.append(renamed_doc) - return get_result(data={"total": tol, "docs": renamed_doc_list}) + # filters - align with OpenAPI parameter names + suffix = q.getlist("suffix") + run_status = q.getlist("run") + create_time_from = int(q.get("create_time_from", 0)) + create_time_to = int(q.get("create_time_to", 0)) + + # map run status (accept text or numeric) - align with API parameter + run_status_text_to_numeric = {"UNSTART": "0", "RUNNING": "1", "CANCEL": "2", "DONE": "3", "FAIL": "4"} + run_status_converted = [run_status_text_to_numeric.get(v, v) for v in run_status] + docs, total = DocumentService.get_list( + dataset_id, page, page_size, orderby, desc, keywords, document_id, name, suffix, run_status_converted + ) + + # time range filter (0 means no bound) + if create_time_from or create_time_to: + docs = [ + d for d in docs + if (create_time_from == 0 or d.get("create_time", 0) >= create_time_from) + and (create_time_to == 0 or d.get("create_time", 0) <= create_time_to) + ] + + # rename keys + map run status back to text for output + key_mapping = { + "chunk_num": "chunk_count", + "kb_id": "dataset_id", + "token_num": "token_count", + "parser_id": "chunk_method", + } + run_status_numeric_to_text = {"0": "UNSTART", "1": "RUNNING", "2": "CANCEL", "3": "DONE", "4": "FAIL"} + + output_docs = [] + for d in docs: + renamed_doc = {key_mapping.get(k, k): v for k, v in d.items()} + if "run" in d: + renamed_doc["run"] = run_status_numeric_to_text.get(str(d["run"]), d["run"]) + output_docs.append(renamed_doc) + + return get_result(data={"total": total, "docs": output_docs}) @manager.route("/datasets//documents", methods=["DELETE"]) # noqa: F821 @token_required @@ -632,16 +670,16 @@ def delete(tenant_id, dataset_id): ) File2DocumentService.delete_by_document_id(doc_id) - STORAGE_IMPL.rm(b, n) + settings.STORAGE_IMPL.rm(b, n) success_count += 1 except Exception as e: errors += str(e) if not_found: - return get_result(message=f"Documents not found: {not_found}", code=settings.RetCode.DATA_ERROR) + return get_result(message=f"Documents not found: {not_found}", code=RetCode.DATA_ERROR) if errors: - return get_result(message=errors, code=settings.RetCode.SERVER_ERROR) + return get_result(message=errors, code=RetCode.SERVER_ERROR) if duplicate_messages: if success_count > 0: @@ -725,7 +763,7 @@ def parse(tenant_id, dataset_id): queue_tasks(doc, bucket, name, 0) success_count += 1 if not_found: - return get_result(message=f"Documents not found: {not_found}", code=settings.RetCode.DATA_ERROR) + return get_result(message=f"Documents not found: {not_found}", code=RetCode.DATA_ERROR) if duplicate_messages: if success_count > 0: return get_result( @@ -931,7 +969,7 @@ def list_chunks(tenant_id, dataset_id, document_id): if req.get("id"): chunk = settings.docStoreConn.get(req.get("id"), search.index_name(tenant_id), [dataset_id]) if not chunk: - return get_result(message=f"Chunk not found: {dataset_id}/{req.get('id')}", code=settings.RetCode.NOT_FOUND) + return get_result(message=f"Chunk not found: {dataset_id}/{req.get('id')}", code=RetCode.NOT_FOUND) k = [] for n in chunk.keys(): if re.search(r"(_vec$|_sm_|_tks|_ltks)", n): @@ -957,12 +995,12 @@ def list_chunks(tenant_id, dataset_id, document_id): _ = Chunk(**final_chunk) elif settings.docStoreConn.indexExist(search.index_name(tenant_id), dataset_id): - sres = settings.retrievaler.search(query, search.index_name(tenant_id), [dataset_id], emb_mdl=None, highlight=True) + sres = settings.retriever.search(query, search.index_name(tenant_id), [dataset_id], emb_mdl=None, highlight=True) res["total"] = sres.total for id in sres.ids: d = { "id": id, - "content": (rmSpace(sres.highlight[id]) if question and id in sres.highlight else sres.field[id].get("content_with_weight", "")), + "content": (remove_redundant_spaces(sres.highlight[id]) if question and id in sres.highlight else sres.field[id].get("content_with_weight", "")), "document_id": sres.field[id]["doc_id"], "docnm_kwd": sres.field[id]["docnm_kwd"], "important_keywords": sres.field[id].get("important_kwd", []), @@ -1263,6 +1301,10 @@ def update_chunk(tenant_id, dataset_id, document_id, chunk_id): d["question_tks"] = rag_tokenizer.tokenize("\n".join(req["questions"])) if "available" in req: d["available_int"] = int(req["available"]) + if "positions" in req: + if not isinstance(req["positions"], list): + return get_error_data_result("`positions` should be a list") + d["position_int"] = req["positions"] embd_id = DocumentService.get_embd_id(document_id) embd_mdl = TenantLLMService.model_instance(tenant_id, LLMType.EMBEDDING.value, embd_id) if doc.parser_id == ParserType.QA: @@ -1326,6 +1368,9 @@ def retrieval_test(tenant_id): highlight: type: boolean description: Whether to highlight matched content. + metadata_condition: + type: object + description: metadata filter condition. - in: header name: Authorization type: string @@ -1373,7 +1418,7 @@ def retrieval_test(tenant_id): if len(embd_nms) != 1: return get_result( message='Datasets use different embedding models."', - code=settings.RetCode.DATA_ERROR, + code=RetCode.DATA_ERROR, ) if "question" not in req: return get_error_data_result("`question` is required.") @@ -1382,12 +1427,17 @@ def retrieval_test(tenant_id): question = req["question"] doc_ids = req.get("document_ids", []) use_kg = req.get("use_kg", False) + langs = req.get("cross_languages", []) if not isinstance(doc_ids, list): return get_error_data_result("`documents` should be a list") doc_ids_list = KnowledgebaseService.list_documents_by_ids(kb_ids) for doc_id in doc_ids: if doc_id not in doc_ids_list: return get_error_data_result(f"The datasets don't own the document {doc_id}") + if not doc_ids: + metadata_condition = req.get("metadata_condition", {}) + metas = DocumentService.get_meta_by_kbs(kb_ids) + doc_ids = meta_filter(metas, convert_conditions(metadata_condition)) similarity_threshold = float(req.get("similarity_threshold", 0.2)) vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3)) top = int(req.get("top_k", 1024)) @@ -1406,11 +1456,14 @@ def retrieval_test(tenant_id): if req.get("rerank_id"): rerank_mdl = LLMBundle(kb.tenant_id, LLMType.RERANK, llm_name=req["rerank_id"]) + if langs: + question = cross_languages(kb.tenant_id, None, question, langs) + if req.get("keyword", False): chat_mdl = LLMBundle(kb.tenant_id, LLMType.CHAT) question += keyword_extraction(chat_mdl, question) - ranks = settings.retrievaler.retrieval( + ranks = settings.retriever.retrieval( question, embd_mdl, tenant_ids, @@ -1426,7 +1479,7 @@ def retrieval_test(tenant_id): rank_feature=label_question(question, kbs), ) if use_kg: - ck = settings.kg_retrievaler.retrieval(question, [k.tenant_id for k in kbs], kb_ids, embd_mdl, LLMBundle(kb.tenant_id, LLMType.CHAT)) + ck = settings.kg_retriever.retrieval(question, [k.tenant_id for k in kbs], kb_ids, embd_mdl, LLMBundle(kb.tenant_id, LLMType.CHAT)) if ck["content_with_weight"]: ranks["chunks"].insert(0, ck) @@ -1456,6 +1509,6 @@ def retrieval_test(tenant_id): if str(e).find("not_found") > 0: return get_result( message="No chunk found! Check the chunk status please!", - code=settings.RetCode.DATA_ERROR, + code=RetCode.DATA_ERROR, ) return server_error_response(e) diff --git a/api/apps/sdk/files.py b/api/apps/sdk/files.py new file mode 100644 index 00000000000..733c894c3e0 --- /dev/null +++ b/api/apps/sdk/files.py @@ -0,0 +1,760 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +import pathlib +import re + +import flask +from flask import request +from pathlib import Path + +from api.db.services.document_service import DocumentService +from api.db.services.file2document_service import File2DocumentService +from api.db.services.knowledgebase_service import KnowledgebaseService +from api.utils.api_utils import server_error_response, token_required +from common.misc_utils import get_uuid +from api.db import FileType +from api.db.services import duplicate_name +from api.db.services.file_service import FileService +from api.utils.api_utils import get_json_result +from api.utils.file_utils import filename_type +from common import settings + + +@manager.route('/file/upload', methods=['POST']) # noqa: F821 +@token_required +def upload(tenant_id): + """ + Upload a file to the system. + --- + tags: + - File Management + security: + - ApiKeyAuth: [] + parameters: + - in: formData + name: file + type: file + required: true + description: The file to upload + - in: formData + name: parent_id + type: string + description: Parent folder ID where the file will be uploaded. Optional. + responses: + 200: + description: Successfully uploaded the file. + schema: + type: object + properties: + data: + type: array + items: + type: object + properties: + id: + type: string + description: File ID + name: + type: string + description: File name + size: + type: integer + description: File size in bytes + type: + type: string + description: File type (e.g., document, folder) + """ + pf_id = request.form.get("parent_id") + + if not pf_id: + root_folder = FileService.get_root_folder(tenant_id) + pf_id = root_folder["id"] + + if 'file' not in request.files: + return get_json_result(data=False, message='No file part!', code=400) + file_objs = request.files.getlist('file') + + for file_obj in file_objs: + if file_obj.filename == '': + return get_json_result(data=False, message='No selected file!', code=400) + + file_res = [] + + try: + e, pf_folder = FileService.get_by_id(pf_id) + if not e: + return get_json_result(data=False, message="Can't find this folder!", code=404) + + for file_obj in file_objs: + # Handle file path + full_path = '/' + file_obj.filename + file_obj_names = full_path.split('/') + file_len = len(file_obj_names) + + # Get folder path ID + file_id_list = FileService.get_id_list_by_id(pf_id, file_obj_names, 1, [pf_id]) + len_id_list = len(file_id_list) + + # Crete file folder + if file_len != len_id_list: + e, file = FileService.get_by_id(file_id_list[len_id_list - 1]) + if not e: + return get_json_result(data=False, message="Folder not found!", code=404) + last_folder = FileService.create_folder(file, file_id_list[len_id_list - 1], file_obj_names, + len_id_list) + else: + e, file = FileService.get_by_id(file_id_list[len_id_list - 2]) + if not e: + return get_json_result(data=False, message="Folder not found!", code=404) + last_folder = FileService.create_folder(file, file_id_list[len_id_list - 2], file_obj_names, + len_id_list) + + filetype = filename_type(file_obj_names[file_len - 1]) + location = file_obj_names[file_len - 1] + while settings.STORAGE_IMPL.obj_exist(last_folder.id, location): + location += "_" + blob = file_obj.read() + filename = duplicate_name(FileService.query, name=file_obj_names[file_len - 1], parent_id=last_folder.id) + + file = { + "id": get_uuid(), + "parent_id": last_folder.id, + "tenant_id": tenant_id, + "created_by": tenant_id, + "type": filetype, + "name": filename, + "location": location, + "size": len(blob), + } + file = FileService.insert(file) + settings.STORAGE_IMPL.put(last_folder.id, location, blob) + file_res.append(file.to_json()) + return get_json_result(data=file_res) + except Exception as e: + return server_error_response(e) + + +@manager.route('/file/create', methods=['POST']) # noqa: F821 +@token_required +def create(tenant_id): + """ + Create a new file or folder. + --- + tags: + - File Management + security: + - ApiKeyAuth: [] + parameters: + - in: body + name: body + description: File creation parameters + required: true + schema: + type: object + properties: + name: + type: string + description: Name of the file/folder + parent_id: + type: string + description: Parent folder ID. Optional. + type: + type: string + enum: ["FOLDER", "VIRTUAL"] + description: Type of the file + responses: + 200: + description: File created successfully. + schema: + type: object + properties: + data: + type: object + properties: + id: + type: string + name: + type: string + type: + type: string + """ + req = request.json + pf_id = request.json.get("parent_id") + input_file_type = request.json.get("type") + if not pf_id: + root_folder = FileService.get_root_folder(tenant_id) + pf_id = root_folder["id"] + + try: + if not FileService.is_parent_folder_exist(pf_id): + return get_json_result(data=False, message="Parent Folder Doesn't Exist!", code=400) + if FileService.query(name=req["name"], parent_id=pf_id): + return get_json_result(data=False, message="Duplicated folder name in the same folder.", code=409) + + if input_file_type == FileType.FOLDER.value: + file_type = FileType.FOLDER.value + else: + file_type = FileType.VIRTUAL.value + + file = FileService.insert({ + "id": get_uuid(), + "parent_id": pf_id, + "tenant_id": tenant_id, + "created_by": tenant_id, + "name": req["name"], + "location": "", + "size": 0, + "type": file_type + }) + + return get_json_result(data=file.to_json()) + except Exception as e: + return server_error_response(e) + + +@manager.route('/file/list', methods=['GET']) # noqa: F821 +@token_required +def list_files(tenant_id): + """ + List files under a specific folder. + --- + tags: + - File Management + security: + - ApiKeyAuth: [] + parameters: + - in: query + name: parent_id + type: string + description: Folder ID to list files from + - in: query + name: keywords + type: string + description: Search keyword filter + - in: query + name: page + type: integer + default: 1 + description: Page number + - in: query + name: page_size + type: integer + default: 15 + description: Number of results per page + - in: query + name: orderby + type: string + default: "create_time" + description: Sort by field + - in: query + name: desc + type: boolean + default: true + description: Descending order + responses: + 200: + description: Successfully retrieved file list. + schema: + type: object + properties: + total: + type: integer + files: + type: array + items: + type: object + properties: + id: + type: string + name: + type: string + type: + type: string + size: + type: integer + create_time: + type: string + format: date-time + """ + pf_id = request.args.get("parent_id") + keywords = request.args.get("keywords", "") + page_number = int(request.args.get("page", 1)) + items_per_page = int(request.args.get("page_size", 15)) + orderby = request.args.get("orderby", "create_time") + desc = request.args.get("desc", True) + + if not pf_id: + root_folder = FileService.get_root_folder(tenant_id) + pf_id = root_folder["id"] + FileService.init_knowledgebase_docs(pf_id, tenant_id) + + try: + e, file = FileService.get_by_id(pf_id) + if not e: + return get_json_result(message="Folder not found!", code=404) + + files, total = FileService.get_by_pf_id(tenant_id, pf_id, page_number, items_per_page, orderby, desc, keywords) + + parent_folder = FileService.get_parent_folder(pf_id) + if not parent_folder: + return get_json_result(message="File not found!", code=404) + + return get_json_result(data={"total": total, "files": files, "parent_folder": parent_folder.to_json()}) + except Exception as e: + return server_error_response(e) + + +@manager.route('/file/root_folder', methods=['GET']) # noqa: F821 +@token_required +def get_root_folder(tenant_id): + """ + Get user's root folder. + --- + tags: + - File Management + security: + - ApiKeyAuth: [] + responses: + 200: + description: Root folder information + schema: + type: object + properties: + data: + type: object + properties: + root_folder: + type: object + properties: + id: + type: string + name: + type: string + type: + type: string + """ + try: + root_folder = FileService.get_root_folder(tenant_id) + return get_json_result(data={"root_folder": root_folder}) + except Exception as e: + return server_error_response(e) + + +@manager.route('/file/parent_folder', methods=['GET']) # noqa: F821 +@token_required +def get_parent_folder(): + """ + Get parent folder info of a file. + --- + tags: + - File Management + security: + - ApiKeyAuth: [] + parameters: + - in: query + name: file_id + type: string + required: true + description: Target file ID + responses: + 200: + description: Parent folder information + schema: + type: object + properties: + data: + type: object + properties: + parent_folder: + type: object + properties: + id: + type: string + name: + type: string + """ + file_id = request.args.get("file_id") + try: + e, file = FileService.get_by_id(file_id) + if not e: + return get_json_result(message="Folder not found!", code=404) + + parent_folder = FileService.get_parent_folder(file_id) + return get_json_result(data={"parent_folder": parent_folder.to_json()}) + except Exception as e: + return server_error_response(e) + + +@manager.route('/file/all_parent_folder', methods=['GET']) # noqa: F821 +@token_required +def get_all_parent_folders(tenant_id): + """ + Get all parent folders of a file. + --- + tags: + - File Management + security: + - ApiKeyAuth: [] + parameters: + - in: query + name: file_id + type: string + required: true + description: Target file ID + responses: + 200: + description: All parent folders of the file + schema: + type: object + properties: + data: + type: object + properties: + parent_folders: + type: array + items: + type: object + properties: + id: + type: string + name: + type: string + """ + file_id = request.args.get("file_id") + try: + e, file = FileService.get_by_id(file_id) + if not e: + return get_json_result(message="Folder not found!", code=404) + + parent_folders = FileService.get_all_parent_folders(file_id) + parent_folders_res = [folder.to_json() for folder in parent_folders] + return get_json_result(data={"parent_folders": parent_folders_res}) + except Exception as e: + return server_error_response(e) + + +@manager.route('/file/rm', methods=['POST']) # noqa: F821 +@token_required +def rm(tenant_id): + """ + Delete one or multiple files/folders. + --- + tags: + - File Management + security: + - ApiKeyAuth: [] + parameters: + - in: body + name: body + description: Files to delete + required: true + schema: + type: object + properties: + file_ids: + type: array + items: + type: string + description: List of file IDs to delete + responses: + 200: + description: Successfully deleted files + schema: + type: object + properties: + data: + type: boolean + example: true + """ + req = request.json + file_ids = req["file_ids"] + try: + for file_id in file_ids: + e, file = FileService.get_by_id(file_id) + if not e: + return get_json_result(message="File or Folder not found!", code=404) + if not file.tenant_id: + return get_json_result(message="Tenant not found!", code=404) + + if file.type == FileType.FOLDER.value: + file_id_list = FileService.get_all_innermost_file_ids(file_id, []) + for inner_file_id in file_id_list: + e, file = FileService.get_by_id(inner_file_id) + if not e: + return get_json_result(message="File not found!", code=404) + settings.STORAGE_IMPL.rm(file.parent_id, file.location) + FileService.delete_folder_by_pf_id(tenant_id, file_id) + else: + settings.STORAGE_IMPL.rm(file.parent_id, file.location) + if not FileService.delete(file): + return get_json_result(message="Database error (File removal)!", code=500) + + informs = File2DocumentService.get_by_file_id(file_id) + for inform in informs: + doc_id = inform.document_id + e, doc = DocumentService.get_by_id(doc_id) + if not e: + return get_json_result(message="Document not found!", code=404) + tenant_id = DocumentService.get_tenant_id(doc_id) + if not tenant_id: + return get_json_result(message="Tenant not found!", code=404) + if not DocumentService.remove_document(doc, tenant_id): + return get_json_result(message="Database error (Document removal)!", code=500) + File2DocumentService.delete_by_file_id(file_id) + + return get_json_result(data=True) + except Exception as e: + return server_error_response(e) + + +@manager.route('/file/rename', methods=['POST']) # noqa: F821 +@token_required +def rename(tenant_id): + """ + Rename a file. + --- + tags: + - File Management + security: + - ApiKeyAuth: [] + parameters: + - in: body + name: body + description: Rename file + required: true + schema: + type: object + properties: + file_id: + type: string + description: Target file ID + name: + type: string + description: New name for the file + responses: + 200: + description: File renamed successfully + schema: + type: object + properties: + data: + type: boolean + example: true + """ + req = request.json + try: + e, file = FileService.get_by_id(req["file_id"]) + if not e: + return get_json_result(message="File not found!", code=404) + + if file.type != FileType.FOLDER.value and pathlib.Path(req["name"].lower()).suffix != pathlib.Path( + file.name.lower()).suffix: + return get_json_result(data=False, message="The extension of file can't be changed", code=400) + + for existing_file in FileService.query(name=req["name"], pf_id=file.parent_id): + if existing_file.name == req["name"]: + return get_json_result(data=False, message="Duplicated file name in the same folder.", code=409) + + if not FileService.update_by_id(req["file_id"], {"name": req["name"]}): + return get_json_result(message="Database error (File rename)!", code=500) + + informs = File2DocumentService.get_by_file_id(req["file_id"]) + if informs: + if not DocumentService.update_by_id(informs[0].document_id, {"name": req["name"]}): + return get_json_result(message="Database error (Document rename)!", code=500) + + return get_json_result(data=True) + except Exception as e: + return server_error_response(e) + + +@manager.route('/file/get/', methods=['GET']) # noqa: F821 +@token_required +def get(tenant_id, file_id): + """ + Download a file. + --- + tags: + - File Management + security: + - ApiKeyAuth: [] + produces: + - application/octet-stream + parameters: + - in: path + name: file_id + type: string + required: true + description: File ID to download + responses: + 200: + description: File stream + schema: + type: file + 404: + description: File not found + """ + try: + e, file = FileService.get_by_id(file_id) + if not e: + return get_json_result(message="Document not found!", code=404) + + blob = settings.STORAGE_IMPL.get(file.parent_id, file.location) + if not blob: + b, n = File2DocumentService.get_storage_address(file_id=file_id) + blob = settings.STORAGE_IMPL.get(b, n) + + response = flask.make_response(blob) + ext = re.search(r"\.([^.]+)$", file.name) + if ext: + if file.type == FileType.VISUAL.value: + response.headers.set('Content-Type', 'image/%s' % ext.group(1)) + else: + response.headers.set('Content-Type', 'application/%s' % ext.group(1)) + return response + except Exception as e: + return server_error_response(e) + + +@manager.route('/file/mv', methods=['POST']) # noqa: F821 +@token_required +def move(tenant_id): + """ + Move one or multiple files to another folder. + --- + tags: + - File Management + security: + - ApiKeyAuth: [] + parameters: + - in: body + name: body + description: Move operation + required: true + schema: + type: object + properties: + src_file_ids: + type: array + items: + type: string + description: Source file IDs + dest_file_id: + type: string + description: Destination folder ID + responses: + 200: + description: Files moved successfully + schema: + type: object + properties: + data: + type: boolean + example: true + """ + req = request.json + try: + file_ids = req["src_file_ids"] + parent_id = req["dest_file_id"] + files = FileService.get_by_ids(file_ids) + files_dict = {f.id: f for f in files} + + for file_id in file_ids: + file = files_dict[file_id] + if not file: + return get_json_result(message="File or Folder not found!", code=404) + if not file.tenant_id: + return get_json_result(message="Tenant not found!", code=404) + + fe, _ = FileService.get_by_id(parent_id) + if not fe: + return get_json_result(message="Parent Folder not found!", code=404) + + FileService.move_file(file_ids, parent_id) + return get_json_result(data=True) + except Exception as e: + return server_error_response(e) + + +@manager.route('/file/convert', methods=['POST']) # noqa: F821 +@token_required +def convert(tenant_id): + req = request.json + kb_ids = req["kb_ids"] + file_ids = req["file_ids"] + file2documents = [] + + try: + files = FileService.get_by_ids(file_ids) + files_set = dict({file.id: file for file in files}) + for file_id in file_ids: + file = files_set[file_id] + if not file: + return get_json_result(message="File not found!", code=404) + file_ids_list = [file_id] + if file.type == FileType.FOLDER.value: + file_ids_list = FileService.get_all_innermost_file_ids(file_id, []) + for id in file_ids_list: + informs = File2DocumentService.get_by_file_id(id) + # delete + for inform in informs: + doc_id = inform.document_id + e, doc = DocumentService.get_by_id(doc_id) + if not e: + return get_json_result(message="Document not found!", code=404) + tenant_id = DocumentService.get_tenant_id(doc_id) + if not tenant_id: + return get_json_result(message="Tenant not found!", code=404) + if not DocumentService.remove_document(doc, tenant_id): + return get_json_result( + message="Database error (Document removal)!", code=404) + File2DocumentService.delete_by_file_id(id) + + # insert + for kb_id in kb_ids: + e, kb = KnowledgebaseService.get_by_id(kb_id) + if not e: + return get_json_result( + message="Can't find this knowledgebase!", code=404) + e, file = FileService.get_by_id(id) + if not e: + return get_json_result( + message="Can't find this file!", code=404) + + doc = DocumentService.insert({ + "id": get_uuid(), + "kb_id": kb.id, + "parser_id": FileService.get_parser(file.type, file.name, kb.parser_id), + "parser_config": kb.parser_config, + "created_by": tenant_id, + "type": file.type, + "name": file.name, + "suffix": Path(file.name).suffix.lstrip("."), + "location": file.location, + "size": file.size + }) + file2document = File2DocumentService.insert({ + "id": get_uuid(), + "file_id": id, + "document_id": doc.id, + }) + + file2documents.append(file2document.to_json()) + return get_json_result(data=file2documents) + except Exception as e: + return server_error_response(e) diff --git a/api/apps/sdk/session.py b/api/apps/sdk/session.py index 1716db9eee5..4edb2bb6b91 100644 --- a/api/apps/sdk/session.py +++ b/api/apps/sdk/session.py @@ -19,22 +19,28 @@ import tiktoken from flask import Response, jsonify, request -from api.db.services.conversation_service import ConversationService, iframe_completion -from api.db.services.conversation_service import completion as rag_completion -from api.db.services.canvas_service import completion as agent_completion, completionOpenAI + from agent.canvas import Canvas -from api.db import LLMType, StatusEnum from api.db.db_models import APIToken from api.db.services.api_service import API4ConversationService -from api.db.services.canvas_service import UserCanvasService -from api.db.services.dialog_service import DialogService, ask, chat -from api.db.services.file_service import FileService +from api.db.services.canvas_service import UserCanvasService, completion_openai +from api.db.services.canvas_service import completion as agent_completion +from api.db.services.conversation_service import ConversationService, iframe_completion +from api.db.services.conversation_service import completion as rag_completion +from api.db.services.dialog_service import DialogService, ask, chat, gen_mindmap, meta_filter +from api.db.services.document_service import DocumentService from api.db.services.knowledgebase_service import KnowledgebaseService -from api.utils import get_uuid -from api.utils.api_utils import get_result, token_required, get_data_openai, get_error_data_result, validate_request, check_duplicate_ids from api.db.services.llm_service import LLMBundle - - +from api.db.services.search_service import SearchService +from api.db.services.user_service import UserTenantService +from common.misc_utils import get_uuid +from api.utils.api_utils import check_duplicate_ids, get_data_openai, get_error_data_result, get_json_result, \ + get_result, server_error_response, token_required, validate_request +from rag.app.tag import label_question +from rag.prompts.template import load_prompt +from rag.prompts.generator import cross_languages, gen_meta_filter, keyword_extraction, chunks_format +from common.constants import RetCode, LLMType, StatusEnum +from common import settings @manager.route("/chats//sessions", methods=["POST"]) # noqa: F821 @token_required @@ -50,6 +56,7 @@ def create(tenant_id, chat_id): "name": req.get("name", "New session"), "message": [{"role": "assistant", "content": dia[0].prompt_config.get("prologue")}], "user_id": req.get("user_id", ""), + "reference": [{}], } if not conv.get("name"): return get_error_data_result(message="`name` can not be empty.") @@ -67,11 +74,7 @@ def create(tenant_id, chat_id): @manager.route("/agents//sessions", methods=["POST"]) # noqa: F821 @token_required def create_agent_session(tenant_id, agent_id): - req = request.json - if not request.is_json: - req = request.form - files = request.files - user_id = request.args.get("user_id", "") + user_id = request.args.get("user_id", tenant_id) e, cvs = UserCanvasService.get_by_id(agent_id) if not e: return get_error_data_result("Agent not found.") @@ -80,45 +83,13 @@ def create_agent_session(tenant_id, agent_id): if not isinstance(cvs.dsl, str): cvs.dsl = json.dumps(cvs.dsl, ensure_ascii=False) - canvas = Canvas(cvs.dsl, tenant_id) + session_id = get_uuid() + canvas = Canvas(cvs.dsl, tenant_id, agent_id) canvas.reset() - query = canvas.get_preset_param() - if query: - for ele in query: - if not ele["optional"]: - if ele["type"] == "file": - if files is None or not files.get(ele["key"]): - return get_error_data_result(f"`{ele['key']}` with type `{ele['type']}` is required") - upload_file = files.get(ele["key"]) - file_content = FileService.parse_docs([upload_file], user_id) - file_name = upload_file.filename - ele["value"] = file_name + "\n" + file_content - else: - if req is None or not req.get(ele["key"]): - return get_error_data_result(f"`{ele['key']}` with type `{ele['type']}` is required") - ele["value"] = req[ele["key"]] - else: - if ele["type"] == "file": - if files is not None and files.get(ele["key"]): - upload_file = files.get(ele["key"]) - file_content = FileService.parse_docs([upload_file], user_id) - file_name = upload_file.filename - ele["value"] = file_name + "\n" + file_content - else: - if "value" in ele: - ele.pop("value") - else: - if req is not None and req.get(ele["key"]): - ele["value"] = req[ele["key"]] - else: - if "value" in ele: - ele.pop("value") - - for ans in canvas.run(stream=False): - pass cvs.dsl = json.loads(str(canvas)) - conv = {"id": get_uuid(), "dialog_id": cvs.id, "user_id": user_id, "message": [{"role": "assistant", "content": canvas.get_prologue()}], "source": "agent", "dsl": cvs.dsl} + conv = {"id": session_id, "dialog_id": cvs.id, "user_id": user_id, + "message": [{"role": "assistant", "content": canvas.get_prologue()}], "source": "agent", "dsl": cvs.dsl} API4ConversationService.save(**conv) conv["agent_id"] = conv.pop("dialog_id") return get_result(data=conv) @@ -181,10 +152,16 @@ def chat_completion(tenant_id, chat_id): def chat_completion_openai_like(tenant_id, chat_id): """ OpenAI-like chat completion API that simulates the behavior of OpenAI's completions endpoint. - + This function allows users to interact with a model and receive responses based on a series of historical messages. If `stream` is set to True (by default), the response will be streamed in chunks, mimicking the OpenAI-style API. Set `stream` to False explicitly, the response will be returned in a single complete answer. + + Reference: + + - If `stream` is True, the final answer and reference information will appear in the **last chunk** of the stream. + - If `stream` is False, the reference will be included in `choices[0].message.reference`. + Example usage: curl -X POST https://ragflow_address.com/api/v1/chats_openai//chat/completions \ @@ -202,7 +179,10 @@ def chat_completion_openai_like(tenant_id, chat_id): model = "model" client = OpenAI(api_key="ragflow-api-key", base_url=f"http://ragflow_address/api/v1/chats_openai/") - + + stream = True + reference = True + completion = client.chat.completions.create( model=model, messages=[ @@ -211,17 +191,24 @@ def chat_completion_openai_like(tenant_id, chat_id): {"role": "assistant", "content": "I am an AI assistant named..."}, {"role": "user", "content": "Can you tell me how to install neovim"}, ], - stream=True + stream=stream, + extra_body={"reference": reference} ) - - stream = True + if stream: - for chunk in completion: - print(chunk) + for chunk in completion: + print(chunk) + if reference and chunk.choices[0].finish_reason == "stop": + print(f"Reference:\n{chunk.choices[0].delta.reference}") + print(f"Final content:\n{chunk.choices[0].delta.final_content}") else: print(completion.choices[0].message.content) + if reference: + print(completion.choices[0].message.reference) """ - req = request.json + req = request.get_json() + + need_reference = bool(req.get("reference", False)) messages = req.get("messages", []) # To prevent empty [] input @@ -261,9 +248,23 @@ def streamed_response_generator(chat_id, dia, msg): token_used = 0 answer_cache = "" reasoning_cache = "" + last_ans = {} response = { "id": f"chatcmpl-{chat_id}", - "choices": [{"delta": {"content": "", "role": "assistant", "function_call": None, "tool_calls": None, "reasoning_content": ""}, "finish_reason": None, "index": 0, "logprobs": None}], + "choices": [ + { + "delta": { + "content": "", + "role": "assistant", + "function_call": None, + "tool_calls": None, + "reasoning_content": "", + }, + "finish_reason": None, + "index": 0, + "logprobs": None, + } + ], "created": int(time.time()), "model": "model", "object": "chat.completion.chunk", @@ -272,13 +273,14 @@ def streamed_response_generator(chat_id, dia, msg): } try: - for ans in chat(dia, msg, True, toolcall_session=toolcall_session, tools=tools): + for ans in chat(dia, msg, True, toolcall_session=toolcall_session, tools=tools, quote=need_reference): + last_ans = ans answer = ans["answer"] reasoning_match = re.search(r"(.*?)", answer, flags=re.DOTALL) if reasoning_match: reasoning_part = reasoning_match.group(1) - content_part = answer[reasoning_match.end() :] + content_part = answer[reasoning_match.end():] else: reasoning_part = "" content_part = answer @@ -323,7 +325,11 @@ def streamed_response_generator(chat_id, dia, msg): response["choices"][0]["delta"]["content"] = None response["choices"][0]["delta"]["reasoning_content"] = None response["choices"][0]["finish_reason"] = "stop" - response["usage"] = {"prompt_tokens": len(prompt), "completion_tokens": token_used, "total_tokens": len(prompt) + token_used} + response["usage"] = {"prompt_tokens": len(prompt), "completion_tokens": token_used, + "total_tokens": len(prompt) + token_used} + if need_reference: + response["choices"][0]["delta"]["reference"] = chunks_format(last_ans.get("reference", [])) + response["choices"][0]["delta"]["final_content"] = last_ans.get("answer", "") yield f"data:{json.dumps(response, ensure_ascii=False)}\n\n" yield "data:[DONE]\n\n" @@ -335,7 +341,7 @@ def streamed_response_generator(chat_id, dia, msg): return resp else: answer = None - for ans in chat(dia, msg, False, toolcall_session=toolcall_session, tools=tools): + for ans in chat(dia, msg, False, toolcall_session=toolcall_session, tools=tools, quote=need_reference): # focus answer content only answer = ans break @@ -356,14 +362,28 @@ def streamed_response_generator(chat_id, dia, msg): "rejected_prediction_tokens": 0, # 0 for simplicity }, }, - "choices": [{"message": {"role": "assistant", "content": content}, "logprobs": None, "finish_reason": "stop", "index": 0}], + "choices": [ + { + "message": { + "role": "assistant", + "content": content, + }, + "logprobs": None, + "finish_reason": "stop", + "index": 0, + } + ], } + if need_reference: + response["choices"][0]["message"]["reference"] = chunks_format(answer.get("reference", [])) + return jsonify(response) -@manager.route('/agents_openai//chat/completions', methods=['POST']) # noqa: F821 + +@manager.route("/agents_openai//chat/completions", methods=["POST"]) # noqa: F821 @validate_request("model", "messages") # noqa: F821 @token_required -def agents_completion_openai_compatibility (tenant_id, agent_id): +def agents_completion_openai_compatibility(tenant_id, agent_id): req = request.json tiktokenenc = tiktoken.get_encoding("cl100k_base") messages = req.get("messages", []) @@ -371,69 +391,104 @@ def agents_completion_openai_compatibility (tenant_id, agent_id): return get_error_data_result("You must provide at least one message.") if not UserCanvasService.query(user_id=tenant_id, id=agent_id): return get_error_data_result(f"You don't own the agent {agent_id}") - + filtered_messages = [m for m in messages if m["role"] in ["user", "assistant"]] prompt_tokens = sum(len(tiktokenenc.encode(m["content"])) for m in filtered_messages) if not filtered_messages: - return jsonify(get_data_openai( - id=agent_id, - content="No valid messages found (user or assistant).", - finish_reason="stop", - model=req.get("model", ""), - completion_tokens=len(tiktokenenc.encode("No valid messages found (user or assistant).")), - prompt_tokens=prompt_tokens, - )) - - # Get the last user message as the question + return jsonify( + get_data_openai( + id=agent_id, + content="No valid messages found (user or assistant).", + finish_reason="stop", + model=req.get("model", ""), + completion_tokens=len(tiktokenenc.encode("No valid messages found (user or assistant).")), + prompt_tokens=prompt_tokens, + ) + ) + question = next((m["content"] for m in reversed(messages) if m["role"] == "user"), "") - - if req.get("stream", True): - return Response(completionOpenAI(tenant_id, agent_id, question, session_id=req.get("id", req.get("metadata", {}).get("id","")), stream=True), mimetype="text/event-stream") + + stream = req.pop("stream", False) + if stream: + resp = Response( + completion_openai( + tenant_id, + agent_id, + question, + session_id=req.pop("session_id", req.get("id", "")) or req.get("metadata", {}).get("id", ""), + stream=True, + **req, + ), + mimetype="text/event-stream", + ) + resp.headers.add_header("Cache-control", "no-cache") + resp.headers.add_header("Connection", "keep-alive") + resp.headers.add_header("X-Accel-Buffering", "no") + resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8") + return resp else: # For non-streaming, just return the response directly - response = next(completionOpenAI(tenant_id, agent_id, question, session_id=req.get("id", req.get("metadata", {}).get("id","")), stream=False)) + response = next( + completion_openai( + tenant_id, + agent_id, + question, + session_id=req.pop("session_id", req.get("id", "")) or req.get("metadata", {}).get("id", ""), + stream=False, + **req, + ) + ) return jsonify(response) - + @manager.route("/agents//completions", methods=["POST"]) # noqa: F821 @token_required def agent_completions(tenant_id, agent_id): req = request.json - cvs = UserCanvasService.query(user_id=tenant_id, id=agent_id) - if not cvs: - return get_error_data_result(f"You don't own the agent {agent_id}") - if req.get("session_id"): - dsl = cvs[0].dsl - if not isinstance(dsl, str): - dsl = json.dumps(dsl) - conv = API4ConversationService.query(id=req["session_id"], dialog_id=agent_id) - if not conv: - return get_error_data_result(f"You don't own the session {req['session_id']}") - # If an update to UserCanvas is detected, update the API4Conversation.dsl - sync_dsl = req.get("sync_dsl", False) - if sync_dsl is True and cvs[0].update_time > conv[0].update_time: - current_dsl = conv[0].dsl - new_dsl = json.loads(dsl) - state_fields = ["history", "messages", "path", "reference"] - states = {field: current_dsl.get(field, []) for field in state_fields} - current_dsl.update(new_dsl) - current_dsl.update(states) - API4ConversationService.update_by_id(req["session_id"], {"dsl": current_dsl}) - else: - req["question"] = "" if req.get("stream", True): - resp = Response(agent_completion(tenant_id, agent_id, **req), mimetype="text/event-stream") + + def generate(): + for answer in agent_completion(tenant_id=tenant_id, agent_id=agent_id, **req): + if isinstance(answer, str): + try: + ans = json.loads(answer[5:]) # remove "data:" + except Exception: + continue + + if ans.get("event") not in ["message", "message_end"]: + continue + + yield answer + + yield "data:[DONE]\n\n" + + resp = Response(generate(), mimetype="text/event-stream") resp.headers.add_header("Cache-control", "no-cache") resp.headers.add_header("Connection", "keep-alive") resp.headers.add_header("X-Accel-Buffering", "no") resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8") return resp - try: - for answer in agent_completion(tenant_id, agent_id, **req): - return get_result(data=answer) - except Exception as e: - return get_error_data_result(str(e)) + + full_content = "" + reference = {} + final_ans = "" + for answer in agent_completion(tenant_id=tenant_id, agent_id=agent_id, **req): + try: + ans = json.loads(answer[5:]) + + if ans["event"] == "message": + full_content += ans["data"]["content"] + + if ans.get("data", {}).get("reference", None): + reference.update(ans["data"]["reference"]) + + final_ans = ans + except Exception as e: + return get_result(data=f"**ERROR**: {str(e)}") + final_ans["data"]["content"] = full_content + final_ans["data"]["reference"] = reference + return get_result(data=final_ans) @manager.route("/chats//sessions", methods=["GET"]) # noqa: F821 @@ -461,14 +516,16 @@ def list_session(tenant_id, chat_id): if "prompt" in info: info.pop("prompt") conv["chat_id"] = conv.pop("dialog_id") - if conv["reference"]: + ref_messages = conv["reference"] + if ref_messages: messages = conv["messages"] message_num = 0 - while message_num < len(messages) and message_num < len(conv["reference"]): - if message_num != 0 and messages[message_num]["role"] != "user": + ref_num = 0 + while message_num < len(messages) and ref_num < len(ref_messages): + if messages[message_num]["role"] != "user": chunk_list = [] - if "chunks" in conv["reference"][message_num]: - chunks = conv["reference"][message_num]["chunks"] + if "chunks" in ref_messages[ref_num]: + chunks = ref_messages[ref_num]["chunks"] for chunk in chunks: new_chunk = { "id": chunk.get("chunk_id", chunk.get("id")), @@ -482,6 +539,7 @@ def list_session(tenant_id, chat_id): chunk_list.append(new_chunk) messages[message_num]["reference"] = chunk_list + ref_num += 1 message_num += 1 del conv["reference"] return get_result(data=convs) @@ -503,7 +561,8 @@ def list_agent_session(tenant_id, agent_id): desc = True # dsl defaults to True in all cases except for False and false include_dsl = request.args.get("dsl") != "False" and request.args.get("dsl") != "false" - convs = API4ConversationService.get_list(agent_id, tenant_id, page_number, items_per_page, orderby, desc, id, user_id, include_dsl) + total, convs = API4ConversationService.get_list(agent_id, tenant_id, page_number, items_per_page, orderby, desc, id, + user_id, include_dsl) if not convs: return get_result(data=[]) for conv in convs: @@ -513,16 +572,25 @@ def list_agent_session(tenant_id, agent_id): if "prompt" in info: info.pop("prompt") conv["agent_id"] = conv.pop("dialog_id") + # Fix for session listing endpoint if conv["reference"]: messages = conv["messages"] message_num = 0 chunk_num = 0 + # Ensure reference is a list type to prevent KeyError + if not isinstance(conv["reference"], list): + conv["reference"] = [] while message_num < len(messages): if message_num != 0 and messages[message_num]["role"] != "user": chunk_list = [] - if "chunks" in conv["reference"][chunk_num]: + # Add boundary and type checks to prevent KeyError + if chunk_num < len(conv["reference"]) and conv["reference"][chunk_num] is not None and isinstance( + conv["reference"][chunk_num], dict) and "chunks" in conv["reference"][chunk_num]: chunks = conv["reference"][chunk_num]["chunks"] for chunk in chunks: + # Ensure chunk is a dictionary before calling get method + if not isinstance(chunk, dict): + continue new_chunk = { "id": chunk.get("chunk_id", chunk.get("id")), "content": chunk.get("content_with_weight", chunk.get("content")), @@ -545,7 +613,7 @@ def list_agent_session(tenant_id, agent_id): def delete(tenant_id, chat_id): if not DialogService.query(id=chat_id, tenant_id=tenant_id, status=StatusEnum.VALID.value): return get_error_data_result(message="You don't own the chat") - + errors = [] success_count = 0 req = request.json @@ -561,10 +629,10 @@ def delete(tenant_id, chat_id): conv_list.append(conv.id) else: conv_list = ids - + unique_conv_ids, duplicate_messages = check_duplicate_ids(conv_list, "session") conv_list = unique_conv_ids - + for id in conv_list: conv = ConversationService.query(id=id, dialog_id=chat_id) if not conv: @@ -572,25 +640,22 @@ def delete(tenant_id, chat_id): continue ConversationService.delete_by_id(id) success_count += 1 - + if errors: if success_count > 0: - return get_result( - data={"success_count": success_count, "errors": errors}, - message=f"Partially deleted {success_count} sessions with {len(errors)} errors" - ) + return get_result(data={"success_count": success_count, "errors": errors}, + message=f"Partially deleted {success_count} sessions with {len(errors)} errors") else: return get_error_data_result(message="; ".join(errors)) - + if duplicate_messages: if success_count > 0: return get_result( - message=f"Partially deleted {success_count} sessions with {len(duplicate_messages)} errors", - data={"success_count": success_count, "errors": duplicate_messages} - ) + message=f"Partially deleted {success_count} sessions with {len(duplicate_messages)} errors", + data={"success_count": success_count, "errors": duplicate_messages}) else: return get_error_data_result(message=";".join(duplicate_messages)) - + return get_result() @@ -630,25 +695,22 @@ def delete_agent_session(tenant_id, agent_id): continue API4ConversationService.delete_by_id(session_id) success_count += 1 - + if errors: if success_count > 0: - return get_result( - data={"success_count": success_count, "errors": errors}, - message=f"Partially deleted {success_count} sessions with {len(errors)} errors" - ) + return get_result(data={"success_count": success_count, "errors": errors}, + message=f"Partially deleted {success_count} sessions with {len(errors)} errors") else: return get_error_data_result(message="; ".join(errors)) - + if duplicate_messages: if success_count > 0: return get_result( - message=f"Partially deleted {success_count} sessions with {len(duplicate_messages)} errors", - data={"success_count": success_count, "errors": duplicate_messages} - ) + message=f"Partially deleted {success_count} sessions with {len(duplicate_messages)} errors", + data={"success_count": success_count, "errors": duplicate_messages}) else: return get_error_data_result(message=";".join(duplicate_messages)) - + return get_result() @@ -678,7 +740,9 @@ def stream(): for ans in ask(req["question"], req["kb_ids"], uid): yield "data:" + json.dumps({"code": 0, "message": "", "data": ans}, ensure_ascii=False) + "\n\n" except Exception as e: - yield "data:" + json.dumps({"code": 500, "message": str(e), "data": {"answer": "**ERROR**: " + str(e), "reference": []}}, ensure_ascii=False) + "\n\n" + yield "data:" + json.dumps( + {"code": 500, "message": str(e), "data": {"answer": "**ERROR**: " + str(e), "reference": []}}, + ensure_ascii=False) + "\n\n" yield "data:" + json.dumps({"code": 0, "message": "", "data": True}, ensure_ascii=False) + "\n\n" resp = Response(stream(), mimetype="text/event-stream") @@ -696,6 +760,7 @@ def related_questions(tenant_id): if not req.get("question"): return get_error_data_result("`question` is required.") question = req["question"] + industry = req.get("industry", "") chat_mdl = LLMBundle(tenant_id, LLMType.CHAT) prompt = """ Objective: To generate search terms related to the user's search keywords, helping users find more valuable information. @@ -705,7 +770,10 @@ def related_questions(tenant_id): - Use common, general terms as much as possible, avoiding obscure words or technical jargon. - Keep the term length between 2-4 words, concise and clear. - DO NOT translate, use the language of the original keywords. - +""" + if industry: + prompt += f" - Ensure all search terms are relevant to the industry: {industry}.\n" + prompt += """ ### Example: Keywords: Chinese football Related search terms: @@ -717,7 +785,7 @@ def related_questions(tenant_id): Reason: - When searching, users often only use one or two keywords, making it difficult to fully express their information needs. - - Generating related search terms can help users dig deeper into relevant information and improve search efficiency. + - Generating related search terms can help users dig deeper into relevant information and improve search efficiency. - At the same time, related terms can also help search engines better understand user needs and return more accurate search results. """ @@ -764,6 +832,29 @@ def chatbot_completions(dialog_id): return get_result(data=answer) +@manager.route("/chatbots//info", methods=["GET"]) # noqa: F821 +def chatbots_inputs(dialog_id): + token = request.headers.get("Authorization").split() + if len(token) != 2: + return get_error_data_result(message='Authorization is not valid!"') + token = token[1] + objs = APIToken.query(beta=token) + if not objs: + return get_error_data_result(message='Authentication error: API key is invalid!"') + + e, dialog = DialogService.get_by_id(dialog_id) + if not e: + return get_error_data_result(f"Can't find dialog by ID: {dialog_id}") + + return get_result( + data={ + "title": dialog.name, + "avatar": dialog.icon, + "prologue": dialog.prompt_config.get("prologue", ""), + } + ) + + @manager.route("/agentbots//completions", methods=["POST"]) # noqa: F821 def agent_bot_completions(agent_id): req = request.json @@ -776,9 +867,6 @@ def agent_bot_completions(agent_id): if not objs: return get_error_data_result(message='Authentication error: API key is invalid!"') - if "quote" not in req: - req["quote"] = False - if req.get("stream", True): resp = Response(agent_completion(objs[0].tenant_id, agent_id, **req), mimetype="text/event-stream") resp.headers.add_header("Cache-control", "no-cache") @@ -789,3 +877,260 @@ def agent_bot_completions(agent_id): for answer in agent_completion(objs[0].tenant_id, agent_id, **req): return get_result(data=answer) + + +@manager.route("/agentbots//inputs", methods=["GET"]) # noqa: F821 +def begin_inputs(agent_id): + token = request.headers.get("Authorization").split() + if len(token) != 2: + return get_error_data_result(message='Authorization is not valid!"') + token = token[1] + objs = APIToken.query(beta=token) + if not objs: + return get_error_data_result(message='Authentication error: API key is invalid!"') + + e, cvs = UserCanvasService.get_by_id(agent_id) + if not e: + return get_error_data_result(f"Can't find agent by ID: {agent_id}") + + canvas = Canvas(json.dumps(cvs.dsl), objs[0].tenant_id) + return get_result( + data={"title": cvs.title, "avatar": cvs.avatar, "inputs": canvas.get_component_input_form("begin"), + "prologue": canvas.get_prologue(), "mode": canvas.get_mode()}) + + +@manager.route("/searchbots/ask", methods=["POST"]) # noqa: F821 +@validate_request("question", "kb_ids") +def ask_about_embedded(): + token = request.headers.get("Authorization").split() + if len(token) != 2: + return get_error_data_result(message='Authorization is not valid!"') + token = token[1] + objs = APIToken.query(beta=token) + if not objs: + return get_error_data_result(message='Authentication error: API key is invalid!"') + + req = request.json + uid = objs[0].tenant_id + + search_id = req.get("search_id", "") + search_config = {} + if search_id: + if search_app := SearchService.get_detail(search_id): + search_config = search_app.get("search_config", {}) + + def stream(): + nonlocal req, uid + try: + for ans in ask(req["question"], req["kb_ids"], uid, search_config=search_config): + yield "data:" + json.dumps({"code": 0, "message": "", "data": ans}, ensure_ascii=False) + "\n\n" + except Exception as e: + yield "data:" + json.dumps( + {"code": 500, "message": str(e), "data": {"answer": "**ERROR**: " + str(e), "reference": []}}, + ensure_ascii=False) + "\n\n" + yield "data:" + json.dumps({"code": 0, "message": "", "data": True}, ensure_ascii=False) + "\n\n" + + resp = Response(stream(), mimetype="text/event-stream") + resp.headers.add_header("Cache-control", "no-cache") + resp.headers.add_header("Connection", "keep-alive") + resp.headers.add_header("X-Accel-Buffering", "no") + resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8") + return resp + + +@manager.route("/searchbots/retrieval_test", methods=["POST"]) # noqa: F821 +@validate_request("kb_id", "question") +def retrieval_test_embedded(): + token = request.headers.get("Authorization").split() + if len(token) != 2: + return get_error_data_result(message='Authorization is not valid!"') + token = token[1] + objs = APIToken.query(beta=token) + if not objs: + return get_error_data_result(message='Authentication error: API key is invalid!"') + + req = request.json + page = int(req.get("page", 1)) + size = int(req.get("size", 30)) + question = req["question"] + kb_ids = req["kb_id"] + if isinstance(kb_ids, str): + kb_ids = [kb_ids] + if not kb_ids: + return get_json_result(data=False, message='Please specify dataset firstly.', + code=RetCode.DATA_ERROR) + doc_ids = req.get("doc_ids", []) + similarity_threshold = float(req.get("similarity_threshold", 0.0)) + vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3)) + use_kg = req.get("use_kg", False) + top = int(req.get("top_k", 1024)) + langs = req.get("cross_languages", []) + tenant_ids = [] + + tenant_id = objs[0].tenant_id + if not tenant_id: + return get_error_data_result(message="permission denined.") + + if req.get("search_id", ""): + search_config = SearchService.get_detail(req.get("search_id", "")).get("search_config", {}) + meta_data_filter = search_config.get("meta_data_filter", {}) + metas = DocumentService.get_meta_by_kbs(kb_ids) + if meta_data_filter.get("method") == "auto": + chat_mdl = LLMBundle(tenant_id, LLMType.CHAT, llm_name=search_config.get("chat_id", "")) + filters = gen_meta_filter(chat_mdl, metas, question) + doc_ids.extend(meta_filter(metas, filters)) + if not doc_ids: + doc_ids = None + elif meta_data_filter.get("method") == "manual": + doc_ids.extend(meta_filter(metas, meta_data_filter["manual"])) + if not doc_ids: + doc_ids = None + + try: + tenants = UserTenantService.query(user_id=tenant_id) + for kb_id in kb_ids: + for tenant in tenants: + if KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id): + tenant_ids.append(tenant.tenant_id) + break + else: + return get_json_result(data=False, message="Only owner of knowledgebase authorized for this operation.", + code=RetCode.OPERATING_ERROR) + + e, kb = KnowledgebaseService.get_by_id(kb_ids[0]) + if not e: + return get_error_data_result(message="Knowledgebase not found!") + + if langs: + question = cross_languages(kb.tenant_id, None, question, langs) + + embd_mdl = LLMBundle(kb.tenant_id, LLMType.EMBEDDING.value, llm_name=kb.embd_id) + + rerank_mdl = None + if req.get("rerank_id"): + rerank_mdl = LLMBundle(kb.tenant_id, LLMType.RERANK.value, llm_name=req["rerank_id"]) + + if req.get("keyword", False): + chat_mdl = LLMBundle(kb.tenant_id, LLMType.CHAT) + question += keyword_extraction(chat_mdl, question) + + labels = label_question(question, [kb]) + ranks = settings.retriever.retrieval( + question, embd_mdl, tenant_ids, kb_ids, page, size, similarity_threshold, vector_similarity_weight, top, + doc_ids, rerank_mdl=rerank_mdl, highlight=req.get("highlight"), rank_feature=labels + ) + if use_kg: + ck = settings.kg_retriever.retrieval(question, tenant_ids, kb_ids, embd_mdl, + LLMBundle(kb.tenant_id, LLMType.CHAT)) + if ck["content_with_weight"]: + ranks["chunks"].insert(0, ck) + + for c in ranks["chunks"]: + c.pop("vector", None) + ranks["labels"] = labels + + return get_json_result(data=ranks) + except Exception as e: + if str(e).find("not_found") > 0: + return get_json_result(data=False, message="No chunk found! Check the chunk status please!", + code=RetCode.DATA_ERROR) + return server_error_response(e) + + +@manager.route("/searchbots/related_questions", methods=["POST"]) # noqa: F821 +@validate_request("question") +def related_questions_embedded(): + token = request.headers.get("Authorization").split() + if len(token) != 2: + return get_error_data_result(message='Authorization is not valid!"') + token = token[1] + objs = APIToken.query(beta=token) + if not objs: + return get_error_data_result(message='Authentication error: API key is invalid!"') + + req = request.json + tenant_id = objs[0].tenant_id + if not tenant_id: + return get_error_data_result(message="permission denined.") + + search_id = req.get("search_id", "") + search_config = {} + if search_id: + if search_app := SearchService.get_detail(search_id): + search_config = search_app.get("search_config", {}) + + question = req["question"] + + chat_id = search_config.get("chat_id", "") + chat_mdl = LLMBundle(tenant_id, LLMType.CHAT, chat_id) + + gen_conf = search_config.get("llm_setting", {"temperature": 0.9}) + prompt = load_prompt("related_question") + ans = chat_mdl.chat( + prompt, + [ + { + "role": "user", + "content": f""" +Keywords: {question} +Related search terms: + """, + } + ], + gen_conf, + ) + return get_json_result(data=[re.sub(r"^[0-9]\. ", "", a) for a in ans.split("\n") if re.match(r"^[0-9]\. ", a)]) + + +@manager.route("/searchbots/detail", methods=["GET"]) # noqa: F821 +def detail_share_embedded(): + token = request.headers.get("Authorization").split() + if len(token) != 2: + return get_error_data_result(message='Authorization is not valid!"') + token = token[1] + objs = APIToken.query(beta=token) + if not objs: + return get_error_data_result(message='Authentication error: API key is invalid!"') + + search_id = request.args["search_id"] + tenant_id = objs[0].tenant_id + if not tenant_id: + return get_error_data_result(message="permission denined.") + try: + tenants = UserTenantService.query(user_id=tenant_id) + for tenant in tenants: + if SearchService.query(tenant_id=tenant.tenant_id, id=search_id): + break + else: + return get_json_result(data=False, message="Has no permission for this operation.", + code=RetCode.OPERATING_ERROR) + + search = SearchService.get_detail(search_id) + if not search: + return get_error_data_result(message="Can't find this Search App!") + return get_json_result(data=search) + except Exception as e: + return server_error_response(e) + + +@manager.route("/searchbots/mindmap", methods=["POST"]) # noqa: F821 +@validate_request("question", "kb_ids") +def mindmap(): + token = request.headers.get("Authorization").split() + if len(token) != 2: + return get_error_data_result(message='Authorization is not valid!"') + token = token[1] + objs = APIToken.query(beta=token) + if not objs: + return get_error_data_result(message='Authentication error: API key is invalid!"') + + tenant_id = objs[0].tenant_id + req = request.json + + search_id = req.get("search_id", "") + search_app = SearchService.get_detail(search_id) if search_id else {} + + mind_map = gen_mindmap(req["question"], req["kb_ids"], tenant_id, search_app.get("search_config", {})) + if "error" in mind_map: + return server_error_response(Exception(mind_map["error"])) + return get_json_result(data=mind_map) diff --git a/api/apps/search_app.py b/api/apps/search_app.py index 083e6308331..79922337138 100644 --- a/api/apps/search_app.py +++ b/api/apps/search_app.py @@ -17,15 +17,13 @@ from flask import request from flask_login import current_user, login_required -from api import settings from api.constants import DATASET_NAME_LIMIT -from api.db import StatusEnum from api.db.db_models import DB from api.db.services import duplicate_name -from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.search_service import SearchService from api.db.services.user_service import TenantService, UserTenantService -from api.utils import get_uuid +from common.misc_utils import get_uuid +from common.constants import RetCode, StatusEnum from api.utils.api_utils import get_data_error_result, get_json_result, not_allowed_parameters, server_error_response, validate_request @@ -40,14 +38,14 @@ def create(): return get_data_error_result(message="Search name must be string.") if search_name.strip() == "": return get_data_error_result(message="Search name can't be empty.") - if len(search_name.encode("utf-8")) > DATASET_NAME_LIMIT: - return get_data_error_result(message=f"Search name length is {len(search_name)} which is large than {DATASET_NAME_LIMIT}") + if len(search_name.encode("utf-8")) > 255: + return get_data_error_result(message=f"Search name length is {len(search_name)} which is large than 255.") e, _ = TenantService.get_by_id(current_user.id) if not e: - return get_data_error_result(message="Authorizationd identity.") + return get_data_error_result(message="Authorized identity.") search_name = search_name.strip() - search_name = duplicate_name(KnowledgebaseService.query, name=search_name, tenant_id=current_user.id, status=StatusEnum.VALID.value) + search_name = duplicate_name(SearchService.query, name=search_name, tenant_id=current_user.id, status=StatusEnum.VALID.value) req["id"] = get_uuid() req["name"] = search_name @@ -79,16 +77,16 @@ def update(): tenant_id = req["tenant_id"] e, _ = TenantService.get_by_id(tenant_id) if not e: - return get_data_error_result(message="Authorizationd identity.") + return get_data_error_result(message="Authorized identity.") search_id = req["search_id"] if not SearchService.accessible4deletion(search_id, current_user.id): - return get_json_result(data=False, message="No authorization.", code=settings.RetCode.AUTHENTICATION_ERROR) + return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) try: search_app = SearchService.query(tenant_id=tenant_id, id=search_id)[0] if not search_app: - return get_json_result(data=False, message=f"Cannot find search {search_id}", code=settings.RetCode.DATA_ERROR) + return get_json_result(data=False, message=f"Cannot find search {search_id}", code=RetCode.DATA_ERROR) if req["name"].lower() != search_app.name.lower() and len(SearchService.query(name=req["name"], tenant_id=tenant_id, status=StatusEnum.VALID.value)) >= 1: return get_data_error_result(message="Duplicated search name.") @@ -130,7 +128,7 @@ def detail(): if SearchService.query(tenant_id=tenant.tenant_id, id=search_id): break else: - return get_json_result(data=False, message="Has no permission for this operation.", code=settings.RetCode.OPERATING_ERROR) + return get_json_result(data=False, message="Has no permission for this operation.", code=RetCode.OPERATING_ERROR) search = SearchService.get_detail(search_id) if not search: @@ -156,8 +154,9 @@ def list_search_app(): owner_ids = req.get("owner_ids", []) try: if not owner_ids: - tenants = TenantService.get_joined_tenants_by_user_id(current_user.id) - tenants = [m["tenant_id"] for m in tenants] + # tenants = TenantService.get_joined_tenants_by_user_id(current_user.id) + # tenants = [m["tenant_id"] for m in tenants] + tenants = [] search_apps, total = SearchService.get_by_tenant_ids(tenants, current_user.id, page_number, items_per_page, orderby, desc, keywords) else: tenants = owner_ids @@ -178,7 +177,7 @@ def rm(): req = request.get_json() search_id = req["search_id"] if not SearchService.accessible4deletion(search_id, current_user.id): - return get_json_result(data=False, message="No authorization.", code=settings.RetCode.AUTHENTICATION_ERROR) + return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) try: if not SearchService.delete_by_id(search_id): diff --git a/api/apps/system_app.py b/api/apps/system_app.py index c4a70bcacb1..b63f80a6a7e 100644 --- a/api/apps/system_app.py +++ b/api/apps/system_app.py @@ -23,19 +23,21 @@ from api.db.services.api_service import APITokenService from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.user_service import UserTenantService -from api import settings -from api.utils import current_timestamp, datetime_format from api.utils.api_utils import ( get_json_result, get_data_error_result, server_error_response, generate_confirmation_token, ) -from api.versions import get_ragflow_version -from rag.utils.storage_factory import STORAGE_IMPL, STORAGE_IMPL_TYPE +from common.versions import get_ragflow_version +from common.time_utils import current_timestamp, datetime_format from timeit import default_timer as timer from rag.utils.redis_conn import REDIS_CONN +from flask import jsonify +from api.utils.health_utils import run_health_checks +from common import settings + @manager.route("/version", methods=["GET"]) # noqa: F821 @login_required @@ -109,15 +111,15 @@ def status(): st = timer() try: - STORAGE_IMPL.health() + settings.STORAGE_IMPL.health() res["storage"] = { - "storage": STORAGE_IMPL_TYPE.lower(), + "storage": settings.STORAGE_IMPL_TYPE.lower(), "status": "green", "elapsed": "{:.1f}".format((timer() - st) * 1000.0), } except Exception as e: res["storage"] = { - "storage": STORAGE_IMPL_TYPE.lower(), + "storage": settings.STORAGE_IMPL_TYPE.lower(), "status": "red", "elapsed": "{:.1f}".format((timer() - st) * 1000.0), "error": str(e), @@ -159,7 +161,7 @@ def status(): task_executors = REDIS_CONN.smembers("TASKEXE") now = datetime.now().timestamp() for task_executor_id in task_executors: - heartbeats = REDIS_CONN.zrangebyscore(task_executor_id, now - 60*30, now) + heartbeats = REDIS_CONN.zrangebyscore(task_executor_id, now - 60 * 30, now) heartbeats = [json.loads(heartbeat) for heartbeat in heartbeats] task_executor_heartbeats[task_executor_id] = heartbeats except Exception: @@ -169,6 +171,17 @@ def status(): return get_json_result(data=res) +@manager.route("/healthz", methods=["GET"]) # noqa: F821 +def healthz(): + result, all_ok = run_health_checks() + return jsonify(result), (200 if all_ok else 500) + + +@manager.route("/ping", methods=["GET"]) # noqa: F821 +def ping(): + return "pong", 200 + + @manager.route("/new_token", methods=["POST"]) # noqa: F821 @login_required def new_token(): @@ -203,8 +216,8 @@ def new_token(): tenant_id = [tenant for tenant in tenants if tenant.role == 'owner'][0].tenant_id obj = { "tenant_id": tenant_id, - "token": generate_confirmation_token(tenant_id), - "beta": generate_confirmation_token(generate_confirmation_token(tenant_id)).replace("ragflow-", "")[:32], + "token": generate_confirmation_token(), + "beta": generate_confirmation_token().replace("ragflow-", "")[:32], "create_time": current_timestamp(), "create_date": datetime_format(datetime.now()), "update_time": None, @@ -260,7 +273,8 @@ def token_list(): objs = [o.to_dict() for o in objs] for o in objs: if not o["beta"]: - o["beta"] = generate_confirmation_token(generate_confirmation_token(tenants[0].tenant_id)).replace("ragflow-", "")[:32] + o["beta"] = generate_confirmation_token().replace( + "ragflow-", "")[:32] APITokenService.filter_update([APIToken.tenant_id == tenant_id, APIToken.token == o["token"]], o) return get_json_result(data=objs) except Exception as e: diff --git a/api/apps/tenant_app.py b/api/apps/tenant_app.py index 42b4d0a14e9..abb096faaa5 100644 --- a/api/apps/tenant_app.py +++ b/api/apps/tenant_app.py @@ -17,13 +17,17 @@ from flask import request from flask_login import login_required, current_user -from api import settings -from api.db import UserTenantRole, StatusEnum +from api.apps import smtp_mail_server +from api.db import UserTenantRole from api.db.db_models import UserTenant from api.db.services.user_service import UserTenantService, UserService -from api.utils import get_uuid, delta_seconds +from common.constants import RetCode, StatusEnum +from common.misc_utils import get_uuid +from common.time_utils import delta_seconds from api.utils.api_utils import get_json_result, validate_request, server_error_response, get_data_error_result +from api.utils.web_utils import send_invite_email +from common import settings @manager.route("//user/list", methods=["GET"]) # noqa: F821 @@ -33,7 +37,7 @@ def user_list(tenant_id): return get_json_result( data=False, message='No authorization.', - code=settings.RetCode.AUTHENTICATION_ERROR) + code=RetCode.AUTHENTICATION_ERROR) try: users = UserTenantService.get_by_tenant_id(tenant_id) @@ -52,7 +56,7 @@ def create(tenant_id): return get_json_result( data=False, message='No authorization.', - code=settings.RetCode.AUTHENTICATION_ERROR) + code=RetCode.AUTHENTICATION_ERROR) req = request.json invite_user_email = req["email"] @@ -68,7 +72,8 @@ def create(tenant_id): return get_data_error_result(message=f"{invite_user_email} is already in the team.") if user_tenant_role == UserTenantRole.OWNER: return get_data_error_result(message=f"{invite_user_email} is the owner of the team.") - return get_data_error_result(message=f"{invite_user_email} is in the team, but the role: {user_tenant_role} is invalid.") + return get_data_error_result( + message=f"{invite_user_email} is in the team, but the role: {user_tenant_role} is invalid.") UserTenantService.save( id=get_uuid(), @@ -78,6 +83,20 @@ def create(tenant_id): role=UserTenantRole.INVITE, status=StatusEnum.VALID.value) + if smtp_mail_server and settings.SMTP_CONF: + from threading import Thread + + user_name = "" + _, user = UserService.get_by_id(current_user.id) + if user: + user_name = user.nickname + + Thread( + target=send_invite_email, + args=(invite_user_email, settings.MAIL_FRONTEND_URL, tenant_id, user_name or current_user.email), + daemon=True + ).start() + usr = invite_users[0].to_dict() usr = {k: v for k, v in usr.items() if k in ["id", "avatar", "email", "nickname"]} @@ -91,7 +110,7 @@ def rm(tenant_id, user_id): return get_json_result( data=False, message='No authorization.', - code=settings.RetCode.AUTHENTICATION_ERROR) + code=RetCode.AUTHENTICATION_ERROR) try: UserTenantService.filter_delete([UserTenant.tenant_id == tenant_id, UserTenant.user_id == user_id]) @@ -116,7 +135,8 @@ def tenant_list(): @login_required def agree(tenant_id): try: - UserTenantService.filter_update([UserTenant.tenant_id == tenant_id, UserTenant.user_id == current_user.id], {"role": UserTenantRole.NORMAL}) + UserTenantService.filter_update([UserTenant.tenant_id == tenant_id, UserTenant.user_id == current_user.id], + {"role": UserTenantRole.NORMAL}) return get_json_result(data=True) except Exception as e: return server_error_response(e) diff --git a/api/apps/user_app.py b/api/apps/user_app.py index b8d66ecba81..06130cce7fe 100644 --- a/api/apps/user_app.py +++ b/api/apps/user_app.py @@ -15,36 +15,49 @@ # import json import logging +import string +import os import re import secrets +import time from datetime import datetime -from flask import redirect, request, session +from flask import redirect, request, session, make_response from flask_login import current_user, login_required, login_user, logout_user from werkzeug.security import check_password_hash, generate_password_hash -from api import settings from api.apps.auth import get_auth_client from api.db import FileType, UserTenantRole from api.db.db_models import TenantLLM from api.db.services.file_service import FileService -from api.db.services.llm_service import LLMService, TenantLLMService +from api.db.services.llm_service import get_init_tenant_llm +from api.db.services.tenant_llm_service import TenantLLMService from api.db.services.user_service import TenantService, UserService, UserTenantService -from api.utils import ( - current_timestamp, - datetime_format, - decrypt, - download_img, - get_format_time, - get_uuid, -) +from common.time_utils import current_timestamp, datetime_format, get_format_time +from common.misc_utils import download_img, get_uuid +from common.constants import RetCode +from common.connection_utils import construct_response from api.utils.api_utils import ( - construct_response, get_data_error_result, get_json_result, server_error_response, validate_request, ) +from api.utils.crypt import decrypt +from rag.utils.redis_conn import REDIS_CONN +from api.apps import smtp_mail_server +from api.utils.web_utils import ( + send_email_html, + OTP_LENGTH, + OTP_TTL_SECONDS, + ATTEMPT_LIMIT, + ATTEMPT_LOCK_SECONDS, + RESEND_COOLDOWN_SECONDS, + otp_keys, + hash_code, + captcha_key, +) +from common import settings @manager.route("/login", methods=["POST", "GET"]) # noqa: F821 @@ -79,14 +92,14 @@ def login(): type: object """ if not request.json: - return get_json_result(data=False, code=settings.RetCode.AUTHENTICATION_ERROR, message="Unauthorized!") + return get_json_result(data=False, code=RetCode.AUTHENTICATION_ERROR, message="Unauthorized!") email = request.json.get("email", "") users = UserService.query(email=email) if not users: return get_json_result( data=False, - code=settings.RetCode.AUTHENTICATION_ERROR, + code=RetCode.AUTHENTICATION_ERROR, message=f"Email: {email} is not registered!", ) @@ -94,10 +107,17 @@ def login(): try: password = decrypt(password) except BaseException: - return get_json_result(data=False, code=settings.RetCode.SERVER_ERROR, message="Fail to crypt password") + return get_json_result(data=False, code=RetCode.SERVER_ERROR, message="Fail to crypt password") user = UserService.query_user(email, password) - if user: + + if user and hasattr(user, 'is_active') and user.is_active == "0": + return get_json_result( + data=False, + code=RetCode.FORBIDDEN, + message="This account has been disabled, please contact the administrator!", + ) + elif user: response_data = user.to_json() user.access_token = get_uuid() login_user(user) @@ -109,7 +129,7 @@ def login(): else: return get_json_result( data=False, - code=settings.RetCode.AUTHENTICATION_ERROR, + code=RetCode.AUTHENTICATION_ERROR, message="Email and password do not match!", ) @@ -132,7 +152,7 @@ def get_login_channels(): return get_json_result(data=channels) except Exception as e: logging.exception(e) - return get_json_result(data=[], message=f"Load channels failure, error: {str(e)}", code=settings.RetCode.EXCEPTION_ERROR) + return get_json_result(data=[], message=f"Load channels failure, error: {str(e)}", code=RetCode.EXCEPTION_ERROR) @manager.route("/login/", methods=["GET"]) # noqa: F821 @@ -226,6 +246,9 @@ def oauth_callback(channel): # User exists, try to log in user = users[0] user.access_token = get_uuid() + if user and hasattr(user, 'is_active') and user.is_active == "0": + return redirect("/?error=user_inactive") + login_user(user) user.save() return redirect(f"/?auth={user.get_id()}") @@ -316,6 +339,8 @@ def github_callback(): # User has already registered, try to log in user = users[0] user.access_token = get_uuid() + if user and hasattr(user, 'is_active') and user.is_active == "0": + return redirect("/?error=user_inactive") login_user(user) user.save() return redirect("/?auth=%s" % user.get_id()) @@ -417,6 +442,8 @@ def feishu_callback(): # User has already registered, try to log in user = users[0] + if user and hasattr(user, 'is_active') and user.is_active == "0": + return redirect("/?error=user_inactive") user.access_token = get_uuid() login_user(user) user.save() @@ -509,7 +536,7 @@ def setting_user(): if not check_password_hash(current_user.password, decrypt(request_data["password"])): return get_json_result( data=False, - code=settings.RetCode.AUTHENTICATION_ERROR, + code=RetCode.AUTHENTICATION_ERROR, message="Password error!", ) @@ -537,7 +564,7 @@ def setting_user(): return get_json_result(data=True) except Exception as e: logging.exception(e) - return get_json_result(data=False, message="Update failure!", code=settings.RetCode.EXCEPTION_ERROR) + return get_json_result(data=False, message="Update failure!", code=RetCode.EXCEPTION_ERROR) @manager.route("/info", methods=["GET"]) # noqa: F821 @@ -619,33 +646,8 @@ def user_register(user_id, user): "size": 0, "location": "", } - tenant_llm = [] - for llm in LLMService.query(fid=settings.LLM_FACTORY): - tenant_llm.append( - { - "tenant_id": user_id, - "llm_factory": settings.LLM_FACTORY, - "llm_name": llm.llm_name, - "model_type": llm.model_type, - "api_key": settings.API_KEY, - "api_base": settings.LLM_BASE_URL, - "max_tokens": llm.max_tokens if llm.max_tokens else 8192, - } - ) - if settings.LIGHTEN != 1: - for buildin_embedding_model in settings.BUILTIN_EMBEDDING_MODELS: - mdlnm, fid = TenantLLMService.split_model_name_and_factory(buildin_embedding_model) - tenant_llm.append( - { - "tenant_id": user_id, - "llm_factory": fid, - "llm_name": mdlnm, - "model_type": "embedding", - "api_key": "", - "api_base": "", - "max_tokens": 1024 if buildin_embedding_model == "BAAI/bge-large-zh-v1.5@BAAI" else 512, - } - ) + + tenant_llm = get_init_tenant_llm(user_id) if not UserService.save(**user): return @@ -692,7 +694,7 @@ def user_add(): return get_json_result( data=False, message="User registration is disabled!", - code=settings.RetCode.OPERATING_ERROR, + code=RetCode.OPERATING_ERROR, ) req = request.json @@ -703,7 +705,7 @@ def user_add(): return get_json_result( data=False, message=f"Invalid email address: {email_address}!", - code=settings.RetCode.OPERATING_ERROR, + code=RetCode.OPERATING_ERROR, ) # Check if the email address is already used @@ -711,7 +713,7 @@ def user_add(): return get_json_result( data=False, message=f"Email: {email_address} has already registered!", - code=settings.RetCode.OPERATING_ERROR, + code=RetCode.OPERATING_ERROR, ) # Construct user info data @@ -746,7 +748,7 @@ def user_add(): return get_json_result( data=False, message=f"User registration failure, error: {str(e)}", - code=settings.RetCode.EXCEPTION_ERROR, + code=RetCode.EXCEPTION_ERROR, ) @@ -835,3 +837,172 @@ def set_tenant_info(): return get_json_result(data=True) except Exception as e: return server_error_response(e) + + +@manager.route("/forget/captcha", methods=["GET"]) # noqa: F821 +def forget_get_captcha(): + """ + GET /forget/captcha?email= + - Generate an image captcha and cache it in Redis under key captcha:{email} with TTL = OTP_TTL_SECONDS. + - Returns the captcha as a PNG image. + """ + email = (request.args.get("email") or "") + if not email: + return get_json_result(data=False, code=RetCode.ARGUMENT_ERROR, message="email is required") + + users = UserService.query(email=email) + if not users: + return get_json_result(data=False, code=RetCode.DATA_ERROR, message="invalid email") + + # Generate captcha text + allowed = string.ascii_uppercase + string.digits + captcha_text = "".join(secrets.choice(allowed) for _ in range(OTP_LENGTH)) + REDIS_CONN.set(captcha_key(email), captcha_text, 60) # Valid for 60 seconds + + from captcha.image import ImageCaptcha + image = ImageCaptcha(width=300, height=120, font_sizes=[50, 60, 70]) + img_bytes = image.generate(captcha_text).read() + response = make_response(img_bytes) + response.headers.set("Content-Type", "image/JPEG") + return response + + +@manager.route("/forget/otp", methods=["POST"]) # noqa: F821 +def forget_send_otp(): + """ + POST /forget/otp + - Verify the image captcha stored at captcha:{email} (case-insensitive). + - On success, generate an email OTP (A–Z with length = OTP_LENGTH), store hash + salt (and timestamp) in Redis with TTL, reset attempts and cooldown, and send the OTP via email. + """ + req = request.get_json() + email = req.get("email") or "" + captcha = (req.get("captcha") or "").strip() + + if not email or not captcha: + return get_json_result(data=False, code=RetCode.ARGUMENT_ERROR, message="email and captcha required") + + users = UserService.query(email=email) + if not users: + return get_json_result(data=False, code=RetCode.DATA_ERROR, message="invalid email") + + stored_captcha = REDIS_CONN.get(captcha_key(email)) + if not stored_captcha: + return get_json_result(data=False, code=RetCode.NOT_EFFECTIVE, message="invalid or expired captcha") + if (stored_captcha or "").strip().lower() != captcha.lower(): + return get_json_result(data=False, code=RetCode.AUTHENTICATION_ERROR, message="invalid or expired captcha") + + # Delete captcha to prevent reuse + REDIS_CONN.delete(captcha_key(email)) + + k_code, k_attempts, k_last, k_lock = otp_keys(email) + now = int(time.time()) + last_ts = REDIS_CONN.get(k_last) + if last_ts: + try: + elapsed = now - int(last_ts) + except Exception: + elapsed = RESEND_COOLDOWN_SECONDS + remaining = RESEND_COOLDOWN_SECONDS - elapsed + if remaining > 0: + return get_json_result(data=False, code=RetCode.NOT_EFFECTIVE, message=f"you still have to wait {remaining} seconds") + + # Generate OTP (uppercase letters only) and store hashed + otp = "".join(secrets.choice(string.ascii_uppercase) for _ in range(OTP_LENGTH)) + salt = os.urandom(16) + code_hash = hash_code(otp, salt) + REDIS_CONN.set(k_code, f"{code_hash}:{salt.hex()}", OTP_TTL_SECONDS) + REDIS_CONN.set(k_attempts, 0, OTP_TTL_SECONDS) + REDIS_CONN.set(k_last, now, OTP_TTL_SECONDS) + REDIS_CONN.delete(k_lock) + + ttl_min = OTP_TTL_SECONDS // 60 + + if not smtp_mail_server: + logging.warning("SMTP mail server not initialized; skip sending email.") + else: + try: + send_email_html( + subject="Your Password Reset Code", + to_email=email, + template_key="reset_code", + code=otp, + ttl_min=ttl_min, + ) + except Exception: + return get_json_result(data=False, code=RetCode.SERVER_ERROR, message="failed to send email") + + return get_json_result(data=True, code=RetCode.SUCCESS, message="verification passed, email sent") + + +@manager.route("/forget", methods=["POST"]) # noqa: F821 +def forget(): + """ + POST: Verify email + OTP and reset password, then log the user in. + Request JSON: { email, otp, new_password, confirm_new_password } + """ + req = request.get_json() + email = req.get("email") or "" + otp = (req.get("otp") or "").strip() + new_pwd = req.get("new_password") + new_pwd2 = req.get("confirm_new_password") + + if not all([email, otp, new_pwd, new_pwd2]): + return get_json_result(data=False, code=RetCode.ARGUMENT_ERROR, message="email, otp and passwords are required") + + # For reset, passwords are provided as-is (no decrypt needed) + if new_pwd != new_pwd2: + return get_json_result(data=False, code=RetCode.ARGUMENT_ERROR, message="passwords do not match") + + users = UserService.query(email=email) + if not users: + return get_json_result(data=False, code=RetCode.DATA_ERROR, message="invalid email") + + user = users[0] + # Verify OTP from Redis + k_code, k_attempts, k_last, k_lock = otp_keys(email) + if REDIS_CONN.get(k_lock): + return get_json_result(data=False, code=RetCode.NOT_EFFECTIVE, message="too many attempts, try later") + + stored = REDIS_CONN.get(k_code) + if not stored: + return get_json_result(data=False, code=RetCode.NOT_EFFECTIVE, message="expired otp") + + try: + stored_hash, salt_hex = str(stored).split(":", 1) + salt = bytes.fromhex(salt_hex) + except Exception: + return get_json_result(data=False, code=RetCode.EXCEPTION_ERROR, message="otp storage corrupted") + + # Case-insensitive verification: OTP generated uppercase + calc = hash_code(otp.upper(), salt) + if calc != stored_hash: + # bump attempts + try: + attempts = int(REDIS_CONN.get(k_attempts) or 0) + 1 + except Exception: + attempts = 1 + REDIS_CONN.set(k_attempts, attempts, OTP_TTL_SECONDS) + if attempts >= ATTEMPT_LIMIT: + REDIS_CONN.set(k_lock, int(time.time()), ATTEMPT_LOCK_SECONDS) + return get_json_result(data=False, code=RetCode.AUTHENTICATION_ERROR, message="expired otp") + + # Success: consume OTP and reset password + REDIS_CONN.delete(k_code) + REDIS_CONN.delete(k_attempts) + REDIS_CONN.delete(k_last) + REDIS_CONN.delete(k_lock) + + try: + UserService.update_user_password(user.id, new_pwd) + except Exception as e: + logging.exception(e) + return get_json_result(data=False, code=RetCode.EXCEPTION_ERROR, message="failed to reset password") + + # Auto login (reuse login flow) + user.access_token = get_uuid() + login_user(user) + user.update_time = (current_timestamp(),) + user.update_date = (datetime_format(datetime.now()),) + user.save() + msg = "Password reset successful. Logged in." + return construct_response(data=user.to_json(), auth=user.get_id(), message=msg) diff --git a/api/common/README.md b/api/common/README.md new file mode 100644 index 00000000000..02f6302169e --- /dev/null +++ b/api/common/README.md @@ -0,0 +1,2 @@ +The python files in this directory are shared between service. They contain common utilities, models, and functions that can be used across various +services to ensure consistency and reduce code duplication. \ No newline at end of file diff --git a/api/common/base64.py b/api/common/base64.py new file mode 100644 index 00000000000..2b37dd28194 --- /dev/null +++ b/api/common/base64.py @@ -0,0 +1,21 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import base64 + +def encode_to_base64(input_string): + base64_encoded = base64.b64encode(input_string.encode('utf-8')) + return base64_encoded.decode('utf-8') \ No newline at end of file diff --git a/api/common/check_team_permission.py b/api/common/check_team_permission.py new file mode 100644 index 00000000000..c8e04d34b5c --- /dev/null +++ b/api/common/check_team_permission.py @@ -0,0 +1,59 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +from api.db import TenantPermission +from api.db.db_models import File, Knowledgebase +from api.db.services.file_service import FileService +from api.db.services.knowledgebase_service import KnowledgebaseService +from api.db.services.user_service import TenantService + + +def check_kb_team_permission(kb: dict | Knowledgebase, other: str) -> bool: + kb = kb.to_dict() if isinstance(kb, Knowledgebase) else kb + + kb_tenant_id = kb["tenant_id"] + + if kb_tenant_id == other: + return True + + if kb["permission"] != TenantPermission.TEAM: + return False + + joined_tenants = TenantService.get_joined_tenants_by_user_id(other) + return any(tenant["tenant_id"] == kb_tenant_id for tenant in joined_tenants) + + +def check_file_team_permission(file: dict | File, other: str) -> bool: + file = file.to_dict() if isinstance(file, File) else file + + file_tenant_id = file["tenant_id"] + if file_tenant_id == other: + return True + + file_id = file["id"] + + kb_ids = [kb_info["kb_id"] for kb_info in FileService.get_kb_id_by_file_id(file_id)] + + for kb_id in kb_ids: + ok, kb = KnowledgebaseService.get_by_id(kb_id) + if not ok: + continue + + if check_kb_team_permission(kb, other): + return True + + return False diff --git a/api/common/exceptions.py b/api/common/exceptions.py new file mode 100644 index 00000000000..508fb552701 --- /dev/null +++ b/api/common/exceptions.py @@ -0,0 +1,43 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +class AdminException(Exception): + def __init__(self, message, code=400): + super().__init__(message) + self.type = "admin" + self.code = code + self.message = message + + +class UserNotFoundError(AdminException): + def __init__(self, username): + super().__init__(f"User '{username}' not found", 404) + + +class UserAlreadyExistsError(AdminException): + def __init__(self, username): + super().__init__(f"User '{username}' already exists", 409) + + +class CannotDeleteAdminError(AdminException): + def __init__(self): + super().__init__("Cannot delete admin account", 403) + + +class NotAdminError(AdminException): + def __init__(self, username): + super().__init__(f"User '{username}' is not admin", 403) diff --git a/api/constants.py b/api/constants.py index ce5cdeb3a8d..464b7d8e669 100644 --- a/api/constants.py +++ b/api/constants.py @@ -17,8 +17,6 @@ IMG_BASE64_PREFIX = "data:image/png;base64," -SERVICE_CONF = "service_conf.yaml" - API_VERSION = "v1" RAG_FLOW_SERVICE_NAME = "ragflow" REQUEST_WAIT_SEC = 2 diff --git a/api/db/__init__.py b/api/db/__init__.py index a8c85ef4c0b..0ebd9f56f3f 100644 --- a/api/db/__init__.py +++ b/api/db/__init__.py @@ -13,16 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from enum import Enum + from enum import IntEnum from strenum import StrEnum -class StatusEnum(Enum): - VALID = "1" - INVALID = "0" - - class UserTenantRole(StrEnum): OWNER = 'owner' ADMIN = 'admin' @@ -51,57 +46,31 @@ class FileType(StrEnum): VALID_FILE_TYPES = {FileType.PDF, FileType.DOC, FileType.VISUAL, FileType.AURAL, FileType.VIRTUAL, FileType.FOLDER, FileType.OTHER} -class LLMType(StrEnum): - CHAT = 'chat' - EMBEDDING = 'embedding' - SPEECH2TEXT = 'speech2text' - IMAGE2TEXT = 'image2text' - RERANK = 'rerank' - TTS = 'tts' - - -class ChatStyle(StrEnum): - CREATIVE = 'Creative' - PRECISE = 'Precise' - EVENLY = 'Evenly' - CUSTOM = 'Custom' - - -class TaskStatus(StrEnum): - UNSTART = "0" - RUNNING = "1" - CANCEL = "2" - DONE = "3" - FAIL = "4" - -VALID_TASK_STATUS = {TaskStatus.UNSTART, TaskStatus.RUNNING, TaskStatus.CANCEL, TaskStatus.DONE, TaskStatus.FAIL} - -class ParserType(StrEnum): - PRESENTATION = "presentation" - LAWS = "laws" - MANUAL = "manual" - PAPER = "paper" - RESUME = "resume" - BOOK = "book" - QA = "qa" - TABLE = "table" - NAIVE = "naive" - PICTURE = "picture" - ONE = "one" - AUDIO = "audio" - EMAIL = "email" - KG = "knowledge_graph" - TAG = "tag" - - -class FileSource(StrEnum): - LOCAL = "" - KNOWLEDGEBASE = "knowledgebase" - S3 = "s3" - - -class CanvasType(StrEnum): - ChatBot = "chatbot" - DocBot = "docbot" + +class InputType(StrEnum): + LOAD_STATE = "load_state" # e.g. loading a current full state or a save state, such as from a file + POLL = "poll" # e.g. calling an API to get all documents in the last hour + EVENT = "event" # e.g. registered an endpoint as a listener, and processing connector events + SLIM_RETRIEVAL = "slim_retrieval" + + +class CanvasCategory(StrEnum): + Agent = "agent_canvas" + DataFlow = "dataflow_canvas" + + +class PipelineTaskType(StrEnum): + PARSE = "Parse" + DOWNLOAD = "Download" + RAPTOR = "RAPTOR" + GRAPH_RAG = "GraphRAG" + MINDMAP = "Mindmap" + + +VALID_PIPELINE_TASK_TYPES = {PipelineTaskType.PARSE, PipelineTaskType.DOWNLOAD, PipelineTaskType.RAPTOR, PipelineTaskType.GRAPH_RAG, PipelineTaskType.MINDMAP} + + +PIPELINE_SPECIAL_PROGRESS_FREEZE_TASK_TYPES = {PipelineTaskType.RAPTOR.lower(), PipelineTaskType.GRAPH_RAG.lower(), PipelineTaskType.MINDMAP.lower()} + KNOWLEDGEBASE_FOLDER_NAME=".knowledgebase" diff --git a/api/db/db_models.py b/api/db/db_models.py index 3ccfbdba392..68bf37ce4c6 100644 --- a/api/db/db_models.py +++ b/api/db/db_models.py @@ -21,29 +21,25 @@ import sys import time import typing +from datetime import datetime, timezone from enum import Enum from functools import wraps from flask_login import UserMixin from itsdangerous.url_safe import URLSafeTimedSerializer as Serializer -from peewee import BigIntegerField, BooleanField, CharField, CompositeKey, DateTimeField, Field, FloatField, IntegerField, Metadata, Model, TextField +from peewee import InterfaceError, OperationalError, BigIntegerField, BooleanField, CharField, CompositeKey, DateTimeField, Field, FloatField, IntegerField, Metadata, Model, TextField from playhouse.migrate import MySQLMigrator, PostgresqlMigrator, migrate from playhouse.pool import PooledMySQLDatabase, PooledPostgresqlDatabase -from api import settings, utils -from api.db import ParserType, SerializedType +from api import utils +from api.db import SerializedType +from api.utils.json_encode import json_dumps, json_loads +from api.utils.configs import deserialize_b64, serialize_b64 - -def singleton(cls, *args, **kw): - instances = {} - - def _singleton(): - key = str(cls) + str(os.getpid()) - if key not in instances: - instances[key] = cls(*args, **kw) - return instances[key] - - return _singleton +from common.time_utils import current_timestamp, timestamp_to_date, date_string_to_timestamp +from common.decorator import singleton +from common.constants import ParserType +from common import settings CONTINUOUS_FIELD_TYPE = {IntegerField, FloatField, DateTimeField} @@ -70,12 +66,12 @@ def __init__(self, object_hook=None, object_pairs_hook=None, **kwargs): def db_value(self, value): if value is None: value = self.default_value - return utils.json_dumps(value) + return json_dumps(value) def python_value(self, value): if not value: return self.default_value - return utils.json_loads(value, object_hook=self._object_hook, object_pairs_hook=self._object_pairs_hook) + return json_loads(value, object_hook=self._object_hook, object_pairs_hook=self._object_pairs_hook) class ListField(JSONField): @@ -91,21 +87,21 @@ def __init__(self, serialized_type=SerializedType.PICKLE, object_hook=None, obje def db_value(self, value): if self._serialized_type == SerializedType.PICKLE: - return utils.serialize_b64(value, to_str=True) + return serialize_b64(value, to_str=True) elif self._serialized_type == SerializedType.JSON: if value is None: return None - return utils.json_dumps(value, with_type=True) + return json_dumps(value, with_type=True) else: raise ValueError(f"the serialized type {self._serialized_type} is not supported") def python_value(self, value): if self._serialized_type == SerializedType.PICKLE: - return utils.deserialize_b64(value) + return deserialize_b64(value) elif self._serialized_type == SerializedType.JSON: if value is None: return {} - return utils.json_loads(value, object_hook=self._object_hook, object_pairs_hook=self._object_pairs_hook) + return json_loads(value, object_hook=self._object_hook, object_pairs_hook=self._object_pairs_hook) else: raise ValueError(f"the serialized type {self._serialized_type} is not supported") @@ -187,7 +183,7 @@ def query(cls, reverse=None, order_by=None, **kwargs): for i, v in enumerate(f_v): if isinstance(v, str) and f_n in auto_date_timestamp_field(): # time type: %Y-%m-%d %H:%M:%S - f_v[i] = utils.date_string_to_timestamp(v) + f_v[i] = date_string_to_timestamp(v) lt_value = f_v[0] gt_value = f_v[1] if lt_value is not None and gt_value is not None: @@ -216,9 +212,9 @@ def query(cls, reverse=None, order_by=None, **kwargs): @classmethod def insert(cls, __data=None, **insert): if isinstance(__data, dict) and __data: - __data[cls._meta.combined["create_time"]] = utils.current_timestamp() + __data[cls._meta.combined["create_time"]] = current_timestamp() if insert: - insert["create_time"] = utils.current_timestamp() + insert["create_time"] = current_timestamp() return super().insert(__data, **insert) @@ -229,11 +225,11 @@ def _normalize_data(cls, data, kwargs): if not normalized: return {} - normalized[cls._meta.combined["update_time"]] = utils.current_timestamp() + normalized[cls._meta.combined["update_time"]] = current_timestamp() for f_n in AUTO_DATE_TIMESTAMP_FIELD_PREFIX: if {f"{f_n}_time", f"{f_n}_date"}.issubset(cls._meta.combined.keys()) and cls._meta.combined[f"{f_n}_time"] in normalized and normalized[cls._meta.combined[f"{f_n}_time"]] is not None: - normalized[cls._meta.combined[f"{f_n}_date"]] = utils.timestamp_to_date(normalized[cls._meta.combined[f"{f_n}_time"]]) + normalized[cls._meta.combined[f"{f_n}_date"]] = timestamp_to_date(normalized[cls._meta.combined[f"{f_n}_time"]]) return normalized @@ -243,9 +239,144 @@ def __init__(self, object_hook=utils.from_dict_hook, object_pairs_hook=None, **k super(JsonSerializedField, self).__init__(serialized_type=SerializedType.JSON, object_hook=object_hook, object_pairs_hook=object_pairs_hook, **kwargs) +class RetryingPooledMySQLDatabase(PooledMySQLDatabase): + def __init__(self, *args, **kwargs): + self.max_retries = kwargs.pop("max_retries", 5) + self.retry_delay = kwargs.pop("retry_delay", 1) + super().__init__(*args, **kwargs) + + def execute_sql(self, sql, params=None, commit=True): + for attempt in range(self.max_retries + 1): + try: + return super().execute_sql(sql, params, commit) + except (OperationalError, InterfaceError) as e: + error_codes = [2013, 2006] + error_messages = ['', 'Lost connection'] + should_retry = ( + (hasattr(e, 'args') and e.args and e.args[0] in error_codes) or + (str(e) in error_messages) or + (hasattr(e, '__class__') and e.__class__.__name__ == 'InterfaceError') + ) + + if should_retry and attempt < self.max_retries: + logging.warning( + f"Database connection issue (attempt {attempt+1}/{self.max_retries}): {e}" + ) + self._handle_connection_loss() + time.sleep(self.retry_delay * (2 ** attempt)) + else: + logging.error(f"DB execution failure: {e}") + raise + return None + + def _handle_connection_loss(self): + # self.close_all() + # self.connect() + try: + self.close() + except Exception: + pass + try: + self.connect() + except Exception as e: + logging.error(f"Failed to reconnect: {e}") + time.sleep(0.1) + self.connect() + + def begin(self): + for attempt in range(self.max_retries + 1): + try: + return super().begin() + except (OperationalError, InterfaceError) as e: + error_codes = [2013, 2006] + error_messages = ['', 'Lost connection'] + + should_retry = ( + (hasattr(e, 'args') and e.args and e.args[0] in error_codes) or + (str(e) in error_messages) or + (hasattr(e, '__class__') and e.__class__.__name__ == 'InterfaceError') + ) + + if should_retry and attempt < self.max_retries: + logging.warning( + f"Lost connection during transaction (attempt {attempt+1}/{self.max_retries})" + ) + self._handle_connection_loss() + time.sleep(self.retry_delay * (2 ** attempt)) + else: + raise + + +class RetryingPooledPostgresqlDatabase(PooledPostgresqlDatabase): + def __init__(self, *args, **kwargs): + self.max_retries = kwargs.pop("max_retries", 5) + self.retry_delay = kwargs.pop("retry_delay", 1) + super().__init__(*args, **kwargs) + + def execute_sql(self, sql, params=None, commit=True): + for attempt in range(self.max_retries + 1): + try: + return super().execute_sql(sql, params, commit) + except (OperationalError, InterfaceError) as e: + # PostgreSQL specific error codes + # 57P01: admin_shutdown + # 57P02: crash_shutdown + # 57P03: cannot_connect_now + # 08006: connection_failure + # 08003: connection_does_not_exist + # 08000: connection_exception + error_messages = ['connection', 'server closed', 'connection refused', + 'no connection to the server', 'terminating connection'] + + should_retry = any(msg in str(e).lower() for msg in error_messages) + + if should_retry and attempt < self.max_retries: + logging.warning( + f"PostgreSQL connection issue (attempt {attempt+1}/{self.max_retries}): {e}" + ) + self._handle_connection_loss() + time.sleep(self.retry_delay * (2 ** attempt)) + else: + logging.error(f"PostgreSQL execution failure: {e}") + raise + return None + + def _handle_connection_loss(self): + try: + self.close() + except Exception: + pass + try: + self.connect() + except Exception as e: + logging.error(f"Failed to reconnect to PostgreSQL: {e}") + time.sleep(0.1) + self.connect() + + def begin(self): + for attempt in range(self.max_retries + 1): + try: + return super().begin() + except (OperationalError, InterfaceError) as e: + error_messages = ['connection', 'server closed', 'connection refused', + 'no connection to the server', 'terminating connection'] + + should_retry = any(msg in str(e).lower() for msg in error_messages) + + if should_retry and attempt < self.max_retries: + logging.warning( + f"PostgreSQL connection lost during transaction (attempt {attempt+1}/{self.max_retries})" + ) + self._handle_connection_loss() + time.sleep(self.retry_delay * (2 ** attempt)) + else: + raise + return None + + class PooledDatabase(Enum): - MYSQL = PooledMySQLDatabase - POSTGRES = PooledPostgresqlDatabase + MYSQL = RetryingPooledMySQLDatabase + POSTGRES = RetryingPooledPostgresqlDatabase class DatabaseMigrator(Enum): @@ -258,7 +389,16 @@ class BaseDataBase: def __init__(self): database_config = settings.DATABASE.copy() db_name = database_config.pop("name") - self.database_connection = PooledDatabase[settings.DATABASE_TYPE.upper()].value(db_name, **database_config) + + pool_config = { + 'max_retries': 5, + 'retry_delay': 1, + } + database_config.update(pool_config) + self.database_connection = PooledDatabase[settings.DATABASE_TYPE.upper()].value( + db_name, **database_config + ) + # self.database_connection = PooledDatabase[settings.DATABASE_TYPE.upper()].value(db_name, **database_config) logging.info("init database on cluster mode successfully") @@ -420,6 +560,7 @@ class Meta: @DB.connection_context() +@DB.lock("init_database_tables", 60) def init_database_tables(alter_fields=[]): members = inspect.getmembers(sys.modules[__name__], inspect.isclass) table_objs = [] @@ -431,7 +572,7 @@ def init_database_tables(alter_fields=[]): if not obj.table_exists(): logging.debug(f"start create table {obj.__name__}") try: - obj.create_table() + obj.create_table(safe=True) logging.debug(f"create table success: {obj.__name__}") except Exception as e: logging.exception(e) @@ -528,6 +669,7 @@ class LLMFactories(DataBaseModel): name = CharField(max_length=128, null=False, help_text="LLM factory name", primary_key=True) logo = TextField(null=True, help_text="llm logo base64") tags = CharField(max_length=255, null=False, help_text="LLM, Text Embedding, Image2Text, ASR", index=True) + rank = IntegerField(default=0, index=False) status = CharField(max_length=1, null=True, help_text="is it validate(0: wasted, 1: validate)", default="1", index=True) def __str__(self): @@ -561,10 +703,11 @@ class TenantLLM(DataBaseModel): llm_factory = CharField(max_length=128, null=False, help_text="LLM factory name", index=True) model_type = CharField(max_length=128, null=True, help_text="LLM, Text Embedding, Image2Text, ASR", index=True) llm_name = CharField(max_length=128, null=True, help_text="LLM name", default="", index=True) - api_key = CharField(max_length=2048, null=True, help_text="API KEY", index=True) + api_key = TextField(null=True, help_text="API KEY") api_base = CharField(max_length=255, null=True, help_text="API Base") max_tokens = IntegerField(default=8192, index=True) used_tokens = IntegerField(default=0, index=True) + status = CharField(max_length=1, null=False, help_text="is it validate(0: wasted, 1: validate)", default="1", index=True) def __str__(self): return self.llm_name @@ -604,8 +747,17 @@ class Knowledgebase(DataBaseModel): vector_similarity_weight = FloatField(default=0.3, index=True) parser_id = CharField(max_length=32, null=False, help_text="default parser ID", default=ParserType.NAIVE.value, index=True) + pipeline_id = CharField(max_length=32, null=True, help_text="Pipeline ID", index=True) parser_config = JSONField(null=False, default={"pages": [[1, 1000000]]}) pagerank = IntegerField(default=0, index=False) + + graphrag_task_id = CharField(max_length=32, null=True, help_text="Graph RAG task ID", index=True) + graphrag_task_finish_at = DateTimeField(null=True) + raptor_task_id = CharField(max_length=32, null=True, help_text="RAPTOR task ID", index=True) + raptor_task_finish_at = DateTimeField(null=True) + mindmap_task_id = CharField(max_length=32, null=True, help_text="Mindmap task ID", index=True) + mindmap_task_finish_at = DateTimeField(null=True) + status = CharField(max_length=1, null=True, help_text="is it validate(0: wasted, 1: validate)", default="1", index=True) def __str__(self): @@ -620,6 +772,7 @@ class Document(DataBaseModel): thumbnail = TextField(null=True, help_text="thumbnail base64 string") kb_id = CharField(max_length=256, null=False, index=True) parser_id = CharField(max_length=32, null=False, help_text="default parser ID", index=True) + pipeline_id = CharField(max_length=32, null=True, help_text="pipleline ID", index=True) parser_config = JSONField(null=False, default={"pages": [[1, 1000000]]}) source_type = CharField(max_length=128, null=False, default="local", help_text="where dose this document come from", index=True) type = CharField(max_length=32, null=False, help_text="file extension", index=True) @@ -632,8 +785,9 @@ class Document(DataBaseModel): progress = FloatField(default=0, index=True) progress_msg = TextField(null=True, help_text="process message", default="") process_begin_at = DateTimeField(null=True, index=True) - process_duation = FloatField(default=0) + process_duration = FloatField(default=0) meta_fields = JSONField(null=True, default={}) + suffix = CharField(max_length=32, null=False, help_text="The real file extension suffix", index=True) run = CharField(max_length=1, null=True, help_text="start to run processing or cancel.(1: run it; 2: cancel)", default="0", index=True) status = CharField(max_length=1, null=True, help_text="is it validate(0: wasted, 1: validate)", default="1", index=True) @@ -675,7 +829,7 @@ class Task(DataBaseModel): priority = IntegerField(default=0) begin_at = DateTimeField(null=True, index=True) - process_duation = FloatField(default=0) + process_duration = FloatField(default=0) progress = FloatField(default=0, index=True) progress_msg = TextField(null=True, help_text="process message", default="") @@ -697,8 +851,9 @@ class Dialog(DataBaseModel): prompt_type = CharField(max_length=16, null=False, default="simple", help_text="simple|advanced", index=True) prompt_config = JSONField( null=False, - default={"system": "", "prologue": "Hi! I'm your assistant, what can I do for you?", "parameters": [], "empty_response": "Sorry! No relevant content was found in the knowledge base!"}, + default={"system": "", "prologue": "Hi! I'm your assistant. What can I do for you?", "parameters": [], "empty_response": "Sorry! No relevant content was found in the knowledge base!"}, ) + meta_data_filter = JSONField(null=True, default={}) similarity_threshold = FloatField(default=0.2) vector_similarity_weight = FloatField(default=0.3) @@ -754,6 +909,7 @@ class API4Conversation(DataBaseModel): duration = FloatField(default=0, index=True) round = IntegerField(default=0, index=True) thumb_up = IntegerField(default=0, index=True) + errors = TextField(null=True, help_text="errors") class Meta: db_table = "api_4_conversation" @@ -768,6 +924,7 @@ class UserCanvas(DataBaseModel): permission = CharField(max_length=16, null=False, help_text="me|team", default="me", index=True) description = TextField(null=True, help_text="Canvas description") canvas_type = CharField(max_length=32, null=True, help_text="Canvas type", index=True) + canvas_category = CharField(max_length=32, null=False, default="agent_canvas", help_text="Canvas category: agent_canvas|dataflow_canvas", index=True) dsl = JSONField(null=True, default={}) class Meta: @@ -777,10 +934,10 @@ class Meta: class CanvasTemplate(DataBaseModel): id = CharField(max_length=32, primary_key=True) avatar = TextField(null=True, help_text="avatar base64 string") - title = CharField(max_length=255, null=True, help_text="Canvas title") - - description = TextField(null=True, help_text="Canvas description") + title = JSONField(null=True, default=dict, help_text="Canvas title") + description = JSONField(null=True, default=dict, help_text="Canvas description") canvas_type = CharField(max_length=32, null=True, help_text="Canvas type", index=True) + canvas_category = CharField(max_length=32, null=False, default="agent_canvas", help_text="Canvas category: agent_canvas|dataflow_canvas", index=True) dsl = JSONField(null=True, default={}) class Meta: @@ -799,6 +956,20 @@ class Meta: db_table = "user_canvas_version" +class MCPServer(DataBaseModel): + id = CharField(max_length=32, primary_key=True) + name = CharField(max_length=255, null=False, help_text="MCP Server name") + tenant_id = CharField(max_length=32, null=False, index=True) + url = CharField(max_length=2048, null=False, help_text="MCP Server URL") + server_type = CharField(max_length=32, null=False, help_text="MCP Server type") + description = TextField(null=True, help_text="MCP Server description") + variables = JSONField(null=True, default=dict, help_text="MCP Server variables") + headers = JSONField(null=True, default=dict, help_text="MCP Server additional request headers") + + class Meta: + db_table = "mcp_server" + + class Search(DataBaseModel): id = CharField(max_length=32, primary_key=True) avatar = TextField(null=True, help_text="avatar base64 string") @@ -811,7 +982,7 @@ class Search(DataBaseModel): default={ "kb_ids": [], "doc_ids": [], - "similarity_threshold": 0.0, + "similarity_threshold": 0.2, "vector_similarity_weight": 0.3, "use_kg": False, # rerank settings @@ -820,11 +991,12 @@ class Search(DataBaseModel): # chat settings "summary": False, "chat_id": "", + # Leave it here for reference, don't need to set default values "llm_setting": { - "temperature": 0.1, - "top_p": 0.3, - "frequency_penalty": 0.7, - "presence_penalty": 0.4, + # "temperature": 0.1, + # "top_p": 0.3, + # "frequency_penalty": 0.7, + # "presence_penalty": 0.4, }, "chat_settingcross_languages": [], "highlight": False, @@ -843,7 +1015,105 @@ class Meta: db_table = "search" +class PipelineOperationLog(DataBaseModel): + id = CharField(max_length=32, primary_key=True) + document_id = CharField(max_length=32, index=True) + tenant_id = CharField(max_length=32, null=False, index=True) + kb_id = CharField(max_length=32, null=False, index=True) + pipeline_id = CharField(max_length=32, null=True, help_text="Pipeline ID", index=True) + pipeline_title = CharField(max_length=32, null=True, help_text="Pipeline title", index=True) + parser_id = CharField(max_length=32, null=False, help_text="Parser ID", index=True) + document_name = CharField(max_length=255, null=False, help_text="File name") + document_suffix = CharField(max_length=255, null=False, help_text="File suffix") + document_type = CharField(max_length=255, null=False, help_text="Document type") + source_from = CharField(max_length=255, null=False, help_text="Source") + progress = FloatField(default=0, index=True) + progress_msg = TextField(null=True, help_text="process message", default="") + process_begin_at = DateTimeField(null=True, index=True) + process_duration = FloatField(default=0) + dsl = JSONField(null=True, default=dict) + task_type = CharField(max_length=32, null=False, default="") + operation_status = CharField(max_length=32, null=False, help_text="Operation status") + avatar = TextField(null=True, help_text="avatar base64 string") + status = CharField(max_length=1, null=True, help_text="is it validate(0: wasted, 1: validate)", default="1", index=True) + + class Meta: + db_table = "pipeline_operation_log" + + +class Connector(DataBaseModel): + id = CharField(max_length=32, primary_key=True) + tenant_id = CharField(max_length=32, null=False, index=True) + name = CharField(max_length=128, null=False, help_text="Search name", index=False) + source = CharField(max_length=128, null=False, help_text="Data source", index=True) + input_type = CharField(max_length=128, null=False, help_text="poll/event/..", index=True) + config = JSONField(null=False, default={}) + refresh_freq = IntegerField(default=0, index=False) + prune_freq = IntegerField(default=0, index=False) + timeout_secs = IntegerField(default=3600, index=False) + indexing_start = DateTimeField(null=True, index=True) + status = CharField(max_length=16, null=True, help_text="schedule", default="schedule", index=True) + + def __str__(self): + return self.name + + class Meta: + db_table = "connector" + + +class Connector2Kb(DataBaseModel): + id = CharField(max_length=32, primary_key=True) + connector_id = CharField(max_length=32, null=False, index=True) + kb_id = CharField(max_length=32, null=False, index=True) + auto_parse = CharField(max_length=1, null=False, default="1", index=False) + + class Meta: + db_table = "connector2kb" + + +class DateTimeTzField(CharField): + field_type = 'VARCHAR' + + def db_value(self, value: datetime|None) -> str|None: + if value is not None: + if value.tzinfo is not None: + return value.isoformat() + else: + return value.replace(tzinfo=timezone.utc).isoformat() + return value + + def python_value(self, value: str|None) -> datetime|None: + if value is not None: + dt = datetime.fromisoformat(value) + if dt.tzinfo is None: + import pytz + return dt.replace(tzinfo=pytz.UTC) + return dt + return value + + +class SyncLogs(DataBaseModel): + id = CharField(max_length=32, primary_key=True) + connector_id = CharField(max_length=32, index=True) + status = CharField(max_length=128, null=False, help_text="Processing status", index=True) + from_beginning = CharField(max_length=1, null=True, help_text="", default="0", index=False) + new_docs_indexed = IntegerField(default=0, index=False) + total_docs_indexed = IntegerField(default=0, index=False) + docs_removed_from_index = IntegerField(default=0, index=False) + error_msg = TextField(null=False, help_text="process message", default="") + error_count = IntegerField(default=0, index=False) + full_exception_trace = TextField(null=True, help_text="process message", default="") + time_started = DateTimeField(null=True, index=True) + poll_range_start = DateTimeTzField(max_length=255, null=True, index=True) + poll_range_end = DateTimeTzField(max_length=255, null=True, index=True) + kb_id = CharField(max_length=32, null=False, index=True) + + class Meta: + db_table = "sync_logs" + + def migrate_db(): + logging.disable(logging.ERROR) migrator = DatabaseMigrator[settings.DATABASE_TYPE.upper()].value(DB) try: migrate(migrator.add_column("file", "source_type", CharField(max_length=128, null=False, default="", help_text="where dose this document come from", index=True))) @@ -934,3 +1204,92 @@ def migrate_db(): migrate(migrator.add_column("llm", "is_tools", BooleanField(null=False, help_text="support tools", default=False))) except Exception: pass + try: + migrate(migrator.add_column("mcp_server", "variables", JSONField(null=True, help_text="MCP Server variables", default=dict))) + except Exception: + pass + try: + migrate(migrator.rename_column("task", "process_duation", "process_duration")) + except Exception: + pass + try: + migrate(migrator.rename_column("document", "process_duation", "process_duration")) + except Exception: + pass + try: + migrate(migrator.add_column("document", "suffix", CharField(max_length=32, null=False, default="", help_text="The real file extension suffix", index=True))) + except Exception: + pass + try: + migrate(migrator.add_column("api_4_conversation", "errors", TextField(null=True, help_text="errors"))) + except Exception: + pass + try: + migrate(migrator.add_column("dialog", "meta_data_filter", JSONField(null=True, default={}))) + except Exception: + pass + try: + migrate(migrator.alter_column_type("canvas_template", "title", JSONField(null=True, default=dict, help_text="Canvas title"))) + except Exception: + pass + try: + migrate(migrator.alter_column_type("canvas_template", "description", JSONField(null=True, default=dict, help_text="Canvas description"))) + except Exception: + pass + try: + migrate(migrator.add_column("user_canvas", "canvas_category", CharField(max_length=32, null=False, default="agent_canvas", help_text="agent_canvas|dataflow_canvas", index=True))) + except Exception: + pass + try: + migrate(migrator.add_column("canvas_template", "canvas_category", CharField(max_length=32, null=False, default="agent_canvas", help_text="agent_canvas|dataflow_canvas", index=True))) + except Exception: + pass + try: + migrate(migrator.add_column("knowledgebase", "pipeline_id", CharField(max_length=32, null=True, help_text="Pipeline ID", index=True))) + except Exception: + pass + try: + migrate(migrator.add_column("document", "pipeline_id", CharField(max_length=32, null=True, help_text="Pipeline ID", index=True))) + except Exception: + pass + try: + migrate(migrator.add_column("knowledgebase", "graphrag_task_id", CharField(max_length=32, null=True, help_text="Gragh RAG task ID", index=True))) + except Exception: + pass + try: + migrate(migrator.add_column("knowledgebase", "raptor_task_id", CharField(max_length=32, null=True, help_text="RAPTOR task ID", index=True))) + except Exception: + pass + try: + migrate(migrator.add_column("knowledgebase", "graphrag_task_finish_at", DateTimeField(null=True))) + except Exception: + pass + try: + migrate(migrator.add_column("knowledgebase", "raptor_task_finish_at", CharField(null=True))) + except Exception: + pass + try: + migrate(migrator.add_column("knowledgebase", "mindmap_task_id", CharField(max_length=32, null=True, help_text="Mindmap task ID", index=True))) + except Exception: + pass + try: + migrate(migrator.add_column("knowledgebase", "mindmap_task_finish_at", CharField(null=True))) + except Exception: + pass + try: + migrate(migrator.alter_column_type("tenant_llm", "api_key", TextField(null=True, help_text="API KEY"))) + except Exception: + pass + try: + migrate(migrator.add_column("tenant_llm", "status", CharField(max_length=1, null=False, help_text="is it validate(0: wasted, 1: validate)", default="1", index=True))) + except Exception: + pass + try: + migrate(migrator.add_column("connector2kb", "auto_parse", CharField(max_length=1, null=False, default="1", index=False))) + except Exception: + pass + try: + migrate(migrator.add_column("llm_factories", "rank", IntegerField(default=0, index=False))) + except Exception: + pass + logging.disable(logging.NOTSET) diff --git a/api/db/db_utils.py b/api/db/db_utils.py index e597e335867..e86f1234a28 100644 --- a/api/db/db_utils.py +++ b/api/db/db_utils.py @@ -18,7 +18,7 @@ from playhouse.pool import PooledMySQLDatabase -from api.utils import current_timestamp, timestamp_to_date +from common.time_utils import current_timestamp, timestamp_to_date from api.db.db_models import DB, DataBaseModel diff --git a/api/db/init_data.py b/api/db/init_data.py index b46b27ce6b0..4a9ad067afd 100644 --- a/api/db/init_data.py +++ b/api/db/init_data.py @@ -14,28 +14,25 @@ # limitations under the License. # import logging -import base64 import json import os import time import uuid from copy import deepcopy -from api.db import LLMType, UserTenantRole +from api.db import UserTenantRole from api.db.db_models import init_database_tables as init_web_db, LLMFactories, LLM, TenantLLM from api.db.services import UserService from api.db.services.canvas_service import CanvasTemplateService from api.db.services.document_service import DocumentService from api.db.services.knowledgebase_service import KnowledgebaseService -from api.db.services.llm_service import LLMFactoriesService, LLMService, TenantLLMService, LLMBundle +from api.db.services.tenant_llm_service import LLMFactoriesService, TenantLLMService +from api.db.services.llm_service import LLMService, LLMBundle, get_init_tenant_llm from api.db.services.user_service import TenantService, UserTenantService -from api import settings -from api.utils.file_utils import get_project_base_directory - - -def encode_to_base64(input_string): - base64_encoded = base64.b64encode(input_string.encode('utf-8')) - return base64_encoded.decode('utf-8') +from common.constants import LLMType +from common.file_utils import get_project_base_directory +from common import settings +from api.common.base64 import encode_to_base64 def init_superuser(): @@ -63,12 +60,8 @@ def init_superuser(): "invited_by": user_info["id"], "role": UserTenantRole.OWNER } - tenant_llm = [] - for llm in LLMService.query(fid=settings.LLM_FACTORY): - tenant_llm.append( - {"tenant_id": user_info["id"], "llm_factory": settings.LLM_FACTORY, "llm_name": llm.llm_name, - "model_type": llm.model_type, - "api_key": settings.API_KEY, "api_base": settings.LLM_BASE_URL}) + + tenant_llm = get_init_tenant_llm(user_info["id"]) if not UserService.save(**user_info): logging.error("can't init admin.") @@ -96,14 +89,8 @@ def init_superuser(): def init_llm_factory(): - try: - LLMService.filter_delete([(LLM.fid == "MiniMax" or LLM.fid == "Minimax")]) - LLMService.filter_delete([(LLM.fid == "cohere")]) - LLMFactoriesService.filter_delete([LLMFactories.name == "cohere"]) - except Exception: - pass - - factory_llm_infos = settings.FACTORY_LLM_INFOS + LLMFactoriesService.filter_delete([1 == 1]) + factory_llm_infos = settings.FACTORY_LLM_INFOS for factory_llm_info in factory_llm_infos: info = deepcopy(factory_llm_info) llm_infos = info.pop("llm") @@ -147,13 +134,19 @@ def init_llm_factory(): except Exception: pass break + doc_count = DocumentService.get_all_kb_doc_count() for kb_id in KnowledgebaseService.get_all_ids(): - KnowledgebaseService.update_document_number_in_init(kb_id=kb_id, doc_num=DocumentService.get_kb_doc_count(kb_id)) + KnowledgebaseService.update_document_number_in_init(kb_id=kb_id, doc_num=doc_count.get(kb_id, 0)) def add_graph_templates(): dir = os.path.join(get_project_base_directory(), "agent", "templates") + CanvasTemplateService.filter_delete([1 == 1]) + if not os.path.exists(dir): + logging.warning("Missing agent templates!") + return + for fnm in os.listdir(dir): try: cnvs = json.load(open(os.path.join(dir, fnm), "r",encoding="utf-8")) @@ -162,7 +155,7 @@ def add_graph_templates(): except Exception: CanvasTemplateService.update_by_id(cnvs["id"], cnvs) except Exception: - logging.exception("Add graph templates error: ") + logging.exception("Add agent templates error: ") def init_web_data(): diff --git a/web/src/pages/flow/flow-setting/index.less b/api/db/joint_services/__init__.py similarity index 100% rename from web/src/pages/flow/flow-setting/index.less rename to api/db/joint_services/__init__.py diff --git a/api/db/joint_services/user_account_service.py b/api/db/joint_services/user_account_service.py new file mode 100644 index 00000000000..34ceee64818 --- /dev/null +++ b/api/db/joint_services/user_account_service.py @@ -0,0 +1,326 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import uuid + +from api.utils.api_utils import group_by +from api.db import FileType, UserTenantRole +from api.db.services.api_service import APITokenService, API4ConversationService +from api.db.services.canvas_service import UserCanvasService +from api.db.services.conversation_service import ConversationService +from api.db.services.dialog_service import DialogService +from api.db.services.document_service import DocumentService +from api.db.services.file2document_service import File2DocumentService +from api.db.services.knowledgebase_service import KnowledgebaseService +from api.db.services.langfuse_service import TenantLangfuseService +from api.db.services.llm_service import get_init_tenant_llm +from api.db.services.file_service import FileService +from api.db.services.mcp_server_service import MCPServerService +from api.db.services.search_service import SearchService +from api.db.services.task_service import TaskService +from api.db.services.tenant_llm_service import TenantLLMService +from api.db.services.user_canvas_version import UserCanvasVersionService +from api.db.services.user_service import TenantService, UserService, UserTenantService +from rag.nlp import search +from common.constants import ActiveEnum +from common import settings + +def create_new_user(user_info: dict) -> dict: + """ + Add a new user, and create tenant, tenant llm, file folder for new user. + :param user_info: { + "email": , + "nickname": , + "password": , + "login_channel": , + "is_superuser": , + } + :return: { + "success": , + "user_info": , # if true, return user_info + } + """ + # generate user_id and access_token for user + user_id = uuid.uuid1().hex + user_info['id'] = user_id + user_info['access_token'] = uuid.uuid1().hex + # construct tenant info + tenant = { + "id": user_id, + "name": user_info["nickname"] + "‘s Kingdom", + "llm_id": settings.CHAT_MDL, + "embd_id": settings.EMBEDDING_MDL, + "asr_id": settings.ASR_MDL, + "parser_ids": settings.PARSERS, + "img2txt_id": settings.IMAGE2TEXT_MDL, + "rerank_id": settings.RERANK_MDL, + } + usr_tenant = { + "tenant_id": user_id, + "user_id": user_id, + "invited_by": user_id, + "role": UserTenantRole.OWNER, + } + # construct file folder info + file_id = uuid.uuid1().hex + file = { + "id": file_id, + "parent_id": file_id, + "tenant_id": user_id, + "created_by": user_id, + "name": "/", + "type": FileType.FOLDER.value, + "size": 0, + "location": "", + } + try: + tenant_llm = get_init_tenant_llm(user_id) + + if not UserService.save(**user_info): + return {"success": False} + + TenantService.insert(**tenant) + UserTenantService.insert(**usr_tenant) + TenantLLMService.insert_many(tenant_llm) + FileService.insert(file) + + return { + "success": True, + "user_info": user_info, + } + + except Exception as create_error: + logging.exception(create_error) + # rollback + try: + TenantService.delete_by_id(user_id) + except Exception as e: + logging.exception(e) + try: + u = UserTenantService.query(tenant_id=user_id) + if u: + UserTenantService.delete_by_id(u[0].id) + except Exception as e: + logging.exception(e) + try: + TenantLLMService.delete_by_tenant_id(user_id) + except Exception as e: + logging.exception(e) + try: + FileService.delete_by_id(file["id"]) + except Exception as e: + logging.exception(e) + # delete user row finally + try: + UserService.delete_by_id(user_id) + except Exception as e: + logging.exception(e) + # reraise + raise create_error + + +def delete_user_data(user_id: str) -> dict: + # use user_id to delete + usr = UserService.filter_by_id(user_id) + if not usr: + return {"success": False, "message": f"{user_id} can't be found."} + # check is inactive and not admin + if usr.is_active == ActiveEnum.ACTIVE.value: + return {"success": False, "message": f"{user_id} is active and can't be deleted."} + if usr.is_superuser: + return {"success": False, "message": "Can't delete the super user."} + # tenant info + tenants = UserTenantService.get_user_tenant_relation_by_user_id(usr.id) + owned_tenant = [t for t in tenants if t["role"] == UserTenantRole.OWNER.value] + + done_msg = '' + try: + # step1. delete owned tenant info + if owned_tenant: + done_msg += "Start to delete owned tenant.\n" + tenant_id = owned_tenant[0]["tenant_id"] + kb_ids = KnowledgebaseService.get_kb_ids(usr.id) + # step1.1 delete knowledgebase related file and info + if kb_ids: + # step1.1.1 delete files in storage, remove bucket + for kb_id in kb_ids: + if settings.STORAGE_IMPL.bucket_exists(kb_id): + settings.STORAGE_IMPL.remove_bucket(kb_id) + done_msg += f"- Removed {len(kb_ids)} dataset's buckets.\n" + # step1.1.2 delete file and document info in db + doc_ids = DocumentService.get_all_doc_ids_by_kb_ids(kb_ids) + if doc_ids: + doc_delete_res = DocumentService.delete_by_ids([i["id"] for i in doc_ids]) + done_msg += f"- Deleted {doc_delete_res} document records.\n" + task_delete_res = TaskService.delete_by_doc_ids([i["id"] for i in doc_ids]) + done_msg += f"- Deleted {task_delete_res} task records.\n" + file_ids = FileService.get_all_file_ids_by_tenant_id(usr.id) + if file_ids: + file_delete_res = FileService.delete_by_ids([f["id"] for f in file_ids]) + done_msg += f"- Deleted {file_delete_res} file records.\n" + if doc_ids or file_ids: + file2doc_delete_res = File2DocumentService.delete_by_document_ids_or_file_ids( + [i["id"] for i in doc_ids], + [f["id"] for f in file_ids] + ) + done_msg += f"- Deleted {file2doc_delete_res} document-file relation records.\n" + # step1.1.3 delete chunk in es + r = settings.docStoreConn.delete({"kb_id": kb_ids}, + search.index_name(tenant_id), kb_ids) + done_msg += f"- Deleted {r} chunk records.\n" + kb_delete_res = KnowledgebaseService.delete_by_ids(kb_ids) + done_msg += f"- Deleted {kb_delete_res} knowledgebase records.\n" + # step1.1.4 delete agents + agent_delete_res = delete_user_agents(usr.id) + done_msg += f"- Deleted {agent_delete_res['agents_deleted_count']} agent, {agent_delete_res['version_deleted_count']} versions records.\n" + # step1.1.5 delete dialogs + dialog_delete_res = delete_user_dialogs(usr.id) + done_msg += f"- Deleted {dialog_delete_res['dialogs_deleted_count']} dialogs, {dialog_delete_res['conversations_deleted_count']} conversations, {dialog_delete_res['api_token_deleted_count']} api tokens, {dialog_delete_res['api4conversation_deleted_count']} api4conversations.\n" + # step1.1.6 delete mcp server + mcp_delete_res = MCPServerService.delete_by_tenant_id(usr.id) + done_msg += f"- Deleted {mcp_delete_res} MCP server.\n" + # step1.1.7 delete search + search_delete_res = SearchService.delete_by_tenant_id(usr.id) + done_msg += f"- Deleted {search_delete_res} search records.\n" + # step1.2 delete tenant_llm and tenant_langfuse + llm_delete_res = TenantLLMService.delete_by_tenant_id(tenant_id) + done_msg += f"- Deleted {llm_delete_res} tenant-LLM records.\n" + langfuse_delete_res = TenantLangfuseService.delete_ty_tenant_id(tenant_id) + done_msg += f"- Deleted {langfuse_delete_res} langfuse records.\n" + # step1.3 delete own tenant + tenant_delete_res = TenantService.delete_by_id(tenant_id) + done_msg += f"- Deleted {tenant_delete_res} tenant.\n" + # step2 delete user-tenant relation + if tenants: + # step2.1 delete docs and files in joined team + joined_tenants = [t for t in tenants if t["role"] == UserTenantRole.NORMAL.value] + if joined_tenants: + done_msg += "Start to delete data in joined tenants.\n" + created_documents = DocumentService.get_all_docs_by_creator_id(usr.id) + if created_documents: + # step2.1.1 delete files + doc_file_info = File2DocumentService.get_by_document_ids([d['id'] for d in created_documents]) + created_files = FileService.get_by_ids([f['file_id'] for f in doc_file_info]) + if created_files: + # step2.1.1.1 delete file in storage + for f in created_files: + settings.STORAGE_IMPL.rm(f.parent_id, f.location) + done_msg += f"- Deleted {len(created_files)} uploaded file.\n" + # step2.1.1.2 delete file record + file_delete_res = FileService.delete_by_ids([f.id for f in created_files]) + done_msg += f"- Deleted {file_delete_res} file records.\n" + # step2.1.2 delete document-file relation record + file2doc_delete_res = File2DocumentService.delete_by_document_ids_or_file_ids( + [d['id'] for d in created_documents], + [f.id for f in created_files] + ) + done_msg += f"- Deleted {file2doc_delete_res} document-file relation records.\n" + # step2.1.3 delete chunks + doc_groups = group_by(created_documents, "tenant_id") + kb_grouped_doc = {k: group_by(v, "kb_id") for k, v in doc_groups.items()} + # chunks in {'tenant_id': {'kb_id': [{'id': doc_id}]}} structure + chunk_delete_res = 0 + kb_doc_info = {} + for _tenant_id, kb_doc in kb_grouped_doc.items(): + for _kb_id, docs in kb_doc.items(): + chunk_delete_res += settings.docStoreConn.delete( + {"doc_id": [d["id"] for d in docs]}, + search.index_name(_tenant_id), _kb_id + ) + # record doc info + if _kb_id in kb_doc_info.keys(): + kb_doc_info[_kb_id]['doc_num'] += 1 + kb_doc_info[_kb_id]['token_num'] += sum([d["token_num"] for d in docs]) + kb_doc_info[_kb_id]['chunk_num'] += sum([d["chunk_num"] for d in docs]) + else: + kb_doc_info[_kb_id] = { + 'doc_num': 1, + 'token_num': sum([d["token_num"] for d in docs]), + 'chunk_num': sum([d["chunk_num"] for d in docs]) + } + done_msg += f"- Deleted {chunk_delete_res} chunks.\n" + # step2.1.4 delete tasks + task_delete_res = TaskService.delete_by_doc_ids([d['id'] for d in created_documents]) + done_msg += f"- Deleted {task_delete_res} tasks.\n" + # step2.1.5 delete document record + doc_delete_res = DocumentService.delete_by_ids([d['id'] for d in created_documents]) + done_msg += f"- Deleted {doc_delete_res} documents.\n" + # step2.1.6 update knowledge base doc&chunk&token cnt + for kb_id, doc_num in kb_doc_info.items(): + KnowledgebaseService.decrease_document_num_in_delete(kb_id, doc_num) + + # step2.2 delete relation + user_tenant_delete_res = UserTenantService.delete_by_ids([t["id"] for t in tenants]) + done_msg += f"- Deleted {user_tenant_delete_res} user-tenant records.\n" + # step3 finally delete user + user_delete_res = UserService.delete_by_id(usr.id) + done_msg += f"- Deleted {user_delete_res} user.\nDelete done!" + + return {"success": True, "message": f"Successfully deleted user. Details:\n{done_msg}"} + + except Exception as e: + logging.exception(e) + return {"success": False, "message": f"Error: {str(e)}. Already done:\n{done_msg}"} + + +def delete_user_agents(user_id: str) -> dict: + """ + use user_id to delete + :return: { + "agents_deleted_count": 1, + "version_deleted_count": 2 + } + """ + agents_deleted_count, agents_version_deleted_count = 0, 0 + user_agents = UserCanvasService.get_all_agents_by_tenant_ids([user_id], user_id) + if user_agents: + agents_version = UserCanvasVersionService.get_all_canvas_version_by_canvas_ids([a['id'] for a in user_agents]) + agents_version_deleted_count = UserCanvasVersionService.delete_by_ids([v['id'] for v in agents_version]) + agents_deleted_count = UserCanvasService.delete_by_ids([a['id'] for a in user_agents]) + return { + "agents_deleted_count": agents_deleted_count, + "version_deleted_count": agents_version_deleted_count + } + + +def delete_user_dialogs(user_id: str) -> dict: + """ + use user_id to delete + :return: { + "dialogs_deleted_count": 1, + "conversations_deleted_count": 1, + "api_token_deleted_count": 2, + "api4conversation_deleted_count": 2 + } + """ + dialog_deleted_count, conversations_deleted_count, api_token_deleted_count, api4conversation_deleted_count = 0, 0, 0, 0 + user_dialogs = DialogService.get_all_dialogs_by_tenant_id(user_id) + if user_dialogs: + # delete conversation + conversations = ConversationService.get_all_conversation_by_dialog_ids([ud['id'] for ud in user_dialogs]) + conversations_deleted_count = ConversationService.delete_by_ids([c['id'] for c in conversations]) + # delete api token + api_token_deleted_count = APITokenService.delete_by_tenant_id(user_id) + # delete api for conversation + api4conversation_deleted_count = API4ConversationService.delete_by_dialog_ids([ud['id'] for ud in user_dialogs]) + # delete dialog at last + dialog_deleted_count = DialogService.delete_by_ids([ud['id'] for ud in user_dialogs]) + return { + "dialogs_deleted_count": dialog_deleted_count, + "conversations_deleted_count": conversations_deleted_count, + "api_token_deleted_count": api_token_deleted_count, + "api4conversation_deleted_count": api4conversation_deleted_count + } diff --git a/api/db/runtime_config.py b/api/db/runtime_config.py index e3e0fb7874d..a3d7680bc48 100644 --- a/api/db/runtime_config.py +++ b/api/db/runtime_config.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from api.versions import get_ragflow_version +from common.versions import get_ragflow_version from .reload_config_base import ReloadConfigBase diff --git a/api/db/services/__init__.py b/api/db/services/__init__.py index 4b3af3ecfb4..ce937911fb4 100644 --- a/api/db/services/__init__.py +++ b/api/db/services/__init__.py @@ -19,7 +19,7 @@ from .user_service import UserService as UserService -def split_name_counter(filename: str) -> tuple[str, int | None]: +def _split_name_counter(filename: str) -> tuple[str, int | None]: """ Splits a filename into main part and counter (if present in parentheses). @@ -87,7 +87,7 @@ def duplicate_name(query_func, **kwargs) -> str: stem = path.stem suffix = path.suffix - main_part, counter = split_name_counter(stem) + main_part, counter = _split_name_counter(stem) counter = counter + 1 if counter else 1 new_name = f"{main_part}({counter}){suffix}" diff --git a/api/db/services/api_service.py b/api/db/services/api_service.py index b393812e973..aee35422b7f 100644 --- a/api/db/services/api_service.py +++ b/api/db/services/api_service.py @@ -19,7 +19,7 @@ from api.db.db_models import DB, API4Conversation, APIToken, Dialog from api.db.services.common_service import CommonService -from api.utils import current_timestamp, datetime_format +from common.time_utils import current_timestamp, datetime_format class APITokenService(CommonService): @@ -35,6 +35,11 @@ def used(cls, token): cls.model.token == token ) + @classmethod + @DB.connection_context() + def delete_by_tenant_id(cls, tenant_id): + return cls.model.delete().where(cls.model.tenant_id == tenant_id).execute() + class API4ConversationService(CommonService): model = API4Conversation @@ -43,7 +48,9 @@ class API4ConversationService(CommonService): @DB.connection_context() def get_list(cls, dialog_id, tenant_id, page_number, items_per_page, - orderby, desc, id, user_id=None, include_dsl=True): + orderby, desc, id, user_id=None, include_dsl=True, keywords="", + from_date=None, to_date=None + ): if include_dsl: sessions = cls.model.select().where(cls.model.dialog_id == dialog_id) else: @@ -53,13 +60,20 @@ def get_list(cls, dialog_id, tenant_id, sessions = sessions.where(cls.model.id == id) if user_id: sessions = sessions.where(cls.model.user_id == user_id) + if keywords: + sessions = sessions.where(peewee.fn.LOWER(cls.model.message).contains(keywords.lower())) + if from_date: + sessions = sessions.where(cls.model.create_date >= from_date) + if to_date: + sessions = sessions.where(cls.model.create_date <= to_date) if desc: sessions = sessions.order_by(cls.model.getter_by(orderby).desc()) else: sessions = sessions.order_by(cls.model.getter_by(orderby).asc()) + count = sessions.count() sessions = sessions.paginate(page_number, items_per_page) - return list(sessions.dicts()) + return count, list(sessions.dicts()) @classmethod @DB.connection_context() @@ -91,3 +105,8 @@ def stats(cls, tenant_id, from_date, to_date, source=None): cls.model.create_date <= to_date, cls.model.source == source ).group_by(cls.model.create_date.truncate("day")).dicts() + + @classmethod + @DB.connection_context() + def delete_by_dialog_ids(cls, dialog_ids): + return cls.model.delete().where(cls.model.dialog_id.in_(dialog_ids)).execute() diff --git a/api/db/services/canvas_service.py b/api/db/services/canvas_service.py index 8bcb7b1bc47..5a0f82c2b00 100644 --- a/api/db/services/canvas_service.py +++ b/api/db/services/canvas_service.py @@ -14,22 +14,29 @@ # limitations under the License. # import json +import logging import time -import traceback from uuid import uuid4 from agent.canvas import Canvas -from api.db import TenantPermission +from api.db import CanvasCategory, TenantPermission from api.db.db_models import DB, CanvasTemplate, User, UserCanvas, API4Conversation from api.db.services.api_service import API4ConversationService from api.db.services.common_service import CommonService -from api.db.services.conversation_service import structure_answer -from api.utils import get_uuid +from common.misc_utils import get_uuid from api.utils.api_utils import get_data_openai import tiktoken from peewee import fn + + class CanvasTemplateService(CommonService): model = CanvasTemplate +class DataFlowTemplateService(CommonService): + """ + Alias of CanvasTemplateService + """ + model = CanvasTemplate + class UserCanvasService(CommonService): model = UserCanvas @@ -37,13 +44,14 @@ class UserCanvasService(CommonService): @classmethod @DB.connection_context() def get_list(cls, tenant_id, - page_number, items_per_page, orderby, desc, id, title): + page_number, items_per_page, orderby, desc, id, title, canvas_category=CanvasCategory.Agent): agents = cls.model.select() if id: agents = agents.where(cls.model.id == id) if title: agents = agents.where(cls.model.title == title) agents = agents.where(cls.model.user_id == tenant_id) + agents = agents.where(cls.model.canvas_category == canvas_category) if desc: agents = agents.order_by(cls.model.getter_by(orderby).desc()) else: @@ -52,12 +60,44 @@ def get_list(cls, tenant_id, agents = agents.paginate(page_number, items_per_page) return list(agents.dicts()) - + @classmethod @DB.connection_context() - def get_by_tenant_id(cls, pid): + def get_all_agents_by_tenant_ids(cls, tenant_ids, user_id): + # will get all permitted agents, be cautious + fields = [ + cls.model.id, + cls.model.avatar, + cls.model.title, + cls.model.permission, + cls.model.canvas_type, + cls.model.canvas_category + ] + # find team agents and owned agents + agents = cls.model.select(*fields).where( + (cls.model.user_id.in_(tenant_ids) & (cls.model.permission == TenantPermission.TEAM.value)) | ( + cls.model.user_id == user_id + ) + ) + # sort by create_time, asc + agents.order_by(cls.model.create_time.asc()) + # maybe cause slow query by deep paginate, optimize later + offset, limit = 0, 50 + res = [] + while True: + ag_batch = agents.offset(offset).limit(limit) + _temp = list(ag_batch.dicts()) + if not _temp: + break + res.extend(_temp) + offset += limit + return res + + @classmethod + @DB.connection_context() + def get_by_canvas_id(cls, pid): try: - + fields = [ cls.model.id, cls.model.avatar, @@ -70,6 +110,7 @@ def get_by_tenant_id(cls, pid): cls.model.create_time, cls.model.create_date, cls.model.update_date, + cls.model.canvas_category, User.nickname, User.avatar.alias('tenant_avatar'), ] @@ -79,14 +120,14 @@ def get_by_tenant_id(cls, pid): # obj = cls.model.query(id=pid)[0] return True, agents.dicts()[0] except Exception as e: - print(e) + logging.exception(e) return False, None - + @classmethod @DB.connection_context() def get_by_tenant_ids(cls, joined_tenant_ids, user_id, page_number, items_per_page, - orderby, desc, keywords, + orderby, desc, keywords, canvas_category=None ): fields = [ cls.model.id, @@ -95,358 +136,213 @@ def get_by_tenant_ids(cls, joined_tenant_ids, user_id, cls.model.dsl, cls.model.description, cls.model.permission, + cls.model.user_id.alias("tenant_id"), User.nickname, User.avatar.alias('tenant_avatar'), - cls.model.update_time + cls.model.update_time, + cls.model.canvas_category, ] if keywords: agents = cls.model.select(*fields).join(User, on=(cls.model.user_id == User.id)).where( - ((cls.model.user_id.in_(joined_tenant_ids) & (cls.model.permission == - TenantPermission.TEAM.value)) | ( - cls.model.user_id == user_id)), + (((cls.model.user_id.in_(joined_tenant_ids)) & (cls.model.permission == TenantPermission.TEAM.value)) | (cls.model.user_id == user_id)), (fn.LOWER(cls.model.title).contains(keywords.lower())) ) else: agents = cls.model.select(*fields).join(User, on=(cls.model.user_id == User.id)).where( - ((cls.model.user_id.in_(joined_tenant_ids) & (cls.model.permission == - TenantPermission.TEAM.value)) | ( - cls.model.user_id == user_id)) + (((cls.model.user_id.in_(joined_tenant_ids)) & (cls.model.permission == TenantPermission.TEAM.value)) | (cls.model.user_id == user_id)) ) + if canvas_category: + agents = agents.where(cls.model.canvas_category == canvas_category) if desc: agents = agents.order_by(cls.model.getter_by(orderby).desc()) else: agents = agents.order_by(cls.model.getter_by(orderby).asc()) + count = agents.count() - agents = agents.paginate(page_number, items_per_page) + if page_number and items_per_page: + agents = agents.paginate(page_number, items_per_page) return list(agents.dicts()), count - - -def completion(tenant_id, agent_id, question, session_id=None, stream=True, **kwargs): - e, cvs = UserCanvasService.get_by_id(agent_id) - assert e, "Agent not found." - assert cvs.user_id == tenant_id, "You do not own the agent." - if not isinstance(cvs.dsl,str): - cvs.dsl = json.dumps(cvs.dsl, ensure_ascii=False) - canvas = Canvas(cvs.dsl, tenant_id) - canvas.reset() - message_id = str(uuid4()) - if not session_id: - query = canvas.get_preset_param() - if query: - for ele in query: - if not ele["optional"]: - if not kwargs.get(ele["key"]): - assert False, f"`{ele['key']}` is required" - ele["value"] = kwargs[ele["key"]] - if ele["optional"]: - if kwargs.get(ele["key"]): - ele["value"] = kwargs[ele['key']] - else: - if "value" in ele: - ele.pop("value") - cvs.dsl = json.loads(str(canvas)) - session_id=get_uuid() - conv = { - "id": session_id, - "dialog_id": cvs.id, - "user_id": kwargs.get("user_id", "") if isinstance(kwargs, dict) else "", - "message": [{"role": "assistant", "content": canvas.get_prologue(), "created_at": time.time()}], - "source": "agent", - "dsl": cvs.dsl - } - API4ConversationService.save(**conv) - conv = API4Conversation(**conv) - else: + + @classmethod + @DB.connection_context() + def accessible(cls, canvas_id, tenant_id): + from api.db.services.user_service import UserTenantService + e, c = UserCanvasService.get_by_canvas_id(canvas_id) + if not e: + return False + + tids = [t.tenant_id for t in UserTenantService.query(user_id=tenant_id)] + if c["user_id"] != canvas_id and c["user_id"] not in tids: + return False + return True + + +def completion(tenant_id, agent_id, session_id=None, **kwargs): + query = kwargs.get("query", "") or kwargs.get("question", "") + files = kwargs.get("files", []) + inputs = kwargs.get("inputs", {}) + user_id = kwargs.get("user_id", "") + + if session_id: e, conv = API4ConversationService.get_by_id(session_id) assert e, "Session not found!" - canvas = Canvas(json.dumps(conv.dsl), tenant_id) - canvas.messages.append({"role": "user", "content": question, "id": message_id}) - canvas.add_user_input(question) if not conv.message: conv.message = [] - conv.message.append({ - "role": "user", - "content": question, - "id": message_id - }) - if not conv.reference: - conv.reference = [] - conv.reference.append({"chunks": [], "doc_aggs": []}) - - kwargs_changed = False - if kwargs: - query = canvas.get_preset_param() - if query: - for ele in query: - if ele["key"] in kwargs: - if ele["value"] != kwargs[ele["key"]]: - ele["value"] = kwargs[ele["key"]] - kwargs_changed = True - if kwargs_changed: - conv.dsl = json.loads(str(canvas)) - API4ConversationService.update_by_id(session_id, {"dsl": conv.dsl}) - - final_ans = {"reference": [], "content": ""} - if stream: - try: - for ans in canvas.run(stream=stream): - if ans.get("running_status"): - yield "data:" + json.dumps({"code": 0, "message": "", - "data": {"answer": ans["content"], - "running_status": True}}, - ensure_ascii=False) + "\n\n" - continue - for k in ans.keys(): - final_ans[k] = ans[k] - ans = {"answer": ans["content"], "reference": ans.get("reference", []), "param": canvas.get_preset_param()} - ans = structure_answer(conv, ans, message_id, session_id) - yield "data:" + json.dumps({"code": 0, "message": "", "data": ans}, - ensure_ascii=False) + "\n\n" - - canvas.messages.append({"role": "assistant", "content": final_ans["content"], "created_at": time.time(), "id": message_id}) - canvas.history.append(("assistant", final_ans["content"])) - if final_ans.get("reference"): - canvas.reference.append(final_ans["reference"]) - conv.dsl = json.loads(str(canvas)) - API4ConversationService.append_message(conv.id, conv.to_dict()) - except Exception as e: - traceback.print_exc() - conv.dsl = json.loads(str(canvas)) - API4ConversationService.append_message(conv.id, conv.to_dict()) - yield "data:" + json.dumps({"code": 500, "message": str(e), - "data": {"answer": "**ERROR**: " + str(e), "reference": []}}, - ensure_ascii=False) + "\n\n" - yield "data:" + json.dumps({"code": 0, "message": "", "data": True}, ensure_ascii=False) + "\n\n" - + if not isinstance(conv.dsl, str): + conv.dsl = json.dumps(conv.dsl, ensure_ascii=False) + canvas = Canvas(conv.dsl, tenant_id, agent_id) else: - for answer in canvas.run(stream=False): - if answer.get("running_status"): - continue - final_ans["content"] = "\n".join(answer["content"]) if "content" in answer else "" - canvas.messages.append({"role": "assistant", "content": final_ans["content"], "id": message_id}) - if final_ans.get("reference"): - canvas.reference.append(final_ans["reference"]) - conv.dsl = json.loads(str(canvas)) - - result = {"answer": final_ans["content"], "reference": final_ans.get("reference", []) , "param": canvas.get_preset_param()} - result = structure_answer(conv, result, message_id, session_id) - API4ConversationService.append_message(conv.id, conv.to_dict()) - yield result - break -def completionOpenAI(tenant_id, agent_id, question, session_id=None, stream=True, **kwargs): - """Main function for OpenAI-compatible completions, structured similarly to the completion function.""" - tiktokenenc = tiktoken.get_encoding("cl100k_base") - e, cvs = UserCanvasService.get_by_id(agent_id) - - if not e: - yield get_data_openai( - id=session_id, - model=agent_id, - content="**ERROR**: Agent not found." - ) - return - - if cvs.user_id != tenant_id: - yield get_data_openai( - id=session_id, - model=agent_id, - content="**ERROR**: You do not own the agent" - ) - return - - if not isinstance(cvs.dsl, str): - cvs.dsl = json.dumps(cvs.dsl, ensure_ascii=False) - - canvas = Canvas(cvs.dsl, tenant_id) - canvas.reset() - message_id = str(uuid4()) - - # Handle new session creation - if not session_id: - query = canvas.get_preset_param() - if query: - for ele in query: - if not ele["optional"]: - if not kwargs.get(ele["key"]): - yield get_data_openai( - id=None, - model=agent_id, - content=f"`{ele['key']}` is required", - completion_tokens=len(tiktokenenc.encode(f"`{ele['key']}` is required")), - prompt_tokens=len(tiktokenenc.encode(question if question else "")) - ) - return - ele["value"] = kwargs[ele["key"]] - if ele["optional"]: - if kwargs.get(ele["key"]): - ele["value"] = kwargs[ele['key']] - else: - if "value" in ele: - ele.pop("value") - - cvs.dsl = json.loads(str(canvas)) - session_id = get_uuid() + e, cvs = UserCanvasService.get_by_id(agent_id) + assert e, "Agent not found." + assert cvs.user_id == tenant_id, "You do not own the agent." + if not isinstance(cvs.dsl, str): + cvs.dsl = json.dumps(cvs.dsl, ensure_ascii=False) + session_id=get_uuid() + canvas = Canvas(cvs.dsl, tenant_id, agent_id) + canvas.reset() conv = { "id": session_id, "dialog_id": cvs.id, - "user_id": kwargs.get("user_id", "") if isinstance(kwargs, dict) else "", - "message": [{"role": "assistant", "content": canvas.get_prologue(), "created_at": time.time()}], + "user_id": user_id, + "message": [], "source": "agent", - "dsl": cvs.dsl + "dsl": cvs.dsl, + "reference": [] } - canvas.messages.append({"role": "user", "content": question, "id": message_id}) - canvas.add_user_input(question) - API4ConversationService.save(**conv) conv = API4Conversation(**conv) - if not conv.message: - conv.message = [] - conv.message.append({ - "role": "user", - "content": question, - "id": message_id - }) - - if not conv.reference: - conv.reference = [] - conv.reference.append({"chunks": [], "doc_aggs": []}) - - # Handle existing session - else: - e, conv = API4ConversationService.get_by_id(session_id) - if not e: - yield get_data_openai( - id=session_id, - model=agent_id, - content="**ERROR**: Session not found!" - ) - return - - canvas = Canvas(json.dumps(conv.dsl), tenant_id) - canvas.messages.append({"role": "user", "content": question, "id": message_id}) - canvas.add_user_input(question) - - if not conv.message: - conv.message = [] - conv.message.append({ - "role": "user", - "content": question, - "id": message_id - }) - - if not conv.reference: - conv.reference = [] - conv.reference.append({"chunks": [], "doc_aggs": []}) - - # Process request based on stream mode - final_ans = {"reference": [], "content": ""} - prompt_tokens = len(tiktokenenc.encode(str(question))) - + + message_id = str(uuid4()) + conv.message.append({ + "role": "user", + "content": query, + "id": message_id + }) + txt = "" + for ans in canvas.run(query=query, files=files, user_id=user_id, inputs=inputs): + ans["session_id"] = session_id + if ans["event"] == "message": + txt += ans["data"]["content"] + yield "data:" + json.dumps(ans, ensure_ascii=False) + "\n\n" + + conv.message.append({"role": "assistant", "content": txt, "created_at": time.time(), "id": message_id}) + conv.reference = canvas.get_reference() + conv.errors = canvas.error + conv.dsl = str(canvas) + conv = conv.to_dict() + API4ConversationService.append_message(conv["id"], conv) + + +def completion_openai(tenant_id, agent_id, question, session_id=None, stream=True, **kwargs): + tiktoken_encoder = tiktoken.get_encoding("cl100k_base") + prompt_tokens = len(tiktoken_encoder.encode(str(question))) + user_id = kwargs.get("user_id", "") + if stream: + completion_tokens = 0 try: - completion_tokens = 0 - for ans in canvas.run(stream=True, bypass_begin=True): - if ans.get("running_status"): - completion_tokens += len(tiktokenenc.encode(ans.get("content", ""))) - yield "data: " + json.dumps( - get_data_openai( - id=session_id, - model=agent_id, - content=ans["content"], - object="chat.completion.chunk", - completion_tokens=completion_tokens, - prompt_tokens=prompt_tokens - ), - ensure_ascii=False - ) + "\n\n" + for ans in completion( + tenant_id=tenant_id, + agent_id=agent_id, + session_id=session_id, + query=question, + user_id=user_id, + **kwargs + ): + if isinstance(ans, str): + try: + ans = json.loads(ans[5:]) # remove "data:" + except Exception as e: + logging.exception(f"Agent OpenAI-Compatible completion_openai parse answer failed: {e}") + continue + if ans.get("event") not in ["message", "message_end"]: continue - - for k in ans.keys(): - final_ans[k] = ans[k] - - completion_tokens += len(tiktokenenc.encode(final_ans.get("content", ""))) - yield "data: " + json.dumps( - get_data_openai( - id=session_id, + + content_piece = "" + if ans["event"] == "message": + content_piece = ans["data"]["content"] + + completion_tokens += len(tiktoken_encoder.encode(content_piece)) + + openai_data = get_data_openai( + id=session_id or str(uuid4()), model=agent_id, - content=final_ans["content"], - object="chat.completion.chunk", - finish_reason="stop", + content=content_piece, + prompt_tokens=prompt_tokens, completion_tokens=completion_tokens, - prompt_tokens=prompt_tokens - ), - ensure_ascii=False - ) + "\n\n" - - # Update conversation - canvas.messages.append({"role": "assistant", "content": final_ans["content"], "created_at": time.time(), "id": message_id}) - canvas.history.append(("assistant", final_ans["content"])) - if final_ans.get("reference"): - canvas.reference.append(final_ans["reference"]) - conv.dsl = json.loads(str(canvas)) - API4ConversationService.append_message(conv.id, conv.to_dict()) - + stream=True + ) + + if ans.get("data", {}).get("reference", None): + openai_data["choices"][0]["delta"]["reference"] = ans["data"]["reference"] + + yield "data: " + json.dumps(openai_data, ensure_ascii=False) + "\n\n" + yield "data: [DONE]\n\n" - + except Exception as e: - traceback.print_exc() - conv.dsl = json.loads(str(canvas)) - API4ConversationService.append_message(conv.id, conv.to_dict()) + logging.exception(e) yield "data: " + json.dumps( get_data_openai( - id=session_id, + id=session_id or str(uuid4()), model=agent_id, - content="**ERROR**: " + str(e), + content=f"**ERROR**: {str(e)}", finish_reason="stop", - completion_tokens=len(tiktokenenc.encode("**ERROR**: " + str(e))), - prompt_tokens=prompt_tokens + prompt_tokens=prompt_tokens, + completion_tokens=len(tiktoken_encoder.encode(f"**ERROR**: {str(e)}")), + stream=True ), ensure_ascii=False ) + "\n\n" yield "data: [DONE]\n\n" - - else: # Non-streaming mode + + else: try: - all_answer_content = "" - for answer in canvas.run(stream=False, bypass_begin=True): - if answer.get("running_status"): + all_content = "" + reference = {} + for ans in completion( + tenant_id=tenant_id, + agent_id=agent_id, + session_id=session_id, + query=question, + user_id=user_id, + **kwargs + ): + if isinstance(ans, str): + ans = json.loads(ans[5:]) + if ans.get("event") not in ["message", "message_end"]: continue - - final_ans["content"] = "\n".join(answer["content"]) if "content" in answer else "" - final_ans["reference"] = answer.get("reference", []) - all_answer_content += final_ans["content"] - - final_ans["content"] = all_answer_content - - # Update conversation - canvas.messages.append({"role": "assistant", "content": final_ans["content"], "created_at": time.time(), "id": message_id}) - canvas.history.append(("assistant", final_ans["content"])) - if final_ans.get("reference"): - canvas.reference.append(final_ans["reference"]) - conv.dsl = json.loads(str(canvas)) - API4ConversationService.append_message(conv.id, conv.to_dict()) - - # Return the response in OpenAI format - yield get_data_openai( - id=session_id, + + if ans["event"] == "message": + all_content += ans["data"]["content"] + + if ans.get("data", {}).get("reference", None): + reference.update(ans["data"]["reference"]) + + completion_tokens = len(tiktoken_encoder.encode(all_content)) + + openai_data = get_data_openai( + id=session_id or str(uuid4()), model=agent_id, - content=final_ans["content"], - finish_reason="stop", - completion_tokens=len(tiktokenenc.encode(final_ans["content"])), prompt_tokens=prompt_tokens, - param=canvas.get_preset_param() # Added param info like in completion + completion_tokens=completion_tokens, + content=all_content, + finish_reason="stop", + param=None ) - + + if reference: + openai_data["choices"][0]["message"]["reference"] = reference + + yield openai_data except Exception as e: - traceback.print_exc() - conv.dsl = json.loads(str(canvas)) - API4ConversationService.append_message(conv.id, conv.to_dict()) + logging.exception(e) yield get_data_openai( - id=session_id, + id=session_id or str(uuid4()), model=agent_id, - content="**ERROR**: " + str(e), + prompt_tokens=prompt_tokens, + completion_tokens=len(tiktoken_encoder.encode(f"**ERROR**: {str(e)}")), + content=f"**ERROR**: {str(e)}", finish_reason="stop", - completion_tokens=len(tiktokenenc.encode("**ERROR**: " + str(e))), - prompt_tokens=prompt_tokens + param=None ) - diff --git a/api/db/services/common_service.py b/api/db/services/common_service.py index 7645b43d4e4..5b906b5a861 100644 --- a/api/db/services/common_service.py +++ b/api/db/services/common_service.py @@ -14,12 +14,25 @@ # limitations under the License. # from datetime import datetime - +from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type import peewee +from peewee import InterfaceError, OperationalError from api.db.db_models import DB -from api.utils import current_timestamp, datetime_format, get_uuid - +from common.misc_utils import get_uuid +from common.time_utils import current_timestamp, datetime_format + +def retry_db_operation(func): + @retry( + stop=stop_after_attempt(3), + wait=wait_exponential(multiplier=1, min=1, max=5), + retry=retry_if_exception_type((InterfaceError, OperationalError)), + before_sleep=lambda retry_state: print(f"RETRY {retry_state.attempt_number} TIMES"), + reraise=True, + ) + def wrapper(*args, **kwargs): + return func(*args, **kwargs) + return wrapper class CommonService: """Base service class that provides common database operations. @@ -77,7 +90,7 @@ def get_all(cls, cols=None, reverse=None, order_by=None): else: query_records = cls.model.select() if reverse is not None: - if not order_by or not hasattr(cls, order_by): + if not order_by or not hasattr(cls.model, order_by): order_by = "create_time" if reverse is True: query_records = query_records.order_by(cls.model.getter_by(order_by).desc()) @@ -202,6 +215,7 @@ def update_many_by_id(cls, data_list): @classmethod @DB.connection_context() + @retry_db_operation def update_by_id(cls, pid, data): # Update a single record by ID # Args: diff --git a/api/db/services/connector_service.py b/api/db/services/connector_service.py new file mode 100644 index 00000000000..2ff16669d3a --- /dev/null +++ b/api/db/services/connector_service.py @@ -0,0 +1,283 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +from datetime import datetime +from typing import Tuple, List + +from anthropic import BaseModel +from peewee import SQL, fn + +from api.db import InputType +from api.db.db_models import Connector, SyncLogs, Connector2Kb, Knowledgebase +from api.db.services.common_service import CommonService +from api.db.services.document_service import DocumentService +from api.db.services.file_service import FileService +from common.misc_utils import get_uuid +from common.constants import TaskStatus +from common.time_utils import current_timestamp, timestamp_to_date + + +class ConnectorService(CommonService): + model = Connector + + @classmethod + def resume(cls, connector_id, status): + for c2k in Connector2KbService.query(connector_id=connector_id): + task = SyncLogsService.get_latest_task(connector_id, c2k.kb_id) + if not task: + if status == TaskStatus.SCHEDULE: + SyncLogsService.schedule(connector_id, c2k.kb_id) + ConnectorService.update_by_id(connector_id, {"status": status}) + return + + if task.status == TaskStatus.DONE: + if status == TaskStatus.SCHEDULE: + SyncLogsService.schedule(connector_id, c2k.kb_id, task.poll_range_end, total_docs_indexed=task.total_docs_indexed) + ConnectorService.update_by_id(connector_id, {"status": status}) + return + + task = task.to_dict() + task["status"] = status + SyncLogsService.update_by_id(task["id"], task) + ConnectorService.update_by_id(connector_id, {"status": status}) + + @classmethod + def list(cls, tenant_id): + fields = [ + cls.model.id, + cls.model.name, + cls.model.source, + cls.model.status + ] + return list(cls.model.select(*fields).where( + cls.model.tenant_id == tenant_id + ).dicts()) + + @classmethod + def rebuild(cls, kb_id:str, connector_id: str, tenant_id:str): + e, conn = cls.get_by_id(connector_id) + if not e: + return + SyncLogsService.filter_delete([SyncLogs.connector_id==connector_id, SyncLogs.kb_id==kb_id]) + docs = DocumentService.query(source_type=f"{conn.source}/{conn.id}", kb_id=kb_id) + err = FileService.delete_docs([d.id for d in docs], tenant_id) + SyncLogsService.schedule(connector_id, kb_id, reindex=True) + return err + + +class SyncLogsService(CommonService): + model = SyncLogs + + @classmethod + def list_sync_tasks(cls, connector_id=None, page_number=None, items_per_page=15) -> Tuple[List[dict], int]: + fields = [ + cls.model.id, + cls.model.connector_id, + cls.model.kb_id, + cls.model.update_date, + cls.model.poll_range_start, + cls.model.poll_range_end, + cls.model.new_docs_indexed, + cls.model.total_docs_indexed, + cls.model.error_msg, + cls.model.full_exception_trace, + cls.model.error_count, + Connector.name, + Connector.source, + Connector.tenant_id, + Connector.timeout_secs, + Knowledgebase.name.alias("kb_name"), + Knowledgebase.avatar.alias("kb_avatar"), + Connector2Kb.auto_parse, + cls.model.from_beginning.alias("reindex"), + cls.model.status + ] + if not connector_id: + fields.append(Connector.config) + + query = cls.model.select(*fields)\ + .join(Connector, on=(cls.model.connector_id==Connector.id))\ + .join(Connector2Kb, on=(cls.model.kb_id==Connector2Kb.kb_id))\ + .join(Knowledgebase, on=(cls.model.kb_id==Knowledgebase.id)) + + if connector_id: + query = query.where(cls.model.connector_id == connector_id) + else: + interval_expr = SQL("INTERVAL `t2`.`refresh_freq` MINUTE") + query = query.where( + Connector.input_type == InputType.POLL, + Connector.status == TaskStatus.SCHEDULE, + cls.model.status == TaskStatus.SCHEDULE, + cls.model.update_date < (fn.NOW() - interval_expr) + ) + + query = query.distinct().order_by(cls.model.update_time.desc()) + totbal = query.count() + if page_number: + query = query.paginate(page_number, items_per_page) + + return list(query.dicts()), totbal + + @classmethod + def start(cls, id, connector_id): + cls.update_by_id(id, {"status": TaskStatus.RUNNING, "time_started": datetime.now().strftime('%Y-%m-%d %H:%M:%S') }) + ConnectorService.update_by_id(connector_id, {"status": TaskStatus.RUNNING}) + + @classmethod + def done(cls, id, connector_id): + cls.update_by_id(id, {"status": TaskStatus.DONE}) + ConnectorService.update_by_id(connector_id, {"status": TaskStatus.DONE}) + + @classmethod + def schedule(cls, connector_id, kb_id, poll_range_start=None, reindex=False, total_docs_indexed=0): + try: + if cls.model.select().where(cls.model.kb_id == kb_id, cls.model.connector_id == connector_id).count() > 100: + rm_ids = [m.id for m in cls.model.select(cls.model.id).where(cls.model.kb_id == kb_id, cls.model.connector_id == connector_id).order_by(cls.model.update_time.asc()).limit(70)] + deleted = cls.model.delete().where(cls.model.id.in_(rm_ids)).execute() + logging.info(f"[SyncLogService] Cleaned {deleted} old logs.") + except Exception as e: + logging.exception(e) + + try: + e = cls.query(kb_id=kb_id, connector_id=connector_id, status=TaskStatus.SCHEDULE) + if e: + logging.warning(f"{kb_id}--{connector_id} has already had a scheduling sync task which is abnormal.") + return None + reindex = "1" if reindex else "0" + ConnectorService.update_by_id(connector_id, {"status": TaskStatus.SCHEDULE}) + return cls.save(**{ + "id": get_uuid(), + "kb_id": kb_id, "status": TaskStatus.SCHEDULE, "connector_id": connector_id, + "poll_range_start": poll_range_start, "from_beginning": reindex, + "total_docs_indexed": total_docs_indexed + }) + except Exception as e: + logging.exception(e) + task = cls.get_latest_task(connector_id, kb_id) + if task: + cls.model.update(status=TaskStatus.SCHEDULE, + poll_range_start=poll_range_start, + error_msg=cls.model.error_msg + str(e), + full_exception_trace=cls.model.full_exception_trace + str(e) + ) \ + .where(cls.model.id == task.id).execute() + ConnectorService.update_by_id(connector_id, {"status": TaskStatus.SCHEDULE}) + + @classmethod + def increase_docs(cls, id, min_update, max_update, doc_num, err_msg="", error_count=0): + cls.model.update(new_docs_indexed=cls.model.new_docs_indexed + doc_num, + total_docs_indexed=cls.model.total_docs_indexed + doc_num, + poll_range_start=fn.COALESCE(fn.LEAST(cls.model.poll_range_start,min_update), min_update), + poll_range_end=fn.COALESCE(fn.GREATEST(cls.model.poll_range_end, max_update), max_update), + error_msg=cls.model.error_msg + err_msg, + error_count=cls.model.error_count + error_count, + update_time=current_timestamp(), + update_date=timestamp_to_date(current_timestamp()) + )\ + .where(cls.model.id == id).execute() + + @classmethod + def duplicate_and_parse(cls, kb, docs, tenant_id, src, auto_parse=True): + if not docs: + return None + + class FileObj(BaseModel): + filename: str + blob: bytes + + def read(self) -> bytes: + return self.blob + + errs = [] + files = [FileObj(filename=d["semantic_identifier"]+(f"{d['extension']}" if d["semantic_identifier"][::-1].find(d['extension'][::-1])<0 else ""), blob=d["blob"]) for d in docs] + doc_ids = [] + err, doc_blob_pairs = FileService.upload_document(kb, files, tenant_id, src) + errs.extend(err) + + kb_table_num_map = {} + for doc, _ in doc_blob_pairs: + doc_ids.append(doc["id"]) + if not auto_parse or auto_parse == "0": + continue + DocumentService.run(tenant_id, doc, kb_table_num_map) + + return errs, doc_ids + + @classmethod + def get_latest_task(cls, connector_id, kb_id): + return cls.model.select().where( + cls.model.connector_id==connector_id, + cls.model.kb_id == kb_id + ).order_by(cls.model.update_time.desc()).first() + + +class Connector2KbService(CommonService): + model = Connector2Kb + + @classmethod + def link_connectors(cls, kb_id:str, connectors: list[dict], tenant_id:str): + arr = cls.query(kb_id=kb_id) + old_conn_ids = [a.connector_id for a in arr] + connector_ids = [] + for conn in connectors: + conn_id = conn["id"] + connector_ids.append(conn_id) + if conn_id in old_conn_ids: + cls.filter_update([cls.model.connector_id==conn_id, cls.model.kb_id==kb_id], {"auto_parse": conn.get("auto_parse", "1")}) + continue + cls.save(**{ + "id": get_uuid(), + "connector_id": conn_id, + "kb_id": kb_id, + "auto_parse": conn.get("auto_parse", "1") + }) + SyncLogsService.schedule(conn_id, kb_id, reindex=True) + + errs = [] + for conn_id in old_conn_ids: + if conn_id in connector_ids: + continue + cls.filter_delete([cls.model.kb_id==kb_id, cls.model.connector_id==conn_id]) + e, conn = ConnectorService.get_by_id(conn_id) + if not e: + continue + #SyncLogsService.filter_delete([SyncLogs.connector_id==conn_id, SyncLogs.kb_id==kb_id]) + # Do not delete docs while unlinking. + SyncLogsService.filter_update([SyncLogs.connector_id==conn_id, SyncLogs.kb_id==kb_id, SyncLogs.status.in_([TaskStatus.SCHEDULE, TaskStatus.RUNNING])], {"status": TaskStatus.CANCEL}) + #docs = DocumentService.query(source_type=f"{conn.source}/{conn.id}") + #err = FileService.delete_docs([d.id for d in docs], tenant_id) + #if err: + # errs.append(err) + return "\n".join(errs) + + @classmethod + def list_connectors(cls, kb_id): + fields = [ + Connector.id, + Connector.source, + Connector.name, + cls.model.auto_parse, + Connector.status + ] + return list(cls.model.select(*fields)\ + .join(Connector, on=(cls.model.connector_id==Connector.id))\ + .where( + cls.model.kb_id==kb_id + ).dicts() + ) + + + diff --git a/api/db/services/conversation_service.py b/api/db/services/conversation_service.py index 5e247c21cc3..60f8e55b1cd 100644 --- a/api/db/services/conversation_service.py +++ b/api/db/services/conversation_service.py @@ -15,15 +15,15 @@ # import time from uuid import uuid4 -from api.db import StatusEnum +from common.constants import StatusEnum from api.db.db_models import Conversation, DB from api.db.services.api_service import API4ConversationService from api.db.services.common_service import CommonService from api.db.services.dialog_service import DialogService, chat -from api.utils import get_uuid +from common.misc_utils import get_uuid import json -from rag.prompts import chunks_format +from rag.prompts.generator import chunks_format class ConversationService(CommonService): @@ -48,6 +48,21 @@ def get_list(cls, dialog_id, page_number, items_per_page, orderby, desc, id, nam return list(sessions.dicts()) + @classmethod + @DB.connection_context() + def get_all_conversation_by_dialog_ids(cls, dialog_ids): + sessions = cls.model.select().where(cls.model.dialog_id.in_(dialog_ids)) + sessions.order_by(cls.model.create_time.asc()) + offset, limit = 0, 100 + res = [] + while True: + s_batch = sessions.offset(offset).limit(limit) + _temp = list(s_batch.dicts()) + if not _temp: + break + res.extend(_temp) + offset += limit + return res def structure_answer(conv, ans, message_id, session_id): reference = ans["reference"] diff --git a/api/db/services/dialog_service.py b/api/db/services/dialog_service.py index 211178a51b7..f54ebf70980 100644 --- a/api/db/services/dialog_service.py +++ b/api/db/services/dialog_service.py @@ -21,24 +21,29 @@ from datetime import datetime from functools import partial from timeit import default_timer as timer - +import trio from langfuse import Langfuse - +from peewee import fn from agentic_reasoning import DeepResearcher -from api import settings -from api.db import LLMType, ParserType, StatusEnum +from common.constants import LLMType, ParserType, StatusEnum from api.db.db_models import DB, Dialog from api.db.services.common_service import CommonService +from api.db.services.document_service import DocumentService from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.langfuse_service import TenantLangfuseService -from api.db.services.llm_service import LLMBundle, TenantLLMService -from api.utils import current_timestamp, datetime_format +from api.db.services.llm_service import LLMBundle +from api.db.services.tenant_llm_service import TenantLLMService +from common.time_utils import current_timestamp, datetime_format +from graphrag.general.mind_map_extractor import MindMapExtractor from rag.app.resume import forbidden_select_fields4resume from rag.app.tag import label_question from rag.nlp.search import index_name -from rag.prompts import chunks_format, citation_prompt, cross_languages, full_question, kb_prompt, keyword_extraction, llm_id2llm_type, message_fit_in -from rag.utils import num_tokens_from_string, rmSpace +from rag.prompts.generator import chunks_format, citation_prompt, cross_languages, full_question, kb_prompt, keyword_extraction, message_fit_in, \ + gen_meta_filter, PROMPT_JINJA_ENV, ASK_SUMMARY +from common.token_utils import num_tokens_from_string from rag.utils.tavily_conn import Tavily +from common.string_utils import remove_redundant_spaces +from common import settings class DialogService(CommonService): @@ -95,9 +100,85 @@ def get_list(cls, tenant_id, page_number, items_per_page, orderby, desc, id, nam return list(chats.dicts()) + @classmethod + @DB.connection_context() + def get_by_tenant_ids(cls, joined_tenant_ids, user_id, page_number, items_per_page, orderby, desc, keywords, parser_id=None): + from api.db.db_models import User + + fields = [ + cls.model.id, + cls.model.tenant_id, + cls.model.name, + cls.model.description, + cls.model.language, + cls.model.llm_id, + cls.model.llm_setting, + cls.model.prompt_type, + cls.model.prompt_config, + cls.model.similarity_threshold, + cls.model.vector_similarity_weight, + cls.model.top_n, + cls.model.top_k, + cls.model.do_refer, + cls.model.rerank_id, + cls.model.kb_ids, + cls.model.icon, + cls.model.status, + User.nickname, + User.avatar.alias("tenant_avatar"), + cls.model.update_time, + cls.model.create_time, + ] + if keywords: + dialogs = ( + cls.model.select(*fields) + .join(User, on=(cls.model.tenant_id == User.id)) + .where( + (cls.model.tenant_id.in_(joined_tenant_ids) | (cls.model.tenant_id == user_id)) & (cls.model.status == StatusEnum.VALID.value), + (fn.LOWER(cls.model.name).contains(keywords.lower())), + ) + ) + else: + dialogs = ( + cls.model.select(*fields) + .join(User, on=(cls.model.tenant_id == User.id)) + .where( + (cls.model.tenant_id.in_(joined_tenant_ids) | (cls.model.tenant_id == user_id)) & (cls.model.status == StatusEnum.VALID.value), + ) + ) + if parser_id: + dialogs = dialogs.where(cls.model.parser_id == parser_id) + if desc: + dialogs = dialogs.order_by(cls.model.getter_by(orderby).desc()) + else: + dialogs = dialogs.order_by(cls.model.getter_by(orderby).asc()) + + count = dialogs.count() + + if page_number and items_per_page: + dialogs = dialogs.paginate(page_number, items_per_page) + + return list(dialogs.dicts()), count + + @classmethod + @DB.connection_context() + def get_all_dialogs_by_tenant_id(cls, tenant_id): + fields = [cls.model.id] + dialogs = cls.model.select(*fields).where(cls.model.tenant_id == tenant_id) + dialogs.order_by(cls.model.create_time.asc()) + offset, limit = 0, 100 + res = [] + while True: + d_batch = dialogs.offset(offset).limit(limit) + _temp = list(d_batch.dicts()) + if not _temp: + break + res.extend(_temp) + offset += limit + return res def chat_solo(dialog, messages, stream=True): - if llm_id2llm_type(dialog.llm_id) == "image2text": + if TenantLLMService.llm_id2llm_type(dialog.llm_id) == "image2text": chat_mdl = LLMBundle(dialog.tenant_id, LLMType.IMAGE2TEXT, dialog.llm_id) else: chat_mdl = LLMBundle(dialog.tenant_id, LLMType.CHAT, dialog.llm_id) @@ -112,7 +193,7 @@ def chat_solo(dialog, messages, stream=True): delta_ans = "" for ans in chat_mdl.chat_streamly(prompt_config.get("system", ""), msg, dialog.llm_setting): answer = ans - delta_ans = ans[len(last_ans) :] + delta_ans = ans[len(last_ans):] if num_tokens_from_string(delta_ans) < 16: continue last_ans = answer @@ -139,7 +220,7 @@ def get_models(dialog): if not embd_mdl: raise LookupError("Embedding model(%s) not found" % embedding_list[0]) - if llm_id2llm_type(dialog.llm_id) == "image2text": + if TenantLLMService.llm_id2llm_type(dialog.llm_id) == "image2text": chat_mdl = LLMBundle(dialog.tenant_id, LLMType.IMAGE2TEXT, dialog.llm_id) else: chat_mdl = LLMBundle(dialog.tenant_id, LLMType.CHAT, dialog.llm_id) @@ -189,6 +270,73 @@ def replacement(match): return answer, idx +def convert_conditions(metadata_condition): + if metadata_condition is None: + metadata_condition = {} + op_mapping = { + "is": "=", + "not is": "≠" + } + return [ + { + "op": op_mapping.get(cond["comparison_operator"], cond["comparison_operator"]), + "key": cond["name"], + "value": cond["value"] + } + for cond in metadata_condition.get("conditions", []) + ] + + +def meta_filter(metas: dict, filters: list[dict]): + doc_ids = set([]) + + def filter_out(v2docs, operator, value): + ids = [] + for input, docids in v2docs.items(): + if operator in ["=", "≠", ">", "<", "≥", "≤"]: + try: + input = float(input) + value = float(value) + except Exception: + input = str(input) + value = str(value) + + for conds in [ + (operator == "contains", str(value).lower() in str(input).lower()), + (operator == "not contains", str(value).lower() not in str(input).lower()), + (operator == "start with", str(input).lower().startswith(str(value).lower())), + (operator == "end with", str(input).lower().endswith(str(value).lower())), + (operator == "empty", not input), + (operator == "not empty", input), + (operator == "=", input == value), + (operator == "≠", input != value), + (operator == ">", input > value), + (operator == "<", input < value), + (operator == "≥", input >= value), + (operator == "≤", input <= value), + ]: + try: + if all(conds): + ids.extend(docids) + break + except Exception: + pass + return ids + + for k, v2docs in metas.items(): + for f in filters: + if k != f["key"]: + continue + ids = filter_out(v2docs, f["op"], f["value"]) + if not doc_ids: + doc_ids = set(ids) + else: + doc_ids = doc_ids & set(ids) + if not doc_ids: + return [] + return list(doc_ids) + + def chat(dialog, messages, stream=True, **kwargs): assert messages[-1]["role"] == "user", "The last content of this conversation is not from user." if not dialog.kb_ids and not dialog.prompt_config.get("tavily_api_key"): @@ -198,7 +346,7 @@ def chat(dialog, messages, stream=True, **kwargs): chat_start_ts = timer() - if llm_id2llm_type(dialog.llm_id) == "image2text": + if TenantLLMService.llm_id2llm_type(dialog.llm_id) == "image2text": llm_model_config = TenantLLMService.get_model_config(dialog.tenant_id, LLMType.IMAGE2TEXT, dialog.llm_id) else: llm_model_config = TenantLLMService.get_model_config(dialog.tenant_id, LLMType.CHAT, dialog.llm_id) @@ -208,12 +356,14 @@ def chat(dialog, messages, stream=True, **kwargs): check_llm_ts = timer() langfuse_tracer = None + trace_context = {} langfuse_keys = TenantLangfuseService.filter_by_tenant(tenant_id=dialog.tenant_id) if langfuse_keys: langfuse = Langfuse(public_key=langfuse_keys.public_key, secret_key=langfuse_keys.secret_key, host=langfuse_keys.host) if langfuse.auth_check(): langfuse_tracer = langfuse - langfuse.trace = langfuse_tracer.trace(name=f"{dialog.name}-{llm_model_config['llm_name']}") + trace_id = langfuse_tracer.create_trace_id() + trace_context = {"trace_id": trace_id} check_langfuse_tracer_ts = timer() kbs, embd_mdl, rerank_mdl, chat_mdl, tts_mdl = get_models(dialog) @@ -222,17 +372,18 @@ def chat(dialog, messages, stream=True, **kwargs): chat_mdl.bind_tools(toolcall_session, tools) bind_models_ts = timer() - retriever = settings.retrievaler + retriever = settings.retriever questions = [m["content"] for m in messages if m["role"] == "user"][-3:] - attachments = kwargs["doc_ids"].split(",") if "doc_ids" in kwargs else None + attachments = kwargs["doc_ids"].split(",") if "doc_ids" in kwargs else [] if "doc_ids" in messages[-1]: attachments = messages[-1]["doc_ids"] + prompt_config = dialog.prompt_config field_map = KnowledgebaseService.get_field_map(dialog.kb_ids) # try to use sql if field mapping is good to go if field_map: logging.debug("Use SQL to retrieval:{}".format(questions[-1])) - ans = use_sql(questions[-1], field_map, dialog.tenant_id, chat_mdl, prompt_config.get("quote", True)) + ans = use_sql(questions[-1], field_map, dialog.tenant_id, chat_mdl, prompt_config.get("quote", True), dialog.kb_ids) if ans: yield ans return @@ -253,6 +404,18 @@ def chat(dialog, messages, stream=True, **kwargs): if prompt_config.get("cross_languages"): questions = [cross_languages(dialog.tenant_id, dialog.llm_id, questions[0], prompt_config["cross_languages"])] + if dialog.meta_data_filter: + metas = DocumentService.get_meta_by_kbs(dialog.kb_ids) + if dialog.meta_data_filter.get("method") == "auto": + filters = gen_meta_filter(chat_mdl, metas, questions[-1]) + attachments.extend(meta_filter(metas, filters)) + if not attachments: + attachments = None + elif dialog.meta_data_filter.get("method") == "manual": + attachments.extend(meta_filter(metas, dialog.meta_data_filter["manual"])) + if not attachments: + attachments = None + if prompt_config.get("keyword", False): questions[-1] += keyword_extraction(chat_mdl, questions[-1]) @@ -260,17 +423,26 @@ def chat(dialog, messages, stream=True, **kwargs): thought = "" kbinfos = {"total": 0, "chunks": [], "doc_aggs": []} + knowledges = [] - if "knowledge" not in [p["key"] for p in prompt_config["parameters"]]: - knowledges = [] - else: + if attachments is not None and "knowledge" in [p["key"] for p in prompt_config["parameters"]]: tenant_ids = list(set([kb.tenant_id for kb in kbs])) knowledges = [] if prompt_config.get("reasoning", False): reasoner = DeepResearcher( chat_mdl, prompt_config, - partial(retriever.retrieval, embd_mdl=embd_mdl, tenant_ids=tenant_ids, kb_ids=dialog.kb_ids, page=1, page_size=dialog.top_n, similarity_threshold=0.2, vector_similarity_weight=0.3), + partial( + retriever.retrieval, + embd_mdl=embd_mdl, + tenant_ids=tenant_ids, + kb_ids=dialog.kb_ids, + page=1, + page_size=dialog.top_n, + similarity_threshold=0.2, + vector_similarity_weight=0.3, + doc_ids=attachments, + ), ) for think in reasoner.thinking(kbinfos, " ".join(questions)): @@ -296,13 +468,18 @@ def chat(dialog, messages, stream=True, **kwargs): rerank_mdl=rerank_mdl, rank_feature=label_question(" ".join(questions), kbs), ) + if prompt_config.get("toc_enhance"): + cks = retriever.retrieval_by_toc(" ".join(questions), kbinfos["chunks"], tenant_ids, chat_mdl, dialog.top_n) + if cks: + kbinfos["chunks"] = cks if prompt_config.get("tavily_api_key"): tav = Tavily(prompt_config["tavily_api_key"]) tav_res = tav.retrieve_chunks(" ".join(questions)) kbinfos["chunks"].extend(tav_res["chunks"]) kbinfos["doc_aggs"].extend(tav_res["doc_aggs"]) if prompt_config.get("use_kg"): - ck = settings.kg_retrievaler.retrieval(" ".join(questions), tenant_ids, dialog.kb_ids, embd_mdl, LLMBundle(dialog.tenant_id, LLMType.CHAT)) + ck = settings.kg_retriever.retrieval(" ".join(questions), tenant_ids, dialog.kb_ids, embd_mdl, + LLMBundle(dialog.tenant_id, LLMType.CHAT)) if ck["content_with_weight"]: kbinfos["chunks"].insert(0, ck) @@ -313,7 +490,8 @@ def chat(dialog, messages, stream=True, **kwargs): retrieval_ts = timer() if not knowledges and prompt_config.get("empty_response"): empty_res = prompt_config["empty_response"] - yield {"answer": empty_res, "reference": kbinfos, "prompt": "\n\n### Query:\n%s" % " ".join(questions), "audio_binary": tts(tts_mdl, empty_res)} + yield {"answer": empty_res, "reference": kbinfos, "prompt": "\n\n### Query:\n%s" % " ".join(questions), + "audio_binary": tts(tts_mdl, empty_res)} return {"answer": prompt_config["empty_response"], "reference": kbinfos} kwargs["knowledge"] = "\n------\n" + "\n\n------\n\n".join(knowledges) @@ -400,17 +578,20 @@ def decorate_answer(answer): f" - Token speed: {int(tk_num / (generate_result_time_cost / 1000.0))}/s" ) - langfuse_output = "\n" + re.sub(r"^.*?(### Query:.*)", r"\1", prompt, flags=re.DOTALL) - langfuse_output = {"time_elapsed:": re.sub(r"\n", " \n", langfuse_output), "created_at": time.time()} - # Add a condition check to call the end method only if langfuse_tracer exists if langfuse_tracer and "langfuse_generation" in locals(): - langfuse_generation.end(output=langfuse_output) + langfuse_output = "\n" + re.sub(r"^.*?(### Query:.*)", r"\1", prompt, flags=re.DOTALL) + langfuse_output = {"time_elapsed:": re.sub(r"\n", " \n", langfuse_output), "created_at": time.time()} + langfuse_generation.update(output=langfuse_output) + langfuse_generation.end() return {"answer": think + answer, "reference": refs, "prompt": re.sub(r"\n", " \n", prompt), "created_at": time.time()} if langfuse_tracer: - langfuse_generation = langfuse_tracer.trace.generation(name="chat", model=llm_model_config["llm_name"], input={"prompt": prompt, "prompt4citation": prompt4citation, "messages": msg}) + langfuse_generation = langfuse_tracer.start_generation( + trace_context=trace_context, name="chat", model=llm_model_config["llm_name"], + input={"prompt": prompt, "prompt4citation": prompt4citation, "messages": msg} + ) if stream: last_ans = "" @@ -419,12 +600,12 @@ def decorate_answer(answer): if thought: ans = re.sub(r"^.*", "", ans, flags=re.DOTALL) answer = ans - delta_ans = ans[len(last_ans) :] + delta_ans = ans[len(last_ans):] if num_tokens_from_string(delta_ans) < 16: continue last_ans = answer yield {"answer": thought + answer, "reference": {}, "audio_binary": tts(tts_mdl, delta_ans)} - delta_ans = answer[len(last_ans) :] + delta_ans = answer[len(last_ans):] if delta_ans: yield {"answer": thought + answer, "reference": {}, "audio_binary": tts(tts_mdl, delta_ans)} yield decorate_answer(thought + answer) @@ -437,8 +618,13 @@ def decorate_answer(answer): yield res -def use_sql(question, field_map, tenant_id, chat_mdl, quota=True): - sys_prompt = "You are a Database Administrator. You need to check the fields of the following tables based on the user's list of questions and write the SQL corresponding to the last question." +def use_sql(question, field_map, tenant_id, chat_mdl, quota=True, kb_ids=None): + sys_prompt = """ +You are a Database Administrator. You need to check the fields of the following tables based on the user's list of questions and write the SQL corresponding to the last question. +Ensure that: +1. Field names should not start with a digit. If any field name starts with a digit, use double quotes around it. +2. Write only the SQL, no explanations or additional text. +""" user_prompt = """ Table name: {}; Table of database fields are as follows: @@ -459,6 +645,7 @@ def get_table(): sql = re.sub(r".*select ", "select ", sql.lower()) sql = re.sub(r" +", " ", sql) sql = re.sub(r"([;;]|```).*", "", sql) + sql = re.sub(r"&", "and", sql) if sql[: len("select ")] != "select ": return None, None if not re.search(r"((sum|avg|max|min)\(|group by )", sql.lower()): @@ -474,9 +661,16 @@ def get_table(): flds.append(k) sql = "select doc_id,docnm_kwd," + ",".join(flds) + sql[8:] + if kb_ids: + kb_filter = "(" + " OR ".join([f"kb_id = '{kb_id}'" for kb_id in kb_ids]) + ")" + if "where" not in sql.lower(): + sql += f" WHERE {kb_filter}" + else: + sql += f" AND {kb_filter}" + logging.debug(f"{question} get SQL(refined): {sql}") tried_times += 1 - return settings.retrievaler.sql_retrieval(sql, format="json"), sql + return settings.retriever.sql_retrieval(sql, format="json"), sql tbl, sql = get_table() if tbl is None: @@ -513,12 +707,14 @@ def get_table(): # compose Markdown table columns = ( - "|" + "|".join([re.sub(r"(/.*|([^()]+))", "", field_map.get(tbl["columns"][i]["name"], tbl["columns"][i]["name"])) for i in column_idx]) + ("|Source|" if docid_idx and docid_idx else "|") + "|" + "|".join( + [re.sub(r"(/.*|([^()]+))", "", field_map.get(tbl["columns"][i]["name"], tbl["columns"][i]["name"])) for i in column_idx]) + ( + "|Source|" if docid_idx and docid_idx else "|") ) line = "|" + "|".join(["------" for _ in range(len(column_idx))]) + ("|------|" if docid_idx and docid_idx else "") - rows = ["|" + "|".join([rmSpace(str(r[i])) for i in column_idx]).replace("None", " ") + "|" for r in tbl["rows"]] + rows = ["|" + "|".join([remove_redundant_spaces(str(r[i])) for i in column_idx]).replace("None", " ") + "|" for r in tbl["rows"]] rows = [r for r in rows if re.sub(r"[ |]+", "", r)] if quota: rows = "\n".join([r + f" ##{ii}$$ |" for ii, r in enumerate(rows)]) @@ -556,40 +752,64 @@ def tts(tts_mdl, text): return binascii.hexlify(bin).decode("utf-8") -def ask(question, kb_ids, tenant_id, chat_llm_name=None): +def ask(question, kb_ids, tenant_id, chat_llm_name=None, search_config={}): + doc_ids = search_config.get("doc_ids", []) + rerank_mdl = None + kb_ids = search_config.get("kb_ids", kb_ids) + chat_llm_name = search_config.get("chat_id", chat_llm_name) + rerank_id = search_config.get("rerank_id", "") + meta_data_filter = search_config.get("meta_data_filter") + kbs = KnowledgebaseService.get_by_ids(kb_ids) embedding_list = list(set([kb.embd_id for kb in kbs])) is_knowledge_graph = all([kb.parser_id == ParserType.KG for kb in kbs]) - retriever = settings.retrievaler if not is_knowledge_graph else settings.kg_retrievaler + retriever = settings.retriever if not is_knowledge_graph else settings.kg_retriever embd_mdl = LLMBundle(tenant_id, LLMType.EMBEDDING, embedding_list[0]) chat_mdl = LLMBundle(tenant_id, LLMType.CHAT, chat_llm_name) + if rerank_id: + rerank_mdl = LLMBundle(tenant_id, LLMType.RERANK, rerank_id) max_tokens = chat_mdl.max_length tenant_ids = list(set([kb.tenant_id for kb in kbs])) - kbinfos = retriever.retrieval(question, embd_mdl, tenant_ids, kb_ids, 1, 12, 0.1, 0.3, aggs=False, rank_feature=label_question(question, kbs)) + + if meta_data_filter: + metas = DocumentService.get_meta_by_kbs(kb_ids) + if meta_data_filter.get("method") == "auto": + filters = gen_meta_filter(chat_mdl, metas, question) + doc_ids.extend(meta_filter(metas, filters)) + if not doc_ids: + doc_ids = None + elif meta_data_filter.get("method") == "manual": + doc_ids.extend(meta_filter(metas, meta_data_filter["manual"])) + if not doc_ids: + doc_ids = None + + kbinfos = retriever.retrieval( + question=question, + embd_mdl=embd_mdl, + tenant_ids=tenant_ids, + kb_ids=kb_ids, + page=1, + page_size=12, + similarity_threshold=search_config.get("similarity_threshold", 0.1), + vector_similarity_weight=search_config.get("vector_similarity_weight", 0.3), + top=search_config.get("top_k", 1024), + doc_ids=doc_ids, + aggs=False, + rerank_mdl=rerank_mdl, + rank_feature=label_question(question, kbs) + ) + knowledges = kb_prompt(kbinfos, max_tokens) - prompt = """ - Role: You're a smart assistant. Your name is Miss R. - Task: Summarize the information from knowledge bases and answer user's question. - Requirements and restriction: - - DO NOT make things up, especially for numbers. - - If the information from knowledge is irrelevant with user's question, JUST SAY: Sorry, no relevant information provided. - - Answer with markdown format text. - - Answer in language of user's question. - - DO NOT make things up, especially for numbers. - - ### Information from knowledge bases - %s - - The above is information from knowledge bases. - - """ % "\n".join(knowledges) + sys_prompt = PROMPT_JINJA_ENV.from_string(ASK_SUMMARY).render(knowledge="\n".join(knowledges)) + msg = [{"role": "user", "content": question}] def decorate_answer(answer): - nonlocal knowledges, kbinfos, prompt - answer, idx = retriever.insert_citations(answer, [ck["content_ltks"] for ck in kbinfos["chunks"]], [ck["vector"] for ck in kbinfos["chunks"]], embd_mdl, tkweight=0.7, vtweight=0.3) + nonlocal knowledges, kbinfos, sys_prompt + answer, idx = retriever.insert_citations(answer, [ck["content_ltks"] for ck in kbinfos["chunks"]], [ck["vector"] for ck in kbinfos["chunks"]], + embd_mdl, tkweight=0.7, vtweight=0.3) idx = set([kbinfos["chunks"][int(i)]["doc_id"] for i in idx]) recall_docs = [d for d in kbinfos["doc_aggs"] if d["doc_id"] in idx] if not recall_docs: @@ -606,7 +826,55 @@ def decorate_answer(answer): return {"answer": answer, "reference": refs} answer = "" - for ans in chat_mdl.chat_streamly(prompt, msg, {"temperature": 0.1}): + for ans in chat_mdl.chat_streamly(sys_prompt, msg, {"temperature": 0.1}): answer = ans yield {"answer": answer, "reference": {}} yield decorate_answer(answer) + + +def gen_mindmap(question, kb_ids, tenant_id, search_config={}): + meta_data_filter = search_config.get("meta_data_filter", {}) + doc_ids = search_config.get("doc_ids", []) + rerank_id = search_config.get("rerank_id", "") + rerank_mdl = None + kbs = KnowledgebaseService.get_by_ids(kb_ids) + if not kbs: + return {"error": "No KB selected"} + embedding_list = list(set([kb.embd_id for kb in kbs])) + tenant_ids = list(set([kb.tenant_id for kb in kbs])) + + embd_mdl = LLMBundle(tenant_id, LLMType.EMBEDDING, llm_name=embedding_list[0]) + chat_mdl = LLMBundle(tenant_id, LLMType.CHAT, llm_name=search_config.get("chat_id", "")) + if rerank_id: + rerank_mdl = LLMBundle(tenant_id, LLMType.RERANK, rerank_id) + + if meta_data_filter: + metas = DocumentService.get_meta_by_kbs(kb_ids) + if meta_data_filter.get("method") == "auto": + filters = gen_meta_filter(chat_mdl, metas, question) + doc_ids.extend(meta_filter(metas, filters)) + if not doc_ids: + doc_ids = None + elif meta_data_filter.get("method") == "manual": + doc_ids.extend(meta_filter(metas, meta_data_filter["manual"])) + if not doc_ids: + doc_ids = None + + ranks = settings.retriever.retrieval( + question=question, + embd_mdl=embd_mdl, + tenant_ids=tenant_ids, + kb_ids=kb_ids, + page=1, + page_size=12, + similarity_threshold=search_config.get("similarity_threshold", 0.2), + vector_similarity_weight=search_config.get("vector_similarity_weight", 0.3), + top=search_config.get("top_k", 1024), + doc_ids=doc_ids, + aggs=False, + rerank_mdl=rerank_mdl, + rank_feature=label_question(question, kbs), + ) + mindmap = MindMapExtractor(chat_mdl) + mind_map = trio.run(mindmap, [c["content_with_weight"] for c in ranks["chunks"]]) + return mind_map.output diff --git a/api/db/services/document_service.py b/api/db/services/document_service.py index 8b7bc666000..a64ae16deb7 100644 --- a/api/db/services/document_service.py +++ b/api/db/services/document_service.py @@ -24,31 +24,66 @@ import trio import xxhash -from peewee import fn +from peewee import fn, Case, JOIN -from api import settings -from api.constants import IMG_BASE64_PREFIX -from api.db import FileType, LLMType, ParserType, StatusEnum, TaskStatus, UserTenantRole -from api.db.db_models import DB, Document, Knowledgebase, Task, Tenant, UserTenant +from api.constants import IMG_BASE64_PREFIX, FILE_NAME_LEN_LIMIT +from api.db import PIPELINE_SPECIAL_PROGRESS_FREEZE_TASK_TYPES, FileType, UserTenantRole, CanvasCategory +from api.db.db_models import DB, Document, Knowledgebase, Task, Tenant, UserTenant, File2Document, File, UserCanvas, \ + User from api.db.db_utils import bulk_insert_into_db from api.db.services.common_service import CommonService from api.db.services.knowledgebase_service import KnowledgebaseService -from api.utils import current_timestamp, get_format_time, get_uuid +from common.misc_utils import get_uuid +from common.time_utils import current_timestamp, get_format_time +from common.constants import LLMType, ParserType, StatusEnum, TaskStatus, SVR_CONSUMER_GROUP_NAME from rag.nlp import rag_tokenizer, search -from rag.settings import get_svr_queue_name, SVR_CONSUMER_GROUP_NAME from rag.utils.redis_conn import REDIS_CONN -from rag.utils.storage_factory import STORAGE_IMPL from rag.utils.doc_store_conn import OrderByExpr - +from common import settings class DocumentService(CommonService): model = Document + @classmethod + def get_cls_model_fields(cls): + return [ + cls.model.id, + cls.model.thumbnail, + cls.model.kb_id, + cls.model.parser_id, + cls.model.pipeline_id, + cls.model.parser_config, + cls.model.source_type, + cls.model.type, + cls.model.created_by, + cls.model.name, + cls.model.location, + cls.model.size, + cls.model.token_num, + cls.model.chunk_num, + cls.model.progress, + cls.model.progress_msg, + cls.model.process_begin_at, + cls.model.process_duration, + cls.model.meta_fields, + cls.model.suffix, + cls.model.run, + cls.model.status, + cls.model.create_time, + cls.model.create_date, + cls.model.update_time, + cls.model.update_date, + ] + @classmethod @DB.connection_context() def get_list(cls, kb_id, page_number, items_per_page, - orderby, desc, keywords, id, name): - docs = cls.model.select().where(cls.model.kb_id == kb_id) + orderby, desc, keywords, id, name, suffix=None, run = None): + fields = cls.get_cls_model_fields() + docs = cls.model.select(*[*fields, UserCanvas.title]).join(File2Document, on = (File2Document.document_id == cls.model.id))\ + .join(File, on = (File.id == File2Document.file_id))\ + .join(UserCanvas, on = ((cls.model.pipeline_id == UserCanvas.id) & (UserCanvas.canvas_category == CanvasCategory.DataFlow.value)), join_type=JOIN.LEFT_OUTER)\ + .where(cls.model.kb_id == kb_id) if id: docs = docs.where( cls.model.id == id) @@ -60,6 +95,10 @@ def get_list(cls, kb_id, page_number, items_per_page, docs = docs.where( fn.LOWER(cls.model.name).contains(keywords.lower()) ) + if suffix: + docs = docs.where(cls.model.suffix.in_(suffix)) + if run: + docs = docs.where(cls.model.run.in_(run)) if desc: docs = docs.order_by(cls.model.getter_by(orderby).desc()) else: @@ -69,22 +108,46 @@ def get_list(cls, kb_id, page_number, items_per_page, docs = docs.paginate(page_number, items_per_page) return list(docs.dicts()), count + @classmethod + @DB.connection_context() + def check_doc_health(cls, tenant_id: str, filename): + import os + MAX_FILE_NUM_PER_USER = int(os.environ.get("MAX_FILE_NUM_PER_USER", 0)) + if MAX_FILE_NUM_PER_USER > 0 and DocumentService.get_doc_count(tenant_id) >= MAX_FILE_NUM_PER_USER: + raise RuntimeError("Exceed the maximum file number of a free user!") + if len(filename.encode("utf-8")) > FILE_NAME_LEN_LIMIT: + raise RuntimeError("Exceed the maximum length of file name!") + return True + @classmethod @DB.connection_context() def get_by_kb_id(cls, kb_id, page_number, items_per_page, - orderby, desc, keywords, run_status, types): + orderby, desc, keywords, run_status, types, suffix): + fields = cls.get_cls_model_fields() if keywords: - docs = cls.model.select().where( - (cls.model.kb_id == kb_id), - (fn.LOWER(cls.model.name).contains(keywords.lower())) - ) + docs = cls.model.select(*[*fields, UserCanvas.title.alias("pipeline_name"), User.nickname])\ + .join(File2Document, on=(File2Document.document_id == cls.model.id))\ + .join(File, on=(File.id == File2Document.file_id))\ + .join(UserCanvas, on=(cls.model.pipeline_id == UserCanvas.id), join_type=JOIN.LEFT_OUTER)\ + .join(User, on=(cls.model.created_by == User.id), join_type=JOIN.LEFT_OUTER)\ + .where( + (cls.model.kb_id == kb_id), + (fn.LOWER(cls.model.name).contains(keywords.lower())) + ) else: - docs = cls.model.select().where(cls.model.kb_id == kb_id) + docs = cls.model.select(*[*fields, UserCanvas.title.alias("pipeline_name"), User.nickname])\ + .join(File2Document, on=(File2Document.document_id == cls.model.id))\ + .join(UserCanvas, on=(cls.model.pipeline_id == UserCanvas.id), join_type=JOIN.LEFT_OUTER)\ + .join(File, on=(File.id == File2Document.file_id))\ + .join(User, on=(cls.model.created_by == User.id), join_type=JOIN.LEFT_OUTER)\ + .where(cls.model.kb_id == kb_id) if run_status: docs = docs.where(cls.model.run.in_(run_status)) if types: docs = docs.where(cls.model.type.in_(types)) + if suffix: + docs = docs.where(cls.model.suffix.in_(suffix)) count = docs.count() if desc: @@ -98,6 +161,55 @@ def get_by_kb_id(cls, kb_id, page_number, items_per_page, return list(docs.dicts()), count + @classmethod + @DB.connection_context() + def get_filter_by_kb_id(cls, kb_id, keywords, run_status, types, suffix): + """ + returns: + { + "suffix": { + "ppt": 1, + "doxc": 2 + }, + "run_status": { + "1": 2, + "2": 2 + } + }, total + where "1" => RUNNING, "2" => CANCEL + """ + fields = cls.get_cls_model_fields() + if keywords: + query = cls.model.select(*fields).join(File2Document, on=(File2Document.document_id == cls.model.id)).join(File, on=(File.id == File2Document.file_id)).where( + (cls.model.kb_id == kb_id), + (fn.LOWER(cls.model.name).contains(keywords.lower())) + ) + else: + query = cls.model.select(*fields).join(File2Document, on=(File2Document.document_id == cls.model.id)).join(File, on=(File.id == File2Document.file_id)).where(cls.model.kb_id == kb_id) + + + if run_status: + query = query.where(cls.model.run.in_(run_status)) + if types: + query = query.where(cls.model.type.in_(types)) + if suffix: + query = query.where(cls.model.suffix.in_(suffix)) + + rows = query.select(cls.model.run, cls.model.suffix) + total = rows.count() + + suffix_counter = {} + run_status_counter = {} + + for row in rows: + suffix_counter[row.suffix] = suffix_counter.get(row.suffix, 0) + 1 + run_status_counter[str(row.run)] = run_status_counter.get(str(row.run), 0) + 1 + + return { + "suffix": suffix_counter, + "run_status": run_status_counter + }, total + @classmethod @DB.connection_context() def count_by_kb_id(cls, kb_id, keywords, run_status, types): @@ -134,6 +246,46 @@ def get_total_size_by_kb_id(cls, kb_id, keywords="", run_status=[], types=[]): return int(query.scalar()) or 0 + @classmethod + @DB.connection_context() + def get_all_doc_ids_by_kb_ids(cls, kb_ids): + fields = [cls.model.id] + docs = cls.model.select(*fields).where(cls.model.kb_id.in_(kb_ids)) + docs.order_by(cls.model.create_time.asc()) + # maybe cause slow query by deep paginate, optimize later + offset, limit = 0, 100 + res = [] + while True: + doc_batch = docs.offset(offset).limit(limit) + _temp = list(doc_batch.dicts()) + if not _temp: + break + res.extend(_temp) + offset += limit + return res + + @classmethod + @DB.connection_context() + def get_all_docs_by_creator_id(cls, creator_id): + fields = [ + cls.model.id, cls.model.kb_id, cls.model.token_num, cls.model.chunk_num, Knowledgebase.tenant_id + ] + docs = cls.model.select(*fields).join(Knowledgebase, on=(Knowledgebase.id == cls.model.kb_id)).where( + cls.model.created_by == creator_id + ) + docs.order_by(cls.model.create_time.asc()) + # maybe cause slow query by deep paginate, optimize later + offset, limit = 0, 100 + res = [] + while True: + doc_batch = docs.offset(offset).limit(limit) + _temp = list(doc_batch.dicts()) + if not _temp: + break + res.extend(_temp) + offset += limit + return res + @classmethod @DB.connection_context() def insert(cls, doc): @@ -146,8 +298,10 @@ def insert(cls, doc): @classmethod @DB.connection_context() def remove_document(cls, doc, tenant_id): + from api.db.services.task_service import TaskService cls.clear_chunk_num(doc.id) try: + TaskService.filter_delete([Task.doc_id == doc.id]) page = 0 page_size = 1000 all_chunk_ids = [] @@ -161,11 +315,11 @@ def remove_document(cls, doc, tenant_id): all_chunk_ids.extend(chunk_ids) page += 1 for cid in all_chunk_ids: - if STORAGE_IMPL.obj_exist(doc.kb_id, cid): - STORAGE_IMPL.rm(doc.kb_id, cid) + if settings.STORAGE_IMPL.obj_exist(doc.kb_id, cid): + settings.STORAGE_IMPL.rm(doc.kb_id, cid) if doc.thumbnail and not doc.thumbnail.startswith(IMG_BASE64_PREFIX): - if STORAGE_IMPL.obj_exist(doc.kb_id, doc.thumbnail): - STORAGE_IMPL.rm(doc.kb_id, doc.thumbnail) + if settings.STORAGE_IMPL.obj_exist(doc.kb_id, doc.thumbnail): + settings.STORAGE_IMPL.rm(doc.kb_id, doc.thumbnail) settings.docStoreConn.delete({"doc_id": doc.id}, search.index_name(tenant_id), doc.kb_id) graph_source = settings.docStoreConn.getFields( @@ -173,13 +327,13 @@ def remove_document(cls, doc, tenant_id): ) if len(graph_source) > 0 and doc.id in list(graph_source.values())[0]["source_id"]: settings.docStoreConn.update({"kb_id": doc.kb_id, "knowledge_graph_kwd": ["entity", "relation", "graph", "subgraph", "community_report"], "source_id": doc.id}, - {"remove": {"source_id": doc.id}}, - search.index_name(tenant_id), doc.kb_id) + {"remove": {"source_id": doc.id}}, + search.index_name(tenant_id), doc.kb_id) settings.docStoreConn.update({"kb_id": doc.kb_id, "knowledge_graph_kwd": ["graph"]}, - {"removed_kwd": "Y"}, - search.index_name(tenant_id), doc.kb_id) + {"removed_kwd": "Y"}, + search.index_name(tenant_id), doc.kb_id) settings.docStoreConn.delete({"kb_id": doc.kb_id, "knowledge_graph_kwd": ["entity", "relation", "graph", "subgraph", "community_report"], "must_not": {"exists": "source_id"}}, - search.index_name(tenant_id), doc.kb_id) + search.index_name(tenant_id), doc.kb_id) except Exception: pass return cls.delete_by_id(doc.id) @@ -218,47 +372,50 @@ def get_newly_uploaded(cls): def get_unfinished_docs(cls): fields = [cls.model.id, cls.model.process_begin_at, cls.model.parser_config, cls.model.progress_msg, cls.model.run, cls.model.parser_id] + unfinished_task_query = Task.select(Task.doc_id).where( + (Task.progress >= 0) & (Task.progress < 1) + ) + docs = cls.model.select(*fields) \ .where( cls.model.status == StatusEnum.VALID.value, ~(cls.model.type == FileType.VIRTUAL.value), - cls.model.progress < 1, - cls.model.progress > 0) + (((cls.model.progress < 1) & (cls.model.progress > 0)) | + (cls.model.id.in_(unfinished_task_query)))) # including unfinished tasks like GraphRAG, RAPTOR and Mindmap return list(docs.dicts()) @classmethod @DB.connection_context() - def increment_chunk_num(cls, doc_id, kb_id, token_num, chunk_num, duation): + def increment_chunk_num(cls, doc_id, kb_id, token_num, chunk_num, duration): num = cls.model.update(token_num=cls.model.token_num + token_num, chunk_num=cls.model.chunk_num + chunk_num, - process_duation=cls.model.process_duation + duation).where( + process_duration=cls.model.process_duration + duration).where( cls.model.id == doc_id).execute() if num == 0: - raise LookupError( - "Document not found which is supposed to be there") + logging.warning("Document not found which is supposed to be there") num = Knowledgebase.update( token_num=Knowledgebase.token_num + - token_num, + token_num, chunk_num=Knowledgebase.chunk_num + - chunk_num).where( + chunk_num).where( Knowledgebase.id == kb_id).execute() return num @classmethod @DB.connection_context() - def decrement_chunk_num(cls, doc_id, kb_id, token_num, chunk_num, duation): + def decrement_chunk_num(cls, doc_id, kb_id, token_num, chunk_num, duration): num = cls.model.update(token_num=cls.model.token_num - token_num, chunk_num=cls.model.chunk_num - chunk_num, - process_duation=cls.model.process_duation + duation).where( + process_duration=cls.model.process_duration + duration).where( cls.model.id == doc_id).execute() if num == 0: raise LookupError( "Document not found which is supposed to be there") num = Knowledgebase.update( token_num=Knowledgebase.token_num - - token_num, + token_num, chunk_num=Knowledgebase.chunk_num - - chunk_num + chunk_num ).where( Knowledgebase.id == kb_id).execute() return num @@ -271,21 +428,39 @@ def clear_chunk_num(cls, doc_id): num = Knowledgebase.update( token_num=Knowledgebase.token_num - - doc.token_num, + doc.token_num, chunk_num=Knowledgebase.chunk_num - - doc.chunk_num, + doc.chunk_num, doc_num=Knowledgebase.doc_num - 1 ).where( Knowledgebase.id == doc.kb_id).execute() return num + + @classmethod + @DB.connection_context() + def clear_chunk_num_when_rerun(cls, doc_id): + doc = cls.model.get_by_id(doc_id) + assert doc, "Can't fine document in database." + + num = ( + Knowledgebase.update( + token_num=Knowledgebase.token_num - doc.token_num, + chunk_num=Knowledgebase.chunk_num - doc.chunk_num, + ) + .where(Knowledgebase.id == doc.kb_id) + .execute() + ) + return num + + @classmethod @DB.connection_context() def get_tenant_id(cls, doc_id): docs = cls.model.select( Knowledgebase.tenant_id).join( Knowledgebase, on=( - Knowledgebase.id == cls.model.kb_id)).where( + Knowledgebase.id == cls.model.kb_id)).where( cls.model.id == doc_id, Knowledgebase.status == StatusEnum.VALID.value) docs = docs.dicts() if not docs: @@ -307,7 +482,7 @@ def get_tenant_id_by_name(cls, name): docs = cls.model.select( Knowledgebase.tenant_id).join( Knowledgebase, on=( - Knowledgebase.id == cls.model.kb_id)).where( + Knowledgebase.id == cls.model.kb_id)).where( cls.model.name == name, Knowledgebase.status == StatusEnum.VALID.value) docs = docs.dicts() if not docs: @@ -320,7 +495,7 @@ def accessible(cls, doc_id, user_id): docs = cls.model.select( cls.model.id).join( Knowledgebase, on=( - Knowledgebase.id == cls.model.kb_id) + Knowledgebase.id == cls.model.kb_id) ).join(UserTenant, on=(UserTenant.tenant_id == Knowledgebase.tenant_id) ).where(cls.model.id == doc_id, UserTenant.user_id == user_id).paginate(0, 1) docs = docs.dicts() @@ -332,12 +507,12 @@ def accessible(cls, doc_id, user_id): @DB.connection_context() def accessible4deletion(cls, doc_id, user_id): docs = cls.model.select(cls.model.id - ).join( + ).join( Knowledgebase, on=( - Knowledgebase.id == cls.model.kb_id) + Knowledgebase.id == cls.model.kb_id) ).join( UserTenant, on=( - (UserTenant.tenant_id == Knowledgebase.created_by) & (UserTenant.user_id == user_id)) + (UserTenant.tenant_id == Knowledgebase.created_by) & (UserTenant.user_id == user_id)) ).where( cls.model.id == doc_id, UserTenant.status == StatusEnum.VALID.value, @@ -354,7 +529,7 @@ def get_embd_id(cls, doc_id): docs = cls.model.select( Knowledgebase.embd_id).join( Knowledgebase, on=( - Knowledgebase.id == cls.model.kb_id)).where( + Knowledgebase.id == cls.model.kb_id)).where( cls.model.id == doc_id, Knowledgebase.status == StatusEnum.VALID.value) docs = docs.dicts() if not docs: @@ -396,7 +571,7 @@ def get_doc_id_by_doc_name(cls, doc_name): if not doc_id: return return doc_id[0]["id"] - + @classmethod @DB.connection_context() def get_doc_ids_by_doc_names(cls, doc_names): @@ -448,37 +623,82 @@ def get_doc_count(cls, tenant_id): @classmethod @DB.connection_context() - def begin2parse(cls, docid): - cls.update_by_id( - docid, {"progress": random.random() * 1 / 100., - "progress_msg": "Task is queued...", - "process_begin_at": get_format_time() - }) + def begin2parse(cls, doc_id, keep_progress=False): + info = { + "progress_msg": "Task is queued...", + "process_begin_at": get_format_time(), + } + if not keep_progress: + info["progress"] = random.random() * 1 / 100. + info["run"] = TaskStatus.RUNNING.value + # keep the doc in DONE state when keep_progress=True for GraphRAG, RAPTOR and Mindmap tasks + + cls.update_by_id(doc_id, info) @classmethod @DB.connection_context() def update_meta_fields(cls, doc_id, meta_fields): return cls.update_by_id(doc_id, {"meta_fields": meta_fields}) + @classmethod + @DB.connection_context() + def get_meta_by_kbs(cls, kb_ids): + fields = [ + cls.model.id, + cls.model.meta_fields, + ] + meta = {} + for r in cls.model.select(*fields).where(cls.model.kb_id.in_(kb_ids)): + doc_id = r.id + for k,v in r.meta_fields.items(): + if k not in meta: + meta[k] = {} + v = str(v) + if v not in meta[k]: + meta[k][v] = [] + meta[k][v].append(doc_id) + return meta + @classmethod @DB.connection_context() def update_progress(cls): docs = cls.get_unfinished_docs() + + cls._sync_progress(docs) + + + @classmethod + @DB.connection_context() + def update_progress_immediately(cls, docs:list[dict]): + if not docs: + return + + cls._sync_progress(docs) + + + @classmethod + @DB.connection_context() + def _sync_progress(cls, docs:list[dict]): + from api.db.services.task_service import TaskService + for d in docs: try: - tsks = Task.query(doc_id=d["id"], order_by=Task.create_time) + tsks = TaskService.query(doc_id=d["id"], order_by=Task.create_time) if not tsks: continue msg = [] prg = 0 finished = True bad = 0 - has_raptor = False - has_graphrag = False e, doc = DocumentService.get_by_id(d["id"]) status = doc.run # TaskStatus.RUNNING.value + doc_progress = doc.progress if doc and doc.progress else 0.0 + special_task_running = False priority = 0 for t in tsks: + task_type = (t.task_type or "").lower() + if task_type in PIPELINE_SPECIAL_PROGRESS_FREEZE_TASK_TYPES: + special_task_running = True if 0 <= t.progress < 1: finished = False if t.progress == -1: @@ -486,35 +706,29 @@ def update_progress(cls): prg += t.progress if t.progress >= 0 else 0 if t.progress_msg.strip(): msg.append(t.progress_msg) - if t.task_type == "raptor": - has_raptor = True - elif t.task_type == "graphrag": - has_graphrag = True priority = max(priority, t.priority) prg /= len(tsks) if finished and bad: prg = -1 status = TaskStatus.FAIL.value elif finished: - if d["parser_config"].get("raptor", {}).get("use_raptor") and not has_raptor: - queue_raptor_o_graphrag_tasks(d, "raptor", priority) - prg = 0.98 * len(tsks) / (len(tsks) + 1) - elif d["parser_config"].get("graphrag", {}).get("use_graphrag") and not has_graphrag: - queue_raptor_o_graphrag_tasks(d, "graphrag", priority) - prg = 0.98 * len(tsks) / (len(tsks) + 1) - else: - status = TaskStatus.DONE.value + prg = 1 + status = TaskStatus.DONE.value + # only for special task and parsed docs and unfinised + freeze_progress = special_task_running and doc_progress >= 1 and not finished msg = "\n".join(sorted(msg)) info = { - "process_duation": datetime.timestamp( + "process_duration": datetime.timestamp( datetime.now()) - - d["process_begin_at"].timestamp(), + d["process_begin_at"].timestamp(), "run": status} - if prg != 0: + if prg != 0 and not freeze_progress: info["progress"] = prg if msg: info["progress_msg"] = msg + if msg.endswith("created task graphrag") or msg.endswith("created task raptor") or msg.endswith("created task mindmap"): + info["progress_msg"] += "\n%d tasks are ahead in the queue..."%get_queue_length(priority) else: info["progress_msg"] = "%d tasks are ahead in the queue..."%get_queue_length(priority) cls.update_by_id(d["id"], info) @@ -525,8 +739,16 @@ def update_progress(cls): @classmethod @DB.connection_context() def get_kb_doc_count(cls, kb_id): - return len(cls.model.select(cls.model.id).where( - cls.model.kb_id == kb_id).dicts()) + return cls.model.select().where(cls.model.kb_id == kb_id).count() + + @classmethod + @DB.connection_context() + def get_all_kb_doc_count(cls): + result = {} + rows = cls.model.select(cls.model.kb_id, fn.COUNT(cls.model.id).alias('count')).group_by(cls.model.kb_id) + for row in rows: + result[row.kb_id] = row.count + return result @classmethod @DB.connection_context() @@ -539,21 +761,107 @@ def do_cancel(cls, doc_id): return False -def queue_raptor_o_graphrag_tasks(doc, ty, priority): - chunking_config = DocumentService.get_chunking_config(doc["id"]) + @classmethod + @DB.connection_context() + def knowledgebase_basic_info(cls, kb_id: str) -> dict[str, int]: + # cancelled: run == "2" but progress can vary + cancelled = ( + cls.model.select(fn.COUNT(1)) + .where((cls.model.kb_id == kb_id) & (cls.model.run == TaskStatus.CANCEL)) + .scalar() + ) + downloaded = ( + cls.model.select(fn.COUNT(1)) + .where( + cls.model.kb_id == kb_id, + cls.model.source_type != "local" + ) + .scalar() + ) + + row = ( + cls.model.select( + # finished: progress == 1 + fn.COALESCE(fn.SUM(Case(None, [(cls.model.progress == 1, 1)], 0)), 0).alias("finished"), + + # failed: progress == -1 + fn.COALESCE(fn.SUM(Case(None, [(cls.model.progress == -1, 1)], 0)), 0).alias("failed"), + + # processing: 0 <= progress < 1 + fn.COALESCE( + fn.SUM( + Case( + None, + [ + (((cls.model.progress == 0) | ((cls.model.progress > 0) & (cls.model.progress < 1))), 1), + ], + 0, + ) + ), + 0, + ).alias("processing"), + ) + .where( + (cls.model.kb_id == kb_id) + & ((cls.model.run.is_null(True)) | (cls.model.run != TaskStatus.CANCEL)) + ) + .dicts() + .get() + ) + + return { + "processing": int(row["processing"]), + "finished": int(row["finished"]), + "failed": int(row["failed"]), + "cancelled": int(cancelled), + "downloaded": int(downloaded) + } + + @classmethod + def run(cls, tenant_id:str, doc:dict, kb_table_num_map:dict): + from api.db.services.task_service import queue_dataflow, queue_tasks + from api.db.services.file2document_service import File2DocumentService + + doc["tenant_id"] = tenant_id + doc_parser = doc.get("parser_id", ParserType.NAIVE) + if doc_parser == ParserType.TABLE: + kb_id = doc.get("kb_id") + if not kb_id: + return + if kb_id not in kb_table_num_map: + count = DocumentService.count_by_kb_id(kb_id=kb_id, keywords="", run_status=[TaskStatus.DONE], types=[]) + kb_table_num_map[kb_id] = count + if kb_table_num_map[kb_id] <= 0: + KnowledgebaseService.delete_field_map(kb_id) + if doc.get("pipeline_id", ""): + queue_dataflow(tenant_id, flow_id=doc["pipeline_id"], task_id=get_uuid(), doc_id=doc["id"]) + else: + bucket, name = File2DocumentService.get_storage_address(doc_id=doc["id"]) + queue_tasks(doc, bucket, name, 0) + + +def queue_raptor_o_graphrag_tasks(sample_doc_id, ty, priority, fake_doc_id="", doc_ids=[]): + """ + You can provide a fake_doc_id to bypass the restriction of tasks at the knowledgebase level. + Optionally, specify a list of doc_ids to determine which documents participate in the task. + """ + assert ty in ["graphrag", "raptor", "mindmap"], "type should be graphrag, raptor or mindmap" + + chunking_config = DocumentService.get_chunking_config(sample_doc_id["id"]) hasher = xxhash.xxh64() for field in sorted(chunking_config.keys()): hasher.update(str(chunking_config[field]).encode("utf-8")) def new_task(): - nonlocal doc + nonlocal sample_doc_id return { "id": get_uuid(), - "doc_id": doc["id"], + "doc_id": sample_doc_id["id"], "from_page": 100000000, "to_page": 100000000, "task_type": ty, - "progress_msg": datetime.now().strftime("%H:%M:%S") + " created task " + ty + "progress_msg": datetime.now().strftime("%H:%M:%S") + " created task " + ty, + "begin_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), } task = new_task() @@ -562,12 +870,19 @@ def new_task(): hasher.update(ty.encode("utf-8")) task["digest"] = hasher.hexdigest() bulk_insert_into_db(Task, [task], True) - assert REDIS_CONN.queue_product(get_svr_queue_name(priority), message=task), "Can't access Redis. Please check the Redis' status." + + task["doc_id"] = fake_doc_id + task["doc_ids"] = doc_ids + DocumentService.begin2parse(sample_doc_id["id"], keep_progress=True) + assert REDIS_CONN.queue_product(settings.get_svr_queue_name(priority), message=task), "Can't access Redis. Please check the Redis' status." + return task["id"] def get_queue_length(priority): - group_info = REDIS_CONN.queue_info(get_svr_queue_name(priority), SVR_CONSUMER_GROUP_NAME) - return int(group_info.get("lag", 0)) + group_info = REDIS_CONN.queue_info(settings.get_svr_queue_name(priority), SVR_CONSUMER_GROUP_NAME) + if not group_info: + return 0 + return int(group_info.get("lag", 0) or 0) def doc_upload_and_parse(conversation_id, file_objs, user_id): @@ -646,7 +961,7 @@ def dummy(prog=None, msg=""): else: d["image"].save(output_buffer, format='JPEG') - STORAGE_IMPL.put(kb.id, d["id"], output_buffer.getvalue()) + settings.STORAGE_IMPL.put(kb.id, d["id"], output_buffer.getvalue()) d["img_id"] = "{}-{}".format(kb.id, d["id"]) d.pop("image", None) docs.append(d) @@ -693,7 +1008,7 @@ def embedding(doc_id, cnts, batch_size=16): "content_with_weight": mind_map, "knowledge_graph_kwd": "mind_map" }) - except Exception as e: + except Exception: logging.exception("Mind map generation error") vects = embedding(doc_id, [c["content_with_weight"] for c in cks]) diff --git a/api/db/services/file2document_service.py b/api/db/services/file2document_service.py index c03dbf92844..079ea783fad 100644 --- a/api/db/services/file2document_service.py +++ b/api/db/services/file2document_service.py @@ -15,12 +15,12 @@ # from datetime import datetime -from api.db import FileSource +from common.constants import FileSource from api.db.db_models import DB from api.db.db_models import File, File2Document from api.db.services.common_service import CommonService from api.db.services.document_service import DocumentService -from api.utils import current_timestamp, datetime_format +from common.time_utils import current_timestamp, datetime_format class File2DocumentService(CommonService): @@ -38,6 +38,12 @@ def get_by_document_id(cls, document_id): objs = cls.model.select().where(cls.model.document_id == document_id) return objs + @classmethod + @DB.connection_context() + def get_by_document_ids(cls, document_ids): + objs = cls.model.select().where(cls.model.document_id.in_(document_ids)) + return list(objs.dicts()) + @classmethod @DB.connection_context() def insert(cls, obj): @@ -50,6 +56,15 @@ def insert(cls, obj): def delete_by_file_id(cls, file_id): return cls.model.delete().where(cls.model.file_id == file_id).execute() + @classmethod + @DB.connection_context() + def delete_by_document_ids_or_file_ids(cls, document_ids, file_ids): + if not document_ids: + return cls.model.delete().where(cls.model.file_id.in_(file_ids)).execute() + elif not file_ids: + return cls.model.delete().where(cls.model.document_id.in_(document_ids)).execute() + return cls.model.delete().where(cls.model.document_id.in_(document_ids) | cls.model.file_id.in_(file_ids)).execute() + @classmethod @DB.connection_context() def delete_by_document_id(cls, doc_id): diff --git a/api/db/services/file_service.py b/api/db/services/file_service.py index 25c856531b5..5a3632e97d3 100644 --- a/api/db/services/file_service.py +++ b/api/db/services/file_service.py @@ -14,23 +14,26 @@ # limitations under the License. # import logging -import os import re from concurrent.futures import ThreadPoolExecutor +from pathlib import Path from flask_login import current_user from peewee import fn -from api.constants import FILE_NAME_LEN_LIMIT -from api.db import KNOWLEDGEBASE_FOLDER_NAME, FileSource, FileType, ParserType -from api.db.db_models import DB, Document, File, File2Document, Knowledgebase +from api.db import KNOWLEDGEBASE_FOLDER_NAME, FileType +from api.db.db_models import DB, Document, File, File2Document, Knowledgebase, Task from api.db.services import duplicate_name from api.db.services.common_service import CommonService from api.db.services.document_service import DocumentService from api.db.services.file2document_service import File2DocumentService -from api.utils import get_uuid +from common.misc_utils import get_uuid +from common.constants import TaskStatus, FileSource, ParserType +from api.db.services.knowledgebase_service import KnowledgebaseService +from api.db.services.task_service import TaskService from api.utils.file_utils import filename_type, read_potential_broken_pdf, thumbnail_img -from rag.utils.storage_factory import STORAGE_IMPL +from rag.llm.cv_model import GptV4 +from common import settings class FileService(CommonService): @@ -161,6 +164,23 @@ def get_all_innermost_file_ids(cls, folder_id, result_ids): result_ids.append(folder_id) return result_ids + @classmethod + @DB.connection_context() + def get_all_file_ids_by_tenant_id(cls, tenant_id): + fields = [cls.model.id] + files = cls.model.select(*fields).where(cls.model.tenant_id == tenant_id) + files.order_by(cls.model.create_time.asc()) + offset, limit = 0, 100 + res = [] + while True: + file_batch = files.offset(offset).limit(limit) + _temp = list(file_batch.dicts()) + if not _temp: + break + res.extend(_temp) + offset += limit + return res + @classmethod @DB.connection_context() def create_folder(cls, file, parent_id, name, count): @@ -227,10 +247,13 @@ def get_kb_folder(cls, tenant_id): # tenant_id: Tenant ID # Returns: # Knowledge base folder dictionary - for root in cls.model.select().where((cls.model.tenant_id == tenant_id), (cls.model.parent_id == cls.model.id)): - for folder in cls.model.select().where((cls.model.tenant_id == tenant_id), (cls.model.parent_id == root.id), (cls.model.name == KNOWLEDGEBASE_FOLDER_NAME)): - return folder.to_dict() - assert False, "Can't find the KB folder. Database init error." + root_folder = cls.get_root_folder(tenant_id) + root_id = root_folder["id"] + kb_folder = cls.model.select().where((cls.model.tenant_id == tenant_id), (cls.model.parent_id == root_id), (cls.model.name == KNOWLEDGEBASE_FOLDER_NAME)).first() + if not kb_folder: + kb_folder = cls.new_a_file_from_kb(tenant_id, KNOWLEDGEBASE_FOLDER_NAME, root_id) + return kb_folder + return kb_folder.to_dict() @classmethod @DB.connection_context() @@ -400,7 +423,7 @@ def move_file(cls, file_ids, folder_id): @classmethod @DB.connection_context() - def upload_document(self, kb, file_objs, user_id): + def upload_document(self, kb, file_objs, user_id, src="local"): root_folder = self.get_root_folder(user_id) pf_id = root_folder["id"] self.init_knowledgebase_docs(pf_id, user_id) @@ -410,25 +433,20 @@ def upload_document(self, kb, file_objs, user_id): err, files = [], [] for file in file_objs: try: - MAX_FILE_NUM_PER_USER = int(os.environ.get("MAX_FILE_NUM_PER_USER", 0)) - if MAX_FILE_NUM_PER_USER > 0 and DocumentService.get_doc_count(kb.tenant_id) >= MAX_FILE_NUM_PER_USER: - raise RuntimeError("Exceed the maximum file number of a free user!") - if len(file.filename.encode("utf-8")) > FILE_NAME_LEN_LIMIT: - raise RuntimeError(f"File name must be {FILE_NAME_LEN_LIMIT} bytes or less.") - + DocumentService.check_doc_health(kb.tenant_id, file.filename) filename = duplicate_name(DocumentService.query, name=file.filename, kb_id=kb.id) filetype = filename_type(filename) if filetype == FileType.OTHER.value: raise RuntimeError("This type of file has not been supported yet!") location = filename - while STORAGE_IMPL.obj_exist(kb.id, location): + while settings.STORAGE_IMPL.obj_exist(kb.id, location): location += "_" blob = file.read() if filetype == FileType.PDF.value: blob = read_potential_broken_pdf(blob) - STORAGE_IMPL.put(kb.id, location, blob) + settings.STORAGE_IMPL.put(kb.id, location, blob) doc_id = get_uuid() @@ -436,16 +454,19 @@ def upload_document(self, kb, file_objs, user_id): thumbnail_location = "" if img is not None: thumbnail_location = f"thumbnail_{doc_id}.png" - STORAGE_IMPL.put(kb.id, thumbnail_location, img) + settings.STORAGE_IMPL.put(kb.id, thumbnail_location, img) doc = { "id": doc_id, "kb_id": kb.id, "parser_id": self.get_parser(filetype, filename, kb.parser_id), + "pipeline_id": kb.pipeline_id, "parser_config": kb.parser_config, "created_by": user_id, "type": filetype, "name": filename, + "source_type": src, + "suffix": Path(filename).suffix.lstrip("."), "location": location, "size": len(blob), "thumbnail": thumbnail_location, @@ -459,29 +480,45 @@ def upload_document(self, kb, file_objs, user_id): return err, files + @classmethod + @DB.connection_context() + def list_all_files_by_parent_id(cls, parent_id): + try: + files = cls.model.select().where((cls.model.parent_id == parent_id) & (cls.model.id != parent_id)) + return list(files) + except Exception: + logging.exception("list_by_parent_id failed") + raise RuntimeError("Database error (list_by_parent_id)!") + @staticmethod def parse_docs(file_objs, user_id): - from rag.app import audio, email, naive, picture, presentation - - def dummy(prog=None, msg=""): - pass - - FACTORY = {ParserType.PRESENTATION.value: presentation, ParserType.PICTURE.value: picture, ParserType.AUDIO.value: audio, ParserType.EMAIL.value: email} - parser_config = {"chunk_token_num": 16096, "delimiter": "\n!?;。;!?", "layout_recognize": "Plain Text"} exe = ThreadPoolExecutor(max_workers=12) threads = [] for file in file_objs: - kwargs = {"lang": "English", "callback": dummy, "parser_config": parser_config, "from_page": 0, "to_page": 100000, "tenant_id": user_id} - filetype = filename_type(file.filename) - blob = file.read() - threads.append(exe.submit(FACTORY.get(FileService.get_parser(filetype, file.filename, ""), naive).chunk, file.filename, blob, **kwargs)) + threads.append(exe.submit(FileService.parse, file.filename, file.read(), False)) res = [] for th in threads: - res.append("\n".join([ck["content_with_weight"] for ck in th.result()])) + res.append(th.result()) return "\n\n".join(res) + @staticmethod + def parse(filename, blob, img_base64=True, tenant_id=None): + from rag.app import audio, email, naive, picture, presentation + + def dummy(prog=None, msg=""): + pass + + FACTORY = {ParserType.PRESENTATION.value: presentation, ParserType.PICTURE.value: picture, ParserType.AUDIO.value: audio, ParserType.EMAIL.value: email} + parser_config = {"chunk_token_num": 16096, "delimiter": "\n!?;。;!?", "layout_recognize": "Plain Text"} + kwargs = {"lang": "English", "callback": dummy, "parser_config": parser_config, "from_page": 0, "to_page": 100000, "tenant_id": current_user.id if current_user else tenant_id} + file_type = filename_type(filename) + if img_base64 and file_type == FileType.VISUAL.value: + return GptV4.image2base64(blob) + cks = FACTORY.get(FileService.get_parser(filename_type(filename), filename, ""), naive).chunk(filename, blob, **kwargs) + return "\n".join([ck["content_with_weight"] for ck in cks]) + @staticmethod def get_parser(doc_type, filename, default): if doc_type == FileType.VISUAL: @@ -490,6 +527,61 @@ def get_parser(doc_type, filename, default): return ParserType.AUDIO.value if re.search(r"\.(ppt|pptx|pages)$", filename): return ParserType.PRESENTATION.value - if re.search(r"\.(eml)$", filename): + if re.search(r"\.(msg|eml)$", filename): return ParserType.EMAIL.value return default + + @staticmethod + def get_blob(user_id, location): + bname = f"{user_id}-downloads" + return settings.STORAGE_IMPL.get(bname, location) + + @staticmethod + def put_blob(user_id, location, blob): + bname = f"{user_id}-downloads" + return settings.STORAGE_IMPL.put(bname, location, blob) + + @classmethod + @DB.connection_context() + def delete_docs(cls, doc_ids, tenant_id): + root_folder = FileService.get_root_folder(tenant_id) + pf_id = root_folder["id"] + FileService.init_knowledgebase_docs(pf_id, tenant_id) + errors = "" + kb_table_num_map = {} + for doc_id in doc_ids: + try: + e, doc = DocumentService.get_by_id(doc_id) + if not e: + raise Exception("Document not found!") + tenant_id = DocumentService.get_tenant_id(doc_id) + if not tenant_id: + raise Exception("Tenant not found!") + + b, n = File2DocumentService.get_storage_address(doc_id=doc_id) + + TaskService.filter_delete([Task.doc_id == doc_id]) + if not DocumentService.remove_document(doc, tenant_id): + raise Exception("Database error (Document removal)!") + + f2d = File2DocumentService.get_by_document_id(doc_id) + deleted_file_count = 0 + if f2d: + deleted_file_count = FileService.filter_delete([File.source_type == FileSource.KNOWLEDGEBASE, File.id == f2d[0].file_id]) + File2DocumentService.delete_by_document_id(doc_id) + if deleted_file_count > 0: + settings.STORAGE_IMPL.rm(b, n) + + doc_parser = doc.parser_id + if doc_parser == ParserType.TABLE: + kb_id = doc.kb_id + if kb_id not in kb_table_num_map: + counts = DocumentService.count_by_kb_id(kb_id=kb_id, keywords="", run_status=[TaskStatus.DONE], types=[]) + kb_table_num_map[kb_id] = counts + kb_table_num_map[kb_id] -= 1 + if kb_table_num_map[kb_id] <= 0: + KnowledgebaseService.delete_field_map(kb_id) + except Exception as e: + errors += str(e) + + return errors diff --git a/api/db/services/knowledgebase_service.py b/api/db/services/knowledgebase_service.py index 454bdbdc746..03179da49bf 100644 --- a/api/db/services/knowledgebase_service.py +++ b/api/db/services/knowledgebase_service.py @@ -15,13 +15,18 @@ # from datetime import datetime -from peewee import fn +from peewee import fn, JOIN -from api.db import StatusEnum, TenantPermission -from api.db.db_models import DB, Document, Knowledgebase, Tenant, User, UserTenant +from api.db import TenantPermission +from api.db.db_models import DB, Document, Knowledgebase, User, UserTenant, UserCanvas from api.db.services.common_service import CommonService -from api.utils import current_timestamp, datetime_format - +from common.time_utils import current_timestamp, datetime_format +from api.db.services import duplicate_name +from api.db.services.user_service import TenantService +from common.misc_utils import get_uuid +from common.constants import StatusEnum +from api.constants import DATASET_NAME_LIMIT +from api.utils.api_utils import get_parser_config, get_data_error_result class KnowledgebaseService(CommonService): """Service class for managing knowledge base operations. @@ -87,7 +92,7 @@ def is_parsed_done(cls, kb_id): # Returns: # If all documents are parsed successfully, returns (True, None) # If any document is not fully parsed, returns (False, error_message) - from api.db import TaskStatus + from common.constants import TaskStatus from api.db.services.document_service import DocumentService # Get knowledge base information @@ -190,6 +195,42 @@ def get_by_tenant_ids(cls, joined_tenant_ids, user_id, return list(kbs.dicts()), count + @classmethod + @DB.connection_context() + def get_all_kb_by_tenant_ids(cls, tenant_ids, user_id): + # will get all permitted kb, be cautious. + fields = [ + cls.model.name, + cls.model.avatar, + cls.model.language, + cls.model.permission, + cls.model.doc_num, + cls.model.token_num, + cls.model.chunk_num, + cls.model.status, + cls.model.create_date, + cls.model.update_date + ] + # find team kb and owned kb + kbs = cls.model.select(*fields).where( + (cls.model.tenant_id.in_(tenant_ids) & (cls.model.permission ==TenantPermission.TEAM.value)) | ( + cls.model.tenant_id == user_id + ) + ) + # sort by create_time asc + kbs.order_by(cls.model.create_time.asc()) + # maybe cause slow query by deep paginate, optimize later. + offset, limit = 0, 50 + res = [] + while True: + kb_batch = kbs.offset(offset).limit(limit) + _temp = list(kb_batch.dicts()) + if not _temp: + break + res.extend(_temp) + offset += limit + return res + @classmethod @DB.connection_context() def get_kb_ids(cls, tenant_id): @@ -225,20 +266,29 @@ def get_detail(cls, kb_id): cls.model.token_num, cls.model.chunk_num, cls.model.parser_id, + cls.model.pipeline_id, + UserCanvas.title.alias("pipeline_name"), + UserCanvas.avatar.alias("pipeline_avatar"), cls.model.parser_config, cls.model.pagerank, + cls.model.graphrag_task_id, + cls.model.graphrag_task_finish_at, + cls.model.raptor_task_id, + cls.model.raptor_task_finish_at, + cls.model.mindmap_task_id, + cls.model.mindmap_task_finish_at, cls.model.create_time, cls.model.update_time ] - kbs = cls.model.select(*fields).join(Tenant, on=( - (Tenant.id == cls.model.tenant_id) & (Tenant.status == StatusEnum.VALID.value))).where( + kbs = cls.model.select(*fields)\ + .join(UserCanvas, on=(cls.model.pipeline_id == UserCanvas.id), join_type=JOIN.LEFT_OUTER)\ + .where( (cls.model.id == kb_id), (cls.model.status == StatusEnum.VALID.value) - ) + ).dicts() if not kbs: - return - d = kbs[0].to_dict() - return d + return None + return kbs[0] @classmethod @DB.connection_context() @@ -319,6 +369,64 @@ def get_all_ids(cls): # List of all knowledge base IDs return [m["id"] for m in cls.model.select(cls.model.id).dicts()] + + @classmethod + @DB.connection_context() + def create_with_name( + cls, + *, + name: str, + tenant_id: str, + parser_id: str | None = None, + **kwargs + ): + """Create a dataset (knowledgebase) by name with kb_app defaults. + + This encapsulates the creation logic used in kb_app.create so other callers + (including RESTFul endpoints) can reuse the same behavior. + + Returns: + (ok: bool, model_or_msg): On success, returns (True, Knowledgebase model instance); + on failure, returns (False, error_message). + """ + # Validate name + if not isinstance(name, str): + return get_data_error_result(message="Dataset name must be string.") + dataset_name = name.strip() + if dataset_name == "": + return get_data_error_result(message="Dataset name can't be empty.") + if len(dataset_name.encode("utf-8")) > DATASET_NAME_LIMIT: + return get_data_error_result(message=f"Dataset name length is {len(dataset_name)} which is larger than {DATASET_NAME_LIMIT}") + + # Deduplicate name within tenant + dataset_name = duplicate_name( + cls.query, + name=dataset_name, + tenant_id=tenant_id, + status=StatusEnum.VALID.value, + ) + + # Verify tenant exists + ok, _t = TenantService.get_by_id(tenant_id) + if not ok: + return False, "Tenant not found." + + # Build payload + kb_id = get_uuid() + payload = { + "id": kb_id, + "name": dataset_name, + "tenant_id": tenant_id, + "created_by": tenant_id, + "parser_id": (parser_id or "naive"), + **kwargs + } + + # Default parser_config (align with kb_app.create) — do not accept external overrides + payload["parser_config"] = get_parser_config(parser_id, kwargs.get("parser_config")) + return payload + + @classmethod @DB.connection_context() def get_list(cls, joined_tenant_ids, user_id, @@ -335,6 +443,7 @@ def get_list(cls, joined_tenant_ids, user_id, # name: Optional name filter # Returns: # List of knowledge bases + # Total count of knowledge bases kbs = cls.model.select() if id: kbs = kbs.where(cls.model.id == id) @@ -346,14 +455,16 @@ def get_list(cls, joined_tenant_ids, user_id, cls.model.tenant_id == user_id)) & (cls.model.status == StatusEnum.VALID.value) ) + if desc: kbs = kbs.order_by(cls.model.getter_by(orderby).desc()) else: kbs = kbs.order_by(cls.model.getter_by(orderby).asc()) + total = kbs.count() kbs = kbs.paginate(page_number, items_per_page) - return list(kbs.dicts()) + return list(kbs.dicts()), total @classmethod @DB.connection_context() @@ -436,3 +547,17 @@ def update_document_number_in_init(cls, kb_id, doc_num): else: raise e + @classmethod + @DB.connection_context() + def decrease_document_num_in_delete(cls, kb_id, doc_num_info: dict): + kb_row = cls.model.get_by_id(kb_id) + if not kb_row: + raise RuntimeError(f"kb_id {kb_id} does not exist") + update_dict = { + 'doc_num': kb_row.doc_num - doc_num_info['doc_num'], + 'chunk_num': kb_row.chunk_num - doc_num_info['chunk_num'], + 'token_num': kb_row.token_num - doc_num_info['token_num'], + 'update_time': current_timestamp(), + 'update_date': datetime_format(datetime.now()) + } + return cls.model.update(update_dict).where(cls.model.id == kb_id).execute() diff --git a/api/db/services/langfuse_service.py b/api/db/services/langfuse_service.py index c75f3d12ec0..af4233bec83 100644 --- a/api/db/services/langfuse_service.py +++ b/api/db/services/langfuse_service.py @@ -20,7 +20,7 @@ from api.db.db_models import DB, TenantLangfuse from api.db.services.common_service import CommonService -from api.utils import current_timestamp, datetime_format +from common.time_utils import current_timestamp, datetime_format class TenantLangfuseService(CommonService): @@ -51,6 +51,11 @@ def filter_by_tenant_with_info(cls, tenant_id): except peewee.DoesNotExist: return None + @classmethod + @DB.connection_context() + def delete_ty_tenant_id(cls, tenant_id): + return cls.model.delete().where(cls.model.tenant_id == tenant_id).execute() + @classmethod def update_by_tenant(cls, tenant_id, langfuse_keys): langfuse_keys["update_time"] = current_timestamp() diff --git a/api/db/services/llm_service.py b/api/db/services/llm_service.py index e124b5b16ac..6ccbf5a94b1 100644 --- a/api/db/services/llm_service.py +++ b/api/db/services/llm_service.py @@ -13,216 +13,64 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import inspect import logging - -from langfuse import Langfuse - -from api import settings -from api.db import LLMType -from api.db.db_models import DB, LLM, LLMFactories, TenantLLM +import re +from common.token_utils import num_tokens_from_string +from functools import partial +from typing import Generator +from api.db.db_models import LLM from api.db.services.common_service import CommonService -from api.db.services.langfuse_service import TenantLangfuseService -from api.db.services.user_service import TenantService -from rag.llm import ChatModel, CvModel, EmbeddingModel, RerankModel, Seq2txtModel, TTSModel - - -class LLMFactoriesService(CommonService): - model = LLMFactories +from api.db.services.tenant_llm_service import LLM4Tenant, TenantLLMService class LLMService(CommonService): model = LLM -class TenantLLMService(CommonService): - model = TenantLLM - - @classmethod - @DB.connection_context() - def get_api_key(cls, tenant_id, model_name): - mdlnm, fid = TenantLLMService.split_model_name_and_factory(model_name) - if not fid: - objs = cls.query(tenant_id=tenant_id, llm_name=mdlnm) - else: - objs = cls.query(tenant_id=tenant_id, llm_name=mdlnm, llm_factory=fid) - if not objs: - return - return objs[0] - - @classmethod - @DB.connection_context() - def get_my_llms(cls, tenant_id): - fields = [cls.model.llm_factory, LLMFactories.logo, LLMFactories.tags, cls.model.model_type, cls.model.llm_name, cls.model.used_tokens] - objs = cls.model.select(*fields).join(LLMFactories, on=(cls.model.llm_factory == LLMFactories.name)).where(cls.model.tenant_id == tenant_id, ~cls.model.api_key.is_null()).dicts() - - return list(objs) - - @staticmethod - def split_model_name_and_factory(model_name): - arr = model_name.split("@") - if len(arr) < 2: - return model_name, None - if len(arr) > 2: - return "@".join(arr[0:-1]), arr[-1] - - # model name must be xxx@yyy - try: - model_factories = settings.FACTORY_LLM_INFOS - model_providers = set([f["name"] for f in model_factories]) - if arr[-1] not in model_providers: - return model_name, None - return arr[0], arr[-1] - except Exception as e: - logging.exception(f"TenantLLMService.split_model_name_and_factory got exception: {e}") - return model_name, None - - @classmethod - @DB.connection_context() - def get_model_config(cls, tenant_id, llm_type, llm_name=None): - e, tenant = TenantService.get_by_id(tenant_id) - if not e: - raise LookupError("Tenant not found") - - if llm_type == LLMType.EMBEDDING.value: - mdlnm = tenant.embd_id if not llm_name else llm_name - elif llm_type == LLMType.SPEECH2TEXT.value: - mdlnm = tenant.asr_id - elif llm_type == LLMType.IMAGE2TEXT.value: - mdlnm = tenant.img2txt_id if not llm_name else llm_name - elif llm_type == LLMType.CHAT.value: - mdlnm = tenant.llm_id if not llm_name else llm_name - elif llm_type == LLMType.RERANK: - mdlnm = tenant.rerank_id if not llm_name else llm_name - elif llm_type == LLMType.TTS: - mdlnm = tenant.tts_id if not llm_name else llm_name - else: - assert False, "LLM type error" - - model_config = cls.get_api_key(tenant_id, mdlnm) - mdlnm, fid = TenantLLMService.split_model_name_and_factory(mdlnm) - if not model_config: # for some cases seems fid mismatch - model_config = cls.get_api_key(tenant_id, mdlnm) - if model_config: - model_config = model_config.to_dict() - llm = LLMService.query(llm_name=mdlnm) if not fid else LLMService.query(llm_name=mdlnm, fid=fid) - if not llm and fid: # for some cases seems fid mismatch - llm = LLMService.query(llm_name=mdlnm) - if llm: - model_config["is_tools"] = llm[0].is_tools - if not model_config: - if llm_type in [LLMType.EMBEDDING, LLMType.RERANK]: - llm = LLMService.query(llm_name=mdlnm) if not fid else LLMService.query(llm_name=mdlnm, fid=fid) - if llm and llm[0].fid in ["Youdao", "FastEmbed", "BAAI"]: - model_config = {"llm_factory": llm[0].fid, "api_key": "", "llm_name": mdlnm, "api_base": ""} - if not model_config: - if mdlnm == "flag-embedding": - model_config = {"llm_factory": "Tongyi-Qianwen", "api_key": "", "llm_name": llm_name, "api_base": ""} - else: - if not mdlnm: - raise LookupError(f"Type of {llm_type} model is not set.") - raise LookupError("Model({}) not authorized".format(mdlnm)) - return model_config - - @classmethod - @DB.connection_context() - def model_instance(cls, tenant_id, llm_type, llm_name=None, lang="Chinese"): - model_config = TenantLLMService.get_model_config(tenant_id, llm_type, llm_name) - if llm_type == LLMType.EMBEDDING.value: - if model_config["llm_factory"] not in EmbeddingModel: - return - return EmbeddingModel[model_config["llm_factory"]](model_config["api_key"], model_config["llm_name"], base_url=model_config["api_base"]) - - if llm_type == LLMType.RERANK: - if model_config["llm_factory"] not in RerankModel: - return - return RerankModel[model_config["llm_factory"]](model_config["api_key"], model_config["llm_name"], base_url=model_config["api_base"]) - - if llm_type == LLMType.IMAGE2TEXT.value: - if model_config["llm_factory"] not in CvModel: - return - return CvModel[model_config["llm_factory"]](model_config["api_key"], model_config["llm_name"], lang, base_url=model_config["api_base"]) +def get_init_tenant_llm(user_id): + from common import settings + tenant_llm = [] + + seen = set() + factory_configs = [] + for factory_config in [ + settings.CHAT_CFG, + settings.EMBEDDING_CFG, + settings.ASR_CFG, + settings.IMAGE2TEXT_CFG, + settings.RERANK_CFG, + ]: + factory_name = factory_config["factory"] + if factory_name not in seen: + seen.add(factory_name) + factory_configs.append(factory_config) + + for factory_config in factory_configs: + for llm in LLMService.query(fid=factory_config["factory"]): + tenant_llm.append( + { + "tenant_id": user_id, + "llm_factory": factory_config["factory"], + "llm_name": llm.llm_name, + "model_type": llm.model_type, + "api_key": factory_config["api_key"], + "api_base": factory_config["base_url"], + "max_tokens": llm.max_tokens if llm.max_tokens else 8192, + } + ) - if llm_type == LLMType.CHAT.value: - if model_config["llm_factory"] not in ChatModel: - return - return ChatModel[model_config["llm_factory"]](model_config["api_key"], model_config["llm_name"], base_url=model_config["api_base"]) + unique = {} + for item in tenant_llm: + key = (item["tenant_id"], item["llm_factory"], item["llm_name"]) + if key not in unique: + unique[key] = item + return list(unique.values()) - if llm_type == LLMType.SPEECH2TEXT: - if model_config["llm_factory"] not in Seq2txtModel: - return - return Seq2txtModel[model_config["llm_factory"]](key=model_config["api_key"], model_name=model_config["llm_name"], lang=lang, base_url=model_config["api_base"]) - if llm_type == LLMType.TTS: - if model_config["llm_factory"] not in TTSModel: - return - return TTSModel[model_config["llm_factory"]]( - model_config["api_key"], - model_config["llm_name"], - base_url=model_config["api_base"], - ) - @classmethod - @DB.connection_context() - def increase_usage(cls, tenant_id, llm_type, used_tokens, llm_name=None): - e, tenant = TenantService.get_by_id(tenant_id) - if not e: - logging.error(f"Tenant not found: {tenant_id}") - return 0 - - llm_map = { - LLMType.EMBEDDING.value: tenant.embd_id if not llm_name else llm_name, - LLMType.SPEECH2TEXT.value: tenant.asr_id, - LLMType.IMAGE2TEXT.value: tenant.img2txt_id, - LLMType.CHAT.value: tenant.llm_id if not llm_name else llm_name, - LLMType.RERANK.value: tenant.rerank_id if not llm_name else llm_name, - LLMType.TTS.value: tenant.tts_id if not llm_name else llm_name, - } - - mdlnm = llm_map.get(llm_type) - if mdlnm is None: - logging.error(f"LLM type error: {llm_type}") - return 0 - - llm_name, llm_factory = TenantLLMService.split_model_name_and_factory(mdlnm) - - try: - num = ( - cls.model.update(used_tokens=cls.model.used_tokens + used_tokens) - .where(cls.model.tenant_id == tenant_id, cls.model.llm_name == llm_name, cls.model.llm_factory == llm_factory if llm_factory else True) - .execute() - ) - except Exception: - logging.exception("TenantLLMService.increase_usage got exception,Failed to update used_tokens for tenant_id=%s, llm_name=%s", tenant_id, llm_name) - return 0 - - return num - - @classmethod - @DB.connection_context() - def get_openai_models(cls): - objs = cls.model.select().where((cls.model.llm_factory == "OpenAI"), ~(cls.model.llm_name == "text-embedding-3-small"), ~(cls.model.llm_name == "text-embedding-3-large")).dicts() - return list(objs) - - -class LLMBundle: - def __init__(self, tenant_id, llm_type, llm_name=None, lang="Chinese"): - self.tenant_id = tenant_id - self.llm_type = llm_type - self.llm_name = llm_name - self.mdl = TenantLLMService.model_instance(tenant_id, llm_type, llm_name, lang=lang) - assert self.mdl, "Can't find model for {}/{}/{}".format(tenant_id, llm_type, llm_name) - model_config = TenantLLMService.get_model_config(tenant_id, llm_type, llm_name) - self.max_length = model_config.get("max_tokens", 8192) - - self.is_tools = model_config.get("is_tools", False) - - langfuse_keys = TenantLangfuseService.filter_by_tenant(tenant_id=tenant_id) - if langfuse_keys: - langfuse = Langfuse(public_key=langfuse_keys.public_key, secret_key=langfuse_keys.secret_key, host=langfuse_keys.host) - if langfuse.auth_check(): - self.langfuse = langfuse - self.trace = self.langfuse.trace(name=f"{self.llm_type}-{self.llm_name}") - else: - self.langfuse = None +class LLMBundle(LLM4Tenant): + def __init__(self, tenant_id, llm_type, llm_name=None, lang="Chinese", **kwargs): + super().__init__(tenant_id, llm_type, llm_name, lang, **kwargs) def bind_tools(self, toolcall_session, tools): if not self.is_tools: @@ -232,21 +80,32 @@ def bind_tools(self, toolcall_session, tools): def encode(self, texts: list): if self.langfuse: - generation = self.trace.generation(name="encode", model=self.llm_name, input={"texts": texts}) + generation = self.langfuse.start_generation(trace_context=self.trace_context, name="encode", model=self.llm_name, input={"texts": texts}) + + safe_texts = [] + for text in texts: + token_size = num_tokens_from_string(text) + if token_size > self.max_length: + target_len = int(self.max_length * 0.95) + safe_texts.append(text[:target_len]) + else: + safe_texts.append(text) + + embeddings, used_tokens = self.mdl.encode(safe_texts) - embeddings, used_tokens = self.mdl.encode(texts) llm_name = getattr(self, "llm_name", None) if not TenantLLMService.increase_usage(self.tenant_id, self.llm_type, used_tokens, llm_name): logging.error("LLMBundle.encode can't update token usage for {}/EMBEDDING used_tokens: {}".format(self.tenant_id, used_tokens)) if self.langfuse: - generation.end(usage_details={"total_tokens": used_tokens}) + generation.update(usage_details={"total_tokens": used_tokens}) + generation.end() return embeddings, used_tokens def encode_queries(self, query: str): if self.langfuse: - generation = self.trace.generation(name="encode_queries", model=self.llm_name, input={"query": query}) + generation = self.langfuse.start_generation(trace_context=self.trace_context, name="encode_queries", model=self.llm_name, input={"query": query}) emd, used_tokens = self.mdl.encode_queries(query) llm_name = getattr(self, "llm_name", None) @@ -254,65 +113,70 @@ def encode_queries(self, query: str): logging.error("LLMBundle.encode_queries can't update token usage for {}/EMBEDDING used_tokens: {}".format(self.tenant_id, used_tokens)) if self.langfuse: - generation.end(usage_details={"total_tokens": used_tokens}) + generation.update(usage_details={"total_tokens": used_tokens}) + generation.end() return emd, used_tokens def similarity(self, query: str, texts: list): if self.langfuse: - generation = self.trace.generation(name="similarity", model=self.llm_name, input={"query": query, "texts": texts}) + generation = self.langfuse.start_generation(trace_context=self.trace_context, name="similarity", model=self.llm_name, input={"query": query, "texts": texts}) sim, used_tokens = self.mdl.similarity(query, texts) if not TenantLLMService.increase_usage(self.tenant_id, self.llm_type, used_tokens): logging.error("LLMBundle.similarity can't update token usage for {}/RERANK used_tokens: {}".format(self.tenant_id, used_tokens)) if self.langfuse: - generation.end(usage_details={"total_tokens": used_tokens}) + generation.update(usage_details={"total_tokens": used_tokens}) + generation.end() return sim, used_tokens def describe(self, image, max_tokens=300): if self.langfuse: - generation = self.trace.generation(name="describe", metadata={"model": self.llm_name}) + generation = self.langfuse.start_generation(trace_context=self.trace_context, name="describe", metadata={"model": self.llm_name}) txt, used_tokens = self.mdl.describe(image) if not TenantLLMService.increase_usage(self.tenant_id, self.llm_type, used_tokens): logging.error("LLMBundle.describe can't update token usage for {}/IMAGE2TEXT used_tokens: {}".format(self.tenant_id, used_tokens)) if self.langfuse: - generation.end(output={"output": txt}, usage_details={"total_tokens": used_tokens}) + generation.update(output={"output": txt}, usage_details={"total_tokens": used_tokens}) + generation.end() return txt def describe_with_prompt(self, image, prompt): if self.langfuse: - generation = self.trace.generation(name="describe_with_prompt", metadata={"model": self.llm_name, "prompt": prompt}) + generation = self.langfuse.start_generation(trace_context=self.trace_context, name="describe_with_prompt", metadata={"model": self.llm_name, "prompt": prompt}) txt, used_tokens = self.mdl.describe_with_prompt(image, prompt) if not TenantLLMService.increase_usage(self.tenant_id, self.llm_type, used_tokens): logging.error("LLMBundle.describe can't update token usage for {}/IMAGE2TEXT used_tokens: {}".format(self.tenant_id, used_tokens)) if self.langfuse: - generation.end(output={"output": txt}, usage_details={"total_tokens": used_tokens}) + generation.update(output={"output": txt}, usage_details={"total_tokens": used_tokens}) + generation.end() return txt def transcription(self, audio): if self.langfuse: - generation = self.trace.generation(name="transcription", metadata={"model": self.llm_name}) + generation = self.langfuse.start_generation(trace_context=self.trace_context, name="transcription", metadata={"model": self.llm_name}) txt, used_tokens = self.mdl.transcription(audio) if not TenantLLMService.increase_usage(self.tenant_id, self.llm_type, used_tokens): logging.error("LLMBundle.transcription can't update token usage for {}/SEQUENCE2TXT used_tokens: {}".format(self.tenant_id, used_tokens)) if self.langfuse: - generation.end(output={"output": txt}, usage_details={"total_tokens": used_tokens}) + generation.update(output={"output": txt}, usage_details={"total_tokens": used_tokens}) + generation.end() return txt - def tts(self, text): + def tts(self, text: str) -> Generator[bytes, None, None]: if self.langfuse: - span = self.trace.span(name="tts", input={"text": text}) + generation = self.langfuse.start_generation(trace_context=self.trace_context, name="tts", input={"text": text}) for chunk in self.mdl.tts(text): if isinstance(chunk, int): @@ -322,7 +186,7 @@ def tts(self, text): yield chunk if self.langfuse: - span.end() + generation.end() def _remove_reasoning_content(self, txt: str) -> str: first_think_start = txt.find("") @@ -338,47 +202,73 @@ def _remove_reasoning_content(self, txt: str) -> str: return txt[last_think_end + len("") :] - def chat(self, system, history, gen_conf): + @staticmethod + def _clean_param(chat_partial, **kwargs): + func = chat_partial.func + sig = inspect.signature(func) + support_var_args = False + allowed_params = set() + + for param in sig.parameters.values(): + if param.kind == inspect.Parameter.VAR_KEYWORD: + support_var_args = True + elif param.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD, inspect.Parameter.KEYWORD_ONLY): + allowed_params.add(param.name) + if support_var_args: + return kwargs + else: + return {k: v for k, v in kwargs.items() if k in allowed_params} + def chat(self, system: str, history: list, gen_conf: dict = {}, **kwargs) -> str: if self.langfuse: - generation = self.trace.generation(name="chat", model=self.llm_name, input={"system": system, "history": history}) + generation = self.langfuse.start_generation(trace_context=self.trace_context, name="chat", model=self.llm_name, input={"system": system, "history": history}) - chat = self.mdl.chat + chat_partial = partial(self.mdl.chat, system, history, gen_conf, **kwargs) if self.is_tools and self.mdl.is_tools: - chat = self.mdl.chat_with_tools + chat_partial = partial(self.mdl.chat_with_tools, system, history, gen_conf, **kwargs) - txt, used_tokens = chat(system, history, gen_conf) + use_kwargs = self._clean_param(chat_partial, **kwargs) + txt, used_tokens = chat_partial(**use_kwargs) txt = self._remove_reasoning_content(txt) + if not self.verbose_tool_use: + txt = re.sub(r".*?", "", txt, flags=re.DOTALL) + if isinstance(txt, int) and not TenantLLMService.increase_usage(self.tenant_id, self.llm_type, used_tokens, self.llm_name): logging.error("LLMBundle.chat can't update token usage for {}/CHAT llm_name: {}, used_tokens: {}".format(self.tenant_id, self.llm_name, used_tokens)) if self.langfuse: - generation.end(output={"output": txt}, usage_details={"total_tokens": used_tokens}) + generation.update(output={"output": txt}, usage_details={"total_tokens": used_tokens}) + generation.end() return txt - def chat_streamly(self, system, history, gen_conf): + def chat_streamly(self, system: str, history: list, gen_conf: dict = {}, **kwargs): if self.langfuse: - generation = self.trace.generation(name="chat_streamly", model=self.llm_name, input={"system": system, "history": history}) + generation = self.langfuse.start_generation(trace_context=self.trace_context, name="chat_streamly", model=self.llm_name, input={"system": system, "history": history}) ans = "" - chat_streamly = self.mdl.chat_streamly + chat_partial = partial(self.mdl.chat_streamly, system, history, gen_conf) total_tokens = 0 if self.is_tools and self.mdl.is_tools: - chat_streamly = self.mdl.chat_streamly_with_tools - - for txt in chat_streamly(system, history, gen_conf): + chat_partial = partial(self.mdl.chat_streamly_with_tools, system, history, gen_conf) + use_kwargs = self._clean_param(chat_partial, **kwargs) + for txt in chat_partial(**use_kwargs): if isinstance(txt, int): total_tokens = txt if self.langfuse: - generation.end(output={"output": ans}) + generation.update(output={"output": ans}) + generation.end() break if txt.endswith(""): - ans = ans.rstrip("") + ans = ans[: -len("")] + + if not self.verbose_tool_use: + txt = re.sub(r".*?", "", txt, flags=re.DOTALL) ans += txt yield ans + if total_tokens > 0: if not TenantLLMService.increase_usage(self.tenant_id, self.llm_type, txt, self.llm_name): logging.error("LLMBundle.chat_streamly can't update token usage for {}/CHAT llm_name: {}, content: {}".format(self.tenant_id, self.llm_name, txt)) diff --git a/api/db/services/mcp_server_service.py b/api/db/services/mcp_server_service.py new file mode 100644 index 00000000000..1eae882d6f3 --- /dev/null +++ b/api/db/services/mcp_server_service.py @@ -0,0 +1,92 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from peewee import fn + +from api.db.db_models import DB, MCPServer +from api.db.services.common_service import CommonService + + +class MCPServerService(CommonService): + """Service class for managing MCP server related database operations. + + This class extends CommonService to provide specialized functionality for MCP server management, + including MCP server creation, updates, and deletions. + + Attributes: + model: The MCPServer model class for database operations. + """ + + model = MCPServer + + @classmethod + @DB.connection_context() + def get_servers(cls, tenant_id: str, id_list: list[str] | None, page_number, items_per_page, orderby, desc, + keywords): + """Retrieve all MCP servers associated with a tenant. + + This method fetches all MCP servers for a given tenant, ordered by creation time. + It only includes fields for list display. + + Args: + tenant_id (str): The unique identifier of the tenant. + id_list (list[str]): Get servers by ID list. Will ignore this condition if None. + + Returns: + list[dict]: List of MCP server dictionaries containing MCP server details. + Returns None if no MCP servers are found. + """ + fields = [ + cls.model.id, + cls.model.name, + cls.model.server_type, + cls.model.url, + cls.model.description, + cls.model.variables, + cls.model.create_date, + cls.model.update_date, + ] + + query = cls.model.select(*fields).order_by(cls.model.create_time.desc()).where(cls.model.tenant_id == tenant_id) + + if id_list: + query = query.where(cls.model.id.in_(id_list)) + if keywords: + query = query.where(fn.LOWER(cls.model.name).contains(keywords.lower())) + if desc: + query = query.order_by(cls.model.getter_by(orderby).desc()) + else: + query = query.order_by(cls.model.getter_by(orderby).asc()) + if page_number and items_per_page: + query = query.paginate(page_number, items_per_page) + + servers = list(query.dicts()) + if not servers: + return None + return servers + + @classmethod + @DB.connection_context() + def get_by_name_and_tenant(cls, name: str, tenant_id: str): + try: + mcp_server = cls.model.query(name=name, tenant_id=tenant_id) + return bool(mcp_server), mcp_server + except Exception: + return False, None + + @classmethod + @DB.connection_context() + def delete_by_tenant_id(cls, tenant_id: str): + return cls.model.delete().where(cls.model.tenant_id == tenant_id).execute() diff --git a/api/db/services/pipeline_operation_log_service.py b/api/db/services/pipeline_operation_log_service.py new file mode 100644 index 00000000000..c3c333665ff --- /dev/null +++ b/api/db/services/pipeline_operation_log_service.py @@ -0,0 +1,264 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json +import logging +import os +from datetime import datetime, timedelta + +from peewee import fn + +from api.db import VALID_PIPELINE_TASK_TYPES, PipelineTaskType +from api.db.db_models import DB, Document, PipelineOperationLog +from api.db.services.canvas_service import UserCanvasService +from api.db.services.common_service import CommonService +from api.db.services.document_service import DocumentService +from api.db.services.knowledgebase_service import KnowledgebaseService +from api.db.services.task_service import GRAPH_RAPTOR_FAKE_DOC_ID +from common.misc_utils import get_uuid +from common.time_utils import current_timestamp, datetime_format + + +class PipelineOperationLogService(CommonService): + model = PipelineOperationLog + + @classmethod + def get_file_logs_fields(cls): + return [ + cls.model.id, + cls.model.document_id, + cls.model.tenant_id, + cls.model.kb_id, + cls.model.pipeline_id, + cls.model.pipeline_title, + cls.model.parser_id, + cls.model.document_name, + cls.model.document_suffix, + cls.model.document_type, + cls.model.source_from, + cls.model.progress, + cls.model.progress_msg, + cls.model.process_begin_at, + cls.model.process_duration, + cls.model.dsl, + cls.model.task_type, + cls.model.operation_status, + cls.model.avatar, + cls.model.status, + cls.model.create_time, + cls.model.create_date, + cls.model.update_time, + cls.model.update_date, + ] + + @classmethod + def get_dataset_logs_fields(cls): + return [ + cls.model.id, + cls.model.tenant_id, + cls.model.kb_id, + cls.model.progress, + cls.model.progress_msg, + cls.model.process_begin_at, + cls.model.process_duration, + cls.model.task_type, + cls.model.operation_status, + cls.model.avatar, + cls.model.status, + cls.model.create_time, + cls.model.create_date, + cls.model.update_time, + cls.model.update_date, + ] + + @classmethod + def save(cls, **kwargs): + """ + wrap this function in a transaction + """ + sample_obj = cls.model(**kwargs).save(force_insert=True) + return sample_obj + + @classmethod + @DB.connection_context() + def create(cls, document_id, pipeline_id, task_type, fake_document_ids=[], dsl: str = "{}"): + referred_document_id = document_id + + if referred_document_id == GRAPH_RAPTOR_FAKE_DOC_ID and fake_document_ids: + referred_document_id = fake_document_ids[0] + ok, document = DocumentService.get_by_id(referred_document_id) + if not ok: + logging.warning(f"Document for referred_document_id {referred_document_id} not found") + return None + DocumentService.update_progress_immediately([document.to_dict()]) + ok, document = DocumentService.get_by_id(referred_document_id) + if not ok: + logging.warning(f"Document for referred_document_id {referred_document_id} not found") + return None + if document.progress not in [1, -1]: + return None + operation_status = document.run + + if pipeline_id: + ok, user_pipeline = UserCanvasService.get_by_id(pipeline_id) + if not ok: + raise RuntimeError(f"Pipeline {pipeline_id} not found") + tenant_id = user_pipeline.user_id + title = user_pipeline.title + avatar = user_pipeline.avatar + else: + ok, kb_info = KnowledgebaseService.get_by_id(document.kb_id) + if not ok: + raise RuntimeError(f"Cannot find knowledge base {document.kb_id} for referred_document {referred_document_id}") + + tenant_id = kb_info.tenant_id + title = document.parser_id + avatar = document.thumbnail + + if task_type not in VALID_PIPELINE_TASK_TYPES: + raise ValueError(f"Invalid task type: {task_type}") + + if task_type in [PipelineTaskType.GRAPH_RAG, PipelineTaskType.RAPTOR, PipelineTaskType.MINDMAP]: + finish_at = document.process_begin_at + timedelta(seconds=document.process_duration) + if task_type == PipelineTaskType.GRAPH_RAG: + KnowledgebaseService.update_by_id( + document.kb_id, + {"graphrag_task_finish_at": finish_at}, + ) + elif task_type == PipelineTaskType.RAPTOR: + KnowledgebaseService.update_by_id( + document.kb_id, + {"raptor_task_finish_at": finish_at}, + ) + elif task_type == PipelineTaskType.MINDMAP: + KnowledgebaseService.update_by_id( + document.kb_id, + {"mindmap_task_finish_at": finish_at}, + ) + + log = dict( + id=get_uuid(), + document_id=document_id, # GRAPH_RAPTOR_FAKE_DOC_ID or real document_id + tenant_id=tenant_id, + kb_id=document.kb_id, + pipeline_id=pipeline_id, + pipeline_title=title, + parser_id=document.parser_id, + document_name=document.name, + document_suffix=document.suffix, + document_type=document.type, + source_from=document.source_type.split("/")[0], + progress=document.progress, + progress_msg=document.progress_msg, + process_begin_at=document.process_begin_at, + process_duration=document.process_duration, + dsl=json.loads(dsl), + task_type=task_type, + operation_status=operation_status, + avatar=avatar, + ) + log["create_time"] = current_timestamp() + log["create_date"] = datetime_format(datetime.now()) + log["update_time"] = current_timestamp() + log["update_date"] = datetime_format(datetime.now()) + + with DB.atomic(): + obj = cls.save(**log) + + limit = int(os.getenv("PIPELINE_OPERATION_LOG_LIMIT", 1000)) + total = cls.model.select().where(cls.model.kb_id == document.kb_id).count() + + if total > limit: + keep_ids = [m.id for m in cls.model.select(cls.model.id).where(cls.model.kb_id == document.kb_id).order_by(cls.model.create_time.desc()).limit(limit)] + + deleted = cls.model.delete().where(cls.model.kb_id == document.kb_id, cls.model.id.not_in(keep_ids)).execute() + logging.info(f"[PipelineOperationLogService] Cleaned {deleted} old logs, kept latest {limit} for {document.kb_id}") + + return obj + + @classmethod + @DB.connection_context() + def record_pipeline_operation(cls, document_id, pipeline_id, task_type, fake_document_ids=[]): + return cls.create(document_id=document_id, pipeline_id=pipeline_id, task_type=task_type, fake_document_ids=fake_document_ids) + + @classmethod + @DB.connection_context() + def get_file_logs_by_kb_id(cls, kb_id, page_number, items_per_page, orderby, desc, keywords, operation_status, types, suffix, create_date_from=None, create_date_to=None): + fields = cls.get_file_logs_fields() + if keywords: + logs = cls.model.select(*fields).where((cls.model.kb_id == kb_id), (fn.LOWER(cls.model.document_name).contains(keywords.lower()))) + else: + logs = cls.model.select(*fields).where(cls.model.kb_id == kb_id) + + logs = logs.where(cls.model.document_id != GRAPH_RAPTOR_FAKE_DOC_ID) + + if operation_status: + logs = logs.where(cls.model.operation_status.in_(operation_status)) + if types: + logs = logs.where(cls.model.document_type.in_(types)) + if suffix: + logs = logs.where(cls.model.document_suffix.in_(suffix)) + if create_date_from: + logs = logs.where(cls.model.create_date >= create_date_from) + if create_date_to: + logs = logs.where(cls.model.create_date <= create_date_to) + + count = logs.count() + if desc: + logs = logs.order_by(cls.model.getter_by(orderby).desc()) + else: + logs = logs.order_by(cls.model.getter_by(orderby).asc()) + + if page_number and items_per_page: + logs = logs.paginate(page_number, items_per_page) + + return list(logs.dicts()), count + + @classmethod + @DB.connection_context() + def get_documents_info(cls, id): + fields = [Document.id, Document.name, Document.progress, Document.kb_id] + return ( + cls.model.select(*fields) + .join(Document, on=(cls.model.document_id == Document.id)) + .where( + cls.model.id == id + ) + .dicts() + ) + + @classmethod + @DB.connection_context() + def get_dataset_logs_by_kb_id(cls, kb_id, page_number, items_per_page, orderby, desc, operation_status, create_date_from=None, create_date_to=None): + fields = cls.get_dataset_logs_fields() + logs = cls.model.select(*fields).where((cls.model.kb_id == kb_id), (cls.model.document_id == GRAPH_RAPTOR_FAKE_DOC_ID)) + + if operation_status: + logs = logs.where(cls.model.operation_status.in_(operation_status)) + if create_date_from: + logs = logs.where(cls.model.create_date >= create_date_from) + if create_date_to: + logs = logs.where(cls.model.create_date <= create_date_to) + + count = logs.count() + if desc: + logs = logs.order_by(cls.model.getter_by(orderby).desc()) + else: + logs = logs.order_by(cls.model.getter_by(orderby).asc()) + + if page_number and items_per_page: + logs = logs.paginate(page_number, items_per_page) + + return list(logs.dicts()), count diff --git a/api/db/services/search_service.py b/api/db/services/search_service.py index c5c812cc99f..1c7687b5447 100644 --- a/api/db/services/search_service.py +++ b/api/db/services/search_service.py @@ -17,10 +17,10 @@ from peewee import fn -from api.db import StatusEnum +from common.constants import StatusEnum from api.db.db_models import DB, Search, User from api.db.services.common_service import CommonService -from api.utils import current_timestamp, datetime_format +from common.time_utils import current_timestamp, datetime_format class SearchService(CommonService): @@ -71,6 +71,8 @@ def get_detail(cls, search_id): .first() .to_dict() ) + if not search: + return {} return search @classmethod @@ -92,7 +94,8 @@ def get_by_tenant_ids(cls, joined_tenant_ids, user_id, page_number, items_per_pa query = ( cls.model.select(*fields) .join(User, on=(cls.model.tenant_id == User.id)) - .where(((cls.model.tenant_id.in_(joined_tenant_ids)) | (cls.model.tenant_id == user_id)) & (cls.model.status == StatusEnum.VALID.value)) + .where(((cls.model.tenant_id.in_(joined_tenant_ids)) | (cls.model.tenant_id == user_id)) & ( + cls.model.status == StatusEnum.VALID.value)) ) if keywords: @@ -108,3 +111,8 @@ def get_by_tenant_ids(cls, joined_tenant_ids, user_id, page_number, items_per_pa query = query.paginate(page_number, items_per_page) return list(query.dicts()), count + + @classmethod + @DB.connection_context() + def delete_by_tenant_id(cls, tenant_id): + return cls.model.delete().where(cls.model.tenant_id == tenant_id).execute() diff --git a/api/db/services/task_service.py b/api/db/services/task_service.py index 5fd0eefc3ca..9c771223f6e 100644 --- a/api/db/services/task_service.py +++ b/api/db/services/task_service.py @@ -23,18 +23,20 @@ from deepdoc.parser import PdfParser from peewee import JOIN from api.db.db_models import DB, File2Document, File -from api.db import StatusEnum, FileType, TaskStatus +from api.db import FileType from api.db.db_models import Task, Document, Knowledgebase, Tenant from api.db.services.common_service import CommonService from api.db.services.document_service import DocumentService -from api.utils import current_timestamp, get_uuid +from common.misc_utils import get_uuid +from common.time_utils import current_timestamp +from common.constants import StatusEnum, TaskStatus from deepdoc.parser.excel_parser import RAGFlowExcelParser -from rag.settings import get_svr_queue_name -from rag.utils.storage_factory import STORAGE_IMPL from rag.utils.redis_conn import REDIS_CONN -from api import settings +from common import settings from rag.nlp import search +CANVAS_DEBUG_DOC_ID = "dataflow_x" +GRAPH_RAPTOR_FAKE_DOC_ID = "graph_raptor_x" def trim_header_by_lines(text: str, max_length) -> str: # Trim header text to maximum length while preserving line breaks @@ -54,15 +56,15 @@ def trim_header_by_lines(text: str, max_length) -> str: class TaskService(CommonService): """Service class for managing document processing tasks. - + This class extends CommonService to provide specialized functionality for document processing task management, including task creation, progress tracking, and chunk management. It handles various document types (PDF, Excel, etc.) and manages their processing lifecycle. - + The class implements a robust task queue system with retry mechanisms and progress tracking, supporting both synchronous and asynchronous task execution. - + Attributes: model: The Task model class for database operations. """ @@ -70,20 +72,24 @@ class TaskService(CommonService): @classmethod @DB.connection_context() - def get_task(cls, task_id): + def get_task(cls, task_id, doc_ids=[]): """Retrieve detailed task information by task ID. - + This method fetches comprehensive task details including associated document, knowledge base, and tenant information. It also handles task retry logic and progress updates. - + Args: task_id (str): The unique identifier of the task to retrieve. - + Returns: dict: Task details dictionary containing all task information and related metadata. Returns None if task is not found or has exceeded retry limit. """ + doc_id = cls.model.doc_id + if doc_id == CANVAS_DEBUG_DOC_ID and doc_ids: + doc_id = doc_ids[0] + fields = [ cls.model.id, cls.model.doc_id, @@ -109,7 +115,7 @@ def get_task(cls, task_id): ] docs = ( cls.model.select(*fields) - .join(Document, on=(cls.model.doc_id == Document.id)) + .join(Document, on=(doc_id == Document.id)) .join(Knowledgebase, on=(Document.kb_id == Knowledgebase.id)) .join(Tenant, on=(Knowledgebase.tenant_id == Tenant.id)) .where(cls.model.id == task_id) @@ -139,13 +145,13 @@ def get_task(cls, task_id): @DB.connection_context() def get_tasks(cls, doc_id: str): """Retrieve all tasks associated with a document. - + This method fetches all processing tasks for a given document, ordered by page number and creation time. It includes task progress and chunk information. - + Args: doc_id (str): The unique identifier of the document. - + Returns: list[dict]: List of task dictionaries containing task details. Returns None if no tasks are found. @@ -159,7 +165,7 @@ def get_tasks(cls, doc_id: str): ] tasks = ( cls.model.select(*fields).order_by(cls.model.from_page.asc(), cls.model.create_time.desc()) - .where(cls.model.doc_id == doc_id) + .where(cls.model.doc_id == doc_id) ) tasks = list(tasks.dicts()) if not tasks: @@ -170,10 +176,10 @@ def get_tasks(cls, doc_id: str): @DB.connection_context() def update_chunk_ids(cls, id: str, chunk_ids: str): """Update the chunk IDs associated with a task. - + This method updates the chunk_ids field of a task, which stores the IDs of processed document chunks in a space-separated string format. - + Args: id (str): The unique identifier of the task. chunk_ids (str): Space-separated string of chunk identifiers. @@ -184,11 +190,11 @@ def update_chunk_ids(cls, id: str, chunk_ids: str): @DB.connection_context() def get_ongoing_doc_name(cls): """Get names of documents that are currently being processed. - + This method retrieves information about documents that are in the processing state, including their locations and associated IDs. It uses database locking to ensure thread safety when accessing the task information. - + Returns: list[tuple]: A list of tuples, each containing (parent_id/kb_id, location) for documents currently being processed. Returns empty list if @@ -199,18 +205,18 @@ def get_ongoing_doc_name(cls): cls.model.select( *[Document.id, Document.kb_id, Document.location, File.parent_id] ) - .join(Document, on=(cls.model.doc_id == Document.id)) - .join( + .join(Document, on=(cls.model.doc_id == Document.id)) + .join( File2Document, on=(File2Document.document_id == Document.id), join_type=JOIN.LEFT_OUTER, ) - .join( + .join( File, on=(File2Document.file_id == File.id), join_type=JOIN.LEFT_OUTER, ) - .where( + .where( Document.status == StatusEnum.VALID.value, Document.run == TaskStatus.RUNNING.value, ~(Document.type == FileType.VIRTUAL.value), @@ -238,14 +244,14 @@ def get_ongoing_doc_name(cls): @DB.connection_context() def do_cancel(cls, id): """Check if a task should be cancelled based on its document status. - + This method determines whether a task should be cancelled by checking the associated document's run status and progress. A task should be cancelled if its document is marked for cancellation or has negative progress. - + Args: id (str): The unique identifier of the task to check. - + Returns: bool: True if the task should be cancelled, False otherwise. """ @@ -288,60 +294,78 @@ def update_progress(cls, id, info): cls.model.update(progress=prog).where( (cls.model.id == id) & ( - (cls.model.progress != -1) & - ((prog == -1) | (prog > cls.model.progress)) + (cls.model.progress != -1) & + ((prog == -1) | (prog > cls.model.progress)) ) ).execute() - return + else: + with DB.lock("update_progress", -1): + if info["progress_msg"]: + progress_msg = trim_header_by_lines(task.progress_msg + "\n" + info["progress_msg"], 3000) + cls.model.update(progress_msg=progress_msg).where(cls.model.id == id).execute() + if "progress" in info: + prog = info["progress"] + cls.model.update(progress=prog).where( + (cls.model.id == id) & + ( + (cls.model.progress != -1) & + ((prog == -1) | (prog > cls.model.progress)) + ) + ).execute() - with DB.lock("update_progress", -1): - if info["progress_msg"]: - progress_msg = trim_header_by_lines(task.progress_msg + "\n" + info["progress_msg"], 3000) - cls.model.update(progress_msg=progress_msg).where(cls.model.id == id).execute() - if "progress" in info: - prog = info["progress"] - cls.model.update(progress=prog).where( - (cls.model.id == id) & - ( - (cls.model.progress != -1) & - ((prog == -1) | (prog > cls.model.progress)) - ) - ).execute() + process_duration = (datetime.now() - task.begin_at).total_seconds() + cls.model.update(process_duration=process_duration).where(cls.model.id == id).execute() + + @classmethod + @DB.connection_context() + def delete_by_doc_ids(cls, doc_ids): + """Delete task associated with a document.""" + return cls.model.delete().where(cls.model.doc_id.in_(doc_ids)).execute() def queue_tasks(doc: dict, bucket: str, name: str, priority: int): """Create and queue document processing tasks. - + This function creates processing tasks for a document based on its type and configuration. It handles different document types (PDF, Excel, etc.) differently and manages task chunking and configuration. It also implements task reuse optimization by checking for previously completed tasks. - + Args: doc (dict): Document dictionary containing metadata and configuration. bucket (str): Storage bucket name where the document is stored. name (str): File name of the document. priority (int, optional): Priority level for task queueing (default is 0). - + Note: - For PDF documents, tasks are created per page range based on configuration - For Excel documents, tasks are created per row range - Task digests are calculated for optimization and reuse - Previous task chunks may be reused if available """ + def new_task(): - return {"id": get_uuid(), "doc_id": doc["id"], "progress": 0.0, "from_page": 0, "to_page": 100000000} + return { + "id": get_uuid(), + "doc_id": doc["id"], + "progress": 0.0, + "from_page": 0, + "to_page": 100000000, + "begin_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + } parse_task_array = [] if doc["type"] == FileType.PDF.value: - file_bin = STORAGE_IMPL.get(bucket, name) + file_bin = settings.STORAGE_IMPL.get(bucket, name) do_layout = doc["parser_config"].get("layout_recognize", "DeepDOC") pages = PdfParser.total_page_number(doc["name"], file_bin) - page_size = doc["parser_config"].get("task_page_size", 12) + if pages is None: + pages = 0 + page_size = doc["parser_config"].get("task_page_size") or 12 if doc["parser_id"] == "paper": - page_size = doc["parser_config"].get("task_page_size", 22) - if doc["parser_id"] in ["one", "knowledge_graph"] or do_layout != "DeepDOC": + page_size = doc["parser_config"].get("task_page_size") or 22 + if doc["parser_id"] in ["one", "knowledge_graph"] or do_layout != "DeepDOC" or doc["parser_config"].get("toc_extraction", False): page_size = 10 ** 9 page_ranges = doc["parser_config"].get("pages") or [(1, 10 ** 5)] for s, e in page_ranges: @@ -355,7 +379,7 @@ def new_task(): parse_task_array.append(task) elif doc["parser_id"] == "table": - file_bin = STORAGE_IMPL.get(bucket, name) + file_bin = settings.STORAGE_IMPL.get(bucket, name) rn = RAGFlowExcelParser.row_number(doc["name"], file_bin) for i in range(0, rn, 3000): task = new_task() @@ -387,12 +411,12 @@ def new_task(): for task in parse_task_array: ck_num += reuse_prev_task_chunks(task, prev_tasks, chunking_config) TaskService.filter_delete([Task.doc_id == doc["id"]]) - chunk_ids = [] - for task in prev_tasks: - if task["chunk_ids"]: - chunk_ids.extend(task["chunk_ids"].split()) - if chunk_ids: - settings.docStoreConn.delete({"id": chunk_ids}, search.index_name(chunking_config["tenant_id"]), + pre_chunk_ids = [] + for pre_task in prev_tasks: + if pre_task["chunk_ids"]: + pre_chunk_ids.extend(pre_task["chunk_ids"].split()) + if pre_chunk_ids: + settings.docStoreConn.delete({"id": pre_chunk_ids}, search.index_name(chunking_config["tenant_id"]), chunking_config["kb_id"]) DocumentService.update_by_id(doc["id"], {"chunk_num": ck_num}) @@ -402,25 +426,25 @@ def new_task(): unfinished_task_array = [task for task in parse_task_array if task["progress"] < 1.0] for unfinished_task in unfinished_task_array: assert REDIS_CONN.queue_product( - get_svr_queue_name(priority), message=unfinished_task + settings.get_svr_queue_name(priority), message=unfinished_task ), "Can't access Redis. Please check the Redis' status." def reuse_prev_task_chunks(task: dict, prev_tasks: list[dict], chunking_config: dict): """Attempt to reuse chunks from previous tasks for optimization. - + This function checks if chunks from previously completed tasks can be reused for the current task, which can significantly improve processing efficiency. It matches tasks based on page ranges and configuration digests. - + Args: task (dict): Current task dictionary to potentially reuse chunks for. prev_tasks (list[dict]): List of previous task dictionaries to check for reuse. chunking_config (dict): Configuration dictionary for chunk processing. - + Returns: int: Number of chunks successfully reused. Returns 0 if no chunks could be reused. - + Note: Chunks can only be reused if: - A previous task exists with matching page range and configuration digest @@ -451,3 +475,49 @@ def reuse_prev_task_chunks(task: dict, prev_tasks: list[dict], chunking_config: prev_task["chunk_ids"] = "" return len(task["chunk_ids"].split()) + + +def cancel_all_task_of(doc_id): + for t in TaskService.query(doc_id=doc_id): + try: + REDIS_CONN.set(f"{t.id}-cancel", "x") + except Exception as e: + logging.exception(e) + + +def has_canceled(task_id): + try: + if REDIS_CONN.get(f"{task_id}-cancel"): + return True + except Exception as e: + logging.exception(e) + return False + + +def queue_dataflow(tenant_id:str, flow_id:str, task_id:str, doc_id:str=CANVAS_DEBUG_DOC_ID, file:dict=None, priority: int=0, rerun:bool=False) -> tuple[bool, str]: + + task = dict( + id=task_id, + doc_id=doc_id, + from_page=0, + to_page=100000000, + task_type="dataflow" if not rerun else "dataflow_rerun", + priority=priority, + begin_at= datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + ) + if doc_id not in [CANVAS_DEBUG_DOC_ID, GRAPH_RAPTOR_FAKE_DOC_ID]: + TaskService.model.delete().where(TaskService.model.doc_id == doc_id).execute() + DocumentService.begin2parse(doc_id) + bulk_insert_into_db(model=Task, data_source=[task], replace_on_conflict=True) + + task["kb_id"] = DocumentService.get_knowledgebase_id(doc_id) + task["tenant_id"] = tenant_id + task["dataflow_id"] = flow_id + task["file"] = file + + if not REDIS_CONN.queue_product( + settings.get_svr_queue_name(priority), message=task + ): + return False, "Can't access Redis. Please check the Redis' status." + + return True, "" diff --git a/api/db/services/tenant_llm_service.py b/api/db/services/tenant_llm_service.py new file mode 100644 index 00000000000..f971be3d42a --- /dev/null +++ b/api/db/services/tenant_llm_service.py @@ -0,0 +1,268 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import logging +from langfuse import Langfuse +from common import settings +from common.constants import LLMType +from api.db.db_models import DB, LLMFactories, TenantLLM +from api.db.services.common_service import CommonService +from api.db.services.langfuse_service import TenantLangfuseService +from api.db.services.user_service import TenantService +from rag.llm import ChatModel, CvModel, EmbeddingModel, RerankModel, Seq2txtModel, TTSModel + + +class LLMFactoriesService(CommonService): + model = LLMFactories + + +class TenantLLMService(CommonService): + model = TenantLLM + + @classmethod + @DB.connection_context() + def get_api_key(cls, tenant_id, model_name): + mdlnm, fid = TenantLLMService.split_model_name_and_factory(model_name) + if not fid: + objs = cls.query(tenant_id=tenant_id, llm_name=mdlnm) + else: + objs = cls.query(tenant_id=tenant_id, llm_name=mdlnm, llm_factory=fid) + + if (not objs) and fid: + if fid == "LocalAI": + mdlnm += "___LocalAI" + elif fid == "HuggingFace": + mdlnm += "___HuggingFace" + elif fid == "OpenAI-API-Compatible": + mdlnm += "___OpenAI-API" + elif fid == "VLLM": + mdlnm += "___VLLM" + objs = cls.query(tenant_id=tenant_id, llm_name=mdlnm, llm_factory=fid) + if not objs: + return None + return objs[0] + + @classmethod + @DB.connection_context() + def get_my_llms(cls, tenant_id): + fields = [cls.model.llm_factory, LLMFactories.logo, LLMFactories.tags, cls.model.model_type, cls.model.llm_name, + cls.model.used_tokens, cls.model.status] + objs = cls.model.select(*fields).join(LLMFactories, on=(cls.model.llm_factory == LLMFactories.name)).where( + cls.model.tenant_id == tenant_id, ~cls.model.api_key.is_null()).dicts() + + return list(objs) + + @staticmethod + def split_model_name_and_factory(model_name): + arr = model_name.split("@") + if len(arr) < 2: + return model_name, None + if len(arr) > 2: + return "@".join(arr[0:-1]), arr[-1] + + # model name must be xxx@yyy + try: + model_factories = settings.FACTORY_LLM_INFOS + model_providers = set([f["name"] for f in model_factories]) + if arr[-1] not in model_providers: + return model_name, None + return arr[0], arr[-1] + except Exception as e: + logging.exception(f"TenantLLMService.split_model_name_and_factory got exception: {e}") + return model_name, None + + @classmethod + @DB.connection_context() + def get_model_config(cls, tenant_id, llm_type, llm_name=None): + from api.db.services.llm_service import LLMService + e, tenant = TenantService.get_by_id(tenant_id) + if not e: + raise LookupError("Tenant not found") + + if llm_type == LLMType.EMBEDDING.value: + mdlnm = tenant.embd_id if not llm_name else llm_name + elif llm_type == LLMType.SPEECH2TEXT.value: + mdlnm = tenant.asr_id + elif llm_type == LLMType.IMAGE2TEXT.value: + mdlnm = tenant.img2txt_id if not llm_name else llm_name + elif llm_type == LLMType.CHAT.value: + mdlnm = tenant.llm_id if not llm_name else llm_name + elif llm_type == LLMType.RERANK: + mdlnm = tenant.rerank_id if not llm_name else llm_name + elif llm_type == LLMType.TTS: + mdlnm = tenant.tts_id if not llm_name else llm_name + else: + assert False, "LLM type error" + + model_config = cls.get_api_key(tenant_id, mdlnm) + mdlnm, fid = TenantLLMService.split_model_name_and_factory(mdlnm) + if not model_config: # for some cases seems fid mismatch + model_config = cls.get_api_key(tenant_id, mdlnm) + if model_config: + model_config = model_config.to_dict() + elif llm_type == LLMType.EMBEDDING and fid == 'Builtin' and "tei-" in os.getenv("COMPOSE_PROFILES", "") and mdlnm == os.getenv('TEI_MODEL', ''): + embedding_cfg = settings.EMBEDDING_CFG + model_config = {"llm_factory": 'Builtin', "api_key": embedding_cfg["api_key"], "llm_name": mdlnm, "api_base": embedding_cfg["base_url"]} + else: + raise LookupError(f"Model({mdlnm}@{fid}) not authorized") + + llm = LLMService.query(llm_name=mdlnm) if not fid else LLMService.query(llm_name=mdlnm, fid=fid) + if not llm and fid: # for some cases seems fid mismatch + llm = LLMService.query(llm_name=mdlnm) + if llm: + model_config["is_tools"] = llm[0].is_tools + return model_config + + @classmethod + @DB.connection_context() + def model_instance(cls, tenant_id, llm_type, llm_name=None, lang="Chinese", **kwargs): + model_config = TenantLLMService.get_model_config(tenant_id, llm_type, llm_name) + kwargs.update({"provider": model_config["llm_factory"]}) + if llm_type == LLMType.EMBEDDING.value: + if model_config["llm_factory"] not in EmbeddingModel: + return None + return EmbeddingModel[model_config["llm_factory"]](model_config["api_key"], model_config["llm_name"], + base_url=model_config["api_base"]) + + if llm_type == LLMType.RERANK: + if model_config["llm_factory"] not in RerankModel: + return None + return RerankModel[model_config["llm_factory"]](model_config["api_key"], model_config["llm_name"], + base_url=model_config["api_base"]) + + if llm_type == LLMType.IMAGE2TEXT.value: + if model_config["llm_factory"] not in CvModel: + return None + return CvModel[model_config["llm_factory"]](model_config["api_key"], model_config["llm_name"], lang, + base_url=model_config["api_base"], **kwargs) + + if llm_type == LLMType.CHAT.value: + if model_config["llm_factory"] not in ChatModel: + return None + return ChatModel[model_config["llm_factory"]](model_config["api_key"], model_config["llm_name"], + base_url=model_config["api_base"], **kwargs) + + if llm_type == LLMType.SPEECH2TEXT: + if model_config["llm_factory"] not in Seq2txtModel: + return None + return Seq2txtModel[model_config["llm_factory"]](key=model_config["api_key"], + model_name=model_config["llm_name"], lang=lang, + base_url=model_config["api_base"]) + if llm_type == LLMType.TTS: + if model_config["llm_factory"] not in TTSModel: + return None + return TTSModel[model_config["llm_factory"]]( + model_config["api_key"], + model_config["llm_name"], + base_url=model_config["api_base"], + ) + return None + + @classmethod + @DB.connection_context() + def increase_usage(cls, tenant_id, llm_type, used_tokens, llm_name=None): + e, tenant = TenantService.get_by_id(tenant_id) + if not e: + logging.error(f"Tenant not found: {tenant_id}") + return 0 + + llm_map = { + LLMType.EMBEDDING.value: tenant.embd_id if not llm_name else llm_name, + LLMType.SPEECH2TEXT.value: tenant.asr_id, + LLMType.IMAGE2TEXT.value: tenant.img2txt_id, + LLMType.CHAT.value: tenant.llm_id if not llm_name else llm_name, + LLMType.RERANK.value: tenant.rerank_id if not llm_name else llm_name, + LLMType.TTS.value: tenant.tts_id if not llm_name else llm_name, + } + + mdlnm = llm_map.get(llm_type) + if mdlnm is None: + logging.error(f"LLM type error: {llm_type}") + return 0 + + llm_name, llm_factory = TenantLLMService.split_model_name_and_factory(mdlnm) + + try: + num = ( + cls.model.update(used_tokens=cls.model.used_tokens + used_tokens) + .where(cls.model.tenant_id == tenant_id, cls.model.llm_name == llm_name, + cls.model.llm_factory == llm_factory if llm_factory else True) + .execute() + ) + except Exception: + logging.exception( + "TenantLLMService.increase_usage got exception,Failed to update used_tokens for tenant_id=%s, llm_name=%s", + tenant_id, llm_name) + return 0 + + return num + + @classmethod + @DB.connection_context() + def get_openai_models(cls): + objs = cls.model.select().where((cls.model.llm_factory == "OpenAI"), + ~(cls.model.llm_name == "text-embedding-3-small"), + ~(cls.model.llm_name == "text-embedding-3-large")).dicts() + return list(objs) + + @classmethod + @DB.connection_context() + def delete_by_tenant_id(cls, tenant_id): + return cls.model.delete().where(cls.model.tenant_id == tenant_id).execute() + + @staticmethod + def llm_id2llm_type(llm_id: str) -> str | None: + from api.db.services.llm_service import LLMService + llm_id, *_ = TenantLLMService.split_model_name_and_factory(llm_id) + llm_factories = settings.FACTORY_LLM_INFOS + for llm_factory in llm_factories: + for llm in llm_factory["llm"]: + if llm_id == llm["llm_name"]: + return llm["model_type"].split(",")[-1] + + for llm in LLMService.query(llm_name=llm_id): + return llm.model_type + + llm = TenantLLMService.get_or_none(llm_name=llm_id) + if llm: + return llm.model_type + for llm in TenantLLMService.query(llm_name=llm_id): + return llm.model_type + return None + + +class LLM4Tenant: + def __init__(self, tenant_id, llm_type, llm_name=None, lang="Chinese", **kwargs): + self.tenant_id = tenant_id + self.llm_type = llm_type + self.llm_name = llm_name + self.mdl = TenantLLMService.model_instance(tenant_id, llm_type, llm_name, lang=lang, **kwargs) + assert self.mdl, "Can't find model for {}/{}/{}".format(tenant_id, llm_type, llm_name) + model_config = TenantLLMService.get_model_config(tenant_id, llm_type, llm_name) + self.max_length = model_config.get("max_tokens", 8192) + + self.is_tools = model_config.get("is_tools", False) + self.verbose_tool_use = kwargs.get("verbose_tool_use") + + langfuse_keys = TenantLangfuseService.filter_by_tenant(tenant_id=tenant_id) + self.langfuse = None + if langfuse_keys: + langfuse = Langfuse(public_key=langfuse_keys.public_key, secret_key=langfuse_keys.secret_key, + host=langfuse_keys.host) + if langfuse.auth_check(): + self.langfuse = langfuse + trace_id = self.langfuse.create_trace_id() + self.trace_context = {"trace_id": trace_id} diff --git a/api/db/services/user_canvas_version.py b/api/db/services/user_canvas_version.py index 9fe12e32e87..89f73264f0d 100644 --- a/api/db/services/user_canvas_version.py +++ b/api/db/services/user_canvas_version.py @@ -2,45 +2,60 @@ from api.db.services.common_service import CommonService from peewee import DoesNotExist + class UserCanvasVersionService(CommonService): model = UserCanvasVersion - - + @classmethod @DB.connection_context() def list_by_canvas_id(cls, user_canvas_id): try: user_canvas_version = cls.model.select( - *[cls.model.id, - cls.model.create_time, - cls.model.title, - cls.model.create_date, - cls.model.update_date, - cls.model.user_canvas_id, - cls.model.update_time] + *[cls.model.id, + cls.model.create_time, + cls.model.title, + cls.model.create_date, + cls.model.update_date, + cls.model.user_canvas_id, + cls.model.update_time] ).where(cls.model.user_canvas_id == user_canvas_id) return user_canvas_version except DoesNotExist: return None except Exception: return None - + + @classmethod + @DB.connection_context() + def get_all_canvas_version_by_canvas_ids(cls, canvas_ids): + fields = [cls.model.id] + versions = cls.model.select(*fields).where(cls.model.user_canvas_id.in_(canvas_ids)) + versions.order_by(cls.model.create_time.asc()) + offset, limit = 0, 100 + res = [] + while True: + version_batch = versions.offset(offset).limit(limit) + _temp = list(version_batch.dicts()) + if not _temp: + break + res.extend(_temp) + offset += limit + return res + @classmethod @DB.connection_context() def delete_all_versions(cls, user_canvas_id): try: - user_canvas_version = cls.model.select().where(cls.model.user_canvas_id == user_canvas_id).order_by(cls.model.create_time.desc()) + user_canvas_version = cls.model.select().where(cls.model.user_canvas_id == user_canvas_id).order_by( + cls.model.create_time.desc()) if user_canvas_version.count() > 20: delete_ids = [] for i in range(20, user_canvas_version.count()): delete_ids.append(user_canvas_version[i].id) - + cls.delete_by_ids(delete_ids) return True except DoesNotExist: return None except Exception: return None - - - diff --git a/api/db/services/user_service.py b/api/db/services/user_service.py index e8344cb43ba..b5e754dbd24 100644 --- a/api/db/services/user_service.py +++ b/api/db/services/user_service.py @@ -24,9 +24,10 @@ from api.db.db_models import DB, UserTenant from api.db.db_models import User, Tenant from api.db.services.common_service import CommonService -from api.utils import get_uuid, current_timestamp, datetime_format -from api.db import StatusEnum -from rag.settings import MINIO +from common.misc_utils import get_uuid +from common.time_utils import current_timestamp, datetime_format +from common.constants import StatusEnum +from common import settings class UserService(CommonService): @@ -45,22 +46,22 @@ class UserService(CommonService): def query(cls, cols=None, reverse=None, order_by=None, **kwargs): if 'access_token' in kwargs: access_token = kwargs['access_token'] - + # Reject empty, None, or whitespace-only access tokens if not access_token or not str(access_token).strip(): logging.warning("UserService.query: Rejecting empty access_token query") return cls.model.select().where(cls.model.id == "INVALID_EMPTY_TOKEN") # Returns empty result - + # Reject tokens that are too short (should be UUID, 32+ chars) if len(str(access_token).strip()) < 32: logging.warning(f"UserService.query: Rejecting short access_token query: {len(str(access_token))} chars") return cls.model.select().where(cls.model.id == "INVALID_SHORT_TOKEN") # Returns empty result - + # Reject tokens that start with "INVALID_" (from logout) if str(access_token).startswith("INVALID_"): logging.warning("UserService.query: Rejecting invalidated access_token") return cls.model.select().where(cls.model.id == "INVALID_LOGOUT_TOKEN") # Returns empty result - + # Call parent query method for valid requests return super().query(cols=cols, reverse=reverse, order_by=order_by, **kwargs) @@ -100,6 +101,12 @@ def query_user(cls, email, password): else: return None + @classmethod + @DB.connection_context() + def query_user_by_email(cls, email): + users = cls.model.select().where((cls.model.email == email)) + return list(users) + @classmethod @DB.connection_context() def save(cls, **kwargs): @@ -133,6 +140,30 @@ def update_user(cls, user_id, user_dict): cls.model.update(user_dict).where( cls.model.id == user_id).execute() + @classmethod + @DB.connection_context() + def update_user_password(cls, user_id, new_password): + with DB.atomic(): + update_dict = { + "password": generate_password_hash(str(new_password)), + "update_time": current_timestamp(), + "update_date": datetime_format(datetime.now()) + } + cls.model.update(update_dict).where(cls.model.id == user_id).execute() + + @classmethod + @DB.connection_context() + def is_admin(cls, user_id): + return cls.model.select().where( + cls.model.id == user_id, + cls.model.is_superuser == 1).count() > 0 + + @classmethod + @DB.connection_context() + def get_all_users(cls): + users = cls.model.select() + return list(users) + class TenantService(CommonService): """Service class for managing tenant-related database operations. @@ -189,8 +220,8 @@ def decrease(cls, user_id, num): @classmethod @DB.connection_context() def user_gateway(cls, tenant_id): - hashobj = hashlib.sha256(tenant_id.encode("utf-8")) - return int(hashobj.hexdigest(), 16)%len(MINIO) + hash_obj = hashlib.sha256(tenant_id.encode("utf-8")) + return int(hash_obj.hexdigest(), 16)%len(settings.MINIO) class UserTenantService(CommonService): @@ -258,6 +289,17 @@ def get_tenants_by_user_id(cls, user_id): .join(User, on=((cls.model.tenant_id == User.id) & (UserTenant.user_id == user_id) & (UserTenant.status == StatusEnum.VALID.value))) .where(cls.model.status == StatusEnum.VALID.value).dicts()) + @classmethod + @DB.connection_context() + def get_user_tenant_relation_by_user_id(cls, user_id): + fields = [ + cls.model.id, + cls.model.user_id, + cls.model.tenant_id, + cls.model.role + ] + return list(cls.model.select(*fields).where(cls.model.user_id == user_id).dicts().dicts()) + @classmethod @DB.connection_context() def get_num_members(cls, user_id: str): @@ -274,4 +316,4 @@ def filter_by_tenant_and_user_id(cls, tenant_id, user_id): ).first() return user_tenant except peewee.DoesNotExist: - return None \ No newline at end of file + return None diff --git a/api/ragflow_server.py b/api/ragflow_server.py index 75bc8916c7d..868e054aeb1 100644 --- a/api/ragflow_server.py +++ b/api/ragflow_server.py @@ -18,7 +18,7 @@ # from beartype.claw import beartype_all # <-- you didn't sign up for this # beartype_all(conf=BeartypeConf(violation_type=UserWarning)) # <-- emit warnings from all code -from api.utils.log_utils import init_root_logger +from common.log_utils import init_root_logger from plugin import GlobalPluginManager init_root_logger("ragflow_server") @@ -32,17 +32,16 @@ import uuid from werkzeug.serving import run_simple -from api import settings -from api.apps import app +from api.apps import app, smtp_mail_server from api.db.runtime_config import RuntimeConfig from api.db.services.document_service import DocumentService -from api import utils - +from common.file_utils import get_project_base_directory +from common import settings from api.db.db_models import init_database_tables as init_web_db from api.db.init_data import init_web_data -from api.versions import get_ragflow_version -from api.utils import show_configs -from rag.settings import print_rag_settings +from common.versions import get_ragflow_version +from common.config_utils import show_configs +from rag.utils.mcp_tool_call_conn import shutdown_all_mcp_sessions from rag.utils.redis_conn import RedisDistributedLock stop_event = threading.Event() @@ -58,36 +57,40 @@ def update_progress(): if redis_lock.acquire(): DocumentService.update_progress() redis_lock.release() - stop_event.wait(6) except Exception: logging.exception("update_progress exception") finally: - redis_lock.release() + try: + redis_lock.release() + except Exception: + logging.exception("update_progress exception") + stop_event.wait(6) def signal_handler(sig, frame): logging.info("Received interrupt signal, shutting down...") + shutdown_all_mcp_sessions() stop_event.set() time.sleep(1) sys.exit(0) if __name__ == '__main__': logging.info(r""" - ____ ___ ______ ______ __ + ____ ___ ______ ______ __ / __ \ / | / ____// ____// /____ _ __ / /_/ // /| | / / __ / /_ / // __ \| | /| / / - / _, _// ___ |/ /_/ // __/ / // /_/ /| |/ |/ / - /_/ |_|/_/ |_|\____//_/ /_/ \____/ |__/|__/ + / _, _// ___ |/ /_/ // __/ / // /_/ /| |/ |/ / + /_/ |_|/_/ |_|\____//_/ /_/ \____/ |__/|__/ """) logging.info( f'RAGFlow version: {get_ragflow_version()}' ) logging.info( - f'project base: {utils.file_utils.get_project_base_directory()}' + f'project base: {get_project_base_directory()}' ) show_configs() settings.init_settings() - print_rag_settings() + settings.print_rag_settings() if RAGFLOW_DEBUGPY_LISTEN > 0: logging.info(f"debugpy listen on {RAGFLOW_DEBUGPY_LISTEN}") @@ -135,6 +138,18 @@ def delayed_start_update_progress(): else: threading.Timer(1.0, delayed_start_update_progress).start() + # init smtp server + if settings.SMTP_CONF: + app.config["MAIL_SERVER"] = settings.MAIL_SERVER + app.config["MAIL_PORT"] = settings.MAIL_PORT + app.config["MAIL_USE_SSL"] = settings.MAIL_USE_SSL + app.config["MAIL_USE_TLS"] = settings.MAIL_USE_TLS + app.config["MAIL_USERNAME"] = settings.MAIL_USERNAME + app.config["MAIL_PASSWORD"] = settings.MAIL_PASSWORD + app.config["MAIL_DEFAULT_SENDER"] = settings.MAIL_DEFAULT_SENDER + smtp_mail_server.init_app(app) + + # start http server try: logging.info("RAGFlow HTTP server start...") diff --git a/api/settings.py b/api/settings.py index 22e9d03f461..cd7307f51a5 100644 --- a/api/settings.py +++ b/api/settings.py @@ -13,199 +13,3 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import json -import os -import secrets -from datetime import date -from enum import Enum, IntEnum - -import rag.utils -import rag.utils.es_conn -import rag.utils.infinity_conn -import rag.utils.opensearch_coon -from api.constants import RAG_FLOW_SERVICE_NAME -from api.utils import decrypt_database_config, get_base_config -from api.utils.file_utils import get_project_base_directory -from graphrag import search as kg_search -from rag.nlp import search - -LIGHTEN = int(os.environ.get("LIGHTEN", "0")) - -LLM = None -LLM_FACTORY = None -LLM_BASE_URL = None -CHAT_MDL = "" -EMBEDDING_MDL = "" -RERANK_MDL = "" -ASR_MDL = "" -IMAGE2TEXT_MDL = "" -API_KEY = None -PARSERS = None -HOST_IP = None -HOST_PORT = None -SECRET_KEY = None -FACTORY_LLM_INFOS = None - -DATABASE_TYPE = os.getenv("DB_TYPE", "mysql") -DATABASE = decrypt_database_config(name=DATABASE_TYPE) - -# authentication -AUTHENTICATION_CONF = None - -# client -CLIENT_AUTHENTICATION = None -HTTP_APP_KEY = None -GITHUB_OAUTH = None -FEISHU_OAUTH = None -OAUTH_CONFIG = None -DOC_ENGINE = None -docStoreConn = None - -retrievaler = None -kg_retrievaler = None - -# user registration switch -REGISTER_ENABLED = 1 - - -# sandbox-executor-manager -SANDBOX_ENABLED = 0 -SANDBOX_HOST = None - -BUILTIN_EMBEDDING_MODELS = ["BAAI/bge-large-zh-v1.5@BAAI", "maidalun1020/bce-embedding-base_v1@Youdao"] - -def get_or_create_secret_key(): - secret_key = os.environ.get("RAGFLOW_SECRET_KEY") - if secret_key and len(secret_key) >= 32: - return secret_key - - # Check if there's a configured secret key - configured_key = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("secret_key") - if configured_key and configured_key != str(date.today()) and len(configured_key) >= 32: - return configured_key - - # Generate a new secure key and warn about it - import logging - new_key = secrets.token_hex(32) - logging.warning( - "SECURITY WARNING: Using auto-generated SECRET_KEY. " - f"Generated key: {new_key}" - ) - return new_key - - -def init_settings(): - global LLM, LLM_FACTORY, LLM_BASE_URL, LIGHTEN, DATABASE_TYPE, DATABASE, FACTORY_LLM_INFOS, REGISTER_ENABLED - LIGHTEN = int(os.environ.get("LIGHTEN", "0")) - DATABASE_TYPE = os.getenv("DB_TYPE", "mysql") - DATABASE = decrypt_database_config(name=DATABASE_TYPE) - LLM = get_base_config("user_default_llm", {}) - LLM_DEFAULT_MODELS = LLM.get("default_models", {}) - LLM_FACTORY = LLM.get("factory") - LLM_BASE_URL = LLM.get("base_url") - try: - REGISTER_ENABLED = int(os.environ.get("REGISTER_ENABLED", "1")) - except Exception: - pass - - try: - with open(os.path.join(get_project_base_directory(), "conf", "llm_factories.json"), "r") as f: - FACTORY_LLM_INFOS = json.load(f)["factory_llm_infos"] - except Exception: - FACTORY_LLM_INFOS = [] - - global CHAT_MDL, EMBEDDING_MDL, RERANK_MDL, ASR_MDL, IMAGE2TEXT_MDL - if not LIGHTEN: - EMBEDDING_MDL = BUILTIN_EMBEDDING_MODELS[0] - - if LLM_DEFAULT_MODELS: - CHAT_MDL = LLM_DEFAULT_MODELS.get("chat_model", CHAT_MDL) - EMBEDDING_MDL = LLM_DEFAULT_MODELS.get("embedding_model", EMBEDDING_MDL) - RERANK_MDL = LLM_DEFAULT_MODELS.get("rerank_model", RERANK_MDL) - ASR_MDL = LLM_DEFAULT_MODELS.get("asr_model", ASR_MDL) - IMAGE2TEXT_MDL = LLM_DEFAULT_MODELS.get("image2text_model", IMAGE2TEXT_MDL) - - # factory can be specified in the config name with "@". LLM_FACTORY will be used if not specified - CHAT_MDL = CHAT_MDL + (f"@{LLM_FACTORY}" if "@" not in CHAT_MDL and CHAT_MDL != "" else "") - EMBEDDING_MDL = EMBEDDING_MDL + (f"@{LLM_FACTORY}" if "@" not in EMBEDDING_MDL and EMBEDDING_MDL != "" else "") - RERANK_MDL = RERANK_MDL + (f"@{LLM_FACTORY}" if "@" not in RERANK_MDL and RERANK_MDL != "" else "") - ASR_MDL = ASR_MDL + (f"@{LLM_FACTORY}" if "@" not in ASR_MDL and ASR_MDL != "" else "") - IMAGE2TEXT_MDL = IMAGE2TEXT_MDL + (f"@{LLM_FACTORY}" if "@" not in IMAGE2TEXT_MDL and IMAGE2TEXT_MDL != "" else "") - - global API_KEY, PARSERS, HOST_IP, HOST_PORT, SECRET_KEY - API_KEY = LLM.get("api_key") - PARSERS = LLM.get( - "parsers", "naive:General,qa:Q&A,resume:Resume,manual:Manual,table:Table,paper:Paper,book:Book,laws:Laws,presentation:Presentation,picture:Picture,one:One,audio:Audio,email:Email,tag:Tag" - ) - - HOST_IP = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("host", "127.0.0.1") - HOST_PORT = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("http_port") - - SECRET_KEY = get_or_create_secret_key() - - global AUTHENTICATION_CONF, CLIENT_AUTHENTICATION, HTTP_APP_KEY, GITHUB_OAUTH, FEISHU_OAUTH, OAUTH_CONFIG - # authentication - AUTHENTICATION_CONF = get_base_config("authentication", {}) - - # client - CLIENT_AUTHENTICATION = AUTHENTICATION_CONF.get("client", {}).get("switch", False) - HTTP_APP_KEY = AUTHENTICATION_CONF.get("client", {}).get("http_app_key") - GITHUB_OAUTH = get_base_config("oauth", {}).get("github") - FEISHU_OAUTH = get_base_config("oauth", {}).get("feishu") - - OAUTH_CONFIG = get_base_config("oauth", {}) - - global DOC_ENGINE, docStoreConn, retrievaler, kg_retrievaler - DOC_ENGINE = os.environ.get("DOC_ENGINE", "elasticsearch") - # DOC_ENGINE = os.environ.get('DOC_ENGINE', "opensearch") - lower_case_doc_engine = DOC_ENGINE.lower() - if lower_case_doc_engine == "elasticsearch": - docStoreConn = rag.utils.es_conn.ESConnection() - elif lower_case_doc_engine == "infinity": - docStoreConn = rag.utils.infinity_conn.InfinityConnection() - elif lower_case_doc_engine == "opensearch": - docStoreConn = rag.utils.opensearch_coon.OSConnection() - else: - raise Exception(f"Not supported doc engine: {DOC_ENGINE}") - - retrievaler = search.Dealer(docStoreConn) - kg_retrievaler = kg_search.KGSearch(docStoreConn) - - if int(os.environ.get("SANDBOX_ENABLED", "0")): - global SANDBOX_HOST - SANDBOX_HOST = os.environ.get("SANDBOX_HOST", "sandbox-executor-manager") - - -class CustomEnum(Enum): - @classmethod - def valid(cls, value): - try: - cls(value) - return True - except BaseException: - return False - - @classmethod - def values(cls): - return [member.value for member in cls.__members__.values()] - - @classmethod - def names(cls): - return [member.name for member in cls.__members__.values()] - - -class RetCode(IntEnum, CustomEnum): - SUCCESS = 0 - NOT_EFFECTIVE = 10 - EXCEPTION_ERROR = 100 - ARGUMENT_ERROR = 101 - DATA_ERROR = 102 - OPERATING_ERROR = 103 - CONNECTION_ERROR = 105 - RUNNING = 106 - PERMISSION_ERROR = 108 - AUTHENTICATION_ERROR = 109 - UNAUTHORIZED = 401 - SERVER_ERROR = 500 - FORBIDDEN = 403 - NOT_FOUND = 404 diff --git a/api/utils/__init__.py b/api/utils/__init__.py index 92086b99b14..e7d5615028d 100644 --- a/api/utils/__init__.py +++ b/api/utils/__init__.py @@ -13,261 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import base64 -import datetime -import io -import json -import os -import pickle -import socket -import time -import uuid -import requests -import logging -import copy -from enum import Enum, IntEnum import importlib -from Cryptodome.PublicKey import RSA -from Cryptodome.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5 -from filelock import FileLock -from api.constants import SERVICE_CONF - -from . import file_utils - - -def conf_realpath(conf_name): - conf_path = f"conf/{conf_name}" - return os.path.join(file_utils.get_project_base_directory(), conf_path) - - -def read_config(conf_name=SERVICE_CONF): - local_config = {} - local_path = conf_realpath(f'local.{conf_name}') - - # load local config file - if os.path.exists(local_path): - local_config = file_utils.load_yaml_conf(local_path) - if not isinstance(local_config, dict): - raise ValueError(f'Invalid config file: "{local_path}".') - - global_config_path = conf_realpath(conf_name) - global_config = file_utils.load_yaml_conf(global_config_path) - - if not isinstance(global_config, dict): - raise ValueError(f'Invalid config file: "{global_config_path}".') - - global_config.update(local_config) - return global_config - - -CONFIGS = read_config() - - -def show_configs(): - msg = f"Current configs, from {conf_realpath(SERVICE_CONF)}:" - for k, v in CONFIGS.items(): - if isinstance(v, dict): - if "password" in v: - v = copy.deepcopy(v) - v["password"] = "*" * 8 - if "access_key" in v: - v = copy.deepcopy(v) - v["access_key"] = "*" * 8 - if "secret_key" in v: - v = copy.deepcopy(v) - v["secret_key"] = "*" * 8 - msg += f"\n\t{k}: {v}" - logging.info(msg) - - -def get_base_config(key, default=None): - if key is None: - return None - if default is None: - default = os.environ.get(key.upper()) - return CONFIGS.get(key, default) - - -use_deserialize_safe_module = get_base_config( - 'use_deserialize_safe_module', False) - - -class BaseType: - def to_dict(self): - return dict([(k.lstrip("_"), v) for k, v in self.__dict__.items()]) - - def to_dict_with_type(self): - def _dict(obj): - module = None - if issubclass(obj.__class__, BaseType): - data = {} - for attr, v in obj.__dict__.items(): - k = attr.lstrip("_") - data[k] = _dict(v) - module = obj.__module__ - elif isinstance(obj, (list, tuple)): - data = [] - for i, vv in enumerate(obj): - data.append(_dict(vv)) - elif isinstance(obj, dict): - data = {} - for _k, vv in obj.items(): - data[_k] = _dict(vv) - else: - data = obj - return {"type": obj.__class__.__name__, - "data": data, "module": module} - - return _dict(self) - - -class CustomJSONEncoder(json.JSONEncoder): - def __init__(self, **kwargs): - self._with_type = kwargs.pop("with_type", False) - super().__init__(**kwargs) - - def default(self, obj): - if isinstance(obj, datetime.datetime): - return obj.strftime('%Y-%m-%d %H:%M:%S') - elif isinstance(obj, datetime.date): - return obj.strftime('%Y-%m-%d') - elif isinstance(obj, datetime.timedelta): - return str(obj) - elif issubclass(type(obj), Enum) or issubclass(type(obj), IntEnum): - return obj.value - elif isinstance(obj, set): - return list(obj) - elif issubclass(type(obj), BaseType): - if not self._with_type: - return obj.to_dict() - else: - return obj.to_dict_with_type() - elif isinstance(obj, type): - return obj.__name__ - else: - return json.JSONEncoder.default(self, obj) - - -def rag_uuid(): - return uuid.uuid1().hex - - -def string_to_bytes(string): - return string if isinstance( - string, bytes) else string.encode(encoding="utf-8") - - -def bytes_to_string(byte): - return byte.decode(encoding="utf-8") - - -def json_dumps(src, byte=False, indent=None, with_type=False): - dest = json.dumps( - src, - indent=indent, - cls=CustomJSONEncoder, - with_type=with_type) - if byte: - dest = string_to_bytes(dest) - return dest - - -def json_loads(src, object_hook=None, object_pairs_hook=None): - if isinstance(src, bytes): - src = bytes_to_string(src) - return json.loads(src, object_hook=object_hook, - object_pairs_hook=object_pairs_hook) - - -def current_timestamp(): - return int(time.time() * 1000) - - -def timestamp_to_date(timestamp, format_string="%Y-%m-%d %H:%M:%S"): - if not timestamp: - timestamp = time.time() - timestamp = int(timestamp) / 1000 - time_array = time.localtime(timestamp) - str_date = time.strftime(format_string, time_array) - return str_date - - -def date_string_to_timestamp(time_str, format_string="%Y-%m-%d %H:%M:%S"): - time_array = time.strptime(time_str, format_string) - time_stamp = int(time.mktime(time_array) * 1000) - return time_stamp - - -def serialize_b64(src, to_str=False): - dest = base64.b64encode(pickle.dumps(src)) - if not to_str: - return dest - else: - return bytes_to_string(dest) - - -def deserialize_b64(src): - src = base64.b64decode( - string_to_bytes(src) if isinstance( - src, str) else src) - if use_deserialize_safe_module: - return restricted_loads(src) - return pickle.loads(src) - - -safe_module = { - 'numpy', - 'rag_flow' -} - - -class RestrictedUnpickler(pickle.Unpickler): - def find_class(self, module, name): - import importlib - if module.split('.')[0] in safe_module: - _module = importlib.import_module(module) - return getattr(_module, name) - # Forbid everything else. - raise pickle.UnpicklingError("global '%s.%s' is forbidden" % - (module, name)) - - -def restricted_loads(src): - """Helper function analogous to pickle.loads().""" - return RestrictedUnpickler(io.BytesIO(src)).load() - - -def get_lan_ip(): - if os.name != "nt": - import fcntl - import struct - - def get_interface_ip(ifname): - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - return socket.inet_ntoa( - fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', string_to_bytes(ifname[:15])))[20:24]) - - ip = socket.gethostbyname(socket.getfqdn()) - if ip.startswith("127.") and os.name != "nt": - interfaces = [ - "bond1", - "eth0", - "eth1", - "eth2", - "wlan0", - "wlan1", - "wifi0", - "ath0", - "ath1", - "ppp0", - ] - for ifname in interfaces: - try: - ip = get_interface_ip(ifname) - break - except IOError: - pass - return ip or '' def from_dict_hook(in_dict: dict): @@ -279,113 +25,3 @@ def from_dict_hook(in_dict: dict): in_dict["module"]), in_dict["type"])(**in_dict["data"]) else: return in_dict - - -def decrypt_database_password(password): - encrypt_password = get_base_config("encrypt_password", False) - encrypt_module = get_base_config("encrypt_module", False) - private_key = get_base_config("private_key", None) - - if not password or not encrypt_password: - return password - - if not private_key: - raise ValueError("No private key") - - module_fun = encrypt_module.split("#") - pwdecrypt_fun = getattr( - importlib.import_module( - module_fun[0]), - module_fun[1]) - - return pwdecrypt_fun(private_key, password) - - -def decrypt_database_config( - database=None, passwd_key="password", name="database"): - if not database: - database = get_base_config(name, {}) - - database[passwd_key] = decrypt_database_password(database[passwd_key]) - return database - - -def update_config(key, value, conf_name=SERVICE_CONF): - conf_path = conf_realpath(conf_name=conf_name) - if not os.path.isabs(conf_path): - conf_path = os.path.join( - file_utils.get_project_base_directory(), conf_path) - - with FileLock(os.path.join(os.path.dirname(conf_path), ".lock")): - config = file_utils.load_yaml_conf(conf_path=conf_path) or {} - config[key] = value - file_utils.rewrite_yaml_conf(conf_path=conf_path, config=config) - - -def get_uuid(): - return uuid.uuid1().hex - - -def datetime_format(date_time: datetime.datetime) -> datetime.datetime: - return datetime.datetime(date_time.year, date_time.month, date_time.day, - date_time.hour, date_time.minute, date_time.second) - - -def get_format_time() -> datetime.datetime: - return datetime_format(datetime.datetime.now()) - - -def str2date(date_time: str): - return datetime.datetime.strptime(date_time, '%Y-%m-%d') - - -def elapsed2time(elapsed): - seconds = elapsed / 1000 - minuter, second = divmod(seconds, 60) - hour, minuter = divmod(minuter, 60) - return '%02d:%02d:%02d' % (hour, minuter, second) - - -def decrypt(line): - file_path = os.path.join( - file_utils.get_project_base_directory(), - "conf", - "private.pem") - rsa_key = RSA.importKey(open(file_path).read(), "Welcome") - cipher = Cipher_pkcs1_v1_5.new(rsa_key) - return cipher.decrypt(base64.b64decode( - line), "Fail to decrypt password!").decode('utf-8') - - -def decrypt2(crypt_text): - from base64 import b64decode, b16decode - from Crypto.Cipher import PKCS1_v1_5 as Cipher_PKCS1_v1_5 - from Crypto.PublicKey import RSA - decode_data = b64decode(crypt_text) - if len(decode_data) == 127: - hex_fixed = '00' + decode_data.hex() - decode_data = b16decode(hex_fixed.upper()) - - file_path = os.path.join( - file_utils.get_project_base_directory(), - "conf", - "private.pem") - pem = open(file_path).read() - rsa_key = RSA.importKey(pem, "Welcome") - cipher = Cipher_PKCS1_v1_5.new(rsa_key) - decrypt_text = cipher.decrypt(decode_data, None) - return (b64decode(decrypt_text)).decode() - - -def download_img(url): - if not url: - return "" - response = requests.get(url) - return "data:" + \ - response.headers.get('Content-Type', 'image/jpg') + ";" + \ - "base64," + base64.b64encode(response.content).decode("utf-8") - - -def delta_seconds(date_string: str): - dt = datetime.datetime.strptime(date_string, "%Y-%m-%d %H:%M:%S") - return (datetime.datetime.now() - dt).total_seconds() diff --git a/api/utils/api_utils.py b/api/utils/api_utils.py index 8368d9ad421..4cace9eca02 100644 --- a/api/utils/api_utils.py +++ b/api/utils/api_utils.py @@ -13,94 +13,65 @@ # See the License for the specific language governing permissions and # limitations under the License. # + import functools import json import logging -import random +import os import time -from base64 import b64encode from copy import deepcopy from functools import wraps -from hmac import HMAC -from io import BytesIO -from urllib.parse import quote, urlencode -from uuid import uuid1 import requests +import trio from flask import ( Response, jsonify, - make_response, - send_file, ) +from flask_login import current_user from flask import ( request as flask_request, ) -from itsdangerous import URLSafeTimedSerializer from peewee import OperationalError -from werkzeug.http import HTTP_STATUS_CODES -from api import settings -from api.constants import REQUEST_MAX_WAIT_SEC, REQUEST_WAIT_SEC +from common.constants import ActiveEnum from api.db.db_models import APIToken -from api.db.services.llm_service import LLMService, TenantLLMService -from api.utils import CustomJSONEncoder, get_uuid, json_dumps +from api.utils.json_encode import CustomJSONEncoder +from rag.utils.mcp_tool_call_conn import MCPToolCallSession, close_multiple_mcp_toolcall_sessions +from api.db.services.tenant_llm_service import LLMFactoriesService +from common.connection_utils import timeout +from common.constants import RetCode +from common import settings requests.models.complexjson.dumps = functools.partial(json.dumps, cls=CustomJSONEncoder) -def request(**kwargs): - sess = requests.Session() - stream = kwargs.pop("stream", sess.stream) - timeout = kwargs.pop("timeout", None) - kwargs["headers"] = {k.replace("_", "-").upper(): v for k, v in kwargs.get("headers", {}).items()} - prepped = requests.Request(**kwargs).prepare() - - if settings.CLIENT_AUTHENTICATION and settings.HTTP_APP_KEY and settings.SECRET_KEY: - timestamp = str(round(time() * 1000)) - nonce = str(uuid1()) - signature = b64encode( - HMAC( - settings.SECRET_KEY.encode("ascii"), - b"\n".join( - [ - timestamp.encode("ascii"), - nonce.encode("ascii"), - settings.HTTP_APP_KEY.encode("ascii"), - prepped.path_url.encode("ascii"), - prepped.body if kwargs.get("json") else b"", - urlencode(sorted(kwargs["data"].items()), quote_via=quote, safe="-._~").encode("ascii") if kwargs.get("data") and isinstance(kwargs["data"], dict) else b"", - ] - ), - "sha1", - ).digest() - ).decode("ascii") - - prepped.headers.update( - { - "TIMESTAMP": timestamp, - "NONCE": nonce, - "APP-KEY": settings.HTTP_APP_KEY, - "SIGNATURE": signature, - } - ) - - return sess.send(prepped, stream=stream, timeout=timeout) - - -def get_exponential_backoff_interval(retries, full_jitter=False): - """Calculate the exponential backoff wait time.""" - # Will be zero if factor equals 0 - countdown = min(REQUEST_MAX_WAIT_SEC, REQUEST_WAIT_SEC * (2**retries)) - # Full jitter according to - # https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ - if full_jitter: - countdown = random.randrange(countdown + 1) - # Adjust according to maximum wait time and account for negative values. - return max(0, countdown) +def serialize_for_json(obj): + """ + Recursively serialize objects to make them JSON serializable. + Handles ModelMetaclass and other non-serializable objects. + """ + if hasattr(obj, "__dict__"): + # For objects with __dict__, try to serialize their attributes + try: + return {key: serialize_for_json(value) for key, value in obj.__dict__.items() if not key.startswith("_")} + except (AttributeError, TypeError): + return str(obj) + elif hasattr(obj, "__name__"): + # For classes and metaclasses, return their name + return f"<{obj.__module__}.{obj.__name__}>" if hasattr(obj, "__module__") else f"<{obj.__name__}>" + elif isinstance(obj, (list, tuple)): + return [serialize_for_json(item) for item in obj] + elif isinstance(obj, dict): + return {key: serialize_for_json(value) for key, value in obj.items()} + elif isinstance(obj, (str, int, float, bool)) or obj is None: + return obj + else: + # Fallback: convert to string representation + return str(obj) -def get_data_error_result(code=settings.RetCode.DATA_ERROR, message="Sorry! Data missing!"): +def get_data_error_result(code=RetCode.DATA_ERROR, message="Sorry! Data missing!"): logging.exception(Exception(message)) result_dict = {"code": code, "message": message} response = {} @@ -115,32 +86,22 @@ def get_data_error_result(code=settings.RetCode.DATA_ERROR, message="Sorry! Data def server_error_response(e): logging.exception(e) try: - if e.code == 401: - return get_json_result(code=401, message=repr(e)) - except BaseException: - pass + msg = repr(e).lower() + if getattr(e, "code", None) == 401 or ("unauthorized" in msg) or ("401" in msg): + return get_json_result(code=RetCode.UNAUTHORIZED, message=repr(e)) + except Exception as ex: + logging.warning(f"error checking authorization: {ex}") + if len(e.args) > 1: - return get_json_result(code=settings.RetCode.EXCEPTION_ERROR, message=repr(e.args[0]), data=e.args[1]) + try: + serialized_data = serialize_for_json(e.args[1]) + return get_json_result(code=RetCode.EXCEPTION_ERROR, message=repr(e.args[0]), data=serialized_data) + except Exception: + return get_json_result(code=RetCode.EXCEPTION_ERROR, message=repr(e.args[0]), data=None) if repr(e).find("index_not_found_exception") >= 0: - return get_json_result(code=settings.RetCode.EXCEPTION_ERROR, message="No chunk found, please upload file and parse it.") - - return get_json_result(code=settings.RetCode.EXCEPTION_ERROR, message=repr(e)) - + return get_json_result(code=RetCode.EXCEPTION_ERROR, message="No chunk found, please upload file and parse it.") -def error_response(response_code, message=None): - if message is None: - message = HTTP_STATUS_CODES.get(response_code, "Unknown Error") - - return Response( - json.dumps( - { - "message": message, - "code": response_code, - } - ), - status=response_code, - mimetype="application/json", - ) + return get_json_result(code=RetCode.EXCEPTION_ERROR, message=repr(e)) def validate_request(*args, **kwargs): @@ -168,7 +129,7 @@ def decorated_function(*_args, **_kwargs): error_string += "required argument are missing: {}; ".format(",".join(no_arguments)) if error_arguments: error_string += "required argument values: {}".format(",".join(["{}={}".format(a[0], a[1]) for a in error_arguments])) - return get_json_result(code=settings.RetCode.ARGUMENT_ERROR, message=error_string) + return get_json_result(code=RetCode.ARGUMENT_ERROR, message=error_string) return func(*_args, **_kwargs) return decorated_function @@ -182,7 +143,7 @@ def wrapper(*args, **kwargs): input_arguments = flask_request.json or flask_request.form.to_dict() for param in params: if param in input_arguments: - return get_json_result(code=settings.RetCode.ARGUMENT_ERROR, message=f"Parameter {param} isn't allowed") + return get_json_result(code=RetCode.ARGUMENT_ERROR, message=f"Parameter {param} isn't allowed") return f(*args, **kwargs) return wrapper @@ -190,24 +151,22 @@ def wrapper(*args, **kwargs): return decorator -def is_localhost(ip): - return ip in {"127.0.0.1", "::1", "[::1]", "localhost"} - +def active_required(f): + @wraps(f) + def wrapper(*args, **kwargs): + from api.db.services import UserService -def send_file_in_mem(data, filename): - if not isinstance(data, (str, bytes)): - data = json_dumps(data) - if isinstance(data, str): - data = data.encode("utf-8") + user_id = current_user.id + usr = UserService.filter_by_id(user_id) + # check is_active + if not usr or not usr.is_active == ActiveEnum.ACTIVE.value: + return get_json_result(code=RetCode.FORBIDDEN, message="User isn't active, please activate first.") + return f(*args, **kwargs) - f = BytesIO() - f.write(data) - f.seek(0) - - return send_file(f, as_attachment=True, attachment_filename=filename) + return wrapper -def get_json_result(code=settings.RetCode.SUCCESS, message="success", data=None): +def get_json_result(code: RetCode = RetCode.SUCCESS, message="success", data=None): response = {"code": code, "message": message, "data": data} return jsonify(response) @@ -218,72 +177,32 @@ def decorated_function(*args, **kwargs): token = flask_request.headers.get("Authorization").split()[1] objs = APIToken.query(token=token) if not objs: - return build_error_result(message="API-KEY is invalid!", code=settings.RetCode.FORBIDDEN) + return build_error_result(message="API-KEY is invalid!", code=RetCode.FORBIDDEN) kwargs["tenant_id"] = objs[0].tenant_id return func(*args, **kwargs) return decorated_function -def build_error_result(code=settings.RetCode.FORBIDDEN, message="success"): +def build_error_result(code=RetCode.FORBIDDEN, message="success"): response = {"code": code, "message": message} response = jsonify(response) response.status_code = code return response -def construct_response(code=settings.RetCode.SUCCESS, message="success", data=None, auth=None): - result_dict = {"code": code, "message": message, "data": data} - response_dict = {} - for key, value in result_dict.items(): - if value is None and key != "code": - continue - else: - response_dict[key] = value - response = make_response(jsonify(response_dict)) - if auth: - response.headers["Authorization"] = auth - response.headers["Access-Control-Allow-Origin"] = "*" - response.headers["Access-Control-Allow-Method"] = "*" - response.headers["Access-Control-Allow-Headers"] = "*" - response.headers["Access-Control-Allow-Headers"] = "*" - response.headers["Access-Control-Expose-Headers"] = "Authorization" - return response - - -def construct_result(code=settings.RetCode.DATA_ERROR, message="data is missing"): - result_dict = {"code": code, "message": message} - response = {} - for key, value in result_dict.items(): - if value is None and key != "code": - continue - else: - response[key] = value - return jsonify(response) - - -def construct_json_result(code=settings.RetCode.SUCCESS, message="success", data=None): +def construct_json_result(code: RetCode = RetCode.SUCCESS, message="success", data=None): if data is None: return jsonify({"code": code, "message": message}) else: return jsonify({"code": code, "message": message, "data": data}) -def construct_error_response(e): - logging.exception(e) - try: - if e.code == 401: - return construct_json_result(code=settings.RetCode.UNAUTHORIZED, message=repr(e)) - except BaseException: - pass - if len(e.args) > 1: - return construct_json_result(code=settings.RetCode.EXCEPTION_ERROR, message=repr(e.args[0]), data=e.args[1]) - return construct_json_result(code=settings.RetCode.EXCEPTION_ERROR, message=repr(e)) - - def token_required(func): @wraps(func) def decorated_function(*args, **kwargs): + if os.environ.get("DISABLE_SDK"): + return get_json_result(data=False, message="`Authorization` can't be empty") authorization_str = flask_request.headers.get("Authorization") if not authorization_str: return get_json_result(data=False, message="`Authorization` can't be empty") @@ -293,27 +212,39 @@ def decorated_function(*args, **kwargs): token = authorization_list[1] objs = APIToken.query(token=token) if not objs: - return get_json_result(data=False, message="Authentication error: API key is invalid!", code=settings.RetCode.AUTHENTICATION_ERROR) + return get_json_result(data=False, message="Authentication error: API key is invalid!", code=RetCode.AUTHENTICATION_ERROR) kwargs["tenant_id"] = objs[0].tenant_id return func(*args, **kwargs) return decorated_function -def get_result(code=settings.RetCode.SUCCESS, message="", data=None): - if code == 0: +def get_result(code=RetCode.SUCCESS, message="", data=None, total=None): + """ + Standard API response format: + { + "code": 0, + "data": [...], # List or object, backward compatible + "total": 47, # Optional field for pagination + "message": "..." # Error or status message + } + """ + response = {"code": code} + + if code == RetCode.SUCCESS: if data is not None: - response = {"code": code, "data": data} - else: - response = {"code": code} + response["data"] = data + if total is not None: + response["total_datasets"] = total else: - response = {"code": code, "message": message} + response["message"] = message or "Error" + return jsonify(response) def get_error_data_result( message="Sorry! Data missing!", - code=settings.RetCode.DATA_ERROR, + code=RetCode.DATA_ERROR, ): result_dict = {"code": code, "message": message} response = {} @@ -326,59 +257,111 @@ def get_error_data_result( def get_error_argument_result(message="Invalid arguments"): - return get_result(code=settings.RetCode.ARGUMENT_ERROR, message=message) + return get_result(code=RetCode.ARGUMENT_ERROR, message=message) def get_error_permission_result(message="Permission error"): - return get_result(code=settings.RetCode.PERMISSION_ERROR, message=message) + return get_result(code=RetCode.PERMISSION_ERROR, message=message) def get_error_operating_result(message="Operating error"): - return get_result(code=settings.RetCode.OPERATING_ERROR, message=message) + return get_result(code=RetCode.OPERATING_ERROR, message=message) + +def generate_confirmation_token(): + import secrets -def generate_confirmation_token(tenant_id): - serializer = URLSafeTimedSerializer(tenant_id) - return "ragflow-" + serializer.dumps(get_uuid(), salt=tenant_id)[2:34] + return "ragflow-" + secrets.token_urlsafe(32) def get_parser_config(chunk_method, parser_config): - if parser_config: - return parser_config if not chunk_method: chunk_method = "naive" + + # Define default configurations for each chunking method key_mapping = { - "naive": {"chunk_token_num": 128, "delimiter": r"\n", "html4excel": False, "layout_recognize": "DeepDOC", "raptor": {"use_raptor": False}}, - "qa": {"raptor": {"use_raptor": False}}, + "naive": { + "layout_recognize": "DeepDOC", + "chunk_token_num": 512, + "delimiter": "\n", + "auto_keywords": 0, + "auto_questions": 0, + "html4excel": False, + "topn_tags": 3, + "raptor": { + "use_raptor": True, + "prompt": "Please summarize the following paragraphs. Be careful with the numbers, do not make things up. Paragraphs as following:\n {cluster_content}\nThe above is the content you need to summarize.", + "max_token": 256, + "threshold": 0.1, + "max_cluster": 64, + "random_seed": 0, + }, + "graphrag": { + "use_graphrag": True, + "entity_types": [ + "organization", + "person", + "geo", + "event", + "category", + ], + "method": "light", + }, + }, + "qa": {"raptor": {"use_raptor": False}, "graphrag": {"use_graphrag": False}}, "tag": None, "resume": None, - "manual": {"raptor": {"use_raptor": False}}, + "manual": {"raptor": {"use_raptor": False}, "graphrag": {"use_graphrag": False}}, "table": None, - "paper": {"raptor": {"use_raptor": False}}, - "book": {"raptor": {"use_raptor": False}}, - "laws": {"raptor": {"use_raptor": False}}, - "presentation": {"raptor": {"use_raptor": False}}, + "paper": {"raptor": {"use_raptor": False}, "graphrag": {"use_graphrag": False}}, + "book": {"raptor": {"use_raptor": False}, "graphrag": {"use_graphrag": False}}, + "laws": {"raptor": {"use_raptor": False}, "graphrag": {"use_graphrag": False}}, + "presentation": {"raptor": {"use_raptor": False}, "graphrag": {"use_graphrag": False}}, "one": None, - "knowledge_graph": {"chunk_token_num": 8192, "delimiter": r"\n", "entity_types": ["organization", "person", "location", "event", "time"]}, + "knowledge_graph": { + "chunk_token_num": 8192, + "delimiter": r"\n", + "entity_types": ["organization", "person", "location", "event", "time"], + "raptor": {"use_raptor": False}, + "graphrag": {"use_graphrag": False}, + }, "email": None, "picture": None, } - parser_config = key_mapping[chunk_method] - return parser_config - - -def get_data_openai( - id=None, - created=None, - model=None, - prompt_tokens=0, - completion_tokens=0, - content=None, - finish_reason=None, - object="chat.completion", - param=None, -): + + default_config = key_mapping[chunk_method] + + # If no parser_config provided, return default + if not parser_config: + return default_config + + # If parser_config is provided, merge with defaults to ensure required fields exist + if default_config is None: + return parser_config + + # Ensure raptor and graphrag fields have default values if not provided + merged_config = deep_merge(default_config, parser_config) + + return merged_config + + +def get_data_openai(id=None, created=None, model=None, prompt_tokens=0, completion_tokens=0, content=None, finish_reason=None, object="chat.completion", param=None, stream=False): total_tokens = prompt_tokens + completion_tokens + + if stream: + return { + "id": f"{id}", + "object": "chat.completion.chunk", + "model": model, + "choices": [ + { + "delta": {"content": content}, + "finish_reason": finish_reason, + "index": 0, + } + ], + } + return { "id": f"{id}", "object": object, @@ -389,9 +372,20 @@ def get_data_openai( "prompt_tokens": prompt_tokens, "completion_tokens": completion_tokens, "total_tokens": total_tokens, - "completion_tokens_details": {"reasoning_tokens": 0, "accepted_prediction_tokens": 0, "rejected_prediction_tokens": 0}, + "completion_tokens_details": { + "reasoning_tokens": 0, + "accepted_prediction_tokens": 0, + "rejected_prediction_tokens": 0, + }, }, - "choices": [{"message": {"role": "assistant", "content": content}, "logprobs": None, "finish_reason": finish_reason, "index": 0}], + "choices": [ + { + "message": {"role": "assistant", "content": content}, + "logprobs": None, + "finish_reason": finish_reason, + "index": 0, + } + ], } @@ -425,6 +419,9 @@ def check_duplicate_ids(ids, id_type="item"): def verify_embedding_availability(embd_id: str, tenant_id: str) -> tuple[bool, Response | None]: + from api.db.services.llm_service import LLMService + from api.db.services.tenant_llm_service import TenantLLMService + """ Verifies availability of an embedding model for a specific tenant. @@ -465,7 +462,7 @@ def verify_embedding_availability(embd_id: str, tenant_id: str) -> tuple[bool, R tenant_llms = TenantLLMService.get_my_llms(tenant_id=tenant_id) is_tenant_model = any(llm["llm_name"] == llm_name and llm["llm_factory"] == llm_factory and llm["model_type"] == "embedding" for llm in tenant_llms) - is_builtin_model = embd_id in settings.BUILTIN_EMBEDDING_MODELS + is_builtin_model = llm_factory == "Builtin" if not (is_builtin_model or is_tenant_model or in_llm_service): return False, get_error_argument_result(f"Unsupported model: <{embd_id}>") @@ -558,3 +555,78 @@ def remap_dictionary_keys(source_data: dict, key_aliases: dict = None) -> dict: transformed_data[mapped_key] = value return transformed_data + + +def group_by(list_of_dict, key): + res = {} + for item in list_of_dict: + if item[key] in res.keys(): + res[item[key]].append(item) + else: + res[item[key]] = [item] + return res + + +def get_mcp_tools(mcp_servers: list, timeout: float | int = 10) -> tuple[dict, str]: + results = {} + tool_call_sessions = [] + try: + for mcp_server in mcp_servers: + server_key = mcp_server.id + + cached_tools = mcp_server.variables.get("tools", {}) + + tool_call_session = MCPToolCallSession(mcp_server, mcp_server.variables) + tool_call_sessions.append(tool_call_session) + + try: + tools = tool_call_session.get_tools(timeout) + except Exception: + tools = [] + + results[server_key] = [] + for tool in tools: + tool_dict = tool.model_dump() + cached_tool = cached_tools.get(tool_dict["name"], {}) + + tool_dict["enabled"] = cached_tool.get("enabled", True) + results[server_key].append(tool_dict) + + # PERF: blocking call to close sessions — consider moving to background thread or task queue + close_multiple_mcp_toolcall_sessions(tool_call_sessions) + return results, "" + except Exception as e: + return {}, str(e) + + +async def is_strong_enough(chat_model, embedding_model): + count = settings.STRONG_TEST_COUNT + if not chat_model or not embedding_model: + return + if isinstance(count, int) and count <= 0: + return + + @timeout(60, 2) + async def _is_strong_enough(): + nonlocal chat_model, embedding_model + if embedding_model: + with trio.fail_after(10): + _ = await trio.to_thread.run_sync(lambda: embedding_model.encode(["Are you strong enough!?"])) + if chat_model: + with trio.fail_after(30): + res = await trio.to_thread.run_sync(lambda: chat_model.chat("Nothing special.", [{"role": "user", "content": "Are you strong enough!?"}], {})) + if res.find("**ERROR**") >= 0: + raise Exception(res) + + # Pressure test for GraphRAG task + async with trio.open_nursery() as nursery: + for _ in range(count): + nursery.start_soon(_is_strong_enough) + + +def get_allowed_llm_factories() -> list: + factories = list(LLMFactoriesService.get_all(reverse=True, order_by="rank")) + if settings.ALLOWED_LLM_FACTORIES is None: + return factories + + return [factory for factory in factories if factory.name in settings.ALLOWED_LLM_FACTORIES] diff --git a/api/utils/base64_image.py b/api/utils/base64_image.py new file mode 100644 index 00000000000..cd7307f51a5 --- /dev/null +++ b/api/utils/base64_image.py @@ -0,0 +1,15 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/api/utils/common.py b/api/utils/common.py new file mode 100644 index 00000000000..958cf20ffc2 --- /dev/null +++ b/api/utils/common.py @@ -0,0 +1,24 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +def string_to_bytes(string): + return string if isinstance( + string, bytes) else string.encode(encoding="utf-8") + + +def bytes_to_string(byte): + return byte.decode(encoding="utf-8") + diff --git a/api/utils/configs.py b/api/utils/configs.py new file mode 100644 index 00000000000..91baa28e36e --- /dev/null +++ b/api/utils/configs.py @@ -0,0 +1,61 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import io +import base64 +import pickle +from api.utils.common import bytes_to_string, string_to_bytes +from common.config_utils import get_base_config + +safe_module = { + 'numpy', + 'rag_flow' +} + + +class RestrictedUnpickler(pickle.Unpickler): + def find_class(self, module, name): + import importlib + if module.split('.')[0] in safe_module: + _module = importlib.import_module(module) + return getattr(_module, name) + # Forbid everything else. + raise pickle.UnpicklingError("global '%s.%s' is forbidden" % + (module, name)) + + +def restricted_loads(src): + """Helper function analogous to pickle.loads().""" + return RestrictedUnpickler(io.BytesIO(src)).load() + + +def serialize_b64(src, to_str=False): + dest = base64.b64encode(pickle.dumps(src)) + if not to_str: + return dest + else: + return bytes_to_string(dest) + + +def deserialize_b64(src): + src = base64.b64decode( + string_to_bytes(src) if isinstance( + src, str) else src) + use_deserialize_safe_module = get_base_config( + 'use_deserialize_safe_module', False) + if use_deserialize_safe_module: + return restricted_loads(src) + return pickle.loads(src) diff --git a/api/utils/crypt.py b/api/utils/crypt.py new file mode 100644 index 00000000000..174ca356835 --- /dev/null +++ b/api/utils/crypt.py @@ -0,0 +1,64 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import base64 +import os +import sys +from Cryptodome.PublicKey import RSA +from Cryptodome.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5 +from common.file_utils import get_project_base_directory + + +def crypt(line): + """ + decrypt(crypt(input_string)) == base64(input_string), which frontend and admin_client use. + """ + file_path = os.path.join(get_project_base_directory(), "conf", "public.pem") + rsa_key = RSA.importKey(open(file_path).read(), "Welcome") + cipher = Cipher_pkcs1_v1_5.new(rsa_key) + password_base64 = base64.b64encode(line.encode('utf-8')).decode("utf-8") + encrypted_password = cipher.encrypt(password_base64.encode()) + return base64.b64encode(encrypted_password).decode('utf-8') + + +def decrypt(line): + file_path = os.path.join(get_project_base_directory(), "conf", "private.pem") + rsa_key = RSA.importKey(open(file_path).read(), "Welcome") + cipher = Cipher_pkcs1_v1_5.new(rsa_key) + return cipher.decrypt(base64.b64decode(line), "Fail to decrypt password!").decode('utf-8') + + +def decrypt2(crypt_text): + from base64 import b64decode, b16decode + from Crypto.Cipher import PKCS1_v1_5 as Cipher_PKCS1_v1_5 + from Crypto.PublicKey import RSA + decode_data = b64decode(crypt_text) + if len(decode_data) == 127: + hex_fixed = '00' + decode_data.hex() + decode_data = b16decode(hex_fixed.upper()) + + file_path = os.path.join(get_project_base_directory(), "conf", "private.pem") + pem = open(file_path).read() + rsa_key = RSA.importKey(pem, "Welcome") + cipher = Cipher_PKCS1_v1_5.new(rsa_key) + decrypt_text = cipher.decrypt(decode_data, None) + return (b64decode(decrypt_text)).decode() + + +if __name__ == "__main__": + passwd = crypt(sys.argv[1]) + print(passwd) + print(decrypt(passwd)) diff --git a/api/utils/email_templates.py b/api/utils/email_templates.py new file mode 100644 index 00000000000..10473908a88 --- /dev/null +++ b/api/utils/email_templates.py @@ -0,0 +1,25 @@ +""" +Reusable HTML email templates and registry. +""" + +# Invitation email template +INVITE_EMAIL_TMPL = """ +

Hi {{email}},

+

{{inviter}} has invited you to join their team (ID: {{tenant_id}}).

+

Click the link below to complete your registration:
+{{invite_url}}

+

If you did not request this, please ignore this email.

+""" + +# Password reset code template +RESET_CODE_EMAIL_TMPL = """ +

Hello,

+

Your password reset code is: {{ code }}

+

This code will expire in {{ ttl_min }} minutes.

+""" + +# Template registry +EMAIL_TEMPLATES = { + "invite": INVITE_EMAIL_TMPL, + "reset_code": RESET_CODE_EMAIL_TMPL, +} diff --git a/api/utils/file_utils.py b/api/utils/file_utils.py index 7fefc54a651..5f0fa70f451 100644 --- a/api/utils/file_utils.py +++ b/api/utils/file_utils.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # + + +# Standard library imports import base64 -import json -import os import re import shutil import subprocess @@ -25,143 +26,29 @@ from io import BytesIO import pdfplumber -from cachetools import LRUCache, cached from PIL import Image -from ruamel.yaml import YAML +# Local imports from api.constants import IMG_BASE64_PREFIX from api.db import FileType -PROJECT_BASE = os.getenv("RAG_PROJECT_BASE") or os.getenv("RAG_DEPLOY_BASE") -RAG_BASE = os.getenv("RAG_BASE") - LOCK_KEY_pdfplumber = "global_shared_lock_pdfplumber" if LOCK_KEY_pdfplumber not in sys.modules: sys.modules[LOCK_KEY_pdfplumber] = threading.Lock() -def get_project_base_directory(*args): - global PROJECT_BASE - if PROJECT_BASE is None: - PROJECT_BASE = os.path.abspath( - os.path.join( - os.path.dirname(os.path.realpath(__file__)), - os.pardir, - os.pardir, - ) - ) - - if args: - return os.path.join(PROJECT_BASE, *args) - return PROJECT_BASE - - -def get_rag_directory(*args): - global RAG_BASE - if RAG_BASE is None: - RAG_BASE = os.path.abspath( - os.path.join( - os.path.dirname(os.path.realpath(__file__)), - os.pardir, - os.pardir, - os.pardir, - ) - ) - if args: - return os.path.join(RAG_BASE, *args) - return RAG_BASE - - -def get_rag_python_directory(*args): - return get_rag_directory("python", *args) - - -def get_home_cache_dir(): - dir = os.path.join(os.path.expanduser("~"), ".ragflow") - try: - os.mkdir(dir) - except OSError: - pass - return dir - - -@cached(cache=LRUCache(maxsize=10)) -def load_json_conf(conf_path): - if os.path.isabs(conf_path): - json_conf_path = conf_path - else: - json_conf_path = os.path.join(get_project_base_directory(), conf_path) - try: - with open(json_conf_path) as f: - return json.load(f) - except BaseException: - raise EnvironmentError("loading json file config from '{}' failed!".format(json_conf_path)) - - -def dump_json_conf(config_data, conf_path): - if os.path.isabs(conf_path): - json_conf_path = conf_path - else: - json_conf_path = os.path.join(get_project_base_directory(), conf_path) - try: - with open(json_conf_path, "w") as f: - json.dump(config_data, f, indent=4) - except BaseException: - raise EnvironmentError("loading json file config from '{}' failed!".format(json_conf_path)) - - -def load_json_conf_real_time(conf_path): - if os.path.isabs(conf_path): - json_conf_path = conf_path - else: - json_conf_path = os.path.join(get_project_base_directory(), conf_path) - try: - with open(json_conf_path) as f: - return json.load(f) - except BaseException: - raise EnvironmentError("loading json file config from '{}' failed!".format(json_conf_path)) - - -def load_yaml_conf(conf_path): - if not os.path.isabs(conf_path): - conf_path = os.path.join(get_project_base_directory(), conf_path) - try: - with open(conf_path) as f: - yaml = YAML(typ="safe", pure=True) - return yaml.load(f) - except Exception as e: - raise EnvironmentError("loading yaml file config from {} failed:".format(conf_path), e) - - -def rewrite_yaml_conf(conf_path, config): - if not os.path.isabs(conf_path): - conf_path = os.path.join(get_project_base_directory(), conf_path) - try: - with open(conf_path, "w") as f: - yaml = YAML(typ="safe") - yaml.dump(config, f) - except Exception as e: - raise EnvironmentError("rewrite yaml file config {} failed:".format(conf_path), e) - - -def rewrite_json_file(filepath, json_data): - with open(filepath, "w", encoding="utf-8") as f: - json.dump(json_data, f, indent=4, separators=(",", ": ")) - f.close() - - def filename_type(filename): filename = filename.lower() if re.match(r".*\.pdf$", filename): return FileType.PDF.value - if re.match(r".*\.(eml|doc|docx|ppt|pptx|yml|xml|htm|json|csv|txt|ini|xls|xlsx|wps|rtf|hlp|pages|numbers|key|md|py|js|java|c|cpp|h|php|go|ts|sh|cs|kt|html|sql)$", filename): + if re.match(r".*\.(msg|eml|doc|docx|ppt|pptx|yml|xml|htm|json|jsonl|ldjson|csv|txt|ini|xls|xlsx|wps|rtf|hlp|pages|numbers|key|md|py|js|java|c|cpp|h|php|go|ts|sh|cs|kt|html|sql)$", filename): return FileType.DOC.value if re.match(r".*\.(wav|flac|ape|alac|wavpack|wv|mp3|aac|ogg|vorbis|opus)$", filename): return FileType.AURAL.value - if re.match(r".*\.(jpg|jpeg|png|tif|gif|pcx|tga|exif|fpx|svg|psd|cdr|pcd|dxf|ufo|eps|ai|raw|WMF|webp|avif|apng|icon|ico|mpg|mpeg|avi|rm|rmvb|mov|wmv|asf|dat|asx|wvx|mpe|mpa|mp4)$", filename): + if re.match(r".*\.(jpg|jpeg|png|tif|gif|pcx|tga|exif|fpx|svg|psd|cdr|pcd|dxf|ufo|eps|ai|raw|WMF|webp|avif|apng|icon|ico|mpg|mpeg|avi|rm|rmvb|mov|wmv|asf|dat|asx|wvx|mpe|mpa|mp4|avi|mkv)$", filename): return FileType.VISUAL.value return FileType.OTHER.value @@ -230,13 +117,6 @@ def thumbnail(filename, blob): return "" -def traversal_files(base): - for root, ds, fs in os.walk(base): - for f in fs: - fullname = os.path.join(root, f) - yield fullname - - def repair_pdf_with_ghostscript(input_bytes): if shutil.which("gs") is None: return input_bytes diff --git a/api/utils/health_utils.py b/api/utils/health_utils.py new file mode 100644 index 00000000000..88e5aaebbee --- /dev/null +++ b/api/utils/health_utils.py @@ -0,0 +1,221 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from datetime import datetime +import json +import os +import requests +from timeit import default_timer as timer + +from api.db.db_models import DB +from rag.utils.redis_conn import REDIS_CONN +from rag.utils.es_conn import ESConnection +from rag.utils.infinity_conn import InfinityConnection +from common import settings + + +def _ok_nok(ok: bool) -> str: + return "ok" if ok else "nok" + + +def check_db() -> tuple[bool, dict]: + st = timer() + try: + # lightweight probe; works for MySQL/Postgres + DB.execute_sql("SELECT 1") + return True, {"elapsed": f"{(timer() - st) * 1000.0:.1f}"} + except Exception as e: + return False, {"elapsed": f"{(timer() - st) * 1000.0:.1f}", "error": str(e)} + + +def check_redis() -> tuple[bool, dict]: + st = timer() + try: + ok = bool(REDIS_CONN.health()) + return ok, {"elapsed": f"{(timer() - st) * 1000.0:.1f}"} + except Exception as e: + return False, {"elapsed": f"{(timer() - st) * 1000.0:.1f}", "error": str(e)} + + +def check_doc_engine() -> tuple[bool, dict]: + st = timer() + try: + meta = settings.docStoreConn.health() + # treat any successful call as ok + return True, {"elapsed": f"{(timer() - st) * 1000.0:.1f}", **(meta or {})} + except Exception as e: + return False, {"elapsed": f"{(timer() - st) * 1000.0:.1f}", "error": str(e)} + + +def check_storage() -> tuple[bool, dict]: + st = timer() + try: + settings.STORAGE_IMPL.health() + return True, {"elapsed": f"{(timer() - st) * 1000.0:.1f}"} + except Exception as e: + return False, {"elapsed": f"{(timer() - st) * 1000.0:.1f}", "error": str(e)} + + +def get_es_cluster_stats() -> dict: + doc_engine = os.getenv('DOC_ENGINE', 'elasticsearch') + if doc_engine != 'elasticsearch': + raise Exception("Elasticsearch is not in use.") + try: + return { + "status": "alive", + "message": ESConnection().get_cluster_stats() + } + except Exception as e: + return { + "status": "timeout", + "message": f"error: {str(e)}", + } + + +def get_infinity_status(): + doc_engine = os.getenv('DOC_ENGINE', 'elasticsearch') + if doc_engine != 'infinity': + raise Exception("Infinity is not in use.") + try: + return { + "status": "alive", + "message": InfinityConnection().health() + } + except Exception as e: + return { + "status": "timeout", + "message": f"error: {str(e)}", + } + + +def get_mysql_status(): + try: + cursor = DB.execute_sql("SHOW PROCESSLIST;") + res_rows = cursor.fetchall() + headers = ['id', 'user', 'host', 'db', 'command', 'time', 'state', 'info'] + cursor.close() + return { + "status": "alive", + "message": [dict(zip(headers, r)) for r in res_rows] + } + except Exception as e: + return { + "status": "timeout", + "message": f"error: {str(e)}", + } + + +def check_minio_alive(): + start_time = timer() + try: + response = requests.get(f'http://{settings.MINIO["host"]}/minio/health/live') + if response.status_code == 200: + return {"status": "alive", "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} + else: + return {"status": "timeout", "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} + except Exception as e: + return { + "status": "timeout", + "message": f"error: {str(e)}", + } + + +def get_redis_info(): + try: + return { + "status": "alive", + "message": REDIS_CONN.info() + } + except Exception as e: + return { + "status": "timeout", + "message": f"error: {str(e)}", + } + + +def check_ragflow_server_alive(): + start_time = timer() + try: + url = f'http://{settings.HOST_IP}:{settings.HOST_PORT}/v1/system/ping' + if '0.0.0.0' in url: + url = url.replace('0.0.0.0', '127.0.0.1') + response = requests.get(url) + if response.status_code == 200: + return {"status": "alive", "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} + else: + return {"status": "timeout", "message": f"Confirm elapsed: {(timer() - start_time) * 1000.0:.1f} ms."} + except Exception as e: + return { + "status": "timeout", + "message": f"error: {str(e)}", + } + + +def check_task_executor_alive(): + task_executor_heartbeats = {} + try: + task_executors = REDIS_CONN.smembers("TASKEXE") + now = datetime.now().timestamp() + for task_executor_id in task_executors: + heartbeats = REDIS_CONN.zrangebyscore(task_executor_id, now - 60 * 30, now) + heartbeats = [json.loads(heartbeat) for heartbeat in heartbeats] + task_executor_heartbeats[task_executor_id] = heartbeats + if task_executor_heartbeats: + return {"status": "alive", "message": task_executor_heartbeats} + else: + return {"status": "timeout", "message": "Not found any task executor."} + except Exception as e: + return { + "status": "timeout", + "message": f"error: {str(e)}" + } + + +def run_health_checks() -> tuple[dict, bool]: + result: dict[str, str | dict] = {} + + db_ok, db_meta = check_db() + result["db"] = _ok_nok(db_ok) + if not db_ok: + result.setdefault("_meta", {})["db"] = db_meta + + try: + redis_ok, redis_meta = check_redis() + result["redis"] = _ok_nok(redis_ok) + if not redis_ok: + result.setdefault("_meta", {})["redis"] = redis_meta + except Exception: + result["redis"] = "nok" + + try: + doc_ok, doc_meta = check_doc_engine() + result["doc_engine"] = _ok_nok(doc_ok) + if not doc_ok: + result.setdefault("_meta", {})["doc_engine"] = doc_meta + except Exception: + result["doc_engine"] = "nok" + + try: + sto_ok, sto_meta = check_storage() + result["storage"] = _ok_nok(sto_ok) + if not sto_ok: + result.setdefault("_meta", {})["storage"] = sto_meta + except Exception: + result["storage"] = "nok" + + all_ok = (result.get("db") == "ok") and (result.get("redis") == "ok") and (result.get("doc_engine") == "ok") and ( + result.get("storage") == "ok") + result["status"] = "ok" if all_ok else "nok" + return result, all_ok diff --git a/api/utils/json_encode.py b/api/utils/json_encode.py new file mode 100644 index 00000000000..b21addd4f9b --- /dev/null +++ b/api/utils/json_encode.py @@ -0,0 +1,78 @@ +import datetime +import json +from enum import Enum, IntEnum +from api.utils.common import string_to_bytes, bytes_to_string + + +class BaseType: + def to_dict(self): + return dict([(k.lstrip("_"), v) for k, v in self.__dict__.items()]) + + def to_dict_with_type(self): + def _dict(obj): + module = None + if issubclass(obj.__class__, BaseType): + data = {} + for attr, v in obj.__dict__.items(): + k = attr.lstrip("_") + data[k] = _dict(v) + module = obj.__module__ + elif isinstance(obj, (list, tuple)): + data = [] + for i, vv in enumerate(obj): + data.append(_dict(vv)) + elif isinstance(obj, dict): + data = {} + for _k, vv in obj.items(): + data[_k] = _dict(vv) + else: + data = obj + return {"type": obj.__class__.__name__, + "data": data, "module": module} + + return _dict(self) + + +class CustomJSONEncoder(json.JSONEncoder): + def __init__(self, **kwargs): + self._with_type = kwargs.pop("with_type", False) + super().__init__(**kwargs) + + def default(self, obj): + if isinstance(obj, datetime.datetime): + return obj.strftime('%Y-%m-%d %H:%M:%S') + elif isinstance(obj, datetime.date): + return obj.strftime('%Y-%m-%d') + elif isinstance(obj, datetime.timedelta): + return str(obj) + elif issubclass(type(obj), Enum) or issubclass(type(obj), IntEnum): + return obj.value + elif isinstance(obj, set): + return list(obj) + elif issubclass(type(obj), BaseType): + if not self._with_type: + return obj.to_dict() + else: + return obj.to_dict_with_type() + elif isinstance(obj, type): + return obj.__name__ + else: + return json.JSONEncoder.default(self, obj) + + +def json_dumps(src, byte=False, indent=None, with_type=False): + dest = json.dumps( + src, + indent=indent, + cls=CustomJSONEncoder, + with_type=with_type) + if byte: + dest = string_to_bytes(dest) + return dest + + +def json_loads(src, object_hook=None, object_pairs_hook=None): + if isinstance(src, bytes): + src = bytes_to_string(src) + return json.loads(src, object_hook=object_hook, + object_pairs_hook=object_pairs_hook) diff --git a/api/utils/log_utils.py b/api/utils/log_utils.py index 3ebedd14821..cd7307f51a5 100644 --- a/api/utils/log_utils.py +++ b/api/utils/log_utils.py @@ -13,75 +13,3 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import os -import os.path -import logging -from logging.handlers import RotatingFileHandler - -initialized_root_logger = False - -def get_project_base_directory(): - PROJECT_BASE = os.path.abspath( - os.path.join( - os.path.dirname(os.path.realpath(__file__)), - os.pardir, - os.pardir, - ) - ) - return PROJECT_BASE - -def init_root_logger(logfile_basename: str, log_format: str = "%(asctime)-15s %(levelname)-8s %(process)d %(message)s"): - global initialized_root_logger - if initialized_root_logger: - return - initialized_root_logger = True - - logger = logging.getLogger() - logger.handlers.clear() - log_path = os.path.abspath(os.path.join(get_project_base_directory(), "logs", f"{logfile_basename}.log")) - - os.makedirs(os.path.dirname(log_path), exist_ok=True) - formatter = logging.Formatter(log_format) - - handler1 = RotatingFileHandler(log_path, maxBytes=10*1024*1024, backupCount=5) - handler1.setFormatter(formatter) - logger.addHandler(handler1) - - handler2 = logging.StreamHandler() - handler2.setFormatter(formatter) - logger.addHandler(handler2) - - logging.captureWarnings(True) - - LOG_LEVELS = os.environ.get("LOG_LEVELS", "") - pkg_levels = {} - for pkg_name_level in LOG_LEVELS.split(","): - terms = pkg_name_level.split("=") - if len(terms)!= 2: - continue - pkg_name, pkg_level = terms[0], terms[1] - pkg_name = pkg_name.strip() - pkg_level = logging.getLevelName(pkg_level.strip().upper()) - if not isinstance(pkg_level, int): - pkg_level = logging.INFO - pkg_levels[pkg_name] = logging.getLevelName(pkg_level) - - for pkg_name in ['peewee', 'pdfminer']: - if pkg_name not in pkg_levels: - pkg_levels[pkg_name] = logging.getLevelName(logging.WARNING) - if 'root' not in pkg_levels: - pkg_levels['root'] = logging.getLevelName(logging.INFO) - - for pkg_name, pkg_level in pkg_levels.items(): - pkg_logger = logging.getLogger(pkg_name) - pkg_logger.setLevel(pkg_level) - - msg = f"{logfile_basename} log path: {log_path}, log levels: {pkg_levels}" - logger.info(msg) - - -def log_exception(e, *args): - logging.exception(e) - for a in args: - logging.error(str(a)) - raise e \ No newline at end of file diff --git a/api/utils/t_crypt.py b/api/utils/t_crypt.py deleted file mode 100644 index d0763c19f45..00000000000 --- a/api/utils/t_crypt.py +++ /dev/null @@ -1,40 +0,0 @@ -# -# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import base64 -import os -import sys -from Cryptodome.PublicKey import RSA -from Cryptodome.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5 -from api.utils import decrypt, file_utils - - -def crypt(line): - file_path = os.path.join( - file_utils.get_project_base_directory(), - "conf", - "public.pem") - rsa_key = RSA.importKey(open(file_path).read(),"Welcome") - cipher = Cipher_pkcs1_v1_5.new(rsa_key) - password_base64 = base64.b64encode(line.encode('utf-8')).decode("utf-8") - encrypted_password = cipher.encrypt(password_base64.encode()) - return base64.b64encode(encrypted_password).decode('utf-8') - - -if __name__ == "__main__": - passwd = crypt(sys.argv[1]) - print(passwd) - print(decrypt(passwd)) diff --git a/api/utils/validation_utils.py b/api/utils/validation_utils.py index d60dc556102..caf3f0924aa 100644 --- a/api/utils/validation_utils.py +++ b/api/utils/validation_utils.py @@ -14,14 +14,19 @@ # limitations under the License. # from collections import Counter -from enum import auto -from typing import Annotated, Any +from typing import Annotated, Any, Literal from uuid import UUID from flask import Request -from pydantic import BaseModel, Field, StringConstraints, ValidationError, field_validator +from pydantic import ( + BaseModel, + ConfigDict, + Field, + StringConstraints, + ValidationError, + field_validator, +) from pydantic_core import PydanticCustomError -from strenum import StrEnum from werkzeug.exceptions import BadRequest, UnsupportedMediaType from api.constants import DATASET_NAME_LIMIT @@ -307,38 +312,12 @@ def validate_uuid1_hex(v: Any) -> str: raise PydanticCustomError("invalid_UUID1_format", "Invalid UUID1 format") -class PermissionEnum(StrEnum): - me = auto() - team = auto() - - -class ChunkMethodEnum(StrEnum): - naive = auto() - book = auto() - email = auto() - laws = auto() - manual = auto() - one = auto() - paper = auto() - picture = auto() - presentation = auto() - qa = auto() - table = auto() - tag = auto() - - -class GraphragMethodEnum(StrEnum): - light = auto() - general = auto() - - class Base(BaseModel): - class Config: - extra = "forbid" + model_config = ConfigDict(extra="forbid", strict=True) class RaptorConfig(Base): - use_raptor: bool = Field(default=False) + use_raptor: Annotated[bool, Field(default=False)] prompt: Annotated[ str, StringConstraints(strip_whitespace=True, min_length=1), @@ -346,46 +325,49 @@ class RaptorConfig(Base): default="Please summarize the following paragraphs. Be careful with the numbers, do not make things up. Paragraphs as following:\n {cluster_content}\nThe above is the content you need to summarize." ), ] - max_token: int = Field(default=256, ge=1, le=2048) - threshold: float = Field(default=0.1, ge=0.0, le=1.0) - max_cluster: int = Field(default=64, ge=1, le=1024) - random_seed: int = Field(default=0, ge=0) + max_token: Annotated[int, Field(default=256, ge=1, le=2048)] + threshold: Annotated[float, Field(default=0.1, ge=0.0, le=1.0)] + max_cluster: Annotated[int, Field(default=64, ge=1, le=1024)] + random_seed: Annotated[int, Field(default=0, ge=0)] class GraphragConfig(Base): - use_graphrag: bool = Field(default=False) - entity_types: list[str] = Field(default_factory=lambda: ["organization", "person", "geo", "event", "category"]) - method: GraphragMethodEnum = Field(default=GraphragMethodEnum.light) - community: bool = Field(default=False) - resolution: bool = Field(default=False) + use_graphrag: Annotated[bool, Field(default=False)] + entity_types: Annotated[list[str], Field(default_factory=lambda: ["organization", "person", "geo", "event", "category"])] + method: Annotated[Literal["light", "general"], Field(default="light")] + community: Annotated[bool, Field(default=False)] + resolution: Annotated[bool, Field(default=False)] class ParserConfig(Base): - auto_keywords: int = Field(default=0, ge=0, le=32) - auto_questions: int = Field(default=0, ge=0, le=10) - chunk_token_num: int = Field(default=128, ge=1, le=2048) - delimiter: str = Field(default=r"\n", min_length=1) - graphrag: GraphragConfig | None = None - html4excel: bool = False - layout_recognize: str = "DeepDOC" - raptor: RaptorConfig | None = None - tag_kb_ids: list[str] = Field(default_factory=list) - topn_tags: int = Field(default=1, ge=1, le=10) - filename_embd_weight: float | None = Field(default=None, ge=0.0, le=1.0) - task_page_size: int | None = Field(default=None, ge=1) - pages: list[list[int]] | None = None + auto_keywords: Annotated[int, Field(default=0, ge=0, le=32)] + auto_questions: Annotated[int, Field(default=0, ge=0, le=10)] + chunk_token_num: Annotated[int, Field(default=512, ge=1, le=2048)] + delimiter: Annotated[str, Field(default=r"\n", min_length=1)] + graphrag: Annotated[GraphragConfig, Field(default_factory=lambda: GraphragConfig(use_graphrag=False))] + html4excel: Annotated[bool, Field(default=False)] + layout_recognize: Annotated[str, Field(default="DeepDOC")] + raptor: Annotated[RaptorConfig, Field(default_factory=lambda: RaptorConfig(use_raptor=False))] + tag_kb_ids: Annotated[list[str], Field(default_factory=list)] + topn_tags: Annotated[int, Field(default=1, ge=1, le=10)] + filename_embd_weight: Annotated[float | None, Field(default=0.1, ge=0.0, le=1.0)] + task_page_size: Annotated[int | None, Field(default=None, ge=1)] + pages: Annotated[list[list[int]] | None, Field(default=None)] class CreateDatasetReq(Base): name: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1, max_length=DATASET_NAME_LIMIT), Field(...)] - avatar: str | None = Field(default=None, max_length=65535) - description: str | None = Field(default=None, max_length=65535) - embedding_model: Annotated[str, StringConstraints(strip_whitespace=True, max_length=255), Field(default="", serialization_alias="embd_id")] - permission: PermissionEnum = Field(default=PermissionEnum.me, min_length=1, max_length=16) - chunk_method: ChunkMethodEnum = Field(default=ChunkMethodEnum.naive, min_length=1, max_length=32, serialization_alias="parser_id") - parser_config: ParserConfig | None = Field(default=None) - - @field_validator("avatar") + avatar: Annotated[str | None, Field(default=None, max_length=65535)] + description: Annotated[str | None, Field(default=None, max_length=65535)] + embedding_model: Annotated[str | None, Field(default=None, max_length=255, serialization_alias="embd_id")] + permission: Annotated[Literal["me", "team"], Field(default="me", min_length=1, max_length=16)] + chunk_method: Annotated[ + Literal["naive", "book", "email", "laws", "manual", "one", "paper", "picture", "presentation", "qa", "table", "tag"], + Field(default="naive", min_length=1, max_length=32, serialization_alias="parser_id"), + ] + parser_config: Annotated[ParserConfig | None, Field(default=None)] + + @field_validator("avatar", mode="after") @classmethod def validate_avatar_base64(cls, v: str | None) -> str | None: """ @@ -435,9 +417,17 @@ def validate_avatar_base64(cls, v: str | None) -> str | None: else: raise PydanticCustomError("format_invalid", "Missing MIME prefix. Expected format: data:;base64,") + @field_validator("embedding_model", mode="before") + @classmethod + def normalize_embedding_model(cls, v: Any) -> Any: + """Normalize embedding model string by stripping whitespace""" + if isinstance(v, str): + return v.strip() + return v + @field_validator("embedding_model", mode="after") @classmethod - def validate_embedding_model(cls, v: str) -> str: + def validate_embedding_model(cls, v: str | None) -> str | None: """ Validates embedding model identifier format compliance. @@ -464,22 +454,23 @@ def validate_embedding_model(cls, v: str) -> str: Invalid: "@openai" (empty model_name) Invalid: "text-embedding-3-large@" (empty provider) """ - if "@" not in v: - raise PydanticCustomError("format_invalid", "Embedding model identifier must follow @ format") + if isinstance(v, str): + if "@" not in v: + raise PydanticCustomError("format_invalid", "Embedding model identifier must follow @ format") - components = v.split("@", 1) - if len(components) != 2 or not all(components): - raise PydanticCustomError("format_invalid", "Both model_name and provider must be non-empty strings") + components = v.split("@", 1) + if len(components) != 2 or not all(components): + raise PydanticCustomError("format_invalid", "Both model_name and provider must be non-empty strings") - model_name, provider = components - if not model_name.strip() or not provider.strip(): - raise PydanticCustomError("format_invalid", "Model name and provider cannot be whitespace-only strings") + model_name, provider = components + if not model_name.strip() or not provider.strip(): + raise PydanticCustomError("format_invalid", "Model name and provider cannot be whitespace-only strings") return v - @field_validator("permission", mode="before") - @classmethod - def normalize_permission(cls, v: Any) -> Any: - return normalize_str(v) + # @field_validator("permission", mode="before") + # @classmethod + # def normalize_permission(cls, v: Any) -> Any: + # return normalize_str(v) @field_validator("parser_config", mode="before") @classmethod @@ -536,9 +527,9 @@ def validate_parser_config_json_length(cls, v: ParserConfig | None) -> ParserCon class UpdateDatasetReq(CreateDatasetReq): - dataset_id: str = Field(...) + dataset_id: Annotated[str, Field(...)] name: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1, max_length=DATASET_NAME_LIMIT), Field(default="")] - pagerank: int = Field(default=0, ge=0, le=100) + pagerank: Annotated[int, Field(default=0, ge=0, le=100)] @field_validator("dataset_id", mode="before") @classmethod @@ -547,7 +538,7 @@ def validate_dataset_id(cls, v: Any) -> str: class DeleteReq(Base): - ids: list[str] | None = Field(...) + ids: Annotated[list[str] | None, Field(...)] @field_validator("ids", mode="after") @classmethod @@ -626,28 +617,20 @@ def validate_ids(cls, v_list: list[str] | None) -> list[str] | None: class DeleteDatasetReq(DeleteReq): ... -class OrderByEnum(StrEnum): - create_time = auto() - update_time = auto() +class BaseListReq(BaseModel): + model_config = ConfigDict(extra="forbid") - -class BaseListReq(Base): - id: str | None = None - name: str | None = None - page: int = Field(default=1, ge=1) - page_size: int = Field(default=30, ge=1) - orderby: OrderByEnum = Field(default=OrderByEnum.create_time) - desc: bool = Field(default=True) + id: Annotated[str | None, Field(default=None)] + name: Annotated[str | None, Field(default=None)] + page: Annotated[int, Field(default=1, ge=1)] + page_size: Annotated[int, Field(default=30, ge=1)] + orderby: Annotated[Literal["create_time", "update_time"], Field(default="create_time")] + desc: Annotated[bool, Field(default=True)] @field_validator("id", mode="before") @classmethod def validate_id(cls, v: Any) -> str: return validate_uuid1_hex(v) - @field_validator("orderby", mode="before") - @classmethod - def normalize_orderby(cls, v: Any) -> Any: - return normalize_str(v) - class ListDatasetReq(BaseListReq): ... diff --git a/api/utils/web_utils.py b/api/utils/web_utils.py index 084b7a6f73f..e0e47f472e6 100644 --- a/api/utils/web_utils.py +++ b/api/utils/web_utils.py @@ -14,28 +14,84 @@ # limitations under the License. # +import base64 +import ipaddress +import json import re import socket from urllib.parse import urlparse -import ipaddress -import json -import base64 +from api.apps import smtp_mail_server +from flask_mail import Message +from flask import render_template_string +from api.utils.email_templates import EMAIL_TEMPLATES from selenium import webdriver +from selenium.common.exceptions import TimeoutException from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service -from selenium.common.exceptions import TimeoutException -from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.common.by import By from selenium.webdriver.support.expected_conditions import staleness_of +from selenium.webdriver.support.ui import WebDriverWait from webdriver_manager.chrome import ChromeDriverManager -from selenium.webdriver.common.by import By + + +OTP_LENGTH = 8 +OTP_TTL_SECONDS = 5 * 60 +ATTEMPT_LIMIT = 5 +ATTEMPT_LOCK_SECONDS = 30 * 60 +RESEND_COOLDOWN_SECONDS = 60 + + +CONTENT_TYPE_MAP = { + # Office + "docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "doc": "application/msword", + "pdf": "application/pdf", + "csv": "text/csv", + "xls": "application/vnd.ms-excel", + "xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + # Text/code + "txt": "text/plain", + "py": "text/plain", + "js": "text/plain", + "java": "text/plain", + "c": "text/plain", + "cpp": "text/plain", + "h": "text/plain", + "php": "text/plain", + "go": "text/plain", + "ts": "text/plain", + "sh": "text/plain", + "cs": "text/plain", + "kt": "text/plain", + "sql": "text/plain", + # Web + "md": "text/markdown", + "markdown": "text/markdown", + "htm": "text/html", + "html": "text/html", + "json": "application/json", + # Image formats + "png": "image/png", + "jpg": "image/jpeg", + "jpeg": "image/jpeg", + "gif": "image/gif", + "bmp": "image/bmp", + "tiff": "image/tiff", + "tif": "image/tiff", + "webp": "image/webp", + "svg": "image/svg+xml", + "ico": "image/x-icon", + "avif": "image/avif", + "heic": "image/heic", +} def html2pdf( - source: str, - timeout: int = 2, - install_driver: bool = True, - print_options: dict = {}, + source: str, + timeout: int = 2, + install_driver: bool = True, + print_options: dict = {}, ): result = __get_pdf_from_html(source, timeout, install_driver, print_options) return result @@ -53,12 +109,7 @@ def __send_devtools(driver, cmd, params={}): return response.get("value") -def __get_pdf_from_html( - path: str, - timeout: int, - install_driver: bool, - print_options: dict -): +def __get_pdf_from_html(path: str, timeout: int, install_driver: bool, print_options: dict): webdriver_options = Options() webdriver_prefs = {} webdriver_options.add_argument("--headless") @@ -78,9 +129,7 @@ def __get_pdf_from_html( driver.get(path) try: - WebDriverWait(driver, timeout).until( - staleness_of(driver.find_element(by=By.TAG_NAME, value="html")) - ) + WebDriverWait(driver, timeout).until(staleness_of(driver.find_element(by=By.TAG_NAME, value="html"))) except TimeoutException: calculated_print_options = { "landscape": False, @@ -89,8 +138,7 @@ def __get_pdf_from_html( "preferCSSPageSize": True, } calculated_print_options.update(print_options) - result = __send_devtools( - driver, "Page.printToPDF", calculated_print_options) + result = __send_devtools(driver, "Page.printToPDF", calculated_print_options) driver.quit() return base64.b64decode(result["data"]) @@ -102,6 +150,7 @@ def is_private_ip(ip: str) -> bool: except ValueError: return False + def is_valid_url(url: str) -> bool: if not re.match(r"(https?)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]", url): return False @@ -116,4 +165,69 @@ def is_valid_url(url: str) -> bool: return False except socket.gaierror: return False - return True \ No newline at end of file + return True + + +def safe_json_parse(data: str | dict) -> dict: + if isinstance(data, dict): + return data + try: + return json.loads(data) if data else {} + except (json.JSONDecodeError, TypeError): + return {} + + +def get_float(req: dict, key: str, default: float | int = 10.0) -> float: + try: + parsed = float(req.get(key, default)) + return parsed if parsed > 0 else default + except (TypeError, ValueError): + return default + + +def send_email_html(subject: str, to_email: str, template_key: str, **context): + """Generic HTML email sender using shared templates. + template_key must exist in EMAIL_TEMPLATES. + """ + from api.apps import app + tmpl = EMAIL_TEMPLATES.get(template_key) + if not tmpl: + raise ValueError(f"Unknown email template: {template_key}") + with app.app_context(): + msg = Message(subject=subject, recipients=[to_email]) + msg.html = render_template_string(tmpl, **context) + smtp_mail_server.send(msg) + + +def send_invite_email(to_email, invite_url, tenant_id, inviter): + # Reuse the generic HTML sender with 'invite' template + send_email_html( + subject="RAGFlow Invitation", + to_email=to_email, + template_key="invite", + email=to_email, + invite_url=invite_url, + tenant_id=tenant_id, + inviter=inviter, + ) + + +def otp_keys(email: str): + email = (email or "").strip().lower() + return ( + f"otp:{email}", + f"otp_attempts:{email}", + f"otp_last_sent:{email}", + f"otp_lock:{email}", + ) + + +def hash_code(code: str, salt: bytes) -> str: + import hashlib + import hmac + return hmac.new(salt, (code or "").encode("utf-8"), hashlib.sha256).hexdigest() + + +def captcha_key(email: str) -> str: + return f"captcha:{email}" + diff --git a/chat_demo/index.html b/chat_demo/index.html new file mode 100644 index 00000000000..114b1368325 --- /dev/null +++ b/chat_demo/index.html @@ -0,0 +1,19 @@ + + \ No newline at end of file diff --git a/chat_demo/widget_demo.html b/chat_demo/widget_demo.html new file mode 100644 index 00000000000..34c262b3782 --- /dev/null +++ b/chat_demo/widget_demo.html @@ -0,0 +1,154 @@ + + + + + + Floating Chat Widget Demo + + + +
+

🚀 Floating Chat Widget Demo

+ +

+ Welcome to our demo page! This page simulates a real website with content. + Look for the floating chat button in the bottom-right corner - just like Intercom! +

+ +
+

🎯 Widget Features

+
    +
  • Floating button that stays visible while scrolling
  • +
  • Click to open/close the chat window
  • +
  • Minimize button to collapse the chat
  • +
  • Professional Intercom-style design
  • +
  • Unread message indicator (red badge)
  • +
  • Transparent background integration
  • +
  • Responsive design for all screen sizes
  • +
+
+ +

+ The chat widget is completely separate from your website's content and won't + interfere with your existing layout or functionality. It's designed to be + lightweight and performant. +

+ +

+ Try scrolling this page - notice how the chat button stays in position. + Click it to start a conversation with our AI assistant! +

+ +
+

🔧 Implementation

+
    +
  • Simple iframe embed - just copy and paste
  • +
  • No JavaScript dependencies required
  • +
  • Works on any website or platform
  • +
  • Customizable appearance and behavior
  • +
  • Secure and privacy-focused
  • +
+
+ +

+ This is just placeholder content to demonstrate how the widget integrates + seamlessly with your existing website content. The widget floats above + everything else without disrupting your user experience. +

+ +

+ 🎉 Ready to add this to your website? Get your embed code from the admin panel! +

+
+ + + + + \ No newline at end of file diff --git a/common/__init__.py b/common/__init__.py new file mode 100644 index 00000000000..e156bc93dde --- /dev/null +++ b/common/__init__.py @@ -0,0 +1,15 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# \ No newline at end of file diff --git a/common/config_utils.py b/common/config_utils.py new file mode 100644 index 00000000000..ac55f7e9720 --- /dev/null +++ b/common/config_utils.py @@ -0,0 +1,155 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import copy +import logging +import importlib +from filelock import FileLock + +from common.file_utils import get_project_base_directory +from common.constants import SERVICE_CONF +from ruamel.yaml import YAML + + +def load_yaml_conf(conf_path): + if not os.path.isabs(conf_path): + conf_path = os.path.join(get_project_base_directory(), conf_path) + try: + with open(conf_path) as f: + yaml = YAML(typ="safe", pure=True) + return yaml.load(f) + except Exception as e: + raise EnvironmentError("loading yaml file config from {} failed:".format(conf_path), e) + + +def rewrite_yaml_conf(conf_path, config): + if not os.path.isabs(conf_path): + conf_path = os.path.join(get_project_base_directory(), conf_path) + try: + with open(conf_path, "w") as f: + yaml = YAML(typ="safe") + yaml.dump(config, f) + except Exception as e: + raise EnvironmentError("rewrite yaml file config {} failed:".format(conf_path), e) + + +def conf_realpath(conf_name): + conf_path = f"conf/{conf_name}" + return os.path.join(get_project_base_directory(), conf_path) + + +def read_config(conf_name=SERVICE_CONF): + local_config = {} + local_path = conf_realpath(f'local.{conf_name}') + + # load local config file + if os.path.exists(local_path): + local_config = load_yaml_conf(local_path) + if not isinstance(local_config, dict): + raise ValueError(f'Invalid config file: "{local_path}".') + + global_config_path = conf_realpath(conf_name) + global_config = load_yaml_conf(global_config_path) + + if not isinstance(global_config, dict): + raise ValueError(f'Invalid config file: "{global_config_path}".') + + global_config.update(local_config) + return global_config + + +CONFIGS = read_config() + + +def show_configs(): + msg = f"Current configs, from {conf_realpath(SERVICE_CONF)}:" + for k, v in CONFIGS.items(): + if isinstance(v, dict): + if "password" in v: + v = copy.deepcopy(v) + v["password"] = "*" * 8 + if "access_key" in v: + v = copy.deepcopy(v) + v["access_key"] = "*" * 8 + if "secret_key" in v: + v = copy.deepcopy(v) + v["secret_key"] = "*" * 8 + if "secret" in v: + v = copy.deepcopy(v) + v["secret"] = "*" * 8 + if "sas_token" in v: + v = copy.deepcopy(v) + v["sas_token"] = "*" * 8 + if "oauth" in k: + v = copy.deepcopy(v) + for key, val in v.items(): + if "client_secret" in val: + val["client_secret"] = "*" * 8 + if "authentication" in k: + v = copy.deepcopy(v) + for key, val in v.items(): + if "http_secret_key" in val: + val["http_secret_key"] = "*" * 8 + msg += f"\n\t{k}: {v}" + logging.info(msg) + + +def get_base_config(key, default=None): + if key is None: + return None + if default is None: + default = os.environ.get(key.upper()) + return CONFIGS.get(key, default) + + +def decrypt_database_password(password): + encrypt_password = get_base_config("encrypt_password", False) + encrypt_module = get_base_config("encrypt_module", False) + private_key = get_base_config("private_key", None) + + if not password or not encrypt_password: + return password + + if not private_key: + raise ValueError("No private key") + + module_fun = encrypt_module.split("#") + pwdecrypt_fun = getattr( + importlib.import_module( + module_fun[0]), + module_fun[1]) + + return pwdecrypt_fun(private_key, password) + + +def decrypt_database_config(database=None, passwd_key="password", name="database"): + if not database: + database = get_base_config(name, {}) + + database[passwd_key] = decrypt_database_password(database[passwd_key]) + return database + + +def update_config(key, value, conf_name=SERVICE_CONF): + conf_path = conf_realpath(conf_name=conf_name) + if not os.path.isabs(conf_path): + conf_path = os.path.join(get_project_base_directory(), conf_path) + + with FileLock(os.path.join(os.path.dirname(conf_path), ".lock")): + config = load_yaml_conf(conf_path=conf_path) or {} + config[key] = value + rewrite_yaml_conf(conf_path=conf_path, config=config) diff --git a/common/connection_utils.py b/common/connection_utils.py new file mode 100644 index 00000000000..618584ae978 --- /dev/null +++ b/common/connection_utils.py @@ -0,0 +1,122 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import queue +import threading +from typing import Any, Callable, Coroutine, Optional, Type, Union +import asyncio +import trio +from functools import wraps +from flask import make_response, jsonify +from common.constants import RetCode + +TimeoutException = Union[Type[BaseException], BaseException] +OnTimeoutCallback = Union[Callable[..., Any], Coroutine[Any, Any, Any]] + + +def timeout(seconds: float | int | str = None, attempts: int = 2, *, exception: Optional[TimeoutException] = None, + on_timeout: Optional[OnTimeoutCallback] = None): + if isinstance(seconds, str): + seconds = float(seconds) + + def decorator(func): + @wraps(func) + def wrapper(*args, **kwargs): + result_queue = queue.Queue(maxsize=1) + + def target(): + try: + result = func(*args, **kwargs) + result_queue.put(result) + except Exception as e: + result_queue.put(e) + + thread = threading.Thread(target=target) + thread.daemon = True + thread.start() + + for a in range(attempts): + try: + if os.environ.get("ENABLE_TIMEOUT_ASSERTION"): + result = result_queue.get(timeout=seconds) + else: + result = result_queue.get() + if isinstance(result, Exception): + raise result + return result + except queue.Empty: + pass + raise TimeoutError(f"Function '{func.__name__}' timed out after {seconds} seconds and {attempts} attempts.") + + @wraps(func) + async def async_wrapper(*args, **kwargs) -> Any: + if seconds is None: + return await func(*args, **kwargs) + + for a in range(attempts): + try: + if os.environ.get("ENABLE_TIMEOUT_ASSERTION"): + with trio.fail_after(seconds): + return await func(*args, **kwargs) + else: + return await func(*args, **kwargs) + except trio.TooSlowError: + if a < attempts - 1: + continue + if on_timeout is not None: + if callable(on_timeout): + result = on_timeout() + if isinstance(result, Coroutine): + return await result + return result + return on_timeout + + if exception is None: + raise TimeoutError(f"Operation timed out after {seconds} seconds and {attempts} attempts.") + + if isinstance(exception, BaseException): + raise exception + + if isinstance(exception, type) and issubclass(exception, BaseException): + raise exception(f"Operation timed out after {seconds} seconds and {attempts} attempts.") + + raise RuntimeError("Invalid exception type provided") + + if asyncio.iscoroutinefunction(func): + return async_wrapper + return wrapper + + return decorator + + +def construct_response(code=RetCode.SUCCESS, message="success", data=None, auth=None): + result_dict = {"code": code, "message": message, "data": data} + response_dict = {} + for key, value in result_dict.items(): + if value is None and key != "code": + continue + else: + response_dict[key] = value + response = make_response(jsonify(response_dict)) + if auth: + response.headers["Authorization"] = auth + response.headers["Access-Control-Allow-Origin"] = "*" + response.headers["Access-Control-Allow-Method"] = "*" + response.headers["Access-Control-Allow-Headers"] = "*" + response.headers["Access-Control-Allow-Headers"] = "*" + response.headers["Access-Control-Expose-Headers"] = "Authorization" + return response diff --git a/common/constants.py b/common/constants.py new file mode 100644 index 00000000000..dd24b4ead7e --- /dev/null +++ b/common/constants.py @@ -0,0 +1,196 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from enum import Enum, IntEnum +from strenum import StrEnum + +SERVICE_CONF = "service_conf.yaml" +RAG_FLOW_SERVICE_NAME = "ragflow" + +class CustomEnum(Enum): + @classmethod + def valid(cls, value): + try: + cls(value) + return True + except BaseException: + return False + + @classmethod + def values(cls): + return [member.value for member in cls.__members__.values()] + + @classmethod + def names(cls): + return [member.name for member in cls.__members__.values()] + + +class RetCode(IntEnum, CustomEnum): + SUCCESS = 0 + NOT_EFFECTIVE = 10 + EXCEPTION_ERROR = 100 + ARGUMENT_ERROR = 101 + DATA_ERROR = 102 + OPERATING_ERROR = 103 + CONNECTION_ERROR = 105 + RUNNING = 106 + PERMISSION_ERROR = 108 + AUTHENTICATION_ERROR = 109 + UNAUTHORIZED = 401 + SERVER_ERROR = 500 + FORBIDDEN = 403 + NOT_FOUND = 404 + + +class StatusEnum(Enum): + VALID = "1" + INVALID = "0" + + +class ActiveEnum(Enum): + ACTIVE = "1" + INACTIVE = "0" + + +class LLMType(StrEnum): + CHAT = 'chat' + EMBEDDING = 'embedding' + SPEECH2TEXT = 'speech2text' + IMAGE2TEXT = 'image2text' + RERANK = 'rerank' + TTS = 'tts' + + +class TaskStatus(StrEnum): + UNSTART = "0" + RUNNING = "1" + CANCEL = "2" + DONE = "3" + FAIL = "4" + SCHEDULE = "5" + + +VALID_TASK_STATUS = {TaskStatus.UNSTART, TaskStatus.RUNNING, TaskStatus.CANCEL, TaskStatus.DONE, TaskStatus.FAIL, + TaskStatus.SCHEDULE} + + +class ParserType(StrEnum): + PRESENTATION = "presentation" + LAWS = "laws" + MANUAL = "manual" + PAPER = "paper" + RESUME = "resume" + BOOK = "book" + QA = "qa" + TABLE = "table" + NAIVE = "naive" + PICTURE = "picture" + ONE = "one" + AUDIO = "audio" + EMAIL = "email" + KG = "knowledge_graph" + TAG = "tag" + + +class FileSource(StrEnum): + LOCAL = "" + KNOWLEDGEBASE = "knowledgebase" + S3 = "s3" + NOTION = "notion" + DISCORD = "discord" + CONFLUENCE = "confluence" + GMAIL = "gmail" + GOOGLE_DRIVE = "google_drive" + JIRA = "jira" + SHAREPOINT = "sharepoint" + SLACK = "slack" + TEAMS = "teams" + + +class PipelineTaskType(StrEnum): + PARSE = "Parse" + DOWNLOAD = "Download" + RAPTOR = "RAPTOR" + GRAPH_RAG = "GraphRAG" + MINDMAP = "Mindmap" + + +VALID_PIPELINE_TASK_TYPES = {PipelineTaskType.PARSE, PipelineTaskType.DOWNLOAD, PipelineTaskType.RAPTOR, + PipelineTaskType.GRAPH_RAG, PipelineTaskType.MINDMAP} + +class MCPServerType(StrEnum): + SSE = "sse" + STREAMABLE_HTTP = "streamable-http" + +VALID_MCP_SERVER_TYPES = {MCPServerType.SSE, MCPServerType.STREAMABLE_HTTP} + +class Storage(Enum): + MINIO = 1 + AZURE_SPN = 2 + AZURE_SAS = 3 + AWS_S3 = 4 + OSS = 5 + OPENDAL = 6 + +# environment +# ENV_STRONG_TEST_COUNT = "STRONG_TEST_COUNT" +# ENV_RAGFLOW_SECRET_KEY = "RAGFLOW_SECRET_KEY" +# ENV_REGISTER_ENABLED = "REGISTER_ENABLED" +# ENV_DOC_ENGINE = "DOC_ENGINE" +# ENV_SANDBOX_ENABLED = "SANDBOX_ENABLED" +# ENV_SANDBOX_HOST = "SANDBOX_HOST" +# ENV_MAX_CONTENT_LENGTH = "MAX_CONTENT_LENGTH" +# ENV_COMPONENT_EXEC_TIMEOUT = "COMPONENT_EXEC_TIMEOUT" +# ENV_TRINO_USE_TLS = "TRINO_USE_TLS" +# ENV_MAX_FILE_NUM_PER_USER = "MAX_FILE_NUM_PER_USER" +# ENV_MACOS = "MACOS" +# ENV_RAGFLOW_DEBUGPY_LISTEN = "RAGFLOW_DEBUGPY_LISTEN" +# ENV_WERKZEUG_RUN_MAIN = "WERKZEUG_RUN_MAIN" +# ENV_DISABLE_SDK = "DISABLE_SDK" +# ENV_ENABLE_TIMEOUT_ASSERTION = "ENABLE_TIMEOUT_ASSERTION" +# ENV_LOG_LEVELS = "LOG_LEVELS" +# ENV_TENSORRT_DLA_SVR = "TENSORRT_DLA_SVR" +# ENV_OCR_GPU_MEM_LIMIT_MB = "OCR_GPU_MEM_LIMIT_MB" +# ENV_OCR_ARENA_EXTEND_STRATEGY = "OCR_ARENA_EXTEND_STRATEGY" +# ENV_MAX_CONCURRENT_PROCESS_AND_EXTRACT_CHUNK = "MAX_CONCURRENT_PROCESS_AND_EXTRACT_CHUNK" +# ENV_MAX_MAX_CONCURRENT_CHATS = "MAX_CONCURRENT_CHATS" +# ENV_RAGFLOW_MCP_BASE_URL = "RAGFLOW_MCP_BASE_URL" +# ENV_RAGFLOW_MCP_HOST = "RAGFLOW_MCP_HOST" +# ENV_RAGFLOW_MCP_PORT = "RAGFLOW_MCP_PORT" +# ENV_RAGFLOW_MCP_LAUNCH_MODE = "RAGFLOW_MCP_LAUNCH_MODE" +# ENV_RAGFLOW_MCP_HOST_API_KEY = "RAGFLOW_MCP_HOST_API_KEY" +# ENV_MINERU_EXECUTABLE = "MINERU_EXECUTABLE" +# ENV_MINERU_APISERVER = "MINERU_APISERVER" +# ENV_MINERU_OUTPUT_DIR = "MINERU_OUTPUT_DIR" +# ENV_MINERU_BACKEND = "MINERU_BACKEND" +# ENV_MINERU_DELETE_OUTPUT = "MINERU_DELETE_OUTPUT" +# ENV_TCADP_OUTPUT_DIR = "TCADP_OUTPUT_DIR" +# ENV_LM_TIMEOUT_SECONDS = "LM_TIMEOUT_SECONDS" +# ENV_LLM_MAX_RETRIES = "LLM_MAX_RETRIES" +# ENV_LLM_BASE_DELAY = "LLM_BASE_DELAY" +# ENV_OLLAMA_KEEP_ALIVE = "OLLAMA_KEEP_ALIVE" +# ENV_DOC_BULK_SIZE = "DOC_BULK_SIZE" +# ENV_EMBEDDING_BATCH_SIZE = "EMBEDDING_BATCH_SIZE" +# ENV_MAX_CONCURRENT_TASKS = "MAX_CONCURRENT_TASKS" +# ENV_MAX_CONCURRENT_CHUNK_BUILDERS = "MAX_CONCURRENT_CHUNK_BUILDERS" +# ENV_MAX_CONCURRENT_MINIO = "MAX_CONCURRENT_MINIO" +# ENV_WORKER_HEARTBEAT_TIMEOUT = "WORKER_HEARTBEAT_TIMEOUT" +# ENV_TRACE_MALLOC_ENABLED = "TRACE_MALLOC_ENABLED" + +PAGERANK_FLD = "pagerank_fea" +SVR_QUEUE_NAME = "rag_flow_svr_queue" +SVR_CONSUMER_GROUP_NAME = "rag_flow_svr_task_broker" +TAG_FLD = "tag_feas" diff --git a/common/data_source/__init__.py b/common/data_source/__init__.py new file mode 100644 index 00000000000..0802a52852a --- /dev/null +++ b/common/data_source/__init__.py @@ -0,0 +1,50 @@ + +""" +Thanks to https://github.com/onyx-dot-app/onyx +""" + +from .blob_connector import BlobStorageConnector +from .slack_connector import SlackConnector +from .gmail_connector import GmailConnector +from .notion_connector import NotionConnector +from .confluence_connector import ConfluenceConnector +from .discord_connector import DiscordConnector +from .dropbox_connector import DropboxConnector +from .google_drive.connector import GoogleDriveConnector +from .jira_connector import JiraConnector +from .sharepoint_connector import SharePointConnector +from .teams_connector import TeamsConnector +from .config import BlobType, DocumentSource +from .models import Document, TextSection, ImageSection, BasicExpertInfo +from .exceptions import ( + ConnectorMissingCredentialError, + ConnectorValidationError, + CredentialExpiredError, + InsufficientPermissionsError, + UnexpectedValidationError +) + +__all__ = [ + "BlobStorageConnector", + "SlackConnector", + "GmailConnector", + "NotionConnector", + "ConfluenceConnector", + "DiscordConnector", + "DropboxConnector", + "GoogleDriveConnector", + "JiraConnector", + "SharePointConnector", + "TeamsConnector", + "BlobType", + "DocumentSource", + "Document", + "TextSection", + "ImageSection", + "BasicExpertInfo", + "ConnectorMissingCredentialError", + "ConnectorValidationError", + "CredentialExpiredError", + "InsufficientPermissionsError", + "UnexpectedValidationError" +] diff --git a/common/data_source/blob_connector.py b/common/data_source/blob_connector.py new file mode 100644 index 00000000000..0bec7cbe643 --- /dev/null +++ b/common/data_source/blob_connector.py @@ -0,0 +1,272 @@ +"""Blob storage connector""" +import logging +import os +from datetime import datetime, timezone +from typing import Any, Optional + +from common.data_source.utils import ( + create_s3_client, + detect_bucket_region, + download_object, + extract_size_bytes, + get_file_ext, +) +from common.data_source.config import BlobType, DocumentSource, BLOB_STORAGE_SIZE_THRESHOLD, INDEX_BATCH_SIZE +from common.data_source.exceptions import ( + ConnectorMissingCredentialError, + ConnectorValidationError, + CredentialExpiredError, + InsufficientPermissionsError +) +from common.data_source.interfaces import LoadConnector, PollConnector +from common.data_source.models import Document, SecondsSinceUnixEpoch, GenerateDocumentsOutput + + +class BlobStorageConnector(LoadConnector, PollConnector): + """Blob storage connector""" + + def __init__( + self, + bucket_type: str, + bucket_name: str, + prefix: str = "", + batch_size: int = INDEX_BATCH_SIZE, + european_residency: bool = False, + ) -> None: + self.bucket_type: BlobType = BlobType(bucket_type) + self.bucket_name = bucket_name.strip() + self.prefix = prefix if not prefix or prefix.endswith("/") else prefix + "/" + self.batch_size = batch_size + self.s3_client: Optional[Any] = None + self._allow_images: bool | None = None + self.size_threshold: int | None = BLOB_STORAGE_SIZE_THRESHOLD + self.bucket_region: Optional[str] = None + self.european_residency: bool = european_residency + + def set_allow_images(self, allow_images: bool) -> None: + """Set whether to process images""" + logging.info(f"Setting allow_images to {allow_images}.") + self._allow_images = allow_images + + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: + """Load credentials""" + logging.debug( + f"Loading credentials for {self.bucket_name} of type {self.bucket_type}" + ) + + # Validate credentials + if self.bucket_type == BlobType.R2: + if not all( + credentials.get(key) + for key in ["r2_access_key_id", "r2_secret_access_key", "account_id"] + ): + raise ConnectorMissingCredentialError("Cloudflare R2") + + elif self.bucket_type == BlobType.S3: + authentication_method = credentials.get("authentication_method", "access_key") + if authentication_method == "access_key": + if not all( + credentials.get(key) + for key in ["aws_access_key_id", "aws_secret_access_key"] + ): + raise ConnectorMissingCredentialError("Amazon S3") + elif authentication_method == "iam_role": + if not credentials.get("aws_role_arn"): + raise ConnectorMissingCredentialError("Amazon S3 IAM role ARN is required") + + elif self.bucket_type == BlobType.GOOGLE_CLOUD_STORAGE: + if not all( + credentials.get(key) for key in ["access_key_id", "secret_access_key"] + ): + raise ConnectorMissingCredentialError("Google Cloud Storage") + + elif self.bucket_type == BlobType.OCI_STORAGE: + if not all( + credentials.get(key) + for key in ["namespace", "region", "access_key_id", "secret_access_key"] + ): + raise ConnectorMissingCredentialError("Oracle Cloud Infrastructure") + + else: + raise ValueError(f"Unsupported bucket type: {self.bucket_type}") + + # Create S3 client + self.s3_client = create_s3_client( + self.bucket_type, credentials, self.european_residency + ) + + # Detect bucket region (only important for S3) + if self.bucket_type == BlobType.S3: + self.bucket_region = detect_bucket_region(self.s3_client, self.bucket_name) + + return None + + def _yield_blob_objects( + self, + start: datetime, + end: datetime, + ) -> GenerateDocumentsOutput: + """Generate bucket objects""" + if self.s3_client is None: + raise ConnectorMissingCredentialError("Blob storage") + + paginator = self.s3_client.get_paginator("list_objects_v2") + pages = paginator.paginate(Bucket=self.bucket_name, Prefix=self.prefix) + + batch: list[Document] = [] + for page in pages: + if "Contents" not in page: + continue + + for obj in page["Contents"]: + if obj["Key"].endswith("/"): + continue + + last_modified = obj["LastModified"].replace(tzinfo=timezone.utc) + + if not (start < last_modified <= end): + continue + + file_name = os.path.basename(obj["Key"]) + key = obj["Key"] + + size_bytes = extract_size_bytes(obj) + if ( + self.size_threshold is not None + and isinstance(size_bytes, int) + and size_bytes > self.size_threshold + ): + logging.warning( + f"{file_name} exceeds size threshold of {self.size_threshold}. Skipping." + ) + continue + try: + blob = download_object(self.s3_client, self.bucket_name, key, self.size_threshold) + if blob is None: + continue + + batch.append( + Document( + id=f"{self.bucket_type}:{self.bucket_name}:{key}", + blob=blob, + source=DocumentSource(self.bucket_type.value), + semantic_identifier=file_name, + extension=get_file_ext(file_name), + doc_updated_at=last_modified, + size_bytes=size_bytes if size_bytes else 0 + ) + ) + if len(batch) == self.batch_size: + yield batch + batch = [] + + except Exception: + logging.exception(f"Error decoding object {key}") + + if batch: + yield batch + + def load_from_state(self) -> GenerateDocumentsOutput: + """Load documents from state""" + logging.debug("Loading blob objects") + return self._yield_blob_objects( + start=datetime(1970, 1, 1, tzinfo=timezone.utc), + end=datetime.now(timezone.utc), + ) + + def poll_source( + self, start: SecondsSinceUnixEpoch, end: SecondsSinceUnixEpoch + ) -> GenerateDocumentsOutput: + """Poll source to get documents""" + if self.s3_client is None: + raise ConnectorMissingCredentialError("Blob storage") + + start_datetime = datetime.fromtimestamp(start, tz=timezone.utc) + end_datetime = datetime.fromtimestamp(end, tz=timezone.utc) + + for batch in self._yield_blob_objects(start_datetime, end_datetime): + yield batch + + def validate_connector_settings(self) -> None: + """Validate connector settings""" + if self.s3_client is None: + raise ConnectorMissingCredentialError( + "Blob storage credentials not loaded." + ) + + if not self.bucket_name: + raise ConnectorValidationError( + "No bucket name was provided in connector settings." + ) + + try: + # Lightweight validation step + self.s3_client.list_objects_v2( + Bucket=self.bucket_name, Prefix=self.prefix, MaxKeys=1 + ) + + except Exception as e: + error_code = getattr(e, 'response', {}).get('Error', {}).get('Code', '') + status_code = getattr(e, 'response', {}).get('ResponseMetadata', {}).get('HTTPStatusCode') + + # Common S3 error scenarios + if error_code in [ + "AccessDenied", + "InvalidAccessKeyId", + "SignatureDoesNotMatch", + ]: + if status_code == 403 or error_code == "AccessDenied": + raise InsufficientPermissionsError( + f"Insufficient permissions to list objects in bucket '{self.bucket_name}'. " + "Please check your bucket policy and/or IAM policy." + ) + if status_code == 401 or error_code == "SignatureDoesNotMatch": + raise CredentialExpiredError( + "Provided blob storage credentials appear invalid or expired." + ) + + raise CredentialExpiredError( + f"Credential issue encountered ({error_code})." + ) + + if error_code == "NoSuchBucket" or status_code == 404: + raise ConnectorValidationError( + f"Bucket '{self.bucket_name}' does not exist or cannot be found." + ) + + raise ConnectorValidationError( + f"Unexpected S3 client error (code={error_code}, status={status_code}): {e}" + ) + + +if __name__ == "__main__": + # Example usage + credentials_dict = { + "aws_access_key_id": os.environ.get("AWS_ACCESS_KEY_ID"), + "aws_secret_access_key": os.environ.get("AWS_SECRET_ACCESS_KEY"), + } + + # Initialize connector + connector = BlobStorageConnector( + bucket_type=os.environ.get("BUCKET_TYPE") or "s3", + bucket_name=os.environ.get("BUCKET_NAME") or "yyboombucket", + prefix="", + ) + + try: + connector.load_credentials(credentials_dict) + document_batch_generator = connector.load_from_state() + for document_batch in document_batch_generator: + print("First batch of documents:") + for doc in document_batch: + print(f"Document ID: {doc.id}") + print(f"Semantic Identifier: {doc.semantic_identifier}") + print(f"Source: {doc.source}") + print(f"Updated At: {doc.doc_updated_at}") + print("---") + break + + except ConnectorMissingCredentialError as e: + print(f"Error: {e}") + except Exception as e: + print(f"An unexpected error occurred: {e}") \ No newline at end of file diff --git a/common/data_source/config.py b/common/data_source/config.py new file mode 100644 index 00000000000..02684dbacc9 --- /dev/null +++ b/common/data_source/config.py @@ -0,0 +1,248 @@ +"""Configuration constants and enum definitions""" +import json +import os +from datetime import datetime, timezone +from enum import Enum +from typing import cast + + +def get_current_tz_offset() -> int: + # datetime now() gets local time, datetime.now(timezone.utc) gets UTC time. + # remove tzinfo to compare non-timezone-aware objects. + time_diff = datetime.now() - datetime.now(timezone.utc).replace(tzinfo=None) + return round(time_diff.total_seconds() / 3600) + + +ONE_HOUR = 3600 +ONE_DAY = ONE_HOUR * 24 + +# Slack API limits +_SLACK_LIMIT = 900 + +# Redis lock configuration +ONYX_SLACK_LOCK_TTL = 1800 +ONYX_SLACK_LOCK_BLOCKING_TIMEOUT = 60 +ONYX_SLACK_LOCK_TOTAL_BLOCKING_TIMEOUT = 3600 + + +class BlobType(str, Enum): + """Supported storage types""" + S3 = "s3" + R2 = "r2" + GOOGLE_CLOUD_STORAGE = "google_cloud_storage" + OCI_STORAGE = "oci_storage" + + +class DocumentSource(str, Enum): + """Document sources""" + S3 = "s3" + NOTION = "notion" + R2 = "r2" + GOOGLE_CLOUD_STORAGE = "google_cloud_storage" + OCI_STORAGE = "oci_storage" + SLACK = "slack" + CONFLUENCE = "confluence" + GOOGLE_DRIVE = "google_drive" + GMAIL = "gmail" + DISCORD = "discord" + + +class FileOrigin(str, Enum): + """File origins""" + CONNECTOR = "connector" + + +# Standard image MIME types supported by most vision LLMs +IMAGE_MIME_TYPES = [ + "image/png", + "image/jpeg", + "image/jpg", + "image/webp", +] + +# Image types that should be excluded from processing +EXCLUDED_IMAGE_TYPES = [ + "image/bmp", + "image/tiff", + "image/gif", + "image/svg+xml", + "image/avif", +] + + +_PAGE_EXPANSION_FIELDS = [ + "body.storage.value", + "version", + "space", + "metadata.labels", + "history.lastUpdated", +] + + +# Configuration constants +BLOB_STORAGE_SIZE_THRESHOLD = 20 * 1024 * 1024 # 20MB +INDEX_BATCH_SIZE = 2 +SLACK_NUM_THREADS = 4 +ENABLE_EXPENSIVE_EXPERT_CALLS = False + +# Slack related constants +_SLACK_LIMIT = 900 +FAST_TIMEOUT = 1 +MAX_RETRIES = 7 +MAX_CHANNELS_TO_LOG = 50 +BOT_CHANNEL_MIN_BATCH_SIZE = 256 +BOT_CHANNEL_PERCENTAGE_THRESHOLD = 0.95 + +# Download configuration +DOWNLOAD_CHUNK_SIZE = 1024 * 1024 # 1MB +SIZE_THRESHOLD_BUFFER = 64 + +NOTION_CONNECTOR_DISABLE_RECURSIVE_PAGE_LOOKUP = ( + os.environ.get("NOTION_CONNECTOR_DISABLE_RECURSIVE_PAGE_LOOKUP", "").lower() + == "true" +) + +SLIM_BATCH_SIZE = 100 + +# Notion API constants +_NOTION_PAGE_SIZE = 100 +_NOTION_CALL_TIMEOUT = 30 # 30 seconds + +_ITERATION_LIMIT = 100_000 + +##### +# Indexing Configs +##### +# NOTE: Currently only supported in the Confluence and Google Drive connectors + +# only handles some failures (Confluence = handles API call failures, Google +# Drive = handles failures pulling files / parsing them) +CONTINUE_ON_CONNECTOR_FAILURE = os.environ.get( + "CONTINUE_ON_CONNECTOR_FAILURE", "" +).lower() not in ["false", ""] + + +##### +# Confluence Connector Configs +##### + +CONFLUENCE_CONNECTOR_LABELS_TO_SKIP = [ + ignored_tag + for ignored_tag in os.environ.get("CONFLUENCE_CONNECTOR_LABELS_TO_SKIP", "").split( + "," + ) + if ignored_tag +] + +# Avoid to get archived pages +CONFLUENCE_CONNECTOR_INDEX_ARCHIVED_PAGES = ( + os.environ.get("CONFLUENCE_CONNECTOR_INDEX_ARCHIVED_PAGES", "").lower() == "true" +) + +# Attachments exceeding this size will not be retrieved (in bytes) +CONFLUENCE_CONNECTOR_ATTACHMENT_SIZE_THRESHOLD = int( + os.environ.get("CONFLUENCE_CONNECTOR_ATTACHMENT_SIZE_THRESHOLD", 10 * 1024 * 1024) +) +# Attachments with more chars than this will not be indexed. This is to prevent extremely +# large files from freezing indexing. 200,000 is ~100 google doc pages. +CONFLUENCE_CONNECTOR_ATTACHMENT_CHAR_COUNT_THRESHOLD = int( + os.environ.get("CONFLUENCE_CONNECTOR_ATTACHMENT_CHAR_COUNT_THRESHOLD", 200_000) +) + +_RAW_CONFLUENCE_CONNECTOR_USER_PROFILES_OVERRIDE = os.environ.get( + "CONFLUENCE_CONNECTOR_USER_PROFILES_OVERRIDE", "" +) +CONFLUENCE_CONNECTOR_USER_PROFILES_OVERRIDE = cast( + list[dict[str, str]] | None, + ( + json.loads(_RAW_CONFLUENCE_CONNECTOR_USER_PROFILES_OVERRIDE) + if _RAW_CONFLUENCE_CONNECTOR_USER_PROFILES_OVERRIDE + else None + ), +) + +# enter as a floating point offset from UTC in hours (-24 < val < 24) +# this will be applied globally, so it probably makes sense to transition this to per +# connector as some point. +# For the default value, we assume that the user's local timezone is more likely to be +# correct (i.e. the configured user's timezone or the default server one) than UTC. +# https://developer.atlassian.com/cloud/confluence/cql-fields/#created +CONFLUENCE_TIMEZONE_OFFSET = float( + os.environ.get("CONFLUENCE_TIMEZONE_OFFSET", get_current_tz_offset()) +) + +CONFLUENCE_SYNC_TIME_BUFFER_SECONDS = int( + os.environ.get("CONFLUENCE_SYNC_TIME_BUFFER_SECONDS", ONE_DAY) +) + +GOOGLE_DRIVE_CONNECTOR_SIZE_THRESHOLD = int( + os.environ.get("GOOGLE_DRIVE_CONNECTOR_SIZE_THRESHOLD", 10 * 1024 * 1024) +) + +OAUTH_SLACK_CLIENT_ID = os.environ.get("OAUTH_SLACK_CLIENT_ID", "") +OAUTH_SLACK_CLIENT_SECRET = os.environ.get("OAUTH_SLACK_CLIENT_SECRET", "") +OAUTH_CONFLUENCE_CLOUD_CLIENT_ID = os.environ.get( + "OAUTH_CONFLUENCE_CLOUD_CLIENT_ID", "" +) + +OAUTH_CONFLUENCE_CLOUD_CLIENT_SECRET = os.environ.get( + "OAUTH_CONFLUENCE_CLOUD_CLIENT_SECRET", "" +) + +OAUTH_JIRA_CLOUD_CLIENT_ID = os.environ.get("OAUTH_JIRA_CLOUD_CLIENT_ID", "") +OAUTH_JIRA_CLOUD_CLIENT_SECRET = os.environ.get("OAUTH_JIRA_CLOUD_CLIENT_SECRET", "") +OAUTH_GOOGLE_DRIVE_CLIENT_ID = os.environ.get("OAUTH_GOOGLE_DRIVE_CLIENT_ID", "") +OAUTH_GOOGLE_DRIVE_CLIENT_SECRET = os.environ.get( + "OAUTH_GOOGLE_DRIVE_CLIENT_SECRET", "" +) +GOOGLE_DRIVE_WEB_OAUTH_REDIRECT_URI = os.environ.get("GOOGLE_DRIVE_WEB_OAUTH_REDIRECT_URI", "http://localhost:9380/v1/connector/google-drive/oauth/web/callback") + +CONFLUENCE_OAUTH_TOKEN_URL = "https://auth.atlassian.com/oauth/token" +RATE_LIMIT_MESSAGE_LOWERCASE = "Rate limit exceeded".lower() + +_DEFAULT_PAGINATION_LIMIT = 1000 + +_PROBLEMATIC_EXPANSIONS = "body.storage.value" +_REPLACEMENT_EXPANSIONS = "body.view.value" + + +class HtmlBasedConnectorTransformLinksStrategy(str, Enum): + # remove links entirely + STRIP = "strip" + # turn HTML links into markdown links + MARKDOWN = "markdown" + + +HTML_BASED_CONNECTOR_TRANSFORM_LINKS_STRATEGY = os.environ.get( + "HTML_BASED_CONNECTOR_TRANSFORM_LINKS_STRATEGY", + HtmlBasedConnectorTransformLinksStrategy.STRIP, +) + +PARSE_WITH_TRAFILATURA = os.environ.get("PARSE_WITH_TRAFILATURA", "").lower() == "true" + +WEB_CONNECTOR_IGNORED_CLASSES = os.environ.get( + "WEB_CONNECTOR_IGNORED_CLASSES", "sidebar,footer" +).split(",") +WEB_CONNECTOR_IGNORED_ELEMENTS = os.environ.get( + "WEB_CONNECTOR_IGNORED_ELEMENTS", "nav,footer,meta,script,style,symbol,aside" +).split(",") + +_USER_NOT_FOUND = "Unknown Confluence User" + +_COMMENT_EXPANSION_FIELDS = ["body.storage.value"] + +_ATTACHMENT_EXPANSION_FIELDS = [ + "version", + "space", + "metadata.labels", +] + +_RESTRICTIONS_EXPANSION_FIELDS = [ + "space", + "restrictions.read.restrictions.user", + "restrictions.read.restrictions.group", + "ancestors.restrictions.read.restrictions.user", + "ancestors.restrictions.read.restrictions.group", +] + + +_SLIM_DOC_BATCH_SIZE = 5000 diff --git a/common/data_source/confluence_connector.py b/common/data_source/confluence_connector.py new file mode 100644 index 00000000000..aed16ad2b66 --- /dev/null +++ b/common/data_source/confluence_connector.py @@ -0,0 +1,2036 @@ + + +"""Confluence connector""" +import copy +import json +import logging +import time +from datetime import datetime, timezone, timedelta +from pathlib import Path +from typing import Any, cast, Iterator, Callable, Generator + +import requests +from typing_extensions import override +from urllib.parse import quote + +import bs4 +from atlassian.errors import ApiError +from atlassian import Confluence +from requests.exceptions import HTTPError + +from common.data_source.config import INDEX_BATCH_SIZE, DocumentSource, CONTINUE_ON_CONNECTOR_FAILURE, \ + CONFLUENCE_CONNECTOR_LABELS_TO_SKIP, CONFLUENCE_TIMEZONE_OFFSET, CONFLUENCE_CONNECTOR_USER_PROFILES_OVERRIDE, \ + CONFLUENCE_SYNC_TIME_BUFFER_SECONDS, \ + OAUTH_CONFLUENCE_CLOUD_CLIENT_ID, OAUTH_CONFLUENCE_CLOUD_CLIENT_SECRET, _DEFAULT_PAGINATION_LIMIT, \ + _PROBLEMATIC_EXPANSIONS, _REPLACEMENT_EXPANSIONS, _USER_NOT_FOUND, _COMMENT_EXPANSION_FIELDS, \ + _ATTACHMENT_EXPANSION_FIELDS, _PAGE_EXPANSION_FIELDS, ONE_DAY, ONE_HOUR, _RESTRICTIONS_EXPANSION_FIELDS, \ + _SLIM_DOC_BATCH_SIZE, CONFLUENCE_CONNECTOR_ATTACHMENT_SIZE_THRESHOLD +from common.data_source.exceptions import ( + ConnectorMissingCredentialError, + ConnectorValidationError, + InsufficientPermissionsError, + UnexpectedValidationError, CredentialExpiredError +) +from common.data_source.html_utils import format_document_soup +from common.data_source.interfaces import ( + ConnectorCheckpoint, + CredentialsConnector, + SecondsSinceUnixEpoch, + SlimConnectorWithPermSync, StaticCredentialsProvider, CheckpointedConnector, SlimConnector, + CredentialsProviderInterface, ConfluenceUser, IndexingHeartbeatInterface, AttachmentProcessingResult, + CheckpointOutput +) +from common.data_source.models import ConnectorFailure, Document, TextSection, ImageSection, BasicExpertInfo, \ + DocumentFailure, GenerateSlimDocumentOutput, SlimDocument, ExternalAccess +from common.data_source.utils import load_all_docs_from_checkpoint_connector, scoped_url, \ + process_confluence_user_profiles_override, confluence_refresh_tokens, run_with_timeout, _handle_http_error, \ + update_param_in_path, get_start_param_from_url, build_confluence_document_id, datetime_from_string, \ + is_atlassian_date_error, validate_attachment_filetype +from rag.utils.redis_conn import RedisDB, REDIS_CONN + +_USER_ID_TO_DISPLAY_NAME_CACHE: dict[str, str | None] = {} +_USER_EMAIL_CACHE: dict[str, str | None] = {} + +class ConfluenceCheckpoint(ConnectorCheckpoint): + + next_page_url: str | None + + +class ConfluenceRateLimitError(Exception): + pass + + +class OnyxConfluence: + """ + This is a custom Confluence class that: + + A. overrides the default Confluence class to add a custom CQL method. + B. + This is necessary because the default Confluence class does not properly support cql expansions. + All methods are automatically wrapped with handle_confluence_rate_limit. + """ + + CREDENTIAL_PREFIX = "connector:confluence:credential" + CREDENTIAL_TTL = 300 # 5 min + PROBE_TIMEOUT = 5 # 5 seconds + + def __init__( + self, + is_cloud: bool, + url: str, + credentials_provider: CredentialsProviderInterface, + timeout: int | None = None, + scoped_token: bool = False, + # should generally not be passed in, but making it overridable for + # easier testing + confluence_user_profiles_override: list[dict[str, str]] | None = ( + CONFLUENCE_CONNECTOR_USER_PROFILES_OVERRIDE + ), + ) -> None: + self.base_url = url #'/'.join(url.rstrip("/").split("/")[:-1]) + url = scoped_url(url, "confluence") if scoped_token else url + + self._is_cloud = is_cloud + self._url = url.rstrip("/") + self._credentials_provider = credentials_provider + self.scoped_token = scoped_token + self.redis_client: RedisDB | None = None + self.static_credentials: dict[str, Any] | None = None + if self._credentials_provider.is_dynamic(): + self.redis_client = REDIS_CONN + else: + self.static_credentials = self._credentials_provider.get_credentials() + + self._confluence = Confluence(url) + self.credential_key: str = ( + self.CREDENTIAL_PREFIX + + f":credential_{self._credentials_provider.get_provider_key()}" + ) + + self._kwargs: Any = None + + self.shared_base_kwargs: dict[str, str | int | bool] = { + "api_version": "cloud" if is_cloud else "latest", + "backoff_and_retry": True, + "cloud": is_cloud, + } + if timeout: + self.shared_base_kwargs["timeout"] = timeout + + self._confluence_user_profiles_override = ( + process_confluence_user_profiles_override(confluence_user_profiles_override) + if confluence_user_profiles_override + else None + ) + + def _renew_credentials(self) -> tuple[dict[str, Any], bool]: + """credential_json - the current json credentials + Returns a tuple + 1. The up to date credentials + 2. True if the credentials were updated + + This method is intended to be used within a distributed lock. + Lock, call this, update credentials if the tokens were refreshed, then release + """ + # static credentials are preloaded, so no locking/redis required + if self.static_credentials: + return self.static_credentials, False + + if not self.redis_client: + raise RuntimeError("self.redis_client is None") + + # dynamic credentials need locking + # check redis first, then fallback to the DB + credential_raw = self.redis_client.get(self.credential_key) + if credential_raw is not None: + credential_bytes = cast(bytes, credential_raw) + credential_str = credential_bytes.decode("utf-8") + credential_json: dict[str, Any] = json.loads(credential_str) + else: + credential_json = self._credentials_provider.get_credentials() + + if "confluence_refresh_token" not in credential_json: + # static credentials ... cache them permanently and return + self.static_credentials = credential_json + return credential_json, False + + if not OAUTH_CONFLUENCE_CLOUD_CLIENT_ID: + raise RuntimeError("OAUTH_CONFLUENCE_CLOUD_CLIENT_ID must be set!") + + if not OAUTH_CONFLUENCE_CLOUD_CLIENT_SECRET: + raise RuntimeError("OAUTH_CONFLUENCE_CLOUD_CLIENT_SECRET must be set!") + + # check if we should refresh tokens. we're deciding to refresh halfway + # to expiration + now = datetime.now(timezone.utc) + created_at = datetime.fromisoformat(credential_json["created_at"]) + expires_in: int = credential_json["expires_in"] + renew_at = created_at + timedelta(seconds=expires_in // 2) + if now <= renew_at: + # cached/current credentials are reasonably up to date + return credential_json, False + + # we need to refresh + logging.info("Renewing Confluence Cloud credentials...") + new_credentials = confluence_refresh_tokens( + OAUTH_CONFLUENCE_CLOUD_CLIENT_ID, + OAUTH_CONFLUENCE_CLOUD_CLIENT_SECRET, + credential_json["cloud_id"], + credential_json["confluence_refresh_token"], + ) + + # store the new credentials to redis and to the db thru the provider + # redis: we use a 5 min TTL because we are given a 10 minute grace period + # when keys are rotated. it's easier to expire the cached credentials + # reasonably frequently rather than trying to handle strong synchronization + # between the db and redis everywhere the credentials might be updated + new_credential_str = json.dumps(new_credentials) + self.redis_client.set( + self.credential_key, new_credential_str, nx=True, ex=self.CREDENTIAL_TTL + ) + self._credentials_provider.set_credentials(new_credentials) + + return new_credentials, True + + @staticmethod + def _make_oauth2_dict(credentials: dict[str, Any]) -> dict[str, Any]: + oauth2_dict: dict[str, Any] = {} + if "confluence_refresh_token" in credentials: + oauth2_dict["client_id"] = OAUTH_CONFLUENCE_CLOUD_CLIENT_ID + oauth2_dict["token"] = {} + oauth2_dict["token"]["access_token"] = credentials[ + "confluence_access_token" + ] + return oauth2_dict + + def _probe_connection( + self, + **kwargs: Any, + ) -> None: + merged_kwargs = {**self.shared_base_kwargs, **kwargs} + # add special timeout to make sure that we don't hang indefinitely + merged_kwargs["timeout"] = self.PROBE_TIMEOUT + + with self._credentials_provider: + credentials, _ = self._renew_credentials() + if self.scoped_token: + # v2 endpoint doesn't always work with scoped tokens, use v1 + token = credentials["confluence_access_token"] + probe_url = f"{self.base_url}/rest/api/space?limit=1" + import requests + + logging.info(f"First and Last 5 of token: {token[:5]}...{token[-5:]}") + + try: + r = requests.get( + probe_url, + headers={"Authorization": f"Bearer {token}"}, + timeout=10, + ) + r.raise_for_status() + except HTTPError as e: + if e.response.status_code == 403: + logging.warning( + "scoped token authenticated but not valid for probe endpoint (spaces)" + ) + else: + if "WWW-Authenticate" in e.response.headers: + logging.warning( + f"WWW-Authenticate: {e.response.headers['WWW-Authenticate']}" + ) + logging.warning(f"Full error: {e.response.text}") + raise e + return + + # probe connection with direct client, no retries + if "confluence_refresh_token" in credentials: + logging.info("Probing Confluence with OAuth Access Token.") + + oauth2_dict: dict[str, Any] = OnyxConfluence._make_oauth2_dict( + credentials + ) + url = ( + f"https://api.atlassian.com/ex/confluence/{credentials['cloud_id']}" + ) + confluence_client_with_minimal_retries = Confluence( + url=url, oauth2=oauth2_dict, **merged_kwargs + ) + else: + logging.info("Probing Confluence with Personal Access Token.") + url = self._url + if self._is_cloud: + logging.info("running with cloud client") + confluence_client_with_minimal_retries = Confluence( + url=url, + username=credentials["confluence_username"], + password=credentials["confluence_access_token"], + **merged_kwargs, + ) + else: + confluence_client_with_minimal_retries = Confluence( + url=url, + token=credentials["confluence_access_token"], + **merged_kwargs, + ) + + # This call sometimes hangs indefinitely, so we run it in a timeout + spaces = run_with_timeout( + timeout=10, + func=confluence_client_with_minimal_retries.get_all_spaces, + limit=1, + ) + + # uncomment the following for testing + # the following is an attempt to retrieve the user's timezone + # Unfornately, all data is returned in UTC regardless of the user's time zone + # even tho CQL parses incoming times based on the user's time zone + # space_key = spaces["results"][0]["key"] + # space_details = confluence_client_with_minimal_retries.cql(f"space.key={space_key}+AND+type=space") + + if not spaces: + raise RuntimeError( + f"No spaces found at {url}! " + "Check your credentials and wiki_base and make sure " + "is_cloud is set correctly." + ) + + logging.info("Confluence probe succeeded.") + + def _initialize_connection( + self, + **kwargs: Any, + ) -> None: + """Called externally to init the connection in a thread safe manner.""" + merged_kwargs = {**self.shared_base_kwargs, **kwargs} + with self._credentials_provider: + credentials, _ = self._renew_credentials() + self._confluence = self._initialize_connection_helper( + credentials, **merged_kwargs + ) + self._kwargs = merged_kwargs + + def _initialize_connection_helper( + self, + credentials: dict[str, Any], + **kwargs: Any, + ) -> Confluence: + """Called internally to init the connection. Distributed locking + to prevent multiple threads from modifying the credentials + must be handled around this function.""" + + confluence = None + + # probe connection with direct client, no retries + if "confluence_refresh_token" in credentials: + logging.info("Connecting to Confluence Cloud with OAuth Access Token.") + + oauth2_dict: dict[str, Any] = OnyxConfluence._make_oauth2_dict(credentials) + url = f"https://api.atlassian.com/ex/confluence/{credentials['cloud_id']}" + confluence = Confluence(url=url, oauth2=oauth2_dict, **kwargs) + else: + logging.info( + f"Connecting to Confluence with Personal Access Token as user: {credentials['confluence_username']}" + ) + if self._is_cloud: + confluence = Confluence( + url=self._url, + username=credentials["confluence_username"], + password=credentials["confluence_access_token"], + **kwargs, + ) + else: + confluence = Confluence( + url=self._url, + token=credentials["confluence_access_token"], + **kwargs, + ) + + return confluence + + # https://developer.atlassian.com/cloud/confluence/rate-limiting/ + # This uses the native rate limiting option provided by the + # confluence client and otherwise applies a simpler set of error handling. + def _make_rate_limited_confluence_method( + self, name: str, credential_provider: CredentialsProviderInterface | None + ) -> Callable[..., Any]: + def wrapped_call(*args: list[Any], **kwargs: Any) -> Any: + MAX_RETRIES = 5 + + TIMEOUT = 600 + timeout_at = time.monotonic() + TIMEOUT + + for attempt in range(MAX_RETRIES): + if time.monotonic() > timeout_at: + raise TimeoutError( + f"Confluence call attempts took longer than {TIMEOUT} seconds." + ) + + # we're relying more on the client to rate limit itself + # and applying our own retries in a more specific set of circumstances + try: + if credential_provider: + with credential_provider: + credentials, renewed = self._renew_credentials() + if renewed: + self._confluence = self._initialize_connection_helper( + credentials, **self._kwargs + ) + attr = getattr(self._confluence, name, None) + if attr is None: + # The underlying Confluence client doesn't have this attribute + raise AttributeError( + f"'{type(self).__name__}' object has no attribute '{name}'" + ) + + return attr(*args, **kwargs) + else: + attr = getattr(self._confluence, name, None) + if attr is None: + # The underlying Confluence client doesn't have this attribute + raise AttributeError( + f"'{type(self).__name__}' object has no attribute '{name}'" + ) + + return attr(*args, **kwargs) + + except HTTPError as e: + delay_until = _handle_http_error(e, attempt) + logging.warning( + f"HTTPError in confluence call. " + f"Retrying in {delay_until} seconds..." + ) + while time.monotonic() < delay_until: + # in the future, check a signal here to exit + time.sleep(1) + except AttributeError as e: + # Some error within the Confluence library, unclear why it fails. + # Users reported it to be intermittent, so just retry + if attempt == MAX_RETRIES - 1: + raise e + + logging.exception( + "Confluence Client raised an AttributeError. Retrying..." + ) + time.sleep(5) + + return wrapped_call + + def __getattr__(self, name: str) -> Any: + """Dynamically intercept attribute/method access.""" + attr = getattr(self._confluence, name, None) + if attr is None: + # The underlying Confluence client doesn't have this attribute + raise AttributeError( + f"'{type(self).__name__}' object has no attribute '{name}'" + ) + + # If it's not a method, just return it after ensuring token validity + if not callable(attr): + return attr + + # skip methods that start with "_" + if name.startswith("_"): + return attr + + # wrap the method with our retry handler + rate_limited_method: Callable[..., Any] = ( + self._make_rate_limited_confluence_method(name, self._credentials_provider) + ) + + return rate_limited_method + + def _try_one_by_one_for_paginated_url( + self, + url_suffix: str, + initial_start: int, + limit: int, + ) -> Generator[dict[str, Any], None, str | None]: + """ + Go through `limit` items, starting at `initial_start` one by one (e.g. using + `limit=1` for each call). + + If we encounter an error, we skip the item and try the next one. We will return + the items we were able to retrieve successfully. + + Returns the expected next url_suffix. Returns None if it thinks we've hit the end. + + TODO (chris): make this yield failures as well as successes. + TODO (chris): make this work for confluence cloud somehow. + """ + if self._is_cloud: + raise RuntimeError("This method is not implemented for Confluence Cloud.") + + found_empty_page = False + temp_url_suffix = url_suffix + + for ind in range(limit): + try: + temp_url_suffix = update_param_in_path( + url_suffix, "start", str(initial_start + ind) + ) + temp_url_suffix = update_param_in_path(temp_url_suffix, "limit", "1") + logging.info(f"Making recovery confluence call to {temp_url_suffix}") + raw_response = self.get(path=temp_url_suffix, advanced_mode=True) + raw_response.raise_for_status() + + latest_results = raw_response.json().get("results", []) + yield from latest_results + + if not latest_results: + # no more results, break out of the loop + logging.info( + f"No results found for call '{temp_url_suffix}'" + "Stopping pagination." + ) + found_empty_page = True + break + except Exception: + logging.exception( + f"Error in confluence call to {temp_url_suffix}. Continuing." + ) + + if found_empty_page: + return None + + # if we got here, we successfully tried `limit` items + return update_param_in_path(url_suffix, "start", str(initial_start + limit)) + + def _paginate_url( + self, + url_suffix: str, + limit: int | None = None, + # Called with the next url to use to get the next page + next_page_callback: Callable[[str], None] | None = None, + force_offset_pagination: bool = False, + ) -> Iterator[dict[str, Any]]: + """ + This will paginate through the top level query. + """ + if not limit: + limit = _DEFAULT_PAGINATION_LIMIT + + url_suffix = update_param_in_path(url_suffix, "limit", str(limit)) + + while url_suffix: + logging.debug(f"Making confluence call to {url_suffix}") + try: + raw_response = self.get( + path=url_suffix, + advanced_mode=True, + params={ + "body-format": "atlas_doc_format", + "expand": "body.atlas_doc_format", + }, + ) + except Exception as e: + logging.exception(f"Error in confluence call to {url_suffix}") + raise e + + try: + raw_response.raise_for_status() + except Exception as e: + logging.warning(f"Error in confluence call to {url_suffix}") + + # If the problematic expansion is in the url, replace it + # with the replacement expansion and try again + # If that fails, raise the error + if _PROBLEMATIC_EXPANSIONS in url_suffix: + logging.warning( + f"Replacing {_PROBLEMATIC_EXPANSIONS} with {_REPLACEMENT_EXPANSIONS}" + " and trying again." + ) + url_suffix = url_suffix.replace( + _PROBLEMATIC_EXPANSIONS, + _REPLACEMENT_EXPANSIONS, + ) + continue + + # If we fail due to a 500, try one by one. + # NOTE: this iterative approach only works for server, since cloud uses cursor-based + # pagination + if raw_response.status_code == 500 and not self._is_cloud: + initial_start = get_start_param_from_url(url_suffix) + if initial_start is None: + # can't handle this if we don't have offset-based pagination + raise + + # this will just yield the successful items from the batch + new_url_suffix = yield from self._try_one_by_one_for_paginated_url( + url_suffix, + initial_start=initial_start, + limit=limit, + ) + + # this means we ran into an empty page + if new_url_suffix is None: + if next_page_callback: + next_page_callback("") + break + + url_suffix = new_url_suffix + continue + + else: + logging.exception( + f"Error in confluence call to {url_suffix} \n" + f"Raw Response Text: {raw_response.text} \n" + f"Full Response: {raw_response.__dict__} \n" + f"Error: {e} \n" + ) + raise + + try: + next_response = raw_response.json() + except Exception as e: + logging.exception( + f"Failed to parse response as JSON. Response: {raw_response.__dict__}" + ) + raise e + + # Yield the results individually. + results = cast(list[dict[str, Any]], next_response.get("results", [])) + + # Note 1: + # Make sure we don't update the start by more than the amount + # of results we were able to retrieve. The Confluence API has a + # weird behavior where if you pass in a limit that is too large for + # the configured server, it will artificially limit the amount of + # results returned BUT will not apply this to the start parameter. + # This will cause us to miss results. + # + # Note 2: + # We specifically perform manual yielding (i.e., `for x in xs: yield x`) as opposed to using a `yield from xs` + # because we *have to call the `next_page_callback`* prior to yielding the last element! + # + # If we did: + # + # ```py + # yield from results + # if next_page_callback: + # next_page_callback(url_suffix) + # ``` + # + # then the logic would fail since the iterator would finish (and the calling scope would exit out of its driving + # loop) prior to the callback being called. + + old_url_suffix = url_suffix + updated_start = get_start_param_from_url(old_url_suffix) + url_suffix = cast(str, next_response.get("_links", {}).get("next", "")) + for i, result in enumerate(results): + updated_start += 1 + if url_suffix and next_page_callback and i == len(results) - 1: + # update the url if we're on the last result in the page + if not self._is_cloud: + # If confluence claims there are more results, we update the start param + # based on how many results were returned and try again. + url_suffix = update_param_in_path( + url_suffix, "start", str(updated_start) + ) + # notify the caller of the new url + next_page_callback(url_suffix) + + elif force_offset_pagination and i == len(results) - 1: + url_suffix = update_param_in_path( + old_url_suffix, "start", str(updated_start) + ) + + yield result + + # we've observed that Confluence sometimes returns a next link despite giving + # 0 results. This is a bug with Confluence, so we need to check for it and + # stop paginating. + if url_suffix and not results: + logging.info( + f"No results found for call '{old_url_suffix}' despite next link " + "being present. Stopping pagination." + ) + break + + def build_cql_url(self, cql: str, expand: str | None = None) -> str: + expand_string = f"&expand={expand}" if expand else "" + return f"rest/api/content/search?cql={cql}{expand_string}" + + def paginated_cql_retrieval( + self, + cql: str, + expand: str | None = None, + limit: int | None = None, + ) -> Iterator[dict[str, Any]]: + """ + The content/search endpoint can be used to fetch pages, attachments, and comments. + """ + cql_url = self.build_cql_url(cql, expand) + yield from self._paginate_url(cql_url, limit) + + def paginated_page_retrieval( + self, + cql_url: str, + limit: int, + # Called with the next url to use to get the next page + next_page_callback: Callable[[str], None] | None = None, + ) -> Iterator[dict[str, Any]]: + """ + Error handling (and testing) wrapper for _paginate_url, + because the current approach to page retrieval involves handling the + next page links manually. + """ + try: + yield from self._paginate_url( + cql_url, limit=limit, next_page_callback=next_page_callback + ) + except Exception as e: + logging.exception(f"Error in paginated_page_retrieval: {e}") + raise e + + def cql_paginate_all_expansions( + self, + cql: str, + expand: str | None = None, + limit: int | None = None, + ) -> Iterator[dict[str, Any]]: + """ + This function will paginate through the top level query first, then + paginate through all of the expansions. + """ + + def _traverse_and_update(data: dict | list) -> None: + if isinstance(data, dict): + next_url = data.get("_links", {}).get("next") + if next_url and "results" in data: + data["results"].extend(self._paginate_url(next_url, limit=limit)) + + for value in data.values(): + _traverse_and_update(value) + elif isinstance(data, list): + for item in data: + _traverse_and_update(item) + + for confluence_object in self.paginated_cql_retrieval(cql, expand, limit): + _traverse_and_update(confluence_object) + yield confluence_object + + def paginated_cql_user_retrieval( + self, + expand: str | None = None, + limit: int | None = None, + ) -> Iterator[ConfluenceUser]: + """ + The search/user endpoint can be used to fetch users. + It's a separate endpoint from the content/search endpoint used only for users. + Otherwise it's very similar to the content/search endpoint. + """ + + # this is needed since there is a live bug with Confluence Server/Data Center + # where not all users are returned by the APIs. This is a workaround needed until + # that is patched. + if self._confluence_user_profiles_override: + yield from self._confluence_user_profiles_override + + elif self._is_cloud: + cql = "type=user" + url = "rest/api/search/user" + expand_string = f"&expand={expand}" if expand else "" + url += f"?cql={cql}{expand_string}" + for user_result in self._paginate_url( + url, limit, force_offset_pagination=True + ): + user = user_result["user"] + yield ConfluenceUser( + user_id=user["accountId"], + username=None, + display_name=user["displayName"], + email=user.get("email"), + type=user["accountType"], + ) + else: + for user in self._paginate_url("rest/api/user/list", limit): + yield ConfluenceUser( + user_id=user["userKey"], + username=user["username"], + display_name=user["displayName"], + email=None, + type=user.get("type", "user"), + ) + + def paginated_groups_by_user_retrieval( + self, + user_id: str, # accountId in Cloud, userKey in Server + limit: int | None = None, + ) -> Iterator[dict[str, Any]]: + """ + This is not an SQL like query. + It's a confluence specific endpoint that can be used to fetch groups. + """ + user_field = "accountId" if self._is_cloud else "key" + user_value = user_id + # Server uses userKey (but calls it key during the API call), Cloud uses accountId + user_query = f"{user_field}={quote(user_value)}" + + url = f"rest/api/user/memberof?{user_query}" + yield from self._paginate_url(url, limit, force_offset_pagination=True) + + def paginated_groups_retrieval( + self, + limit: int | None = None, + ) -> Iterator[dict[str, Any]]: + """ + This is not an SQL like query. + It's a confluence specific endpoint that can be used to fetch groups. + """ + yield from self._paginate_url("rest/api/group", limit) + + def paginated_group_members_retrieval( + self, + group_name: str, + limit: int | None = None, + ) -> Iterator[dict[str, Any]]: + """ + This is not an SQL like query. + It's a confluence specific endpoint that can be used to fetch the members of a group. + THIS DOESN'T WORK FOR SERVER because it breaks when there is a slash in the group name. + E.g. neither "test/group" nor "test%2Fgroup" works for confluence. + """ + group_name = quote(group_name) + yield from self._paginate_url(f"rest/api/group/{group_name}/member", limit) + + def get_all_space_permissions_server( + self, + space_key: str, + ) -> list[dict[str, Any]]: + """ + This is a confluence server specific method that can be used to + fetch the permissions of a space. + This is better logging than calling the get_space_permissions method + because it returns a jsonrpc response. + TODO: Make this call these endpoints for newer confluence versions: + - /rest/api/space/{spaceKey}/permissions + - /rest/api/space/{spaceKey}/permissions/anonymous + """ + url = "rpc/json-rpc/confluenceservice-v2" + data = { + "jsonrpc": "2.0", + "method": "getSpacePermissionSets", + "id": 7, + "params": [space_key], + } + response = self.post(url, data=data) + logging.debug(f"jsonrpc response: {response}") + if not response.get("result"): + logging.warning( + f"No jsonrpc response for space permissions for space {space_key}" + f"\nResponse: {response}" + ) + + return response.get("result", []) + + def get_current_user(self, expand: str | None = None) -> Any: + """ + Implements a method that isn't in the third party client. + + Get information about the current user + :param expand: OPTIONAL expand for get status of user. + Possible param is "status". Results are "Active, Deactivated" + :return: Returns the user details + """ + + from atlassian.errors import ApiPermissionError # type:ignore + + url = "rest/api/user/current" + params = {} + if expand: + params["expand"] = expand + try: + response = self.get(url, params=params) + except HTTPError as e: + if e.response.status_code == 403: + raise ApiPermissionError( + "The calling user does not have permission", reason=e + ) + raise + return response + + +def get_user_email_from_username__server( + confluence_client: OnyxConfluence, user_name: str +) -> str | None: + global _USER_EMAIL_CACHE + if _USER_EMAIL_CACHE.get(user_name) is None: + try: + response = confluence_client.get_mobile_parameters(user_name) + email = response.get("email") + except Exception: + logging.warning(f"failed to get confluence email for {user_name}") + # For now, we'll just return None and log a warning. This means + # we will keep retrying to get the email every group sync. + email = None + # We may want to just return a string that indicates failure so we dont + # keep retrying + # email = f"FAILED TO GET CONFLUENCE EMAIL FOR {user_name}" + _USER_EMAIL_CACHE[user_name] = email + return _USER_EMAIL_CACHE[user_name] + + +def _get_user(confluence_client: OnyxConfluence, user_id: str) -> str: + """Get Confluence Display Name based on the account-id or userkey value + + Args: + user_id (str): The user id (i.e: the account-id or userkey) + confluence_client (Confluence): The Confluence Client + + Returns: + str: The User Display Name. 'Unknown User' if the user is deactivated or not found + """ + global _USER_ID_TO_DISPLAY_NAME_CACHE + if _USER_ID_TO_DISPLAY_NAME_CACHE.get(user_id) is None: + try: + result = confluence_client.get_user_details_by_userkey(user_id) + found_display_name = result.get("displayName") + except Exception: + found_display_name = None + + if not found_display_name: + try: + result = confluence_client.get_user_details_by_accountid(user_id) + found_display_name = result.get("displayName") + except Exception: + found_display_name = None + + _USER_ID_TO_DISPLAY_NAME_CACHE[user_id] = found_display_name + + return _USER_ID_TO_DISPLAY_NAME_CACHE.get(user_id) or _USER_NOT_FOUND + + +def sanitize_attachment_title(title: str) -> str: + """ + Sanitize the attachment title to be a valid HTML attribute. + """ + return title.replace("<", "_").replace(">", "_").replace(" ", "_").replace(":", "_") + + +def extract_text_from_confluence_html( + confluence_client: OnyxConfluence, + confluence_object: dict[str, Any], + fetched_titles: set[str], +) -> str: + """Parse a Confluence html page and replace the 'user Id' by the real + User Display Name + + Args: + confluence_object (dict): The confluence object as a dict + confluence_client (Confluence): Confluence client + fetched_titles (set[str]): The titles of the pages that have already been fetched + Returns: + str: loaded and formated Confluence page + """ + body = confluence_object["body"] + object_html = body.get("storage", body.get("view", {})).get("value") + + soup = bs4.BeautifulSoup(object_html, "html.parser") + + _remove_macro_stylings(soup=soup) + + for user in soup.findAll("ri:user"): + user_id = ( + user.attrs["ri:account-id"] + if "ri:account-id" in user.attrs + else user.get("ri:userkey") + ) + if not user_id: + logging.warning( + "ri:userkey not found in ri:user element. " f"Found attrs: {user.attrs}" + ) + continue + # Include @ sign for tagging, more clear for LLM + user.replaceWith("@" + _get_user(confluence_client, user_id)) + + for html_page_reference in soup.findAll("ac:structured-macro"): + # Here, we only want to process page within page macros + if html_page_reference.attrs.get("ac:name") != "include": + continue + + page_data = html_page_reference.find("ri:page") + if not page_data: + logging.warning( + f"Skipping retrieval of {html_page_reference} because because page data is missing" + ) + continue + + page_title = page_data.attrs.get("ri:content-title") + if not page_title: + # only fetch pages that have a title + logging.warning( + f"Skipping retrieval of {html_page_reference} because it has no title" + ) + continue + + if page_title in fetched_titles: + # prevent recursive fetching of pages + logging.debug(f"Skipping {page_title} because it has already been fetched") + continue + + fetched_titles.add(page_title) + + # Wrap this in a try-except because there are some pages that might not exist + try: + page_query = f"type=page and title='{quote(page_title)}'" + + page_contents: dict[str, Any] | None = None + # Confluence enforces title uniqueness, so we should only get one result here + for page in confluence_client.paginated_cql_retrieval( + cql=page_query, + expand="body.storage.value", + limit=1, + ): + page_contents = page + break + except Exception as e: + logging.warning( + f"Error getting page contents for object {confluence_object}: {e}" + ) + continue + + if not page_contents: + continue + + text_from_page = extract_text_from_confluence_html( + confluence_client=confluence_client, + confluence_object=page_contents, + fetched_titles=fetched_titles, + ) + + html_page_reference.replaceWith(text_from_page) + + for html_link_body in soup.findAll("ac:link-body"): + # This extracts the text from inline links in the page so they can be + # represented in the document text as plain text + try: + text_from_link = html_link_body.text + html_link_body.replaceWith(f"(LINK TEXT: {text_from_link})") + except Exception as e: + logging.warning(f"Error processing ac:link-body: {e}") + + for html_attachment in soup.findAll("ri:attachment"): + # This extracts the text from inline attachments in the page so they can be + # represented in the document text as plain text + try: + html_attachment.replaceWith( + f"{sanitize_attachment_title(html_attachment.attrs['ri:filename'])}" + ) # to be replaced later + except Exception as e: + logging.warning(f"Error processing ac:attachment: {e}") + + return format_document_soup(soup) + + +def _remove_macro_stylings(soup: bs4.BeautifulSoup) -> None: + for macro_root in soup.findAll("ac:structured-macro"): + if not isinstance(macro_root, bs4.Tag): + continue + + macro_styling = macro_root.find(name="ac:parameter", attrs={"ac:name": "page"}) + if not macro_styling or not isinstance(macro_styling, bs4.Tag): + continue + + macro_styling.extract() + + +def get_page_restrictions( + confluence_client: OnyxConfluence, + page_id: str, + page_restrictions: dict[str, Any], + ancestors: list[dict[str, Any]], +) -> ExternalAccess | None: + """ + Get page access restrictions for a Confluence page. + This functionality requires Enterprise Edition. + + Args: + confluence_client: OnyxConfluence client instance + page_id: The ID of the page + page_restrictions: Dictionary containing page restriction data + ancestors: List of ancestor pages with their restriction data + + Returns: + ExternalAccess object for the page. None if EE is not enabled or no restrictions found. + """ + # Fetch the EE implementation + """ + ee_get_all_page_restrictions = cast( + Callable[ + [OnyxConfluence, str, dict[str, Any], list[dict[str, Any]]], + ExternalAccess | None, + ], + fetch_versioned_implementation( + "onyx.external_permissions.confluence.page_access", "get_page_restrictions" + ), + ) + + return ee_get_all_page_restrictions( + confluence_client, page_id, page_restrictions, ancestors + )""" + return {} + + +def get_all_space_permissions( + confluence_client: OnyxConfluence, + is_cloud: bool, +) -> dict[str, ExternalAccess]: + """ + Get access permissions for all spaces in Confluence. + This functionality requires Enterprise Edition. + + Args: + confluence_client: OnyxConfluence client instance + is_cloud: Whether this is a Confluence Cloud instance + + Returns: + Dictionary mapping space keys to ExternalAccess objects. Empty dict if EE is not enabled. + """ + """ + # Fetch the EE implementation + ee_get_all_space_permissions = cast( + Callable[ + [OnyxConfluence, bool], + dict[str, ExternalAccess], + ], + fetch_versioned_implementation( + "onyx.external_permissions.confluence.space_access", + "get_all_space_permissions", + ), + ) + + return ee_get_all_space_permissions(confluence_client, is_cloud)""" + return {} + + +def _make_attachment_link( + confluence_client: "OnyxConfluence", + attachment: dict[str, Any], + parent_content_id: str | None = None, +) -> str | None: + download_link = "" + + if "api.atlassian.com" in confluence_client.url: + # https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-content---attachments/#api-wiki-rest-api-content-id-child-attachment-attachmentid-download-get + if not parent_content_id: + logging.warning( + "parent_content_id is required to download attachments from Confluence Cloud!" + ) + return None + + download_link = ( + confluence_client.url + + f"/rest/api/content/{parent_content_id}/child/attachment/{attachment['id']}/download" + ) + else: + download_link = confluence_client.url + attachment["_links"]["download"] + + return download_link + + +def _process_image_attachment( + confluence_client: "OnyxConfluence", + attachment: dict[str, Any], + raw_bytes: bytes, + media_type: str, +) -> AttachmentProcessingResult: + """Process an image attachment by saving it without generating a summary.""" + return AttachmentProcessingResult(text="", file_blob=raw_bytes, file_name=attachment.get("title", "unknown_title"), error=None) + + +def process_attachment( + confluence_client: "OnyxConfluence", + attachment: dict[str, Any], + parent_content_id: str | None, + allow_images: bool, +) -> AttachmentProcessingResult: + """ + Processes a Confluence attachment. If it's a document, extracts text, + or if it's an image, stores it for later analysis. Returns a structured result. + """ + try: + # Get the media type from the attachment metadata + media_type: str = attachment.get("metadata", {}).get("mediaType", "") + # Validate the attachment type + if not validate_attachment_filetype(attachment): + return AttachmentProcessingResult( + text=None, + file_blob=None, + file_name=None, + error=f"Unsupported file type: {media_type}", + ) + + attachment_link = _make_attachment_link( + confluence_client, attachment, parent_content_id + ) + if not attachment_link: + return AttachmentProcessingResult( + text=None, file_blob=None, file_name=None, error="Failed to make attachment link" + ) + + attachment_size = attachment["extensions"]["fileSize"] + + if media_type.startswith("image/"): + if not allow_images: + return AttachmentProcessingResult( + text=None, + file_blob=None, + file_name=None, + error="Image downloading is not enabled", + ) + else: + if attachment_size > CONFLUENCE_CONNECTOR_ATTACHMENT_SIZE_THRESHOLD: + logging.warning( + f"Skipping {attachment_link} due to size. " + f"size={attachment_size} " + f"threshold={CONFLUENCE_CONNECTOR_ATTACHMENT_SIZE_THRESHOLD}" + ) + return AttachmentProcessingResult( + text=None, + file_blob=None, + file_name=None, + error=f"Attachment text too long: {attachment_size} chars", + ) + + logging.info( + f"Downloading attachment: " + f"title={attachment['title']} " + f"length={attachment_size} " + f"link={attachment_link}" + ) + + # Download the attachment + resp: requests.Response = confluence_client._session.get(attachment_link) + if resp.status_code != 200: + logging.warning( + f"Failed to fetch {attachment_link} with status code {resp.status_code}" + ) + return AttachmentProcessingResult( + text=None, + file_blob=None, + file_name=None, + error=f"Attachment download status code is {resp.status_code}", + ) + + raw_bytes = resp.content + if not raw_bytes: + return AttachmentProcessingResult( + text=None, file_blob=None, file_name=None, error="attachment.content is None" + ) + + # Process image attachments + if media_type.startswith("image/"): + return _process_image_attachment( + confluence_client, attachment, raw_bytes, media_type + ) + + # Process document attachments + try: + return AttachmentProcessingResult(text="",file_blob=raw_bytes, file_name=attachment.get("title", "unknown_title"), error=None) + except Exception as e: + logging.exception(e) + return AttachmentProcessingResult( + text=None, file_blob=None, file_name=None, error=f"Failed to extract text: {e}" + ) + + except Exception as e: + return AttachmentProcessingResult( + text=None, file_blob=None, file_name=None, error=f"Failed to process attachment: {e}" + ) + + +def convert_attachment_to_content( + confluence_client: "OnyxConfluence", + attachment: dict[str, Any], + page_id: str, + allow_images: bool, +) -> tuple[str | None, bytes | bytearray | None] | None: + """ + Facade function which: + 1. Validates attachment type + 2. Extracts content or stores image for later processing + 3. Returns (content_text, stored_file_name) or None if we should skip it + """ + media_type = attachment.get("metadata", {}).get("mediaType", "") + # Quick check for unsupported types: + if media_type.startswith("video/") or media_type == "application/gliffy+json": + logging.warning( + f"Skipping unsupported attachment type: '{media_type}' for {attachment['title']}" + ) + return None + + result = process_attachment(confluence_client, attachment, page_id, allow_images) + if result.error is not None: + logging.warning( + f"Attachment {attachment['title']} encountered error: {result.error}" + ) + return None + + return result.file_name, result.file_blob + + +class ConfluenceConnector( + CheckpointedConnector[ConfluenceCheckpoint], + SlimConnector, + SlimConnectorWithPermSync, + CredentialsConnector, +): + def __init__( + self, + wiki_base: str, + is_cloud: bool, + space: str = "", + page_id: str = "", + index_recursively: bool = False, + cql_query: str | None = None, + batch_size: int = INDEX_BATCH_SIZE, + continue_on_failure: bool = CONTINUE_ON_CONNECTOR_FAILURE, + # if a page has one of the labels specified in this list, we will just + # skip it. This is generally used to avoid indexing extra sensitive + # pages. + labels_to_skip: list[str] = CONFLUENCE_CONNECTOR_LABELS_TO_SKIP, + timezone_offset: float = CONFLUENCE_TIMEZONE_OFFSET, + time_buffer_seconds: int = CONFLUENCE_SYNC_TIME_BUFFER_SECONDS, + scoped_token: bool = False, + ) -> None: + self.wiki_base = wiki_base + self.is_cloud = is_cloud + self.space = space + self.page_id = page_id + self.index_recursively = index_recursively + self.cql_query = cql_query + self.batch_size = batch_size + self.labels_to_skip = labels_to_skip + self.timezone_offset = timezone_offset + self.time_buffer_seconds = max(0, time_buffer_seconds) + self.scoped_token = scoped_token + self._confluence_client: OnyxConfluence | None = None + self._low_timeout_confluence_client: OnyxConfluence | None = None + self._fetched_titles: set[str] = set() + self.allow_images = False + + # Remove trailing slash from wiki_base if present + self.wiki_base = wiki_base.rstrip("/") + """ + If nothing is provided, we default to fetching all pages + Only one or none of the following options should be specified so + the order shouldn't matter + However, we use elif to ensure that only of the following is enforced + """ + base_cql_page_query = "type=page" + if cql_query: + base_cql_page_query = cql_query + elif page_id: + if index_recursively: + base_cql_page_query += f" and (ancestor='{page_id}' or id='{page_id}')" + else: + base_cql_page_query += f" and id='{page_id}'" + elif space: + uri_safe_space = quote(space) + base_cql_page_query += f" and space='{uri_safe_space}'" + + self.base_cql_page_query = base_cql_page_query + + self.cql_label_filter = "" + if labels_to_skip: + labels_to_skip = list(set(labels_to_skip)) + comma_separated_labels = ",".join( + f"'{quote(label)}'" for label in labels_to_skip + ) + self.cql_label_filter = f" and label not in ({comma_separated_labels})" + + self.timezone: timezone = timezone(offset=timedelta(hours=timezone_offset)) + self.credentials_provider: CredentialsProviderInterface | None = None + + self.probe_kwargs = { + "max_backoff_retries": 6, + "max_backoff_seconds": 10, + } + + self.final_kwargs = { + "max_backoff_retries": 10, + "max_backoff_seconds": 60, + } + + # deprecated + self.continue_on_failure = continue_on_failure + + def set_allow_images(self, value: bool) -> None: + logging.info(f"Setting allow_images to {value}.") + self.allow_images = value + + def _adjust_start_for_query( + self, start: SecondsSinceUnixEpoch | None + ) -> SecondsSinceUnixEpoch | None: + if not start or start <= 0: + return start + if self.time_buffer_seconds <= 0: + return start + return max(0.0, start - self.time_buffer_seconds) + + def _is_newer_than_start( + self, doc_time: datetime | None, start: SecondsSinceUnixEpoch | None + ) -> bool: + if not start or start <= 0: + return True + if doc_time is None: + return True + return doc_time.timestamp() > start + + @property + def confluence_client(self) -> OnyxConfluence: + if self._confluence_client is None: + raise ConnectorMissingCredentialError("Confluence") + return self._confluence_client + + @property + def low_timeout_confluence_client(self) -> OnyxConfluence: + if self._low_timeout_confluence_client is None: + raise ConnectorMissingCredentialError("Confluence") + return self._low_timeout_confluence_client + + def set_credentials_provider( + self, credentials_provider: CredentialsProviderInterface + ) -> None: + self.credentials_provider = credentials_provider + + # raises exception if there's a problem + confluence_client = OnyxConfluence( + is_cloud=self.is_cloud, + url=self.wiki_base, + credentials_provider=credentials_provider, + scoped_token=self.scoped_token, + ) + confluence_client._probe_connection(**self.probe_kwargs) + confluence_client._initialize_connection(**self.final_kwargs) + + self._confluence_client = confluence_client + + # create a low timeout confluence client for sync flows + low_timeout_confluence_client = OnyxConfluence( + is_cloud=self.is_cloud, + url=self.wiki_base, + credentials_provider=credentials_provider, + timeout=3, + scoped_token=self.scoped_token, + ) + low_timeout_confluence_client._probe_connection(**self.probe_kwargs) + low_timeout_confluence_client._initialize_connection(**self.final_kwargs) + + self._low_timeout_confluence_client = low_timeout_confluence_client + + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: + raise NotImplementedError("Use set_credentials_provider with this connector.") + + def _construct_page_cql_query( + self, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> str: + """ + Constructs a CQL query for use in the confluence API. See + https://developer.atlassian.com/server/confluence/advanced-searching-using-cql/ + for more information. This is JUST the CQL, not the full URL used to hit the API. + Use _build_page_retrieval_url to get the full URL. + """ + page_query = self.base_cql_page_query + self.cql_label_filter + # Add time filters + query_start = self._adjust_start_for_query(start) + if query_start: + formatted_start_time = datetime.fromtimestamp( + query_start, tz=self.timezone + ).strftime("%Y-%m-%d %H:%M") + page_query += f" and lastmodified >= '{formatted_start_time}'" + if end: + formatted_end_time = datetime.fromtimestamp(end, tz=self.timezone).strftime( + "%Y-%m-%d %H:%M" + ) + page_query += f" and lastmodified <= '{formatted_end_time}'" + + page_query += " order by lastmodified asc" + return page_query + + def _construct_attachment_query( + self, + confluence_page_id: str, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> str: + attachment_query = f"type=attachment and container='{confluence_page_id}'" + attachment_query += self.cql_label_filter + + # Add time filters to avoid reprocessing unchanged attachments during refresh + query_start = self._adjust_start_for_query(start) + if query_start: + formatted_start_time = datetime.fromtimestamp( + query_start, tz=self.timezone + ).strftime("%Y-%m-%d %H:%M") + attachment_query += f" and lastmodified >= '{formatted_start_time}'" + if end: + formatted_end_time = datetime.fromtimestamp(end, tz=self.timezone).strftime( + "%Y-%m-%d %H:%M" + ) + attachment_query += f" and lastmodified <= '{formatted_end_time}'" + + attachment_query += " order by lastmodified asc" + return attachment_query + + def _get_comment_string_for_page_id(self, page_id: str) -> str: + comment_string = "" + comment_cql = f"type=comment and container='{page_id}'" + comment_cql += self.cql_label_filter + expand = ",".join(_COMMENT_EXPANSION_FIELDS) + + for comment in self.confluence_client.paginated_cql_retrieval( + cql=comment_cql, + expand=expand, + ): + comment_string += "\nComment:\n" + comment_string += extract_text_from_confluence_html( + confluence_client=self.confluence_client, + confluence_object=comment, + fetched_titles=set(), + ) + return comment_string + + def _convert_page_to_document( + self, page: dict[str, Any] + ) -> Document | ConnectorFailure: + """ + Converts a Confluence page to a Document object. + Includes the page content, comments, and attachments. + """ + page_id = page_url = "" + try: + # Extract basic page information + page_id = page["id"] + page_title = page["title"] + logging.info(f"Converting page {page_title} to document") + page_url = build_confluence_document_id( + self.wiki_base, page["_links"]["webui"], self.is_cloud + ) + + # Get the page content + page_content = extract_text_from_confluence_html( + self.confluence_client, page, self._fetched_titles + ) + + # Create the main section for the page content + sections: list[TextSection | ImageSection] = [ + TextSection(text=page_content, link=page_url) + ] + + # Process comments if available + comment_text = self._get_comment_string_for_page_id(page_id) + if comment_text: + sections.append( + TextSection(text=comment_text, link=f"{page_url}#comments") + ) + # Note: attachments are no longer merged into the page document. + # They are indexed as separate documents downstream. + + # Extract metadata + metadata = {} + if "space" in page: + metadata["space"] = page["space"].get("name", "") + + # Extract labels + labels = [] + if "metadata" in page and "labels" in page["metadata"]: + for label in page["metadata"]["labels"].get("results", []): + labels.append(label.get("name", "")) + if labels: + metadata["labels"] = labels + + # Extract owners + primary_owners = [] + if "version" in page and "by" in page["version"]: + author = page["version"]["by"] + display_name = author.get("displayName", "Unknown") + email = author.get("email", "unknown@domain.invalid") + primary_owners.append( + BasicExpertInfo(display_name=display_name, email=email) + ) + + # Create the document + return Document( + id=page_url, + source=DocumentSource.CONFLUENCE, + semantic_identifier=page_title, + extension=".html", # Confluence pages are HTML + blob=page_content.encode("utf-8"), # Encode page content as bytes + size_bytes=len(page_content.encode("utf-8")), # Calculate size in bytes + doc_updated_at=datetime_from_string(page["version"]["when"]), + primary_owners=primary_owners if primary_owners else None, + ) + except Exception as e: + logging.error(f"Error converting page {page.get('id', 'unknown')}: {e}") + if is_atlassian_date_error(e): # propagate error to be caught and retried + raise + return ConnectorFailure( + failed_document=DocumentFailure( + document_id=page_id, + document_link=page_url, + ), + failure_message=f"Error converting page {page.get('id', 'unknown')}: {e}", + exception=e, + ) + + def _fetch_page_attachments( + self, + page: dict[str, Any], + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> tuple[list[Document], list[ConnectorFailure]]: + """ + Inline attachments are added directly to the document as text or image sections by + this function. The returned documents/connectorfailures are for non-inline attachments + and those at the end of the page. + """ + attachment_query = self._construct_attachment_query(page["id"], start, end) + attachment_failures: list[ConnectorFailure] = [] + attachment_docs: list[Document] = [] + page_url = "" + + for attachment in self.confluence_client.paginated_cql_retrieval( + cql=attachment_query, + expand=",".join(_ATTACHMENT_EXPANSION_FIELDS), + ): + media_type: str = attachment.get("metadata", {}).get("mediaType", "") + + # TODO(rkuo): this check is partially redundant with validate_attachment_filetype + # and checks in convert_attachment_to_content/process_attachment + # but doing the check here avoids an unnecessary download. Due for refactoring. + if not self.allow_images: + if media_type.startswith("image/"): + logging.info( + f"Skipping attachment because allow images is False: {attachment['title']}" + ) + continue + + if not validate_attachment_filetype( + attachment, + ): + logging.info( + f"Skipping attachment because it is not an accepted file type: {attachment['title']}" + ) + continue + + + logging.info( + f"Processing attachment: {attachment['title']} attached to page {page['title']}" + ) + # Attachment document id: use the download URL for stable identity + try: + object_url = build_confluence_document_id( + self.wiki_base, attachment["_links"]["download"], self.is_cloud + ) + except Exception as e: + logging.warning( + f"Invalid attachment url for id {attachment['id']}, skipping" + ) + logging.debug(f"Error building attachment url: {e}") + continue + try: + response = convert_attachment_to_content( + confluence_client=self.confluence_client, + attachment=attachment, + page_id=page["id"], + allow_images=self.allow_images, + ) + if response is None: + continue + + file_storage_name, file_blob = response + + if not file_blob: + logging.info("Skipping attachment because it is no blob fetched") + continue + + # Build attachment-specific metadata + attachment_metadata: dict[str, str | list[str]] = {} + if "space" in attachment: + attachment_metadata["space"] = attachment["space"].get("name", "") + labels: list[str] = [] + if "metadata" in attachment and "labels" in attachment["metadata"]: + for label in attachment["metadata"]["labels"].get("results", []): + labels.append(label.get("name", "")) + if labels: + attachment_metadata["labels"] = labels + page_url = page_url or build_confluence_document_id( + self.wiki_base, page["_links"]["webui"], self.is_cloud + ) + attachment_metadata["parent_page_id"] = page_url + attachment_id = build_confluence_document_id( + self.wiki_base, attachment["_links"]["webui"], self.is_cloud + ) + + primary_owners: list[BasicExpertInfo] | None = None + if "version" in attachment and "by" in attachment["version"]: + author = attachment["version"]["by"] + display_name = author.get("displayName", "Unknown") + email = author.get("email", "unknown@domain.invalid") + primary_owners = [ + BasicExpertInfo(display_name=display_name, email=email) + ] + + extension = Path(attachment.get("title", "")).suffix or ".unknown" + + attachment_doc = Document( + id=attachment_id, + # sections=sections, + source=DocumentSource.CONFLUENCE, + semantic_identifier=attachment.get("title", object_url), + extension=extension, + blob=file_blob, + size_bytes=len(file_blob), + metadata=attachment_metadata, + doc_updated_at=( + datetime_from_string(attachment["version"]["when"]) + if attachment.get("version") + and attachment["version"].get("when") + else None + ), + primary_owners=primary_owners, + ) + if self._is_newer_than_start(attachment_doc.doc_updated_at, start): + attachment_docs.append(attachment_doc) + except Exception as e: + logging.error( + f"Failed to extract/summarize attachment {attachment['title']}", + exc_info=e, + ) + if is_atlassian_date_error(e): + # propagate error to be caught and retried + raise + attachment_failures.append( + ConnectorFailure( + failed_document=DocumentFailure( + document_id=object_url, + document_link=object_url, + ), + failure_message=f"Failed to extract/summarize attachment {attachment['title']} for doc {object_url}", + exception=e, + ) + ) + + return attachment_docs, attachment_failures + + def _fetch_document_batches( + self, + checkpoint: ConfluenceCheckpoint, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> CheckpointOutput[ConfluenceCheckpoint]: + """ + Yields batches of Documents. For each page: + - Create a Document with 1 Section for the page text/comments + - Then fetch attachments. For each attachment: + - Attempt to convert it with convert_attachment_to_content(...) + - If successful, create a new Section with the extracted text or summary. + """ + checkpoint = copy.deepcopy(checkpoint) + + # use "start" when last_updated is 0 or for confluence server + start_ts = start + page_query_url = checkpoint.next_page_url or self._build_page_retrieval_url( + start_ts, end, self.batch_size + ) + logging.debug(f"page_query_url: {page_query_url}") + + # store the next page start for confluence server, cursor for confluence cloud + def store_next_page_url(next_page_url: str) -> None: + checkpoint.next_page_url = next_page_url + + for page in self.confluence_client.paginated_page_retrieval( + cql_url=page_query_url, + limit=self.batch_size, + next_page_callback=store_next_page_url, + ): + # Build doc from page + doc_or_failure = self._convert_page_to_document(page) + + if isinstance(doc_or_failure, ConnectorFailure): + yield doc_or_failure + continue + + # yield completed document (or failure) + if self._is_newer_than_start(doc_or_failure.doc_updated_at, start): + yield doc_or_failure + + # Now get attachments for that page: + attachment_docs, attachment_failures = self._fetch_page_attachments( + page, start, end + ) + # yield attached docs and failures + yield from attachment_docs + # yield from attachment_failures + + # Create checkpoint once a full page of results is returned + if checkpoint.next_page_url and checkpoint.next_page_url != page_query_url: + return checkpoint + + checkpoint.has_more = False + return checkpoint + + def _build_page_retrieval_url( + self, + start: SecondsSinceUnixEpoch | None, + end: SecondsSinceUnixEpoch | None, + limit: int, + ) -> str: + """ + Builds the full URL used to retrieve pages from the confluence API. + This can be used as input to the confluence client's _paginate_url + or paginated_page_retrieval methods. + """ + page_query = self._construct_page_cql_query(start, end) + cql_url = self.confluence_client.build_cql_url( + page_query, expand=",".join(_PAGE_EXPANSION_FIELDS) + ) + return update_param_in_path(cql_url, "limit", str(limit)) + + @override + def load_from_checkpoint( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: ConfluenceCheckpoint, + ) -> CheckpointOutput[ConfluenceCheckpoint]: + end += ONE_DAY # handle time zone weirdness + try: + return self._fetch_document_batches(checkpoint, start, end) + except Exception as e: + if is_atlassian_date_error(e) and start is not None: + logging.warning( + "Confluence says we provided an invalid 'updated' field. This may indicate" + "a real issue, but can also appear during edge cases like daylight" + f"savings time changes. Retrying with a 1 hour offset. Error: {e}" + ) + return self._fetch_document_batches(checkpoint, start - ONE_HOUR, end) + raise + + @override + def build_dummy_checkpoint(self) -> ConfluenceCheckpoint: + return ConfluenceCheckpoint(has_more=True, next_page_url=None) + + @override + def validate_checkpoint_json(self, checkpoint_json: str) -> ConfluenceCheckpoint: + return ConfluenceCheckpoint.model_validate_json(checkpoint_json) + + @override + def retrieve_all_slim_docs( + self, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + callback: IndexingHeartbeatInterface | None = None, + ) -> GenerateSlimDocumentOutput: + return self._retrieve_all_slim_docs( + start=start, + end=end, + callback=callback, + include_permissions=False, + ) + + def retrieve_all_slim_docs_perm_sync( + self, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + callback: IndexingHeartbeatInterface | None = None, + ) -> GenerateSlimDocumentOutput: + """ + Return 'slim' docs (IDs + minimal permission data). + Does not fetch actual text. Used primarily for incremental permission sync. + """ + return self._retrieve_all_slim_docs( + start=start, + end=end, + callback=callback, + include_permissions=True, + ) + + def _retrieve_all_slim_docs( + self, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + callback: IndexingHeartbeatInterface | None = None, + include_permissions: bool = True, + ) -> GenerateSlimDocumentOutput: + doc_metadata_list: list[SlimDocument] = [] + restrictions_expand = ",".join(_RESTRICTIONS_EXPANSION_FIELDS) + + space_level_access_info: dict[str, ExternalAccess] = {} + if include_permissions: + space_level_access_info = get_all_space_permissions( + self.confluence_client, self.is_cloud + ) + + def get_external_access( + doc_id: str, restrictions: dict[str, Any], ancestors: list[dict[str, Any]] + ) -> ExternalAccess | None: + return get_page_restrictions( + self.confluence_client, doc_id, restrictions, ancestors + ) or space_level_access_info.get(page_space_key) + + # Query pages + page_query = self.base_cql_page_query + self.cql_label_filter + for page in self.confluence_client.cql_paginate_all_expansions( + cql=page_query, + expand=restrictions_expand, + limit=_SLIM_DOC_BATCH_SIZE, + ): + page_id = page["id"] + page_restrictions = page.get("restrictions") or {} + page_space_key = page.get("space", {}).get("key") + page_ancestors = page.get("ancestors", []) + + page_id = build_confluence_document_id( + self.wiki_base, page["_links"]["webui"], self.is_cloud + ) + doc_metadata_list.append( + SlimDocument( + id=page_id, + external_access=( + get_external_access(page_id, page_restrictions, page_ancestors) + if include_permissions + else None + ), + ) + ) + + # Query attachments for each page + attachment_query = self._construct_attachment_query(page["id"]) + for attachment in self.confluence_client.cql_paginate_all_expansions( + cql=attachment_query, + expand=restrictions_expand, + limit=_SLIM_DOC_BATCH_SIZE, + ): + # If you skip images, you'll skip them in the permission sync + attachment["metadata"].get("mediaType", "") + if not validate_attachment_filetype( + attachment, + ): + continue + + attachment_restrictions = attachment.get("restrictions", {}) + if not attachment_restrictions: + attachment_restrictions = page_restrictions or {} + + attachment_space_key = attachment.get("space", {}).get("key") + if not attachment_space_key: + attachment_space_key = page_space_key + + attachment_id = build_confluence_document_id( + self.wiki_base, + attachment["_links"]["webui"], + self.is_cloud, + ) + doc_metadata_list.append( + SlimDocument( + id=attachment_id, + external_access=( + get_external_access( + attachment_id, attachment_restrictions, [] + ) + if include_permissions + else None + ), + ) + ) + + if len(doc_metadata_list) > _SLIM_DOC_BATCH_SIZE: + yield doc_metadata_list[:_SLIM_DOC_BATCH_SIZE] + doc_metadata_list = doc_metadata_list[_SLIM_DOC_BATCH_SIZE:] + + if callback and callback.should_stop(): + raise RuntimeError( + "retrieve_all_slim_docs_perm_sync: Stop signal detected" + ) + if callback: + callback.progress("retrieve_all_slim_docs_perm_sync", 1) + + yield doc_metadata_list + + def validate_connector_settings(self) -> None: + try: + spaces = self.low_timeout_confluence_client.get_all_spaces(limit=1) + except HTTPError as e: + status_code = e.response.status_code if e.response else None + if status_code == 401: + raise CredentialExpiredError( + "Invalid or expired Confluence credentials (HTTP 401)." + ) + elif status_code == 403: + raise InsufficientPermissionsError( + "Insufficient permissions to access Confluence resources (HTTP 403)." + ) + raise UnexpectedValidationError( + f"Unexpected Confluence error (status={status_code}): {e}" + ) + except Exception as e: + raise UnexpectedValidationError( + f"Unexpected error while validating Confluence settings: {e}" + ) + + if self.space: + try: + self.low_timeout_confluence_client.get_space(self.space) + except ApiError as e: + raise ConnectorValidationError( + "Invalid Confluence space key provided" + ) from e + + if not spaces or not spaces.get("results"): + raise ConnectorValidationError( + "No Confluence spaces found. Either your credentials lack permissions, or " + "there truly are no spaces in this Confluence instance." + ) + + + +if __name__ == "__main__": + import os + + # base url + wiki_base = os.environ["CONFLUENCE_URL"] + + # auth stuff + username = os.environ["CONFLUENCE_USERNAME"] + access_token = os.environ["CONFLUENCE_ACCESS_TOKEN"] + is_cloud = os.environ["CONFLUENCE_IS_CLOUD"].lower() == "true" + + # space + page + space = os.environ["CONFLUENCE_SPACE_KEY"] + # page_id = os.environ["CONFLUENCE_PAGE_ID"] + + confluence_connector = ConfluenceConnector( + wiki_base=wiki_base, + space=space, + is_cloud=is_cloud, + # page_id=page_id, + ) + + credentials_provider = StaticCredentialsProvider( + None, + DocumentSource.CONFLUENCE, + { + "confluence_username": username, + "confluence_access_token": access_token, + }, + ) + confluence_connector.set_credentials_provider(credentials_provider) + + start = 0.0 + end = datetime.now().timestamp() + + # Fetch all `SlimDocuments`. + for slim_doc in confluence_connector.retrieve_all_slim_docs_perm_sync(): + print(slim_doc) + + # Fetch all `Documents`. + for doc in load_all_docs_from_checkpoint_connector( + connector=confluence_connector, + start=start, + end=end, + ): + print(doc) diff --git a/common/data_source/discord_connector.py b/common/data_source/discord_connector.py new file mode 100644 index 00000000000..93a0477b078 --- /dev/null +++ b/common/data_source/discord_connector.py @@ -0,0 +1,340 @@ +"""Discord connector""" + +import asyncio +import logging +import os +from datetime import datetime, timezone +from typing import Any, AsyncIterable, Iterable + +from discord import Client, MessageType +from discord.channel import TextChannel, Thread +from discord.flags import Intents +from discord.message import Message as DiscordMessage + +from common.data_source.config import INDEX_BATCH_SIZE, DocumentSource +from common.data_source.exceptions import ConnectorMissingCredentialError +from common.data_source.interfaces import LoadConnector, PollConnector, SecondsSinceUnixEpoch +from common.data_source.models import Document, GenerateDocumentsOutput, TextSection + +_DISCORD_DOC_ID_PREFIX = "DISCORD_" +_SNIPPET_LENGTH = 30 + + +def _convert_message_to_document( + message: DiscordMessage, + sections: list[TextSection], +) -> Document: + """ + Convert a discord message to a document + Sections are collected before calling this function because it relies on async + calls to fetch the thread history if there is one + """ + + metadata: dict[str, str | list[str]] = {} + semantic_substring = "" + + # Only messages from TextChannels will make it here but we have to check for it anyways + if isinstance(message.channel, TextChannel) and (channel_name := message.channel.name): + metadata["Channel"] = channel_name + semantic_substring += f" in Channel: #{channel_name}" + + # If there is a thread, add more detail to the metadata, title, and semantic identifier + if isinstance(message.channel, Thread): + # Threads do have a title + title = message.channel.name + + # Add more detail to the semantic identifier if available + semantic_substring += f" in Thread: {title}" + + snippet: str = message.content[:_SNIPPET_LENGTH].rstrip() + "..." if len(message.content) > _SNIPPET_LENGTH else message.content + + semantic_identifier = f"{message.author.name} said{semantic_substring}: {snippet}" + + # fallback to created_at + doc_updated_at = message.edited_at if message.edited_at else message.created_at + if doc_updated_at and doc_updated_at.tzinfo is None: + doc_updated_at = doc_updated_at.replace(tzinfo=timezone.utc) + elif doc_updated_at: + doc_updated_at = doc_updated_at.astimezone(timezone.utc) + + return Document( + id=f"{_DISCORD_DOC_ID_PREFIX}{message.id}", + source=DocumentSource.DISCORD, + semantic_identifier=semantic_identifier, + doc_updated_at=doc_updated_at, + blob=message.content.encode("utf-8"), + extension=".txt", + size_bytes=len(message.content.encode("utf-8")), + ) + + +async def _fetch_filtered_channels( + discord_client: Client, + server_ids: list[int] | None, + channel_names: list[str] | None, +) -> list[TextChannel]: + filtered_channels: list[TextChannel] = [] + + for channel in discord_client.get_all_channels(): + if not channel.permissions_for(channel.guild.me).read_message_history: + continue + if not isinstance(channel, TextChannel): + continue + if server_ids and len(server_ids) > 0 and channel.guild.id not in server_ids: + continue + if channel_names and channel.name not in channel_names: + continue + filtered_channels.append(channel) + + logging.info(f"Found {len(filtered_channels)} channels for the authenticated user") + return filtered_channels + + +async def _fetch_documents_from_channel( + channel: TextChannel, + start_time: datetime | None, + end_time: datetime | None, +) -> AsyncIterable[Document]: + # Discord's epoch starts at 2015-01-01 + discord_epoch = datetime(2015, 1, 1, tzinfo=timezone.utc) + if start_time and start_time < discord_epoch: + start_time = discord_epoch + + # NOTE: limit=None is the correct way to fetch all messages and threads with pagination + # The discord package erroneously uses limit for both pagination AND number of results + # This causes the history and archived_threads methods to return 100 results even if there are more results within the filters + # Pagination is handled automatically (100 results at a time) when limit=None + + async for channel_message in channel.history( + limit=None, + after=start_time, + before=end_time, + ): + # Skip messages that are not the default type + if channel_message.type != MessageType.default: + continue + + sections: list[TextSection] = [ + TextSection( + text=channel_message.content, + link=channel_message.jump_url, + ) + ] + + yield _convert_message_to_document(channel_message, sections) + + for active_thread in channel.threads: + async for thread_message in active_thread.history( + limit=None, + after=start_time, + before=end_time, + ): + # Skip messages that are not the default type + if thread_message.type != MessageType.default: + continue + + sections = [ + TextSection( + text=thread_message.content, + link=thread_message.jump_url, + ) + ] + + yield _convert_message_to_document(thread_message, sections) + + async for archived_thread in channel.archived_threads( + limit=None, + ): + async for thread_message in archived_thread.history( + limit=None, + after=start_time, + before=end_time, + ): + # Skip messages that are not the default type + if thread_message.type != MessageType.default: + continue + + sections = [ + TextSection( + text=thread_message.content, + link=thread_message.jump_url, + ) + ] + + yield _convert_message_to_document(thread_message, sections) + + +def _manage_async_retrieval( + token: str, + requested_start_date_string: str, + channel_names: list[str], + server_ids: list[int], + start: datetime | None = None, + end: datetime | None = None, +) -> Iterable[Document]: + # parse requested_start_date_string to datetime + pull_date: datetime | None = datetime.strptime(requested_start_date_string, "%Y-%m-%d").replace(tzinfo=timezone.utc) if requested_start_date_string else None + + # Set start_time to the later of start and pull_date, or whichever is provided + start_time = max(filter(None, [start, pull_date])) if start or pull_date else None + + end_time: datetime | None = end + proxy_url: str | None = os.environ.get("https_proxy") or os.environ.get("http_proxy") + if proxy_url: + logging.info(f"Using proxy for Discord: {proxy_url}") + + async def _async_fetch() -> AsyncIterable[Document]: + intents = Intents.default() + intents.message_content = True + async with Client(intents=intents, proxy=proxy_url) as cli: + asyncio.create_task(coro=cli.start(token)) + await cli.wait_until_ready() + + filtered_channels: list[TextChannel] = await _fetch_filtered_channels( + discord_client=cli, + server_ids=server_ids, + channel_names=channel_names, + ) + + for channel in filtered_channels: + async for doc in _fetch_documents_from_channel( + channel=channel, + start_time=start_time, + end_time=end_time, + ): + print(doc) + yield doc + + def run_and_yield() -> Iterable[Document]: + loop = asyncio.new_event_loop() + try: + # Get the async generator + async_gen = _async_fetch() + # Convert to AsyncIterator + async_iter = async_gen.__aiter__() + while True: + try: + # Create a coroutine by calling anext with the async iterator + next_coro = anext(async_iter) + # Run the coroutine to get the next document + doc = loop.run_until_complete(next_coro) + yield doc + except StopAsyncIteration: + break + finally: + loop.close() + + return run_and_yield() + + +class DiscordConnector(LoadConnector, PollConnector): + """Discord connector for accessing Discord messages and channels""" + + def __init__( + self, + server_ids: list[str] = [], + channel_names: list[str] = [], + # YYYY-MM-DD + start_date: str | None = None, + batch_size: int = INDEX_BATCH_SIZE, + ): + self.batch_size = batch_size + self.channel_names: list[str] = channel_names if channel_names else [] + self.server_ids: list[int] = [int(server_id) for server_id in server_ids] if server_ids else [] + self._discord_bot_token: str | None = None + self.requested_start_date_string: str = start_date or "" + + @property + def discord_bot_token(self) -> str: + if self._discord_bot_token is None: + raise ConnectorMissingCredentialError("Discord") + return self._discord_bot_token + + def _manage_doc_batching( + self, + start: datetime | None = None, + end: datetime | None = None, + ) -> GenerateDocumentsOutput: + doc_batch = [] + def merge_batch(): + nonlocal doc_batch + id = doc_batch[0].id + min_updated_at = doc_batch[0].doc_updated_at + max_updated_at = doc_batch[-1].doc_updated_at + blob = b'' + size_bytes = 0 + for d in doc_batch: + min_updated_at = min(min_updated_at, d.doc_updated_at) + max_updated_at = max(max_updated_at, d.doc_updated_at) + blob += b'\n\n' + d.blob + size_bytes += d.size_bytes + + return Document( + id=id, + source=DocumentSource.DISCORD, + semantic_identifier=f"{min_updated_at} -> {max_updated_at}", + doc_updated_at=max_updated_at, + blob=blob, + extension=".txt", + size_bytes=size_bytes, + ) + + for doc in _manage_async_retrieval( + token=self.discord_bot_token, + requested_start_date_string=self.requested_start_date_string, + channel_names=self.channel_names, + server_ids=self.server_ids, + start=start, + end=end, + ): + doc_batch.append(doc) + if len(doc_batch) >= self.batch_size: + yield [merge_batch()] + doc_batch = [] + + if doc_batch: + yield [merge_batch()] + + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: + self._discord_bot_token = credentials["discord_bot_token"] + return None + + def validate_connector_settings(self) -> None: + """Validate Discord connector settings""" + if not self.discord_client: + raise ConnectorMissingCredentialError("Discord") + + def poll_source(self, start: SecondsSinceUnixEpoch, end: SecondsSinceUnixEpoch) -> Any: + """Poll Discord for recent messages""" + return self._manage_doc_batching( + datetime.fromtimestamp(start, tz=timezone.utc), + datetime.fromtimestamp(end, tz=timezone.utc), + ) + + def load_from_state(self) -> Any: + """Load messages from Discord state""" + return self._manage_doc_batching(None, None) + + +if __name__ == "__main__": + import os + import time + + end = time.time() + # 1 day + start = end - 24 * 60 * 60 * 1 + # "1,2,3" + server_ids: str | None = os.environ.get("server_ids", None) + # "channel1,channel2" + channel_names: str | None = os.environ.get("channel_names", None) + + connector = DiscordConnector( + server_ids=server_ids.split(",") if server_ids else [], + channel_names=channel_names.split(",") if channel_names else [], + start_date=os.environ.get("start_date", None), + ) + connector.load_credentials({"discord_bot_token": os.environ.get("discord_bot_token")}) + + for doc_batch in connector.poll_source(start, end): + for doc in doc_batch: + print(doc) diff --git a/common/data_source/dropbox_connector.py b/common/data_source/dropbox_connector.py new file mode 100644 index 00000000000..fd349baa111 --- /dev/null +++ b/common/data_source/dropbox_connector.py @@ -0,0 +1,79 @@ +"""Dropbox connector""" + +from typing import Any + +from dropbox import Dropbox +from dropbox.exceptions import ApiError, AuthError + +from common.data_source.config import INDEX_BATCH_SIZE +from common.data_source.exceptions import ConnectorValidationError, InsufficientPermissionsError, ConnectorMissingCredentialError +from common.data_source.interfaces import LoadConnector, PollConnector, SecondsSinceUnixEpoch + + +class DropboxConnector(LoadConnector, PollConnector): + """Dropbox connector for accessing Dropbox files and folders""" + + def __init__(self, batch_size: int = INDEX_BATCH_SIZE) -> None: + self.batch_size = batch_size + self.dropbox_client: Dropbox | None = None + + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: + """Load Dropbox credentials""" + try: + access_token = credentials.get("dropbox_access_token") + if not access_token: + raise ConnectorMissingCredentialError("Dropbox access token is required") + + self.dropbox_client = Dropbox(access_token) + return None + except Exception as e: + raise ConnectorMissingCredentialError(f"Dropbox: {e}") + + def validate_connector_settings(self) -> None: + """Validate Dropbox connector settings""" + if not self.dropbox_client: + raise ConnectorMissingCredentialError("Dropbox") + + try: + # Test connection by getting current account info + self.dropbox_client.users_get_current_account() + except (AuthError, ApiError) as e: + if "invalid_access_token" in str(e).lower(): + raise InsufficientPermissionsError("Invalid Dropbox access token") + else: + raise ConnectorValidationError(f"Dropbox validation error: {e}") + + def _download_file(self, path: str) -> bytes: + """Download a single file from Dropbox.""" + if self.dropbox_client is None: + raise ConnectorMissingCredentialError("Dropbox") + _, resp = self.dropbox_client.files_download(path) + return resp.content + + def _get_shared_link(self, path: str) -> str: + """Create a shared link for a file in Dropbox.""" + if self.dropbox_client is None: + raise ConnectorMissingCredentialError("Dropbox") + + try: + # Try to get existing shared links first + shared_links = self.dropbox_client.sharing_list_shared_links(path=path) + if shared_links.links: + return shared_links.links[0].url + + # Create a new shared link + link_settings = self.dropbox_client.sharing_create_shared_link_with_settings(path) + return link_settings.url + except Exception: + # Fallback to basic link format + return f"https://www.dropbox.com/home{path}" + + def poll_source(self, start: SecondsSinceUnixEpoch, end: SecondsSinceUnixEpoch) -> Any: + """Poll Dropbox for recent file changes""" + # Simplified implementation - in production this would handle actual polling + return [] + + def load_from_state(self) -> Any: + """Load files from Dropbox state""" + # Simplified implementation + return [] \ No newline at end of file diff --git a/common/data_source/exceptions.py b/common/data_source/exceptions.py new file mode 100644 index 00000000000..eeb60132bdf --- /dev/null +++ b/common/data_source/exceptions.py @@ -0,0 +1,30 @@ +"""Exception class definitions""" + + +class ConnectorMissingCredentialError(Exception): + """Missing credentials exception""" + def __init__(self, connector_name: str): + super().__init__(f"Missing credentials for {connector_name}") + + +class ConnectorValidationError(Exception): + """Connector validation exception""" + pass + + +class CredentialExpiredError(Exception): + """Credential expired exception""" + pass + + +class InsufficientPermissionsError(Exception): + """Insufficient permissions exception""" + pass + + +class UnexpectedValidationError(Exception): + """Unexpected validation exception""" + pass + +class RateLimitTriedTooManyTimesError(Exception): + pass \ No newline at end of file diff --git a/common/data_source/file_types.py b/common/data_source/file_types.py new file mode 100644 index 00000000000..bf7eafaaaba --- /dev/null +++ b/common/data_source/file_types.py @@ -0,0 +1,39 @@ +PRESENTATION_MIME_TYPE = ( + "application/vnd.openxmlformats-officedocument.presentationml.presentation" +) + +SPREADSHEET_MIME_TYPE = ( + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" +) +WORD_PROCESSING_MIME_TYPE = ( + "application/vnd.openxmlformats-officedocument.wordprocessingml.document" +) +PDF_MIME_TYPE = "application/pdf" + + +class UploadMimeTypes: + IMAGE_MIME_TYPES = {"image/jpeg", "image/png", "image/webp"} + CSV_MIME_TYPES = {"text/csv"} + TEXT_MIME_TYPES = { + "text/plain", + "text/markdown", + "text/x-markdown", + "text/x-config", + "text/tab-separated-values", + "application/json", + "application/xml", + "text/xml", + "application/x-yaml", + } + DOCUMENT_MIME_TYPES = { + PDF_MIME_TYPE, + WORD_PROCESSING_MIME_TYPE, + PRESENTATION_MIME_TYPE, + SPREADSHEET_MIME_TYPE, + "message/rfc822", + "application/epub+zip", + } + + ALLOWED_MIME_TYPES = IMAGE_MIME_TYPES.union( + TEXT_MIME_TYPES, DOCUMENT_MIME_TYPES, CSV_MIME_TYPES + ) diff --git a/common/data_source/gmail_connector.py b/common/data_source/gmail_connector.py new file mode 100644 index 00000000000..67ebfae989a --- /dev/null +++ b/common/data_source/gmail_connector.py @@ -0,0 +1,313 @@ +import logging +from typing import Any + +from google.oauth2.credentials import Credentials as OAuthCredentials +from google.oauth2.service_account import Credentials as ServiceAccountCredentials +from googleapiclient.errors import HttpError + +from common.data_source.config import INDEX_BATCH_SIZE, SLIM_BATCH_SIZE, DocumentSource +from common.data_source.google_util.auth import get_google_creds +from common.data_source.google_util.constant import DB_CREDENTIALS_PRIMARY_ADMIN_KEY, MISSING_SCOPES_ERROR_STR, SCOPE_INSTRUCTIONS, USER_FIELDS +from common.data_source.google_util.resource import get_admin_service, get_gmail_service +from common.data_source.google_util.util import _execute_single_retrieval, execute_paginated_retrieval +from common.data_source.interfaces import LoadConnector, PollConnector, SecondsSinceUnixEpoch, SlimConnectorWithPermSync +from common.data_source.models import BasicExpertInfo, Document, ExternalAccess, GenerateDocumentsOutput, GenerateSlimDocumentOutput, SlimDocument, TextSection +from common.data_source.utils import build_time_range_query, clean_email_and_extract_name, get_message_body, is_mail_service_disabled_error, time_str_to_utc + +# Constants for Gmail API fields +THREAD_LIST_FIELDS = "nextPageToken, threads(id)" +PARTS_FIELDS = "parts(body(data), mimeType)" +PAYLOAD_FIELDS = f"payload(headers, {PARTS_FIELDS})" +MESSAGES_FIELDS = f"messages(id, {PAYLOAD_FIELDS})" +THREADS_FIELDS = f"threads(id, {MESSAGES_FIELDS})" +THREAD_FIELDS = f"id, {MESSAGES_FIELDS}" + +EMAIL_FIELDS = ["cc", "bcc", "from", "to"] + + +def _get_owners_from_emails(emails: dict[str, str | None]) -> list[BasicExpertInfo]: + """Convert email dictionary to list of BasicExpertInfo objects.""" + owners = [] + for email, names in emails.items(): + if names: + name_parts = names.split(" ") + first_name = " ".join(name_parts[:-1]) + last_name = name_parts[-1] + else: + first_name = None + last_name = None + owners.append(BasicExpertInfo(email=email, first_name=first_name, last_name=last_name)) + return owners + + +def message_to_section(message: dict[str, Any]) -> tuple[TextSection, dict[str, str]]: + """Convert Gmail message to text section and metadata.""" + link = f"https://mail.google.com/mail/u/0/#inbox/{message['id']}" + + payload = message.get("payload", {}) + headers = payload.get("headers", []) + metadata: dict[str, Any] = {} + + for header in headers: + name = header.get("name", "").lower() + value = header.get("value", "") + if name in EMAIL_FIELDS: + metadata[name] = value + if name == "subject": + metadata["subject"] = value + if name == "date": + metadata["updated_at"] = value + + if labels := message.get("labelIds"): + metadata["labels"] = labels + + message_data = "" + for name, value in metadata.items(): + if name != "updated_at": + message_data += f"{name}: {value}\n" + + message_body_text: str = get_message_body(payload) + + return TextSection(link=link, text=message_body_text + message_data), metadata + + +def thread_to_document(full_thread: dict[str, Any], email_used_to_fetch_thread: str) -> Document | None: + """Convert Gmail thread to Document object.""" + all_messages = full_thread.get("messages", []) + if not all_messages: + return None + + sections = [] + semantic_identifier = "" + updated_at = None + from_emails: dict[str, str | None] = {} + other_emails: dict[str, str | None] = {} + + for message in all_messages: + section, message_metadata = message_to_section(message) + sections.append(section) + + for name, value in message_metadata.items(): + if name in EMAIL_FIELDS: + email, display_name = clean_email_and_extract_name(value) + if name == "from": + from_emails[email] = display_name if not from_emails.get(email) else None + else: + other_emails[email] = display_name if not other_emails.get(email) else None + + if not semantic_identifier: + semantic_identifier = message_metadata.get("subject", "") + + if message_metadata.get("updated_at"): + updated_at = message_metadata.get("updated_at") + + updated_at_datetime = None + if updated_at: + updated_at_datetime = time_str_to_utc(updated_at) + + thread_id = full_thread.get("id") + if not thread_id: + raise ValueError("Thread ID is required") + + primary_owners = _get_owners_from_emails(from_emails) + secondary_owners = _get_owners_from_emails(other_emails) + + if not semantic_identifier: + semantic_identifier = "(no subject)" + + return Document( + id=thread_id, + semantic_identifier=semantic_identifier, + sections=sections, + source=DocumentSource.GMAIL, + primary_owners=primary_owners, + secondary_owners=secondary_owners, + doc_updated_at=updated_at_datetime, + metadata={}, + external_access=ExternalAccess( + external_user_emails={email_used_to_fetch_thread}, + external_user_group_ids=set(), + is_public=False, + ), + ) + + +class GmailConnector(LoadConnector, PollConnector, SlimConnectorWithPermSync): + """Gmail connector for synchronizing emails from Gmail accounts.""" + + def __init__(self, batch_size: int = INDEX_BATCH_SIZE) -> None: + self.batch_size = batch_size + self._creds: OAuthCredentials | ServiceAccountCredentials | None = None + self._primary_admin_email: str | None = None + + @property + def primary_admin_email(self) -> str: + """Get primary admin email.""" + if self._primary_admin_email is None: + raise RuntimeError("Primary admin email missing, should not call this property before calling load_credentials") + return self._primary_admin_email + + @property + def google_domain(self) -> str: + """Get Google domain from email.""" + if self._primary_admin_email is None: + raise RuntimeError("Primary admin email missing, should not call this property before calling load_credentials") + return self._primary_admin_email.split("@")[-1] + + @property + def creds(self) -> OAuthCredentials | ServiceAccountCredentials: + """Get Google credentials.""" + if self._creds is None: + raise RuntimeError("Creds missing, should not call this property before calling load_credentials") + return self._creds + + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, str] | None: + """Load Gmail credentials.""" + primary_admin_email = credentials[DB_CREDENTIALS_PRIMARY_ADMIN_KEY] + self._primary_admin_email = primary_admin_email + + self._creds, new_creds_dict = get_google_creds( + credentials=credentials, + source=DocumentSource.GMAIL, + ) + return new_creds_dict + + def _get_all_user_emails(self) -> list[str]: + """Get all user emails for Google Workspace domain.""" + try: + admin_service = get_admin_service(self.creds, self.primary_admin_email) + emails = [] + for user in execute_paginated_retrieval( + retrieval_function=admin_service.users().list, + list_key="users", + fields=USER_FIELDS, + domain=self.google_domain, + ): + if email := user.get("primaryEmail"): + emails.append(email) + return emails + except HttpError as e: + if e.resp.status == 404: + logging.warning("Received 404 from Admin SDK; this may indicate a personal Gmail account with no Workspace domain. Falling back to single user.") + return [self.primary_admin_email] + raise + except Exception: + raise + + def _fetch_threads( + self, + time_range_start: SecondsSinceUnixEpoch | None = None, + time_range_end: SecondsSinceUnixEpoch | None = None, + ) -> GenerateDocumentsOutput: + """Fetch Gmail threads within time range.""" + query = build_time_range_query(time_range_start, time_range_end) + doc_batch = [] + + for user_email in self._get_all_user_emails(): + gmail_service = get_gmail_service(self.creds, user_email) + try: + for thread in execute_paginated_retrieval( + retrieval_function=gmail_service.users().threads().list, + list_key="threads", + userId=user_email, + fields=THREAD_LIST_FIELDS, + q=query, + continue_on_404_or_403=True, + ): + full_threads = _execute_single_retrieval( + retrieval_function=gmail_service.users().threads().get, + list_key=None, + userId=user_email, + fields=THREAD_FIELDS, + id=thread["id"], + continue_on_404_or_403=True, + ) + full_thread = list(full_threads)[0] + doc = thread_to_document(full_thread, user_email) + if doc is None: + continue + + doc_batch.append(doc) + if len(doc_batch) > self.batch_size: + yield doc_batch + doc_batch = [] + except HttpError as e: + if is_mail_service_disabled_error(e): + logging.warning( + "Skipping Gmail sync for %s because the mailbox is disabled.", + user_email, + ) + continue + raise + + if doc_batch: + yield doc_batch + + def load_from_state(self) -> GenerateDocumentsOutput: + """Load all documents from Gmail.""" + try: + yield from self._fetch_threads() + except Exception as e: + if MISSING_SCOPES_ERROR_STR in str(e): + raise PermissionError(SCOPE_INSTRUCTIONS) from e + raise e + + def poll_source(self, start: SecondsSinceUnixEpoch, end: SecondsSinceUnixEpoch) -> GenerateDocumentsOutput: + """Poll Gmail for documents within time range.""" + try: + yield from self._fetch_threads(start, end) + except Exception as e: + if MISSING_SCOPES_ERROR_STR in str(e): + raise PermissionError(SCOPE_INSTRUCTIONS) from e + raise e + + def retrieve_all_slim_docs_perm_sync( + self, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + callback=None, + ) -> GenerateSlimDocumentOutput: + """Retrieve slim documents for permission synchronization.""" + query = build_time_range_query(start, end) + doc_batch = [] + + for user_email in self._get_all_user_emails(): + logging.info(f"Fetching slim threads for user: {user_email}") + gmail_service = get_gmail_service(self.creds, user_email) + try: + for thread in execute_paginated_retrieval( + retrieval_function=gmail_service.users().threads().list, + list_key="threads", + userId=user_email, + fields=THREAD_LIST_FIELDS, + q=query, + continue_on_404_or_403=True, + ): + doc_batch.append( + SlimDocument( + id=thread["id"], + external_access=ExternalAccess( + external_user_emails={user_email}, + external_user_group_ids=set(), + is_public=False, + ), + ) + ) + if len(doc_batch) > SLIM_BATCH_SIZE: + yield doc_batch + doc_batch = [] + except HttpError as e: + if is_mail_service_disabled_error(e): + logging.warning( + "Skipping slim Gmail sync for %s because the mailbox is disabled.", + user_email, + ) + continue + raise + + if doc_batch: + yield doc_batch + + +if __name__ == "__main__": + pass diff --git a/web/src/pages/flow/hooks/use-iteration.ts b/common/data_source/google_drive/__init__.py similarity index 100% rename from web/src/pages/flow/hooks/use-iteration.ts rename to common/data_source/google_drive/__init__.py diff --git a/common/data_source/google_drive/connector.py b/common/data_source/google_drive/connector.py new file mode 100644 index 00000000000..fb88d0ed050 --- /dev/null +++ b/common/data_source/google_drive/connector.py @@ -0,0 +1,1292 @@ +"""Google Drive connector""" + +import copy +import json +import logging +import os +import sys +import threading +from collections.abc import Callable, Generator, Iterator +from enum import Enum +from functools import partial +from typing import Any, Protocol, cast +from urllib.parse import urlparse + +from google.auth.exceptions import RefreshError # type: ignore # type: ignore +from google.oauth2.credentials import Credentials as OAuthCredentials # type: ignore # type: ignore # type: ignore +from google.oauth2.service_account import Credentials as ServiceAccountCredentials # type: ignore # type: ignore +from googleapiclient.errors import HttpError # type: ignore # type: ignore +from typing_extensions import override + +from common.data_source.config import GOOGLE_DRIVE_CONNECTOR_SIZE_THRESHOLD, INDEX_BATCH_SIZE, SLIM_BATCH_SIZE, DocumentSource +from common.data_source.exceptions import ConnectorMissingCredentialError, ConnectorValidationError, CredentialExpiredError, InsufficientPermissionsError +from common.data_source.google_drive.doc_conversion import PermissionSyncContext, build_slim_document, convert_drive_item_to_document, onyx_document_id_from_drive_file +from common.data_source.google_drive.file_retrieval import ( + DriveFileFieldType, + crawl_folders_for_files, + get_all_files_for_oauth, + get_all_files_in_my_drive_and_shared, + get_files_in_shared_drive, + get_root_folder_id, +) +from common.data_source.google_drive.model import DriveRetrievalStage, GoogleDriveCheckpoint, GoogleDriveFileType, RetrievedDriveFile, StageCompletion +from common.data_source.google_util.auth import get_google_creds +from common.data_source.google_util.constant import DB_CREDENTIALS_PRIMARY_ADMIN_KEY, MISSING_SCOPES_ERROR_STR, USER_FIELDS +from common.data_source.google_util.oauth_flow import ensure_oauth_token_dict +from common.data_source.google_util.resource import GoogleDriveService, get_admin_service, get_drive_service +from common.data_source.google_util.util import GoogleFields, execute_paginated_retrieval, get_file_owners +from common.data_source.google_util.util_threadpool_concurrency import ThreadSafeDict +from common.data_source.interfaces import ( + CheckpointedConnectorWithPermSync, + IndexingHeartbeatInterface, + SlimConnectorWithPermSync, +) +from common.data_source.models import CheckpointOutput, ConnectorFailure, Document, EntityFailure, GenerateSlimDocumentOutput, SecondsSinceUnixEpoch +from common.data_source.utils import datetime_from_string, parallel_yield, run_functions_tuples_in_parallel + +MAX_DRIVE_WORKERS = int(os.environ.get("MAX_DRIVE_WORKERS", 4)) +SHARED_DRIVE_PAGES_PER_CHECKPOINT = 2 +MY_DRIVE_PAGES_PER_CHECKPOINT = 2 +OAUTH_PAGES_PER_CHECKPOINT = 2 +FOLDERS_PER_CHECKPOINT = 1 + + +def _extract_str_list_from_comma_str(string: str | None) -> list[str]: + if not string: + return [] + return [s.strip() for s in string.split(",") if s.strip()] + + +def _extract_ids_from_urls(urls: list[str]) -> list[str]: + return [urlparse(url).path.strip("/").split("/")[-1] for url in urls] + + +def _clean_requested_drive_ids( + requested_drive_ids: set[str], + requested_folder_ids: set[str], + all_drive_ids_available: set[str], +) -> tuple[list[str], list[str]]: + invalid_requested_drive_ids = requested_drive_ids - all_drive_ids_available + filtered_folder_ids = requested_folder_ids - all_drive_ids_available + if invalid_requested_drive_ids: + logging.warning(f"Some shared drive IDs were not found. IDs: {invalid_requested_drive_ids}") + logging.warning("Checking for folder access instead...") + filtered_folder_ids.update(invalid_requested_drive_ids) + + valid_requested_drive_ids = requested_drive_ids - invalid_requested_drive_ids + return sorted(valid_requested_drive_ids), sorted(filtered_folder_ids) + + +def add_retrieval_info( + drive_files: Iterator[GoogleDriveFileType | str], + user_email: str, + completion_stage: DriveRetrievalStage, + parent_id: str | None = None, +) -> Iterator[RetrievedDriveFile | str]: + for file in drive_files: + if isinstance(file, str): + yield file + continue + yield RetrievedDriveFile( + drive_file=file, + user_email=user_email, + parent_id=parent_id, + completion_stage=completion_stage, + ) + + +class CredentialedRetrievalMethod(Protocol): + def __call__( + self, + field_type: DriveFileFieldType, + checkpoint: GoogleDriveCheckpoint, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> Iterator[RetrievedDriveFile]: ... + + +class DriveIdStatus(str, Enum): + AVAILABLE = "available" + IN_PROGRESS = "in_progress" + FINISHED = "finished" + + +class GoogleDriveConnector(SlimConnectorWithPermSync, CheckpointedConnectorWithPermSync): + def __init__( + self, + include_shared_drives: bool = False, + include_my_drives: bool = False, + include_files_shared_with_me: bool = False, + shared_drive_urls: str | None = None, + my_drive_emails: str | None = None, + shared_folder_urls: str | None = None, + specific_user_emails: str | None = None, + batch_size: int = INDEX_BATCH_SIZE, + ) -> None: + if not any( + ( + include_shared_drives, + include_my_drives, + include_files_shared_with_me, + shared_folder_urls, + my_drive_emails, + shared_drive_urls, + ) + ): + raise ConnectorValidationError( + "Nothing to index. Please specify at least one of the following: include_shared_drives, include_my_drives, include_files_shared_with_me, shared_folder_urls, or my_drive_emails" + ) + + specific_requests_made = False + if bool(shared_drive_urls) or bool(my_drive_emails) or bool(shared_folder_urls): + specific_requests_made = True + self.specific_requests_made = specific_requests_made + + # NOTE: potentially modified in load_credentials if using service account + self.include_files_shared_with_me = False if specific_requests_made else include_files_shared_with_me + self.include_my_drives = False if specific_requests_made else include_my_drives + self.include_shared_drives = False if specific_requests_made else include_shared_drives + + shared_drive_url_list = _extract_str_list_from_comma_str(shared_drive_urls) + self._requested_shared_drive_ids = set(_extract_ids_from_urls(shared_drive_url_list)) + + self._requested_my_drive_emails = set(_extract_str_list_from_comma_str(my_drive_emails)) + + shared_folder_url_list = _extract_str_list_from_comma_str(shared_folder_urls) + self._requested_folder_ids = set(_extract_ids_from_urls(shared_folder_url_list)) + self._specific_user_emails = _extract_str_list_from_comma_str(specific_user_emails) + + self._primary_admin_email: str | None = None + + self._creds: OAuthCredentials | ServiceAccountCredentials | None = None + self._creds_dict: dict[str, Any] | None = None + + # ids of folders and shared drives that have been traversed + self._retrieved_folder_and_drive_ids: set[str] = set() + + self.allow_images = False + + self.size_threshold = GOOGLE_DRIVE_CONNECTOR_SIZE_THRESHOLD + + self.logger = logging.getLogger(self.__class__.__name__) + + def set_allow_images(self, value: bool) -> None: + self.allow_images = value + + @property + def primary_admin_email(self) -> str: + if self._primary_admin_email is None: + raise RuntimeError("Primary admin email missing, should not call this property before calling load_credentials") + return self._primary_admin_email + + @property + def google_domain(self) -> str: + if self._primary_admin_email is None: + raise RuntimeError("Primary admin email missing, should not call this property before calling load_credentials") + return self._primary_admin_email.split("@")[-1] + + @property + def creds(self) -> OAuthCredentials | ServiceAccountCredentials: + if self._creds is None: + raise RuntimeError("Creds missing, should not call this property before calling load_credentials") + return self._creds + + # TODO: ensure returned new_creds_dict is actually persisted when this is called? + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: + try: + self._primary_admin_email = credentials[DB_CREDENTIALS_PRIMARY_ADMIN_KEY] + except KeyError: + raise ValueError("Credentials json missing primary admin key") + + self._creds, new_creds_dict = get_google_creds( + credentials=credentials, + source=DocumentSource.GOOGLE_DRIVE, + ) + + # Service account connectors don't have a specific setting determining whether + # to include "shared with me" for each user, so we default to true unless the connector + # is in specific folders/drives mode. Note that shared files are only picked up during + # the My Drive stage, so this does nothing if the connector is set to only index shared drives. + if isinstance(self._creds, ServiceAccountCredentials) and not self.specific_requests_made: + self.include_files_shared_with_me = True + + self._creds_dict = new_creds_dict + + return new_creds_dict + + def _update_traversed_parent_ids(self, folder_id: str) -> None: + self._retrieved_folder_and_drive_ids.add(folder_id) + + def _get_all_user_emails(self) -> list[str]: + if self._specific_user_emails: + return self._specific_user_emails + + # Start with primary admin email + user_emails = [self.primary_admin_email] + + # Only fetch additional users if using service account + if isinstance(self.creds, OAuthCredentials): + return user_emails + + admin_service = get_admin_service( + creds=self.creds, + user_email=self.primary_admin_email, + ) + + # Get admins first since they're more likely to have access to most files + for is_admin in [True, False]: + query = "isAdmin=true" if is_admin else "isAdmin=false" + for user in execute_paginated_retrieval( + retrieval_function=admin_service.users().list, + list_key="users", + fields=USER_FIELDS, + domain=self.google_domain, + query=query, + ): + if email := user.get("primaryEmail"): + if email not in user_emails: + user_emails.append(email) + return user_emails + + def get_all_drive_ids(self) -> set[str]: + return self._get_all_drives_for_user(self.primary_admin_email) + + def _get_all_drives_for_user(self, user_email: str) -> set[str]: + drive_service = get_drive_service(self.creds, user_email) + is_service_account = isinstance(self.creds, ServiceAccountCredentials) + self.logger.info(f"Getting all drives for user {user_email} with service account: {is_service_account}") + all_drive_ids: set[str] = set() + for drive in execute_paginated_retrieval( + retrieval_function=drive_service.drives().list, + list_key="drives", + useDomainAdminAccess=is_service_account, + fields="drives(id),nextPageToken", + ): + all_drive_ids.add(drive["id"]) + + if not all_drive_ids: + self.logger.warning("No drives found even though indexing shared drives was requested.") + + return all_drive_ids + + def make_drive_id_getter(self, drive_ids: list[str], checkpoint: GoogleDriveCheckpoint) -> Callable[[str], str | None]: + status_lock = threading.Lock() + + in_progress_drive_ids = { + completion.current_folder_or_drive_id: user_email + for user_email, completion in checkpoint.completion_map.items() + if completion.stage == DriveRetrievalStage.SHARED_DRIVE_FILES and completion.current_folder_or_drive_id is not None + } + drive_id_status: dict[str, DriveIdStatus] = {} + for drive_id in drive_ids: + if drive_id in self._retrieved_folder_and_drive_ids: + drive_id_status[drive_id] = DriveIdStatus.FINISHED + elif drive_id in in_progress_drive_ids: + drive_id_status[drive_id] = DriveIdStatus.IN_PROGRESS + else: + drive_id_status[drive_id] = DriveIdStatus.AVAILABLE + + def get_available_drive_id(thread_id: str) -> str | None: + completion = checkpoint.completion_map[thread_id] + with status_lock: + future_work = None + for drive_id, status in drive_id_status.items(): + if drive_id in self._retrieved_folder_and_drive_ids: + drive_id_status[drive_id] = DriveIdStatus.FINISHED + continue + if drive_id in completion.processed_drive_ids: + continue + + if status == DriveIdStatus.AVAILABLE: + # add to processed drive ids so if this user fails to retrieve once + # they won't try again on the next checkpoint run + completion.processed_drive_ids.add(drive_id) + return drive_id + elif status == DriveIdStatus.IN_PROGRESS: + self.logger.debug(f"Drive id in progress: {drive_id}") + future_work = drive_id + + if future_work: + # in this case, all drive ids are either finished or in progress. + # This thread will pick up one of the in progress ones in case it fails. + # This is a much simpler approach than waiting for a failure picking it up, + # at the cost of some repeated work until all shared drives are retrieved. + # we avoid apocalyptic cases like all threads focusing on one huge drive + # because the drive id is added to _retrieved_folder_and_drive_ids after any thread + # manages to retrieve any file from it (unfortunately, this is also the reason we currently + # sometimes fail to retrieve restricted access folders/files) + completion.processed_drive_ids.add(future_work) + return future_work + return None # no work available, return None + + return get_available_drive_id + + def _impersonate_user_for_retrieval( + self, + user_email: str, + field_type: DriveFileFieldType, + checkpoint: GoogleDriveCheckpoint, + get_new_drive_id: Callable[[str], str | None], + sorted_filtered_folder_ids: list[str], + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> Iterator[RetrievedDriveFile]: + self.logger.info(f"Impersonating user {user_email}") + curr_stage = checkpoint.completion_map[user_email] + resuming = True + if curr_stage.stage == DriveRetrievalStage.START: + self.logger.info(f"Setting stage to {DriveRetrievalStage.MY_DRIVE_FILES.value}") + curr_stage.stage = DriveRetrievalStage.MY_DRIVE_FILES + resuming = False + drive_service = get_drive_service(self.creds, user_email) + + # validate that the user has access to the drive APIs by performing a simple + # request and checking for a 401 + try: + self.logger.debug(f"Getting root folder id for user {user_email}") + get_root_folder_id(drive_service) + except HttpError as e: + if e.status_code == 401: + # fail gracefully, let the other impersonations continue + # one user without access shouldn't block the entire connector + self.logger.warning(f"User '{user_email}' does not have access to the drive APIs.") + # mark this user as done so we don't try to retrieve anything for them + # again + curr_stage.stage = DriveRetrievalStage.DONE + return + raise + except RefreshError as e: + self.logger.warning(f"User '{user_email}' could not refresh their token. Error: {e}") + # mark this user as done so we don't try to retrieve anything for them + # again + yield RetrievedDriveFile( + completion_stage=DriveRetrievalStage.DONE, + drive_file={}, + user_email=user_email, + error=e, + ) + curr_stage.stage = DriveRetrievalStage.DONE + return + # if we are including my drives, try to get the current user's my + # drive if any of the following are true: + # - include_my_drives is true + # - the current user's email is in the requested emails + if curr_stage.stage == DriveRetrievalStage.MY_DRIVE_FILES: + if self.include_my_drives or user_email in self._requested_my_drive_emails: + self.logger.info( + f"Getting all files in my drive as '{user_email}. Resuming: {resuming}. Stage completed until: {curr_stage.completed_until}. Next page token: {curr_stage.next_page_token}" + ) + + for file_or_token in add_retrieval_info( + get_all_files_in_my_drive_and_shared( + service=drive_service, + update_traversed_ids_func=self._update_traversed_parent_ids, + field_type=field_type, + include_shared_with_me=self.include_files_shared_with_me, + max_num_pages=MY_DRIVE_PAGES_PER_CHECKPOINT, + start=curr_stage.completed_until if resuming else start, + end=end, + cache_folders=not bool(curr_stage.completed_until), + page_token=curr_stage.next_page_token, + ), + user_email, + DriveRetrievalStage.MY_DRIVE_FILES, + ): + if isinstance(file_or_token, str): + self.logger.debug(f"Done with max num pages for user {user_email}") + checkpoint.completion_map[user_email].next_page_token = file_or_token + return # done with the max num pages, return checkpoint + yield file_or_token + + checkpoint.completion_map[user_email].next_page_token = None + curr_stage.stage = DriveRetrievalStage.SHARED_DRIVE_FILES + curr_stage.current_folder_or_drive_id = None + return # resume from next stage on the next run + + if curr_stage.stage == DriveRetrievalStage.SHARED_DRIVE_FILES: + + def _yield_from_drive(drive_id: str, drive_start: SecondsSinceUnixEpoch | None) -> Iterator[RetrievedDriveFile | str]: + yield from add_retrieval_info( + get_files_in_shared_drive( + service=drive_service, + drive_id=drive_id, + field_type=field_type, + max_num_pages=SHARED_DRIVE_PAGES_PER_CHECKPOINT, + update_traversed_ids_func=self._update_traversed_parent_ids, + cache_folders=not bool(drive_start), # only cache folders for 0 or None + start=drive_start, + end=end, + page_token=curr_stage.next_page_token, + ), + user_email, + DriveRetrievalStage.SHARED_DRIVE_FILES, + parent_id=drive_id, + ) + + # resume from a checkpoint + if resuming and (drive_id := curr_stage.current_folder_or_drive_id): + resume_start = curr_stage.completed_until + for file_or_token in _yield_from_drive(drive_id, resume_start): + if isinstance(file_or_token, str): + checkpoint.completion_map[user_email].next_page_token = file_or_token + return # done with the max num pages, return checkpoint + yield file_or_token + + drive_id = get_new_drive_id(user_email) + if drive_id: + self.logger.info(f"Getting files in shared drive '{drive_id}' as '{user_email}. Resuming: {resuming}") + curr_stage.completed_until = 0 + curr_stage.current_folder_or_drive_id = drive_id + for file_or_token in _yield_from_drive(drive_id, start): + if isinstance(file_or_token, str): + checkpoint.completion_map[user_email].next_page_token = file_or_token + return # done with the max num pages, return checkpoint + yield file_or_token + curr_stage.current_folder_or_drive_id = None + return # get a new drive id on the next run + + checkpoint.completion_map[user_email].next_page_token = None + curr_stage.stage = DriveRetrievalStage.FOLDER_FILES + curr_stage.current_folder_or_drive_id = None + return # resume from next stage on the next run + + # In the folder files section of service account retrieval we take extra care + # to not retrieve duplicate docs. In particular, we only add a folder to + # retrieved_folder_and_drive_ids when all users are finished retrieving files + # from that folder, and maintain a set of all file ids that have been retrieved + # for each folder. This might get rather large; in practice we assume that the + # specific folders users choose to index don't have too many files. + if curr_stage.stage == DriveRetrievalStage.FOLDER_FILES: + + def _yield_from_folder_crawl(folder_id: str, folder_start: SecondsSinceUnixEpoch | None) -> Iterator[RetrievedDriveFile]: + for retrieved_file in crawl_folders_for_files( + service=drive_service, + parent_id=folder_id, + field_type=field_type, + user_email=user_email, + traversed_parent_ids=self._retrieved_folder_and_drive_ids, + update_traversed_ids_func=self._update_traversed_parent_ids, + start=folder_start, + end=end, + ): + yield retrieved_file + + # resume from a checkpoint + last_processed_folder = None + if resuming: + folder_id = curr_stage.current_folder_or_drive_id + if folder_id is None: + self.logger.warning(f"folder id not set in checkpoint for user {user_email}. This happens occasionally when the connector is interrupted and resumed.") + else: + resume_start = curr_stage.completed_until + yield from _yield_from_folder_crawl(folder_id, resume_start) + last_processed_folder = folder_id + + skipping_seen_folders = last_processed_folder is not None + # NOTE: this assumes a small number of folders to crawl. If someone + # really wants to specify a large number of folders, we should use + # binary search to find the first unseen folder. + num_completed_folders = 0 + for folder_id in sorted_filtered_folder_ids: + if skipping_seen_folders: + skipping_seen_folders = folder_id != last_processed_folder + continue + + if folder_id in self._retrieved_folder_and_drive_ids: + continue + + curr_stage.completed_until = 0 + curr_stage.current_folder_or_drive_id = folder_id + + if num_completed_folders >= FOLDERS_PER_CHECKPOINT: + return # resume from this folder on the next run + + self.logger.info(f"Getting files in folder '{folder_id}' as '{user_email}'") + yield from _yield_from_folder_crawl(folder_id, start) + num_completed_folders += 1 + + curr_stage.stage = DriveRetrievalStage.DONE + + def _manage_service_account_retrieval( + self, + field_type: DriveFileFieldType, + checkpoint: GoogleDriveCheckpoint, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> Iterator[RetrievedDriveFile]: + """ + The current implementation of the service account retrieval does some + initial setup work using the primary admin email, then runs MAX_DRIVE_WORKERS + concurrent threads, each of which impersonates a different user and retrieves + files for that user. Technically, the actual work each thread does is "yield the + next file retrieved by the user", at which point it returns to the thread pool; + see parallel_yield for more details. + """ + if checkpoint.completion_stage == DriveRetrievalStage.START: + checkpoint.completion_stage = DriveRetrievalStage.USER_EMAILS + + if checkpoint.completion_stage == DriveRetrievalStage.USER_EMAILS: + all_org_emails: list[str] = self._get_all_user_emails() + checkpoint.user_emails = all_org_emails + checkpoint.completion_stage = DriveRetrievalStage.DRIVE_IDS + else: + if checkpoint.user_emails is None: + raise ValueError("user emails not set") + all_org_emails = checkpoint.user_emails + + sorted_drive_ids, sorted_folder_ids = self._determine_retrieval_ids(checkpoint, DriveRetrievalStage.MY_DRIVE_FILES) + + # Setup initial completion map on first connector run + for email in all_org_emails: + # don't overwrite existing completion map on resuming runs + if email in checkpoint.completion_map: + continue + checkpoint.completion_map[email] = StageCompletion( + stage=DriveRetrievalStage.START, + completed_until=0, + processed_drive_ids=set(), + ) + + # we've found all users and drives, now time to actually start + # fetching stuff + self.logger.info(f"Found {len(all_org_emails)} users to impersonate") + self.logger.debug(f"Users: {all_org_emails}") + self.logger.info(f"Found {len(sorted_drive_ids)} drives to retrieve") + self.logger.debug(f"Drives: {sorted_drive_ids}") + self.logger.info(f"Found {len(sorted_folder_ids)} folders to retrieve") + self.logger.debug(f"Folders: {sorted_folder_ids}") + + drive_id_getter = self.make_drive_id_getter(sorted_drive_ids, checkpoint) + + # only process emails that we haven't already completed retrieval for + non_completed_org_emails = [user_email for user_email, stage_completion in checkpoint.completion_map.items() if stage_completion.stage != DriveRetrievalStage.DONE] + + self.logger.debug(f"Non-completed users remaining: {len(non_completed_org_emails)}") + + # don't process too many emails before returning a checkpoint. This is + # to resolve the case where there are a ton of emails that don't have access + # to the drive APIs. Without this, we could loop through these emails for + # more than 3 hours, causing a timeout and stalling progress. + email_batch_takes_us_to_completion = True + MAX_EMAILS_TO_PROCESS_BEFORE_CHECKPOINTING = MAX_DRIVE_WORKERS + if len(non_completed_org_emails) > MAX_EMAILS_TO_PROCESS_BEFORE_CHECKPOINTING: + non_completed_org_emails = non_completed_org_emails[:MAX_EMAILS_TO_PROCESS_BEFORE_CHECKPOINTING] + email_batch_takes_us_to_completion = False + + user_retrieval_gens = [ + self._impersonate_user_for_retrieval( + email, + field_type, + checkpoint, + drive_id_getter, + sorted_folder_ids, + start, + end, + ) + for email in non_completed_org_emails + ] + yield from parallel_yield(user_retrieval_gens, max_workers=MAX_DRIVE_WORKERS) + + # if there are more emails to process, don't mark as complete + if not email_batch_takes_us_to_completion: + return + + remaining_folders = (set(sorted_drive_ids) | set(sorted_folder_ids)) - self._retrieved_folder_and_drive_ids + if remaining_folders: + self.logger.warning(f"Some folders/drives were not retrieved. IDs: {remaining_folders}") + if any(checkpoint.completion_map[user_email].stage != DriveRetrievalStage.DONE for user_email in all_org_emails): + self.logger.info("some users did not complete retrieval, returning checkpoint for another run") + return + checkpoint.completion_stage = DriveRetrievalStage.DONE + + def _determine_retrieval_ids( + self, + checkpoint: GoogleDriveCheckpoint, + next_stage: DriveRetrievalStage, + ) -> tuple[list[str], list[str]]: + all_drive_ids = self.get_all_drive_ids() + sorted_drive_ids: list[str] = [] + sorted_folder_ids: list[str] = [] + if checkpoint.completion_stage == DriveRetrievalStage.DRIVE_IDS: + if self._requested_shared_drive_ids or self._requested_folder_ids: + ( + sorted_drive_ids, + sorted_folder_ids, + ) = _clean_requested_drive_ids( + requested_drive_ids=self._requested_shared_drive_ids, + requested_folder_ids=self._requested_folder_ids, + all_drive_ids_available=all_drive_ids, + ) + elif self.include_shared_drives: + sorted_drive_ids = sorted(all_drive_ids) + + checkpoint.drive_ids_to_retrieve = sorted_drive_ids + checkpoint.folder_ids_to_retrieve = sorted_folder_ids + checkpoint.completion_stage = next_stage + else: + if checkpoint.drive_ids_to_retrieve is None: + raise ValueError("drive ids to retrieve not set in checkpoint") + if checkpoint.folder_ids_to_retrieve is None: + raise ValueError("folder ids to retrieve not set in checkpoint") + # When loading from a checkpoint, load the previously cached drive and folder ids + sorted_drive_ids = checkpoint.drive_ids_to_retrieve + sorted_folder_ids = checkpoint.folder_ids_to_retrieve + + return sorted_drive_ids, sorted_folder_ids + + def _oauth_retrieval_drives( + self, + field_type: DriveFileFieldType, + drive_service: GoogleDriveService, + drive_ids_to_retrieve: list[str], + checkpoint: GoogleDriveCheckpoint, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> Iterator[RetrievedDriveFile | str]: + def _yield_from_drive(drive_id: str, drive_start: SecondsSinceUnixEpoch | None) -> Iterator[RetrievedDriveFile | str]: + yield from add_retrieval_info( + get_files_in_shared_drive( + service=drive_service, + drive_id=drive_id, + field_type=field_type, + max_num_pages=SHARED_DRIVE_PAGES_PER_CHECKPOINT, + cache_folders=not bool(drive_start), # only cache folders for 0 or None + update_traversed_ids_func=self._update_traversed_parent_ids, + start=drive_start, + end=end, + page_token=checkpoint.completion_map[self.primary_admin_email].next_page_token, + ), + self.primary_admin_email, + DriveRetrievalStage.SHARED_DRIVE_FILES, + parent_id=drive_id, + ) + + # If we are resuming from a checkpoint, we need to finish retrieving the files from the last drive we retrieved + if checkpoint.completion_map[self.primary_admin_email].stage == DriveRetrievalStage.SHARED_DRIVE_FILES: + drive_id = checkpoint.completion_map[self.primary_admin_email].current_folder_or_drive_id + if drive_id is None: + raise ValueError("drive id not set in checkpoint") + resume_start = checkpoint.completion_map[self.primary_admin_email].completed_until + for file_or_token in _yield_from_drive(drive_id, resume_start): + if isinstance(file_or_token, str): + checkpoint.completion_map[self.primary_admin_email].next_page_token = file_or_token + return # done with the max num pages, return checkpoint + yield file_or_token + checkpoint.completion_map[self.primary_admin_email].next_page_token = None + + for drive_id in drive_ids_to_retrieve: + if drive_id in self._retrieved_folder_and_drive_ids: + self.logger.info(f"Skipping drive '{drive_id}' as it has already been retrieved") + continue + self.logger.info(f"Getting files in shared drive '{drive_id}' as '{self.primary_admin_email}'") + for file_or_token in _yield_from_drive(drive_id, start): + if isinstance(file_or_token, str): + checkpoint.completion_map[self.primary_admin_email].next_page_token = file_or_token + return # done with the max num pages, return checkpoint + yield file_or_token + checkpoint.completion_map[self.primary_admin_email].next_page_token = None + + def _oauth_retrieval_folders( + self, + field_type: DriveFileFieldType, + drive_service: GoogleDriveService, + drive_ids_to_retrieve: set[str], + folder_ids_to_retrieve: set[str], + checkpoint: GoogleDriveCheckpoint, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> Iterator[RetrievedDriveFile]: + """ + If there are any remaining folder ids to retrieve found earlier in the + retrieval process, we recursively descend the file tree and retrieve all + files in the folder(s). + """ + # Even if no folders were requested, we still check if any drives were requested + # that could be folders. + remaining_folders = folder_ids_to_retrieve - self._retrieved_folder_and_drive_ids + + def _yield_from_folder_crawl(folder_id: str, folder_start: SecondsSinceUnixEpoch | None) -> Iterator[RetrievedDriveFile]: + yield from crawl_folders_for_files( + service=drive_service, + parent_id=folder_id, + field_type=field_type, + user_email=self.primary_admin_email, + traversed_parent_ids=self._retrieved_folder_and_drive_ids, + update_traversed_ids_func=self._update_traversed_parent_ids, + start=folder_start, + end=end, + ) + + # resume from a checkpoint + # TODO: actually checkpoint folder retrieval. Since we moved towards returning from + # generator functions to indicate when a checkpoint should be returned, this code + # shouldn't be used currently. Unfortunately folder crawling is quite difficult to checkpoint + # effectively (likely need separate folder crawling and file retrieval stages), + # so we'll revisit this later. + if checkpoint.completion_map[self.primary_admin_email].stage == DriveRetrievalStage.FOLDER_FILES and ( + folder_id := checkpoint.completion_map[self.primary_admin_email].current_folder_or_drive_id + ): + resume_start = checkpoint.completion_map[self.primary_admin_email].completed_until + yield from _yield_from_folder_crawl(folder_id, resume_start) + + # the times stored in the completion_map aren't used due to the crawling behavior + # instead, the traversed_parent_ids are used to determine what we have left to retrieve + for folder_id in remaining_folders: + self.logger.info(f"Getting files in folder '{folder_id}' as '{self.primary_admin_email}'") + yield from _yield_from_folder_crawl(folder_id, start) + + remaining_folders = (drive_ids_to_retrieve | folder_ids_to_retrieve) - self._retrieved_folder_and_drive_ids + if remaining_folders: + self.logger.warning(f"Some folders/drives were not retrieved. IDs: {remaining_folders}") + + def _load_from_checkpoint( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: GoogleDriveCheckpoint, + include_permissions: bool, + ) -> CheckpointOutput: + """ + Entrypoint for the connector; first run is with an empty checkpoint. + """ + if self._creds is None or self._primary_admin_email is None: + raise RuntimeError("Credentials missing, should not call this method before calling load_credentials") + + self.logger.info(f"Loading from checkpoint with completion stage: {checkpoint.completion_stage},num retrieved ids: {len(checkpoint.all_retrieved_file_ids)}") + checkpoint = copy.deepcopy(checkpoint) + self._retrieved_folder_and_drive_ids = checkpoint.retrieved_folder_and_drive_ids + try: + yield from self._extract_docs_from_google_drive(checkpoint, start, end, include_permissions) + except Exception as e: + if MISSING_SCOPES_ERROR_STR in str(e): + raise PermissionError() from e + raise e + checkpoint.retrieved_folder_and_drive_ids = self._retrieved_folder_and_drive_ids + + self.logger.info(f"num drive files retrieved: {len(checkpoint.all_retrieved_file_ids)}") + if checkpoint.completion_stage == DriveRetrievalStage.DONE: + checkpoint.has_more = False + return checkpoint + + def _checkpointed_retrieval( + self, + retrieval_method: CredentialedRetrievalMethod, + field_type: DriveFileFieldType, + checkpoint: GoogleDriveCheckpoint, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> Iterator[RetrievedDriveFile]: + drive_files = retrieval_method( + field_type=field_type, + checkpoint=checkpoint, + start=start, + end=end, + ) + + for file in drive_files: + document_id = onyx_document_id_from_drive_file(file.drive_file) + logging.debug(f"Updating checkpoint for file: {file.drive_file.get('name')}. Seen: {document_id in checkpoint.all_retrieved_file_ids}") + checkpoint.completion_map[file.user_email].update( + stage=file.completion_stage, + completed_until=datetime_from_string(file.drive_file[GoogleFields.MODIFIED_TIME.value]).timestamp(), + current_folder_or_drive_id=file.parent_id, + ) + if document_id not in checkpoint.all_retrieved_file_ids: + checkpoint.all_retrieved_file_ids.add(document_id) + yield file + + def _oauth_retrieval_all_files( + self, + field_type: DriveFileFieldType, + drive_service: GoogleDriveService, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + page_token: str | None = None, + ) -> Iterator[RetrievedDriveFile | str]: + if not self.include_files_shared_with_me and not self.include_my_drives: + return + + self.logger.info( + f"Getting shared files/my drive files for OAuth " + f"with include_files_shared_with_me={self.include_files_shared_with_me}, " + f"include_my_drives={self.include_my_drives}, " + f"include_shared_drives={self.include_shared_drives}." + f"Using '{self.primary_admin_email}' as the account." + ) + yield from add_retrieval_info( + get_all_files_for_oauth( + service=drive_service, + include_files_shared_with_me=self.include_files_shared_with_me, + include_my_drives=self.include_my_drives, + include_shared_drives=self.include_shared_drives, + field_type=field_type, + max_num_pages=OAUTH_PAGES_PER_CHECKPOINT, + start=start, + end=end, + page_token=page_token, + ), + self.primary_admin_email, + DriveRetrievalStage.OAUTH_FILES, + ) + + def _manage_oauth_retrieval( + self, + field_type: DriveFileFieldType, + checkpoint: GoogleDriveCheckpoint, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> Iterator[RetrievedDriveFile]: + if checkpoint.completion_stage == DriveRetrievalStage.START: + checkpoint.completion_stage = DriveRetrievalStage.OAUTH_FILES + checkpoint.completion_map[self.primary_admin_email] = StageCompletion( + stage=DriveRetrievalStage.START, + completed_until=0, + current_folder_or_drive_id=None, + ) + + drive_service = get_drive_service(self.creds, self.primary_admin_email) + + if checkpoint.completion_stage == DriveRetrievalStage.OAUTH_FILES: + completion = checkpoint.completion_map[self.primary_admin_email] + all_files_start = start + # if resuming from a checkpoint + if completion.stage == DriveRetrievalStage.OAUTH_FILES: + all_files_start = completion.completed_until + + for file_or_token in self._oauth_retrieval_all_files( + field_type=field_type, + drive_service=drive_service, + start=all_files_start, + end=end, + page_token=checkpoint.completion_map[self.primary_admin_email].next_page_token, + ): + if isinstance(file_or_token, str): + checkpoint.completion_map[self.primary_admin_email].next_page_token = file_or_token + return # done with the max num pages, return checkpoint + yield file_or_token + checkpoint.completion_stage = DriveRetrievalStage.DRIVE_IDS + checkpoint.completion_map[self.primary_admin_email].next_page_token = None + return # create a new checkpoint + + all_requested = self.include_files_shared_with_me and self.include_my_drives and self.include_shared_drives + if all_requested: + # If all 3 are true, we already yielded from get_all_files_for_oauth + checkpoint.completion_stage = DriveRetrievalStage.DONE + return + + sorted_drive_ids, sorted_folder_ids = self._determine_retrieval_ids(checkpoint, DriveRetrievalStage.SHARED_DRIVE_FILES) + + if checkpoint.completion_stage == DriveRetrievalStage.SHARED_DRIVE_FILES: + for file_or_token in self._oauth_retrieval_drives( + field_type=field_type, + drive_service=drive_service, + drive_ids_to_retrieve=sorted_drive_ids, + checkpoint=checkpoint, + start=start, + end=end, + ): + if isinstance(file_or_token, str): + checkpoint.completion_map[self.primary_admin_email].next_page_token = file_or_token + return # done with the max num pages, return checkpoint + yield file_or_token + checkpoint.completion_stage = DriveRetrievalStage.FOLDER_FILES + checkpoint.completion_map[self.primary_admin_email].next_page_token = None + return # create a new checkpoint + + if checkpoint.completion_stage == DriveRetrievalStage.FOLDER_FILES: + yield from self._oauth_retrieval_folders( + field_type=field_type, + drive_service=drive_service, + drive_ids_to_retrieve=set(sorted_drive_ids), + folder_ids_to_retrieve=set(sorted_folder_ids), + checkpoint=checkpoint, + start=start, + end=end, + ) + + checkpoint.completion_stage = DriveRetrievalStage.DONE + + def _fetch_drive_items( + self, + field_type: DriveFileFieldType, + checkpoint: GoogleDriveCheckpoint, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + ) -> Iterator[RetrievedDriveFile]: + retrieval_method = self._manage_service_account_retrieval if isinstance(self.creds, ServiceAccountCredentials) else self._manage_oauth_retrieval + + return self._checkpointed_retrieval( + retrieval_method=retrieval_method, + field_type=field_type, + checkpoint=checkpoint, + start=start, + end=end, + ) + + def _extract_docs_from_google_drive( + self, + checkpoint: GoogleDriveCheckpoint, + start: SecondsSinceUnixEpoch | None, + end: SecondsSinceUnixEpoch | None, + include_permissions: bool, + ) -> Iterator[Document | ConnectorFailure]: + """ + Retrieves and converts Google Drive files to documents. + """ + field_type = DriveFileFieldType.WITH_PERMISSIONS if include_permissions else DriveFileFieldType.STANDARD + + try: + # Prepare a partial function with the credentials and admin email + convert_func = partial( + convert_drive_item_to_document, + self.creds, + self.allow_images, + self.size_threshold, + ( + PermissionSyncContext( + primary_admin_email=self.primary_admin_email, + google_domain=self.google_domain, + ) + if include_permissions + else None + ), + ) + # Fetch files in batches + batches_complete = 0 + files_batch: list[RetrievedDriveFile] = [] + + def _yield_batch( + files_batch: list[RetrievedDriveFile], + ) -> Iterator[Document | ConnectorFailure]: + nonlocal batches_complete + # Process the batch using run_functions_tuples_in_parallel + func_with_args = [ + ( + convert_func, + ( + [file.user_email, self.primary_admin_email] + get_file_owners(file.drive_file, self.primary_admin_email), + file.drive_file, + ), + ) + for file in files_batch + ] + results = cast( + list[Document | ConnectorFailure | None], + run_functions_tuples_in_parallel(func_with_args, max_workers=8), + ) + self.logger.debug(f"finished processing batch {batches_complete} with {len(results)} results") + + docs_and_failures = [result for result in results if result is not None] + self.logger.debug(f"batch {batches_complete} has {len(docs_and_failures)} docs or failures") + + if docs_and_failures: + yield from docs_and_failures + batches_complete += 1 + self.logger.debug(f"finished yielding batch {batches_complete}") + + for retrieved_file in self._fetch_drive_items( + field_type=field_type, + checkpoint=checkpoint, + start=start, + end=end, + ): + if retrieved_file.error is None: + files_batch.append(retrieved_file) + continue + + # handle retrieval errors + failure_stage = retrieved_file.completion_stage.value + failure_message = f"retrieval failure during stage: {failure_stage}," + failure_message += f"user: {retrieved_file.user_email}," + failure_message += f"parent drive/folder: {retrieved_file.parent_id}," + failure_message += f"error: {retrieved_file.error}" + self.logger.error(failure_message) + yield ConnectorFailure( + failed_entity=EntityFailure( + entity_id=failure_stage, + ), + failure_message=failure_message, + exception=retrieved_file.error, + ) + + yield from _yield_batch(files_batch) + checkpoint.retrieved_folder_and_drive_ids = self._retrieved_folder_and_drive_ids + + except Exception as e: + self.logger.exception(f"Error extracting documents from Google Drive: {e}") + raise e + + @override + def load_from_checkpoint( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: GoogleDriveCheckpoint, + ) -> CheckpointOutput: + return self._load_from_checkpoint(start, end, checkpoint, include_permissions=False) + + @override + def load_from_checkpoint_with_perm_sync( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: GoogleDriveCheckpoint, + ) -> CheckpointOutput: + return self._load_from_checkpoint(start, end, checkpoint, include_permissions=True) + + def _extract_slim_docs_from_google_drive( + self, + checkpoint: GoogleDriveCheckpoint, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + callback: IndexingHeartbeatInterface | None = None, + ) -> GenerateSlimDocumentOutput: + slim_batch = [] + for file in self._fetch_drive_items( + field_type=DriveFileFieldType.SLIM, + checkpoint=checkpoint, + start=start, + end=end, + ): + if file.error is not None: + raise file.error + if doc := build_slim_document( + self.creds, + file.drive_file, + # for now, always fetch permissions for slim runs + # TODO: move everything to load_from_checkpoint + # and only fetch permissions if needed + PermissionSyncContext( + primary_admin_email=self.primary_admin_email, + google_domain=self.google_domain, + ), + ): + slim_batch.append(doc) + if len(slim_batch) >= SLIM_BATCH_SIZE: + yield slim_batch + slim_batch = [] + if callback: + if callback.should_stop(): + raise RuntimeError("_extract_slim_docs_from_google_drive: Stop signal detected") + callback.progress("_extract_slim_docs_from_google_drive", 1) + yield slim_batch + + def retrieve_all_slim_docs_perm_sync( + self, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + callback: IndexingHeartbeatInterface | None = None, + ) -> GenerateSlimDocumentOutput: + try: + checkpoint = self.build_dummy_checkpoint() + while checkpoint.completion_stage != DriveRetrievalStage.DONE: + yield from self._extract_slim_docs_from_google_drive( + checkpoint=checkpoint, + start=start, + end=end, + ) + self.logger.info("Drive perm sync: Slim doc retrieval complete") + + except Exception as e: + if MISSING_SCOPES_ERROR_STR in str(e): + raise PermissionError() from e + raise e + + def validate_connector_settings(self) -> None: + if self._creds is None: + raise ConnectorMissingCredentialError("Google Drive credentials not loaded.") + + if self._primary_admin_email is None: + raise ConnectorValidationError("Primary admin email not found in credentials. Ensure DB_CREDENTIALS_PRIMARY_ADMIN_KEY is set.") + + try: + drive_service = get_drive_service(self._creds, self._primary_admin_email) + drive_service.files().list(pageSize=1, fields="files(id)").execute() + + if isinstance(self._creds, ServiceAccountCredentials): + # default is ~17mins of retries, don't do that here since this is called from + # the UI + get_root_folder_id(drive_service) + + except HttpError as e: + status_code = e.resp.status if e.resp else None + if status_code == 401: + raise CredentialExpiredError("Invalid or expired Google Drive credentials (401).") + elif status_code == 403: + raise InsufficientPermissionsError("Google Drive app lacks required permissions (403). Please ensure the necessary scopes are granted and Drive apps are enabled.") + else: + raise ConnectorValidationError(f"Unexpected Google Drive error (status={status_code}): {e}") + + except Exception as e: + # Check for scope-related hints from the error message + if MISSING_SCOPES_ERROR_STR in str(e): + raise InsufficientPermissionsError("Google Drive credentials are missing required scopes.") + raise ConnectorValidationError(f"Unexpected error during Google Drive validation: {e}") + + @override + def build_dummy_checkpoint(self) -> GoogleDriveCheckpoint: + return GoogleDriveCheckpoint( + retrieved_folder_and_drive_ids=set(), + completion_stage=DriveRetrievalStage.START, + completion_map=ThreadSafeDict(), + all_retrieved_file_ids=set(), + has_more=True, + ) + + @override + def validate_checkpoint_json(self, checkpoint_json: str) -> GoogleDriveCheckpoint: + return GoogleDriveCheckpoint.model_validate_json(checkpoint_json) + + +def get_credentials_from_env(email: str, oauth: bool = False) -> dict: + try: + if oauth: + raw_credential_string = os.environ["GOOGLE_DRIVE_OAUTH_CREDENTIALS_JSON_STR"] + else: + raw_credential_string = os.environ["GOOGLE_DRIVE_SERVICE_ACCOUNT_JSON_STR"] + except KeyError: + raise ValueError("Missing Google Drive credentials in environment variables") + + try: + credential_dict = json.loads(raw_credential_string) + except json.JSONDecodeError: + raise ValueError("Invalid JSON in Google Drive credentials") + + if oauth: + credential_dict = ensure_oauth_token_dict(credential_dict, DocumentSource.GOOGLE_DRIVE) + + refried_credential_string = json.dumps(credential_dict) + + DB_CREDENTIALS_DICT_TOKEN_KEY = "google_tokens" + DB_CREDENTIALS_DICT_SERVICE_ACCOUNT_KEY = "google_service_account_key" + DB_CREDENTIALS_PRIMARY_ADMIN_KEY = "google_primary_admin" + DB_CREDENTIALS_AUTHENTICATION_METHOD = "authentication_method" + + cred_key = DB_CREDENTIALS_DICT_TOKEN_KEY if oauth else DB_CREDENTIALS_DICT_SERVICE_ACCOUNT_KEY + + return { + cred_key: refried_credential_string, + DB_CREDENTIALS_PRIMARY_ADMIN_KEY: email, + DB_CREDENTIALS_AUTHENTICATION_METHOD: "uploaded", + } + + +class CheckpointOutputWrapper: + """ + Wraps a CheckpointOutput generator to give things back in a more digestible format. + The connector format is easier for the connector implementor (e.g. it enforces exactly + one new checkpoint is returned AND that the checkpoint is at the end), thus the different + formats. + """ + + def __init__(self) -> None: + self.next_checkpoint: GoogleDriveCheckpoint | None = None + + def __call__( + self, + checkpoint_connector_generator: CheckpointOutput, + ) -> Generator[ + tuple[Document | None, ConnectorFailure | None, GoogleDriveCheckpoint | None], + None, + None, + ]: + # grabs the final return value and stores it in the `next_checkpoint` variable + def _inner_wrapper( + checkpoint_connector_generator: CheckpointOutput, + ) -> CheckpointOutput: + self.next_checkpoint = yield from checkpoint_connector_generator + return self.next_checkpoint # not used + + for document_or_failure in _inner_wrapper(checkpoint_connector_generator): + if isinstance(document_or_failure, Document): + yield document_or_failure, None, None + elif isinstance(document_or_failure, ConnectorFailure): + yield None, document_or_failure, None + else: + raise ValueError(f"Invalid document_or_failure type: {type(document_or_failure)}") + + if self.next_checkpoint is None: + raise RuntimeError("Checkpoint is None. This should never happen - the connector should always return a checkpoint.") + + yield None, None, self.next_checkpoint + + +def yield_all_docs_from_checkpoint_connector( + connector: GoogleDriveConnector, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, +) -> Iterator[Document | ConnectorFailure]: + num_iterations = 0 + + checkpoint = connector.build_dummy_checkpoint() + while checkpoint.has_more: + doc_batch_generator = CheckpointOutputWrapper()(connector.load_from_checkpoint(start, end, checkpoint)) + for document, failure, next_checkpoint in doc_batch_generator: + if failure is not None: + yield failure + if document is not None: + yield document + if next_checkpoint is not None: + checkpoint = next_checkpoint + + num_iterations += 1 + if num_iterations > 100_000: + raise RuntimeError("Too many iterations. Infinite loop?") + + +if __name__ == "__main__": + import time + + logging.basicConfig(level=logging.DEBUG) + + try: + # Get credentials from environment + email = os.environ.get("GOOGLE_DRIVE_PRIMARY_ADMIN_EMAIL", "yongtengrey@gmail.com") + creds = get_credentials_from_env(email, oauth=True) + print("Credentials loaded successfully") + print(f"{creds=}") + + connector = GoogleDriveConnector( + include_shared_drives=False, + shared_drive_urls=None, + include_my_drives=True, + my_drive_emails="yongtengrey@gmail.com", + shared_folder_urls="https://drive.google.com/drive/folders/1fAKwbmf3U2oM139ZmnOzgIZHGkEwnpfy", + include_files_shared_with_me=False, + specific_user_emails=None, + ) + print("GoogleDriveConnector initialized successfully") + connector.load_credentials(creds) + print("Credentials loaded into connector successfully") + + print("Google Drive connector is ready to use!") + max_fsize = 0 + biggest_fsize = 0 + num_errors = 0 + docs_processed = 0 + start_time = time.time() + with open("stats.txt", "w") as f: + for num, doc_or_failure in enumerate(yield_all_docs_from_checkpoint_connector(connector, 0, time.time())): + if num % 200 == 0: + f.write(f"Processed {num} files\n") + f.write(f"Max file size: {max_fsize / 1000_000:.2f} MB\n") + f.write(f"Time so far: {time.time() - start_time:.2f} seconds\n") + f.write(f"Docs per minute: {num / (time.time() - start_time) * 60:.2f}\n") + biggest_fsize = max(biggest_fsize, max_fsize) + if isinstance(doc_or_failure, Document): + docs_processed += 1 + max_fsize = max(max_fsize, doc_or_failure.size_bytes) + print(f"{doc_or_failure=}") + elif isinstance(doc_or_failure, ConnectorFailure): + num_errors += 1 + print(f"Num errors: {num_errors}") + print(f"Biggest file size: {biggest_fsize / 1000_000:.2f} MB") + print(f"Time taken: {time.time() - start_time:.2f} seconds") + print(f"Total documents produced: {docs_processed}") + + except Exception as e: + print(f"Error: {e}") + import traceback + + traceback.print_exc() + sys.exit(1) diff --git a/common/data_source/google_drive/constant.py b/common/data_source/google_drive/constant.py new file mode 100644 index 00000000000..4fdfb23d57b --- /dev/null +++ b/common/data_source/google_drive/constant.py @@ -0,0 +1,4 @@ +UNSUPPORTED_FILE_TYPE_CONTENT = "" # keep empty for now +DRIVE_FOLDER_TYPE = "application/vnd.google-apps.folder" +DRIVE_SHORTCUT_TYPE = "application/vnd.google-apps.shortcut" +DRIVE_FILE_TYPE = "application/vnd.google-apps.file" diff --git a/common/data_source/google_drive/doc_conversion.py b/common/data_source/google_drive/doc_conversion.py new file mode 100644 index 00000000000..d697c1b2b86 --- /dev/null +++ b/common/data_source/google_drive/doc_conversion.py @@ -0,0 +1,607 @@ +import io +import logging +import mimetypes +from datetime import datetime, timezone +from pathlib import Path +from typing import Any, cast +from urllib.parse import urlparse, urlunparse + +from googleapiclient.errors import HttpError # type: ignore # type: ignore +from googleapiclient.http import MediaIoBaseDownload # type: ignore +from pydantic import BaseModel + +from common.data_source.config import DocumentSource, FileOrigin +from common.data_source.google_drive.constant import DRIVE_FOLDER_TYPE, DRIVE_SHORTCUT_TYPE +from common.data_source.google_drive.model import GDriveMimeType, GoogleDriveFileType +from common.data_source.google_drive.section_extraction import HEADING_DELIMITER +from common.data_source.google_util.resource import GoogleDriveService, get_drive_service +from common.data_source.models import ConnectorFailure, Document, DocumentFailure, ImageSection, SlimDocument, TextSection +from common.data_source.utils import get_file_ext + +# Image types that should be excluded from processing +EXCLUDED_IMAGE_TYPES = [ + "image/bmp", + "image/tiff", + "image/gif", + "image/svg+xml", + "image/avif", +] + +GOOGLE_MIME_TYPES_TO_EXPORT = { + GDriveMimeType.DOC.value: "text/plain", + GDriveMimeType.SPREADSHEET.value: "text/csv", + GDriveMimeType.PPT.value: "text/plain", +} + +GOOGLE_NATIVE_EXPORT_TARGETS: dict[str, tuple[str, str]] = { + GDriveMimeType.DOC.value: ("application/vnd.openxmlformats-officedocument.wordprocessingml.document", ".docx"), + GDriveMimeType.SPREADSHEET.value: ("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ".xlsx"), + GDriveMimeType.PPT.value: ("application/vnd.openxmlformats-officedocument.presentationml.presentation", ".pptx"), +} +GOOGLE_NATIVE_EXPORT_FALLBACK: tuple[str, str] = ("application/pdf", ".pdf") + +ACCEPTED_PLAIN_TEXT_FILE_EXTENSIONS = [ + ".txt", + ".md", + ".mdx", + ".conf", + ".log", + ".json", + ".csv", + ".tsv", + ".xml", + ".yml", + ".yaml", + ".sql", +] + +ACCEPTED_DOCUMENT_FILE_EXTENSIONS = [ + ".pdf", + ".docx", + ".pptx", + ".xlsx", + ".eml", + ".epub", + ".html", +] + +ACCEPTED_IMAGE_FILE_EXTENSIONS = [ + ".png", + ".jpg", + ".jpeg", + ".webp", +] + +ALL_ACCEPTED_FILE_EXTENSIONS = ACCEPTED_PLAIN_TEXT_FILE_EXTENSIONS + ACCEPTED_DOCUMENT_FILE_EXTENSIONS + ACCEPTED_IMAGE_FILE_EXTENSIONS + +MAX_RETRIEVER_EMAILS = 20 +CHUNK_SIZE_BUFFER = 64 # extra bytes past the limit to read +# This is not a standard valid unicode char, it is used by the docs advanced API to +# represent smart chips (elements like dates and doc links). +SMART_CHIP_CHAR = "\ue907" +WEB_VIEW_LINK_KEY = "webViewLink" +# Fallback templates for generating web links when Drive omits webViewLink. +_FALLBACK_WEB_VIEW_LINK_TEMPLATES = { + GDriveMimeType.DOC.value: "https://docs.google.com/document/d/{}/view", + GDriveMimeType.SPREADSHEET.value: "https://docs.google.com/spreadsheets/d/{}/view", + GDriveMimeType.PPT.value: "https://docs.google.com/presentation/d/{}/view", +} + + +class PermissionSyncContext(BaseModel): + """ + This is the information that is needed to sync permissions for a document. + """ + + primary_admin_email: str + google_domain: str + + +def onyx_document_id_from_drive_file(file: GoogleDriveFileType) -> str: + link = file.get(WEB_VIEW_LINK_KEY) + if not link: + file_id = file.get("id") + if not file_id: + raise KeyError(f"Google Drive file missing both '{WEB_VIEW_LINK_KEY}' and 'id' fields.") + mime_type = file.get("mimeType", "") + template = _FALLBACK_WEB_VIEW_LINK_TEMPLATES.get(mime_type) + if template is None: + link = f"https://drive.google.com/file/d/{file_id}/view" + else: + link = template.format(file_id) + logging.debug( + "Missing webViewLink for Google Drive file with id %s. Falling back to constructed link %s", + file_id, + link, + ) + parsed_url = urlparse(link) + parsed_url = parsed_url._replace(query="") # remove query parameters + spl_path = parsed_url.path.split("/") + if spl_path and (spl_path[-1] in ["edit", "view", "preview"]): + spl_path.pop() + parsed_url = parsed_url._replace(path="/".join(spl_path)) + # Remove query parameters and reconstruct URL + return urlunparse(parsed_url) + + +def _find_nth(haystack: str, needle: str, n: int, start: int = 0) -> int: + start = haystack.find(needle, start) + while start >= 0 and n > 1: + start = haystack.find(needle, start + len(needle)) + n -= 1 + return start + + +def align_basic_advanced(basic_sections: list[TextSection | ImageSection], adv_sections: list[TextSection]) -> list[TextSection | ImageSection]: + """Align the basic sections with the advanced sections. + In particular, the basic sections contain all content of the file, + including smart chips like dates and doc links. The advanced sections + are separated by section headers and contain header-based links that + improve user experience when they click on the source in the UI. + + There are edge cases in text matching (i.e. the heading is a smart chip or + there is a smart chip in the doc with text containing the actual heading text) + that make the matching imperfect; this is hence done on a best-effort basis. + """ + if len(adv_sections) <= 1: + return basic_sections # no benefit from aligning + + basic_full_text = "".join([section.text for section in basic_sections if isinstance(section, TextSection)]) + new_sections: list[TextSection | ImageSection] = [] + heading_start = 0 + for adv_ind in range(1, len(adv_sections)): + heading = adv_sections[adv_ind].text.split(HEADING_DELIMITER)[0] + # retrieve the longest part of the heading that is not a smart chip + heading_key = max(heading.split(SMART_CHIP_CHAR), key=len).strip() + if heading_key == "": + logging.warning(f"Cannot match heading: {heading}, its link will come from the following section") + continue + heading_offset = heading.find(heading_key) + + # count occurrences of heading str in previous section + heading_count = adv_sections[adv_ind - 1].text.count(heading_key) + + prev_start = heading_start + heading_start = _find_nth(basic_full_text, heading_key, heading_count, start=prev_start) - heading_offset + if heading_start < 0: + logging.warning(f"Heading key {heading_key} from heading {heading} not found in basic text") + heading_start = prev_start + continue + + new_sections.append( + TextSection( + link=adv_sections[adv_ind - 1].link, + text=basic_full_text[prev_start:heading_start], + ) + ) + + # handle last section + new_sections.append(TextSection(link=adv_sections[-1].link, text=basic_full_text[heading_start:])) + return new_sections + + +def is_valid_image_type(mime_type: str) -> bool: + """ + Check if mime_type is a valid image type. + + Args: + mime_type: The MIME type to check + + Returns: + True if the MIME type is a valid image type, False otherwise + """ + return bool(mime_type) and mime_type.startswith("image/") and mime_type not in EXCLUDED_IMAGE_TYPES + + +def is_gdrive_image_mime_type(mime_type: str) -> bool: + """ + Return True if the mime_type is a common image type in GDrive. + (e.g. 'image/png', 'image/jpeg') + """ + return is_valid_image_type(mime_type) + + +def _get_extension_from_file(file: GoogleDriveFileType, mime_type: str, fallback: str = ".bin") -> str: + file_name = file.get("name") or "" + if file_name: + suffix = Path(file_name).suffix + if suffix: + return suffix + + file_extension = file.get("fileExtension") + if file_extension: + return f".{file_extension.lstrip('.')}" + + guessed = mimetypes.guess_extension(mime_type or "") + if guessed: + return guessed + + return fallback + + +def _download_file_blob( + service: GoogleDriveService, + file: GoogleDriveFileType, + size_threshold: int, + allow_images: bool, +) -> tuple[bytes, str] | None: + mime_type = file.get("mimeType", "") + file_id = file.get("id") + if not file_id: + logging.warning("Encountered Google Drive file without id.") + return None + + if is_gdrive_image_mime_type(mime_type) and not allow_images: + logging.debug(f"Skipping image {file.get('name')} because allow_images is False.") + return None + + blob: bytes = b"" + extension = ".bin" + try: + if mime_type in GOOGLE_NATIVE_EXPORT_TARGETS: + export_mime, extension = GOOGLE_NATIVE_EXPORT_TARGETS[mime_type] + request = service.files().export_media(fileId=file_id, mimeType=export_mime) + blob = _download_request(request, file_id, size_threshold) + elif mime_type.startswith("application/vnd.google-apps"): + export_mime, extension = GOOGLE_NATIVE_EXPORT_FALLBACK + request = service.files().export_media(fileId=file_id, mimeType=export_mime) + blob = _download_request(request, file_id, size_threshold) + else: + extension = _get_extension_from_file(file, mime_type) + blob = download_request(service, file_id, size_threshold) + except HttpError: + raise + + if not blob: + return None + if not extension: + extension = _get_extension_from_file(file, mime_type) + return blob, extension + + +def download_request(service: GoogleDriveService, file_id: str, size_threshold: int) -> bytes: + """ + Download the file from Google Drive. + """ + # For other file types, download the file + # Use the correct API call for downloading files + request = service.files().get_media(fileId=file_id) + return _download_request(request, file_id, size_threshold) + + +def _download_request(request: Any, file_id: str, size_threshold: int) -> bytes: + response_bytes = io.BytesIO() + downloader = MediaIoBaseDownload(response_bytes, request, chunksize=size_threshold + CHUNK_SIZE_BUFFER) + done = False + while not done: + download_progress, done = downloader.next_chunk() + if download_progress.resumable_progress > size_threshold: + logging.warning(f"File {file_id} exceeds size threshold of {size_threshold}. Skipping2.") + return bytes() + + response = response_bytes.getvalue() + if not response: + logging.warning(f"Failed to download {file_id}") + return bytes() + return response + + +def _download_and_extract_sections_basic( + file: dict[str, str], + service: GoogleDriveService, + allow_images: bool, + size_threshold: int, +) -> list[TextSection | ImageSection]: + """Extract text and images from a Google Drive file.""" + file_id = file["id"] + file_name = file["name"] + mime_type = file["mimeType"] + link = file.get(WEB_VIEW_LINK_KEY, "") + + # For non-Google files, download the file + # Use the correct API call for downloading files + # lazy evaluation to only download the file if necessary + def response_call() -> bytes: + return download_request(service, file_id, size_threshold) + + if is_gdrive_image_mime_type(mime_type): + # Skip images if not explicitly enabled + if not allow_images: + return [] + + # Store images for later processing + sections: list[TextSection | ImageSection] = [] + + def store_image_and_create_section(**kwargs): + pass + + try: + section, embedded_id = store_image_and_create_section( + image_data=response_call(), + file_id=file_id, + display_name=file_name, + media_type=mime_type, + file_origin=FileOrigin.CONNECTOR, + link=link, + ) + sections.append(section) + except Exception as e: + logging.error(f"Failed to process image {file_name}: {e}") + return sections + + # For Google Docs, Sheets, and Slides, export as plain text + if mime_type in GOOGLE_MIME_TYPES_TO_EXPORT: + export_mime_type = GOOGLE_MIME_TYPES_TO_EXPORT[mime_type] + # Use the correct API call for exporting files + request = service.files().export_media(fileId=file_id, mimeType=export_mime_type) + response = _download_request(request, file_id, size_threshold) + if not response: + logging.warning(f"Failed to export {file_name} as {export_mime_type}") + return [] + + text = response.decode("utf-8") + return [TextSection(link=link, text=text)] + + # Process based on mime type + if mime_type == "text/plain": + try: + text = response_call().decode("utf-8") + return [TextSection(link=link, text=text)] + except UnicodeDecodeError as e: + logging.warning(f"Failed to extract text from {file_name}: {e}") + return [] + + elif mime_type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document": + + def docx_to_text_and_images(*args, **kwargs): + return "docx_to_text_and_images" + + text, _ = docx_to_text_and_images(io.BytesIO(response_call())) + return [TextSection(link=link, text=text)] + + elif mime_type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": + + def xlsx_to_text(*args, **kwargs): + return "xlsx_to_text" + + text = xlsx_to_text(io.BytesIO(response_call()), file_name=file_name) + return [TextSection(link=link, text=text)] if text else [] + + elif mime_type == "application/vnd.openxmlformats-officedocument.presentationml.presentation": + + def pptx_to_text(*args, **kwargs): + return "pptx_to_text" + + text = pptx_to_text(io.BytesIO(response_call()), file_name=file_name) + return [TextSection(link=link, text=text)] if text else [] + + elif mime_type == "application/pdf": + + def read_pdf_file(*args, **kwargs): + return "read_pdf_file" + + text, _pdf_meta, images = read_pdf_file(io.BytesIO(response_call())) + pdf_sections: list[TextSection | ImageSection] = [TextSection(link=link, text=text)] + + # Process embedded images in the PDF + try: + for idx, (img_data, img_name) in enumerate(images): + section, embedded_id = store_image_and_create_section( + image_data=img_data, + file_id=f"{file_id}_img_{idx}", + display_name=img_name or f"{file_name} - image {idx}", + file_origin=FileOrigin.CONNECTOR, + ) + pdf_sections.append(section) + except Exception as e: + logging.error(f"Failed to process PDF images in {file_name}: {e}") + return pdf_sections + + # Final attempt at extracting text + file_ext = get_file_ext(file.get("name", "")) + if file_ext not in ALL_ACCEPTED_FILE_EXTENSIONS: + logging.warning(f"Skipping file {file.get('name')} due to extension.") + return [] + + try: + + def extract_file_text(*args, **kwargs): + return "extract_file_text" + + text = extract_file_text(io.BytesIO(response_call()), file_name) + return [TextSection(link=link, text=text)] + except Exception as e: + logging.warning(f"Failed to extract text from {file_name}: {e}") + return [] + + +def _convert_drive_item_to_document( + creds: Any, + allow_images: bool, + size_threshold: int, + retriever_email: str, + file: GoogleDriveFileType, + # if not specified, we will not sync permissions + # will also be a no-op if EE is not enabled + permission_sync_context: PermissionSyncContext | None, +) -> Document | ConnectorFailure | None: + """ + Main entry point for converting a Google Drive file => Document object. + """ + + def _get_drive_service() -> GoogleDriveService: + return get_drive_service(creds, user_email=retriever_email) + + doc_id = "unknown" + link = file.get(WEB_VIEW_LINK_KEY) + + try: + if file.get("mimeType") in [DRIVE_SHORTCUT_TYPE, DRIVE_FOLDER_TYPE]: + logging.info("Skipping shortcut/folder.") + return None + + size_str = file.get("size") + if size_str: + try: + size_int = int(size_str) + except ValueError: + logging.warning(f"Parsing string to int failed: size_str={size_str}") + else: + if size_int > size_threshold: + logging.warning(f"{file.get('name')} exceeds size threshold of {size_threshold}. Skipping.") + return None + + blob_and_ext = _download_file_blob( + service=_get_drive_service(), + file=file, + size_threshold=size_threshold, + allow_images=allow_images, + ) + + if blob_and_ext is None: + logging.info(f"Skipping file {file.get('name')} due to incompatible type or download failure.") + return None + + blob, extension = blob_and_ext + if not blob: + logging.warning(f"Failed to download {file.get('name')}. Skipping.") + return None + + doc_id = onyx_document_id_from_drive_file(file) + modified_time = file.get("modifiedTime") + try: + doc_updated_at = datetime.fromisoformat(modified_time.replace("Z", "+00:00")) if modified_time else datetime.now(timezone.utc) + except ValueError: + logging.warning(f"Failed to parse modifiedTime for {file.get('name')}, defaulting to current time.") + doc_updated_at = datetime.now(timezone.utc) + + return Document( + id=doc_id, + source=DocumentSource.GOOGLE_DRIVE, + semantic_identifier=file.get("name", ""), + blob=blob, + extension=extension, + size_bytes=len(blob), + doc_updated_at=doc_updated_at, + ) + except Exception as e: + doc_id = "unknown" + try: + doc_id = onyx_document_id_from_drive_file(file) + except Exception as e2: + logging.warning(f"Error getting document id from file: {e2}") + + file_name = file.get("name", doc_id) + error_str = f"Error converting file '{file_name}' to Document as {retriever_email}: {e}" + if isinstance(e, HttpError) and e.status_code == 403: + logging.warning(f"Uncommon permissions error while downloading file. User {retriever_email} was able to see file {file_name} but cannot download it.") + logging.warning(error_str) + + return ConnectorFailure( + failed_document=DocumentFailure( + document_id=doc_id, + document_link=link, + ), + failed_entity=None, + failure_message=error_str, + exception=e, + ) + + +def convert_drive_item_to_document( + creds: Any, + allow_images: bool, + size_threshold: int, + # if not specified, we will not sync permissions + # will also be a no-op if EE is not enabled + permission_sync_context: PermissionSyncContext | None, + retriever_emails: list[str], + file: GoogleDriveFileType, +) -> Document | ConnectorFailure | None: + """ + Attempt to convert a drive item to a document with each retriever email + in order. returns upon a successful retrieval or a non-403 error. + + We used to always get the user email from the file owners when available, + but this was causing issues with shared folders where the owner was not included in the service account + now we use the email of the account that successfully listed the file. There are cases where a + user that can list a file cannot download it, so we retry with file owners and admin email. + """ + first_error = None + doc_or_failure = None + retriever_emails = retriever_emails[:MAX_RETRIEVER_EMAILS] + # use seen instead of list(set()) to avoid re-ordering the retriever emails + seen = set() + for retriever_email in retriever_emails: + if retriever_email in seen: + continue + seen.add(retriever_email) + doc_or_failure = _convert_drive_item_to_document( + creds, + allow_images, + size_threshold, + retriever_email, + file, + permission_sync_context, + ) + + # There are a variety of permissions-based errors that occasionally occur + # when retrieving files. Often when these occur, there is another user + # that can successfully retrieve the file, so we try the next user. + if doc_or_failure is None or isinstance(doc_or_failure, Document) or not (isinstance(doc_or_failure.exception, HttpError) and doc_or_failure.exception.status_code in [401, 403, 404]): + return doc_or_failure + + if first_error is None: + first_error = doc_or_failure + else: + first_error.failure_message += f"\n\n{doc_or_failure.failure_message}" + + if first_error and isinstance(first_error.exception, HttpError) and first_error.exception.status_code == 403: + # This SHOULD happen very rarely, and we don't want to break the indexing process when + # a high volume of 403s occurs early. We leave a verbose log to help investigate. + logging.error( + f"Skipping file id: {file.get('id')} name: {file.get('name')} due to 403 error.Attempted to retrieve with {retriever_emails},got the following errors: {first_error.failure_message}" + ) + return None + return first_error + + +def build_slim_document( + creds: Any, + file: GoogleDriveFileType, + # if not specified, we will not sync permissions + # will also be a no-op if EE is not enabled + permission_sync_context: PermissionSyncContext | None, +) -> SlimDocument | None: + if file.get("mimeType") in [DRIVE_FOLDER_TYPE, DRIVE_SHORTCUT_TYPE]: + return None + + owner_email = cast(str | None, file.get("owners", [{}])[0].get("emailAddress")) + + def _get_external_access_for_raw_gdrive_file(*args, **kwargs): + return None + + external_access = ( + _get_external_access_for_raw_gdrive_file( + file=file, + company_domain=permission_sync_context.google_domain, + retriever_drive_service=( + get_drive_service( + creds, + user_email=owner_email, + ) + if owner_email + else None + ), + admin_drive_service=get_drive_service( + creds, + user_email=permission_sync_context.primary_admin_email, + ), + ) + if permission_sync_context + else None + ) + return SlimDocument( + id=onyx_document_id_from_drive_file(file), + external_access=external_access, + ) diff --git a/common/data_source/google_drive/file_retrieval.py b/common/data_source/google_drive/file_retrieval.py new file mode 100644 index 00000000000..ee6ea6b62c9 --- /dev/null +++ b/common/data_source/google_drive/file_retrieval.py @@ -0,0 +1,346 @@ +import logging +from collections.abc import Callable, Iterator +from datetime import datetime, timezone +from enum import Enum + +from googleapiclient.discovery import Resource # type: ignore +from googleapiclient.errors import HttpError # type: ignore + +from common.data_source.google_drive.constant import DRIVE_FOLDER_TYPE, DRIVE_SHORTCUT_TYPE +from common.data_source.google_drive.model import DriveRetrievalStage, GoogleDriveFileType, RetrievedDriveFile +from common.data_source.google_util.resource import GoogleDriveService +from common.data_source.google_util.util import ORDER_BY_KEY, PAGE_TOKEN_KEY, GoogleFields, execute_paginated_retrieval, execute_paginated_retrieval_with_max_pages +from common.data_source.models import SecondsSinceUnixEpoch + +PERMISSION_FULL_DESCRIPTION = "permissions(id, emailAddress, type, domain, permissionDetails)" + +FILE_FIELDS = "nextPageToken, files(mimeType, id, name, modifiedTime, webViewLink, shortcutDetails, owners(emailAddress), size)" +FILE_FIELDS_WITH_PERMISSIONS = f"nextPageToken, files(mimeType, id, name, {PERMISSION_FULL_DESCRIPTION}, permissionIds, modifiedTime, webViewLink, shortcutDetails, owners(emailAddress), size)" +SLIM_FILE_FIELDS = f"nextPageToken, files(mimeType, driveId, id, name, {PERMISSION_FULL_DESCRIPTION}, permissionIds, webViewLink, owners(emailAddress), modifiedTime)" + +FOLDER_FIELDS = "nextPageToken, files(id, name, permissions, modifiedTime, webViewLink, shortcutDetails)" + + +class DriveFileFieldType(Enum): + """Enum to specify which fields to retrieve from Google Drive files""" + + SLIM = "slim" # Minimal fields for basic file info + STANDARD = "standard" # Standard fields including content metadata + WITH_PERMISSIONS = "with_permissions" # Full fields including permissions + + +def generate_time_range_filter( + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, +) -> str: + time_range_filter = "" + if start is not None: + time_start = datetime.fromtimestamp(start, tz=timezone.utc).isoformat() + time_range_filter += f" and {GoogleFields.MODIFIED_TIME.value} > '{time_start}'" + if end is not None: + time_stop = datetime.fromtimestamp(end, tz=timezone.utc).isoformat() + time_range_filter += f" and {GoogleFields.MODIFIED_TIME.value} <= '{time_stop}'" + return time_range_filter + + +def _get_folders_in_parent( + service: Resource, + parent_id: str | None = None, +) -> Iterator[GoogleDriveFileType]: + # Follow shortcuts to folders + query = f"(mimeType = '{DRIVE_FOLDER_TYPE}' or mimeType = '{DRIVE_SHORTCUT_TYPE}')" + query += " and trashed = false" + + if parent_id: + query += f" and '{parent_id}' in parents" + + for file in execute_paginated_retrieval( + retrieval_function=service.files().list, + list_key="files", + continue_on_404_or_403=True, + corpora="allDrives", + supportsAllDrives=True, + includeItemsFromAllDrives=True, + fields=FOLDER_FIELDS, + q=query, + ): + yield file + + +def _get_fields_for_file_type(field_type: DriveFileFieldType) -> str: + """Get the appropriate fields string based on the field type enum""" + if field_type == DriveFileFieldType.SLIM: + return SLIM_FILE_FIELDS + elif field_type == DriveFileFieldType.WITH_PERMISSIONS: + return FILE_FIELDS_WITH_PERMISSIONS + else: # DriveFileFieldType.STANDARD + return FILE_FIELDS + + +def _get_files_in_parent( + service: Resource, + parent_id: str, + field_type: DriveFileFieldType, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, +) -> Iterator[GoogleDriveFileType]: + query = f"mimeType != '{DRIVE_FOLDER_TYPE}' and '{parent_id}' in parents" + query += " and trashed = false" + query += generate_time_range_filter(start, end) + + kwargs = {ORDER_BY_KEY: GoogleFields.MODIFIED_TIME.value} + + for file in execute_paginated_retrieval( + retrieval_function=service.files().list, + list_key="files", + continue_on_404_or_403=True, + corpora="allDrives", + supportsAllDrives=True, + includeItemsFromAllDrives=True, + fields=_get_fields_for_file_type(field_type), + q=query, + **kwargs, + ): + yield file + + +def crawl_folders_for_files( + service: Resource, + parent_id: str, + field_type: DriveFileFieldType, + user_email: str, + traversed_parent_ids: set[str], + update_traversed_ids_func: Callable[[str], None], + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, +) -> Iterator[RetrievedDriveFile]: + """ + This function starts crawling from any folder. It is slower though. + """ + logging.info("Entered crawl_folders_for_files with parent_id: " + parent_id) + if parent_id not in traversed_parent_ids: + logging.info("Parent id not in traversed parent ids, getting files") + found_files = False + file = {} + try: + for file in _get_files_in_parent( + service=service, + parent_id=parent_id, + field_type=field_type, + start=start, + end=end, + ): + logging.info(f"Found file: {file['name']}, user email: {user_email}") + found_files = True + yield RetrievedDriveFile( + drive_file=file, + user_email=user_email, + parent_id=parent_id, + completion_stage=DriveRetrievalStage.FOLDER_FILES, + ) + # Only mark a folder as done if it was fully traversed without errors + # This usually indicates that the owner of the folder was impersonated. + # In cases where this never happens, most likely the folder owner is + # not part of the google workspace in question (or for oauth, the authenticated + # user doesn't own the folder) + if found_files: + update_traversed_ids_func(parent_id) + except Exception as e: + if isinstance(e, HttpError) and e.status_code == 403: + # don't yield an error here because this is expected behavior + # when a user doesn't have access to a folder + logging.debug(f"Error getting files in parent {parent_id}: {e}") + else: + logging.error(f"Error getting files in parent {parent_id}: {e}") + yield RetrievedDriveFile( + drive_file=file, + user_email=user_email, + parent_id=parent_id, + completion_stage=DriveRetrievalStage.FOLDER_FILES, + error=e, + ) + else: + logging.info(f"Skipping subfolder files since already traversed: {parent_id}") + + for subfolder in _get_folders_in_parent( + service=service, + parent_id=parent_id, + ): + logging.info("Fetching all files in subfolder: " + subfolder["name"]) + yield from crawl_folders_for_files( + service=service, + parent_id=subfolder["id"], + field_type=field_type, + user_email=user_email, + traversed_parent_ids=traversed_parent_ids, + update_traversed_ids_func=update_traversed_ids_func, + start=start, + end=end, + ) + + +def get_files_in_shared_drive( + service: Resource, + drive_id: str, + field_type: DriveFileFieldType, + max_num_pages: int, + update_traversed_ids_func: Callable[[str], None] = lambda _: None, + cache_folders: bool = True, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + page_token: str | None = None, +) -> Iterator[GoogleDriveFileType | str]: + kwargs = {ORDER_BY_KEY: GoogleFields.MODIFIED_TIME.value} + if page_token: + logging.info(f"Using page token: {page_token}") + kwargs[PAGE_TOKEN_KEY] = page_token + + if cache_folders: + # If we know we are going to folder crawl later, we can cache the folders here + # Get all folders being queried and add them to the traversed set + folder_query = f"mimeType = '{DRIVE_FOLDER_TYPE}'" + folder_query += " and trashed = false" + for folder in execute_paginated_retrieval( + retrieval_function=service.files().list, + list_key="files", + continue_on_404_or_403=True, + corpora="drive", + driveId=drive_id, + supportsAllDrives=True, + includeItemsFromAllDrives=True, + fields="nextPageToken, files(id)", + q=folder_query, + ): + update_traversed_ids_func(folder["id"]) + + # Get all files in the shared drive + file_query = f"mimeType != '{DRIVE_FOLDER_TYPE}'" + file_query += " and trashed = false" + file_query += generate_time_range_filter(start, end) + + for file in execute_paginated_retrieval_with_max_pages( + retrieval_function=service.files().list, + max_num_pages=max_num_pages, + list_key="files", + continue_on_404_or_403=True, + corpora="drive", + driveId=drive_id, + supportsAllDrives=True, + includeItemsFromAllDrives=True, + fields=_get_fields_for_file_type(field_type), + q=file_query, + **kwargs, + ): + # If we found any files, mark this drive as traversed. When a user has access to a drive, + # they have access to all the files in the drive. Also not a huge deal if we re-traverse + # empty drives. + # NOTE: ^^ the above is not actually true due to folder restrictions: + # https://support.google.com/a/users/answer/12380484?hl=en + # So we may have to change this logic for people who use folder restrictions. + update_traversed_ids_func(drive_id) + yield file + + +def get_all_files_in_my_drive_and_shared( + service: GoogleDriveService, + update_traversed_ids_func: Callable, + field_type: DriveFileFieldType, + include_shared_with_me: bool, + max_num_pages: int, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + cache_folders: bool = True, + page_token: str | None = None, +) -> Iterator[GoogleDriveFileType | str]: + kwargs = {ORDER_BY_KEY: GoogleFields.MODIFIED_TIME.value} + if page_token: + logging.info(f"Using page token: {page_token}") + kwargs[PAGE_TOKEN_KEY] = page_token + + if cache_folders: + # If we know we are going to folder crawl later, we can cache the folders here + # Get all folders being queried and add them to the traversed set + folder_query = f"mimeType = '{DRIVE_FOLDER_TYPE}'" + folder_query += " and trashed = false" + if not include_shared_with_me: + folder_query += " and 'me' in owners" + found_folders = False + for folder in execute_paginated_retrieval( + retrieval_function=service.files().list, + list_key="files", + corpora="user", + fields=_get_fields_for_file_type(field_type), + q=folder_query, + ): + update_traversed_ids_func(folder[GoogleFields.ID]) + found_folders = True + if found_folders: + update_traversed_ids_func(get_root_folder_id(service)) + + # Then get the files + file_query = f"mimeType != '{DRIVE_FOLDER_TYPE}'" + file_query += " and trashed = false" + if not include_shared_with_me: + file_query += " and 'me' in owners" + file_query += generate_time_range_filter(start, end) + yield from execute_paginated_retrieval_with_max_pages( + retrieval_function=service.files().list, + max_num_pages=max_num_pages, + list_key="files", + continue_on_404_or_403=False, + corpora="user", + fields=_get_fields_for_file_type(field_type), + q=file_query, + **kwargs, + ) + + +def get_all_files_for_oauth( + service: GoogleDriveService, + include_files_shared_with_me: bool, + include_my_drives: bool, + # One of the above 2 should be true + include_shared_drives: bool, + field_type: DriveFileFieldType, + max_num_pages: int, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + page_token: str | None = None, +) -> Iterator[GoogleDriveFileType | str]: + kwargs = {ORDER_BY_KEY: GoogleFields.MODIFIED_TIME.value} + if page_token: + logging.info(f"Using page token: {page_token}") + kwargs[PAGE_TOKEN_KEY] = page_token + + should_get_all = include_shared_drives and include_my_drives and include_files_shared_with_me + corpora = "allDrives" if should_get_all else "user" + + file_query = f"mimeType != '{DRIVE_FOLDER_TYPE}'" + file_query += " and trashed = false" + file_query += generate_time_range_filter(start, end) + + if not should_get_all: + if include_files_shared_with_me and not include_my_drives: + file_query += " and not 'me' in owners" + if not include_files_shared_with_me and include_my_drives: + file_query += " and 'me' in owners" + + yield from execute_paginated_retrieval_with_max_pages( + max_num_pages=max_num_pages, + retrieval_function=service.files().list, + list_key="files", + continue_on_404_or_403=False, + corpora=corpora, + includeItemsFromAllDrives=should_get_all, + supportsAllDrives=should_get_all, + fields=_get_fields_for_file_type(field_type), + q=file_query, + **kwargs, + ) + + +# Just in case we need to get the root folder id +def get_root_folder_id(service: Resource) -> str: + # we dont paginate here because there is only one root folder per user + # https://developers.google.com/drive/api/guides/v2-to-v3-reference + return service.files().get(fileId="root", fields=GoogleFields.ID.value).execute()[GoogleFields.ID.value] diff --git a/common/data_source/google_drive/model.py b/common/data_source/google_drive/model.py new file mode 100644 index 00000000000..d0e89c24e35 --- /dev/null +++ b/common/data_source/google_drive/model.py @@ -0,0 +1,144 @@ +from enum import Enum +from typing import Any + +from pydantic import BaseModel, ConfigDict, field_serializer, field_validator + +from common.data_source.google_util.util_threadpool_concurrency import ThreadSafeDict +from common.data_source.models import ConnectorCheckpoint, SecondsSinceUnixEpoch + +GoogleDriveFileType = dict[str, Any] + + +class GDriveMimeType(str, Enum): + DOC = "application/vnd.google-apps.document" + SPREADSHEET = "application/vnd.google-apps.spreadsheet" + SPREADSHEET_OPEN_FORMAT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + SPREADSHEET_MS_EXCEL = "application/vnd.ms-excel" + PDF = "application/pdf" + WORD_DOC = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" + PPT = "application/vnd.google-apps.presentation" + POWERPOINT = "application/vnd.openxmlformats-officedocument.presentationml.presentation" + PLAIN_TEXT = "text/plain" + MARKDOWN = "text/markdown" + + +# These correspond to The major stages of retrieval for google drive. +# The stages for the oauth flow are: +# get_all_files_for_oauth(), +# get_all_drive_ids(), +# get_files_in_shared_drive(), +# crawl_folders_for_files() +# +# The stages for the service account flow are roughly: +# get_all_user_emails(), +# get_all_drive_ids(), +# get_files_in_shared_drive(), +# Then for each user: +# get_files_in_my_drive() +# get_files_in_shared_drive() +# crawl_folders_for_files() +class DriveRetrievalStage(str, Enum): + START = "start" + DONE = "done" + # OAuth specific stages + OAUTH_FILES = "oauth_files" + + # Service account specific stages + USER_EMAILS = "user_emails" + MY_DRIVE_FILES = "my_drive_files" + + # Used for both oauth and service account flows + DRIVE_IDS = "drive_ids" + SHARED_DRIVE_FILES = "shared_drive_files" + FOLDER_FILES = "folder_files" + + +class StageCompletion(BaseModel): + """ + Describes the point in the retrieval+indexing process that the + connector is at. completed_until is the timestamp of the latest + file that has been retrieved or error that has been yielded. + Optional fields are used for retrieval stages that need more information + for resuming than just the timestamp of the latest file. + """ + + stage: DriveRetrievalStage + completed_until: SecondsSinceUnixEpoch + current_folder_or_drive_id: str | None = None + next_page_token: str | None = None + + # only used for shared drives + processed_drive_ids: set[str] = set() + + def update( + self, + stage: DriveRetrievalStage, + completed_until: SecondsSinceUnixEpoch, + current_folder_or_drive_id: str | None = None, + ) -> None: + self.stage = stage + self.completed_until = completed_until + self.current_folder_or_drive_id = current_folder_or_drive_id + + +class GoogleDriveCheckpoint(ConnectorCheckpoint): + # Checkpoint version of _retrieved_ids + retrieved_folder_and_drive_ids: set[str] + + # Describes the point in the retrieval+indexing process that the + # checkpoint is at. when this is set to a given stage, the connector + # has finished yielding all values from the previous stage. + completion_stage: DriveRetrievalStage + + # The latest timestamp of a file that has been retrieved per user email. + # StageCompletion is used to track the completion of each stage, but the + # timestamp part is not used for folder crawling. + completion_map: ThreadSafeDict[str, StageCompletion] + + # all file ids that have been retrieved + all_retrieved_file_ids: set[str] = set() + + # cached version of the drive and folder ids to retrieve + drive_ids_to_retrieve: list[str] | None = None + folder_ids_to_retrieve: list[str] | None = None + + # cached user emails + user_emails: list[str] | None = None + + @field_serializer("completion_map") + def serialize_completion_map(self, completion_map: ThreadSafeDict[str, StageCompletion], _info: Any) -> dict[str, StageCompletion]: + return completion_map._dict + + @field_validator("completion_map", mode="before") + def validate_completion_map(cls, v: Any) -> ThreadSafeDict[str, StageCompletion]: + assert isinstance(v, dict) or isinstance(v, ThreadSafeDict) + return ThreadSafeDict({k: StageCompletion.model_validate(val) for k, val in v.items()}) + + +class RetrievedDriveFile(BaseModel): + """ + Describes a file that has been retrieved from google drive. + user_email is the email of the user that the file was retrieved + by impersonating. If an error worthy of being reported is encountered, + error should be set and later propagated as a ConnectorFailure. + """ + + # The stage at which this file was retrieved + completion_stage: DriveRetrievalStage + + # The file that was retrieved + drive_file: GoogleDriveFileType + + # The email of the user that the file was retrieved by impersonating + user_email: str + + # The id of the parent folder or drive of the file + parent_id: str | None = None + + # Any unexpected error that occurred while retrieving the file. + # In particular, this is not used for 403/404 errors, which are expected + # in the context of impersonating all the users to try to retrieve all + # files from all their Drives and Folders. + error: Exception | None = None + + model_config = ConfigDict(arbitrary_types_allowed=True) diff --git a/common/data_source/google_drive/section_extraction.py b/common/data_source/google_drive/section_extraction.py new file mode 100644 index 00000000000..ed672fb39ca --- /dev/null +++ b/common/data_source/google_drive/section_extraction.py @@ -0,0 +1,183 @@ +from typing import Any + +from pydantic import BaseModel + +from common.data_source.google_util.resource import GoogleDocsService +from common.data_source.models import TextSection + +HEADING_DELIMITER = "\n" + + +class CurrentHeading(BaseModel): + id: str | None + text: str + + +def get_document_sections( + docs_service: GoogleDocsService, + doc_id: str, +) -> list[TextSection]: + """Extracts sections from a Google Doc, including their headings and content""" + # Fetch the document structure + http_request = docs_service.documents().get(documentId=doc_id) + + # Google has poor support for tabs in the docs api, see + # https://cloud.google.com/python/docs/reference/cloudtasks/ + # latest/google.cloud.tasks_v2.types.HttpRequest + # https://developers.google.com/workspace/docs/api/how-tos/tabs + # https://developers.google.com/workspace/docs/api/reference/rest/v1/documents/get + # this is a hack to use the param mentioned in the rest api docs + # TODO: check if it can be specified i.e. in documents() + http_request.uri += "&includeTabsContent=true" + doc = http_request.execute() + + # Get the content + tabs = doc.get("tabs", {}) + sections: list[TextSection] = [] + for tab in tabs: + sections.extend(get_tab_sections(tab, doc_id)) + return sections + + +def _is_heading(paragraph: dict[str, Any]) -> bool: + """Checks if a paragraph (a block of text in a drive document) is a heading""" + if not ("paragraphStyle" in paragraph and "namedStyleType" in paragraph["paragraphStyle"]): + return False + + style = paragraph["paragraphStyle"]["namedStyleType"] + is_heading = style.startswith("HEADING_") + is_title = style.startswith("TITLE") + return is_heading or is_title + + +def _add_finished_section( + sections: list[TextSection], + doc_id: str, + tab_id: str, + current_heading: CurrentHeading, + current_section: list[str], +) -> None: + """Adds a finished section to the list of sections if the section has content. + Returns the list of sections to use going forward, which may be the old list + if a new section was not added. + """ + if not (current_section or current_heading.text): + return + # If we were building a previous section, add it to sections list + + # this is unlikely to ever matter, but helps if the doc contains weird headings + header_text = current_heading.text.replace(HEADING_DELIMITER, "") + section_text = f"{header_text}{HEADING_DELIMITER}" + "\n".join(current_section) + sections.append( + TextSection( + text=section_text.strip(), + link=_build_gdoc_section_link(doc_id, tab_id, current_heading.id), + ) + ) + + +def _build_gdoc_section_link(doc_id: str, tab_id: str, heading_id: str | None) -> str: + """Builds a Google Doc link that jumps to a specific heading""" + # NOTE: doesn't support docs with multiple tabs atm, if we need that ask + # @Chris + heading_str = f"#heading={heading_id}" if heading_id else "" + return f"https://docs.google.com/document/d/{doc_id}/edit?tab={tab_id}{heading_str}" + + +def _extract_id_from_heading(paragraph: dict[str, Any]) -> str: + """Extracts the id from a heading paragraph element""" + return paragraph["paragraphStyle"]["headingId"] + + +def _extract_text_from_paragraph(paragraph: dict[str, Any]) -> str: + """Extracts the text content from a paragraph element""" + text_elements = [] + for element in paragraph.get("elements", []): + if "textRun" in element: + text_elements.append(element["textRun"].get("content", "")) + + # Handle links + if "textStyle" in element and "link" in element["textStyle"]: + text_elements.append(f"({element['textStyle']['link'].get('url', '')})") + + if "person" in element: + name = element["person"].get("personProperties", {}).get("name", "") + email = element["person"].get("personProperties", {}).get("email", "") + person_str = " str: + """ + Extracts the text content from a table element. + """ + row_strs = [] + + for row in table.get("tableRows", []): + cells = row.get("tableCells", []) + cell_strs = [] + for cell in cells: + child_elements = cell.get("content", {}) + cell_str = [] + for child_elem in child_elements: + if "paragraph" not in child_elem: + continue + cell_str.append(_extract_text_from_paragraph(child_elem["paragraph"])) + cell_strs.append("".join(cell_str)) + row_strs.append(", ".join(cell_strs)) + return "\n".join(row_strs) + + +def get_tab_sections(tab: dict[str, Any], doc_id: str) -> list[TextSection]: + tab_id = tab["tabProperties"]["tabId"] + content = tab.get("documentTab", {}).get("body", {}).get("content", []) + + sections: list[TextSection] = [] + current_section: list[str] = [] + current_heading = CurrentHeading(id=None, text="") + + for element in content: + if "paragraph" in element: + paragraph = element["paragraph"] + + # If this is not a heading, add content to current section + if not _is_heading(paragraph): + text = _extract_text_from_paragraph(paragraph) + if text.strip(): + current_section.append(text) + continue + + _add_finished_section(sections, doc_id, tab_id, current_heading, current_section) + + current_section = [] + + # Start new heading + heading_id = _extract_id_from_heading(paragraph) + heading_text = _extract_text_from_paragraph(paragraph) + current_heading = CurrentHeading( + id=heading_id, + text=heading_text, + ) + elif "table" in element: + text = _extract_text_from_table(element["table"]) + if text.strip(): + current_section.append(text) + + # Don't forget to add the last section + _add_finished_section(sections, doc_id, tab_id, current_heading, current_section) + + return sections diff --git a/common/data_source/google_util/__init__.py b/common/data_source/google_util/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/common/data_source/google_util/auth.py b/common/data_source/google_util/auth.py new file mode 100644 index 00000000000..85c2e6c828e --- /dev/null +++ b/common/data_source/google_util/auth.py @@ -0,0 +1,157 @@ +import json +import logging +from typing import Any + +from google.auth.transport.requests import Request # type: ignore +from google.oauth2.credentials import Credentials as OAuthCredentials # type: ignore # type: ignore +from google.oauth2.service_account import Credentials as ServiceAccountCredentials # type: ignore # type: ignore + +from common.data_source.config import OAUTH_GOOGLE_DRIVE_CLIENT_ID, OAUTH_GOOGLE_DRIVE_CLIENT_SECRET, DocumentSource +from common.data_source.google_util.constant import ( + DB_CREDENTIALS_AUTHENTICATION_METHOD, + DB_CREDENTIALS_DICT_SERVICE_ACCOUNT_KEY, + DB_CREDENTIALS_DICT_TOKEN_KEY, + DB_CREDENTIALS_PRIMARY_ADMIN_KEY, + GOOGLE_SCOPES, + GoogleOAuthAuthenticationMethod, +) +from common.data_source.google_util.oauth_flow import ensure_oauth_token_dict + + +def sanitize_oauth_credentials(oauth_creds: OAuthCredentials) -> str: + """we really don't want to be persisting the client id and secret anywhere but the + environment. + + Returns a string of serialized json. + """ + + # strip the client id and secret + oauth_creds_json_str = oauth_creds.to_json() + oauth_creds_sanitized_json: dict[str, Any] = json.loads(oauth_creds_json_str) + oauth_creds_sanitized_json.pop("client_id", None) + oauth_creds_sanitized_json.pop("client_secret", None) + oauth_creds_sanitized_json_str = json.dumps(oauth_creds_sanitized_json) + return oauth_creds_sanitized_json_str + + +def get_google_creds( + credentials: dict[str, str], + source: DocumentSource, +) -> tuple[ServiceAccountCredentials | OAuthCredentials, dict[str, str] | None]: + """Checks for two different types of credentials. + (1) A credential which holds a token acquired via a user going through + the Google OAuth flow. + (2) A credential which holds a service account key JSON file, which + can then be used to impersonate any user in the workspace. + + Return a tuple where: + The first element is the requested credentials + The second element is a new credentials dict that the caller should write back + to the db. This happens if token rotation occurs while loading credentials. + """ + oauth_creds = None + service_creds = None + new_creds_dict = None + if DB_CREDENTIALS_DICT_TOKEN_KEY in credentials: + # OAUTH + authentication_method: str = credentials.get( + DB_CREDENTIALS_AUTHENTICATION_METHOD, + GoogleOAuthAuthenticationMethod.UPLOADED, + ) + + credentials_dict_str = credentials[DB_CREDENTIALS_DICT_TOKEN_KEY] + credentials_dict = json.loads(credentials_dict_str) + + regenerated_from_client_secret = False + if "client_id" not in credentials_dict or "client_secret" not in credentials_dict or "refresh_token" not in credentials_dict: + try: + credentials_dict = ensure_oauth_token_dict(credentials_dict, source) + except Exception as exc: + raise PermissionError( + "Google Drive OAuth credentials are incomplete. Please finish the OAuth flow to generate access tokens." + ) from exc + credentials_dict_str = json.dumps(credentials_dict) + regenerated_from_client_secret = True + + # only send what get_google_oauth_creds needs + authorized_user_info = {} + + # oauth_interactive is sanitized and needs credentials from the environment + if authentication_method == GoogleOAuthAuthenticationMethod.OAUTH_INTERACTIVE: + authorized_user_info["client_id"] = OAUTH_GOOGLE_DRIVE_CLIENT_ID + authorized_user_info["client_secret"] = OAUTH_GOOGLE_DRIVE_CLIENT_SECRET + else: + authorized_user_info["client_id"] = credentials_dict["client_id"] + authorized_user_info["client_secret"] = credentials_dict["client_secret"] + + authorized_user_info["refresh_token"] = credentials_dict["refresh_token"] + + authorized_user_info["token"] = credentials_dict["token"] + authorized_user_info["expiry"] = credentials_dict["expiry"] + + token_json_str = json.dumps(authorized_user_info) + oauth_creds = get_google_oauth_creds(token_json_str=token_json_str, source=source) + + # tell caller to update token stored in DB if the refresh token changed + if oauth_creds: + should_persist = regenerated_from_client_secret or oauth_creds.refresh_token != authorized_user_info["refresh_token"] + if should_persist: + # if oauth_interactive, sanitize the credentials so they don't get stored in the db + if authentication_method == GoogleOAuthAuthenticationMethod.OAUTH_INTERACTIVE: + oauth_creds_json_str = sanitize_oauth_credentials(oauth_creds) + else: + oauth_creds_json_str = oauth_creds.to_json() + + new_creds_dict = { + DB_CREDENTIALS_DICT_TOKEN_KEY: oauth_creds_json_str, + DB_CREDENTIALS_PRIMARY_ADMIN_KEY: credentials[DB_CREDENTIALS_PRIMARY_ADMIN_KEY], + DB_CREDENTIALS_AUTHENTICATION_METHOD: authentication_method, + } + elif DB_CREDENTIALS_DICT_SERVICE_ACCOUNT_KEY in credentials: + # SERVICE ACCOUNT + service_account_key_json_str = credentials[DB_CREDENTIALS_DICT_SERVICE_ACCOUNT_KEY] + service_account_key = json.loads(service_account_key_json_str) + + service_creds = ServiceAccountCredentials.from_service_account_info(service_account_key, scopes=GOOGLE_SCOPES[source]) + + if not service_creds.valid or not service_creds.expired: + service_creds.refresh(Request()) + + if not service_creds.valid: + raise PermissionError(f"Unable to access {source} - service account credentials are invalid.") + + creds: ServiceAccountCredentials | OAuthCredentials | None = oauth_creds or service_creds + if creds is None: + raise PermissionError(f"Unable to access {source} - unknown credential structure.") + + return creds, new_creds_dict + + +def get_google_oauth_creds(token_json_str: str, source: DocumentSource) -> OAuthCredentials | None: + """creds_json only needs to contain client_id, client_secret and refresh_token to + refresh the creds. + + expiry and token are optional ... however, if passing in expiry, token + should also be passed in or else we may not return any creds. + (probably a sign we should refactor the function) + """ + + creds_json = json.loads(token_json_str) + creds = OAuthCredentials.from_authorized_user_info( + info=creds_json, + scopes=GOOGLE_SCOPES[source], + ) + if creds.valid: + return creds + + if creds.expired and creds.refresh_token: + try: + creds.refresh(Request()) + if creds.valid: + logging.info("Refreshed Google Drive tokens.") + return creds + except Exception: + logging.exception("Failed to refresh google drive access token") + return None + + return None diff --git a/common/data_source/google_util/constant.py b/common/data_source/google_util/constant.py new file mode 100644 index 00000000000..8ab75fa141c --- /dev/null +++ b/common/data_source/google_util/constant.py @@ -0,0 +1,103 @@ +from enum import Enum + +from common.data_source.config import DocumentSource + +SLIM_BATCH_SIZE = 500 +# NOTE: do not need https://www.googleapis.com/auth/documents.readonly +# this is counted under `/auth/drive.readonly` +GOOGLE_SCOPES = { + DocumentSource.GOOGLE_DRIVE: [ + "https://www.googleapis.com/auth/drive.readonly", + "https://www.googleapis.com/auth/drive.metadata.readonly", + "https://www.googleapis.com/auth/admin.directory.group.readonly", + "https://www.googleapis.com/auth/admin.directory.user.readonly", + ], + DocumentSource.GMAIL: [ + "https://www.googleapis.com/auth/gmail.readonly", + "https://www.googleapis.com/auth/admin.directory.user.readonly", + "https://www.googleapis.com/auth/admin.directory.group.readonly", + ], +} + + +# This is the Oauth token +DB_CREDENTIALS_DICT_TOKEN_KEY = "google_tokens" +# This is the service account key +DB_CREDENTIALS_DICT_SERVICE_ACCOUNT_KEY = "google_service_account_key" +# The email saved for both auth types +DB_CREDENTIALS_PRIMARY_ADMIN_KEY = "google_primary_admin" + + +# https://developers.google.com/workspace/guides/create-credentials +# Internally defined authentication method type. +# The value must be one of "oauth_interactive" or "uploaded" +# Used to disambiguate whether credentials have already been created via +# certain methods and what actions we allow users to take +DB_CREDENTIALS_AUTHENTICATION_METHOD = "authentication_method" + + +class GoogleOAuthAuthenticationMethod(str, Enum): + OAUTH_INTERACTIVE = "oauth_interactive" + UPLOADED = "uploaded" + + +USER_FIELDS = "nextPageToken, users(primaryEmail)" + + +# Error message substrings +MISSING_SCOPES_ERROR_STR = "client not authorized for any of the scopes requested" +SCOPE_INSTRUCTIONS = "" + + +GOOGLE_DRIVE_WEB_OAUTH_POPUP_TEMPLATE = """ + + + + Google Drive Authorization + + + +
+

{heading}

+

{message}

+

You can close this window.

+
+ + + +""" diff --git a/common/data_source/google_util/oauth_flow.py b/common/data_source/google_util/oauth_flow.py new file mode 100644 index 00000000000..7e39e5283a4 --- /dev/null +++ b/common/data_source/google_util/oauth_flow.py @@ -0,0 +1,191 @@ +import json +import os +import threading +from typing import Any, Callable + +import requests + +from common.data_source.config import DocumentSource +from common.data_source.google_util.constant import GOOGLE_SCOPES + +GOOGLE_DEVICE_CODE_URL = "https://oauth2.googleapis.com/device/code" +GOOGLE_DEVICE_TOKEN_URL = "https://oauth2.googleapis.com/token" +DEFAULT_DEVICE_INTERVAL = 5 + + +def _get_requested_scopes(source: DocumentSource) -> list[str]: + """Return the scopes to request, honoring an optional override env var.""" + override = os.environ.get("GOOGLE_OAUTH_SCOPE_OVERRIDE", "") + if override.strip(): + scopes = [scope.strip() for scope in override.split(",") if scope.strip()] + if scopes: + return scopes + return GOOGLE_SCOPES[source] + + +def _get_oauth_timeout_secs() -> int: + raw_timeout = os.environ.get("GOOGLE_OAUTH_FLOW_TIMEOUT_SECS", "300").strip() + try: + timeout = int(raw_timeout) + except ValueError: + timeout = 300 + return timeout + + +def _run_with_timeout(func: Callable[[], Any], timeout_secs: int, timeout_message: str) -> Any: + if timeout_secs <= 0: + return func() + + result: dict[str, Any] = {} + error: dict[str, BaseException] = {} + + def _target() -> None: + try: + result["value"] = func() + except BaseException as exc: # pragma: no cover + error["error"] = exc + + thread = threading.Thread(target=_target, daemon=True) + thread.start() + thread.join(timeout_secs) + if thread.is_alive(): + raise TimeoutError(timeout_message) + if "error" in error: + raise error["error"] + return result.get("value") + + +def _extract_client_info(credentials: dict[str, Any]) -> tuple[str, str | None]: + if "client_id" in credentials: + return credentials["client_id"], credentials.get("client_secret") + for key in ("installed", "web"): + if key in credentials and isinstance(credentials[key], dict): + nested = credentials[key] + if "client_id" not in nested: + break + return nested["client_id"], nested.get("client_secret") + raise ValueError("Provided Google OAuth credentials are missing client_id.") + + +def start_device_authorization_flow( + credentials: dict[str, Any], + source: DocumentSource, +) -> tuple[dict[str, Any], dict[str, Any]]: + client_id, client_secret = _extract_client_info(credentials) + data = { + "client_id": client_id, + "scope": " ".join(_get_requested_scopes(source)), + } + if client_secret: + data["client_secret"] = client_secret + resp = requests.post(GOOGLE_DEVICE_CODE_URL, data=data, timeout=15) + resp.raise_for_status() + payload = resp.json() + state = { + "client_id": client_id, + "client_secret": client_secret, + "device_code": payload.get("device_code"), + "interval": payload.get("interval", DEFAULT_DEVICE_INTERVAL), + } + response_data = { + "user_code": payload.get("user_code"), + "verification_url": payload.get("verification_url") or payload.get("verification_uri"), + "verification_url_complete": payload.get("verification_url_complete") + or payload.get("verification_uri_complete"), + "expires_in": payload.get("expires_in"), + "interval": state["interval"], + } + return state, response_data + + +def poll_device_authorization_flow(state: dict[str, Any]) -> dict[str, Any]: + data = { + "client_id": state["client_id"], + "device_code": state["device_code"], + "grant_type": "urn:ietf:params:oauth:grant-type:device_code", + } + if state.get("client_secret"): + data["client_secret"] = state["client_secret"] + resp = requests.post(GOOGLE_DEVICE_TOKEN_URL, data=data, timeout=20) + resp.raise_for_status() + return resp.json() + + +def _run_local_server_flow(client_config: dict[str, Any], source: DocumentSource) -> dict[str, Any]: + """Launch the standard Google OAuth local-server flow to mint user tokens.""" + from google_auth_oauthlib.flow import InstalledAppFlow # type: ignore + + scopes = _get_requested_scopes(source) + flow = InstalledAppFlow.from_client_config( + client_config, + scopes=scopes, + ) + + open_browser = os.environ.get("GOOGLE_OAUTH_OPEN_BROWSER", "true").lower() != "false" + preferred_port = os.environ.get("GOOGLE_OAUTH_LOCAL_SERVER_PORT") + port = int(preferred_port) if preferred_port else 0 + timeout_secs = _get_oauth_timeout_secs() + timeout_message = ( + f"Google OAuth verification timed out after {timeout_secs} seconds. " + "Close any pending consent windows and rerun the connector configuration to try again." + ) + + print("Launching Google OAuth flow. A browser window should open shortly.") + print("If it does not, copy the URL shown in the console into your browser manually.") + if timeout_secs > 0: + print(f"You have {timeout_secs} seconds to finish granting access before the request times out.") + + try: + creds = _run_with_timeout( + lambda: flow.run_local_server(port=port, open_browser=open_browser, prompt="consent"), + timeout_secs, + timeout_message, + ) + except OSError as exc: + allow_console = os.environ.get("GOOGLE_OAUTH_ALLOW_CONSOLE_FALLBACK", "true").lower() != "false" + if not allow_console: + raise + print(f"Local server flow failed ({exc}). Falling back to console-based auth.") + creds = _run_with_timeout(flow.run_console, timeout_secs, timeout_message) + except Warning as warning: + warning_msg = str(warning) + if "Scope has changed" in warning_msg: + instructions = [ + "Google rejected one or more of the requested OAuth scopes.", + "Fix options:", + " 1. In Google Cloud Console, open APIs & Services > OAuth consent screen and add the missing scopes " + " (Drive metadata + Admin Directory read scopes), then re-run the flow.", + " 2. Set GOOGLE_OAUTH_SCOPE_OVERRIDE to a comma-separated list of scopes you are allowed to request.", + " 3. For quick local testing only, export OAUTHLIB_RELAX_TOKEN_SCOPE=1 to accept the reduced scopes " + " (be aware the connector may lose functionality).", + ] + raise RuntimeError("\n".join(instructions)) from warning + raise + + token_dict: dict[str, Any] = json.loads(creds.to_json()) + + print("\nGoogle OAuth flow completed successfully.") + print("Copy the JSON blob below into GOOGLE_DRIVE_OAUTH_CREDENTIALS_JSON_STR to reuse these tokens without re-authenticating:\n") + print(json.dumps(token_dict, indent=2)) + print() + + return token_dict + + +def ensure_oauth_token_dict(credentials: dict[str, Any], source: DocumentSource) -> dict[str, Any]: + """Return a dict that contains OAuth tokens, running the flow if only a client config is provided.""" + if "refresh_token" in credentials and "token" in credentials: + return credentials + + client_config: dict[str, Any] | None = None + if "installed" in credentials: + client_config = {"installed": credentials["installed"]} + elif "web" in credentials: + client_config = {"web": credentials["web"]} + + if client_config is None: + raise ValueError( + "Provided Google OAuth credentials are missing both tokens and a client configuration." + ) + + return _run_local_server_flow(client_config, source) diff --git a/common/data_source/google_util/resource.py b/common/data_source/google_util/resource.py new file mode 100644 index 00000000000..fa598c1c0f7 --- /dev/null +++ b/common/data_source/google_util/resource.py @@ -0,0 +1,120 @@ +import logging +from collections.abc import Callable +from typing import Any + +from google.auth.exceptions import RefreshError # type: ignore +from google.oauth2.credentials import Credentials as OAuthCredentials # type: ignore # type: ignore +from google.oauth2.service_account import Credentials as ServiceAccountCredentials # type: ignore # type: ignore +from googleapiclient.discovery import ( + Resource, # type: ignore + build, # type: ignore +) + + +class GoogleDriveService(Resource): + pass + + +class GoogleDocsService(Resource): + pass + + +class AdminService(Resource): + pass + + +class GmailService(Resource): + pass + + +class RefreshableDriveObject: + """ + Running Google drive service retrieval functions + involves accessing methods of the service object (ie. files().list()) + which can raise a RefreshError if the access token is expired. + This class is a wrapper that propagates the ability to refresh the access token + and retry the final retrieval function until execute() is called. + """ + + def __init__( + self, + call_stack: Callable[[ServiceAccountCredentials | OAuthCredentials], Any], + creds: ServiceAccountCredentials | OAuthCredentials, + creds_getter: Callable[..., ServiceAccountCredentials | OAuthCredentials], + ): + self.call_stack = call_stack + self.creds = creds + self.creds_getter = creds_getter + + def __getattr__(self, name: str) -> Any: + if name == "execute": + return self.make_refreshable_execute() + return RefreshableDriveObject( + lambda creds: getattr(self.call_stack(creds), name), + self.creds, + self.creds_getter, + ) + + def __call__(self, *args: Any, **kwargs: Any) -> Any: + return RefreshableDriveObject( + lambda creds: self.call_stack(creds)(*args, **kwargs), + self.creds, + self.creds_getter, + ) + + def make_refreshable_execute(self) -> Callable: + def execute(*args: Any, **kwargs: Any) -> Any: + try: + return self.call_stack(self.creds).execute(*args, **kwargs) + except RefreshError as e: + logging.warning(f"RefreshError, going to attempt a creds refresh and retry: {e}") + # Refresh the access token + self.creds = self.creds_getter() + return self.call_stack(self.creds).execute(*args, **kwargs) + + return execute + + +def _get_google_service( + service_name: str, + service_version: str, + creds: ServiceAccountCredentials | OAuthCredentials, + user_email: str | None = None, +) -> GoogleDriveService | GoogleDocsService | AdminService | GmailService: + service: Resource + if isinstance(creds, ServiceAccountCredentials): + # NOTE: https://developers.google.com/identity/protocols/oauth2/service-account#error-codes + creds = creds.with_subject(user_email) + service = build(service_name, service_version, credentials=creds) + elif isinstance(creds, OAuthCredentials): + service = build(service_name, service_version, credentials=creds) + + return service + + +def get_google_docs_service( + creds: ServiceAccountCredentials | OAuthCredentials, + user_email: str | None = None, +) -> GoogleDocsService: + return _get_google_service("docs", "v1", creds, user_email) + + +def get_drive_service( + creds: ServiceAccountCredentials | OAuthCredentials, + user_email: str | None = None, +) -> GoogleDriveService: + return _get_google_service("drive", "v3", creds, user_email) + + +def get_admin_service( + creds: ServiceAccountCredentials | OAuthCredentials, + user_email: str | None = None, +) -> AdminService: + return _get_google_service("admin", "directory_v1", creds, user_email) + + +def get_gmail_service( + creds: ServiceAccountCredentials | OAuthCredentials, + user_email: str | None = None, +) -> GmailService: + return _get_google_service("gmail", "v1", creds, user_email) diff --git a/common/data_source/google_util/util.py b/common/data_source/google_util/util.py new file mode 100644 index 00000000000..bc1a581ed6d --- /dev/null +++ b/common/data_source/google_util/util.py @@ -0,0 +1,152 @@ +import logging +import socket +from collections.abc import Callable, Iterator +from enum import Enum +from typing import Any + +from googleapiclient.errors import HttpError # type: ignore # type: ignore + +from common.data_source.google_drive.model import GoogleDriveFileType + + +# See https://developers.google.com/drive/api/reference/rest/v3/files/list for more +class GoogleFields(str, Enum): + ID = "id" + CREATED_TIME = "createdTime" + MODIFIED_TIME = "modifiedTime" + NAME = "name" + SIZE = "size" + PARENTS = "parents" + + +NEXT_PAGE_TOKEN_KEY = "nextPageToken" +PAGE_TOKEN_KEY = "pageToken" +ORDER_BY_KEY = "orderBy" + + +def get_file_owners(file: GoogleDriveFileType, primary_admin_email: str) -> list[str]: + """ + Get the owners of a file if the attribute is present. + """ + return [email for owner in file.get("owners", []) if (email := owner.get("emailAddress")) and email.split("@")[-1] == primary_admin_email.split("@")[-1]] + + +# included for type purposes; caller should not need to address +# Nones unless max_num_pages is specified. Use +# execute_paginated_retrieval_with_max_pages instead if you want +# the early stop + yield None after max_num_pages behavior. +def execute_paginated_retrieval( + retrieval_function: Callable, + list_key: str | None = None, + continue_on_404_or_403: bool = False, + **kwargs: Any, +) -> Iterator[GoogleDriveFileType]: + for item in _execute_paginated_retrieval( + retrieval_function, + list_key, + continue_on_404_or_403, + **kwargs, + ): + if not isinstance(item, str): + yield item + + +def execute_paginated_retrieval_with_max_pages( + retrieval_function: Callable, + max_num_pages: int, + list_key: str | None = None, + continue_on_404_or_403: bool = False, + **kwargs: Any, +) -> Iterator[GoogleDriveFileType | str]: + yield from _execute_paginated_retrieval( + retrieval_function, + list_key, + continue_on_404_or_403, + max_num_pages=max_num_pages, + **kwargs, + ) + + +def _execute_paginated_retrieval( + retrieval_function: Callable, + list_key: str | None = None, + continue_on_404_or_403: bool = False, + max_num_pages: int | None = None, + **kwargs: Any, +) -> Iterator[GoogleDriveFileType | str]: + """Execute a paginated retrieval from Google Drive API + Args: + retrieval_function: The specific list function to call (e.g., service.files().list) + list_key: If specified, each object returned by the retrieval function + will be accessed at the specified key and yielded from. + continue_on_404_or_403: If True, the retrieval will continue even if the request returns a 404 or 403 error. + max_num_pages: If specified, the retrieval will stop after the specified number of pages and yield None. + **kwargs: Arguments to pass to the list function + """ + if "fields" not in kwargs or "nextPageToken" not in kwargs["fields"]: + raise ValueError("fields must contain nextPageToken for execute_paginated_retrieval") + next_page_token = kwargs.get(PAGE_TOKEN_KEY, "") + num_pages = 0 + while next_page_token is not None: + if max_num_pages is not None and num_pages >= max_num_pages: + yield next_page_token + return + num_pages += 1 + request_kwargs = kwargs.copy() + if next_page_token: + request_kwargs[PAGE_TOKEN_KEY] = next_page_token + results = _execute_single_retrieval( + retrieval_function, + continue_on_404_or_403, + **request_kwargs, + ) + + next_page_token = results.get(NEXT_PAGE_TOKEN_KEY) + if list_key: + for item in results.get(list_key, []): + yield item + else: + yield results + + +def _execute_single_retrieval( + retrieval_function: Callable, + continue_on_404_or_403: bool = False, + **request_kwargs: Any, +) -> GoogleDriveFileType: + """Execute a single retrieval from Google Drive API""" + try: + results = retrieval_function(**request_kwargs).execute() + except HttpError as e: + if e.resp.status >= 500: + results = retrieval_function() + elif e.resp.status == 400: + if "pageToken" in request_kwargs and "Invalid Value" in str(e) and "pageToken" in str(e): + logging.warning(f"Invalid page token: {request_kwargs['pageToken']}, retrying from start of request") + request_kwargs.pop("pageToken") + return _execute_single_retrieval( + retrieval_function, + continue_on_404_or_403, + **request_kwargs, + ) + logging.error(f"Error executing request: {e}") + raise e + elif e.resp.status == 404 or e.resp.status == 403: + if continue_on_404_or_403: + logging.debug(f"Error executing request: {e}") + results = {} + else: + raise e + elif e.resp.status == 429: + results = retrieval_function() + else: + logging.exception("Error executing request:") + raise e + except (TimeoutError, socket.timeout) as error: + logging.warning( + "Timed out executing Google API request; retrying with backoff. Details: %s", + error, + ) + results = retrieval_function() + + return results diff --git a/common/data_source/google_util/util_threadpool_concurrency.py b/common/data_source/google_util/util_threadpool_concurrency.py new file mode 100644 index 00000000000..6e9ccd1e288 --- /dev/null +++ b/common/data_source/google_util/util_threadpool_concurrency.py @@ -0,0 +1,141 @@ +import collections.abc +import copy +import threading +from collections.abc import Callable, Iterator, MutableMapping +from typing import Any, TypeVar, overload + +from pydantic import GetCoreSchemaHandler +from pydantic_core import core_schema + +R = TypeVar("R") +KT = TypeVar("KT") # Key type +VT = TypeVar("VT") # Value type +_T = TypeVar("_T") # Default type + + +class ThreadSafeDict(MutableMapping[KT, VT]): + """ + A thread-safe dictionary implementation that uses a lock to ensure thread safety. + Implements the MutableMapping interface to provide a complete dictionary-like interface. + + Example usage: + # Create a thread-safe dictionary + safe_dict: ThreadSafeDict[str, int] = ThreadSafeDict() + + # Basic operations (atomic) + safe_dict["key"] = 1 + value = safe_dict["key"] + del safe_dict["key"] + + # Bulk operations (atomic) + safe_dict.update({"key1": 1, "key2": 2}) + """ + + def __init__(self, input_dict: dict[KT, VT] | None = None) -> None: + self._dict: dict[KT, VT] = input_dict or {} + self.lock = threading.Lock() + + def __getitem__(self, key: KT) -> VT: + with self.lock: + return self._dict[key] + + def __setitem__(self, key: KT, value: VT) -> None: + with self.lock: + self._dict[key] = value + + def __delitem__(self, key: KT) -> None: + with self.lock: + del self._dict[key] + + def __iter__(self) -> Iterator[KT]: + # Return a snapshot of keys to avoid potential modification during iteration + with self.lock: + return iter(list(self._dict.keys())) + + def __len__(self) -> int: + with self.lock: + return len(self._dict) + + @classmethod + def __get_pydantic_core_schema__(cls, source_type: Any, handler: GetCoreSchemaHandler) -> core_schema.CoreSchema: + return core_schema.no_info_after_validator_function(cls.validate, handler(dict[KT, VT])) + + @classmethod + def validate(cls, v: Any) -> "ThreadSafeDict[KT, VT]": + if isinstance(v, dict): + return ThreadSafeDict(v) + return v + + def __deepcopy__(self, memo: Any) -> "ThreadSafeDict[KT, VT]": + return ThreadSafeDict(copy.deepcopy(self._dict)) + + def clear(self) -> None: + """Remove all items from the dictionary atomically.""" + with self.lock: + self._dict.clear() + + def copy(self) -> dict[KT, VT]: + """Return a shallow copy of the dictionary atomically.""" + with self.lock: + return self._dict.copy() + + @overload + def get(self, key: KT) -> VT | None: ... + + @overload + def get(self, key: KT, default: VT | _T) -> VT | _T: ... + + def get(self, key: KT, default: Any = None) -> Any: + """Get a value with a default, atomically.""" + with self.lock: + return self._dict.get(key, default) + + def pop(self, key: KT, default: Any = None) -> Any: + """Remove and return a value with optional default, atomically.""" + with self.lock: + if default is None: + return self._dict.pop(key) + return self._dict.pop(key, default) + + def setdefault(self, key: KT, default: VT) -> VT: + """Set a default value if key is missing, atomically.""" + with self.lock: + return self._dict.setdefault(key, default) + + def update(self, *args: Any, **kwargs: VT) -> None: + """Update the dictionary atomically from another mapping or from kwargs.""" + with self.lock: + self._dict.update(*args, **kwargs) + + def items(self) -> collections.abc.ItemsView[KT, VT]: + """Return a view of (key, value) pairs atomically.""" + with self.lock: + return collections.abc.ItemsView(self) + + def keys(self) -> collections.abc.KeysView[KT]: + """Return a view of keys atomically.""" + with self.lock: + return collections.abc.KeysView(self) + + def values(self) -> collections.abc.ValuesView[VT]: + """Return a view of values atomically.""" + with self.lock: + return collections.abc.ValuesView(self) + + @overload + def atomic_get_set(self, key: KT, value_callback: Callable[[VT], VT], default: VT) -> tuple[VT, VT]: ... + + @overload + def atomic_get_set(self, key: KT, value_callback: Callable[[VT | _T], VT], default: VT | _T) -> tuple[VT | _T, VT]: ... + + def atomic_get_set(self, key: KT, value_callback: Callable[[Any], VT], default: Any = None) -> tuple[Any, VT]: + """Replace a value from the dict with a function applied to the previous value, atomically. + + Returns: + A tuple of the previous value and the new value. + """ + with self.lock: + val = self._dict.get(key, default) + new_val = value_callback(val) + self._dict[key] = new_val + return val, new_val diff --git a/common/data_source/html_utils.py b/common/data_source/html_utils.py new file mode 100644 index 00000000000..5f548c631d4 --- /dev/null +++ b/common/data_source/html_utils.py @@ -0,0 +1,219 @@ +import logging +import re +from copy import copy +from dataclasses import dataclass +from io import BytesIO +from typing import IO + +import bs4 + +from common.data_source.config import HTML_BASED_CONNECTOR_TRANSFORM_LINKS_STRATEGY, \ + HtmlBasedConnectorTransformLinksStrategy, WEB_CONNECTOR_IGNORED_CLASSES, WEB_CONNECTOR_IGNORED_ELEMENTS, \ + PARSE_WITH_TRAFILATURA + +MINTLIFY_UNWANTED = ["sticky", "hidden"] + + +@dataclass +class ParsedHTML: + title: str | None + cleaned_text: str + + +def strip_excessive_newlines_and_spaces(document: str) -> str: + # collapse repeated spaces into one + document = re.sub(r" +", " ", document) + # remove trailing spaces + document = re.sub(r" +[\n\r]", "\n", document) + # remove repeated newlines + document = re.sub(r"[\n\r]+", "\n", document) + return document.strip() + + +def strip_newlines(document: str) -> str: + # HTML might contain newlines which are just whitespaces to a browser + return re.sub(r"[\n\r]+", " ", document) + + +def format_element_text(element_text: str, link_href: str | None) -> str: + element_text_no_newlines = strip_newlines(element_text) + + if ( + not link_href + or HTML_BASED_CONNECTOR_TRANSFORM_LINKS_STRATEGY + == HtmlBasedConnectorTransformLinksStrategy.STRIP + ): + return element_text_no_newlines + + return f"[{element_text_no_newlines}]({link_href})" + + +def parse_html_with_trafilatura(html_content: str) -> str: + """Parse HTML content using trafilatura.""" + import trafilatura # type: ignore + from trafilatura.settings import use_config # type: ignore + + config = use_config() + config.set("DEFAULT", "include_links", "True") + config.set("DEFAULT", "include_tables", "True") + config.set("DEFAULT", "include_images", "True") + config.set("DEFAULT", "include_formatting", "True") + + extracted_text = trafilatura.extract(html_content, config=config) + return strip_excessive_newlines_and_spaces(extracted_text) if extracted_text else "" + + +def format_document_soup( + document: bs4.BeautifulSoup, table_cell_separator: str = "\t" +) -> str: + """Format html to a flat text document. + + The following goals: + - Newlines from within the HTML are removed (as browser would ignore them as well). + - Repeated newlines/spaces are removed (as browsers would ignore them). + - Newlines only before and after headlines and paragraphs or when explicit (br or pre tag) + - Table columns/rows are separated by newline + - List elements are separated by newline and start with a hyphen + """ + text = "" + list_element_start = False + verbatim_output = 0 + in_table = False + last_added_newline = False + link_href: str | None = None + + for e in document.descendants: + verbatim_output -= 1 + if isinstance(e, bs4.element.NavigableString): + if isinstance(e, (bs4.element.Comment, bs4.element.Doctype)): + continue + element_text = e.text + if in_table: + # Tables are represented in natural language with rows separated by newlines + # Can't have newlines then in the table elements + element_text = element_text.replace("\n", " ").strip() + + # Some tags are translated to spaces but in the logic underneath this section, we + # translate them to newlines as a browser should render them such as with br + # This logic here avoids a space after newline when it shouldn't be there. + if last_added_newline and element_text.startswith(" "): + element_text = element_text[1:] + last_added_newline = False + + if element_text: + content_to_add = ( + element_text + if verbatim_output > 0 + else format_element_text(element_text, link_href) + ) + + # Don't join separate elements without any spacing + if (text and not text[-1].isspace()) and ( + content_to_add and not content_to_add[0].isspace() + ): + text += " " + + text += content_to_add + + list_element_start = False + elif isinstance(e, bs4.element.Tag): + # table is standard HTML element + if e.name == "table": + in_table = True + # tr is for rows + elif e.name == "tr" and in_table: + text += "\n" + # td for data cell, th for header + elif e.name in ["td", "th"] and in_table: + text += table_cell_separator + elif e.name == "/table": + in_table = False + elif in_table: + # don't handle other cases while in table + pass + elif e.name == "a": + href_value = e.get("href", None) + # mostly for typing, having multiple hrefs is not valid HTML + link_href = ( + href_value[0] if isinstance(href_value, list) else href_value + ) + elif e.name == "/a": + link_href = None + elif e.name in ["p", "div"]: + if not list_element_start: + text += "\n" + elif e.name in ["h1", "h2", "h3", "h4"]: + text += "\n" + list_element_start = False + last_added_newline = True + elif e.name == "br": + text += "\n" + list_element_start = False + last_added_newline = True + elif e.name == "li": + text += "\n- " + list_element_start = True + elif e.name == "pre": + if verbatim_output <= 0: + verbatim_output = len(list(e.childGenerator())) + return strip_excessive_newlines_and_spaces(text) + + +def parse_html_page_basic(text: str | BytesIO | IO[bytes]) -> str: + soup = bs4.BeautifulSoup(text, "html.parser") + return format_document_soup(soup) + + +def web_html_cleanup( + page_content: str | bs4.BeautifulSoup, + mintlify_cleanup_enabled: bool = True, + additional_element_types_to_discard: list[str] | None = None, +) -> ParsedHTML: + if isinstance(page_content, str): + soup = bs4.BeautifulSoup(page_content, "html.parser") + else: + soup = page_content + + title_tag = soup.find("title") + title = None + if title_tag and title_tag.text: + title = title_tag.text + title_tag.extract() + + # Heuristics based cleaning of elements based on css classes + unwanted_classes = copy(WEB_CONNECTOR_IGNORED_CLASSES) + if mintlify_cleanup_enabled: + unwanted_classes.extend(MINTLIFY_UNWANTED) + for undesired_element in unwanted_classes: + [ + tag.extract() + for tag in soup.find_all( + class_=lambda x: x and undesired_element in x.split() + ) + ] + + for undesired_tag in WEB_CONNECTOR_IGNORED_ELEMENTS: + [tag.extract() for tag in soup.find_all(undesired_tag)] + + if additional_element_types_to_discard: + for undesired_tag in additional_element_types_to_discard: + [tag.extract() for tag in soup.find_all(undesired_tag)] + + soup_string = str(soup) + page_text = "" + + if PARSE_WITH_TRAFILATURA: + try: + page_text = parse_html_with_trafilatura(soup_string) + if not page_text: + raise ValueError("Empty content returned by trafilatura.") + except Exception as e: + logging.info(f"Trafilatura parsing failed: {e}. Falling back on bs4.") + page_text = format_document_soup(soup) + else: + page_text = format_document_soup(soup) + + # 200B is ZeroWidthSpace which we don't care for + cleaned_text = page_text.replace("\u200b", "") + + return ParsedHTML(title=title, cleaned_text=cleaned_text) diff --git a/common/data_source/interfaces.py b/common/data_source/interfaces.py new file mode 100644 index 00000000000..9c5f00141f3 --- /dev/null +++ b/common/data_source/interfaces.py @@ -0,0 +1,412 @@ +"""Interface definitions""" +import abc +import uuid +from abc import ABC, abstractmethod +from enum import IntFlag, auto +from types import TracebackType +from typing import Any, Dict, Generator, TypeVar, Generic, Callable, TypeAlias + +from anthropic import BaseModel + +from common.data_source.models import ( + Document, + SlimDocument, + ConnectorCheckpoint, + ConnectorFailure, + SecondsSinceUnixEpoch, GenerateSlimDocumentOutput +) + + +class LoadConnector(ABC): + """Load connector interface""" + + @abstractmethod + def load_credentials(self, credentials: Dict[str, Any]) -> Dict[str, Any] | None: + """Load credentials""" + pass + + @abstractmethod + def load_from_state(self) -> Generator[list[Document], None, None]: + """Load documents from state""" + pass + + @abstractmethod + def validate_connector_settings(self) -> None: + """Validate connector settings""" + pass + + +class PollConnector(ABC): + """Poll connector interface""" + + @abstractmethod + def poll_source(self, start: SecondsSinceUnixEpoch, end: SecondsSinceUnixEpoch) -> Generator[list[Document], None, None]: + """Poll source to get documents""" + pass + + +class CredentialsConnector(ABC): + """Credentials connector interface""" + + @abstractmethod + def load_credentials(self, credentials: Dict[str, Any]) -> Dict[str, Any] | None: + """Load credentials""" + pass + + +class SlimConnectorWithPermSync(ABC): + """Simplified connector interface (with permission sync)""" + + @abstractmethod + def retrieve_all_slim_docs_perm_sync( + self, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + callback: Any = None, + ) -> Generator[list[SlimDocument], None, None]: + """Retrieve all simplified documents (with permission sync)""" + pass + + +class CheckpointedConnectorWithPermSync(ABC): + """Checkpointed connector interface (with permission sync)""" + + @abstractmethod + def load_from_checkpoint( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: ConnectorCheckpoint, + ) -> Generator[Document | ConnectorFailure, None, ConnectorCheckpoint]: + """Load documents from checkpoint""" + pass + + @abstractmethod + def load_from_checkpoint_with_perm_sync( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: ConnectorCheckpoint, + ) -> Generator[Document | ConnectorFailure, None, ConnectorCheckpoint]: + """Load documents from checkpoint (with permission sync)""" + pass + + @abstractmethod + def build_dummy_checkpoint(self) -> ConnectorCheckpoint: + """Build dummy checkpoint""" + pass + + @abstractmethod + def validate_checkpoint_json(self, checkpoint_json: str) -> ConnectorCheckpoint: + """Validate checkpoint JSON""" + pass + + +T = TypeVar("T", bound="CredentialsProviderInterface") + + +class CredentialsProviderInterface(abc.ABC, Generic[T]): + @abc.abstractmethod + def __enter__(self) -> T: + raise NotImplementedError + + @abc.abstractmethod + def __exit__( + self, + exc_type: type[BaseException] | None, + exc_value: BaseException | None, + traceback: TracebackType | None, + ) -> None: + raise NotImplementedError + + @abc.abstractmethod + def get_tenant_id(self) -> str | None: + raise NotImplementedError + + @abc.abstractmethod + def get_provider_key(self) -> str: + """a unique key that the connector can use to lock around a credential + that might be used simultaneously. + + Will typically be the credential id, but can also just be something random + in cases when there is nothing to lock (aka static credentials) + """ + raise NotImplementedError + + @abc.abstractmethod + def get_credentials(self) -> dict[str, Any]: + raise NotImplementedError + + @abc.abstractmethod + def set_credentials(self, credential_json: dict[str, Any]) -> None: + raise NotImplementedError + + @abc.abstractmethod + def is_dynamic(self) -> bool: + """If dynamic, the credentials may change during usage ... maening the client + needs to use the locking features of the credentials provider to operate + correctly. + + If static, the client can simply reference the credentials once and use them + through the entire indexing run. + """ + raise NotImplementedError + + +class StaticCredentialsProvider( + CredentialsProviderInterface["StaticCredentialsProvider"] +): + """Implementation (a very simple one!) to handle static credentials.""" + + def __init__( + self, + tenant_id: str | None, + connector_name: str, + credential_json: dict[str, Any], + ): + self._tenant_id = tenant_id + self._connector_name = connector_name + self._credential_json = credential_json + + self._provider_key = str(uuid.uuid4()) + + def __enter__(self) -> "StaticCredentialsProvider": + return self + + def __exit__( + self, + exc_type: type[BaseException] | None, + exc_value: BaseException | None, + traceback: TracebackType | None, + ) -> None: + pass + + def get_tenant_id(self) -> str | None: + return self._tenant_id + + def get_provider_key(self) -> str: + return self._provider_key + + def get_credentials(self) -> dict[str, Any]: + return self._credential_json + + def set_credentials(self, credential_json: dict[str, Any]) -> None: + self._credential_json = credential_json + + def is_dynamic(self) -> bool: + return False + + +CT = TypeVar("CT", bound=ConnectorCheckpoint) + + +class BaseConnector(abc.ABC, Generic[CT]): + REDIS_KEY_PREFIX = "da_connector_data:" + # Common image file extensions supported across connectors + IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".webp", ".gif"} + + @abc.abstractmethod + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: + raise NotImplementedError + + @staticmethod + def parse_metadata(metadata: dict[str, Any]) -> list[str]: + """Parse the metadata for a document/chunk into a string to pass to Generative AI as additional context""" + custom_parser_req_msg = ( + "Specific metadata parsing required, connector has not implemented it." + ) + metadata_lines = [] + for metadata_key, metadata_value in metadata.items(): + if isinstance(metadata_value, str): + metadata_lines.append(f"{metadata_key}: {metadata_value}") + elif isinstance(metadata_value, list): + if not all([isinstance(val, str) for val in metadata_value]): + raise RuntimeError(custom_parser_req_msg) + metadata_lines.append(f'{metadata_key}: {", ".join(metadata_value)}') + else: + raise RuntimeError(custom_parser_req_msg) + return metadata_lines + + def validate_connector_settings(self) -> None: + """ + Override this if your connector needs to validate credentials or settings. + Raise an exception if invalid, otherwise do nothing. + + Default is a no-op (always successful). + """ + + def validate_perm_sync(self) -> None: + """ + Don't override this; add a function to perm_sync_valid.py in the ee package + to do permission sync validation + """ + """ + validate_connector_settings_fn = fetch_ee_implementation_or_noop( + "onyx.connectors.perm_sync_valid", + "validate_perm_sync", + noop_return_value=None, + ) + validate_connector_settings_fn(self)""" + + def set_allow_images(self, value: bool) -> None: + """Implement if the underlying connector wants to skip/allow image downloading + based on the application level image analysis setting.""" + + def build_dummy_checkpoint(self) -> CT: + # TODO: find a way to make this work without type: ignore + return ConnectorCheckpoint(has_more=True) # type: ignore + + +CheckpointOutput: TypeAlias = Generator[Document | ConnectorFailure, None, CT] +LoadFunction = Callable[[CT], CheckpointOutput[CT]] + + +class CheckpointedConnector(BaseConnector[CT]): + @abc.abstractmethod + def load_from_checkpoint( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: CT, + ) -> CheckpointOutput[CT]: + """Yields back documents or failures. Final return is the new checkpoint. + + Final return can be access via either: + + ``` + try: + for document_or_failure in connector.load_from_checkpoint(start, end, checkpoint): + print(document_or_failure) + except StopIteration as e: + checkpoint = e.value # Extracting the return value + print(checkpoint) + ``` + + OR + + ``` + checkpoint = yield from connector.load_from_checkpoint(start, end, checkpoint) + ``` + """ + raise NotImplementedError + + @abc.abstractmethod + def build_dummy_checkpoint(self) -> CT: + raise NotImplementedError + + @abc.abstractmethod + def validate_checkpoint_json(self, checkpoint_json: str) -> CT: + """Validate the checkpoint json and return the checkpoint object""" + raise NotImplementedError + + +class CheckpointOutputWrapper(Generic[CT]): + """ + Wraps a CheckpointOutput generator to give things back in a more digestible format, + specifically for Document outputs. + The connector format is easier for the connector implementor (e.g. it enforces exactly + one new checkpoint is returned AND that the checkpoint is at the end), thus the different + formats. + """ + + def __init__(self) -> None: + self.next_checkpoint: CT | None = None + + def __call__( + self, + checkpoint_connector_generator: CheckpointOutput[CT], + ) -> Generator[ + tuple[Document | None, ConnectorFailure | None, CT | None], + None, + None, + ]: + # grabs the final return value and stores it in the `next_checkpoint` variable + def _inner_wrapper( + checkpoint_connector_generator: CheckpointOutput[CT], + ) -> CheckpointOutput[CT]: + self.next_checkpoint = yield from checkpoint_connector_generator + return self.next_checkpoint # not used + + for document_or_failure in _inner_wrapper(checkpoint_connector_generator): + if isinstance(document_or_failure, Document): + yield document_or_failure, None, None + elif isinstance(document_or_failure, ConnectorFailure): + yield None, document_or_failure, None + else: + raise ValueError( + f"Invalid document_or_failure type: {type(document_or_failure)}" + ) + + if self.next_checkpoint is None: + raise RuntimeError( + "Checkpoint is None. This should never happen - the connector should always return a checkpoint." + ) + + yield None, None, self.next_checkpoint + + +# Slim connectors retrieve just the ids of documents +class SlimConnector(BaseConnector): + @abc.abstractmethod + def retrieve_all_slim_docs( + self, + ) -> GenerateSlimDocumentOutput: + raise NotImplementedError + + +class ConfluenceUser(BaseModel): + user_id: str # accountId in Cloud, userKey in Server + username: str | None # Confluence Cloud doesn't give usernames + display_name: str + # Confluence Data Center doesn't give email back by default, + # have to fetch it with a different endpoint + email: str | None + type: str + + +class TokenResponse(BaseModel): + access_token: str + expires_in: int + token_type: str + refresh_token: str + scope: str + + +class OnyxExtensionType(IntFlag): + Plain = auto() + Document = auto() + Multimedia = auto() + All = Plain | Document | Multimedia + + +class AttachmentProcessingResult(BaseModel): + """ + A container for results after processing a Confluence attachment. + 'text' is the textual content of the attachment. + 'file_name' is the final file name used in FileStore to store the content. + 'error' holds an exception or string if something failed. + """ + + text: str | None + file_blob: bytes | bytearray | None + file_name: str | None + error: str | None = None + + model_config = {"arbitrary_types_allowed": True} + + +class IndexingHeartbeatInterface(ABC): + """Defines a callback interface to be passed to + to run_indexing_entrypoint.""" + + @abstractmethod + def should_stop(self) -> bool: + """Signal to stop the looping function in flight.""" + + @abstractmethod + def progress(self, tag: str, amount: int) -> None: + """Send progress updates to the caller. + Amount can be a positive number to indicate progress or <= 0 + just to act as a keep-alive. + """ + diff --git a/common/data_source/jira_connector.py b/common/data_source/jira_connector.py new file mode 100644 index 00000000000..4d6f1160e57 --- /dev/null +++ b/common/data_source/jira_connector.py @@ -0,0 +1,112 @@ +"""Jira connector""" + +from typing import Any + +from jira import JIRA + +from common.data_source.config import INDEX_BATCH_SIZE +from common.data_source.exceptions import ( + ConnectorValidationError, + InsufficientPermissionsError, + UnexpectedValidationError, ConnectorMissingCredentialError +) +from common.data_source.interfaces import ( + CheckpointedConnectorWithPermSync, + SecondsSinceUnixEpoch, + SlimConnectorWithPermSync +) +from common.data_source.models import ( + ConnectorCheckpoint +) + + +class JiraConnector(CheckpointedConnectorWithPermSync, SlimConnectorWithPermSync): + """Jira connector for accessing Jira issues and projects""" + + def __init__(self, batch_size: int = INDEX_BATCH_SIZE) -> None: + self.batch_size = batch_size + self.jira_client: JIRA | None = None + + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: + """Load Jira credentials""" + try: + url = credentials.get("url") + username = credentials.get("username") + password = credentials.get("password") + token = credentials.get("token") + + if not url: + raise ConnectorMissingCredentialError("Jira URL is required") + + if token: + # API token authentication + self.jira_client = JIRA(server=url, token_auth=token) + elif username and password: + # Basic authentication + self.jira_client = JIRA(server=url, basic_auth=(username, password)) + else: + raise ConnectorMissingCredentialError("Jira credentials are incomplete") + + return None + except Exception as e: + raise ConnectorMissingCredentialError(f"Jira: {e}") + + def validate_connector_settings(self) -> None: + """Validate Jira connector settings""" + if not self.jira_client: + raise ConnectorMissingCredentialError("Jira") + + try: + # Test connection by getting server info + self.jira_client.server_info() + except Exception as e: + if "401" in str(e) or "403" in str(e): + raise InsufficientPermissionsError("Invalid credentials or insufficient permissions") + elif "404" in str(e): + raise ConnectorValidationError("Jira instance not found") + else: + raise UnexpectedValidationError(f"Jira validation error: {e}") + + def poll_source(self, start: SecondsSinceUnixEpoch, end: SecondsSinceUnixEpoch) -> Any: + """Poll Jira for recent issues""" + # Simplified implementation - in production this would handle actual polling + return [] + + def load_from_checkpoint( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: ConnectorCheckpoint, + ) -> Any: + """Load documents from checkpoint""" + # Simplified implementation + return [] + + def load_from_checkpoint_with_perm_sync( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: ConnectorCheckpoint, + ) -> Any: + """Load documents from checkpoint with permission sync""" + # Simplified implementation + return [] + + def build_dummy_checkpoint(self) -> ConnectorCheckpoint: + """Build dummy checkpoint""" + return ConnectorCheckpoint() + + def validate_checkpoint_json(self, checkpoint_json: str) -> ConnectorCheckpoint: + """Validate checkpoint JSON""" + # Simplified implementation + return ConnectorCheckpoint() + + def retrieve_all_slim_docs_perm_sync( + self, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + callback: Any = None, + ) -> Any: + """Retrieve all simplified documents with permission sync""" + # Simplified implementation + return [] \ No newline at end of file diff --git a/common/data_source/models.py b/common/data_source/models.py new file mode 100644 index 00000000000..032f26cc8d9 --- /dev/null +++ b/common/data_source/models.py @@ -0,0 +1,308 @@ +"""Data model definitions for all connectors""" +from dataclasses import dataclass +from datetime import datetime +from typing import Any, Optional, List, Sequence, NamedTuple +from typing_extensions import TypedDict, NotRequired +from pydantic import BaseModel + + +@dataclass(frozen=True) +class ExternalAccess: + + # arbitrary limit to prevent excessively large permissions sets + # not internally enforced ... the caller can check this before using the instance + MAX_NUM_ENTRIES = 5000 + + # Emails of external users with access to the doc externally + external_user_emails: set[str] + # Names or external IDs of groups with access to the doc + external_user_group_ids: set[str] + # Whether the document is public in the external system or Onyx + is_public: bool + + def __str__(self) -> str: + """Prevent extremely long logs""" + + def truncate_set(s: set[str], max_len: int = 100) -> str: + s_str = str(s) + if len(s_str) > max_len: + return f"{s_str[:max_len]}... ({len(s)} items)" + return s_str + + return ( + f"ExternalAccess(" + f"external_user_emails={truncate_set(self.external_user_emails)}, " + f"external_user_group_ids={truncate_set(self.external_user_group_ids)}, " + f"is_public={self.is_public})" + ) + + @property + def num_entries(self) -> int: + return len(self.external_user_emails) + len(self.external_user_group_ids) + + @classmethod + def public(cls) -> "ExternalAccess": + return cls( + external_user_emails=set(), + external_user_group_ids=set(), + is_public=True, + ) + + @classmethod + def empty(cls) -> "ExternalAccess": + """ + A helper function that returns an *empty* set of external user-emails and group-ids, and sets `is_public` to `False`. + This effectively makes the document in question "private" or inaccessible to anyone else. + + This is especially helpful to use when you are performing permission-syncing, and some document's permissions aren't able + to be determined (for whatever reason). Setting its `ExternalAccess` to "private" is a feasible fallback. + """ + + return cls( + external_user_emails=set(), + external_user_group_ids=set(), + is_public=False, + ) + + +class ExtractionResult(NamedTuple): + """Structured result from text and image extraction from various file types.""" + + text_content: str + embedded_images: Sequence[tuple[bytes, str]] + metadata: dict[str, Any] + + +class TextSection(BaseModel): + """Text section model""" + link: str + text: str + + +class ImageSection(BaseModel): + """Image section model""" + link: str + image_file_id: str + + +class Document(BaseModel): + """Document model""" + id: str + source: str + semantic_identifier: str + extension: str + blob: bytes + doc_updated_at: datetime + size_bytes: int + + +class BasicExpertInfo(BaseModel): + """Expert information model""" + display_name: Optional[str] = None + first_name: Optional[str] = None + last_name: Optional[str] = None + email: Optional[str] = None + + def get_semantic_name(self) -> str: + """Get semantic name for display""" + if self.display_name: + return self.display_name + elif self.first_name and self.last_name: + return f"{self.first_name} {self.last_name}" + elif self.first_name: + return self.first_name + elif self.last_name: + return self.last_name + else: + return "Unknown" + + +class SlimDocument(BaseModel): + """Simplified document model (contains only ID and permission info)""" + id: str + external_access: Optional[Any] = None + + +class ConnectorCheckpoint(BaseModel): + """Connector checkpoint model""" + has_more: bool = True + + +class DocumentFailure(BaseModel): + """Document processing failure information""" + document_id: str + document_link: str + + +class EntityFailure(BaseModel): + """Entity processing failure information""" + entity_id: str + missed_time_range: tuple[datetime, datetime] + + +class ConnectorFailure(BaseModel): + """Connector failure information""" + failed_document: Optional[DocumentFailure] = None + failed_entity: Optional[EntityFailure] = None + failure_message: str + exception: Optional[Exception] = None + + model_config = {"arbitrary_types_allowed": True} + + +# Gmail Models +class GmailCredentials(BaseModel): + """Gmail authentication credentials model""" + primary_admin_email: str + credentials: dict[str, Any] + + +class GmailThread(BaseModel): + """Gmail thread data model""" + id: str + messages: list[dict[str, Any]] + + +class GmailMessage(BaseModel): + """Gmail message data model""" + id: str + payload: dict[str, Any] + label_ids: Optional[list[str]] = None + + +# Notion Models +class NotionPage(BaseModel): + """Represents a Notion Page object""" + id: str + created_time: str + last_edited_time: str + archived: bool + properties: dict[str, Any] + url: str + database_name: Optional[str] = None # Only applicable to database type pages + + +class NotionBlock(BaseModel): + """Represents a Notion Block object""" + id: str # Used for the URL + text: str + prefix: str # How this block should be joined with existing text + + +class NotionSearchResponse(BaseModel): + """Represents the response from the Notion Search API""" + results: list[dict[str, Any]] + next_cursor: Optional[str] + has_more: bool = False + + +class NotionCredentials(BaseModel): + """Notion authentication credentials model""" + integration_token: str + + +# Slack Models +class ChannelTopicPurposeType(TypedDict): + """Slack channel topic or purpose""" + value: str + creator: str + last_set: int + + +class ChannelType(TypedDict): + """Slack channel""" + id: str + name: str + is_channel: bool + is_group: bool + is_im: bool + created: int + creator: str + is_archived: bool + is_general: bool + unlinked: int + name_normalized: str + is_shared: bool + is_ext_shared: bool + is_org_shared: bool + pending_shared: List[str] + is_pending_ext_shared: bool + is_member: bool + is_private: bool + is_mpim: bool + updated: int + topic: ChannelTopicPurposeType + purpose: ChannelTopicPurposeType + previous_names: List[str] + num_members: int + + +class AttachmentType(TypedDict): + """Slack message attachment""" + service_name: NotRequired[str] + text: NotRequired[str] + fallback: NotRequired[str] + thumb_url: NotRequired[str] + thumb_width: NotRequired[int] + thumb_height: NotRequired[int] + id: NotRequired[int] + + +class BotProfileType(TypedDict): + """Slack bot profile""" + id: NotRequired[str] + deleted: NotRequired[bool] + name: NotRequired[str] + updated: NotRequired[int] + app_id: NotRequired[str] + team_id: NotRequired[str] + + +class MessageType(TypedDict): + """Slack message""" + type: str + user: str + text: str + ts: str + attachments: NotRequired[List[AttachmentType]] + bot_id: NotRequired[str] + app_id: NotRequired[str] + bot_profile: NotRequired[BotProfileType] + thread_ts: NotRequired[str] + subtype: NotRequired[str] + + +# Thread message list +ThreadType = List[MessageType] + + +class SlackCheckpoint(TypedDict): + """Slack checkpoint""" + channel_ids: List[str] | None + channel_completion_map: dict[str, str] + current_channel: ChannelType | None + current_channel_access: Any | None + seen_thread_ts: List[str] + has_more: bool + + +class SlackMessageFilterReason(str): + """Slack message filter reason""" + BOT = "bot" + DISALLOWED = "disallowed" + + +class ProcessedSlackMessage: + """Processed Slack message""" + def __init__(self, doc=None, thread_or_message_ts=None, filter_reason=None, failure=None): + self.doc = doc + self.thread_or_message_ts = thread_or_message_ts + self.filter_reason = filter_reason + self.failure = failure + + +# Type aliases for type hints +SecondsSinceUnixEpoch = float +GenerateDocumentsOutput = Any +GenerateSlimDocumentOutput = Any +CheckpointOutput = Any diff --git a/common/data_source/notion_connector.py b/common/data_source/notion_connector.py new file mode 100644 index 00000000000..8c6a522ad42 --- /dev/null +++ b/common/data_source/notion_connector.py @@ -0,0 +1,428 @@ +import logging +from collections.abc import Generator +from typing import Any, Optional +from retry import retry + +from common.data_source.config import ( + INDEX_BATCH_SIZE, + DocumentSource, NOTION_CONNECTOR_DISABLE_RECURSIVE_PAGE_LOOKUP +) +from common.data_source.interfaces import ( + LoadConnector, + PollConnector, + SecondsSinceUnixEpoch +) +from common.data_source.models import ( + Document, + TextSection, GenerateDocumentsOutput +) +from common.data_source.exceptions import ( + ConnectorValidationError, + CredentialExpiredError, + InsufficientPermissionsError, + UnexpectedValidationError, ConnectorMissingCredentialError +) +from common.data_source.models import ( + NotionPage, + NotionBlock, + NotionSearchResponse +) +from common.data_source.utils import ( + rl_requests, + batch_generator, + fetch_notion_data, + properties_to_str, + filter_pages_by_time, datetime_from_string +) + + +class NotionConnector(LoadConnector, PollConnector): + """Notion Page connector that reads all Notion pages this integration has access to. + + Arguments: + batch_size (int): Number of objects to index in a batch + recursive_index_enabled (bool): Whether to recursively index child pages + root_page_id (str | None): Specific root page ID to start indexing from + """ + + def __init__( + self, + batch_size: int = INDEX_BATCH_SIZE, + recursive_index_enabled: bool = not NOTION_CONNECTOR_DISABLE_RECURSIVE_PAGE_LOOKUP, + root_page_id: Optional[str] = None, + ) -> None: + self.batch_size = batch_size + self.headers = { + "Content-Type": "application/json", + "Notion-Version": "2022-06-28", + } + self.indexed_pages: set[str] = set() + self.root_page_id = root_page_id + self.recursive_index_enabled = recursive_index_enabled or bool(root_page_id) + + @retry(tries=3, delay=1, backoff=2) + def _fetch_child_blocks( + self, block_id: str, cursor: Optional[str] = None + ) -> dict[str, Any] | None: + """Fetch all child blocks via the Notion API.""" + logging.debug(f"Fetching children of block with ID '{block_id}'") + block_url = f"https://api.notion.com/v1/blocks/{block_id}/children" + query_params = {"start_cursor": cursor} if cursor else None + + try: + response = rl_requests.get( + block_url, + headers=self.headers, + params=query_params, + timeout=30, + ) + response.raise_for_status() + return response.json() + except Exception as e: + if hasattr(e, 'response') and e.response.status_code == 404: + logging.error( + f"Unable to access block with ID '{block_id}'. " + f"This is likely due to the block not being shared with the integration." + ) + return None + else: + logging.exception(f"Error fetching blocks: {e}") + raise + + @retry(tries=3, delay=1, backoff=2) + def _fetch_page(self, page_id: str) -> NotionPage: + """Fetch a page from its ID via the Notion API.""" + logging.debug(f"Fetching page for ID '{page_id}'") + page_url = f"https://api.notion.com/v1/pages/{page_id}" + + try: + data = fetch_notion_data(page_url, self.headers, "GET") + return NotionPage(**data) + except Exception as e: + logging.warning(f"Failed to fetch page, trying database for ID '{page_id}': {e}") + return self._fetch_database_as_page(page_id) + + @retry(tries=3, delay=1, backoff=2) + def _fetch_database_as_page(self, database_id: str) -> NotionPage: + """Attempt to fetch a database as a page.""" + logging.debug(f"Fetching database for ID '{database_id}' as a page") + database_url = f"https://api.notion.com/v1/databases/{database_id}" + + data = fetch_notion_data(database_url, self.headers, "GET") + database_name = data.get("title") + database_name = ( + database_name[0].get("text", {}).get("content") if database_name else None + ) + + return NotionPage(**data, database_name=database_name) + + @retry(tries=3, delay=1, backoff=2) + def _fetch_database( + self, database_id: str, cursor: Optional[str] = None + ) -> dict[str, Any]: + """Fetch a database from its ID via the Notion API.""" + logging.debug(f"Fetching database for ID '{database_id}'") + block_url = f"https://api.notion.com/v1/databases/{database_id}/query" + body = {"start_cursor": cursor} if cursor else None + + try: + data = fetch_notion_data(block_url, self.headers, "POST", body) + return data + except Exception as e: + if hasattr(e, 'response') and e.response.status_code in [404, 400]: + logging.error( + f"Unable to access database with ID '{database_id}'. " + f"This is likely due to the database not being shared with the integration." + ) + return {"results": [], "next_cursor": None} + raise + + def _read_pages_from_database( + self, database_id: str + ) -> tuple[list[NotionBlock], list[str]]: + """Returns a list of top level blocks and all page IDs in the database.""" + result_blocks: list[NotionBlock] = [] + result_pages: list[str] = [] + cursor = None + + while True: + data = self._fetch_database(database_id, cursor) + + for result in data["results"]: + obj_id = result["id"] + obj_type = result["object"] + text = properties_to_str(result.get("properties", {})) + + if text: + result_blocks.append(NotionBlock(id=obj_id, text=text, prefix="\n")) + + if self.recursive_index_enabled: + if obj_type == "page": + logging.debug(f"Found page with ID '{obj_id}' in database '{database_id}'") + result_pages.append(result["id"]) + elif obj_type == "database": + logging.debug(f"Found database with ID '{obj_id}' in database '{database_id}'") + _, child_pages = self._read_pages_from_database(obj_id) + result_pages.extend(child_pages) + + if data["next_cursor"] is None: + break + + cursor = data["next_cursor"] + + return result_blocks, result_pages + + def _read_blocks(self, base_block_id: str) -> tuple[list[NotionBlock], list[str]]: + """Reads all child blocks for the specified block, returns blocks and child page ids.""" + result_blocks: list[NotionBlock] = [] + child_pages: list[str] = [] + cursor = None + + while True: + data = self._fetch_child_blocks(base_block_id, cursor) + + if data is None: + return result_blocks, child_pages + + for result in data["results"]: + logging.debug(f"Found child block for block with ID '{base_block_id}': {result}") + result_block_id = result["id"] + result_type = result["type"] + result_obj = result[result_type] + + if result_type in ["ai_block", "unsupported", "external_object_instance_page"]: + logging.warning(f"Skipping unsupported block type '{result_type}'") + continue + + cur_result_text_arr = [] + if "rich_text" in result_obj: + for rich_text in result_obj["rich_text"]: + if "text" in rich_text: + text = rich_text["text"]["content"] + cur_result_text_arr.append(text) + + if result["has_children"]: + if result_type == "child_page": + child_pages.append(result_block_id) + else: + logging.debug(f"Entering sub-block: {result_block_id}") + subblocks, subblock_child_pages = self._read_blocks(result_block_id) + logging.debug(f"Finished sub-block: {result_block_id}") + result_blocks.extend(subblocks) + child_pages.extend(subblock_child_pages) + + if result_type == "child_database": + inner_blocks, inner_child_pages = self._read_pages_from_database(result_block_id) + result_blocks.extend(inner_blocks) + + if self.recursive_index_enabled: + child_pages.extend(inner_child_pages) + + if cur_result_text_arr: + new_block = NotionBlock( + id=result_block_id, + text="\n".join(cur_result_text_arr), + prefix="\n", + ) + result_blocks.append(new_block) + + if data["next_cursor"] is None: + break + + cursor = data["next_cursor"] + + return result_blocks, child_pages + + def _read_page_title(self, page: NotionPage) -> Optional[str]: + """Extracts the title from a Notion page.""" + if hasattr(page, "database_name") and page.database_name: + return page.database_name + + for _, prop in page.properties.items(): + if prop["type"] == "title" and len(prop["title"]) > 0: + page_title = " ".join([t["plain_text"] for t in prop["title"]]).strip() + return page_title + + return None + + def _read_pages( + self, pages: list[NotionPage] + ) -> Generator[Document, None, None]: + """Reads pages for rich text content and generates Documents.""" + all_child_page_ids: list[str] = [] + + for page in pages: + if isinstance(page, dict): + page = NotionPage(**page) + if page.id in self.indexed_pages: + logging.debug(f"Already indexed page with ID '{page.id}'. Skipping.") + continue + + logging.info(f"Reading page with ID '{page.id}', with url {page.url}") + page_blocks, child_page_ids = self._read_blocks(page.id) + all_child_page_ids.extend(child_page_ids) + self.indexed_pages.add(page.id) + + raw_page_title = self._read_page_title(page) + page_title = raw_page_title or f"Untitled Page with ID {page.id}" + + if not page_blocks: + if not raw_page_title: + logging.warning(f"No blocks OR title found for page with ID '{page.id}'. Skipping.") + continue + + text = page_title + if page.properties: + text += "\n\n" + "\n".join( + [f"{key}: {value}" for key, value in page.properties.items()] + ) + sections = [TextSection(link=page.url, text=text)] + else: + sections = [ + TextSection( + link=f"{page.url}#{block.id.replace('-', '')}", + text=block.prefix + block.text, + ) + for block in page_blocks + ] + + blob = ("\n".join([sec.text for sec in sections])).encode("utf-8") + yield Document( + id=page.id, + blob=blob, + source=DocumentSource.NOTION, + semantic_identifier=page_title, + extension=".txt", + size_bytes=len(blob), + doc_updated_at=datetime_from_string(page.last_edited_time) + ) + + if self.recursive_index_enabled and all_child_page_ids: + for child_page_batch_ids in batch_generator(all_child_page_ids, INDEX_BATCH_SIZE): + child_page_batch = [ + self._fetch_page(page_id) + for page_id in child_page_batch_ids + if page_id not in self.indexed_pages + ] + yield from self._read_pages(child_page_batch) + + @retry(tries=3, delay=1, backoff=2) + def _search_notion(self, query_dict: dict[str, Any]) -> NotionSearchResponse: + """Search for pages from a Notion database.""" + logging.debug(f"Searching for pages in Notion with query_dict: {query_dict}") + data = fetch_notion_data("https://api.notion.com/v1/search", self.headers, "POST", query_dict) + return NotionSearchResponse(**data) + + def _recursive_load(self) -> Generator[list[Document], None, None]: + """Recursively load pages starting from root page ID.""" + if self.root_page_id is None or not self.recursive_index_enabled: + raise RuntimeError("Recursive page lookup is not enabled") + + logging.info(f"Recursively loading pages from Notion based on root page with ID: {self.root_page_id}") + pages = [self._fetch_page(page_id=self.root_page_id)] + yield from batch_generator(self._read_pages(pages), self.batch_size) + + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: + """Applies integration token to headers.""" + self.headers["Authorization"] = f'Bearer {credentials["notion_integration_token"]}' + return None + + def load_from_state(self) -> GenerateDocumentsOutput: + """Loads all page data from a Notion workspace.""" + if self.recursive_index_enabled and self.root_page_id: + yield from self._recursive_load() + return + + query_dict = { + "filter": {"property": "object", "value": "page"}, + "page_size": 100, + } + + while True: + db_res = self._search_notion(query_dict) + pages = [NotionPage(**page) for page in db_res.results] + yield from batch_generator(self._read_pages(pages), self.batch_size) + + if db_res.has_more: + query_dict["start_cursor"] = db_res.next_cursor + else: + break + + def poll_source( + self, start: SecondsSinceUnixEpoch, end: SecondsSinceUnixEpoch + ) -> GenerateDocumentsOutput: + """Poll Notion for updated pages within a time period.""" + if self.recursive_index_enabled and self.root_page_id: + yield from self._recursive_load() + return + + query_dict = { + "page_size": 100, + "sort": {"timestamp": "last_edited_time", "direction": "descending"}, + "filter": {"property": "object", "value": "page"}, + } + + while True: + db_res = self._search_notion(query_dict) + pages = filter_pages_by_time(db_res.results, start, end, "last_edited_time") + + if pages: + yield from batch_generator(self._read_pages(pages), self.batch_size) + if db_res.has_more: + query_dict["start_cursor"] = db_res.next_cursor + else: + break + else: + break + + def validate_connector_settings(self) -> None: + """Validate Notion connector settings and credentials.""" + if not self.headers.get("Authorization"): + raise ConnectorMissingCredentialError("Notion credentials not loaded.") + + try: + if self.root_page_id: + response = rl_requests.get( + f"https://api.notion.com/v1/pages/{self.root_page_id}", + headers=self.headers, + timeout=30, + ) + else: + test_query = {"filter": {"property": "object", "value": "page"}, "page_size": 1} + response = rl_requests.post( + "https://api.notion.com/v1/search", + headers=self.headers, + json=test_query, + timeout=30, + ) + + response.raise_for_status() + + except rl_requests.exceptions.HTTPError as http_err: + status_code = http_err.response.status_code if http_err.response else None + + if status_code == 401: + raise CredentialExpiredError("Notion credential appears to be invalid or expired (HTTP 401).") + elif status_code == 403: + raise InsufficientPermissionsError("Your Notion token does not have sufficient permissions (HTTP 403).") + elif status_code == 404: + raise ConnectorValidationError("Notion resource not found or not shared with the integration (HTTP 404).") + elif status_code == 429: + raise ConnectorValidationError("Validation failed due to Notion rate-limits being exceeded (HTTP 429).") + else: + raise UnexpectedValidationError(f"Unexpected Notion HTTP error (status={status_code}): {http_err}") + + except Exception as exc: + raise UnexpectedValidationError(f"Unexpected error during Notion settings validation: {exc}") + + +if __name__ == "__main__": + import os + + root_page_id = os.environ.get("NOTION_ROOT_PAGE_ID") + connector = NotionConnector(root_page_id=root_page_id) + connector.load_credentials({"notion_integration_token": os.environ.get("NOTION_INTEGRATION_TOKEN")}) + document_batches = connector.load_from_state() + for doc_batch in document_batches: + for doc in doc_batch: + print(doc) diff --git a/common/data_source/sharepoint_connector.py b/common/data_source/sharepoint_connector.py new file mode 100644 index 00000000000..7bc8e3410dc --- /dev/null +++ b/common/data_source/sharepoint_connector.py @@ -0,0 +1,121 @@ +"""SharePoint connector""" + +from typing import Any +import msal +from office365.graph_client import GraphClient +from office365.runtime.client_request import ClientRequestException +from office365.sharepoint.client_context import ClientContext + +from common.data_source.config import INDEX_BATCH_SIZE +from common.data_source.exceptions import ConnectorValidationError, ConnectorMissingCredentialError +from common.data_source.interfaces import ( + CheckpointedConnectorWithPermSync, + SecondsSinceUnixEpoch, + SlimConnectorWithPermSync +) +from common.data_source.models import ( + ConnectorCheckpoint +) + + +class SharePointConnector(CheckpointedConnectorWithPermSync, SlimConnectorWithPermSync): + """SharePoint connector for accessing SharePoint sites and documents""" + + def __init__(self, batch_size: int = INDEX_BATCH_SIZE) -> None: + self.batch_size = batch_size + self.sharepoint_client = None + self.graph_client = None + + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: + """Load SharePoint credentials""" + try: + tenant_id = credentials.get("tenant_id") + client_id = credentials.get("client_id") + client_secret = credentials.get("client_secret") + site_url = credentials.get("site_url") + + if not all([tenant_id, client_id, client_secret, site_url]): + raise ConnectorMissingCredentialError("SharePoint credentials are incomplete") + + # Create MSAL confidential client + app = msal.ConfidentialClientApplication( + client_id=client_id, + client_credential=client_secret, + authority=f"https://login.microsoftonline.com/{tenant_id}" + ) + + # Get access token + result = app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"]) + + if "access_token" not in result: + raise ConnectorMissingCredentialError("Failed to acquire SharePoint access token") + + # Create Graph client + self.graph_client = GraphClient(result["access_token"]) + + # Create SharePoint client context + self.sharepoint_client = ClientContext(site_url).with_access_token(result["access_token"]) + + return None + except Exception as e: + raise ConnectorMissingCredentialError(f"SharePoint: {e}") + + def validate_connector_settings(self) -> None: + """Validate SharePoint connector settings""" + if not self.sharepoint_client or not self.graph_client: + raise ConnectorMissingCredentialError("SharePoint") + + try: + # Test connection by getting site info + site = self.sharepoint_client.site.get().execute_query() + if not site: + raise ConnectorValidationError("Failed to access SharePoint site") + except ClientRequestException as e: + if "401" in str(e) or "403" in str(e): + raise ConnectorValidationError("Invalid credentials or insufficient permissions") + else: + raise ConnectorValidationError(f"SharePoint validation error: {e}") + + def poll_source(self, start: SecondsSinceUnixEpoch, end: SecondsSinceUnixEpoch) -> Any: + """Poll SharePoint for recent documents""" + # Simplified implementation - in production this would handle actual polling + return [] + + def load_from_checkpoint( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: ConnectorCheckpoint, + ) -> Any: + """Load documents from checkpoint""" + # Simplified implementation + return [] + + def load_from_checkpoint_with_perm_sync( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: ConnectorCheckpoint, + ) -> Any: + """Load documents from checkpoint with permission sync""" + # Simplified implementation + return [] + + def build_dummy_checkpoint(self) -> ConnectorCheckpoint: + """Build dummy checkpoint""" + return ConnectorCheckpoint() + + def validate_checkpoint_json(self, checkpoint_json: str) -> ConnectorCheckpoint: + """Validate checkpoint JSON""" + # Simplified implementation + return ConnectorCheckpoint() + + def retrieve_all_slim_docs_perm_sync( + self, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + callback: Any = None, + ) -> Any: + """Retrieve all simplified documents with permission sync""" + # Simplified implementation + return [] \ No newline at end of file diff --git a/common/data_source/slack_connector.py b/common/data_source/slack_connector.py new file mode 100644 index 00000000000..b6aa80bdda6 --- /dev/null +++ b/common/data_source/slack_connector.py @@ -0,0 +1,670 @@ +"""Slack connector""" + +import itertools +import logging +import re +from collections.abc import Callable, Generator +from datetime import datetime, timezone +from http.client import IncompleteRead, RemoteDisconnected +from typing import Any, cast +from urllib.error import URLError + +from slack_sdk import WebClient +from slack_sdk.errors import SlackApiError +from slack_sdk.http_retry import ConnectionErrorRetryHandler +from slack_sdk.http_retry.builtin_interval_calculators import FixedValueRetryIntervalCalculator + +from common.data_source.config import ( + INDEX_BATCH_SIZE, SLACK_NUM_THREADS, ENABLE_EXPENSIVE_EXPERT_CALLS, + _SLACK_LIMIT, FAST_TIMEOUT, MAX_RETRIES, MAX_CHANNELS_TO_LOG +) +from common.data_source.exceptions import ( + ConnectorMissingCredentialError, + ConnectorValidationError, + CredentialExpiredError, + InsufficientPermissionsError, + UnexpectedValidationError +) +from common.data_source.interfaces import ( + CheckpointedConnectorWithPermSync, + CredentialsConnector, + SlimConnectorWithPermSync +) +from common.data_source.models import ( + BasicExpertInfo, + ConnectorCheckpoint, + ConnectorFailure, + Document, + DocumentFailure, + SlimDocument, + TextSection, + SecondsSinceUnixEpoch, + GenerateSlimDocumentOutput, MessageType, SlackMessageFilterReason, ChannelType, ThreadType, ProcessedSlackMessage, + CheckpointOutput +) +from common.data_source.utils import make_paginated_slack_api_call, SlackTextCleaner, expert_info_from_slack_id, \ + get_message_link + +# Disallowed message subtypes list +_DISALLOWED_MSG_SUBTYPES = { + "channel_join", "channel_leave", "channel_archive", "channel_unarchive", + "pinned_item", "unpinned_item", "ekm_access_denied", "channel_posting_permissions", + "group_join", "group_leave", "group_archive", "group_unarchive", + "channel_leave", "channel_name", "channel_join", +} + + +def default_msg_filter(message: MessageType) -> SlackMessageFilterReason | None: + """Default message filter""" + # Filter bot messages + if message.get("bot_id") or message.get("app_id"): + bot_profile_name = message.get("bot_profile", {}).get("name") + if bot_profile_name == "DanswerBot Testing": + return None + return SlackMessageFilterReason.BOT + + # Filter non-informative content + if message.get("subtype", "") in _DISALLOWED_MSG_SUBTYPES: + return SlackMessageFilterReason.DISALLOWED + + return None + + +def _collect_paginated_channels( + client: WebClient, + exclude_archived: bool, + channel_types: list[str], +) -> list[ChannelType]: + """收集分页的频道列表""" + channels: list[ChannelType] = [] + for result in make_paginated_slack_api_call( + client.conversations_list, + exclude_archived=exclude_archived, + types=channel_types, + ): + channels.extend(result["channels"]) + + return channels + + +def get_channels( + client: WebClient, + exclude_archived: bool = True, + get_public: bool = True, + get_private: bool = True, +) -> list[ChannelType]: + channel_types = [] + if get_public: + channel_types.append("public_channel") + if get_private: + channel_types.append("private_channel") + + # First try to get public and private channels + try: + channels = _collect_paginated_channels( + client=client, + exclude_archived=exclude_archived, + channel_types=channel_types, + ) + except SlackApiError as e: + msg = f"Unable to fetch private channels due to: {e}." + if not get_public: + logging.warning(msg + " Public channels are not enabled.") + return [] + + logging.warning(msg + " Trying again with public channels only.") + channel_types = ["public_channel"] + channels = _collect_paginated_channels( + client=client, + exclude_archived=exclude_archived, + channel_types=channel_types, + ) + return channels + + +def get_channel_messages( + client: WebClient, + channel: ChannelType, + oldest: str | None = None, + latest: str | None = None, + callback: Any = None, +) -> Generator[list[MessageType], None, None]: + """Get all messages in a channel""" + # Join channel so bot can access messages + if not channel["is_member"]: + client.conversations_join( + channel=channel["id"], + is_private=channel["is_private"], + ) + logging.info(f"Successfully joined '{channel['name']}'") + + for result in make_paginated_slack_api_call( + client.conversations_history, + channel=channel["id"], + oldest=oldest, + latest=latest, + ): + if callback: + if callback.should_stop(): + raise RuntimeError("get_channel_messages: Stop signal detected") + + callback.progress("get_channel_messages", 0) + yield cast(list[MessageType], result["messages"]) + + +def get_thread(client: WebClient, channel_id: str, thread_id: str) -> ThreadType: + threads: list[MessageType] = [] + for result in make_paginated_slack_api_call( + client.conversations_replies, channel=channel_id, ts=thread_id + ): + threads.extend(result["messages"]) + return threads + + +def get_latest_message_time(thread: ThreadType) -> datetime: + max_ts = max([float(msg.get("ts", 0)) for msg in thread]) + return datetime.fromtimestamp(max_ts, tz=timezone.utc) + + +def _build_doc_id(channel_id: str, thread_ts: str) -> str: + """构建文档ID""" + return f"{channel_id}__{thread_ts}" + + +def thread_to_doc( + channel: ChannelType, + thread: ThreadType, + slack_cleaner: SlackTextCleaner, + client: WebClient, + user_cache: dict[str, BasicExpertInfo | None], + channel_access: Any | None, +) -> Document: + """将线程转换为文档""" + channel_id = channel["id"] + + initial_sender_expert_info = expert_info_from_slack_id( + user_id=thread[0].get("user"), client=client, user_cache=user_cache + ) + initial_sender_name = ( + initial_sender_expert_info.get_semantic_name() + if initial_sender_expert_info + else "Unknown" + ) + + valid_experts = None + if ENABLE_EXPENSIVE_EXPERT_CALLS: + all_sender_ids = [m.get("user") for m in thread] + experts = [ + expert_info_from_slack_id( + user_id=sender_id, client=client, user_cache=user_cache + ) + for sender_id in all_sender_ids + if sender_id + ] + valid_experts = [expert for expert in experts if expert] + + first_message = slack_cleaner.index_clean(cast(str, thread[0]["text"])) + snippet = ( + first_message[:50].rstrip() + "..." + if len(first_message) > 50 + else first_message + ) + + doc_sem_id = f"{initial_sender_name} in #{channel['name']}: {snippet}".replace( + "\n", " " + ) + + return Document( + id=_build_doc_id(channel_id=channel_id, thread_ts=thread[0]["ts"]), + sections=[ + TextSection( + link=get_message_link(event=m, client=client, channel_id=channel_id), + text=slack_cleaner.index_clean(cast(str, m["text"])), + ) + for m in thread + ], + source="slack", + semantic_identifier=doc_sem_id, + doc_updated_at=get_latest_message_time(thread), + primary_owners=valid_experts, + metadata={"Channel": channel["name"]}, + external_access=channel_access, + ) + + +def filter_channels( + all_channels: list[ChannelType], + channels_to_connect: list[str] | None, + regex_enabled: bool, +) -> list[ChannelType]: + """过滤频道""" + if not channels_to_connect: + return all_channels + + if regex_enabled: + return [ + channel + for channel in all_channels + if any( + re.fullmatch(channel_to_connect, channel["name"]) + for channel_to_connect in channels_to_connect + ) + ] + + # Validate all specified channels are valid + all_channel_names = {channel["name"] for channel in all_channels} + for channel in channels_to_connect: + if channel not in all_channel_names: + raise ValueError( + f"Channel '{channel}' not found in workspace. " + f"Available channels (Showing {len(all_channel_names)} of " + f"{min(len(all_channel_names), MAX_CHANNELS_TO_LOG)}): " + f"{list(itertools.islice(all_channel_names, MAX_CHANNELS_TO_LOG))}" + ) + + return [ + channel for channel in all_channels if channel["name"] in channels_to_connect + ] + + +def _get_channel_by_id(client: WebClient, channel_id: str) -> ChannelType: + response = client.conversations_info( + channel=channel_id, + ) + return cast(ChannelType, response["channel"]) + + +def _get_messages( + channel: ChannelType, + client: WebClient, + oldest: str | None = None, + latest: str | None = None, + limit: int = _SLACK_LIMIT, +) -> tuple[list[MessageType], bool]: + """Get messages (Slack returns from newest to oldest)""" + + # Must join channel to read messages + if not channel["is_member"]: + try: + client.conversations_join( + channel=channel["id"], + is_private=channel["is_private"], + ) + except SlackApiError as e: + if e.response["error"] == "is_archived": + logging.warning(f"Channel {channel['name']} is archived. Skipping.") + return [], False + + logging.exception(f"Error joining channel {channel['name']}") + raise + logging.info(f"Successfully joined '{channel['name']}'") + + response = client.conversations_history( + channel=channel["id"], + oldest=oldest, + latest=latest, + limit=limit, + ) + response.validate() + + messages = cast(list[MessageType], response.get("messages", [])) + + cursor = cast(dict[str, Any], response.get("response_metadata", {})).get( + "next_cursor", "" + ) + has_more = bool(cursor) + return messages, has_more + + +def _message_to_doc( + message: MessageType, + client: WebClient, + channel: ChannelType, + slack_cleaner: SlackTextCleaner, + user_cache: dict[str, BasicExpertInfo | None], + seen_thread_ts: set[str], + channel_access: Any | None, + msg_filter_func: Callable[ + [MessageType], SlackMessageFilterReason | None + ] = default_msg_filter, +) -> tuple[Document | None, SlackMessageFilterReason | None]: + """Convert message to document""" + filtered_thread: ThreadType | None = None + filter_reason: SlackMessageFilterReason | None = None + thread_ts = message.get("thread_ts") + if thread_ts: + # If thread_ts exists, need to process thread + if thread_ts in seen_thread_ts: + return None, None + + thread = get_thread( + client=client, channel_id=channel["id"], thread_id=thread_ts + ) + + filtered_thread = [] + for message in thread: + filter_reason = msg_filter_func(message) + if filter_reason: + continue + + filtered_thread.append(message) + else: + filter_reason = msg_filter_func(message) + if filter_reason: + return None, filter_reason + + filtered_thread = [message] + + if not filtered_thread: + return None, filter_reason + + doc = thread_to_doc( + channel=channel, + thread=filtered_thread, + slack_cleaner=slack_cleaner, + client=client, + user_cache=user_cache, + channel_access=channel_access, + ) + return doc, None + + +def _process_message( + message: MessageType, + client: WebClient, + channel: ChannelType, + slack_cleaner: SlackTextCleaner, + user_cache: dict[str, BasicExpertInfo | None], + seen_thread_ts: set[str], + channel_access: Any | None, + msg_filter_func: Callable[ + [MessageType], SlackMessageFilterReason | None + ] = default_msg_filter, +) -> ProcessedSlackMessage: + """处理消息""" + thread_ts = message.get("thread_ts") + thread_or_message_ts = thread_ts or message["ts"] + try: + doc, filter_reason = _message_to_doc( + message=message, + client=client, + channel=channel, + slack_cleaner=slack_cleaner, + user_cache=user_cache, + seen_thread_ts=seen_thread_ts, + channel_access=channel_access, + msg_filter_func=msg_filter_func, + ) + return ProcessedSlackMessage( + doc=doc, + thread_or_message_ts=thread_or_message_ts, + filter_reason=filter_reason, + failure=None, + ) + except Exception as e: + (logging.exception(f"Error processing message {message['ts']}")) + return ProcessedSlackMessage( + doc=None, + thread_or_message_ts=thread_or_message_ts, + filter_reason=None, + failure=ConnectorFailure( + failed_document=DocumentFailure( + document_id=_build_doc_id( + channel_id=channel["id"], thread_ts=thread_or_message_ts + ), + document_link=get_message_link(message, client, channel["id"]), + ), + failure_message=str(e), + exception=e, + ), + ) + + +def _get_all_doc_ids( + client: WebClient, + channels: list[str] | None = None, + channel_name_regex_enabled: bool = False, + msg_filter_func: Callable[ + [MessageType], SlackMessageFilterReason | None + ] = default_msg_filter, + callback: Any = None, +) -> GenerateSlimDocumentOutput: + all_channels = get_channels(client) + filtered_channels = filter_channels( + all_channels, channels, channel_name_regex_enabled + ) + + for channel in filtered_channels: + channel_id = channel["id"] + external_access = None # Simplified version, not handling permissions + channel_message_batches = get_channel_messages( + client=client, + channel=channel, + callback=callback, + ) + + for message_batch in channel_message_batches: + slim_doc_batch: list[SlimDocument] = [] + for message in message_batch: + filter_reason = msg_filter_func(message) + if filter_reason: + continue + + slim_doc_batch.append( + SlimDocument( + id=_build_doc_id( + channel_id=channel_id, thread_ts=message["ts"] + ), + external_access=external_access, + ) + ) + + yield slim_doc_batch + + +class SlackConnector( + SlimConnectorWithPermSync, + CredentialsConnector, + CheckpointedConnectorWithPermSync, +): + """Slack connector""" + + def __init__( + self, + channels: list[str] | None = None, + channel_regex_enabled: bool = False, + batch_size: int = INDEX_BATCH_SIZE, + num_threads: int = SLACK_NUM_THREADS, + use_redis: bool = False, # Simplified version, not using Redis + ) -> None: + self.channels = channels + self.channel_regex_enabled = channel_regex_enabled + self.batch_size = batch_size + self.num_threads = num_threads + self.client: WebClient | None = None + self.fast_client: WebClient | None = None + self.text_cleaner: SlackTextCleaner | None = None + self.user_cache: dict[str, BasicExpertInfo | None] = {} + self.credentials_provider: Any = None + self.use_redis = use_redis + + @property + def channels(self) -> list[str] | None: + return self._channels + + @channels.setter + def channels(self, channels: list[str] | None) -> None: + self._channels = ( + [channel.removeprefix("#") for channel in channels] if channels else None + ) + + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: + """Load credentials""" + raise NotImplementedError("Use set_credentials_provider with this connector.") + + def set_credentials_provider(self, credentials_provider: Any) -> None: + """Set credentials provider""" + credentials = credentials_provider.get_credentials() + bot_token = credentials["slack_bot_token"] + + # Simplified version, not using Redis + connection_error_retry_handler = ConnectionErrorRetryHandler( + max_retry_count=MAX_RETRIES, + interval_calculator=FixedValueRetryIntervalCalculator(), + error_types=[ + URLError, + ConnectionResetError, + RemoteDisconnected, + IncompleteRead, + ], + ) + + self.client = WebClient( + token=bot_token, retry_handlers=[connection_error_retry_handler] + ) + + # For fast response requests + self.fast_client = WebClient( + token=bot_token, timeout=FAST_TIMEOUT + ) + self.text_cleaner = SlackTextCleaner(client=self.client) + self.credentials_provider = credentials_provider + + def retrieve_all_slim_docs_perm_sync( + self, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + callback: Any = None, + ) -> GenerateSlimDocumentOutput: + """获取所有简化文档(带权限同步)""" + if self.client is None: + raise ConnectorMissingCredentialError("Slack") + + return _get_all_doc_ids( + client=self.client, + channels=self.channels, + channel_name_regex_enabled=self.channel_regex_enabled, + callback=callback, + ) + + def load_from_checkpoint( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: ConnectorCheckpoint, + ) -> CheckpointOutput: + """Load documents from checkpoint""" + # Simplified version, not implementing full checkpoint functionality + logging.warning("Checkpoint functionality not implemented in simplified version") + return [] + + def load_from_checkpoint_with_perm_sync( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: ConnectorCheckpoint, + ) -> CheckpointOutput: + """Load documents from checkpoint (with permission sync)""" + # Simplified version, not implementing full checkpoint functionality + logging.warning("Checkpoint functionality not implemented in simplified version") + return [] + + def build_dummy_checkpoint(self) -> ConnectorCheckpoint: + """Build dummy checkpoint""" + return ConnectorCheckpoint() + + def validate_checkpoint_json(self, checkpoint_json: str) -> ConnectorCheckpoint: + """Validate checkpoint JSON""" + return ConnectorCheckpoint() + + def validate_connector_settings(self) -> None: + """Validate connector settings""" + if self.fast_client is None: + raise ConnectorMissingCredentialError("Slack credentials not loaded.") + + try: + # 1) Validate workspace connection + auth_response = self.fast_client.auth_test() + if not auth_response.get("ok", False): + error_msg = auth_response.get( + "error", "Unknown error from Slack auth_test" + ) + raise ConnectorValidationError(f"Failed Slack auth_test: {error_msg}") + + # 2) Confirm listing channels functionality works + test_resp = self.fast_client.conversations_list( + limit=1, types=["public_channel"] + ) + if not test_resp.get("ok", False): + error_msg = test_resp.get("error", "Unknown error from Slack") + if error_msg == "invalid_auth": + raise ConnectorValidationError( + f"Invalid Slack bot token ({error_msg})." + ) + elif error_msg == "not_authed": + raise CredentialExpiredError( + f"Invalid or expired Slack bot token ({error_msg})." + ) + raise UnexpectedValidationError( + f"Slack API returned a failure: {error_msg}" + ) + + except SlackApiError as e: + slack_error = e.response.get("error", "") + if slack_error == "ratelimited": + retry_after = int(e.response.headers.get("Retry-After", 1)) + logging.warning( + f"Slack API rate limited during validation. Retry suggested after {retry_after} seconds. " + "Proceeding with validation, but be aware that connector operations might be throttled." + ) + return + elif slack_error == "missing_scope": + raise InsufficientPermissionsError( + "Slack bot token lacks the necessary scope to list/access channels. " + "Please ensure your Slack app has 'channels:read' (and/or 'groups:read' for private channels)." + ) + elif slack_error == "invalid_auth": + raise CredentialExpiredError( + f"Invalid Slack bot token ({slack_error})." + ) + elif slack_error == "not_authed": + raise CredentialExpiredError( + f"Invalid or expired Slack bot token ({slack_error})." + ) + raise UnexpectedValidationError( + f"Unexpected Slack error '{slack_error}' during settings validation." + ) + except ConnectorValidationError as e: + raise e + except Exception as e: + raise UnexpectedValidationError( + f"Unexpected error during Slack settings validation: {e}" + ) + + +if __name__ == "__main__": + # Example usage + import os + + slack_channel = os.environ.get("SLACK_CHANNEL") + connector = SlackConnector( + channels=[slack_channel] if slack_channel else None, + ) + + # Simplified version, directly using credentials dictionary + credentials = { + "slack_bot_token": os.environ.get("SLACK_BOT_TOKEN", "test-token") + } + + class SimpleCredentialsProvider: + def get_credentials(self): + return credentials + + provider = SimpleCredentialsProvider() + connector.set_credentials_provider(provider) + + try: + connector.validate_connector_settings() + print("Slack connector settings validated successfully") + except Exception as e: + print(f"Validation failed: {e}") \ No newline at end of file diff --git a/common/data_source/teams_connector.py b/common/data_source/teams_connector.py new file mode 100644 index 00000000000..0b4cd564252 --- /dev/null +++ b/common/data_source/teams_connector.py @@ -0,0 +1,115 @@ +"""Microsoft Teams connector""" + +from typing import Any + +import msal +from office365.graph_client import GraphClient +from office365.runtime.client_request_exception import ClientRequestException + +from common.data_source.exceptions import ( + ConnectorValidationError, + InsufficientPermissionsError, + UnexpectedValidationError, ConnectorMissingCredentialError +) +from common.data_source.interfaces import ( + SecondsSinceUnixEpoch, + SlimConnectorWithPermSync, CheckpointedConnectorWithPermSync +) +from common.data_source.models import ( + ConnectorCheckpoint +) + +_SLIM_DOC_BATCH_SIZE = 5000 + + +class TeamsCheckpoint(ConnectorCheckpoint): + """Teams-specific checkpoint""" + todo_team_ids: list[str] | None = None + + +class TeamsConnector(CheckpointedConnectorWithPermSync, SlimConnectorWithPermSync): + """Microsoft Teams connector for accessing Teams messages and channels""" + + def __init__(self, batch_size: int = _SLIM_DOC_BATCH_SIZE) -> None: + self.batch_size = batch_size + self.teams_client = None + + def load_credentials(self, credentials: dict[str, Any]) -> dict[str, Any] | None: + """Load Microsoft Teams credentials""" + try: + tenant_id = credentials.get("tenant_id") + client_id = credentials.get("client_id") + client_secret = credentials.get("client_secret") + + if not all([tenant_id, client_id, client_secret]): + raise ConnectorMissingCredentialError("Microsoft Teams credentials are incomplete") + + # Create MSAL confidential client + app = msal.ConfidentialClientApplication( + client_id=client_id, + client_credential=client_secret, + authority=f"https://login.microsoftonline.com/{tenant_id}" + ) + + # Get access token + result = app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"]) + + if "access_token" not in result: + raise ConnectorMissingCredentialError("Failed to acquire Microsoft Teams access token") + + # Create Graph client for Teams + self.teams_client = GraphClient(result["access_token"]) + + return None + except Exception as e: + raise ConnectorMissingCredentialError(f"Microsoft Teams: {e}") + + def validate_connector_settings(self) -> None: + """Validate Microsoft Teams connector settings""" + if not self.teams_client: + raise ConnectorMissingCredentialError("Microsoft Teams") + + try: + # Test connection by getting teams + teams = self.teams_client.teams.get().execute_query() + if not teams: + raise ConnectorValidationError("Failed to access Microsoft Teams") + except ClientRequestException as e: + if "401" in str(e) or "403" in str(e): + raise InsufficientPermissionsError("Invalid credentials or insufficient permissions") + else: + raise UnexpectedValidationError(f"Microsoft Teams validation error: {e}") + + def poll_source(self, start: SecondsSinceUnixEpoch, end: SecondsSinceUnixEpoch) -> Any: + """Poll Microsoft Teams for recent messages""" + # Simplified implementation - in production this would handle actual polling + return [] + + def load_from_checkpoint( + self, + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, + checkpoint: ConnectorCheckpoint, + ) -> Any: + """Load documents from checkpoint""" + # Simplified implementation + return [] + + def build_dummy_checkpoint(self) -> ConnectorCheckpoint: + """Build dummy checkpoint""" + return TeamsCheckpoint() + + def validate_checkpoint_json(self, checkpoint_json: str) -> ConnectorCheckpoint: + """Validate checkpoint JSON""" + # Simplified implementation + return TeamsCheckpoint() + + def retrieve_all_slim_docs_perm_sync( + self, + start: SecondsSinceUnixEpoch | None = None, + end: SecondsSinceUnixEpoch | None = None, + callback: Any = None, + ) -> Any: + """Retrieve all simplified documents with permission sync""" + # Simplified implementation + return [] \ No newline at end of file diff --git a/common/data_source/utils.py b/common/data_source/utils.py new file mode 100644 index 00000000000..7c2cdf898ab --- /dev/null +++ b/common/data_source/utils.py @@ -0,0 +1,1099 @@ +"""Utility functions for all connectors""" + +import base64 +import contextvars +import json +import logging +import math +import os +import re +import threading +import time +from collections.abc import Callable, Generator, Iterator, Mapping, Sequence +from concurrent.futures import FIRST_COMPLETED, Future, ThreadPoolExecutor, as_completed, wait +from datetime import datetime, timedelta, timezone +from functools import lru_cache, wraps +from io import BytesIO +from itertools import islice +from numbers import Integral +from pathlib import Path +from typing import IO, Any, Generic, Iterable, Optional, Protocol, TypeVar, cast +from urllib.parse import parse_qs, quote, urljoin, urlparse + +import boto3 +import chardet +import requests +from botocore.client import Config +from botocore.credentials import RefreshableCredentials +from botocore.session import get_session +from googleapiclient.errors import HttpError +from mypy_boto3_s3 import S3Client +from retry import retry +from slack_sdk import WebClient +from slack_sdk.errors import SlackApiError +from slack_sdk.web import SlackResponse + +from common.data_source.config import ( + _ITERATION_LIMIT, + _NOTION_CALL_TIMEOUT, + _SLACK_LIMIT, + CONFLUENCE_OAUTH_TOKEN_URL, + DOWNLOAD_CHUNK_SIZE, + EXCLUDED_IMAGE_TYPES, + RATE_LIMIT_MESSAGE_LOWERCASE, + SIZE_THRESHOLD_BUFFER, + BlobType, +) +from common.data_source.exceptions import RateLimitTriedTooManyTimesError +from common.data_source.interfaces import CT, CheckpointedConnector, CheckpointOutputWrapper, ConfluenceUser, LoadFunction, OnyxExtensionType, SecondsSinceUnixEpoch, TokenResponse +from common.data_source.models import BasicExpertInfo, Document + + +def datetime_from_string(datetime_string: str) -> datetime: + datetime_string = datetime_string.strip() + + # Handle the case where the datetime string ends with 'Z' (Zulu time) + if datetime_string.endswith('Z'): + datetime_string = datetime_string[:-1] + '+00:00' + + # Handle timezone format "+0000" -> "+00:00" + if datetime_string.endswith('+0000'): + datetime_string = datetime_string[:-5] + '+00:00' + + datetime_object = datetime.fromisoformat(datetime_string) + + if datetime_object.tzinfo is None: + # If no timezone info, assume it is UTC + datetime_object = datetime_object.replace(tzinfo=timezone.utc) + else: + # If not in UTC, translate it + datetime_object = datetime_object.astimezone(timezone.utc) + + return datetime_object + + +def is_valid_image_type(mime_type: str) -> bool: + """ + Check if mime_type is a valid image type. + + Args: + mime_type: The MIME type to check + + Returns: + True if the MIME type is a valid image type, False otherwise + """ + return bool(mime_type) and mime_type.startswith("image/") and mime_type not in EXCLUDED_IMAGE_TYPES + + +"""If you want to allow the external service to tell you when you've hit the rate limit, +use the following instead""" + +R = TypeVar("R", bound=Callable[..., requests.Response]) + + +def _handle_http_error(e: requests.HTTPError, attempt: int) -> int: + MIN_DELAY = 2 + MAX_DELAY = 60 + STARTING_DELAY = 5 + BACKOFF = 2 + + # Check if the response or headers are None to avoid potential AttributeError + if e.response is None or e.response.headers is None: + logging.warning("HTTPError with `None` as response or as headers") + raise e + + # Confluence Server returns 403 when rate limited + if e.response.status_code == 403: + FORBIDDEN_MAX_RETRY_ATTEMPTS = 7 + FORBIDDEN_RETRY_DELAY = 10 + if attempt < FORBIDDEN_MAX_RETRY_ATTEMPTS: + logging.warning(f"403 error. This sometimes happens when we hit Confluence rate limits. Retrying in {FORBIDDEN_RETRY_DELAY} seconds...") + return FORBIDDEN_RETRY_DELAY + + raise e + + if e.response.status_code != 429 and RATE_LIMIT_MESSAGE_LOWERCASE not in e.response.text.lower(): + raise e + + retry_after = None + + retry_after_header = e.response.headers.get("Retry-After") + if retry_after_header is not None: + try: + retry_after = int(retry_after_header) + if retry_after > MAX_DELAY: + logging.warning(f"Clamping retry_after from {retry_after} to {MAX_DELAY} seconds...") + retry_after = MAX_DELAY + if retry_after < MIN_DELAY: + retry_after = MIN_DELAY + except ValueError: + pass + + if retry_after is not None: + logging.warning(f"Rate limiting with retry header. Retrying after {retry_after} seconds...") + delay = retry_after + else: + logging.warning("Rate limiting without retry header. Retrying with exponential backoff...") + delay = min(STARTING_DELAY * (BACKOFF**attempt), MAX_DELAY) + + delay_until = math.ceil(time.monotonic() + delay) + return delay_until + + +def update_param_in_path(path: str, param: str, value: str) -> str: + """Update a parameter in a path. Path should look something like: + + /api/rest/users?start=0&limit=10 + """ + parsed_url = urlparse(path) + query_params = parse_qs(parsed_url.query) + query_params[param] = [value] + return path.split("?")[0] + "?" + "&".join(f"{k}={quote(v[0])}" for k, v in query_params.items()) + + +def build_confluence_document_id(base_url: str, content_url: str, is_cloud: bool) -> str: + """For confluence, the document id is the page url for a page based document + or the attachment download url for an attachment based document + + Args: + base_url (str): The base url of the Confluence instance + content_url (str): The url of the page or attachment download url + + Returns: + str: The document id + """ + + # NOTE: urljoin is tricky and will drop the last segment of the base if it doesn't + # end with "/" because it believes that makes it a file. + final_url = base_url.rstrip("/") + "/" + if is_cloud and not final_url.endswith("/wiki/"): + final_url = urljoin(final_url, "wiki") + "/" + final_url = urljoin(final_url, content_url.lstrip("/")) + return final_url + + +def get_single_param_from_url(url: str, param: str) -> str | None: + """Get a parameter from a url""" + parsed_url = urlparse(url) + return parse_qs(parsed_url.query).get(param, [None])[0] + + +def get_start_param_from_url(url: str) -> int: + """Get the start parameter from a url""" + start_str = get_single_param_from_url(url, "start") + return int(start_str) if start_str else 0 + + +def wrap_request_to_handle_ratelimiting(request_fn: R, default_wait_time_sec: int = 30, max_waits: int = 30) -> R: + def wrapped_request(*args: list, **kwargs: dict[str, Any]) -> requests.Response: + for _ in range(max_waits): + response = request_fn(*args, **kwargs) + if response.status_code == 429: + try: + wait_time = int(response.headers.get("Retry-After", default_wait_time_sec)) + except ValueError: + wait_time = default_wait_time_sec + + time.sleep(wait_time) + continue + + return response + + raise RateLimitTriedTooManyTimesError(f"Exceeded '{max_waits}' retries") + + return cast(R, wrapped_request) + + +_rate_limited_get = wrap_request_to_handle_ratelimiting(requests.get) +_rate_limited_post = wrap_request_to_handle_ratelimiting(requests.post) + + +class _RateLimitedRequest: + get = _rate_limited_get + post = _rate_limited_post + + +rl_requests = _RateLimitedRequest + +# Blob Storage Utilities + + +def create_s3_client(bucket_type: BlobType, credentials: dict[str, Any], european_residency: bool = False) -> S3Client: + """Create S3 client for different blob storage types""" + if bucket_type == BlobType.R2: + subdomain = "eu." if european_residency else "" + endpoint_url = f"https://{credentials['account_id']}.{subdomain}r2.cloudflarestorage.com" + + return boto3.client( + "s3", + endpoint_url=endpoint_url, + aws_access_key_id=credentials["r2_access_key_id"], + aws_secret_access_key=credentials["r2_secret_access_key"], + region_name="auto", + config=Config(signature_version="s3v4"), + ) + + elif bucket_type == BlobType.S3: + authentication_method = credentials.get("authentication_method", "access_key") + + if authentication_method == "access_key": + session = boto3.Session( + aws_access_key_id=credentials["aws_access_key_id"], + aws_secret_access_key=credentials["aws_secret_access_key"], + ) + return session.client("s3") + + elif authentication_method == "iam_role": + role_arn = credentials["aws_role_arn"] + + def _refresh_credentials() -> dict[str, str]: + sts_client = boto3.client("sts") + assumed_role_object = sts_client.assume_role( + RoleArn=role_arn, + RoleSessionName=f"onyx_blob_storage_{int(datetime.now().timestamp())}", + ) + creds = assumed_role_object["Credentials"] + return { + "access_key": creds["AccessKeyId"], + "secret_key": creds["SecretAccessKey"], + "token": creds["SessionToken"], + "expiry_time": creds["Expiration"].isoformat(), + } + + refreshable = RefreshableCredentials.create_from_metadata( + metadata=_refresh_credentials(), + refresh_using=_refresh_credentials, + method="sts-assume-role", + ) + botocore_session = get_session() + botocore_session._credentials = refreshable + session = boto3.Session(botocore_session=botocore_session) + return session.client("s3") + + elif authentication_method == "assume_role": + return boto3.client("s3") + + else: + raise ValueError("Invalid authentication method for S3.") + + elif bucket_type == BlobType.GOOGLE_CLOUD_STORAGE: + return boto3.client( + "s3", + endpoint_url="https://storage.googleapis.com", + aws_access_key_id=credentials["access_key_id"], + aws_secret_access_key=credentials["secret_access_key"], + region_name="auto", + ) + + elif bucket_type == BlobType.OCI_STORAGE: + return boto3.client( + "s3", + endpoint_url=f"https://{credentials['namespace']}.compat.objectstorage.{credentials['region']}.oraclecloud.com", + aws_access_key_id=credentials["access_key_id"], + aws_secret_access_key=credentials["secret_access_key"], + region_name=credentials["region"], + ) + + else: + raise ValueError(f"Unsupported bucket type: {bucket_type}") + + +def detect_bucket_region(s3_client: S3Client, bucket_name: str) -> str | None: + """Detect bucket region""" + try: + response = s3_client.head_bucket(Bucket=bucket_name) + bucket_region = response.get("BucketRegion") or response.get("ResponseMetadata", {}).get("HTTPHeaders", {}).get("x-amz-bucket-region") + + if bucket_region: + logging.debug(f"Detected bucket region: {bucket_region}") + else: + logging.warning("Bucket region not found in head_bucket response") + + return bucket_region + except Exception as e: + logging.warning(f"Failed to detect bucket region via head_bucket: {e}") + return None + + +def download_object(s3_client: S3Client, bucket_name: str, key: str, size_threshold: int | None = None) -> bytes | None: + """Download object from blob storage""" + response = s3_client.get_object(Bucket=bucket_name, Key=key) + body = response["Body"] + + try: + if size_threshold is None: + return body.read() + + return read_stream_with_limit(body, key, size_threshold) + finally: + body.close() + + +def read_stream_with_limit(body: Any, key: str, size_threshold: int) -> bytes | None: + """Read stream with size limit""" + bytes_read = 0 + chunks: list[bytes] = [] + chunk_size = min(DOWNLOAD_CHUNK_SIZE, size_threshold + SIZE_THRESHOLD_BUFFER) + + for chunk in body.iter_chunks(chunk_size=chunk_size): + if not chunk: + continue + chunks.append(chunk) + bytes_read += len(chunk) + + if bytes_read > size_threshold + SIZE_THRESHOLD_BUFFER: + logging.warning(f"{key} exceeds size threshold of {size_threshold}. Skipping.") + return None + + return b"".join(chunks) + + +def _extract_onyx_metadata(line: str) -> dict | None: + """ + Example: first line has: + + or + #ONYX_METADATA={"title":"..."} + """ + html_comment_pattern = r"" + hashtag_pattern = r"#ONYX_METADATA=\{(.*?)\}" + + html_comment_match = re.search(html_comment_pattern, line) + hashtag_match = re.search(hashtag_pattern, line) + + if html_comment_match: + json_str = html_comment_match.group(1) + elif hashtag_match: + json_str = hashtag_match.group(1) + else: + return None + + try: + return json.loads("{" + json_str + "}") + except json.JSONDecodeError: + return None + + +def read_text_file( + file: IO, + encoding: str = "utf-8", + errors: str = "replace", + ignore_onyx_metadata: bool = True, +) -> tuple[str, dict]: + """ + For plain text files. Optionally extracts Onyx metadata from the first line. + """ + metadata = {} + file_content_raw = "" + for ind, line in enumerate(file): + # decode + try: + line = line.decode(encoding) if isinstance(line, bytes) else line + except UnicodeDecodeError: + line = line.decode(encoding, errors=errors) if isinstance(line, bytes) else line + + # optionally parse metadata in the first line + if ind == 0 and not ignore_onyx_metadata: + potential_meta = _extract_onyx_metadata(line) + if potential_meta is not None: + metadata = potential_meta + continue + + file_content_raw += line + + return file_content_raw, metadata + + +def get_blob_link(bucket_type: BlobType, s3_client: S3Client, bucket_name: str, key: str, bucket_region: str | None = None) -> str: + """Get object link for different blob storage types""" + encoded_key = quote(key, safe="/") + + if bucket_type == BlobType.R2: + account_id = s3_client.meta.endpoint_url.split("//")[1].split(".")[0] + subdomain = "eu/" if "eu." in s3_client.meta.endpoint_url else "default/" + + return f"https://dash.cloudflare.com/{account_id}/r2/{subdomain}buckets/{bucket_name}/objects/{encoded_key}/details" + + elif bucket_type == BlobType.S3: + region = bucket_region or s3_client.meta.region_name + return f"https://s3.console.aws.amazon.com/s3/object/{bucket_name}?region={region}&prefix={encoded_key}" + + elif bucket_type == BlobType.GOOGLE_CLOUD_STORAGE: + return f"https://console.cloud.google.com/storage/browser/_details/{bucket_name}/{encoded_key}" + + elif bucket_type == BlobType.OCI_STORAGE: + namespace = s3_client.meta.endpoint_url.split("//")[1].split(".")[0] + region = s3_client.meta.region_name + return f"https://objectstorage.{region}.oraclecloud.com/n/{namespace}/b/{bucket_name}/o/{encoded_key}" + + else: + raise ValueError(f"Unsupported bucket type: {bucket_type}") + + +def extract_size_bytes(obj: Mapping[str, Any]) -> int | None: + """Extract size bytes from object metadata""" + candidate_keys = ( + "Size", + "size", + "ContentLength", + "content_length", + "Content-Length", + "contentLength", + "bytes", + "Bytes", + ) + + def _normalize(value: Any) -> int | None: + if value is None or isinstance(value, bool): + return None + if isinstance(value, Integral): + return int(value) + try: + numeric = float(value) + except (TypeError, ValueError): + return None + if numeric >= 0 and numeric.is_integer(): + return int(numeric) + return None + + for key in candidate_keys: + if key in obj: + normalized = _normalize(obj.get(key)) + if normalized is not None: + return normalized + + for key, value in obj.items(): + if not isinstance(key, str): + continue + lowered_key = key.lower() + if "size" in lowered_key or "length" in lowered_key: + normalized = _normalize(value) + if normalized is not None: + return normalized + + return None + + +def get_file_ext(file_name: str) -> str: + """Get file extension""" + return os.path.splitext(file_name)[1].lower() + + +def is_accepted_file_ext(file_ext: str, extension_type: OnyxExtensionType) -> bool: + image_extensions = {'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.webp'} + text_extensions = {".txt", ".md", ".mdx", ".conf", ".log", ".json", ".csv", ".tsv", ".xml", ".yml", ".yaml", ".sql"} + document_extensions = {".pdf", ".docx", ".pptx", ".xlsx", ".eml", ".epub", ".html"} + + if extension_type & OnyxExtensionType.Multimedia and file_ext in image_extensions: + return True + + if extension_type & OnyxExtensionType.Plain and file_ext in text_extensions: + return True + + if extension_type & OnyxExtensionType.Document and file_ext in document_extensions: + return True + + return False + + +def detect_encoding(file: IO[bytes]) -> str: + raw_data = file.read(50000) + file.seek(0) + encoding = chardet.detect(raw_data)["encoding"] or "utf-8" + return encoding + + +def get_markitdown_converter(): + global _MARKITDOWN_CONVERTER + from markitdown import MarkItDown + + if _MARKITDOWN_CONVERTER is None: + _MARKITDOWN_CONVERTER = MarkItDown(enable_plugins=False) + return _MARKITDOWN_CONVERTER + + +def to_bytesio(stream: IO[bytes]) -> BytesIO: + if isinstance(stream, BytesIO): + return stream + data = stream.read() # consumes the stream! + return BytesIO(data) + + +# Slack Utilities + + +@lru_cache() +def get_base_url(token: str) -> str: + """Get and cache Slack workspace base URL""" + client = WebClient(token=token) + return client.auth_test()["url"] + + +def get_message_link(event: dict, client: WebClient, channel_id: str) -> str: + """Get message link""" + message_ts = event["ts"] + message_ts_without_dot = message_ts.replace(".", "") + thread_ts = event.get("thread_ts") + base_url = get_base_url(client.token) + + link = f"{base_url.rstrip('/')}/archives/{channel_id}/p{message_ts_without_dot}" + (f"?thread_ts={thread_ts}" if thread_ts else "") + return link + + +def make_slack_api_call(call: Callable[..., SlackResponse], **kwargs: Any) -> SlackResponse: + """Make Slack API call""" + return call(**kwargs) + + +def make_paginated_slack_api_call(call: Callable[..., SlackResponse], **kwargs: Any) -> Generator[dict[str, Any], None, None]: + """Make paginated Slack API call""" + return _make_slack_api_call_paginated(call)(**kwargs) + + +def _make_slack_api_call_paginated( + call: Callable[..., SlackResponse], +) -> Callable[..., Generator[dict[str, Any], None, None]]: + """Wrap Slack API call to automatically handle pagination""" + + @wraps(call) + def paginated_call(**kwargs: Any) -> Generator[dict[str, Any], None, None]: + cursor: str | None = None + has_more = True + while has_more: + response = call(cursor=cursor, limit=_SLACK_LIMIT, **kwargs) + yield response.validate() + cursor = response.get("response_metadata", {}).get("next_cursor", "") + has_more = bool(cursor) + + return paginated_call + + +def is_atlassian_date_error(e: Exception) -> bool: + return "field 'updated' is invalid" in str(e) + + +def expert_info_from_slack_id( + user_id: str | None, + client: WebClient, + user_cache: dict[str, BasicExpertInfo | None], +) -> BasicExpertInfo | None: + """Get expert information from Slack user ID""" + if not user_id: + return None + + if user_id in user_cache: + return user_cache[user_id] + + response = client.users_info(user=user_id) + + if not response["ok"]: + user_cache[user_id] = None + return None + + user: dict = response.data.get("user", {}) + profile = user.get("profile", {}) + + expert = BasicExpertInfo( + display_name=user.get("real_name") or profile.get("display_name"), + first_name=profile.get("first_name"), + last_name=profile.get("last_name"), + email=profile.get("email"), + ) + + user_cache[user_id] = expert + + return expert + + +class SlackTextCleaner: + """Slack text cleaning utility class""" + + def __init__(self, client: WebClient) -> None: + self._client = client + self._id_to_name_map: dict[str, str] = {} + + def _get_slack_name(self, user_id: str) -> str: + """Get Slack username""" + if user_id not in self._id_to_name_map: + try: + response = self._client.users_info(user=user_id) + self._id_to_name_map[user_id] = response["user"]["profile"]["display_name"] or response["user"]["profile"]["real_name"] + except SlackApiError as e: + logging.exception(f"Error fetching data for user {user_id}: {e.response['error']}") + raise + + return self._id_to_name_map[user_id] + + def _replace_user_ids_with_names(self, message: str) -> str: + """Replace user IDs with usernames""" + user_ids = re.findall("<@(.*?)>", message) + + for user_id in user_ids: + try: + if user_id in self._id_to_name_map: + user_name = self._id_to_name_map[user_id] + else: + user_name = self._get_slack_name(user_id) + + message = message.replace(f"<@{user_id}>", f"@{user_name}") + except Exception: + logging.exception(f"Unable to replace user ID with username for user_id '{user_id}'") + + return message + + def index_clean(self, message: str) -> str: + """Index cleaning""" + message = self._replace_user_ids_with_names(message) + message = self.replace_tags_basic(message) + message = self.replace_channels_basic(message) + message = self.replace_special_mentions(message) + message = self.replace_special_catchall(message) + return message + + @staticmethod + def replace_tags_basic(message: str) -> str: + """Basic tag replacement""" + user_ids = re.findall("<@(.*?)>", message) + for user_id in user_ids: + message = message.replace(f"<@{user_id}>", f"@{user_id}") + return message + + @staticmethod + def replace_channels_basic(message: str) -> str: + """Basic channel replacement""" + channel_matches = re.findall(r"<#(.*?)\|(.*?)>", message) + for channel_id, channel_name in channel_matches: + message = message.replace(f"<#{channel_id}|{channel_name}>", f"#{channel_name}") + return message + + @staticmethod + def replace_special_mentions(message: str) -> str: + """Special mention replacement""" + message = message.replace("", "@channel") + message = message.replace("", "@here") + message = message.replace("", "@everyone") + return message + + @staticmethod + def replace_special_catchall(message: str) -> str: + """Special catchall replacement""" + pattern = r"]+)>" + return re.sub(pattern, r"\2", message) + + @staticmethod + def add_zero_width_whitespace_after_tag(message: str) -> str: + """Add zero-width whitespace after tag""" + return message.replace("@", "@\u200b") + + +# Gmail Utilities + + +def is_mail_service_disabled_error(error: HttpError) -> bool: + """Detect if the Gmail API is telling us the mailbox is not provisioned.""" + if error.resp.status != 400: + return False + + error_message = str(error) + return "Mail service not enabled" in error_message or "failedPrecondition" in error_message + + +def build_time_range_query( + time_range_start: SecondsSinceUnixEpoch | None = None, + time_range_end: SecondsSinceUnixEpoch | None = None, +) -> str | None: + """Build time range query for Gmail API""" + query = "" + if time_range_start is not None and time_range_start != 0: + query += f"after:{int(time_range_start)}" + if time_range_end is not None and time_range_end != 0: + query += f" before:{int(time_range_end)}" + query = query.strip() + + if len(query) == 0: + return None + + return query + + +def clean_email_and_extract_name(email: str) -> tuple[str, str | None]: + """Extract email address and display name from email string.""" + email = email.strip() + if "<" in email and ">" in email: + # Handle format: "Display Name " + display_name = email[: email.find("<")].strip() + email_address = email[email.find("<") + 1 : email.find(">")].strip() + return email_address, display_name if display_name else None + else: + # Handle plain email address + return email.strip(), None + + +def get_message_body(payload: dict[str, Any]) -> str: + """Extract message body text from Gmail message payload.""" + parts = payload.get("parts", []) + message_body = "" + for part in parts: + mime_type = part.get("mimeType") + body = part.get("body") + if mime_type == "text/plain" and body: + data = body.get("data", "") + text = base64.urlsafe_b64decode(data).decode() + message_body += text + return message_body + + +def time_str_to_utc(time_str: str): + """Convert time string to UTC datetime.""" + from datetime import datetime + + return datetime.fromisoformat(time_str.replace("Z", "+00:00")) + + +# Notion Utilities +T = TypeVar("T") + + +def batch_generator( + items: Iterable[T], + batch_size: int, + pre_batch_yield: Callable[[list[T]], None] | None = None, +) -> Generator[list[T], None, None]: + iterable = iter(items) + while True: + batch = list(islice(iterable, batch_size)) + if not batch: + return + + if pre_batch_yield: + pre_batch_yield(batch) + yield batch + + +@retry(tries=3, delay=1, backoff=2) +def fetch_notion_data(url: str, headers: dict[str, str], method: str = "GET", json_data: Optional[dict] = None) -> dict[str, Any]: + """Fetch data from Notion API with retry logic.""" + try: + if method == "GET": + response = rl_requests.get(url, headers=headers, timeout=_NOTION_CALL_TIMEOUT) + elif method == "POST": + response = rl_requests.post(url, headers=headers, json=json_data, timeout=_NOTION_CALL_TIMEOUT) + else: + raise ValueError(f"Unsupported HTTP method: {method}") + + response.raise_for_status() + return response.json() + except requests.exceptions.RequestException as e: + logging.error(f"Error fetching data from Notion API: {e}") + raise + + +def properties_to_str(properties: dict[str, Any]) -> str: + """Convert Notion properties to a string representation.""" + + def _recurse_list_properties(inner_list: list[Any]) -> str | None: + list_properties: list[str | None] = [] + for item in inner_list: + if item and isinstance(item, dict): + list_properties.append(_recurse_properties(item)) + elif item and isinstance(item, list): + list_properties.append(_recurse_list_properties(item)) + else: + list_properties.append(str(item)) + return ", ".join([list_property for list_property in list_properties if list_property]) or None + + def _recurse_properties(inner_dict: dict[str, Any]) -> str | None: + sub_inner_dict: dict[str, Any] | list[Any] | str = inner_dict + while isinstance(sub_inner_dict, dict) and "type" in sub_inner_dict: + type_name = sub_inner_dict["type"] + sub_inner_dict = sub_inner_dict[type_name] + + if not sub_inner_dict: + return None + + if isinstance(sub_inner_dict, list): + return _recurse_list_properties(sub_inner_dict) + elif isinstance(sub_inner_dict, str): + return sub_inner_dict + elif isinstance(sub_inner_dict, dict): + if "name" in sub_inner_dict: + return sub_inner_dict["name"] + if "content" in sub_inner_dict: + return sub_inner_dict["content"] + start = sub_inner_dict.get("start") + end = sub_inner_dict.get("end") + if start is not None: + if end is not None: + return f"{start} - {end}" + return start + elif end is not None: + return f"Until {end}" + + if "id" in sub_inner_dict: + logging.debug("Skipping Notion object id field property") + return None + + logging.debug(f"Unreadable property from innermost prop: {sub_inner_dict}") + return None + + result = "" + for prop_name, prop in properties.items(): + if not prop or not isinstance(prop, dict): + continue + + try: + inner_value = _recurse_properties(prop) + except Exception as e: + logging.warning(f"Error recursing properties for {prop_name}: {e}") + continue + + if inner_value: + result += f"{prop_name}: {inner_value}\t" + + return result + + +def filter_pages_by_time(pages: list[dict[str, Any]], start: float, end: float, filter_field: str = "last_edited_time") -> list[dict[str, Any]]: + """Filter pages by time range.""" + from datetime import datetime + + filtered_pages: list[dict[str, Any]] = [] + for page in pages: + timestamp = page[filter_field].replace(".000Z", "+00:00") + compare_time = datetime.fromisoformat(timestamp).timestamp() + if compare_time > start and compare_time <= end: + filtered_pages.append(page) + return filtered_pages + + +def _load_all_docs( + connector: CheckpointedConnector[CT], + load: LoadFunction, +) -> list[Document]: + num_iterations = 0 + + checkpoint = cast(CT, connector.build_dummy_checkpoint()) + documents: list[Document] = [] + while checkpoint.has_more: + doc_batch_generator = CheckpointOutputWrapper[CT]()(load(checkpoint)) + for document, failure, next_checkpoint in doc_batch_generator: + if failure is not None: + raise RuntimeError(f"Failed to load documents: {failure}") + if document is not None and isinstance(document, Document): + documents.append(document) + if next_checkpoint is not None: + checkpoint = next_checkpoint + + num_iterations += 1 + if num_iterations > _ITERATION_LIMIT: + raise RuntimeError("Too many iterations. Infinite loop?") + + return documents + + +def load_all_docs_from_checkpoint_connector( + connector: CheckpointedConnector[CT], + start: SecondsSinceUnixEpoch, + end: SecondsSinceUnixEpoch, +) -> list[Document]: + return _load_all_docs( + connector=connector, + load=lambda checkpoint: connector.load_from_checkpoint(start=start, end=end, checkpoint=checkpoint), + ) + + +def get_cloudId(base_url: str) -> str: + tenant_info_url = urljoin(base_url, "/_edge/tenant_info") + response = requests.get(tenant_info_url, timeout=10) + response.raise_for_status() + return response.json()["cloudId"] + + +def scoped_url(url: str, product: str) -> str: + parsed = urlparse(url) + base_url = parsed.scheme + "://" + parsed.netloc + cloud_id = get_cloudId(base_url) + return f"https://api.atlassian.com/ex/{product}/{cloud_id}{parsed.path}" + + +def process_confluence_user_profiles_override( + confluence_user_email_override: list[dict[str, str]], +) -> list[ConfluenceUser]: + return [ + ConfluenceUser( + user_id=override["user_id"], + # username is not returned by the Confluence Server API anyways + username=override["username"], + display_name=override["display_name"], + email=override["email"], + type=override["type"], + ) + for override in confluence_user_email_override + if override is not None + ] + + +def confluence_refresh_tokens(client_id: str, client_secret: str, cloud_id: str, refresh_token: str) -> dict[str, Any]: + # rotate the refresh and access token + # Note that access tokens are only good for an hour in confluence cloud, + # so we're going to have problems if the connector runs for longer + # https://developer.atlassian.com/cloud/confluence/oauth-2-3lo-apps/#use-a-refresh-token-to-get-another-access-token-and-refresh-token-pair + response = requests.post( + CONFLUENCE_OAUTH_TOKEN_URL, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + data={ + "grant_type": "refresh_token", + "client_id": client_id, + "client_secret": client_secret, + "refresh_token": refresh_token, + }, + ) + + try: + token_response = TokenResponse.model_validate_json(response.text) + except Exception: + raise RuntimeError("Confluence Cloud token refresh failed.") + + now = datetime.now(timezone.utc) + expires_at = now + timedelta(seconds=token_response.expires_in) + + new_credentials: dict[str, Any] = {} + new_credentials["confluence_access_token"] = token_response.access_token + new_credentials["confluence_refresh_token"] = token_response.refresh_token + new_credentials["created_at"] = now.isoformat() + new_credentials["expires_at"] = expires_at.isoformat() + new_credentials["expires_in"] = token_response.expires_in + new_credentials["scope"] = token_response.scope + new_credentials["cloud_id"] = cloud_id + return new_credentials + + +class TimeoutThread(threading.Thread, Generic[R]): + def __init__(self, timeout: float, func: Callable[..., R], *args: Any, **kwargs: Any): + super().__init__() + self.timeout = timeout + self.func = func + self.args = args + self.kwargs = kwargs + self.exception: Exception | None = None + + def run(self) -> None: + try: + self.result = self.func(*self.args, **self.kwargs) + except Exception as e: + self.exception = e + + def end(self) -> None: + raise TimeoutError(f"Function {self.func.__name__} timed out after {self.timeout} seconds") + + +def run_with_timeout(timeout: float, func: Callable[..., R], *args: Any, **kwargs: Any) -> R: + """ + Executes a function with a timeout. If the function doesn't complete within the specified + timeout, raises TimeoutError. + """ + context = contextvars.copy_context() + task = TimeoutThread(timeout, context.run, func, *args, **kwargs) + task.start() + task.join(timeout) + + if task.exception is not None: + raise task.exception + if task.is_alive(): + task.end() + + return task.result # type: ignore + + +def validate_attachment_filetype( + attachment: dict[str, Any], +) -> bool: + """ + Validates if the attachment is a supported file type. + """ + media_type = attachment.get("metadata", {}).get("mediaType", "") + if media_type.startswith("image/"): + return is_valid_image_type(media_type) + + # For non-image files, check if we support the extension + title = attachment.get("title", "") + extension = Path(title).suffix.lstrip(".").lower() if "." in title else "" + + return is_accepted_file_ext("." + extension, OnyxExtensionType.Plain | OnyxExtensionType.Document) + + +class CallableProtocol(Protocol): + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + + +def run_functions_tuples_in_parallel( + functions_with_args: Sequence[tuple[CallableProtocol, tuple[Any, ...]]], + allow_failures: bool = False, + max_workers: int | None = None, +) -> list[Any]: + """ + Executes multiple functions in parallel and returns a list of the results for each function. + This function preserves contextvars across threads, which is important for maintaining + context like tenant IDs in database sessions. + + Args: + functions_with_args: List of tuples each containing the function callable and a tuple of arguments. + allow_failures: if set to True, then the function result will just be None + max_workers: Max number of worker threads + + Returns: + list: A list of results from each function, in the same order as the input functions. + """ + workers = min(max_workers, len(functions_with_args)) if max_workers is not None else len(functions_with_args) + + if workers <= 0: + return [] + + results = [] + with ThreadPoolExecutor(max_workers=workers) as executor: + # The primary reason for propagating contextvars is to allow acquiring a db session + # that respects tenant id. Context.run is expected to be low-overhead, but if we later + # find that it is increasing latency we can make using it optional. + future_to_index = {executor.submit(contextvars.copy_context().run, func, *args): i for i, (func, args) in enumerate(functions_with_args)} + + for future in as_completed(future_to_index): + index = future_to_index[future] + try: + results.append((index, future.result())) + except Exception as e: + logging.exception(f"Function at index {index} failed due to {e}") + results.append((index, None)) # type: ignore + + if not allow_failures: + raise + + results.sort(key=lambda x: x[0]) + return [result for index, result in results] + + +def _next_or_none(ind: int, gen: Iterator[R]) -> tuple[int, R | None]: + return ind, next(gen, None) + + +def parallel_yield(gens: list[Iterator[R]], max_workers: int = 10) -> Iterator[R]: + """ + Runs the list of generators with thread-level parallelism, yielding + results as available. The asynchronous nature of this yielding means + that stopping the returned iterator early DOES NOT GUARANTEE THAT NO + FURTHER ITEMS WERE PRODUCED by the input gens. Only use this function + if you are consuming all elements from the generators OR it is acceptable + for some extra generator code to run and not have the result(s) yielded. + """ + with ThreadPoolExecutor(max_workers=max_workers) as executor: + future_to_index: dict[Future[tuple[int, R | None]], int] = {executor.submit(_next_or_none, ind, gen): ind for ind, gen in enumerate(gens)} + + next_ind = len(gens) + while future_to_index: + done, _ = wait(future_to_index, return_when=FIRST_COMPLETED) + for future in done: + ind, result = future.result() + if result is not None: + yield result + future_to_index[executor.submit(_next_or_none, ind, gens[ind])] = next_ind + next_ind += 1 + del future_to_index[future] diff --git a/common/decorator.py b/common/decorator.py new file mode 100644 index 00000000000..f45a41a9d8d --- /dev/null +++ b/common/decorator.py @@ -0,0 +1,27 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os + +def singleton(cls, *args, **kw): + instances = {} + + def _singleton(): + key = str(cls) + str(os.getpid()) + if key not in instances: + instances[key] = cls(*args, **kw) + return instances[key] + + return _singleton \ No newline at end of file diff --git a/common/exceptions.py b/common/exceptions.py new file mode 100644 index 00000000000..c0caac4842e --- /dev/null +++ b/common/exceptions.py @@ -0,0 +1,18 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class TaskCanceledException(Exception): + def __init__(self, msg): + self.msg = msg diff --git a/common/file_utils.py b/common/file_utils.py new file mode 100644 index 00000000000..3d7455b6b4a --- /dev/null +++ b/common/file_utils.py @@ -0,0 +1,39 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os + +PROJECT_BASE = os.getenv("RAG_PROJECT_BASE") or os.getenv("RAG_DEPLOY_BASE") + +def get_project_base_directory(*args): + global PROJECT_BASE + if PROJECT_BASE is None: + PROJECT_BASE = os.path.abspath( + os.path.join( + os.path.dirname(os.path.realpath(__file__)), + os.pardir, + ) + ) + + if args: + return os.path.join(PROJECT_BASE, *args) + return PROJECT_BASE + +def traversal_files(base): + for root, ds, fs in os.walk(base): + for f in fs: + fullname = os.path.join(root, f) + yield fullname diff --git a/common/float_utils.py b/common/float_utils.py new file mode 100644 index 00000000000..74db3b1cfdf --- /dev/null +++ b/common/float_utils.py @@ -0,0 +1,46 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +def get_float(v): + """ + Convert a value to float, handling None and exceptions gracefully. + + Attempts to convert the input value to a float. If the value is None or + cannot be converted to float, returns negative infinity as a default value. + + Args: + v: The value to convert to float. Can be any type that float() accepts, + or None. + + Returns: + float: The converted float value if successful, otherwise float('-inf'). + + Examples: + >>> get_float("3.14") + 3.14 + >>> get_float(None) + -inf + >>> get_float("invalid") + -inf + >>> get_float(42) + 42.0 + """ + if v is None: + return float('-inf') + try: + return float(v) + except Exception: + return float('-inf') \ No newline at end of file diff --git a/common/log_utils.py b/common/log_utils.py new file mode 100644 index 00000000000..e2110ebeb7e --- /dev/null +++ b/common/log_utils.py @@ -0,0 +1,83 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import os.path +import logging +from logging.handlers import RotatingFileHandler +from common.file_utils import get_project_base_directory + +initialized_root_logger = False + +def init_root_logger(logfile_basename: str, log_format: str = "%(asctime)-15s %(levelname)-8s %(process)d %(message)s"): + global initialized_root_logger + if initialized_root_logger: + return + initialized_root_logger = True + + logger = logging.getLogger() + logger.handlers.clear() + log_path = os.path.abspath(os.path.join(get_project_base_directory(), "logs", f"{logfile_basename}.log")) + + os.makedirs(os.path.dirname(log_path), exist_ok=True) + formatter = logging.Formatter(log_format) + + handler1 = RotatingFileHandler(log_path, maxBytes=10*1024*1024, backupCount=5) + handler1.setFormatter(formatter) + logger.addHandler(handler1) + + handler2 = logging.StreamHandler() + handler2.setFormatter(formatter) + logger.addHandler(handler2) + + logging.captureWarnings(True) + + LOG_LEVELS = os.environ.get("LOG_LEVELS", "") + pkg_levels = {} + for pkg_name_level in LOG_LEVELS.split(","): + terms = pkg_name_level.split("=") + if len(terms)!= 2: + continue + pkg_name, pkg_level = terms[0], terms[1] + pkg_name = pkg_name.strip() + pkg_level = logging.getLevelName(pkg_level.strip().upper()) + if not isinstance(pkg_level, int): + pkg_level = logging.INFO + pkg_levels[pkg_name] = logging.getLevelName(pkg_level) + + for pkg_name in ['peewee', 'pdfminer']: + if pkg_name not in pkg_levels: + pkg_levels[pkg_name] = logging.getLevelName(logging.WARNING) + if 'root' not in pkg_levels: + pkg_levels['root'] = logging.getLevelName(logging.INFO) + + for pkg_name, pkg_level in pkg_levels.items(): + pkg_logger = logging.getLogger(pkg_name) + pkg_logger.setLevel(pkg_level) + + msg = f"{logfile_basename} log path: {log_path}, log levels: {pkg_levels}" + logger.info(msg) + + +def log_exception(e, *args): + logging.exception(e) + for a in args: + if hasattr(a, "text"): + logging.error(a.text) + raise Exception(a.text) + else: + logging.error(str(a)) + raise e \ No newline at end of file diff --git a/common/misc_utils.py b/common/misc_utils.py new file mode 100644 index 00000000000..ae56fe5c484 --- /dev/null +++ b/common/misc_utils.py @@ -0,0 +1,108 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import base64 +import hashlib +import uuid +import requests +import threading +import subprocess +import sys +import os +import logging + +def get_uuid(): + return uuid.uuid1().hex + + +def download_img(url): + if not url: + return "" + response = requests.get(url) + return "data:" + \ + response.headers.get('Content-Type', 'image/jpg') + ";" + \ + "base64," + base64.b64encode(response.content).decode("utf-8") + + +def hash_str2int(line: str, mod: int = 10 ** 8) -> int: + return int(hashlib.sha1(line.encode("utf-8")).hexdigest(), 16) % mod + +def convert_bytes(size_in_bytes: int) -> str: + """ + Format size in bytes. + """ + if size_in_bytes == 0: + return "0 B" + + units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'] + i = 0 + size = float(size_in_bytes) + + while size >= 1024 and i < len(units) - 1: + size /= 1024 + i += 1 + + if i == 0 or size >= 100: + return f"{size:.0f} {units[i]}" + elif size >= 10: + return f"{size:.1f} {units[i]}" + else: + return f"{size:.2f} {units[i]}" + + +def once(func): + """ + A thread-safe decorator that ensures the decorated function runs exactly once, + caching and returning its result for all subsequent calls. This prevents + race conditions in multi-thread environments by using a lock to protect + the execution state. + + Args: + func (callable): The function to be executed only once. + + Returns: + callable: A wrapper function that executes `func` on the first call + and returns the cached result thereafter. + + Example: + @once + def compute_expensive_value(): + print("Computing...") + return 42 + + # First call: executes and prints + # Subsequent calls: return 42 without executing + """ + executed = False + result = None + lock = threading.Lock() + def wrapper(*args, **kwargs): + nonlocal executed, result + with lock: + if not executed: + executed = True + result = func(*args, **kwargs) + return result + return wrapper + +@once +def pip_install_torch(): + device = os.getenv("DEVICE", "cpu") + if device=="cpu": + return + logging.info("Installing pytorch") + pkg_names = ["torch>=2.5.0,<3.0.0"] + subprocess.check_call([sys.executable, "-m", "pip", "install", *pkg_names]) diff --git a/common/settings.py b/common/settings.py new file mode 100644 index 00000000000..27894b77416 --- /dev/null +++ b/common/settings.py @@ -0,0 +1,332 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import json +import secrets +from datetime import date +import logging +from common.constants import RAG_FLOW_SERVICE_NAME +from common.file_utils import get_project_base_directory +from common.config_utils import get_base_config, decrypt_database_config +from common.misc_utils import pip_install_torch +from common.constants import SVR_QUEUE_NAME, Storage + +import rag.utils +import rag.utils.es_conn +import rag.utils.infinity_conn +import rag.utils.opensearch_conn +from rag.utils.azure_sas_conn import RAGFlowAzureSasBlob +from rag.utils.azure_spn_conn import RAGFlowAzureSpnBlob +from rag.utils.minio_conn import RAGFlowMinio +from rag.utils.opendal_conn import OpenDALStorage +from rag.utils.s3_conn import RAGFlowS3 +from rag.utils.oss_conn import RAGFlowOSS + +from rag.nlp import search + +LLM = None +LLM_FACTORY = None +LLM_BASE_URL = None +CHAT_MDL = "" +EMBEDDING_MDL = "" +RERANK_MDL = "" +ASR_MDL = "" +IMAGE2TEXT_MDL = "" + + +CHAT_CFG = "" +EMBEDDING_CFG = "" +RERANK_CFG = "" +ASR_CFG = "" +IMAGE2TEXT_CFG = "" +API_KEY = None +PARSERS = None +HOST_IP = None +HOST_PORT = None +SECRET_KEY = None +FACTORY_LLM_INFOS = None +ALLOWED_LLM_FACTORIES = None + +DATABASE_TYPE = os.getenv("DB_TYPE", "mysql") +DATABASE = decrypt_database_config(name=DATABASE_TYPE) + +# authentication +AUTHENTICATION_CONF = None + +# client +CLIENT_AUTHENTICATION = None +HTTP_APP_KEY = None +GITHUB_OAUTH = None +FEISHU_OAUTH = None +OAUTH_CONFIG = None +DOC_ENGINE = os.getenv('DOC_ENGINE', 'elasticsearch') + +docStoreConn = None + +retriever = None +kg_retriever = None + +# user registration switch +REGISTER_ENABLED = 1 + + +# sandbox-executor-manager +SANDBOX_HOST = None +STRONG_TEST_COUNT = int(os.environ.get("STRONG_TEST_COUNT", "8")) + +SMTP_CONF = None +MAIL_SERVER = "" +MAIL_PORT = 000 +MAIL_USE_SSL = True +MAIL_USE_TLS = False +MAIL_USERNAME = "" +MAIL_PASSWORD = "" +MAIL_DEFAULT_SENDER = () +MAIL_FRONTEND_URL = "" + +# move from rag.settings +ES = {} +INFINITY = {} +AZURE = {} +S3 = {} +MINIO = {} +OSS = {} +OS = {} + +DOC_MAXIMUM_SIZE: int = 128 * 1024 * 1024 +DOC_BULK_SIZE: int = 4 +EMBEDDING_BATCH_SIZE: int = 16 + +PARALLEL_DEVICES: int = 0 + +STORAGE_IMPL_TYPE = os.getenv('STORAGE_IMPL', 'MINIO') +STORAGE_IMPL = None + +def get_svr_queue_name(priority: int) -> str: + if priority == 0: + return SVR_QUEUE_NAME + return f"{SVR_QUEUE_NAME}_{priority}" + +def get_svr_queue_names(): + return [get_svr_queue_name(priority) for priority in [1, 0]] + +def _get_or_create_secret_key(): + secret_key = os.environ.get("RAGFLOW_SECRET_KEY") + if secret_key and len(secret_key) >= 32: + return secret_key + + # Check if there's a configured secret key + configured_key = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("secret_key") + if configured_key and configured_key != str(date.today()) and len(configured_key) >= 32: + return configured_key + + # Generate a new secure key and warn about it + import logging + + new_key = secrets.token_hex(32) + logging.warning(f"SECURITY WARNING: Using auto-generated SECRET_KEY. Generated key: {new_key}") + return new_key + +class StorageFactory: + storage_mapping = { + Storage.MINIO: RAGFlowMinio, + Storage.AZURE_SPN: RAGFlowAzureSpnBlob, + Storage.AZURE_SAS: RAGFlowAzureSasBlob, + Storage.AWS_S3: RAGFlowS3, + Storage.OSS: RAGFlowOSS, + Storage.OPENDAL: OpenDALStorage + } + + @classmethod + def create(cls, storage: Storage): + return cls.storage_mapping[storage]() + + +def init_settings(): + global DATABASE_TYPE, DATABASE + DATABASE_TYPE = os.getenv("DB_TYPE", "mysql") + DATABASE = decrypt_database_config(name=DATABASE_TYPE) + + global ALLOWED_LLM_FACTORIES, LLM_FACTORY, LLM_BASE_URL + llm_settings = get_base_config("user_default_llm", {}) or {} + llm_default_models = llm_settings.get("default_models", {}) or {} + LLM_FACTORY = llm_settings.get("factory", "") or "" + LLM_BASE_URL = llm_settings.get("base_url", "") or "" + ALLOWED_LLM_FACTORIES = llm_settings.get("allowed_factories", None) + + global REGISTER_ENABLED + try: + REGISTER_ENABLED = int(os.environ.get("REGISTER_ENABLED", "1")) + except Exception: + pass + + global FACTORY_LLM_INFOS + try: + with open(os.path.join(get_project_base_directory(), "conf", "llm_factories.json"), "r") as f: + FACTORY_LLM_INFOS = json.load(f)["factory_llm_infos"] + except Exception: + FACTORY_LLM_INFOS = [] + + global API_KEY + API_KEY = llm_settings.get("api_key") + + global PARSERS + PARSERS = llm_settings.get( + "parsers", "naive:General,qa:Q&A,resume:Resume,manual:Manual,table:Table,paper:Paper,book:Book,laws:Laws,presentation:Presentation,picture:Picture,one:One,audio:Audio,email:Email,tag:Tag" + ) + + global CHAT_MDL, EMBEDDING_MDL, RERANK_MDL, ASR_MDL, IMAGE2TEXT_MDL + chat_entry = _parse_model_entry(llm_default_models.get("chat_model", CHAT_MDL)) + embedding_entry = _parse_model_entry(llm_default_models.get("embedding_model", EMBEDDING_MDL)) + rerank_entry = _parse_model_entry(llm_default_models.get("rerank_model", RERANK_MDL)) + asr_entry = _parse_model_entry(llm_default_models.get("asr_model", ASR_MDL)) + image2text_entry = _parse_model_entry(llm_default_models.get("image2text_model", IMAGE2TEXT_MDL)) + + global CHAT_CFG, EMBEDDING_CFG, RERANK_CFG, ASR_CFG, IMAGE2TEXT_CFG + CHAT_CFG = _resolve_per_model_config(chat_entry, LLM_FACTORY, API_KEY, LLM_BASE_URL) + EMBEDDING_CFG = _resolve_per_model_config(embedding_entry, LLM_FACTORY, API_KEY, LLM_BASE_URL) + RERANK_CFG = _resolve_per_model_config(rerank_entry, LLM_FACTORY, API_KEY, LLM_BASE_URL) + ASR_CFG = _resolve_per_model_config(asr_entry, LLM_FACTORY, API_KEY, LLM_BASE_URL) + IMAGE2TEXT_CFG = _resolve_per_model_config(image2text_entry, LLM_FACTORY, API_KEY, LLM_BASE_URL) + + CHAT_MDL = CHAT_CFG.get("model", "") or "" + EMBEDDING_MDL = os.getenv("TEI_MODEL", "BAAI/bge-small-en-v1.5") if "tei-" in os.getenv("COMPOSE_PROFILES", "") else "" + RERANK_MDL = RERANK_CFG.get("model", "") or "" + ASR_MDL = ASR_CFG.get("model", "") or "" + IMAGE2TEXT_MDL = IMAGE2TEXT_CFG.get("model", "") or "" + + global HOST_IP, HOST_PORT + HOST_IP = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("host", "127.0.0.1") + HOST_PORT = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("http_port") + + global SECRET_KEY + SECRET_KEY = _get_or_create_secret_key() + + + # authentication + authentication_conf = get_base_config("authentication", {}) + + global CLIENT_AUTHENTICATION, HTTP_APP_KEY, GITHUB_OAUTH, FEISHU_OAUTH, OAUTH_CONFIG + # client + CLIENT_AUTHENTICATION = authentication_conf.get("client", {}).get("switch", False) + HTTP_APP_KEY = authentication_conf.get("client", {}).get("http_app_key") + GITHUB_OAUTH = get_base_config("oauth", {}).get("github") + FEISHU_OAUTH = get_base_config("oauth", {}).get("feishu") + OAUTH_CONFIG = get_base_config("oauth", {}) + + global DOC_ENGINE, docStoreConn, ES, OS, INFINITY + DOC_ENGINE = os.environ.get("DOC_ENGINE", "elasticsearch") + # DOC_ENGINE = os.environ.get('DOC_ENGINE', "opensearch") + lower_case_doc_engine = DOC_ENGINE.lower() + if lower_case_doc_engine == "elasticsearch": + ES = get_base_config("es", {}) + docStoreConn = rag.utils.es_conn.ESConnection() + elif lower_case_doc_engine == "infinity": + INFINITY = get_base_config("infinity", {"uri": "infinity:23817"}) + docStoreConn = rag.utils.infinity_conn.InfinityConnection() + elif lower_case_doc_engine == "opensearch": + OS = get_base_config("os", {}) + docStoreConn = rag.utils.opensearch_conn.OSConnection() + else: + raise Exception(f"Not supported doc engine: {DOC_ENGINE}") + + global AZURE, S3, MINIO, OSS + if STORAGE_IMPL_TYPE in ['AZURE_SPN', 'AZURE_SAS']: + AZURE = get_base_config("azure", {}) + elif STORAGE_IMPL_TYPE == 'AWS_S3': + S3 = get_base_config("s3", {}) + elif STORAGE_IMPL_TYPE == 'MINIO': + MINIO = decrypt_database_config(name="minio") + elif STORAGE_IMPL_TYPE == 'OSS': + OSS = get_base_config("oss", {}) + + global STORAGE_IMPL + STORAGE_IMPL = StorageFactory.create(Storage[STORAGE_IMPL_TYPE]) + + global retriever, kg_retriever + retriever = search.Dealer(docStoreConn) + from graphrag import search as kg_search + + kg_retriever = kg_search.KGSearch(docStoreConn) + + global SANDBOX_HOST + if int(os.environ.get("SANDBOX_ENABLED", "0")): + SANDBOX_HOST = os.environ.get("SANDBOX_HOST", "sandbox-executor-manager") + + global SMTP_CONF + SMTP_CONF = get_base_config("smtp", {}) + + global MAIL_SERVER, MAIL_PORT, MAIL_USE_SSL, MAIL_USE_TLS, MAIL_USERNAME, MAIL_PASSWORD, MAIL_DEFAULT_SENDER, MAIL_FRONTEND_URL + MAIL_SERVER = SMTP_CONF.get("mail_server", "") + MAIL_PORT = SMTP_CONF.get("mail_port", 000) + MAIL_USE_SSL = SMTP_CONF.get("mail_use_ssl", True) + MAIL_USE_TLS = SMTP_CONF.get("mail_use_tls", False) + MAIL_USERNAME = SMTP_CONF.get("mail_username", "") + MAIL_PASSWORD = SMTP_CONF.get("mail_password", "") + mail_default_sender = SMTP_CONF.get("mail_default_sender", []) + if mail_default_sender and len(mail_default_sender) >= 2: + MAIL_DEFAULT_SENDER = (mail_default_sender[0], mail_default_sender[1]) + MAIL_FRONTEND_URL = SMTP_CONF.get("mail_frontend_url", "") + + global DOC_MAXIMUM_SIZE, DOC_BULK_SIZE, EMBEDDING_BATCH_SIZE + DOC_MAXIMUM_SIZE = int(os.environ.get("MAX_CONTENT_LENGTH", 128 * 1024 * 1024)) + DOC_BULK_SIZE = int(os.environ.get("DOC_BULK_SIZE", 4)) + EMBEDDING_BATCH_SIZE = int(os.environ.get("EMBEDDING_BATCH_SIZE", 16)) + +def check_and_install_torch(): + global PARALLEL_DEVICES + try: + pip_install_torch() + import torch.cuda + PARALLEL_DEVICES = torch.cuda.device_count() + logging.info(f"found {PARALLEL_DEVICES} gpus") + except Exception: + logging.info("can't import package 'torch'") + +def _parse_model_entry(entry): + if isinstance(entry, str): + return {"name": entry, "factory": None, "api_key": None, "base_url": None} + if isinstance(entry, dict): + name = entry.get("name") or entry.get("model") or "" + return { + "name": name, + "factory": entry.get("factory"), + "api_key": entry.get("api_key"), + "base_url": entry.get("base_url"), + } + return {"name": "", "factory": None, "api_key": None, "base_url": None} + + +def _resolve_per_model_config(entry_dict, backup_factory, backup_api_key, backup_base_url): + name = (entry_dict.get("name") or "").strip() + m_factory = entry_dict.get("factory") or backup_factory or "" + m_api_key = entry_dict.get("api_key") or backup_api_key or "" + m_base_url = entry_dict.get("base_url") or backup_base_url or "" + + if name and "@" not in name and m_factory: + name = f"{name}@{m_factory}" + + return { + "model": name, + "factory": m_factory, + "api_key": m_api_key, + "base_url": m_base_url, + } + +def print_rag_settings(): + logging.info(f"MAX_CONTENT_LENGTH: {DOC_MAXIMUM_SIZE}") + logging.info(f"MAX_FILE_COUNT_PER_USER: {int(os.environ.get('MAX_FILE_NUM_PER_USER', 0))}") + diff --git a/common/signal_utils.py b/common/signal_utils.py new file mode 100644 index 00000000000..eb814325ae0 --- /dev/null +++ b/common/signal_utils.py @@ -0,0 +1,55 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import sys +from datetime import datetime +import logging +import tracemalloc +from common.log_utils import get_project_base_directory + +# SIGUSR1 handler: start tracemalloc and take snapshot +def start_tracemalloc_and_snapshot(signum, frame): + if not tracemalloc.is_tracing(): + logging.info("start tracemalloc") + tracemalloc.start() + else: + logging.info("tracemalloc is already running") + + timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + snapshot_file = f"snapshot_{timestamp}.trace" + snapshot_file = os.path.abspath(os.path.join(get_project_base_directory(), "logs", f"{os.getpid()}_snapshot_{timestamp}.trace")) + + snapshot = tracemalloc.take_snapshot() + snapshot.dump(snapshot_file) + current, peak = tracemalloc.get_traced_memory() + if sys.platform == "win32": + import psutil + process = psutil.Process() + max_rss = process.memory_info().rss / 1024 + else: + import resource + max_rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss + logging.info(f"taken snapshot {snapshot_file}. max RSS={max_rss / 1000:.2f} MB, current memory usage: {current / 10**6:.2f} MB, Peak memory usage: {peak / 10**6:.2f} MB") + + +# SIGUSR2 handler: stop tracemalloc +def stop_tracemalloc(signum, frame): + if tracemalloc.is_tracing(): + logging.info("stop tracemalloc") + tracemalloc.stop() + else: + logging.info("tracemalloc not running") diff --git a/common/string_utils.py b/common/string_utils.py new file mode 100644 index 00000000000..9d4dc8d4d35 --- /dev/null +++ b/common/string_utils.py @@ -0,0 +1,73 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import re + + +def remove_redundant_spaces(txt: str): + """ + Remove redundant spaces around punctuation marks while preserving meaningful spaces. + + This function performs two main operations: + 1. Remove spaces after left-boundary characters (opening brackets, etc.) + 2. Remove spaces before right-boundary characters (closing brackets, punctuation, etc.) + + Args: + txt (str): Input text to process + + Returns: + str: Text with redundant spaces removed + """ + # First pass: Remove spaces after left-boundary characters + # Matches: [non-alphanumeric-and-specific-right-punctuation] + [non-space] + # Removes spaces after characters like '(', '<', and other non-alphanumeric chars + # Examples: + # "( test" → "(test" + txt = re.sub(r"([^a-z0-9.,\)>]) +([^ ])", r"\1\2", txt, flags=re.IGNORECASE) + + # Second pass: Remove spaces before right-boundary characters + # Matches: [non-space] + [non-alphanumeric-and-specific-left-punctuation] + # Removes spaces before characters like non-')', non-',', non-'.', and non-alphanumeric chars + # Examples: + # "world !" → "world!" + return re.sub(r"([^ ]) +([^a-z0-9.,\(<])", r"\1\2", txt, flags=re.IGNORECASE) + + +def clean_markdown_block(text): + """ + Remove Markdown code block syntax from the beginning and end of text. + + This function cleans Markdown code blocks by removing: + - Opening ```Markdown tags (with optional whitespace and newlines) + - Closing ``` tags (with optional whitespace and newlines) + + Args: + text (str): Input text that may be wrapped in Markdown code blocks + + Returns: + str: Cleaned text with Markdown code block syntax removed, and stripped of surrounding whitespace + + """ + # Remove opening ```markdown tag with optional whitespace and newlines + # Matches: optional whitespace + ```markdown + optional whitespace + optional newline + text = re.sub(r'^\s*```markdown\s*\n?', '', text) + + # Remove closing ``` tag with optional whitespace and newlines + # Matches: optional newline + optional whitespace + ``` + optional whitespace at end + text = re.sub(r'\n?\s*```\s*$', '', text) + + # Return text with surrounding whitespace removed + return text.strip() diff --git a/common/time_utils.py b/common/time_utils.py new file mode 100644 index 00000000000..a924b3405d7 --- /dev/null +++ b/common/time_utils.py @@ -0,0 +1,126 @@ +# +# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import datetime +import time + +def current_timestamp(): + """ + Get the current timestamp in milliseconds. + + Returns: + int: Current Unix timestamp in milliseconds (13 digits) + + Example: + >>> current_timestamp() + 1704067200000 + """ + return int(time.time() * 1000) + + +def timestamp_to_date(timestamp, format_string="%Y-%m-%d %H:%M:%S"): + """ + Convert a timestamp to formatted date string. + + Args: + timestamp: Unix timestamp in milliseconds. If None or empty, uses current time. + format_string: Format string for the output date (default: "%Y-%m-%d %H:%M:%S") + + Returns: + str: Formatted date string + + Example: + >>> timestamp_to_date(1704067200000) + '2024-01-01 08:00:00' + """ + if not timestamp: + timestamp = time.time() + timestamp = int(timestamp) / 1000 + time_array = time.localtime(timestamp) + str_date = time.strftime(format_string, time_array) + return str_date + + +def date_string_to_timestamp(time_str, format_string="%Y-%m-%d %H:%M:%S"): + """ + Convert a date string to timestamp in milliseconds. + + Args: + time_str: Date string to convert + format_string: Format of the input date string (default: "%Y-%m-%d %H:%M:%S") + + Returns: + int: Unix timestamp in milliseconds + + Example: + >>> date_string_to_timestamp("2024-01-01 00:00:00") + 1704067200000 + """ + time_array = time.strptime(time_str, format_string) + time_stamp = int(time.mktime(time_array) * 1000) + return time_stamp + +def datetime_format(date_time: datetime.datetime) -> datetime.datetime: + """ + Normalize a datetime object by removing microsecond component. + + Creates a new datetime object with only year, month, day, hour, minute, second. + Microseconds are set to 0. + + Args: + date_time: datetime object to normalize + + Returns: + datetime.datetime: New datetime object without microseconds + + Example: + >>> dt = datetime.datetime(2024, 1, 1, 12, 30, 45, 123456) + >>> datetime_format(dt) + datetime.datetime(2024, 1, 1, 12, 30, 45) + """ + return datetime.datetime(date_time.year, date_time.month, date_time.day, + date_time.hour, date_time.minute, date_time.second) + + +def get_format_time() -> datetime.datetime: + """ + Get current datetime normalized without microseconds. + + Returns: + datetime.datetime: Current datetime with microseconds set to 0 + + Example: + >>> get_format_time() + datetime.datetime(2024, 1, 1, 12, 30, 45) + """ + return datetime_format(datetime.datetime.now()) + + +def delta_seconds(date_string: str): + """ + Calculate seconds elapsed from a given date string to now. + + Args: + date_string: Date string in "YYYY-MM-DD HH:MM:SS" format + + Returns: + float: Number of seconds between the given date and current time + + Example: + >>> delta_seconds("2024-01-01 12:00:00") + 3600.0 # If current time is 2024-01-01 13:00:00 + """ + dt = datetime.datetime.strptime(date_string, "%Y-%m-%d %H:%M:%S") + return (datetime.datetime.now() - dt).total_seconds() \ No newline at end of file diff --git a/common/token_utils.py b/common/token_utils.py new file mode 100644 index 00000000000..29f10f7eb45 --- /dev/null +++ b/common/token_utils.py @@ -0,0 +1,76 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +import os +import tiktoken + +from common.file_utils import get_project_base_directory + +tiktoken_cache_dir = get_project_base_directory() +os.environ["TIKTOKEN_CACHE_DIR"] = tiktoken_cache_dir +# encoder = tiktoken.encoding_for_model("gpt-3.5-turbo") +encoder = tiktoken.get_encoding("cl100k_base") + + +def num_tokens_from_string(string: str) -> int: + """Returns the number of tokens in a text string.""" + try: + code_list = encoder.encode(string) + return len(code_list) + except Exception: + return 0 + +def total_token_count_from_response(resp): + if resp is None: + return 0 + + if hasattr(resp, "usage") and hasattr(resp.usage, "total_tokens"): + try: + return resp.usage.total_tokens + except Exception: + pass + + if hasattr(resp, "usage_metadata") and hasattr(resp.usage_metadata, "total_tokens"): + try: + return resp.usage_metadata.total_tokens + except Exception: + pass + + if 'usage' in resp and 'total_tokens' in resp['usage']: + try: + return resp["usage"]["total_tokens"] + except Exception: + pass + + if 'usage' in resp and 'input_tokens' in resp['usage'] and 'output_tokens' in resp['usage']: + try: + return resp["usage"]["input_tokens"] + resp["usage"]["output_tokens"] + except Exception: + pass + + if 'meta' in resp and 'tokens' in resp['meta'] and 'input_tokens' in resp['meta']['tokens'] and 'output_tokens' in resp['meta']['tokens']: + try: + return resp["meta"]["tokens"]["input_tokens"] + resp["meta"]["tokens"]["output_tokens"] + except Exception: + pass + return 0 + + +def truncate(string: str, max_len: int) -> str: + """Returns truncated text if the length of text exceed max_len.""" + return encoder.decode(encoder.encode(string)[:max_len]) + diff --git a/api/versions.py b/common/versions.py similarity index 89% rename from api/versions.py rename to common/versions.py index 6ba1e343a3c..082927c5854 100644 --- a/api/versions.py +++ b/common/versions.py @@ -1,5 +1,5 @@ # -# Copyright 2024 The InfiniFlow Authors. All Rights Reserved. +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -34,8 +34,6 @@ def get_ragflow_version() -> str: RAGFLOW_VERSION_INFO = f.read().strip() else: RAGFLOW_VERSION_INFO = get_closest_tag_and_count() - LIGHTEN = int(os.environ.get("LIGHTEN", "0")) - RAGFLOW_VERSION_INFO += " slim" if LIGHTEN == 1 else " full" return RAGFLOW_VERSION_INFO diff --git a/conf/infinity_mapping.json b/conf/infinity_mapping.json index f6772852c2a..51888e9ded7 100644 --- a/conf/infinity_mapping.json +++ b/conf/infinity_mapping.json @@ -30,8 +30,7 @@ "knowledge_graph_kwd": {"type": "varchar", "default": ""}, "entities_kwd": {"type": "varchar", "default": "", "analyzer": "whitespace-#"}, "pagerank_fea": {"type": "integer", "default": 0}, - "tag_feas": {"type": "varchar", "default": ""}, - + "tag_feas": {"type": "varchar", "default": "", "analyzer": "rankfeatures"}, "from_entity_kwd": {"type": "varchar", "default": "", "analyzer": "whitespace-#"}, "to_entity_kwd": {"type": "varchar", "default": "", "analyzer": "whitespace-#"}, "entity_kwd": {"type": "varchar", "default": "", "analyzer": "whitespace-#"}, @@ -39,6 +38,7 @@ "source_id": {"type": "varchar", "default": "", "analyzer": "whitespace-#"}, "n_hop_with_weight": {"type": "varchar", "default": ""}, "removed_kwd": {"type": "varchar", "default": "", "analyzer": "whitespace-#"}, - - "doc_type_kwd": {"type": "varchar", "default": "", "analyzer": "whitespace-#"} + "doc_type_kwd": {"type": "varchar", "default": "", "analyzer": "whitespace-#"}, + "toc_kwd": {"type": "varchar", "default": "", "analyzer": "whitespace-#"}, + "raptor_kwd": {"type": "varchar", "default": "", "analyzer": "whitespace-#"} } diff --git a/conf/llm_factories.json b/conf/llm_factories.json index 5e02696e669..82eb2528515 100644 --- a/conf/llm_factories.json +++ b/conf/llm_factories.json @@ -5,7 +5,36 @@ "logo": "", "tags": "LLM,TEXT EMBEDDING,TTS,TEXT RE-RANK,SPEECH2TEXT,MODERATION", "status": "1", + "rank": "999", "llm": [ + { + "llm_name": "gpt-5", + "tags": "LLM,CHAT,400k,IMAGE2TEXT", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5-mini", + "tags": "LLM,CHAT,400k,IMAGE2TEXT", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5-nano", + "tags": "LLM,CHAT,400k,IMAGE2TEXT", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5-chat-latest", + "tags": "LLM,CHAT,400k,IMAGE2TEXT", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": false + }, { "llm_name": "gpt-4.1", "tags": "LLM,CHAT,1M,IMAGE2TEXT", @@ -141,12 +170,177 @@ } ] }, + { + "name": "xAI", + "logo": "", + "tags": "LLM", + "status": "1", + "rank": "930", + "llm": [ + { + "llm_name": "grok-4", + "tags": "LLM,CHAT,256k", + "max_tokens": 256000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3", + "tags": "LLM,CHAT,130k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3-fast", + "tags": "LLM,CHAT,130k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3-mini", + "tags": "LLM,CHAT,130k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3-mini-mini-fast", + "tags": "LLM,CHAT,130k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-2-vision", + "tags": "LLM,CHAT,IMAGE2TEXT,32k", + "max_tokens": 32768, + "model_type": "image2text", + "is_tools": true + } + ] + }, + { + "name": "TokenPony", + "logo": "", + "tags": "LLM", + "status": "1", + "llm": [ + { + "llm_name": "qwen3-8b", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-v3-0324", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-32b", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "kimi-k2-instruct-0905", + "tags": "LLM,CHAT,256K", + "max_tokens": 256000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-r1-0528", + "tags": "LLM,CHAT,164k", + "max_tokens": 164000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-coder-480b", + "tags": "LLM,CHAT,1024k", + "max_tokens": 1024000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "glm-4.5", + "tags": "LLM,CHAT,131K", + "max_tokens": 131000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-v3.1", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "hunyuan-a13b-instruct", + "tags": "LLM,CHAT,256k", + "max_tokens": 256000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-next-80b-a3b-instruct", + "tags": "LLM,CHAT,1024k", + "max_tokens": 1024000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-v3.2-exp", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-v3.1-terminus", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-vl-235b-a22b-instruct", + "tags": "LLM,CHAT,262k", + "max_tokens": 262000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-vl-30b-a3b-instruct", + "tags": "LLM,CHAT,262k", + "max_tokens": 262000, + "model_type": "chat", + "is_tools": true + } + ] + }, { "name": "Tongyi-Qianwen", "logo": "", "tags": "LLM,TEXT EMBEDDING,TEXT RE-RANK,TTS,SPEECH2TEXT,MODERATION", "status": "1", + "rank": "950", "llm": [ + { + "llm_name": "Moonshot-Kimi-K2-Instruct", + "tags": "LLM,CHAT,128K", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, { "llm_name": "deepseek-r1", "tags": "LLM,CHAT,64K", @@ -217,6 +411,20 @@ "model_type": "chat", "is_tools": true }, + { + "llm_name": "qwen-plus-2025-07-28", + "tags": "LLM,CHAT,132k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen-plus-2025-07-14", + "tags": "LLM,CHAT,132k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, { "llm_name": "qwq-plus-latest", "tags": "LLM,CHAT,132k", @@ -224,6 +432,48 @@ "model_type": "chat", "is_tools": true }, + { + "llm_name": "qwen-flash", + "tags": "LLM,CHAT,1M", + "max_tokens": 1000000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen-flash-2025-07-28", + "tags": "LLM,CHAT,1M", + "max_tokens": 1000000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-max", + "tags": "LLM,CHAT,256k", + "max_tokens": 256000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-coder-480b-a35b-instruct", + "tags": "LLM,CHAT,256k", + "max_tokens": 256000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-30b-a3b-instruct-2507", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-30b-a3b-thinking-2507", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, { "llm_name": "qwen3-30b-a3b", "tags": "LLM,CHAT,128k", @@ -231,6 +481,41 @@ "model_type": "chat", "is_tools": true }, + { + "llm_name": "qwen3-vl-plus", + "tags": "LLM,CHAT,IMAGE2TEXT,256k", + "max_tokens": 256000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "qwen3-vl-235b-a22b-instruct", + "tags": "LLM,CHAT,IMAGE2TEXT,128k", + "max_tokens": 128000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "qwen3-vl-235b-a22b-thinking", + "tags": "LLM,CHAT,IMAGE2TEXT,128k", + "max_tokens": 128000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "qwen3-235b-a22b-instruct-2507", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-235b-a22b-thinking-2507", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, { "llm_name": "qwen3-235b-a22b", "tags": "LLM,CHAT,128k", @@ -238,6 +523,20 @@ "model_type": "chat", "is_tools": true }, + { + "llm_name": "qwen3-next-80b-a3b-instruct", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-next-80b-a3b-thinking", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, { "llm_name": "qwen3-0.6b", "tags": "LLM,CHAT,32k", @@ -385,6 +684,31 @@ "tags": "RE-RANK,4k", "max_tokens": 4000, "model_type": "rerank" + }, + { + "llm_name": "qwen-audio-asr", + "tags": "SPEECH2TEXT,8k", + "max_tokens": 8000, + "model_type": "speech2text" + }, + { + "llm_name": "qwen-audio-asr-latest", + "tags": "SPEECH2TEXT,8k", + "max_tokens": 8000, + "model_type": "speech2text" + }, + { + "llm_name": "qwen-audio-asr-1204", + "tags": "SPEECH2TEXT,8k", + "max_tokens": 8000, + "model_type": "speech2text" + }, + { + "llm_name": "qianwen-deepresearch-30b-a3b-131k", + "tags": "LLM,CHAT,1M,AGENT,DEEPRESEARCH", + "max_tokens": 1000000, + "model_type": "chat", + "is_tools": true } ] }, @@ -393,24 +717,67 @@ "logo": "", "tags": "LLM,TEXT EMBEDDING,SPEECH2TEXT,MODERATION", "status": "1", + "rank": "940", "llm": [ { - "llm_name": "glm-4-plus", - "tags": "LLM,CHAT,", + "llm_name": "glm-4.5", + "tags": "LLM,CHAT,128K", "max_tokens": 128000, "model_type": "chat", "is_tools": true }, { - "llm_name": "glm-4-0520", - "tags": "LLM,CHAT,", + "llm_name": "glm-4.5-x", + "tags": "LLM,CHAT,128k", "max_tokens": 128000, "model_type": "chat", "is_tools": true }, { - "llm_name": "glm-4", - "tags": "LLM,CHAT,", + "llm_name": "glm-4.5-air", + "tags": "LLM,CHAT,128K", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "glm-4.5-airx", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "glm-4.5-flash", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "glm-4.5v", + "tags": "LLM,IMAGE2TEXT,64,", + "max_tokens": 64000, + "model_type": "image2text", + "is_tools": false + }, + { + "llm_name": "glm-4-plus", + "tags": "LLM,CHAT,128K", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "glm-4-0520", + "tags": "LLM,CHAT,128K", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "glm-4", + "tags": "LLM,CHAT,128K", "max_tokens": 128000, "model_type": "chat", "is_tools": true @@ -482,6 +849,12 @@ "tags": "TEXT EMBEDDING", "max_tokens": 512, "model_type": "embedding" + }, + { + "llm_name": "glm-asr", + "tags": "SPEECH2TEXT", + "max_tokens": 4096, + "model_type": "speech2text" } ] }, @@ -490,6 +863,7 @@ "logo": "", "tags": "LLM,TEXT EMBEDDING,SPEECH2TEXT,MODERATION", "status": "1", + "rank": "830", "llm": [] }, { @@ -511,7 +885,8 @@ "logo": "", "tags": "LLM,TEXT EMBEDDING,SPEECH2TEXT,MODERATION", "status": "1", - "llm": [] + "llm": [], + "rank": "890" }, { "name": "VLLM", @@ -523,30 +898,101 @@ { "name": "Moonshot", "logo": "", - "tags": "LLM,TEXT EMBEDDING", + "tags": "LLM,TEXT EMBEDDING,IMAGE2TEXT", "status": "1", + "rank": "960", "llm": [ + { + "llm_name": "kimi-thinking-preview", + "tags": "LLM,CHAT,1M", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "kimi-k2-0711-preview", + "tags": "LLM,CHAT,128k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "kimi-k2-0905-preview", + "tags": "LLM,CHAT,256k", + "max_tokens": 262144, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "kimi-k2-thinking", + "tags": "LLM,CHAT,256k", + "max_tokens": 262144, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "kimi-k2-thinking-turbo", + "tags": "LLM,CHAT,256k", + "max_tokens": 262144, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "kimi-k2-turbo-preview", + "tags": "LLM,CHAT,256k", + "max_tokens": 262144, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "kimi-latest", + "tags": "LLM,CHAT,8k,32k,128k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, { "llm_name": "moonshot-v1-8k", - "tags": "LLM,CHAT,", - "max_tokens": 7900, + "tags": "LLM,CHAT,8k", + "max_tokens": 8192, "model_type": "chat", "is_tools": true }, { "llm_name": "moonshot-v1-32k", - "tags": "LLM,CHAT,", + "tags": "LLM,CHAT,32k", "max_tokens": 32768, "model_type": "chat", "is_tools": true }, { "llm_name": "moonshot-v1-128k", - "tags": "LLM,CHAT", - "max_tokens": 128000, + "tags": "LLM,CHAT,128k", + "max_tokens": 131072, "model_type": "chat", "is_tools": true }, + { + "llm_name": "moonshot-v1-8k-vision-preview", + "tags": "LLM,IMAGE2TEXT,8k", + "max_tokens": 8192, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "moonshot-v1-32k-vision-preview", + "tags": "LLM,IMAGE2TEXT,32k", + "max_tokens": 32768, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "moonshot-v1-128k-vision-preview", + "tags": "LLM,IMAGE2TEXT,128k", + "max_tokens": 131072, + "model_type": "image2text", + "is_tools": true + }, { "llm_name": "moonshot-v1-auto", "tags": "LLM,CHAT,", @@ -570,25 +1016,12 @@ "status": "1", "llm": [] }, - { - "name": "Youdao", - "logo": "", - "tags": "TEXT EMBEDDING", - "status": "1", - "llm": [ - { - "llm_name": "maidalun1020/bce-embedding-base_v1", - "tags": "TEXT EMBEDDING,", - "max_tokens": 512, - "model_type": "embedding" - } - ] - }, { "name": "DeepSeek", "logo": "", "tags": "LLM", "status": "1", + "rank": "970", "llm": [ { "llm_name": "deepseek-chat", @@ -609,31 +1042,9 @@ { "name": "VolcEngine", "logo": "", - "tags": "LLM, TEXT EMBEDDING", + "tags": "LLM, TEXT EMBEDDING, IMAGE2TEXT", "status": "1", - "llm": [ - { - "llm_name": "Doubao-pro-128k", - "tags": "LLM,CHAT,128k", - "max_tokens": 131072, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Doubao-pro-32k", - "tags": "LLM,CHAT,32k", - "max_tokens": 32768, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Doubao-pro-4k", - "tags": "LLM,CHAT,4k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - } - ] + "llm": [] }, { "name": "BaiChuan", @@ -759,15 +1170,27 @@ ] }, { - "name": "BAAI", + "name": "Builtin", "logo": "", - "tags": "TEXT EMBEDDING", + "tags": "TEXT EMBEDDING", "status": "1", "llm": [ { - "llm_name": "BAAI/bge-large-zh-v1.5", - "tags": "TEXT EMBEDDING,", - "max_tokens": 1024, + "llm_name": "BAAI/bge-small-en-v1.5", + "tags": "TEXT EMBEDDING,512", + "max_tokens": 512, + "model_type": "embedding" + }, + { + "llm_name": "BAAI/bge-m3", + "tags": "TEXT EMBEDDING,8k", + "max_tokens": 8192, + "model_type": "embedding" + }, + { + "llm_name": "Qwen/Qwen3-Embedding-0.6B", + "tags": "TEXT EMBEDDING,32k", + "max_tokens": 32768, "model_type": "embedding" } ] @@ -777,6 +1200,7 @@ "logo": "", "tags": "LLM,TEXT EMBEDDING", "status": "1", + "rank": "810", "llm": [ { "llm_name": "abab6.5-chat", @@ -816,6 +1240,7 @@ "logo": "", "tags": "LLM,TEXT EMBEDDING,MODERATION", "status": "1", + "rank": "910", "llm": [ { "llm_name": "codestral-latest", @@ -909,6 +1334,7 @@ "logo": "", "tags": "LLM,TEXT EMBEDDING,SPEECH2TEXT,MODERATION", "status": "1", + "rank": "850", "llm": [ { "llm_name": "gpt-4o-mini", @@ -993,6 +1419,7 @@ "logo": "", "tags": "LLM,TEXT EMBEDDING", "status": "1", + "rank": "860", "llm": [] }, { @@ -1000,49 +1427,39 @@ "logo": "", "tags": "LLM,TEXT EMBEDDING,IMAGE2TEXT", "status": "1", + "rank": "980", "llm": [ { - "llm_name": "gemini-2.5-flash-preview-05-20", + "llm_name": "gemini-2.5-flash", "tags": "LLM,CHAT,1024K,IMAGE2TEXT", "max_tokens": 1048576, "model_type": "image2text", "is_tools": true }, { - "llm_name": "gemini-2.0-flash-001", - "tags": "LLM,CHAT,1024K", + "llm_name": "gemini-2.5-pro", + "tags": "LLM,CHAT,IMAGE2TEXT,1024K", "max_tokens": 1048576, "model_type": "image2text", "is_tools": true }, { - "llm_name": "gemini-2.0-flash-thinking-exp-01-21", - "tags": "LLM,CHAT,1024K", + "llm_name": "gemini-2.5-flash-lite", + "tags": "LLM,CHAT,1024K,IMAGE2TEXT", "max_tokens": 1048576, - "model_type": "chat", + "model_type": "image2text", "is_tools": true }, { - "llm_name": "gemini-1.5-flash", - "tags": "LLM,IMAGE2TEXT,1024K", - "max_tokens": 1048576, - "model_type": "image2text" - }, - { - "llm_name": "gemini-2.5-pro-preview-05-06", - "tags": "LLM,IMAGE2TEXT,1024K", + "llm_name": "gemini-2.0-flash", + "tags": "LLM,CHAT,1024K", "max_tokens": 1048576, - "model_type": "image2text" - }, - { - "llm_name": "gemini-1.5-pro", - "tags": "LLM,IMAGE2TEXT,2048K", - "max_tokens": 2097152, - "model_type": "image2text" + "model_type": "image2text", + "is_tools": true }, { - "llm_name": "gemini-1.5-flash-8b", - "tags": "LLM,IMAGE2TEXT,1024K", + "llm_name": "gemini-2.0-flash-lite", + "tags": "LLM,CHAT,1024K", "max_tokens": 1048576, "model_type": "image2text", "is_tools": true @@ -1066,6 +1483,7 @@ "logo": "", "tags": "LLM", "status": "1", + "rank": "800", "llm": [ { "llm_name": "gemma2-9b-it", @@ -1125,7 +1543,8 @@ "logo": "", "tags": "LLM,IMAGE2TEXT", "status": "1", - "llm": [] + "llm": [], + "rank": "840" }, { "name": "StepFun", @@ -1175,6 +1594,7 @@ "logo": "", "tags": "LLM,TEXT EMBEDDING, TEXT RE-RANK", "status": "1", + "rank": "790", "llm": [ { "llm_name": "01-ai/yi-large", @@ -1929,6 +2349,7 @@ "logo": "", "tags": "LLM,TEXT EMBEDDING, TEXT RE-RANK", "status": "1", + "rank": "900", "llm": [ { "llm_name": "command-r-plus", @@ -2037,782 +2458,499 @@ ] }, { - "name": "LeptonAI", + "name": "TogetherAI", "logo": "", - "tags": "LLM", + "tags": "LLM,TEXT EMBEDDING,IMAGE2TEXT", + "status": "1", + "llm": [] + }, + { + "name": "Upstage", + "logo": "", + "tags": "LLM,TEXT EMBEDDING", "status": "1", "llm": [ { - "llm_name": "dolphin-mixtral-8x7b", + "llm_name": "solar-1-mini-chat", "tags": "LLM,CHAT,32k", "max_tokens": 32768, - "model_type": "chat", - "is_tools": true + "model_type": "chat" }, { - "llm_name": "gemma-7b", - "tags": "LLM,CHAT,8k", - "max_tokens": 8192, + "llm_name": "solar-1-mini-chat-ja", + "tags": "LLM,CHAT,32k", + "max_tokens": 32768, "model_type": "chat" }, { - "llm_name": "llama3-1-8b", - "tags": "LLM,CHAT,4k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true + "llm_name": "solar-embedding-1-large-query", + "tags": "TEXT EMBEDDING", + "max_tokens": 4000, + "model_type": "embedding" }, { - "llm_name": "llama3-8b", - "tags": "LLM,CHAT,8K", - "max_tokens": 8192, + "llm_name": "solar-embedding-1-large-passage", + "tags": "TEXT EMBEDDING", + "max_tokens": 4000, + "model_type": "embedding" + } + ] + }, + { + "name": "NovitaAI", + "logo": "", + "tags": "LLM,TEXT EMBEDDING", + "status": "1", + "llm": [ + { + "llm_name": "qwen/qwen2.5-7b-instruct", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, "model_type": "chat" }, { - "llm_name": "llama2-13b", - "tags": "LLM,CHAT,4K", - "max_tokens": 4096, + "llm_name": "meta-llama/llama-3.2-1b-instruct", + "tags": "LLM,CHAT,131k", + "max_tokens": 131000, "model_type": "chat" }, { - "llm_name": "llama3-1-70b", - "tags": "LLM,CHAT,8k", - "max_tokens": 8192, - "model_type": "chat", - "is_tools": true + "llm_name": "meta-llama/llama-3.2-3b-instruct", + "tags": "LLM,CHAT,32k", + "max_tokens": 32768, + "model_type": "chat" }, { - "llm_name": "llama3-70b", - "tags": "LLM,CHAT,8k", - "max_tokens": 8192, + "llm_name": "thudm/glm-4-9b-0414", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, + "model_type": "chat" + }, + { + "llm_name": "thudm/glm-z1-9b-0414", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, "model_type": "chat" }, { - "llm_name": "llama3-1-405b", + "llm_name": "meta-llama/llama-3.1-8b-instruct-bf16", "tags": "LLM,CHAT,8k", "max_tokens": 8192, "model_type": "chat", "is_tools": true }, { - "llm_name": "mistral-7b", - "tags": "LLM,CHAT,8K", - "max_tokens": 8192, - "model_type": "chat" + "llm_name": "meta-llama/llama-3.1-8b-instruct", + "tags": "LLM,CHAT,16k", + "max_tokens": 16384, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "mistral-8x7b", - "tags": "LLM,CHAT,8K", - "max_tokens": 8192, + "llm_name": "deepseek/deepseek-v3-0324", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, "model_type": "chat" }, { - "llm_name": "nous-hermes-llama2", - "tags": "LLM,CHAT,4k", - "max_tokens": 4096, + "llm_name": "deepseek/deepseek-r1-turbo", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, "model_type": "chat" }, { - "llm_name": "openchat-3-5", - "tags": "LLM,CHAT,4k", - "max_tokens": 4096, + "llm_name": "Sao10K/L3-8B-Stheno-v3.2", + "tags": "LLM,CHAT,8k", + "max_tokens": 8192, "model_type": "chat" }, { - "llm_name": "toppy-m-7b", - "tags": "LLM,CHAT,4k", - "max_tokens": 4096, + "llm_name": "meta-llama/llama-3.3-70b-instruct", + "tags": "LLM,CHAT,128k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek/deepseek-r1-distill-llama-8b", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, "model_type": "chat" }, { - "llm_name": "wizardlm-2-7b", + "llm_name": "mistralai/mistral-nemo", + "tags": "LLM,CHAT,128k", + "max_tokens": 131072, + "model_type": "chat" + }, + { + "llm_name": "meta-llama/llama-3-8b-instruct", + "tags": "LLM,CHAT,8k", + "max_tokens": 8192, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek/deepseek-v3-turbo", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "mistralai/mistral-7b-instruct", "tags": "LLM,CHAT,32k", "max_tokens": 32768, "model_type": "chat" }, { - "llm_name": "wizardlm-2-8x22b", - "tags": "LLM,CHAT,64K", - "max_tokens": 65536, + "llm_name": "deepseek/deepseek-r1", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat" + }, + { + "llm_name": "deepseek/deepseek-r1-distill-qwen-14b", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, "model_type": "chat" + }, + { + "llm_name": "baai/bge-m3", + "tags": "TEXT EMBEDDING,8K", + "max_tokens": 8192, + "model_type": "embedding" } ] }, { - "name": "TogetherAI", - "logo": "", - "tags": "LLM,TEXT EMBEDDING,IMAGE2TEXT", - "status": "1", - "llm": [] - }, - { - "name": "PerfXCloud", + "name": "SILICONFLOW", "logo": "", - "tags": "LLM,TEXT EMBEDDING", + "tags": "LLM,TEXT EMBEDDING,TEXT RE-RANK,IMAGE2TEXT", "status": "1", + "rank": "780", "llm": [ { - "llm_name": "deepseek-v2-chat", - "tags": "LLM,CHAT,4k", - "max_tokens": 4096, + "llm_name": "THUDM/GLM-4.1V-9B-Thinking", + "tags": "LLM,CHAT,IMAGE2TEXT, 64k", + "max_tokens": 64000, "model_type": "chat", - "is_tools": true + "is_tools": false + }, + { + "llm_name": "Qwen/Qwen3-Embedding-8B", + "tags": "TEXT EMBEDDING,TEXT RE-RANK,32k", + "max_tokens": 32000, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "Qwen/Qwen3-Embedding-4B", + "tags": "TEXT EMBEDDING,TEXT RE-RANK,32k", + "max_tokens": 32000, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "Qwen/Qwen3-Embedding-0.6B", + "tags": "TEXT EMBEDDING,TEXT RE-RANK,32k", + "max_tokens": 32000, + "model_type": "embedding", + "is_tools": false }, { - "llm_name": "llama3.1:405b", + "llm_name": "Qwen/Qwen3-235B-A22B", "tags": "LLM,CHAT,128k", - "max_tokens": 131072, + "max_tokens": 128000, "model_type": "chat", "is_tools": true }, { - "llm_name": "Qwen2-72B-Instruct", + "llm_name": "Qwen/Qwen3-30B-A3B", "tags": "LLM,CHAT,128k", - "max_tokens": 131072, + "max_tokens": 128000, "model_type": "chat", "is_tools": true }, { - "llm_name": "Qwen2-72B-Instruct-GPTQ-Int4", - "tags": "LLM,CHAT,2k", - "max_tokens": 2048, + "llm_name": "Qwen/Qwen3-32B", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, "model_type": "chat", "is_tools": true }, { - "llm_name": "Qwen2-72B-Instruct-awq-int4", - "tags": "LLM,CHAT,32k", - "max_tokens": 32768, + "llm_name": "Qwen/Qwen3-14B", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, "model_type": "chat", "is_tools": true }, { - "llm_name": "Llama3-Chinese_v2", - "tags": "LLM,CHAT,8k", - "max_tokens": 8192, - "model_type": "chat" - }, - { - "llm_name": "Yi-1_5-9B-Chat-16K", - "tags": "LLM,CHAT,16k", - "max_tokens": 16384, - "model_type": "chat" + "llm_name": "Qwen/Qwen3-8B", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "Qwen1.5-72B-Chat-GPTQ-Int4", - "tags": "LLM,CHAT,2k", - "max_tokens": 2048, - "model_type": "chat" + "llm_name": "Qwen/QVQ-72B-Preview", + "tags": "LLM,CHAT,IMAGE2TEXT,32k", + "max_tokens": 32000, + "model_type": "image2text", + "is_tools": false }, { - "llm_name": "Meta-Llama-3.1-8B-Instruct", - "tags": "LLM,CHAT,4k", - "max_tokens": 4096, + "llm_name": "Pro/deepseek-ai/DeepSeek-R1", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, "model_type": "chat", "is_tools": true }, { - "llm_name": "Qwen2-7B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 32768, + "llm_name": "deepseek-ai/DeepSeek-R1", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, "model_type": "chat", "is_tools": true }, { - "llm_name": "deepseek-v2-lite-chat", - "tags": "LLM,CHAT,2k", - "max_tokens": 2048, + "llm_name": "Pro/deepseek-ai/DeepSeek-V3", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, "model_type": "chat", "is_tools": true }, { - "llm_name": "Qwen2-7B", - "tags": "LLM,CHAT,128k", - "max_tokens": 131072, - "model_type": "chat" - }, - { - "llm_name": "chatglm3-6b", - "tags": "LLM,CHAT,8k", - "max_tokens": 8192, - "model_type": "chat" + "llm_name": "deepseek-ai/DeepSeek-V3", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "Meta-Llama-3-70B-Instruct-GPTQ-Int4", - "tags": "LLM,CHAT,1k", - "max_tokens": 1024, - "model_type": "chat" + "llm_name": "Pro/deepseek-ai/DeepSeek-V3.1", + "tags": "LLM,CHAT,160k", + "max_tokens": 160000, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "Meta-Llama-3-8B-Instruct", - "tags": "LLM,CHAT,8k", - "max_tokens": 8192, - "model_type": "chat" + "llm_name": "deepseek-ai/DeepSeek-V3.1", + "tags": "LLM,CHAT,160", + "max_tokens": 160000, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "Mistral-7B-Instruct", + "llm_name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B", "tags": "LLM,CHAT,32k", - "max_tokens": 32768, + "max_tokens": 32000, "model_type": "chat", "is_tools": true }, { - "llm_name": "MindChat-Qwen-7B-v2", - "tags": "LLM,CHAT,2k", - "max_tokens": 2048, - "model_type": "chat" + "llm_name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-14B", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "phi-2", - "tags": "LLM,CHAT,2k", - "max_tokens": 2048, - "model_type": "chat" + "llm_name": "Pro/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "SOLAR-10_7B-Instruct", - "tags": "LLM,CHAT,4k", - "max_tokens": 4096, - "model_type": "chat" + "llm_name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "Mixtral-8x7B-Instruct-v0.1-GPTQ", + "llm_name": "deepseek-ai/DeepSeek-V2.5", "tags": "LLM,CHAT,32k", - "max_tokens": 32768, - "model_type": "chat" + "max_tokens": 32000, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "Qwen1.5-7B", + "llm_name": "Qwen/QwQ-32B", "tags": "LLM,CHAT,32k", - "max_tokens": 32768, - "model_type": "chat" + "max_tokens": 32000, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "BAAI/bge-large-en-v1.5", - "tags": "TEXT EMBEDDING", - "max_tokens": 512, - "model_type": "embedding" + "llm_name": "Qwen/Qwen2.5-VL-72B-Instruct", + "tags": "LLM,CHAT,IMAGE2TEXT,128k", + "max_tokens": 128000, + "model_type": "image2text", + "is_tools": true }, { - "llm_name": "BAAI/bge-large-zh-v1.5", - "tags": "TEXT EMBEDDING", - "max_tokens": 1024, - "model_type": "embedding" + "llm_name": "Pro/Qwen/Qwen2.5-VL-7B-Instruct", + "tags": "LLM,CHAT,IMAGE2TEXT,32k", + "max_tokens": 32000, + "model_type": "image2text", + "is_tools": false }, { - "llm_name": "BAAI/bge-m3", - "tags": "TEXT EMBEDDING", - "max_tokens": 8192, - "model_type": "embedding" - } - ] - }, - { - "name": "Upstage", - "logo": "", - "tags": "LLM,TEXT EMBEDDING", - "status": "1", - "llm": [ - { - "llm_name": "solar-1-mini-chat", + "llm_name": "THUDM/GLM-Z1-32B-0414", "tags": "LLM,CHAT,32k", - "max_tokens": 32768, - "model_type": "chat" + "max_tokens": 32000, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "solar-1-mini-chat-ja", + "llm_name": "THUDM/GLM-4-32B-0414", "tags": "LLM,CHAT,32k", - "max_tokens": 32768, - "model_type": "chat" + "max_tokens": 32000, + "model_type": "chat", + "is_tools": true }, { - "llm_name": "solar-embedding-1-large-query", - "tags": "TEXT EMBEDDING", - "max_tokens": 4000, - "model_type": "embedding" - }, - { - "llm_name": "solar-embedding-1-large-passage", - "tags": "TEXT EMBEDDING", - "max_tokens": 4000, - "model_type": "embedding" - } - ] - }, - { - "name": "NovitaAI", - "logo": "", - "tags": "LLM,TEXT EMBEDDING", - "status": "1", - "llm": [ - { - "llm_name": "qwen/qwen2.5-7b-instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 32000, - "model_type": "chat" - }, - { - "llm_name": "meta-llama/llama-3.2-1b-instruct", - "tags": "LLM,CHAT,131k", - "max_tokens": 131000, - "model_type": "chat" - }, - { - "llm_name": "meta-llama/llama-3.2-3b-instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 32768, - "model_type": "chat" - }, - { - "llm_name": "thudm/glm-4-9b-0414", - "tags": "LLM,CHAT,32k", - "max_tokens": 32000, - "model_type": "chat" - }, - { - "llm_name": "thudm/glm-z1-9b-0414", + "llm_name": "THUDM/GLM-Z1-9B-0414", "tags": "LLM,CHAT,32k", "max_tokens": 32000, - "model_type": "chat" - }, - { - "llm_name": "meta-llama/llama-3.1-8b-instruct-bf16", - "tags": "LLM,CHAT,8k", - "max_tokens": 8192, "model_type": "chat", "is_tools": true }, { - "llm_name": "meta-llama/llama-3.1-8b-instruct", - "tags": "LLM,CHAT,16k", - "max_tokens": 16384, + "llm_name": "THUDM/GLM-4-9B-0414", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, "model_type": "chat", "is_tools": true }, { - "llm_name": "deepseek/deepseek-v3-0324", + "llm_name": "Pro/THUDM/glm-4-9b-chat", "tags": "LLM,CHAT,128k", "max_tokens": 128000, - "model_type": "chat" - }, - { - "llm_name": "deepseek/deepseek-r1-turbo", - "tags": "LLM,CHAT,64k", - "max_tokens": 64000, - "model_type": "chat" - }, - { - "llm_name": "Sao10K/L3-8B-Stheno-v3.2", - "tags": "LLM,CHAT,8k", - "max_tokens": 8192, - "model_type": "chat" - }, - { - "llm_name": "meta-llama/llama-3.3-70b-instruct", - "tags": "LLM,CHAT,128k", - "max_tokens": 131072, "model_type": "chat", - "is_tools": true + "is_tools": false }, { - "llm_name": "deepseek/deepseek-r1-distill-llama-8b", + "llm_name": "THUDM/GLM-Z1-Rumination-32B-0414", "tags": "LLM,CHAT,32k", "max_tokens": 32000, - "model_type": "chat" - }, - { - "llm_name": "mistralai/mistral-nemo", - "tags": "LLM,CHAT,128k", - "max_tokens": 131072, - "model_type": "chat" - }, - { - "llm_name": "meta-llama/llama-3-8b-instruct", - "tags": "LLM,CHAT,8k", - "max_tokens": 8192, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "deepseek/deepseek-v3-turbo", - "tags": "LLM,CHAT,64k", - "max_tokens": 64000, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "mistralai/mistral-7b-instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 32768, - "model_type": "chat" - }, - { - "llm_name": "deepseek/deepseek-r1", - "tags": "LLM,CHAT,64k", - "max_tokens": 64000, - "model_type": "chat" - }, - { - "llm_name": "deepseek/deepseek-r1-distill-qwen-14b", - "tags": "LLM,CHAT,64k", - "max_tokens": 64000, - "model_type": "chat" - }, - { - "llm_name": "baai/bge-m3", - "tags": "TEXT EMBEDDING,8K", - "max_tokens": 8192, - "model_type": "embedding" - } - ] - }, - { - "name": "SILICONFLOW", - "logo": "", - "tags": "LLM,TEXT EMBEDDING,TEXT RE-RANK,IMAGE2TEXT", - "status": "1", - "llm": [ - { - "llm_name": "Qwen/Qwen3-235B-A22B", - "tags": "LLM,CHAT,128k", - "max_tokens": 8192, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Qwen/Qwen3-30B-A3B", - "tags": "LLM,CHAT,128k", - "max_tokens": 8192, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Qwen/Qwen3-32B", - "tags": "LLM,CHAT,128k", - "max_tokens": 8192, "model_type": "chat", - "is_tools": true + "is_tools": false }, { - "llm_name": "Qwen/Qwen3-14B", + "llm_name": "THUDM/glm-4-9b-chat", "tags": "LLM,CHAT,128k", - "max_tokens": 8192, + "max_tokens": 128000, "model_type": "chat", "is_tools": true }, { - "llm_name": "Qwen/Qwen3-8B", - "tags": "LLM,CHAT,64k", - "max_tokens": 8192, + "llm_name": "Qwen/Qwen2.5-Coder-32B-Instruct", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, "model_type": "chat", - "is_tools": true + "is_tools": false }, { - "llm_name": "Qwen/QVQ-72B-Preview", - "tags": "LLM,CHAT,IMAGE2TEXT,32k", - "max_tokens": 16384, + "llm_name": "Qwen/Qwen2-VL-72B-Instruct", + "tags": "LLM,IMAGE2TEXT,32k", + "max_tokens": 32000, "model_type": "image2text", "is_tools": false }, { - "llm_name": "Pro/deepseek-ai/DeepSeek-R1", - "tags": "LLM,CHAT,64k", - "max_tokens": 16384, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "deepseek-ai/DeepSeek-R1", - "tags": "LLM,CHAT,64k", - "max_tokens": 16384, - "model_type": "chat", - "is_tools": true + "llm_name": "Qwen/Qwen2.5-72B-Instruct-128Kt", + "tags": "LLM,IMAGE2TEXT,128k", + "max_tokens": 128000, + "model_type": "image2text", + "is_tools": false }, { - "llm_name": "Pro/deepseek-ai/DeepSeek-V3", - "tags": "LLM,CHAT,64k", - "max_tokens": 8192, - "model_type": "chat", - "is_tools": true + "llm_name": "deepseek-ai/deepseek-vl2", + "tags": "LLM,IMAGE2TEXT,4k", + "max_tokens": 4096, + "model_type": "image2text", + "is_tools": false }, { - "llm_name": "deepseek-ai/DeepSeek-V3", - "tags": "LLM,CHAT,64k", - "max_tokens": 8192, + "llm_name": "Qwen/Qwen2.5-72B-Instruct", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, "model_type": "chat", "is_tools": true }, { - "llm_name": "Pro/deepseek-ai/DeepSeek-V3-1226", - "tags": "LLM,CHAT,64k", - "max_tokens": 4096, + "llm_name": "Qwen/Qwen2.5-32B-Instruct", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, "model_type": "chat", "is_tools": true }, { - "llm_name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B", + "llm_name": "Qwen/Qwen2.5-14B-Instruct", "tags": "LLM,CHAT,32k", - "max_tokens": 16384, + "max_tokens": 32000, "model_type": "chat", "is_tools": true }, { - "llm_name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-14B", + "llm_name": "Qwen/Qwen2.5-7B-Instruct", "tags": "LLM,CHAT,32k", - "max_tokens": 16384, + "max_tokens": 32000, "model_type": "chat", "is_tools": true }, { - "llm_name": "Pro/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B", + "llm_name": "Qwen/Qwen2.5-Coder-7B-Instruct", "tags": "LLM,CHAT,32k", - "max_tokens": 16384, + "max_tokens": 32000, "model_type": "chat", "is_tools": true }, { - "llm_name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B", + "llm_name": "internlm/internlm2_5-7b-chat", "tags": "LLM,CHAT,32k", - "max_tokens": 16384, + "max_tokens": 32000, "model_type": "chat", "is_tools": true }, { - "llm_name": "Pro/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B", + "llm_name": "Qwen/Qwen2-7B-Instruct", "tags": "LLM,CHAT,32k", - "max_tokens": 16384, + "max_tokens": 32000, "model_type": "chat", "is_tools": true }, { - "llm_name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B", + "llm_name": "Pro/Qwen/Qwen2.5-Coder-7B-Instruct", "tags": "LLM,CHAT,32k", - "max_tokens": 16384, + "max_tokens": 32000, "model_type": "chat", - "is_tools": true + "is_tools": false }, { - "llm_name": "deepseek-ai/DeepSeek-V2.5", + "llm_name": "Pro/Qwen/Qwen2.5-7B-Instruct", "tags": "LLM,CHAT,32k", - "max_tokens": 4096, + "max_tokens": 32000, "model_type": "chat", "is_tools": true }, { - "llm_name": "Qwen/QwQ-32B", + "llm_name": "Pro/Qwen/Qwen2-7B-Instruct", "tags": "LLM,CHAT,32k", - "max_tokens": 32768, + "max_tokens": 32000, "model_type": "chat", - "is_tools": true + "is_tools": false }, { - "llm_name": "Qwen/Qwen2.5-VL-72B-Instruct", - "tags": "LLM,CHAT,IMAGE2TEXT,128k", - "max_tokens": 4096, - "model_type": "image2text", - "is_tools": true - }, - { - "llm_name": "Pro/Qwen/Qwen2.5-VL-7B-Instruct", - "tags": "LLM,CHAT,IMAGE2TEXT,32k", - "max_tokens": 4096, - "model_type": "image2text", - "is_tools": true - }, - { - "llm_name": "THUDM/GLM-Z1-32B-0414", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "THUDM/GLM-4-32B-0414", - "tags": "LLM,CHAT,32k", - "max_tokens": 8192, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "THUDM/GLM-Z1-9B-0414", - "tags": "LLM,CHAT,32k", - "max_tokens": 8192, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "THUDM/GLM-4-9B-0414", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "THUDM/chatglm3-6b", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": false - }, - { - "llm_name": "Pro/THUDM/glm-4-9b-chat", - "tags": "LLM,CHAT,128k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": false - }, - { - "llm_name": "THUDM/GLM-Z1-Rumination-32B-0414", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": false - }, - { - "llm_name": "THUDM/glm-4-9b-chat", - "tags": "LLM,CHAT,128k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Qwen/QwQ-32B-Preview", - "tags": "LLM,CHAT,32k", - "max_tokens": 8192, - "model_type": "chat", - "is_tools": false - }, - { - "llm_name": "Qwen/Qwen2.5-Coder-32B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": false - }, - { - "llm_name": "Qwen/Qwen2-VL-72B-Instruct", - "tags": "LLM,IMAGE2TEXT,32k", - "max_tokens": 4096, - "model_type": "image2text", - "is_tools": false - }, - { - "llm_name": "Qwen/Qwen2.5-72B-Instruct-128Kt", - "tags": "LLM,IMAGE2TEXT,128k", - "max_tokens": 4096, - "model_type": "image2text", - "is_tools": false - }, - { - "llm_name": "deepseek-ai/deepseek-vl2", - "tags": "LLM,IMAGE2TEXT,4k", - "max_tokens": 4096, - "model_type": "image2text", - "is_tools": false - }, - { - "llm_name": "Qwen/Qwen2.5-72B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Qwen/Qwen2.5-32B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Qwen/Qwen2.5-14B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Qwen/Qwen2.5-7B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Qwen/Qwen2.5-Coder-7B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "internlm/internlm2_5-20b-chat", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "internlm/internlm2_5-7b-chat", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Qwen/Qwen2-7B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Qwen/Qwen2-1.5B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Pro/Qwen/Qwen2.5-Coder-7B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": false - }, - { - "llm_name": "Pro/Qwen/Qwen2-VL-7B-Instruct", - "tags": "LLM,CHAT,IMAGE2TEXT,32k", - "max_tokens": 4096, - "model_type": "image2text", - "is_tools": false - }, - { - "llm_name": "Pro/Qwen/Qwen2.5-7B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "Pro/Qwen/Qwen2-7B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": false - }, - { - "llm_name": "Pro/Qwen/Qwen2-1.5B-Instruct", - "tags": "LLM,CHAT,32k", - "max_tokens": 4096, - "model_type": "chat", - "is_tools": false - }, - { - "llm_name": "BAAI/bge-m3", - "tags": "LLM,EMBEDDING,8k", - "max_tokens": 8192, - "model_type": "embedding", - "is_tools": false + "llm_name": "BAAI/bge-m3", + "tags": "LLM,EMBEDDING,8k", + "max_tokens": 8192, + "model_type": "embedding", + "is_tools": false }, { "llm_name": "BAAI/bge-reranker-v2-m3", @@ -2990,75 +3128,6 @@ } ] }, - { - "name": "01.AI", - "logo": "", - "tags": "LLM,IMAGE2TEXT", - "status": "1", - "llm": [ - { - "llm_name": "yi-lightning", - "tags": "LLM,CHAT,16k", - "max_tokens": 16384, - "model_type": "chat" - }, - { - "llm_name": "yi-large", - "tags": "LLM,CHAT,32k", - "max_tokens": 32768, - "model_type": "chat" - }, - { - "llm_name": "yi-medium", - "tags": "LLM,CHAT,16k", - "max_tokens": 16384, - "model_type": "chat" - }, - { - "llm_name": "yi-medium-200k", - "tags": "LLM,CHAT,200k", - "max_tokens": 204800, - "model_type": "chat" - }, - { - "llm_name": "yi-spark", - "tags": "LLM,CHAT,16k", - "max_tokens": 16384, - "model_type": "chat" - }, - { - "llm_name": "yi-large-rag", - "tags": "LLM,CHAT,16k", - "max_tokens": 16384, - "model_type": "chat" - }, - { - "llm_name": "yi-large-fc", - "tags": "LLM,CHAT,32k", - "max_tokens": 32768, - "model_type": "chat", - "is_tools": true - }, - { - "llm_name": "yi-large-turbo", - "tags": "LLM,CHAT,16k", - "max_tokens": 16384, - "model_type": "chat" - }, - { - "llm_name": "yi-large-preview", - "tags": "LLM,CHAT,16k", - "max_tokens": 16384, - "model_type": "chat" - }, - { - "llm_name": "yi-vision", - "tags": "LLM,CHAT,IMAGE2TEXT,16k", - "max_tokens": 16384, - "model_type": "image2text" - } - ] - }, { "name": "Replicate", "logo": "", @@ -3110,6 +3179,7 @@ "logo": "", "tags": "LLM,TTS", "status": "1", + "rank": "820", "llm": [] }, { @@ -3117,6 +3187,7 @@ "logo": "", "tags": "LLM", "status": "1", + "rank": "880", "llm": [] }, { @@ -3138,60 +3209,63 @@ "logo": "", "tags": "LLM", "status": "1", + "rank": "990", "llm": [ { - "llm_name": "claude-opus-4-20250514", - "tags": "LLM,IMAGE2TEXT,200k", + "llm_name": "claude-opus-4-1-20250805", + "tags": "LLM,CHAT,IMAGE2TEXT,200k", "max_tokens": 204800, - "model_type": "image2text", + "model_type": "chat", "is_tools": true }, { - "llm_name": "claude-sonnet-4-20250514", - "tags": "LLM,IMAGE2TEXT,200k", + "llm_name": "claude-opus-4-20250514", + "tags": "LLM,CHAT,IMAGE2TEXT,200k", "max_tokens": 204800, - "model_type": "image2text", + "model_type": "chat", "is_tools": true }, { - "llm_name": "claude-3-7-sonnet-20250219", - "tags": "LLM,IMAGE2TEXT,200k", + "llm_name": "claude-sonnet-4-5-20250929", + "tags": "LLM,CHAT,IMAGE2TEXT,200k", "max_tokens": 204800, - "model_type": "image2text", + "model_type": "chat", "is_tools": true }, { - "llm_name": "claude-3-5-sonnet-20241022", - "tags": "LLM,IMAGE2TEXT,200k", + "llm_name": "claude-sonnet-4-20250514", + "tags": "LLM,CHAT,IMAGE2TEXT,200k", "max_tokens": 204800, "model_type": "chat", "is_tools": true }, { - "llm_name": "claude-3-opus-20240229", - "tags": "LLM,IMAGE2TEXT,200k", + "llm_name": "claude-3-7-sonnet-20250219", + "tags": "LLM,CHAT,IMAGE2TEXT,200k", "max_tokens": 204800, "model_type": "chat", "is_tools": true }, { - "llm_name": "claude-3-haiku-20240307", - "tags": "LLM,IMAGE2TEXT,200k", + "llm_name": "claude-3-5-sonnet-20241022", + "tags": "LLM,CHAT,IMAGE2TEXT,200k", "max_tokens": 204800, - "model_type": "image2text", + "model_type": "chat", "is_tools": true }, { - "llm_name": "claude-2.1", - "tags": "LLM,CHAT,200k", + "llm_name": "claude-3-5-haiku-20241022", + "tags": "LLM,CHAT,IMAGE2TEXT,200k", "max_tokens": 204800, - "model_type": "chat" + "model_type": "chat", + "is_tools": true }, { - "llm_name": "claude-2.0", - "tags": "LLM,CHAT,100k", - "max_tokens": 102400, - "model_type": "chat" + "llm_name": "claude-3-haiku-20240307", + "tags": "LLM,CHAT,IMAGE2TEXT,200k", + "max_tokens": 204800, + "model_type": "chat", + "is_tools": true } ] }, @@ -3201,6 +3275,30 @@ "tags": "TEXT EMBEDDING, TEXT RE-RANK", "status": "1", "llm": [ + { + "llm_name": "voyage-3-large", + "tags": "TEXT EMBEDDING,32000", + "max_tokens": 32000, + "model_type": "embedding" + }, + { + "llm_name": "voyage-3.5", + "tags": "TEXT EMBEDDING,32000", + "max_tokens": 32000, + "model_type": "embedding" + }, + { + "llm_name": "voyage-3.5-lite", + "tags": "TEXT EMBEDDING,32000", + "max_tokens": 32000, + "model_type": "embedding" + }, + { + "llm_name": "voyage-code-3", + "tags": "TEXT EMBEDDING,32000", + "max_tokens": 32000, + "model_type": "embedding" + }, { "llm_name": "voyage-multimodal-3", "tags": "TEXT EMBEDDING,Chat,IMAGE2TEXT,32000", @@ -3288,25 +3386,1459 @@ ] }, { - "name": "Google Cloud", - "logo": "", - "tags": "LLM", - "status": "1", - "llm": [] - }, - { - "name": "HuggingFace", - "logo": "", - "tags": "TEXT EMBEDDING,TEXT RE-RANK", - "status": "1", - "llm": [] - }, - { - "name": "GPUStack", + "name": "GiteeAI", "logo": "", - "tags": "LLM,TEXT EMBEDDING,TTS,SPEECH2TEXT,TEXT RE-RANK", + "tags": "LLM,TEXT EMBEDDING,IMAGE2TEXT,SPEECH2TEXT,TEXT RE-RANK", "status": "1", - "llm": [] + "llm": [ + { + "llm_name": "ERNIE-4.5-Turbo", + "tags": "LLM,CHAT", + "max_tokens": 32768, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "ERNIE-X1-Turbo", + "tags": "LLM,CHAT", + "max_tokens": 4096, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "DeepSeek-R1", + "tags": "LLM,CHAT", + "max_tokens": 65792, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "DeepSeek-V3", + "tags": "LLM,CHAT", + "max_tokens": 65792, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "Qwen3-235B-A22B", + "tags": "LLM,CHAT", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "Qwen3-30B-A3B", + "tags": "LLM,CHAT", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "Qwen3-32B", + "tags": "LLM,CHAT", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "Qwen3-8B", + "tags": "LLM,CHAT", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "Qwen3-4B", + "tags": "LLM,CHAT", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "Qwen3-0.6B", + "tags": "LLM,CHAT", + "max_tokens": 32000, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "QwQ-32B", + "tags": "LLM,CHAT", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "DeepSeek-R1-Distill-Qwen-32B", + "tags": "LLM,CHAT", + "max_tokens": 65792, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "DeepSeek-R1-Distill-Qwen-14B", + "tags": "LLM,CHAT", + "max_tokens": 65792, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "DeepSeek-R1-Distill-Qwen-7B", + "tags": "LLM,CHAT", + "max_tokens": 65792, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "DeepSeek-R1-Distill-Qwen-1.5B", + "tags": "LLM,CHAT", + "max_tokens": 65792, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "Qwen2.5-72B-Instruct", + "tags": "LLM,CHAT", + "max_tokens": 4096, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "Qwen2.5-32B-Instruct", + "tags": "LLM,CHAT", + "max_tokens": 4096, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "Qwen2.5-14B-Instruct", + "tags": "LLM,CHAT", + "max_tokens": 4096, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "Qwen2.5-7B-Instruct", + "tags": "LLM,CHAT", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "Qwen2-72B-Instruct", + "tags": "LLM,CHAT", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "Qwen2-7B-Instruct", + "tags": "LLM,CHAT", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "GLM-4-32B", + "tags": "LLM,CHAT", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "GLM-4-9B-0414", + "tags": "LLM,CHAT", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "glm-4-9b-chat", + "tags": "LLM,CHAT", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "internlm3-8b-instruct", + "tags": "LLM,CHAT", + "max_tokens": 4096, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "Yi-34B-Chat", + "tags": "LLM,CHAT", + "max_tokens": 32768, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "ERNIE-4.5-Turbo-VL", + "tags": "LLM,IMAGE2TEXT", + "max_tokens": 4096, + "model_type": "image2text", + "is_tools": false + }, + { + "llm_name": "Qwen2.5-VL-32B-Instruct", + "tags": "LLM,IMAGE2TEXT", + "max_tokens": 32768, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "Qwen2-VL-72B", + "tags": "LLM,IMAGE2TEXT", + "max_tokens": 4096, + "model_type": "image2text", + "is_tools": false + }, + { + "llm_name": "Align-DS-V", + "tags": "LLM,IMAGE2TEXT", + "max_tokens": 4096, + "model_type": "image2text", + "is_tools": false + }, + { + "llm_name": "InternVL3-78B", + "tags": "LLM,IMAGE2TEXT", + "max_tokens": 32768, + "model_type": "image2text", + "is_tools": false + }, + { + "llm_name": "InternVL3-38B", + "tags": "LLM,IMAGE2TEXT", + "max_tokens": 32768, + "model_type": "image2text", + "is_tools": false + }, + { + "llm_name": "InternVL2.5-78B", + "tags": "LLM,IMAGE2TEXT", + "max_tokens": 32768, + "model_type": "image2text", + "is_tools": false + }, + { + "llm_name": "InternVL2.5-26B", + "tags": "LLM,IMAGE2TEXT", + "max_tokens": 16384, + "model_type": "image2text", + "is_tools": false + }, + { + "llm_name": "InternVL2-8B", + "tags": "LLM,IMAGE2TEXT", + "max_tokens": 8192, + "model_type": "image2text", + "is_tools": false + }, + { + "llm_name": "Qwen2-Audio-7B-Instruct", + "tags": "LLM,SPEECH2TEXT,IMAGE2TEXT", + "max_tokens": 8192, + "model_type": "speech2text", + "is_tools": false + }, + { + "llm_name": "whisper-base", + "tags": "SPEECH2TEXT", + "max_tokens": 512, + "model_type": "speech2text", + "is_tools": false + }, + { + "llm_name": "whisper-large", + "tags": "SPEECH2TEXT", + "max_tokens": 512, + "model_type": "speech2text", + "is_tools": false + }, + { + "llm_name": "whisper-large-v3-turbo", + "tags": "SPEECH2TEXT", + "max_tokens": 512, + "model_type": "speech2text", + "is_tools": false + }, + { + "llm_name": "whisper-large-v3", + "tags": "SPEECH2TEXT", + "max_tokens": 512, + "model_type": "speech2text", + "is_tools": false + }, + { + "llm_name": "SenseVoiceSmall", + "tags": "SPEECH2TEXT", + "max_tokens": 512, + "model_type": "speech2text", + "is_tools": false + }, + { + "llm_name": "Qwen3-Reranker-8B", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 32768, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "Qwen3-Reranker-4B", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 32768, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "Qwen3-Reranker-0.6B", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 32768, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "Qwen3-Embedding-8B", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 8192, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "Qwen3-Embedding-4B", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 4096, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "Qwen3-Embedding-0.6B", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 4096, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "jina-clip-v1", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 512, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "jina-clip-v2", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 8192, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "jina-reranker-m0", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 10240, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "bce-embedding-base_v1", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 512, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "bce-reranker-base_v1", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 512, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "bge-m3", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 8192, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "bge-reranker-v2-m3", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 8192, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "bge-large-zh-v1.5", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 1024, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "bge-small-zh-v1.5", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 512, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "nomic-embed-code", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 512, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "all-mpnet-base-v2", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 512, + "model_type": "embedding", + "is_tools": false + } + ] + }, + { + "name": "Google Cloud", + "logo": "", + "tags": "LLM", + "status": "1", + "llm": [] + }, + { + "name": "HuggingFace", + "logo": "", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "status": "1", + "rank": "920", + "llm": [] + }, + { + "name": "GPUStack", + "logo": "", + "tags": "LLM,TEXT EMBEDDING,TTS,SPEECH2TEXT,TEXT RE-RANK", + "status": "1", + "llm": [] + }, + { + "name": "DeepInfra", + "logo": "", + "tags": "LLM,TEXT EMBEDDING,TTS,SPEECH2TEXT,MODERATION", + "status": "1", + "llm": [ + { + "llm_name": "moonshotai/Kimi-K2-Instruct", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "mistralai/Voxtral-Small-24B-2507", + "tags": "SPEECH2TEXT", + "model_type": "speech2text" + }, + { + "llm_name": "mistralai/Voxtral-Mini-3B-2507", + "tags": "SPEECH2TEXT", + "model_type": "speech2text" + }, + { + "llm_name": "deepseek-ai/DeepSeek-R1-0528-Turbo", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "Qwen/Qwen3-235B-A22B", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "Qwen/Qwen3-30B-A3B", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "Qwen/Qwen3-32B", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "Qwen/Qwen3-14B", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "deepseek-ai/DeepSeek-V3-0324-Turbo", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "meta-llama/Llama-4-Maverick-17B-128E-Instruct-Turbo", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "meta-llama/Llama-4-Scout-17B-16E-Instruct", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "deepseek-ai/DeepSeek-R1-0528", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "deepseek-ai/DeepSeek-V3-0324", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "mistralai/Devstral-Small-2507", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "mistralai/Mistral-Small-3.2-24B-Instruct-2506", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "meta-llama/Llama-Guard-4-12B", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "Qwen/QwQ-32B", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "anthropic/claude-4-opus", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "anthropic/claude-4-sonnet", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "google/gemini-2.5-flash", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "google/gemini-2.5-pro", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "google/gemma-3-27b-it", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "google/gemma-3-12b-it", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "google/gemma-3-4b-it", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "hexgrad/Kokoro-82M", + "tags": "TTS", + "model_type": "tts" + }, + { + "llm_name": "canopylabs/orpheus-3b-0.1-ft", + "tags": "TTS", + "model_type": "tts" + }, + { + "llm_name": "sesame/csm-1b", + "tags": "TTS", + "model_type": "tts" + }, + { + "llm_name": "microsoft/Phi-4-multimodal-instruct", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "deepseek-ai/DeepSeek-R1-Distill-Llama-70B", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "deepseek-ai/DeepSeek-V3", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "meta-llama/Llama-3.3-70B-Instruct-Turbo", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "meta-llama/Llama-3.3-70B-Instruct", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "microsoft/phi-4", + "tags": "LLM,CHAT", + "model_type": "chat" + }, + { + "llm_name": "openai/whisper-large-v3-turbo", + "tags": "SPEECH2TEXT", + "model_type": "speech2text" + }, + { + "llm_name": "BAAI/bge-base-en-v1.5", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "BAAI/bge-en-icl", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "BAAI/bge-large-en-v1.5", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "BAAI/bge-m3", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "BAAI/bge-m3-multi", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "Qwen/Qwen3-Embedding-0.6B", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "Qwen/Qwen3-Embedding-4B", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "Qwen/Qwen3-Embedding-8B", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "intfloat/e5-base-v2", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "intfloat/e5-large-v2", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "intfloat/multilingual-e5-large", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "intfloat/multilingual-e5-large-instruct", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "sentence-transformers/all-MiniLM-L12-v2", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "sentence-transformers/all-MiniLM-L6-v2", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "sentence-transformers/all-mpnet-base-v2", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "sentence-transformers/clip-ViT-B-32", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "sentence-transformers/clip-ViT-B-32-multilingual-v1", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "sentence-transformers/multi-qa-mpnet-base-dot-v1", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "sentence-transformers/paraphrase-MiniLM-L6-v2", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "shibing624/text2vec-base-chinese", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "thenlper/gte-base", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + }, + { + "llm_name": "thenlper/gte-large", + "tags": "TEXT EMBEDDING", + "model_type": "embedding" + } + ] + }, + { + "name": "302.AI", + "logo": "", + "tags": "LLM,TEXT EMBEDDING,TEXT RE-RANK,IMAGE2TEXT", + "status": "1", + "llm": [ + { + "llm_name": "deepseek-chat", + "tags": "LLM,CHAT", + "max_tokens": 32000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4o", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "chatgpt-4o-latest", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "llama3.3-70b", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-reasoner", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gemini-2.0-flash", + "tags": "LLM,CHAT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-3-7-sonnet-20250219", + "tags": "LLM,CHAT", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "claude-3-7-sonnet-latest", + "tags": "LLM,CHAT", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3-beta", + "tags": "LLM,CHAT", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3-mini-beta", + "tags": "LLM,CHAT", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4.1", + "tags": "LLM,CHAT", + "max_tokens": 1000000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "o3", + "tags": "LLM,CHAT", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "o4-mini", + "tags": "LLM,CHAT", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-235b-a22b", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "qwen3-32b", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": false + }, + { + "llm_name": "gemini-2.5-pro-preview-05-06", + "tags": "LLM,CHAT", + "max_tokens": 1000000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "llama-4-maverick", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gemini-2.5-flash", + "tags": "LLM,CHAT", + "max_tokens": 1000000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "claude-sonnet-4-20250514", + "tags": "LLM,CHAT", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "claude-opus-4-20250514", + "tags": "LLM,CHAT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "gemini-2.5-pro", + "tags": "LLM,CHAT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "jina-clip-v2", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 8192, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "jina-reranker-m0", + "tags": "TEXT EMBEDDING,TEXT RE-RANK", + "max_tokens": 10240, + "model_type": "rerank", + "is_tools": false + } + ] + }, + { + "name": "CometAPI", + "logo": "", + "tags": "LLM,TEXT EMBEDDING,IMAGE2TEXT", + "status": "1", + "llm": [ + { + "llm_name": "gpt-5-chat-latest", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "chatgpt-4o-latest", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5-mini", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5-nano", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4.1-mini", + "tags": "LLM,CHAT,1M", + "max_tokens": 1047576, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4.1-nano", + "tags": "LLM,CHAT,1M", + "max_tokens": 1047576, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4.1", + "tags": "LLM,CHAT,1M", + "max_tokens": 1047576, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4o-mini", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "o4-mini-2025-04-16", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "o3-pro-2025-06-10", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "claude-opus-4-1-20250805", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-opus-4-1-20250805-thinking", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-sonnet-4-20250514", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-sonnet-4-20250514-thinking", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-3-7-sonnet-latest", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "claude-3-5-haiku-latest", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gemini-2.5-pro", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "gemini-2.5-flash", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "gemini-2.5-flash-lite", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "gemini-2.0-flash", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "grok-4-0709", + "tags": "LLM,CHAT,131k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3", + "tags": "LLM,CHAT,131k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3-mini", + "tags": "LLM,CHAT,131k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-2-image-1212", + "tags": "LLM,CHAT,32k,IMAGE2TEXT", + "max_tokens": 32768, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "deepseek-v3.1", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-v3", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-r1-0528", + "tags": "LLM,CHAT,164k", + "max_tokens": 164000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-chat", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-reasoner", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-30b-a3b", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-coder-plus-2025-07-22", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "text-embedding-ada-002", + "tags": "TEXT EMBEDDING,8K", + "max_tokens": 8191, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "text-embedding-3-small", + "tags": "TEXT EMBEDDING,8K", + "max_tokens": 8191, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "text-embedding-3-large", + "tags": "TEXT EMBEDDING,8K", + "max_tokens": 8191, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "whisper-1", + "tags": "SPEECH2TEXT", + "max_tokens": 26214400, + "model_type": "speech2text", + "is_tools": false + }, + { + "llm_name": "tts-1", + "tags": "TTS", + "max_tokens": 2048, + "model_type": "tts", + "is_tools": false + } + ] + }, + { + "name": "LongCat", + "logo": "", + "tags": "LLM", + "status": "1", + "rank": "870", + "llm": [ + { + "llm_name": "LongCat-Flash-Chat", + "tags": "LLM,CHAT,8000", + "max_tokens": 8000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "LongCat-Flash-Thinking", + "tags": "LLM,CHAT,8000", + "max_tokens": 8000, + "model_type": "chat", + "is_tools": true + } + ] + }, + { + "name": "DeerAPI", + "logo": "", + "tags": "LLM,TEXT EMBEDDING,IMAGE2TEXT", + "status": "1", + "llm": [ + { + "llm_name": "gpt-5-chat-latest", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "chatgpt-4o-latest", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5-mini", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5-nano", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4.1-mini", + "tags": "LLM,CHAT,1M", + "max_tokens": 1047576, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4.1-nano", + "tags": "LLM,CHAT,1M", + "max_tokens": 1047576, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4.1", + "tags": "LLM,CHAT,1M", + "max_tokens": 1047576, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4o-mini", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "o4-mini-2025-04-16", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "o3-pro-2025-06-10", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "claude-opus-4-1-20250805", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-opus-4-1-20250805-thinking", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-sonnet-4-20250514", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-sonnet-4-20250514-thinking", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-3-7-sonnet-latest", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "claude-3-5-haiku-latest", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gemini-2.5-pro", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "gemini-2.5-flash", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "gemini-2.5-flash-lite", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "gemini-2.0-flash", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "grok-4-0709", + "tags": "LLM,CHAT,131k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3", + "tags": "LLM,CHAT,131k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3-mini", + "tags": "LLM,CHAT,131k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-2-image-1212", + "tags": "LLM,CHAT,32k,IMAGE2TEXT", + "max_tokens": 32768, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "deepseek-v3.1", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-v3", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-r1-0528", + "tags": "LLM,CHAT,164k", + "max_tokens": 164000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-chat", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-reasoner", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-30b-a3b", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-coder-plus-2025-07-22", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "text-embedding-ada-002", + "tags": "TEXT EMBEDDING,8K", + "max_tokens": 8191, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "text-embedding-3-small", + "tags": "TEXT EMBEDDING,8K", + "max_tokens": 8191, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "text-embedding-3-large", + "tags": "TEXT EMBEDDING,8K", + "max_tokens": 8191, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "whisper-1", + "tags": "SPEECH2TEXT", + "max_tokens": 26214400, + "model_type": "speech2text", + "is_tools": false + }, + { + "llm_name": "tts-1", + "tags": "TTS", + "max_tokens": 2048, + "model_type": "tts", + "is_tools": false + } + ] } ] -} +} \ No newline at end of file diff --git a/conf/os_mapping.json b/conf/os_mapping.json index a8663e069a3..47b7c24b0f5 100644 --- a/conf/os_mapping.json +++ b/conf/os_mapping.json @@ -200,6 +200,61 @@ } } }, + { + "knn_vector": { + "match": "*_2048_vec", + "mapping": { + "type": "knn_vector", + "index": true, + "space_type": "cosinesimil", + "dimension": 2048 + } + } + }, + { + "knn_vector": { + "match": "*_4096_vec", + "mapping": { + "type": "knn_vector", + "index": true, + "space_type": "cosinesimil", + "dimension": 4096 + } + } + }, + { + "knn_vector": { + "match": "*_6144_vec", + "mapping": { + "type": "knn_vector", + "index": true, + "space_type": "cosinesimil", + "dimension": 6144 + } + } + }, + { + "knn_vector": { + "match": "*_8192_vec", + "mapping": { + "type": "knn_vector", + "index": true, + "space_type": "cosinesimil", + "dimension": 8192 + } + } + }, + { + "knn_vector": { + "match": "*_10240_vec", + "mapping": { + "type": "knn_vector", + "index": true, + "space_type": "cosinesimil", + "dimension": 10240 + } + } + }, { "binary": { "match": "*_bin", diff --git a/conf/service_conf.yaml b/conf/service_conf.yaml index 4c0635770c9..df629004209 100644 --- a/conf/service_conf.yaml +++ b/conf/service_conf.yaml @@ -1,6 +1,9 @@ ragflow: host: 0.0.0.0 http_port: 9380 +admin: + host: 0.0.0.0 + http_port: 9381 mysql: name: 'rag_flow' user: 'root' @@ -29,6 +32,13 @@ redis: db: 1 password: 'infini_rag_flow' host: 'localhost:6379' +task_executor: + message_queue_type: 'redis' +user_default_llm: + default_models: + embedding_model: + api_key: 'xxx' + base_url: 'http://localhost:6380' # postgres: # name: 'rag_flow' # user: 'rag_flow' @@ -62,11 +72,24 @@ redis: # opendal: # scheme: 'mysql' # Storage type, such as s3, oss, azure, etc. # config: -# oss_table: 'your_table_name' +# oss_table: 'opendal_storage' # user_default_llm: -# factory: 'Tongyi-Qianwen' -# api_key: 'sk-xxxxxxxxxxxxx' -# base_url: '' +# factory: 'BAAI' +# api_key: 'backup' +# base_url: 'backup_base_url' +# default_models: +# chat_model: +# name: 'qwen2.5-7b-instruct' +# factory: 'xxxx' +# api_key: 'xxxx' +# base_url: 'https://api.xx.com' +# embedding_model: +# api_key: 'xxx' +# base_url: 'http://localhost:6380' +# rerank_model: 'bge-reranker-v2' +# asr_model: +# model: 'whisper-large-v3' # alias of name +# image2text_model: '' # oauth: # oauth2: # display_name: "OAuth2" @@ -101,3 +124,20 @@ redis: # switch: false # component: false # dataset: false +# smtp: +# mail_server: "" +# mail_port: 465 +# mail_use_ssl: true +# mail_use_tls: false +# mail_username: "" +# mail_password: "" +# mail_default_sender: +# - "RAGFlow" # display name +# - "" # sender email address +# mail_frontend_url: "https://your-frontend.example.com" +# tcadp_config: +# secret_id: 'tencent_secret_id' +# secret_key: 'tencent_secret_key' +# region: 'tencent_region' +# table_result_type: '1' +# markdown_image_response_type: '1' diff --git a/deepdoc/parser/__init__.py b/deepdoc/parser/__init__.py index 1597ed08169..809a56edf70 100644 --- a/deepdoc/parser/__init__.py +++ b/deepdoc/parser/__init__.py @@ -14,13 +14,15 @@ # limitations under the License. # -from .pdf_parser import RAGFlowPdfParser as PdfParser, PlainParser from .docx_parser import RAGFlowDocxParser as DocxParser from .excel_parser import RAGFlowExcelParser as ExcelParser -from .ppt_parser import RAGFlowPptParser as PptParser from .html_parser import RAGFlowHtmlParser as HtmlParser from .json_parser import RAGFlowJsonParser as JsonParser +from .markdown_parser import MarkdownElementExtractor from .markdown_parser import RAGFlowMarkdownParser as MarkdownParser +from .pdf_parser import PlainParser +from .pdf_parser import RAGFlowPdfParser as PdfParser +from .ppt_parser import RAGFlowPptParser as PptParser from .txt_parser import RAGFlowTxtParser as TxtParser __all__ = [ @@ -33,4 +35,6 @@ "JsonParser", "MarkdownParser", "TxtParser", -] \ No newline at end of file + "MarkdownElementExtractor", +] + diff --git a/deepdoc/parser/docling_parser.py b/deepdoc/parser/docling_parser.py new file mode 100644 index 00000000000..dd0f57ea4b1 --- /dev/null +++ b/deepdoc/parser/docling_parser.py @@ -0,0 +1,344 @@ +# +# Copyright 2025 The InfiniFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +import logging +import re +from dataclasses import dataclass +from enum import Enum +from io import BytesIO +from os import PathLike +from pathlib import Path +from typing import Any, Callable, Iterable, Optional + +import pdfplumber +from PIL import Image + +try: + from docling.document_converter import DocumentConverter +except Exception: + DocumentConverter = None + +try: + from deepdoc.parser.pdf_parser import RAGFlowPdfParser +except Exception: + class RAGFlowPdfParser: + pass + + +class DoclingContentType(str, Enum): + IMAGE = "image" + TABLE = "table" + TEXT = "text" + EQUATION = "equation" + + +@dataclass +class _BBox: + page_no: int + x0: float + y0: float + x1: float + y1: float + + +class DoclingParser(RAGFlowPdfParser): + def __init__(self): + self.logger = logging.getLogger(self.__class__.__name__) + self.page_images: list[Image.Image] = [] + self.page_from = 0 + self.page_to = 10_000 + + def check_installation(self) -> bool: + if DocumentConverter is None: + self.logger.warning("[Docling] 'docling' is not importable, please: pip install docling") + return False + try: + _ = DocumentConverter() + return True + except Exception as e: + self.logger.error(f"[Docling] init DocumentConverter failed: {e}") + return False + + def __images__(self, fnm, zoomin: int = 1, page_from=0, page_to=600, callback=None): + self.page_from = page_from + self.page_to = page_to + try: + opener = pdfplumber.open(fnm) if isinstance(fnm, (str, PathLike)) else pdfplumber.open(BytesIO(fnm)) + with opener as pdf: + pages = pdf.pages[page_from:page_to] + self.page_images = [p.to_image(resolution=72 * zoomin, antialias=True).original for p in pages] + except Exception as e: + self.page_images = [] + self.logger.exception(e) + + def _make_line_tag(self,bbox: _BBox) -> str: + if bbox is None: + return "" + x0,x1, top, bott = bbox.x0, bbox.x1, bbox.y0, bbox.y1 + if hasattr(self, "page_images") and self.page_images and len(self.page_images) >= bbox.page_no: + _, page_height = self.page_images[bbox.page_no-1].size + top, bott = page_height-top ,page_height-bott + return "@@{}\t{:.1f}\t{:.1f}\t{:.1f}\t{:.1f}##".format( + bbox.page_no, x0,x1, top, bott + ) + + @staticmethod + def extract_positions(txt: str) -> list[tuple[list[int], float, float, float, float]]: + poss = [] + for tag in re.findall(r"@@[0-9-]+\t[0-9.\t]+##", txt): + pn, left, right, top, bottom = tag.strip("#").strip("@").split("\t") + left, right, top, bottom = float(left), float(right), float(top), float(bottom) + poss.append(([int(p) - 1 for p in pn.split("-")], left, right, top, bottom)) + return poss + + def crop(self, text: str, ZM: int = 1, need_position: bool = False): + imgs = [] + poss = self.extract_positions(text) + if not poss: + return (None, None) if need_position else None + + GAP = 6 + pos = poss[0] + poss.insert(0, ([pos[0][0]], pos[1], pos[2], max(0, pos[3] - 120), max(pos[3] - GAP, 0))) + pos = poss[-1] + poss.append(([pos[0][-1]], pos[1], pos[2], min(self.page_images[pos[0][-1]].size[1], pos[4] + GAP), min(self.page_images[pos[0][-1]].size[1], pos[4] + 120))) + positions = [] + for ii, (pns, left, right, top, bottom) in enumerate(poss): + if bottom <= top: + bottom = top + 4 + img0 = self.page_images[pns[0]] + x0, y0, x1, y1 = int(left), int(top), int(right), int(min(bottom, img0.size[1])) + + crop0 = img0.crop((x0, y0, x1, y1)) + imgs.append(crop0) + if 0 < ii < len(poss)-1: + positions.append((pns[0] + self.page_from, x0, x1, y0, y1)) + remain_bottom = bottom - img0.size[1] + for pn in pns[1:]: + if remain_bottom <= 0: + break + page = self.page_images[pn] + x0, y0, x1, y1 = int(left), 0, int(right), int(min(remain_bottom, page.size[1])) + cimgp = page.crop((x0, y0, x1, y1)) + imgs.append(cimgp) + if 0 < ii < len(poss) - 1: + positions.append((pn + self.page_from, x0, x1, y0, y1)) + remain_bottom -= page.size[1] + + if not imgs: + return (None, None) if need_position else None + + height = sum(i.size[1] + GAP for i in imgs) + width = max(i.size[0] for i in imgs) + pic = Image.new("RGB", (width, int(height)), (245, 245, 245)) + h = 0 + for ii, img in enumerate(imgs): + if ii == 0 or ii + 1 == len(imgs): + img = img.convert("RGBA") + overlay = Image.new("RGBA", img.size, (0, 0, 0, 0)) + overlay.putalpha(128) + img = Image.alpha_composite(img, overlay).convert("RGB") + pic.paste(img, (0, int(h))) + h += img.size[1] + GAP + + return (pic, positions) if need_position else pic + + def _iter_doc_items(self, doc) -> Iterable[tuple[str, Any, Optional[_BBox]]]: + for t in getattr(doc, "texts", []): + parent=getattr(t, "parent", "") + ref=getattr(parent,"cref","") + label=getattr(t, "label", "") + if (label in ("section_header","text",) and ref in ("#/body",)) or label in ("list_item",): + text = getattr(t, "text", "") or "" + bbox = None + if getattr(t, "prov", None): + pn = getattr(t.prov[0], "page_no", None) + bb = getattr(t.prov[0], "bbox", None) + bb = [getattr(bb, "l", None),getattr(bb, "t", None),getattr(bb, "r", None),getattr(bb, "b", None)] + if pn and bb and len(bb) == 4: + bbox = _BBox(page_no=int(pn), x0=bb[0], y0=bb[1], x1=bb[2], y1=bb[3]) + yield (DoclingContentType.TEXT.value, text, bbox) + + for item in getattr(doc, "texts", []): + if getattr(item, "label", "") in ("FORMULA",): + text = getattr(item, "text", "") or "" + bbox = None + if getattr(item, "prov", None): + pn = getattr(item.prov, "page_no", None) + bb = getattr(item.prov, "bbox", None) + bb = [getattr(bb, "l", None),getattr(bb, "t", None),getattr(bb, "r", None),getattr(bb, "b", None)] + if pn and bb and len(bb) == 4: + bbox = _BBox(int(pn), bb[0], bb[1], bb[2], bb[3]) + yield (DoclingContentType.EQUATION.value, text, bbox) + + def _transfer_to_sections(self, doc) -> list[tuple[str, str]]: + """ + 和 MinerUParser 保持一致:返回 [(section_text, line_tag), ...] + """ + sections: list[tuple[str, str]] = [] + for typ, payload, bbox in self._iter_doc_items(doc): + if typ == DoclingContentType.TEXT.value: + section = payload.strip() + if not section: + continue + elif typ == DoclingContentType.EQUATION.value: + section = payload.strip() + else: + continue + + tag = self._make_line_tag(bbox) if isinstance(bbox,_BBox) else "" + sections.append((section, tag)) + return sections + + def cropout_docling_table(self, page_no: int, bbox: tuple[float, float, float, float], zoomin: int = 1): + if not getattr(self, "page_images", None): + return None, "" + + idx = (page_no - 1) - getattr(self, "page_from", 0) + if idx < 0 or idx >= len(self.page_images): + return None, "" + + page_img = self.page_images[idx] + W, H = page_img.size + left, top, right, bott = bbox + + x0 = float(left) + y0 = float(H-top) + x1 = float(right) + y1 = float(H-bott) + + x0, y0 = max(0.0, min(x0, W - 1)), max(0.0, min(y0, H - 1)) + x1, y1 = max(x0 + 1.0, min(x1, W)), max(y0 + 1.0, min(y1, H)) + + try: + crop = page_img.crop((int(x0), int(y0), int(x1), int(y1))).convert("RGB") + except Exception: + return None, "" + + pos = (page_no-1 if page_no>0 else 0, x0, x1, y0, y1) + return crop, [pos] + + def _transfer_to_tables(self, doc): + tables = [] + for tab in getattr(doc, "tables", []): + img = None + positions = "" + if getattr(tab, "prov", None): + pn = getattr(tab.prov[0], "page_no", None) + bb = getattr(tab.prov[0], "bbox", None) + if pn is not None and bb is not None: + left = getattr(bb, "l", None) + top = getattr(bb, "t", None) + right = getattr(bb, "r", None) + bott = getattr(bb, "b", None) + if None not in (left, top, right, bott): + img, positions = self.cropout_docling_table(int(pn), (float(left), float(top), float(right), float(bott))) + html = "" + try: + html = tab.export_to_html(doc=doc) + except Exception: + pass + tables.append(((img, html), positions if positions else "")) + for pic in getattr(doc, "pictures", []): + img = None + positions = "" + if getattr(pic, "prov", None): + pn = getattr(pic.prov[0], "page_no", None) + bb = getattr(pic.prov[0], "bbox", None) + if pn is not None and bb is not None: + left = getattr(bb, "l", None) + top = getattr(bb, "t", None) + right = getattr(bb, "r", None) + bott = getattr(bb, "b", None) + if None not in (left, top, right, bott): + img, positions = self.cropout_docling_table(int(pn), (float(left), float(top), float(right), float(bott))) + captions = "" + try: + captions = pic.caption_text(doc=doc) + except Exception: + pass + tables.append(((img, [captions]), positions if positions else "")) + return tables + + def parse_pdf( + self, + filepath: str | PathLike[str], + binary: BytesIO | bytes | None = None, + callback: Optional[Callable] = None, + *, + output_dir: Optional[str] = None, + lang: Optional[str] = None, + method: str = "auto", + delete_output: bool = True, + ): + + if not self.check_installation(): + raise RuntimeError("Docling not available, please install `docling`") + + if binary is not None: + tmpdir = Path(output_dir) if output_dir else Path.cwd() / ".docling_tmp" + tmpdir.mkdir(parents=True, exist_ok=True) + name = Path(filepath).name or "input.pdf" + tmp_pdf = tmpdir / name + with open(tmp_pdf, "wb") as f: + if isinstance(binary, (bytes, bytearray)): + f.write(binary) + else: + f.write(binary.getbuffer()) + src_path = tmp_pdf + else: + src_path = Path(filepath) + if not src_path.exists(): + raise FileNotFoundError(f"PDF not found: {src_path}") + + if callback: + callback(0.1, f"[Docling] Converting: {src_path}") + + try: + self.__images__(str(src_path), zoomin=1) + except Exception as e: + self.logger.warning(f"[Docling] render pages failed: {e}") + + conv = DocumentConverter() + conv_res = conv.convert(str(src_path)) + doc = conv_res.document + if callback: + callback(0.7, f"[Docling] Parsed doc: {getattr(doc, 'num_pages', 'n/a')} pages") + + sections = self._transfer_to_sections(doc) + tables = self._transfer_to_tables(doc) + + if callback: + callback(0.95, f"[Docling] Sections: {len(sections)}, Tables: {len(tables)}") + + if binary is not None and delete_output: + try: + Path(src_path).unlink(missing_ok=True) + except Exception: + pass + + if callback: + callback(1.0, "[Docling] Done.") + return sections, tables + + +if __name__ == "__main__": + logging.basicConfig(level=logging.INFO) + parser = DoclingParser() + print("Docling available:", parser.check_installation()) + sections, tables = parser.parse_pdf(filepath="test_docling/toc.pdf", binary=None) + print(len(sections), len(tables)) diff --git a/deepdoc/parser/docx_parser.py b/deepdoc/parser/docx_parser.py index f3711961564..2a65841e246 100644 --- a/deepdoc/parser/docx_parser.py +++ b/deepdoc/parser/docx_parser.py @@ -33,7 +33,7 @@ def __extract_table_content(self, tb): def __compose_table_content(self, df): def blockType(b): - patt = [ + pattern = [ ("^(20|19)[0-9]{2}[年/-][0-9]{1,2}[月/-][0-9]{1,2}日*$", "Dt"), (r"^(20|19)[0-9]{2}年$", "Dt"), (r"^(20|19)[0-9]{2}[年/-][0-9]{1,2}月*$", "Dt"), @@ -47,7 +47,7 @@ def blockType(b): (r"^[0-9.,+-]+[0-9A-Za-z/$¥%<>()()' -]+$", "NE"), (r"^.{1}$", "Sg") ] - for p, n in patt: + for p, n in pattern: if re.search(p, b): return n tks = [t for t in rag_tokenizer.tokenize(b).split() if len(t) > 1] diff --git a/deepdoc/parser/excel_parser.py b/deepdoc/parser/excel_parser.py index 8eb726a08cf..868fc5f41c2 100644 --- a/deepdoc/parser/excel_parser.py +++ b/deepdoc/parser/excel_parser.py @@ -12,6 +12,7 @@ # import logging +import re import sys from io import BytesIO @@ -20,9 +21,11 @@ from rag.nlp import find_codec +# copied from `/openpyxl/cell/cell.py` +ILLEGAL_CHARACTERS_RE = re.compile(r"[\000-\010]|[\013-\014]|[\016-\037]") -class RAGFlowExcelParser: +class RAGFlowExcelParser: @staticmethod def _load_excel_to_workbook(file_like_object): if isinstance(file_like_object, bytes): @@ -33,8 +36,8 @@ def _load_excel_to_workbook(file_like_object): file_head = file_like_object.read(4) file_like_object.seek(0) - if not (file_head.startswith(b'PK\x03\x04') or file_head.startswith(b'\xD0\xCF\x11\xE0')): - logging.info("****wxy: Not an Excel file, converting CSV to Excel Workbook") + if not (file_head.startswith(b"PK\x03\x04") or file_head.startswith(b"\xd0\xcf\x11\xe0")): + logging.info("Not an Excel file, converting CSV to Excel Workbook") try: file_like_object.seek(0) @@ -42,21 +45,41 @@ def _load_excel_to_workbook(file_like_object): return RAGFlowExcelParser._dataframe_to_workbook(df) except Exception as e_csv: - raise Exception(f"****wxy: Failed to parse CSV and convert to Excel Workbook: {e_csv}") + raise Exception(f"Failed to parse CSV and convert to Excel Workbook: {e_csv}") try: - return load_workbook(file_like_object,data_only= True) + return load_workbook(file_like_object, data_only=True) except Exception as e: - logging.info(f"****wxy: openpyxl load error: {e}, try pandas instead") + logging.info(f"openpyxl load error: {e}, try pandas instead") try: file_like_object.seek(0) - df = pd.read_excel(file_like_object) - return RAGFlowExcelParser._dataframe_to_workbook(df) + try: + dfs = pd.read_excel(file_like_object, sheet_name=None) + return RAGFlowExcelParser._dataframe_to_workbook(dfs) + except Exception as ex: + logging.info(f"pandas with default engine load error: {ex}, try calamine instead") + file_like_object.seek(0) + df = pd.read_excel(file_like_object, engine="calamine") + return RAGFlowExcelParser._dataframe_to_workbook(df) except Exception as e_pandas: - raise Exception(f"****wxy: pandas.read_excel error: {e_pandas}, original openpyxl error: {e}") + raise Exception(f"pandas.read_excel error: {e_pandas}, original openpyxl error: {e}") + + @staticmethod + def _clean_dataframe(df: pd.DataFrame): + def clean_string(s): + if isinstance(s, str): + return ILLEGAL_CHARACTERS_RE.sub(" ", s) + return s + + return df.apply(lambda col: col.map(clean_string)) @staticmethod def _dataframe_to_workbook(df): + # if contains multiple sheets use _dataframes_to_workbook + if isinstance(df, dict) and len(df) > 1: + return RAGFlowExcelParser._dataframes_to_workbook(df) + + df = RAGFlowExcelParser._clean_dataframe(df) wb = Workbook() ws = wb.active ws.title = "Data" @@ -69,41 +92,82 @@ def _dataframe_to_workbook(df): ws.cell(row=row_num, column=col_num, value=value) return wb + + @staticmethod + def _dataframes_to_workbook(dfs: dict): + wb = Workbook() + default_sheet = wb.active + wb.remove(default_sheet) + + for sheet_name, df in dfs.items(): + df = RAGFlowExcelParser._clean_dataframe(df) + ws = wb.create_sheet(title=sheet_name) + for col_num, column_name in enumerate(df.columns, 1): + ws.cell(row=1, column=col_num, value=column_name) + for row_num, row in enumerate(df.values, 2): + for col_num, value in enumerate(row, 1): + ws.cell(row=row_num, column=col_num, value=value) + return wb def html(self, fnm, chunk_rows=256): + from html import escape + file_like_object = BytesIO(fnm) if not isinstance(fnm, str) else fnm wb = RAGFlowExcelParser._load_excel_to_workbook(file_like_object) tb_chunks = [] + + def _fmt(v): + if v is None: + return "" + return str(v).strip() + for sheetname in wb.sheetnames: ws = wb[sheetname] - rows = list(ws.rows) + try: + rows = list(ws.rows) + except Exception as e: + logging.warning(f"Skip sheet '{sheetname}' due to rows access error: {e}") + continue + if not rows: continue tb_rows_0 = "" for t in list(rows[0]): - tb_rows_0 += f"{t.value}" + tb_rows_0 += f"{escape(_fmt(t.value))}" tb_rows_0 += "" for chunk_i in range((len(rows) - 1) // chunk_rows + 1): tb = "" tb += f"" tb += tb_rows_0 - for r in list( - rows[1 + chunk_i * chunk_rows: 1 + (chunk_i + 1) * chunk_rows] - ): + for r in list(rows[1 + chunk_i * chunk_rows : min(1 + (chunk_i + 1) * chunk_rows, len(rows))]): tb += "" for i, c in enumerate(r): if c.value is None: tb += "" else: - tb += f"" + tb += f"" tb += "" tb += "
{sheetname}
{c.value}{escape(_fmt(c.value))}
\n" tb_chunks.append(tb) return tb_chunks + def markdown(self, fnm): + import pandas as pd + + file_like_object = BytesIO(fnm) if not isinstance(fnm, str) else fnm + try: + file_like_object.seek(0) + df = pd.read_excel(file_like_object) + except Exception as e: + logging.warning(f"Parse spreadsheet error: {e}, trying to interpret as CSV file") + file_like_object.seek(0) + df = pd.read_csv(file_like_object) + df = df.replace(r"^\s*$", "", regex=True) + return df.to_markdown(index=False) + def __call__(self, fnm): file_like_object = BytesIO(fnm) if not isinstance(fnm, str) else fnm wb = RAGFlowExcelParser._load_excel_to_workbook(file_like_object) @@ -111,7 +175,11 @@ def __call__(self, fnm): res = [] for sheetname in wb.sheetnames: ws = wb[sheetname] - rows = list(ws.rows) + try: + rows = list(ws.rows) + except Exception as e: + logging.warning(f"Skip sheet '{sheetname}' due to rows access error: {e}") + continue if not rows: continue ti = list(rows[0]) @@ -134,9 +202,14 @@ def row_number(fnm, binary): if fnm.split(".")[-1].lower().find("xls") >= 0: wb = RAGFlowExcelParser._load_excel_to_workbook(BytesIO(binary)) total = 0 + for sheetname in wb.sheetnames: - ws = wb[sheetname] - total += len(list(ws.rows)) + try: + ws = wb[sheetname] + total += len(list(ws.rows)) + except Exception as e: + logging.warning(f"Skip sheet '{sheetname}' due to rows access error: {e}") + continue return total if fnm.split(".")[-1].lower() in ["csv", "txt"]: diff --git a/deepdoc/parser/figure_parser.py b/deepdoc/parser/figure_parser.py index b29a4a8a527..a913822c32e 100644 --- a/deepdoc/parser/figure_parser.py +++ b/deepdoc/parser/figure_parser.py @@ -17,8 +17,11 @@ from PIL import Image +from common.constants import LLMType +from api.db.services.llm_service import LLMBundle +from common.connection_utils import timeout from rag.app.picture import vision_llm_chunk as picture_vision_llm_chunk -from rag.prompts import vision_llm_figure_describe_prompt +from rag.prompts.generator import vision_llm_figure_describe_prompt def vision_figure_parser_figure_data_wrapper(figures_data_without_positions): @@ -31,6 +34,43 @@ def vision_figure_parser_figure_data_wrapper(figures_data_without_positions): if isinstance(figure_data[1], Image.Image) ] +def vision_figure_parser_docx_wrapper(sections,tbls,callback=None,**kwargs): + try: + vision_model = LLMBundle(kwargs["tenant_id"], LLMType.IMAGE2TEXT) + callback(0.7, "Visual model detected. Attempting to enhance figure extraction...") + except Exception: + vision_model = None + if vision_model: + figures_data = vision_figure_parser_figure_data_wrapper(sections) + try: + docx_vision_parser = VisionFigureParser(vision_model=vision_model, figures_data=figures_data, **kwargs) + boosted_figures = docx_vision_parser(callback=callback) + tbls.extend(boosted_figures) + except Exception as e: + callback(0.8, f"Visual model error: {e}. Skipping figure parsing enhancement.") + return tbls + +def vision_figure_parser_pdf_wrapper(tbls,callback=None,**kwargs): + try: + vision_model = LLMBundle(kwargs["tenant_id"], LLMType.IMAGE2TEXT) + callback(0.7, "Visual model detected. Attempting to enhance figure extraction...") + except Exception: + vision_model = None + if vision_model: + def is_figure_item(item): + return ( + isinstance(item[0][0], Image.Image) and + isinstance(item[0][1], list) + ) + figures_data = [item for item in tbls if is_figure_item(item)] + try: + docx_vision_parser = VisionFigureParser(vision_model=vision_model, figures_data=figures_data, **kwargs) + boosted_figures = docx_vision_parser(callback=callback) + tbls = [item for item in tbls if not is_figure_item(item)] + tbls.extend(boosted_figures) + except Exception as e: + callback(0.8, f"Visual model error: {e}. Skipping figure parsing enhancement.") + return tbls shared_executor = ThreadPoolExecutor(max_workers=10) @@ -80,6 +120,7 @@ def _assemble(self): def __call__(self, **kwargs): callback = kwargs.get("callback", lambda prog, msg: None) + @timeout(30, 3) def process(figure_idx, figure_binary): description_text = picture_vision_llm_chunk( binary=figure_binary, diff --git a/deepdoc/parser/html_parser.py b/deepdoc/parser/html_parser.py index 29cc43a1d44..44ff1038952 100644 --- a/deepdoc/parser/html_parser.py +++ b/deepdoc/parser/html_parser.py @@ -15,36 +15,200 @@ # limitations under the License. # -from rag.nlp import find_codec -import readability -import html_text +from rag.nlp import find_codec, rag_tokenizer +import uuid import chardet - +from bs4 import BeautifulSoup, NavigableString, Tag, Comment +import html def get_encoding(file): with open(file,'rb') as f: tmp = chardet.detect(f.read()) return tmp['encoding'] +BLOCK_TAGS = [ + "h1", "h2", "h3", "h4", "h5", "h6", + "p", "div", "article", "section", "aside", + "ul", "ol", "li", + "table", "pre", "code", "blockquote", + "figure", "figcaption" +] +TITLE_TAGS = {"h1": "#", "h2": "##", "h3": "###", "h4": "#####", "h5": "#####", "h6": "######"} + class RAGFlowHtmlParser: - def __call__(self, fnm, binary=None): - txt = "" + def __call__(self, fnm, binary=None, chunk_token_num=512): if binary: encoding = find_codec(binary) txt = binary.decode(encoding, errors="ignore") else: with open(fnm, "r",encoding=get_encoding(fnm)) as f: txt = f.read() - return self.parser_txt(txt) + return self.parser_txt(txt, chunk_token_num) @classmethod - def parser_txt(cls, txt): + def parser_txt(cls, txt, chunk_token_num): if not isinstance(txt, str): - raise TypeError("txt type should be str!") - html_doc = readability.Document(txt) - title = html_doc.title() - content = html_text.extract_text(html_doc.summary(html_partial=True)) - txt = f"{title}\n{content}" - sections = txt.split("\n") + raise TypeError("txt type should be string!") + + temp_sections = [] + soup = BeautifulSoup(txt, "html5lib") + # delete - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Gemini \ No newline at end of file diff --git a/web/src/assets/svg/llm/github.svg b/web/src/assets/svg/llm/github.svg deleted file mode 100644 index 6f80a87ed11..00000000000 --- a/web/src/assets/svg/llm/github.svg +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/web/src/assets/svg/llm/google-cloud.svg b/web/src/assets/svg/llm/google-cloud.svg deleted file mode 100644 index 2f7870552c5..00000000000 --- a/web/src/assets/svg/llm/google-cloud.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/web/src/assets/svg/llm/google.svg b/web/src/assets/svg/llm/google.svg deleted file mode 100644 index f0d10ecfd99..00000000000 --- a/web/src/assets/svg/llm/google.svg +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/web/src/assets/svg/llm/gpustack.svg b/web/src/assets/svg/llm/gpustack.svg deleted file mode 100644 index 95a07f912bc..00000000000 --- a/web/src/assets/svg/llm/gpustack.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - Combined Shape - - - - - - - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/groq-next.svg b/web/src/assets/svg/llm/groq-next.svg deleted file mode 100644 index 5608a42e4fc..00000000000 --- a/web/src/assets/svg/llm/groq-next.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/web/src/assets/svg/llm/huggingface.svg b/web/src/assets/svg/llm/huggingface.svg deleted file mode 100644 index 43c5d3c0c97..00000000000 --- a/web/src/assets/svg/llm/huggingface.svg +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - diff --git a/web/src/assets/svg/llm/hunyuan.svg b/web/src/assets/svg/llm/hunyuan.svg deleted file mode 100644 index 43a78d0077a..00000000000 --- a/web/src/assets/svg/llm/hunyuan.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/web/src/assets/svg/llm/jina.svg b/web/src/assets/svg/llm/jina.svg deleted file mode 100644 index 6a241fc9ae3..00000000000 --- a/web/src/assets/svg/llm/jina.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/web/src/assets/svg/llm/lepton-ai.svg b/web/src/assets/svg/llm/lepton-ai.svg deleted file mode 100644 index b7ccd3d26e2..00000000000 --- a/web/src/assets/svg/llm/lepton-ai.svg +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - diff --git a/web/src/assets/svg/llm/lm-studio.svg b/web/src/assets/svg/llm/lm-studio.svg deleted file mode 100644 index 98d4c1d990c..00000000000 --- a/web/src/assets/svg/llm/lm-studio.svg +++ /dev/null @@ -1,9704 +0,0 @@ - - - - diff --git a/web/src/assets/svg/llm/local-ai.svg b/web/src/assets/svg/llm/local-ai.svg index 3be050a3784..9dc6e6276ea 100644 --- a/web/src/assets/svg/llm/local-ai.svg +++ b/web/src/assets/svg/llm/local-ai.svg @@ -1,17 +1,15 @@ - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + diff --git a/web/src/assets/svg/llm/mistral.svg b/web/src/assets/svg/llm/mistral.svg deleted file mode 100644 index b4a57ef79fa..00000000000 --- a/web/src/assets/svg/llm/mistral.svg +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/modelscope.svg b/web/src/assets/svg/llm/modelscope.svg deleted file mode 100644 index 8b3778fc456..00000000000 --- a/web/src/assets/svg/llm/modelscope.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/web/src/assets/svg/llm/moonshot.svg b/web/src/assets/svg/llm/moonshot.svg deleted file mode 100644 index dbaf1f64734..00000000000 --- a/web/src/assets/svg/llm/moonshot.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/nomic-ai.svg b/web/src/assets/svg/llm/nomic-ai.svg deleted file mode 100644 index 26e624a88b8..00000000000 --- a/web/src/assets/svg/llm/nomic-ai.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/web/src/assets/svg/llm/novita-ai.svg b/web/src/assets/svg/llm/novita-ai.svg deleted file mode 100644 index c44bd707b7c..00000000000 --- a/web/src/assets/svg/llm/novita-ai.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/web/src/assets/svg/llm/nvidia.svg b/web/src/assets/svg/llm/nvidia.svg deleted file mode 100644 index 217afaac9ca..00000000000 --- a/web/src/assets/svg/llm/nvidia.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/web/src/assets/svg/llm/ollama.svg b/web/src/assets/svg/llm/ollama.svg deleted file mode 100644 index 6e9fb283c01..00000000000 --- a/web/src/assets/svg/llm/ollama.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/web/src/assets/svg/llm/open-router.svg b/web/src/assets/svg/llm/open-router.svg deleted file mode 100644 index e6130e73d41..00000000000 --- a/web/src/assets/svg/llm/open-router.svg +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/openai-api.svg b/web/src/assets/svg/llm/openai-api.svg deleted file mode 100644 index a0ecf992f46..00000000000 --- a/web/src/assets/svg/llm/openai-api.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/web/src/assets/svg/llm/openai.svg b/web/src/assets/svg/llm/openai.svg deleted file mode 100644 index 6114c7c7ed6..00000000000 --- a/web/src/assets/svg/llm/openai.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/perfx-cloud.svg b/web/src/assets/svg/llm/perfx-cloud.svg deleted file mode 100644 index 3767a1e8664..00000000000 --- a/web/src/assets/svg/llm/perfx-cloud.svg +++ /dev/null @@ -1,10 +0,0 @@ - - logo - - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/ppio.svg b/web/src/assets/svg/llm/ppio.svg deleted file mode 100755 index 49ab9a1f6c8..00000000000 --- a/web/src/assets/svg/llm/ppio.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/web/src/assets/svg/llm/replicate.svg b/web/src/assets/svg/llm/replicate.svg deleted file mode 100644 index 31241923ed3..00000000000 --- a/web/src/assets/svg/llm/replicate.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/web/src/assets/svg/llm/sentence-transformers.svg b/web/src/assets/svg/llm/sentence-transformers.svg deleted file mode 100644 index f777b3d26cc..00000000000 --- a/web/src/assets/svg/llm/sentence-transformers.svg +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/siliconflow.svg b/web/src/assets/svg/llm/siliconflow.svg deleted file mode 100644 index 4ce6323dcb1..00000000000 --- a/web/src/assets/svg/llm/siliconflow.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/web/src/assets/svg/llm/spark.svg b/web/src/assets/svg/llm/spark.svg deleted file mode 100644 index 30f6040f24f..00000000000 --- a/web/src/assets/svg/llm/spark.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/web/src/assets/svg/llm/stepfun.svg b/web/src/assets/svg/llm/stepfun.svg index 919ab7f0c3e..70989521a51 100644 --- a/web/src/assets/svg/llm/stepfun.svg +++ b/web/src/assets/svg/llm/stepfun.svg @@ -1,37 +1 @@ - - - - +Stepfun \ No newline at end of file diff --git a/web/src/assets/svg/llm/tencent-cloud.svg b/web/src/assets/svg/llm/tencent-cloud.svg deleted file mode 100644 index b33a9701a1f..00000000000 --- a/web/src/assets/svg/llm/tencent-cloud.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/web/src/assets/svg/llm/together-ai.svg b/web/src/assets/svg/llm/together-ai.svg deleted file mode 100644 index 93e744c3df2..00000000000 --- a/web/src/assets/svg/llm/together-ai.svg +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/tongyi.svg b/web/src/assets/svg/llm/tongyi.svg deleted file mode 100644 index d7104d6d370..00000000000 --- a/web/src/assets/svg/llm/tongyi.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/upstage.svg b/web/src/assets/svg/llm/upstage.svg deleted file mode 100644 index 09a7512ca94..00000000000 --- a/web/src/assets/svg/llm/upstage.svg +++ /dev/null @@ -1,255 +0,0 @@ - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/vllm.svg b/web/src/assets/svg/llm/vllm.svg deleted file mode 100644 index 6aca3848649..00000000000 --- a/web/src/assets/svg/llm/vllm.svg +++ /dev/null @@ -1,59 +0,0 @@ - - vllm - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/volc_engine.svg b/web/src/assets/svg/llm/volc_engine.svg deleted file mode 100644 index 2c56cb00bdd..00000000000 --- a/web/src/assets/svg/llm/volc_engine.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/voyage.svg b/web/src/assets/svg/llm/voyage.svg deleted file mode 100644 index 88ffbdff91c..00000000000 --- a/web/src/assets/svg/llm/voyage.svg +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/xinference.svg b/web/src/assets/svg/llm/xinference.svg deleted file mode 100644 index 8d2ab4f3e4d..00000000000 --- a/web/src/assets/svg/llm/xinference.svg +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/yi.svg b/web/src/assets/svg/llm/yi.svg deleted file mode 100644 index 83ebd22d9f1..00000000000 --- a/web/src/assets/svg/llm/yi.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/web/src/assets/svg/llm/yiyan.svg b/web/src/assets/svg/llm/yiyan.svg deleted file mode 100644 index 4c571c34a07..00000000000 --- a/web/src/assets/svg/llm/yiyan.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/web/src/assets/svg/llm/youdao.svg b/web/src/assets/svg/llm/youdao.svg deleted file mode 100644 index 5af58851fd3..00000000000 --- a/web/src/assets/svg/llm/youdao.svg +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/llm/zhipu.svg b/web/src/assets/svg/llm/zhipu.svg deleted file mode 100644 index 5561830e619..00000000000 --- a/web/src/assets/svg/llm/zhipu.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - \ No newline at end of file diff --git a/web/src/assets/svg/pubmed.svg b/web/src/assets/svg/pubmed.svg index 6a17fa89c44..4fa20542644 100644 --- a/web/src/assets/svg/pubmed.svg +++ b/web/src/assets/svg/pubmed.svg @@ -1,6 +1,37 @@ - - - + + + pubmed + + + + + + \ No newline at end of file diff --git a/web/src/assets/svg/rerun.svg b/web/src/assets/svg/rerun.svg new file mode 100644 index 00000000000..cd972f4e6cd --- /dev/null +++ b/web/src/assets/svg/rerun.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/web/src/assets/svg/searxng.svg b/web/src/assets/svg/searxng.svg new file mode 100644 index 00000000000..8b6fd7e3c20 --- /dev/null +++ b/web/src/assets/svg/searxng.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/web/src/assets/svg/tavily.svg b/web/src/assets/svg/tavily.svg new file mode 100644 index 00000000000..f4e5fb783de --- /dev/null +++ b/web/src/assets/svg/tavily.svg @@ -0,0 +1,35 @@ + + + tavily + + + + + + + \ No newline at end of file diff --git a/web/src/assets/svg/wencai.svg b/web/src/assets/svg/wencai.svg index 0010ed8af18..1ba940f773c 100644 --- a/web/src/assets/svg/wencai.svg +++ b/web/src/assets/svg/wencai.svg @@ -1,152 +1,25 @@ - - - - + + + wencai + + + + + + + \ No newline at end of file diff --git a/web/src/assets/svg/wikipedia.svg b/web/src/assets/svg/wikipedia.svg index ee2f8850e38..f7e0c19451a 100644 --- a/web/src/assets/svg/wikipedia.svg +++ b/web/src/assets/svg/wikipedia.svg @@ -1,6 +1,24 @@ - - + + + wikipedia + + + + + + \ No newline at end of file diff --git a/web/src/assets/svg/yahoo-finance.svg b/web/src/assets/svg/yahoo-finance.svg index 9bf55ce2f6b..bb6df47501b 100644 --- a/web/src/assets/svg/yahoo-finance.svg +++ b/web/src/assets/svg/yahoo-finance.svg @@ -1,32 +1,37 @@ - - - favicon_y19_28x28_custom - Created with Sketch. + + yahoofinance - + + - - - - - - - - - - - - - - + + diff --git a/web/src/base.ts b/web/src/base.ts deleted file mode 100644 index b453ca4831a..00000000000 --- a/web/src/base.ts +++ /dev/null @@ -1,48 +0,0 @@ -import isObject from 'lodash/isObject'; -import { DvaModel } from 'umi'; -import { BaseState } from './interfaces/common'; - -type State = Record; -type DvaModelKey = keyof DvaModel; - -export const modelExtend = ( - baseModel: Partial>, - extendModel: DvaModel, -): DvaModel => { - return Object.keys(extendModel).reduce>((pre, cur) => { - const baseValue = baseModel[cur as DvaModelKey]; - const value = extendModel[cur as DvaModelKey]; - - if (isObject(value) && isObject(baseValue) && typeof value !== 'string') { - const key = cur as Exclude, 'namespace'>; - - pre[key] = { - ...baseValue, - ...value, - } as any; - } else { - pre[cur as DvaModelKey] = value as any; - } - - return pre; - }, {} as DvaModel); -}; - -export const paginationModel: Partial> = { - state: { - searchString: '', - pagination: { - total: 0, - current: 1, - pageSize: 10, - }, - }, - reducers: { - setSearchString(state, { payload }) { - return { ...state, searchString: payload }; - }, - setPagination(state, { payload }) { - return { ...state, pagination: { ...state.pagination, ...payload } }; - }, - }, -}; diff --git a/web/src/components/api-service/chat-overview-modal/markdown-toc.tsx b/web/src/components/api-service/chat-overview-modal/markdown-toc.tsx index 7694a0cb906..498026b09b7 100644 --- a/web/src/components/api-service/chat-overview-modal/markdown-toc.tsx +++ b/web/src/components/api-service/chat-overview-modal/markdown-toc.tsx @@ -53,14 +53,13 @@ const MarkdownToc: React.FC = ({ content }) => { return (
); } @@ -25,6 +27,7 @@ export function AutoQuestionsFormField() { max={10} min={0} tooltip={t('autoQuestionsTip')} + layout={FormLayout.Horizontal} > ); } diff --git a/web/src/components/avatar-upload.tsx b/web/src/components/avatar-upload.tsx new file mode 100644 index 00000000000..7a85e08defb --- /dev/null +++ b/web/src/components/avatar-upload.tsx @@ -0,0 +1,99 @@ +import { transformFile2Base64 } from '@/utils/file-util'; +import { Pencil, Plus, XIcon } from 'lucide-react'; +import { + ChangeEventHandler, + forwardRef, + useCallback, + useEffect, + useState, +} from 'react'; +import { useTranslation } from 'react-i18next'; +import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar'; +import { Button } from './ui/button'; +import { Input } from './ui/input'; + +type AvatarUploadProps = { + value?: string; + onChange?: (value: string) => void; + tips?: string; +}; + +export const AvatarUpload = forwardRef( + function AvatarUpload({ value, onChange, tips }, ref) { + const { t } = useTranslation(); + const [avatarBase64Str, setAvatarBase64Str] = useState(''); // Avatar Image base64 + + const handleChange: ChangeEventHandler = useCallback( + async (ev) => { + const file = ev.target?.files?.[0]; + if (/\.(jpg|jpeg|png|webp|bmp)$/i.test(file?.name ?? '')) { + const str = await transformFile2Base64(file!); + setAvatarBase64Str(str); + onChange?.(str); + } + ev.target.value = ''; + }, + [onChange], + ); + + const handleRemove = useCallback(() => { + setAvatarBase64Str(''); + onChange?.(''); + }, [onChange]); + + useEffect(() => { + if (value) { + setAvatarBase64Str(value); + } + }, [value]); + + return ( +
+
+ {!avatarBase64Str ? ( +
+
+ +

{t('common.upload')}

+
+
+ ) : ( +
+ + + + +
+ +
+ +
+ )} + +
+
+ {tips ?? t('knowledgeConfiguration.photoTip')} +
+
+ ); + }, +); diff --git a/web/src/components/back-button/index.tsx b/web/src/components/back-button/index.tsx new file mode 100644 index 00000000000..c790d688280 --- /dev/null +++ b/web/src/components/back-button/index.tsx @@ -0,0 +1,42 @@ +import { cn } from '@/lib/utils'; +import { t } from 'i18next'; +import { ArrowBigLeft } from 'lucide-react'; +import React from 'react'; +import { useNavigate } from 'umi'; +import { Button } from '../ui/button'; + +interface BackButtonProps + extends React.ButtonHTMLAttributes { + to?: string; +} + +const BackButton: React.FC = ({ + to, + className, + children, + ...props +}) => { + const navigate = useNavigate(); + + const handleClick = () => { + if (to) { + navigate(to); + } else { + navigate(-1); + } + }; + + return ( + + ); +}; + +export default BackButton; diff --git a/web/src/components/bulk-operate-bar.tsx b/web/src/components/bulk-operate-bar.tsx index 51652ff72a5..bf13c765d3c 100644 --- a/web/src/components/bulk-operate-bar.tsx +++ b/web/src/components/bulk-operate-bar.tsx @@ -13,15 +13,23 @@ export type BulkOperateItemType = { onClick(): void; }; -type BulkOperateBarProps = { list: BulkOperateItemType[]; count: number }; +type BulkOperateBarProps = { + list: BulkOperateItemType[]; + count: number; + className?: string; +}; -export function BulkOperateBar({ list, count }: BulkOperateBarProps) { +export function BulkOperateBar({ + list, + count, + className, +}: BulkOperateBarProps) { const isDeleteItem = useCallback((id: string) => { return id === 'delete'; }, []); return ( - +
Selected: {count} Files @@ -32,7 +40,7 @@ export function BulkOperateBar({ list, count }: BulkOperateBarProps) { {list.map((x) => (