Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/models_provider/constants/model_provider_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from models_provider.impl.xinference_model_provider.xinference_model_provider import XinferenceModelProvider
from models_provider.impl.minimax_model_provider.minimax_model_provider import MiniMaxModelProvider
from models_provider.impl.zhipu_model_provider.zhipu_model_provider import ZhiPuModelProvider
from models_provider.impl.webwright_model_provider.webwright_model_provider import WebWrightModelProvider


class ModelProvideConstants(Enum):
Expand All @@ -48,3 +49,4 @@ class ModelProvideConstants(Enum):
model_siliconCloud_provider = SiliconCloudModelProvider()
model_regolo_provider = RegoloModelProvider()
model_minimax_provider = MiniMaxModelProvider()
model_webwright_provider = WebWrightModelProvider()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project :MaxKB
@File :__init__.py
@Desc :WebWright model provider package
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# coding=utf-8
"""
@project: MaxKB
@file: llm.py
@desc: WebWright LLM credential. WebWright is OpenAI-compatible, so the
credential is an API base URL and an API key.
"""
from typing import Dict

from django.utils.translation import gettext_lazy as _, gettext
from langchain_core.messages import HumanMessage

from common import forms
from common.exception.app_exception import AppApiException
from common.forms import BaseForm, TooltipLabel
from models_provider.base_model_provider import BaseModelCredential, ValidCode
from common.utils.logger import maxkb_logger


class WebWrightLLMModelParams(BaseForm):
temperature = forms.SliderField(
TooltipLabel(_('Temperature'),
_('Higher values make the output more random, while lower values make it more focused and deterministic')),
required=True, default_value=0.7, _min=0.1, _max=1.0, _step=0.01, precision=2)

max_tokens = forms.SliderField(
TooltipLabel(_('Output the maximum Tokens'),
_('Specify the maximum number of tokens that the model can generate')),
required=True, default_value=8192, _min=1, _max=100000, _step=1, precision=0)


class WebWrightLLMModelCredential(BaseForm, BaseModelCredential):

def is_valid(self, model_type: str, model_name, model_credential: Dict[str, object], model_params, provider,
raise_exception=False):
model_type_list = provider.get_model_type_list()
if not any(list(filter(lambda mt: mt.get('value') == model_type, model_type_list))):
raise AppApiException(ValidCode.valid_error.value,
gettext('{model_type} Model type is not supported').format(model_type=model_type))

for key in ['api_base', 'api_key']:
if key not in model_credential:
if raise_exception:
raise AppApiException(ValidCode.valid_error.value, gettext('{key} is required').format(key=key))
else:
return False
try:
model = provider.get_model(model_type, model_name, model_credential, **model_params)
model.invoke([HumanMessage(content=gettext('Hello'))])
except Exception as e:
maxkb_logger.error(f'Exception: {e}', exc_info=True)
if isinstance(e, AppApiException):
raise e
if raise_exception:
raise AppApiException(ValidCode.valid_error.value,
gettext(
'Verification failed, please check whether the parameters are correct: {error}').format(
error=str(e)))
else:
return False
return True

def encryption_dict(self, model: Dict[str, object]):
return {**model, 'api_key': super().encryption(model.get('api_key', ''))}

api_base = forms.TextInputField(_('API URL'), required=True, default_value='https://webwright.ai/v1')
api_key = forms.PasswordInputField('API Key', required=True)

def get_model_params_setting_form(self, model_name):
return WebWrightLLMModelParams()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<defs>
<style>
.cls-1 {
fill: #fff;
}

.cls-2 {
fill: #243e8e;
}
</style>
<clipPath id="rounded-corners">
<rect width="32" height="32" rx="4" ry="4"/>
</clipPath>
</defs>
<g clip-path="url(#rounded-corners)">
<g id="WHITE_BACK" data-name="WHITE BACK">
<rect class="cls-1" y="-.77" width="32.77" height="32.77"/>
</g>
<g id="Favicons">
<g id="Version_1" data-name="Version 1">
<path class="cls-2" d="M8.91,17.5c-.02-1.52.11-3,.46-4.47l13.83-4.13c-2.71,3.2-2.01,8,1.56,10.28l-5.79.49-10.07-2.17Z"/>
<path class="cls-2" d="M30.85,23.56c-.62,1.56-1.54,2.9-2.59,4.12-1.9,1.8-4.25,2.91-6.84,3.26-1.51.2-3.03.28-4.55.17-1.44-.1-3.19-.68-2.96-2.37-1.38,1.7-3.4,2.93-5.53,2.05-.85-.35-1.65-.81-2.36-1.42-1.65-1.45-2.94-3.29-3.82-5.32,2.28,2.35,5.08,3.79,8.34,3.62.56,0,1.05-.28,1.49-.61l-.79-.86c-.71-.76-.98-1.78-1.29-2.78-.36-.22-.68-.54-.89-1.01-.34.86-.19,1.75.17,2.56-.48-.63-.9-1.28-1.29-1.97l-.05-1.58c-.01-.3.03-.56.13-.86l-6.85-2.81.46-1.13,6.61,1.92.69.2h.05s0,.01,0,.01l11.32,2.44c.86.22,1.71.46,2.57.73.87.27,1.69.54,2.49.98.14.36.07.74,0,1.11l-.16.9c-.03.17-.04.33-.21.4.05-.45,0-.93-.11-1.37-.5-.24-.99-.41-1.53-.56-2.13-.6-4.26-1.14-6.45-1.46-1.65-.24-3.28-.25-4.92.06-.98,1.4.06,3.2,1.07,4.43.78-.71,1.51-1.33,2.33-1.91.58-.41,1.21-.64,1.93-.64-1.2.94-1.49,3.25-.36,3.98.59.38,1.26.46,1.94.42,1.09-.07,2.11-.27,3.19-.49l2.89-.73c2.29-.58,4.24-1.73,5.89-3.49Z"/>
<path class="cls-2" d="M10.72,10.43c-.2.06-.32.19-.48.19.72-1.57,1.56-3.01,2.45-4.45l8.18-2.44c-.59.51-.89,1.17-.81,1.92.08.68.49,1.29,1.15,1.65l-10.49,3.14Z"/>
<path class="cls-2" d="M7.16,17.15c-1.14-.7-2.2-1.58-2.92-2.7-.86-1.34-.81-2.85.2-4.09,1.39-1.71,3.58-2.75,5.66-3.57-.74,1.29-1.5,2.49-1.95,3.88-.68,2.08-.9,4.24-.98,6.48Z"/>
<path class="cls-2" d="M29.96,4.68c-.12-.53-.4-.81-.91-.94-.63-.16-1.25.03-1.82.32-.92.49-1.85.59-2.88.66-.74.05-1.53-.3-1.89-1.01-.17-.35-.11-.81-.22-1.2-.62-.11-1.22.03-1.84.13-1.5.31-2.93.78-4.39,1.3V1.74c.88-.31,1.77-.56,2.71-.73,1.36-.25,2.72-.24,4.06.04.37.26.36.69.12,1.06-.13.15-.24.33-.2.53.12.65,1.37.7,2.26.19.51-.29.99-.48,1.58-.55,1.18-.13,2.41-.1,3.11.91.29.44.53.93.3,1.5Z"/>
</g>
</g>
</g>
</svg>
Empty file.
29 changes: 29 additions & 0 deletions apps/models_provider/impl/webwright_model_provider/model/llm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# coding=utf-8
"""
@project: MaxKB
@file: llm.py
@desc: WebWright chat model. WebWright exposes an OpenAI-compatible
/v1/chat/completions endpoint, so this model reuses the shared
BaseChatOpenAI implementation.
"""
from typing import Dict

from models_provider.base_model_provider import MaxKBBaseModel
from models_provider.impl.base_chat_open_ai import BaseChatOpenAI


class WebWrightChatModel(MaxKBBaseModel, BaseChatOpenAI):

@staticmethod
def is_cache_model():
return False

@staticmethod
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
optional_params = MaxKBBaseModel.filter_optional_params(model_kwargs)
return WebWrightChatModel(
model=model_name,
openai_api_base=model_credential.get('api_base') or 'https://webwright.ai/v1',
openai_api_key=model_credential.get('api_key'),
**optional_params,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# coding=utf-8
"""
@project: MaxKB
@file: webwright_model_provider.py
@desc: WebWright provider. WebWright serves an OpenAI-compatible chat
completions API at https://webwright.ai/v1 with the Wren R1 model.
"""
import os

from common.utils.common import get_file_content
from models_provider.base_model_provider import (
IModelProvider,
ModelProvideInfo,
ModelInfo,
ModelTypeConst,
ModelInfoManage,
)
from models_provider.impl.webwright_model_provider.credential.llm import WebWrightLLMModelCredential
from models_provider.impl.webwright_model_provider.model.llm import WebWrightChatModel
from maxkb.conf import PROJECT_DIR

webwright_llm_model_credential = WebWrightLLMModelCredential()
webwright_llm_list = [
ModelInfo('wren-r1', '', ModelTypeConst.LLM, webwright_llm_model_credential, WebWrightChatModel),
]

model_info_manage = (
ModelInfoManage.builder()
.append_model_info_list(webwright_llm_list)
.append_default_model_info(webwright_llm_list[0])
.build()
)


class WebWrightModelProvider(IModelProvider):
def get_model_info_manage(self):
return model_info_manage

def get_model_provide_info(self):
return ModelProvideInfo(
provider='model_webwright_provider',
name='WebWright',
icon=get_file_content(
os.path.join(
PROJECT_DIR,
"apps",
"models_provider",
"impl",
"webwright_model_provider",
"icon",
"webwright_icon_svg",
)
),
)
7 changes: 6 additions & 1 deletion ui/src/components/dynamics-form/items/model/provider-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,10 @@ export const providerList = [
"provider": "model_minimax_provider",
"name": "MiniMax",
"icon": "<svg t=\"1776929669814\" class=\"icon\" viewBox=\"0 0 1169 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"4810\" width=\"100%\" height=\"100%\"><path d=\"M474.173841 470.682521V847.403039c-25.441562 127.572805-194.68465 94.674371-195.416638 2.192962-0.802986-116.24 0-231.750012 0-347.113027V368.697276c0-16.740712-3.654937-29.973484-18.275685-40.428305-28.512509-21.346633-62.725921 3.728936-63.456908 34.507407-1.608972 41.305289-0.804986 81.733594-1.608973 122.453893 0 32.167446 0 63.384909 0.730988 95.478357C175.164986 722.025196 3.947932 698.5576 0 581.512614V483.5493c0-32.021449 62.725921-39.551319 59.655973 8.406855-2.046965 23.759591-0.731987 48.25117-1.535973 71.791765-0.729987 42.036277 63.530907 70.32879 78.663646 1.607972 0.730987-56.658025 0.730987-113.31605 0.730988-170.486067 0-71.644767 20.32365-129.984763 96.282343-135.39467 32.898434-2.92395 54.757058 10.819814 75.738697 34.579405 8.042862 8.407855 27.049535 35.092396 27.781522 64.115897 0 26.75754 0.729987 53.368082 0.729987 80.418616 0 53.367082-0.729987 107.028158-0.729987 160.39724 0 34.579405 0.729987 68.792816 0.729987 102.568235 0 42.841263 0 86.267516-0.729987 129.180778-0.730987 55.78104 67.111845 54.977054 78.005658-0.876985 0-65.796868 0.729987-130.78875 0.729987-196.585618 0-162.078211-0.729987-324.157422-0.729987-486.163634 0-16.814711-2.33996-63.456908 6.579886-80.417617C469.274925-48.744541 613.003452 1.625592 614.319429 97.176948c2.777952 195.781631 0 393.756225 0.730988 589.975848 0 68.062829-55.269049 53.44208-58.338996 26.830538 0-204.188487 0-409.180959 0.729987-613.07745-2.703953-51.175119-78.589648-44.229239-82.976572-7.529871-1.461975 42.109275-0.729987 84.950538-1.461975 126.987815v250.025698h0.730987l0.511992 0.292995z\" fill=\"#D4367A\" p-id=\"4811\"></path><path d=\"M696.347018 467.684573v276.638239-652.848766c24.709575-128.44779 193.880664-95.038365 194.611651-2.484957 0.803986 115.437014 0 231.677014 0.803986 347.040028 0 44.303238 0 88.752473-0.730987 133.055711 0 17.545698 4.312926 29.900486 19.007673 41.159292 27.780522 20.835641 61.921935-3.654937 63.456908-34.945399 1.535974-40.501303 0.731987-81.002606 0.731987-122.527892v-94.893367c21.200635-141.315568 191.906698-117.847972 195.488637-0.803986V711.645375c0 32.166447-61.994933 39.769316-59.216981-8.334857 1.680971-24.490579 0-304.930753 0.876985-329.49433 1.461975-41.305289-63.602906-70.402789-78.663647-0.876985v169.609081c0 72.66875-20.396649 130.057762-97.013331 136.271656-72.228757 1.680971-101.253258-48.25117-103.593217-98.695302V237.250538c0-43.645249 0-86.266516 0.731987-129.107779 0.729987-55.78004-67.112845-55.78004-78.663646 0.804986v767.626792c0 16.667713 2.33996 63.383909-5.921898 80.417616-47.300186 115.363015-191.7607 64.918883-193.076678-30.559474v-90.871437c3.582938-61.190947 55.269049-46.643197 57.609009-20.762642V922.631744c2.777952 51.321117 78.663646 45.107224 82.245585 7.602869 1.534974-42.109275 1.534974-84.146552 1.534973-127.059813V467.757571h-0.219996v-0.072998z\" fill=\"#ED6D48\" p-id=\"4812\"></path></svg>"
}
},
{
"provider": "model_webwright_provider",
"name": "WebWright",
"icon": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\">\n <defs>\n <style>\n .cls-1 {\n fill: #fff;\n }\n\n .cls-2 {\n fill: #243e8e;\n }\n </style>\n <clipPath id=\"rounded-corners\">\n <rect width=\"32\" height=\"32\" rx=\"4\" ry=\"4\"/>\n </clipPath>\n </defs>\n <g clip-path=\"url(#rounded-corners)\">\n <g id=\"WHITE_BACK\" data-name=\"WHITE BACK\">\n <rect class=\"cls-1\" y=\"-.77\" width=\"32.77\" height=\"32.77\"/>\n </g>\n <g id=\"Favicons\">\n <g id=\"Version_1\" data-name=\"Version 1\">\n <path class=\"cls-2\" d=\"M8.91,17.5c-.02-1.52.11-3,.46-4.47l13.83-4.13c-2.71,3.2-2.01,8,1.56,10.28l-5.79.49-10.07-2.17Z\"/>\n <path class=\"cls-2\" d=\"M30.85,23.56c-.62,1.56-1.54,2.9-2.59,4.12-1.9,1.8-4.25,2.91-6.84,3.26-1.51.2-3.03.28-4.55.17-1.44-.1-3.19-.68-2.96-2.37-1.38,1.7-3.4,2.93-5.53,2.05-.85-.35-1.65-.81-2.36-1.42-1.65-1.45-2.94-3.29-3.82-5.32,2.28,2.35,5.08,3.79,8.34,3.62.56,0,1.05-.28,1.49-.61l-.79-.86c-.71-.76-.98-1.78-1.29-2.78-.36-.22-.68-.54-.89-1.01-.34.86-.19,1.75.17,2.56-.48-.63-.9-1.28-1.29-1.97l-.05-1.58c-.01-.3.03-.56.13-.86l-6.85-2.81.46-1.13,6.61,1.92.69.2h.05s0,.01,0,.01l11.32,2.44c.86.22,1.71.46,2.57.73.87.27,1.69.54,2.49.98.14.36.07.74,0,1.11l-.16.9c-.03.17-.04.33-.21.4.05-.45,0-.93-.11-1.37-.5-.24-.99-.41-1.53-.56-2.13-.6-4.26-1.14-6.45-1.46-1.65-.24-3.28-.25-4.92.06-.98,1.4.06,3.2,1.07,4.43.78-.71,1.51-1.33,2.33-1.91.58-.41,1.21-.64,1.93-.64-1.2.94-1.49,3.25-.36,3.98.59.38,1.26.46,1.94.42,1.09-.07,2.11-.27,3.19-.49l2.89-.73c2.29-.58,4.24-1.73,5.89-3.49Z\"/>\n <path class=\"cls-2\" d=\"M10.72,10.43c-.2.06-.32.19-.48.19.72-1.57,1.56-3.01,2.45-4.45l8.18-2.44c-.59.51-.89,1.17-.81,1.92.08.68.49,1.29,1.15,1.65l-10.49,3.14Z\"/>\n <path class=\"cls-2\" d=\"M7.16,17.15c-1.14-.7-2.2-1.58-2.92-2.7-.86-1.34-.81-2.85.2-4.09,1.39-1.71,3.58-2.75,5.66-3.57-.74,1.29-1.5,2.49-1.95,3.88-.68,2.08-.9,4.24-.98,6.48Z\"/>\n <path class=\"cls-2\" d=\"M29.96,4.68c-.12-.53-.4-.81-.91-.94-.63-.16-1.25.03-1.82.32-.92.49-1.85.59-2.88.66-.74.05-1.53-.3-1.89-1.01-.17-.35-.11-.81-.22-1.2-.62-.11-1.22.03-1.84.13-1.5.31-2.93.78-4.39,1.3V1.74c.88-.31,1.77-.56,2.71-.73,1.36-.25,2.72-.24,4.06.04.37.26.36.69.12,1.06-.13.15-.24.33-.2.53.12.65,1.37.7,2.26.19.51-.29.99-.48,1.58-.55,1.18-.13,2.41-.1,3.11.91.29.44.53.93.3,1.5Z\"/>\n </g>\n </g>\n </g>\n</svg>"
}
]