|
|
|
|
@ -28,7 +28,10 @@ from core.model_runtime.entities.common_entities import I18nObject
|
|
|
|
|
from core.model_runtime.entities.llm_entities import LLMMode, LLMResult, LLMResultChunk, LLMResultChunkDelta
|
|
|
|
|
from core.model_runtime.entities.message_entities import (
|
|
|
|
|
AssistantPromptMessage,
|
|
|
|
|
ImagePromptMessageContent,
|
|
|
|
|
PromptMessage,
|
|
|
|
|
PromptMessageContent,
|
|
|
|
|
PromptMessageContentType,
|
|
|
|
|
PromptMessageTool,
|
|
|
|
|
SystemPromptMessage,
|
|
|
|
|
ToolPromptMessage,
|
|
|
|
|
@ -115,6 +118,9 @@ class XinferenceAILargeLanguageModel(LargeLanguageModel):
|
|
|
|
|
if extra_param.support_function_call:
|
|
|
|
|
credentials['support_function_call'] = True
|
|
|
|
|
|
|
|
|
|
if extra_param.support_vision:
|
|
|
|
|
credentials['support_vision'] = True
|
|
|
|
|
|
|
|
|
|
if extra_param.context_length:
|
|
|
|
|
credentials['context_length'] = extra_param.context_length
|
|
|
|
|
|
|
|
|
|
@ -155,7 +161,7 @@ class XinferenceAILargeLanguageModel(LargeLanguageModel):
|
|
|
|
|
text = ''
|
|
|
|
|
for item in value:
|
|
|
|
|
if isinstance(item, dict) and item['type'] == 'text':
|
|
|
|
|
text += item.text
|
|
|
|
|
text += item['text']
|
|
|
|
|
|
|
|
|
|
value = text
|
|
|
|
|
|
|
|
|
|
@ -260,7 +266,26 @@ class XinferenceAILargeLanguageModel(LargeLanguageModel):
|
|
|
|
|
if isinstance(message.content, str):
|
|
|
|
|
message_dict = {"role": "user", "content": message.content}
|
|
|
|
|
else:
|
|
|
|
|
raise ValueError("User message content must be str")
|
|
|
|
|
sub_messages = []
|
|
|
|
|
for message_content in message.content:
|
|
|
|
|
if message_content.type == PromptMessageContentType.TEXT:
|
|
|
|
|
message_content = cast(PromptMessageContent, message_content)
|
|
|
|
|
sub_message_dict = {
|
|
|
|
|
"type": "text",
|
|
|
|
|
"text": message_content.data
|
|
|
|
|
}
|
|
|
|
|
sub_messages.append(sub_message_dict)
|
|
|
|
|
elif message_content.type == PromptMessageContentType.IMAGE:
|
|
|
|
|
message_content = cast(ImagePromptMessageContent, message_content)
|
|
|
|
|
sub_message_dict = {
|
|
|
|
|
"type": "image_url",
|
|
|
|
|
"image_url": {
|
|
|
|
|
"url": message_content.data,
|
|
|
|
|
"detail": message_content.detail.value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sub_messages.append(sub_message_dict)
|
|
|
|
|
message_dict = {"role": "user", "content": sub_messages}
|
|
|
|
|
elif isinstance(message, AssistantPromptMessage):
|
|
|
|
|
message = cast(AssistantPromptMessage, message)
|
|
|
|
|
message_dict = {"role": "assistant", "content": message.content}
|
|
|
|
|
@ -339,7 +364,17 @@ class XinferenceAILargeLanguageModel(LargeLanguageModel):
|
|
|
|
|
else:
|
|
|
|
|
raise ValueError(f'xinference model ability {extra_args.model_ability} is not supported')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
features = []
|
|
|
|
|
|
|
|
|
|
support_function_call = credentials.get('support_function_call', False)
|
|
|
|
|
if support_function_call:
|
|
|
|
|
features.append(ModelFeature.TOOL_CALL)
|
|
|
|
|
|
|
|
|
|
support_vision = credentials.get('support_vision', False)
|
|
|
|
|
if support_vision:
|
|
|
|
|
features.append(ModelFeature.VISION)
|
|
|
|
|
|
|
|
|
|
context_length = credentials.get('context_length', 2048)
|
|
|
|
|
|
|
|
|
|
entity = AIModelEntity(
|
|
|
|
|
@ -349,9 +384,7 @@ class XinferenceAILargeLanguageModel(LargeLanguageModel):
|
|
|
|
|
),
|
|
|
|
|
fetch_from=FetchFrom.CUSTOMIZABLE_MODEL,
|
|
|
|
|
model_type=ModelType.LLM,
|
|
|
|
|
features=[
|
|
|
|
|
ModelFeature.TOOL_CALL
|
|
|
|
|
] if support_function_call else [],
|
|
|
|
|
features=features,
|
|
|
|
|
model_properties={
|
|
|
|
|
ModelPropertyKey.MODE: completion_type,
|
|
|
|
|
ModelPropertyKey.CONTEXT_SIZE: context_length
|
|
|
|
|
@ -408,7 +441,7 @@ class XinferenceAILargeLanguageModel(LargeLanguageModel):
|
|
|
|
|
'function': helper.dump_model(tool)
|
|
|
|
|
} for tool in tools
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
vision = credentials.get('support_vision', False)
|
|
|
|
|
if isinstance(xinference_model, RESTfulChatModelHandle | RESTfulChatglmCppChatModelHandle):
|
|
|
|
|
resp = client.chat.completions.create(
|
|
|
|
|
model=credentials['model_uid'],
|
|
|
|
|
|