| | |
| | | DF_CHAT_WORKFLOW |
| | | from app.config.config import settings |
| | | from app.config.const import * |
| | | from app.models import DialogModel, ApiTokenModel |
| | | from app.models import DialogModel, ApiTokenModel, UserTokenModel |
| | | from app.models.v2.session_model import ChatSessionDao, ChatData |
| | | from app.service.v2.app_driver.chat_agent import ChatAgent |
| | | from app.service.v2.app_driver.chat_data import ChatBaseApply |
| | |
| | | logger.error(e) |
| | | return None |
| | | |
| | | async def get_app_token(db, app_id): |
| | | app_token = db.query(UserTokenModel).filter_by(id=app_id).first() |
| | | if app_token: |
| | | return app_token.access_token |
| | | return "" |
| | | |
| | | |
| | | |
| | | async def get_chat_token(db, app_id): |
| | | app_token = db.query(ApiTokenModel).filter_by(app_id=app_id).first() |
| | | if app_token: |
| | | return app_token.token |
| | | return "" |
| | | |
| | | |
| | | async def add_chat_token(db, data): |
| | | try: |
| | | api_token = ApiTokenModel(**data) |
| | | db.add(api_token) |
| | | db.commit() |
| | | except Exception as e: |
| | | logger.error(e) |
| | | |
| | | |
| | | |
| | | async def get_chat_info(db, chat_id: str): |
| | |
| | | logger.error(e) |
| | | try: |
| | | yield "data: " + json.dumps({"message": smart_message_error, |
| | | "error": "**ERROR**: " + str(e), "status": http_500}, |
| | | "error": "\n**ERROR**: " + str(e), "status": http_500}, |
| | | ensure_ascii=False) + "\n\n" |
| | | except: |
| | | ... |
| | |
| | | data = ans.get("data", {}) |
| | | event = smart_workflow_finished |
| | | node_list.append(ans) |
| | | |
| | | elif ans.get("event") == message_end: |
| | | event = smart_message_end |
| | | else: |
| | |
| | | logger.error(e) |
| | | try: |
| | | yield "data: " + json.dumps({"message": smart_message_error, |
| | | "error": "**ERROR**: " + str(e), "status": http_500}, |
| | | "error": "\n**ERROR**: " + str(e), "status": http_500}, |
| | | ensure_ascii=False) + "\n\n" |
| | | except: |
| | | ... |
| | |
| | | "error": error}, conversation_id) |
| | | |
| | | |
| | | async def service_chat_basic(db, chat_id: str, question: str, session_id: str, user_id): |
| | | async def service_chat_basic(db, chat_id: str, chat_data: ChatData, session_id: str, user_id, mode: str): |
| | | ... |
| | | |
| | | |