mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-01-29 21:51:31 +00:00
perf: chat ai custom model (#16428)
This commit is contained in:
@@ -42,16 +42,22 @@ class ChatAITestingAPI(GenericAPIView):
|
||||
)
|
||||
|
||||
tp = config['CHAT_AI_TYPE']
|
||||
is_custom_model = config['IS_CUSTOM_MODEL']
|
||||
if tp == ChatAITypeChoices.gpt:
|
||||
url = config['GPT_BASE_URL']
|
||||
api_key = config['GPT_API_KEY']
|
||||
proxy = config['GPT_PROXY']
|
||||
model = config['GPT_MODEL']
|
||||
custom_model = config['CUSTOM_GPT_MODEL']
|
||||
else:
|
||||
url = config['DEEPSEEK_BASE_URL']
|
||||
api_key = config['DEEPSEEK_API_KEY']
|
||||
proxy = config['DEEPSEEK_PROXY']
|
||||
model = config['DEEPSEEK_MODEL']
|
||||
custom_model = config['CUSTOM_DEEPSEEK_MODEL']
|
||||
|
||||
model = custom_model or model \
|
||||
if is_custom_model else model
|
||||
|
||||
kwargs = {
|
||||
'base_url': url or None,
|
||||
|
||||
@@ -19,11 +19,23 @@ class ChatAITypeChoices(TextChoices):
|
||||
|
||||
|
||||
class GPTModelChoices(TextChoices):
|
||||
gpt_4o_mini = 'gpt-4o-mini', 'gpt-4o-mini'
|
||||
gpt_4o = 'gpt-4o', 'gpt-4o'
|
||||
o3_mini = 'o3-mini', 'o3-mini'
|
||||
o1_mini = 'o1-mini', 'o1-mini'
|
||||
o1 = 'o1', 'o1'
|
||||
# 🚀 Latest flagship dialogue model
|
||||
GPT_5_2 = 'gpt-5.2', 'gpt-5.2'
|
||||
GPT_5_2_PRO = 'gpt-5.2-pro', 'gpt-5.2-pro'
|
||||
|
||||
GPT_5_1 = 'gpt-5.1', 'gpt-5.1'
|
||||
GPT_5 = 'gpt-5', 'gpt-5'
|
||||
|
||||
# 💡 Lightweight & Cost-Friendly Version
|
||||
GPT_5_MINI = 'gpt-5-mini', 'gpt-5-mini'
|
||||
GPT_5_NANO = 'gpt-5-nano', 'gpt-5-nano'
|
||||
|
||||
# 🧠 GPT-4 series of dialogues (still supports chat tasks)
|
||||
GPT_4O = 'gpt-4o', 'gpt-4o'
|
||||
GPT_4O_MINI = 'gpt-4o-mini', 'gpt-4o-mini'
|
||||
GPT_4_1 = 'gpt-4.1', 'gpt-4.1'
|
||||
GPT_4_1_MINI = 'gpt-4.1-mini', 'gpt-4.1-mini'
|
||||
GPT_4_1_NANO = 'gpt-4.1-nano', 'gpt-4.1-nano'
|
||||
|
||||
|
||||
class DeepSeekModelChoices(TextChoices):
|
||||
|
||||
@@ -203,12 +203,16 @@ def get_chatai_data():
|
||||
'proxy': settings.GPT_PROXY,
|
||||
'model': settings.GPT_MODEL,
|
||||
}
|
||||
custom_model = settings.CUSTOM_GPT_MODEL
|
||||
if settings.CHAT_AI_TYPE != ChatAITypeChoices.gpt:
|
||||
data['url'] = settings.DEEPSEEK_BASE_URL
|
||||
data['api_key'] = settings.DEEPSEEK_API_KEY
|
||||
data['proxy'] = settings.DEEPSEEK_PROXY
|
||||
data['model'] = settings.DEEPSEEK_MODEL
|
||||
custom_model = settings.CUSTOM_DEEPSEEK_MODEL
|
||||
|
||||
data['model'] = custom_model or data['model'] \
|
||||
if settings.IS_CUSTOM_MODEL else data['model']
|
||||
return data
|
||||
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ class ChatAISettingSerializer(serializers.Serializer):
|
||||
help_text=_('The proxy server address of the GPT service. For example: http://ip:port')
|
||||
)
|
||||
GPT_MODEL = serializers.ChoiceField(
|
||||
default=GPTModelChoices.gpt_4o_mini, choices=GPTModelChoices.choices,
|
||||
default=GPTModelChoices.GPT_4_1_MINI, choices=GPTModelChoices.choices,
|
||||
label=_("GPT Model"), required=False,
|
||||
)
|
||||
DEEPSEEK_BASE_URL = serializers.CharField(
|
||||
@@ -168,6 +168,18 @@ class ChatAISettingSerializer(serializers.Serializer):
|
||||
default=DeepSeekModelChoices.deepseek_chat, choices=DeepSeekModelChoices.choices,
|
||||
label=_("DeepSeek Model"), required=False,
|
||||
)
|
||||
IS_CUSTOM_MODEL = serializers.BooleanField(
|
||||
required=False, default=False, label=_("Custom Model"),
|
||||
help_text=_("Whether to use a custom model")
|
||||
)
|
||||
CUSTOM_GPT_MODEL = serializers.CharField(
|
||||
max_length=256, allow_blank=True,
|
||||
required=False, label=_('Custom gpt model'),
|
||||
)
|
||||
CUSTOM_DEEPSEEK_MODEL = serializers.CharField(
|
||||
max_length=256, allow_blank=True,
|
||||
required=False, label=_('Custom DeepSeek model'),
|
||||
)
|
||||
|
||||
|
||||
class TicketSettingSerializer(serializers.Serializer):
|
||||
|
||||
Reference in New Issue
Block a user