Signed-off-by: -LAN- <laipz8200@outlook.com>tags/0.6.16
| create_count = 0 | create_count = 0 | ||||
| skipped_count = 0 | skipped_count = 0 | ||||
| total_count = 0 | total_count = 0 | ||||
| config = current_app.config | |||||
| vector_type = config.get('VECTOR_STORE') | |||||
| vector_type = dify_config.VECTOR_STORE | |||||
| page = 1 | page = 1 | ||||
| while True: | while True: | ||||
| try: | try: | ||||
| @click.option('--field', default='metadata.doc_id', prompt=False, help='index field , default is metadata.doc_id.') | @click.option('--field', default='metadata.doc_id', prompt=False, help='index field , default is metadata.doc_id.') | ||||
| def add_qdrant_doc_id_index(field: str): | def add_qdrant_doc_id_index(field: str): | ||||
| click.echo(click.style('Start add qdrant doc_id index.', fg='green')) | click.echo(click.style('Start add qdrant doc_id index.', fg='green')) | ||||
| config = current_app.config | |||||
| vector_type = config.get('VECTOR_STORE') | |||||
| vector_type = dify_config.VECTOR_STORE | |||||
| if vector_type != "qdrant": | if vector_type != "qdrant": | ||||
| click.echo(click.style('Sorry, only support qdrant vector store.', fg='red')) | click.echo(click.style('Sorry, only support qdrant vector store.', fg='red')) | ||||
| return | return | ||||
| from core.rag.datasource.vdb.qdrant.qdrant_vector import QdrantConfig | from core.rag.datasource.vdb.qdrant.qdrant_vector import QdrantConfig | ||||
| for binding in bindings: | for binding in bindings: | ||||
| if dify_config.QDRANT_URL is None: | |||||
| raise ValueError('Qdrant url is required.') | |||||
| qdrant_config = QdrantConfig( | qdrant_config = QdrantConfig( | ||||
| endpoint=config.get('QDRANT_URL'), | |||||
| api_key=config.get('QDRANT_API_KEY'), | |||||
| endpoint=dify_config.QDRANT_URL, | |||||
| api_key=dify_config.QDRANT_API_KEY, | |||||
| root_path=current_app.root_path, | root_path=current_app.root_path, | ||||
| timeout=config.get('QDRANT_CLIENT_TIMEOUT'), | |||||
| grpc_port=config.get('QDRANT_GRPC_PORT'), | |||||
| prefer_grpc=config.get('QDRANT_GRPC_ENABLED') | |||||
| timeout=dify_config.QDRANT_CLIENT_TIMEOUT, | |||||
| grpc_port=dify_config.QDRANT_GRPC_PORT, | |||||
| prefer_grpc=dify_config.QDRANT_GRPC_ENABLED | |||||
| ) | ) | ||||
| try: | try: | ||||
| client = qdrant_client.QdrantClient(**qdrant_config.to_qdrant_params()) | client = qdrant_client.QdrantClient(**qdrant_config.to_qdrant_params()) |
| # AccountService.update_password(account, new_password) | # AccountService.update_password(account, new_password) | ||||
| # todo: Send email | # todo: Send email | ||||
| # MAILCHIMP_API_KEY = current_app.config['MAILCHIMP_TRANSACTIONAL_API_KEY'] | |||||
| # MAILCHIMP_API_KEY = dify_config.MAILCHIMP_TRANSACTIONAL_API_KEY | |||||
| # mailchimp = MailchimpTransactional(MAILCHIMP_API_KEY) | # mailchimp = MailchimpTransactional(MAILCHIMP_API_KEY) | ||||
| # message = { | # message = { | ||||
| # 'message': message, | # 'message': message, | ||||
| # # required for transactional email | # # required for transactional email | ||||
| # ' settings': { | # ' settings': { | ||||
| # 'sandbox_mode': current_app.config['MAILCHIMP_SANDBOX_MODE'], | |||||
| # 'sandbox_mode': dify_config.MAILCHIMP_SANDBOX_MODE, | |||||
| # }, | # }, | ||||
| # }) | # }) | ||||
| from flask_login import current_user | from flask_login import current_user | ||||
| from sqlalchemy.orm.exc import ObjectDeletedError | from sqlalchemy.orm.exc import ObjectDeletedError | ||||
| from configs import dify_config | |||||
| from core.errors.error import ProviderTokenNotInitError | from core.errors.error import ProviderTokenNotInitError | ||||
| from core.llm_generator.llm_generator import LLMGenerator | from core.llm_generator.llm_generator import LLMGenerator | ||||
| from core.model_manager import ModelInstance, ModelManager | from core.model_manager import ModelInstance, ModelManager | ||||
| features = FeatureService.get_features(tenant_id) | features = FeatureService.get_features(tenant_id) | ||||
| if features.billing.enabled: | if features.billing.enabled: | ||||
| count = len(extract_settings) | count = len(extract_settings) | ||||
| batch_upload_limit = int(current_app.config['BATCH_UPLOAD_LIMIT']) | |||||
| batch_upload_limit = dify_config.BATCH_UPLOAD_LIMIT | |||||
| if count > batch_upload_limit: | if count > batch_upload_limit: | ||||
| raise ValueError(f"You have reached the batch upload limit of {batch_upload_limit}.") | raise ValueError(f"You have reached the batch upload limit of {batch_upload_limit}.") | ||||
| # The user-defined segmentation rule | # The user-defined segmentation rule | ||||
| rules = json.loads(processing_rule.rules) | rules = json.loads(processing_rule.rules) | ||||
| segmentation = rules["segmentation"] | segmentation = rules["segmentation"] | ||||
| max_segmentation_tokens_length = int(current_app.config['INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH']) | |||||
| max_segmentation_tokens_length = dify_config.INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH | |||||
| if segmentation["max_tokens"] < 50 or segmentation["max_tokens"] > max_segmentation_tokens_length: | if segmentation["max_tokens"] < 50 or segmentation["max_tokens"] > max_segmentation_tokens_length: | ||||
| raise ValueError(f"Custom segment length should be between 50 and {max_segmentation_tokens_length}.") | raise ValueError(f"Custom segment length should be between 50 and {max_segmentation_tokens_length}.") | ||||
| from collections import defaultdict | from collections import defaultdict | ||||
| from typing import Any, Optional | from typing import Any, Optional | ||||
| from flask import current_app | |||||
| from pydantic import BaseModel | from pydantic import BaseModel | ||||
| from configs import dify_config | |||||
| from core.rag.datasource.keyword.jieba.jieba_keyword_table_handler import JiebaKeywordTableHandler | from core.rag.datasource.keyword.jieba.jieba_keyword_table_handler import JiebaKeywordTableHandler | ||||
| from core.rag.datasource.keyword.keyword_base import BaseKeyword | from core.rag.datasource.keyword.keyword_base import BaseKeyword | ||||
| from core.rag.models.document import Document | from core.rag.models.document import Document | ||||
| if keyword_table_dict: | if keyword_table_dict: | ||||
| return keyword_table_dict['__data__']['table'] | return keyword_table_dict['__data__']['table'] | ||||
| else: | else: | ||||
| keyword_data_source_type = current_app.config['KEYWORD_DATA_SOURCE_TYPE'] | |||||
| keyword_data_source_type = dify_config.KEYWORD_DATA_SOURCE_TYPE | |||||
| dataset_keyword_table = DatasetKeywordTable( | dataset_keyword_table = DatasetKeywordTable( | ||||
| dataset_id=self.dataset.id, | dataset_id=self.dataset.id, | ||||
| keyword_table='', | keyword_table='', |
| import jwt | import jwt | ||||
| from flask import current_app | |||||
| from werkzeug.exceptions import Unauthorized | from werkzeug.exceptions import Unauthorized | ||||
| from configs import dify_config | |||||
| class PassportService: | class PassportService: | ||||
| def __init__(self): | def __init__(self): | ||||
| self.sk = current_app.config.get('SECRET_KEY') | |||||
| self.sk = dify_config.SECRET_KEY | |||||
| def issue(self, payload): | def issue(self, payload): | ||||
| return jwt.encode(payload, self.sk, algorithm='HS256') | return jwt.encode(payload, self.sk, algorithm='HS256') | ||||
| def verify(self, token): | def verify(self, token): | ||||
| try: | try: | ||||
| return jwt.decode(token, self.sk, algorithms=['HS256']) | return jwt.decode(token, self.sk, algorithms=['HS256']) |