mirror of
				https://github.com/langgenius/dify.git
				synced 2025-11-04 04:43:09 +00:00 
			
		
		
		
	Co-authored-by: StyleZhang <jasonapring2015@outlook.com> Co-authored-by: Garfield Dai <dai.hai@foxmail.com> Co-authored-by: chenhe <guchenhe@gmail.com> Co-authored-by: jyong <jyong@dify.ai> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Yeuoly <admin@srmxy.cn>
		
			
				
	
	
		
			57 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# -*- coding:utf-8 -*-
 | 
						|
 | 
						|
from flask import request
 | 
						|
from flask_restful import Resource
 | 
						|
from flask_login import current_user
 | 
						|
 | 
						|
from controllers.console import api
 | 
						|
from controllers.console.app import _get_app
 | 
						|
from controllers.console.setup import setup_required
 | 
						|
from controllers.console.wraps import account_initialization_required
 | 
						|
from libs.login import login_required
 | 
						|
from events.app_event import app_model_config_was_updated
 | 
						|
from extensions.ext_database import db
 | 
						|
from models.model import AppModelConfig
 | 
						|
from services.app_model_config_service import AppModelConfigService
 | 
						|
 | 
						|
 | 
						|
class ModelConfigResource(Resource):
 | 
						|
 | 
						|
    @setup_required
 | 
						|
    @login_required
 | 
						|
    @account_initialization_required
 | 
						|
    def post(self, app_id):
 | 
						|
        """Modify app model config"""
 | 
						|
        app_id = str(app_id)
 | 
						|
 | 
						|
        app = _get_app(app_id)
 | 
						|
 | 
						|
        # validate config
 | 
						|
        model_configuration = AppModelConfigService.validate_configuration(
 | 
						|
            tenant_id=current_user.current_tenant_id,
 | 
						|
            account=current_user,
 | 
						|
            config=request.json,
 | 
						|
            app_mode=app.mode
 | 
						|
        )
 | 
						|
 | 
						|
        new_app_model_config = AppModelConfig(
 | 
						|
            app_id=app.id,
 | 
						|
        )
 | 
						|
        new_app_model_config = new_app_model_config.from_model_config_dict(model_configuration)
 | 
						|
 | 
						|
        db.session.add(new_app_model_config)
 | 
						|
        db.session.flush()
 | 
						|
 | 
						|
        app.app_model_config_id = new_app_model_config.id
 | 
						|
        db.session.commit()
 | 
						|
 | 
						|
        app_model_config_was_updated.send(
 | 
						|
            app,
 | 
						|
            app_model_config=new_app_model_config
 | 
						|
        )
 | 
						|
 | 
						|
        return {'result': 'success'}
 | 
						|
 | 
						|
 | 
						|
api.add_resource(ModelConfigResource, '/apps/<uuid:app_id>/model-config')
 |