2626from openai import OpenAI
2727from openai .types .chat import ChatCompletionMessageParam
2828
29- from consts .const import ES_API_KEY , ES_HOST , LANGUAGE , MODEL_CONFIG_MAPPING
29+ from consts .const import ES_API_KEY , ES_HOST , LANGUAGE , MODEL_CONFIG_MAPPING , MESSAGE_ROLE , KNOWLEDGE_SUMMARY_MAX_TOKENS_ZH , KNOWLEDGE_SUMMARY_MAX_TOKENS_EN
3030from database .attachment_db import delete_file
3131from database .knowledge_db import (
3232 create_knowledge_record ,
@@ -69,8 +69,8 @@ def generate_knowledge_summary_stream(keywords: str, language: str, tenant_id: s
6969
7070 # Build messages
7171 messages : List [ChatCompletionMessageParam ] = [
72- {"role" : "system" , "content" : system_prompt },
73- {"role" : "user" , "content" : user_prompt }
72+ {"role" : MESSAGE_ROLE [ "SYSTEM" ] , "content" : system_prompt },
73+ {"role" : MESSAGE_ROLE [ "USER" ] , "content" : user_prompt }
7474 ]
7575
7676 # Get model configuration from tenant config manager
@@ -83,7 +83,7 @@ def generate_knowledge_summary_stream(keywords: str, language: str, tenant_id: s
8383
8484 try :
8585 # Create stream chat completion request
86- max_tokens = 300 if language == LANGUAGE ["ZH" ] else 120
86+ max_tokens = KNOWLEDGE_SUMMARY_MAX_TOKENS_ZH if language == LANGUAGE ["ZH" ] else KNOWLEDGE_SUMMARY_MAX_TOKENS_EN
8787 stream = client .chat .completions .create (
8888 model = get_model_name_from_config (model_config ) if model_config .get (
8989 "model_name" ) else "" , # use model name from config
0 commit comments