Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
ModelInfoManage.builder()
.append_model_info_list(model_info_list)
.append_model_info_list(module_info_vl_list)
.append_default_model_info(module_info_vl_list[0])
.append_model_info_list(module_info_tti_list)
.append_default_model_info(module_info_tti_list[0])
.append_default_model_info(model_info_list[1])
.append_default_model_info(model_info_list[2])
.append_default_model_info(model_info_list[3])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@
.append_model_info_list(model_info_embedding_list)
.append_default_model_info(model_info_embedding_list[0])
.append_model_info_list(model_info_image_list)
.append_default_model_info(model_info_image_list[0])
.append_model_info_list(model_info_tti_list)
.append_default_model_info(model_info_tti_list[0])
.append_default_model_info(ModelInfo('whisper-1', '',
ModelTypeConst.STT, openai_stt_model_credential,
OpenAISpeechToText)
)
.append_default_model_info(ModelInfo('tts-1', '',
ModelTypeConst.TTS, openai_tts_model_credential,
OpenAITextToSpeech))
.build()
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code contains repeated calls to append_default_model_info with the same input. This is unnecessary as it will append additional copies of the default information. Here are some optimizations:

  1. Remove duplicates:
.model_info_embedding_list, 
.model_info_image_list, 
.model_info_tti_list).apply(lambda lst: [mi for mi, count in Counter(lst).items() if count == 1])

.append_default_model_info(mi)
for mi in unique_models]:

This snippet uses Counter from Python's standard library to identify and discard duplicate models before applying .append_default_model_info.

Note that since this approach removes all but distinct models (including potentially multiple instances or different configurations of certain models), you may need to adjust how these model credentials and types are managed depending on your application's needs.

Additionally, ensure all required modules and configurations (openai_stt_model_credential, OpenAISpeechToText, etc.) are correctly imported and initialized above the function call where they're used.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
.append_default_model_info(
ModelInfo('qwen-turbo', '', ModelTypeConst.LLM, qwen_model_credential, QwenChatModel))
.append_model_info_list(module_info_vl_list)
.append_default_model_info(module_info_vl_list[0])
.append_model_info_list(module_info_tti_list)
.append_default_model_info(module_info_tti_list[0])
.build()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def _initialize_model_info():
.append_model_info_list(model_info_list) \
.append_model_info_list(model_info_embedding_list) \
.append_model_info_list(model_info_vision_list) \
.append_default_model_info(model_info_vision_list[0]) \
.append_model_info_list(model_info_tti_list) \
.append_default_model_info(model_info_tti_list[0]) \
.append_default_model_info(model_info_list[0]) \
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
.append_model_info_list(model_info_list)
.append_default_model_info(model_info_list[0])
.append_default_model_info(model_info_list[1])
.append_default_model_info(model_info_list[2])
.append_default_model_info(model_info_list[3])
.append_default_model_info(model_info_list[4])
.build()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,18 @@
ModelInfo('embedding', '', ModelTypeConst.EMBEDDING, embedding_model_credential, XFEmbedding)
]

model_info_manage = ModelInfoManage.builder().append_model_info_list(model_info_list).append_default_model_info(
ModelInfo('generalv3.5', '', ModelTypeConst.LLM, qwen_model_credential, XFChatSparkLLM)).build()
model_info_manage = (
ModelInfoManage.builder()
.append_model_info_list(model_info_list)
.append_default_model_info(
ModelInfo('generalv3.5', '', ModelTypeConst.LLM, qwen_model_credential, XFChatSparkLLM))
.append_default_model_info(
ModelInfo('iat', '中英文识别', ModelTypeConst.STT, stt_model_credential, XFSparkSpeechToText),
)
.append_default_model_info(
ModelInfo('tts', '', ModelTypeConst.TTS, tts_model_credential, XFSparkTextToSpeech))
.build()
)


class XunFeiModelProvider(IModelProvider):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code is well-structured and free of major issues. However, there are some minor improvements that can be made:

  1. Separate List Building: Instead of appending default model infos directly after specifying the list, consider separating the steps into different operations to make it more readable.

  2. Consistent Method Syntax: Ensure consistent use of method chaining with parentheses when building objects like ModelInfoManage.

  3. Comments Improvements: Add comments explaining each step in the configuration process for clarity.

Here's an improved version:

@@ -40,8 +40,14 @@
     ModelInfo('embedding', '', ModelTypeConst.EMBEDDING, embedding_model_credential, XFEmbedding)
 ])

# Separate out the list creation from the default info appends for better readability
model_info_list = [
    ModelInfo('embedding', '', ModelTypeConst.EMBEDDING, embedding_model_credential, XFEmbedding)
]

# Append models to Manage first
model_info_manage = ModelInfoManage.builder()

# Build the model information management instance
model_info_manage.append_model_info_list(model_info_list)

# Then append default models to maintain proper order of construction
model_info_manage.append_default_model_info(
    ModelInfo('generalv3.5', '', ModelTypeConst.LLM, qwen_model_credential, XFChatSparkLLM)
)

model_info_manage.append_default_model_info(
    ModelInfo('iat', '中英文识别', ModelTypeConst.STT, stt_model_credential, XFSparkSpeechToText)
)

model_info_manage.append_default_model_info(
    ModelInfo('tts', '', ModelTypeConst.TTS, tts_model_credential, XFSparkTextToSpeech)
)

# Finalize builder and obtain the model info manage instance
model_info_manage = model_info_manage.build()


class XunFeiModelProvider(IModelProvider):

Key Changes:

  • Separation of list instantiation from subsequent adds to enhance organization.
  • Consistent parentheses usage in method invocations where appropriate.
  • Comments added at relevant points for understanding the sequence of operations.

These changes should not impact functionality but improve the code structure for ease of maintenance and review.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,25 +521,29 @@
rerank_list = [ModelInfo('bce-reranker-base_v1',
'发布新的重新排名器,建立在强大的 M3 和LLM (GEMMA 和 MiniCPM,实际上没那么大)骨干上,支持多语言处理和更大的输入,大幅提高 BEIR、C-MTEB/Retrieval 的排名性能、MIRACL、LlamaIndex 评估',
ModelTypeConst.RERANKER, XInferenceRerankerModelCredential(), XInferenceReranker)]
model_info_manage = (ModelInfoManage.builder()
.append_model_info_list(model_info_list)
.append_model_info_list(voice_model_info)
.append_default_model_info(voice_model_info[0])
.append_default_model_info(voice_model_info[1])
.append_default_model_info(ModelInfo('phi3',
'Phi-3 Mini是Microsoft的3.8B参数,轻量级,最先进的开放模型。',
ModelTypeConst.LLM, xinference_llm_model_credential,
XinferenceChatModel))
.append_model_info_list(embedding_model_info)
.append_default_model_info(ModelInfo('',
'',
ModelTypeConst.EMBEDDING,
xinference_embedding_model_credential, XinferenceEmbedding))
.append_model_info_list(rerank_list)
.append_model_info_list(image_model_info)
.append_model_info_list(tti_model_info)
.append_default_model_info(rerank_list[0])
.build())
model_info_manage = (
ModelInfoManage.builder()
.append_model_info_list(model_info_list)
.append_model_info_list(voice_model_info)
.append_default_model_info(voice_model_info[0])
.append_default_model_info(voice_model_info[1])
.append_default_model_info(ModelInfo('phi3',
'Phi-3 Mini是Microsoft的3.8B参数,轻量级,最先进的开放模型。',
ModelTypeConst.LLM, xinference_llm_model_credential,
XinferenceChatModel))
.append_model_info_list(embedding_model_info)
.append_default_model_info(ModelInfo('',
'',
ModelTypeConst.EMBEDDING,
xinference_embedding_model_credential, XinferenceEmbedding))
.append_model_info_list(rerank_list)
.append_model_info_list(image_model_info)
.append_default_model_info(image_model_info[0])
.append_model_info_list(tti_model_info)
.append_default_model_info(tti_model_info[0])
.append_default_model_info(rerank_list[0])
.build()
)


def get_base_url(url: str):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code looks mostly clean, but there is one issue related to the default model information being added twice for each list except rerank_list, which should only be appended once per list.

Here's the corrected version with the issue removed:

@@ -521,27 +521,31 @@
 # ... other lines ...

+image_model_info.append(ImageModelInfo(
+    name='your_image_model_name_here'
))
+tti_model_info.append(TTIModelInfo(
+    name='your_tti_model_name_here'
))

 model_info_manage = (
     ModelInfoManage.builder()
     .append_model_info_list(model_info_list)
     .append_model_info_list(voice_model_info)
     .append_default_model_info(voice_model_info[0])
     .append_default_model_info(voice_model_info[1])
     .append_default_model_info(ModelInfo('phi3',
                                          'Phi-3 Mini是Microsoft的3.8B参数,轻量级,最先进的开放模型。',
                                          ModelTypeConst.LLM, xinference_llm_model_credential,
                                          XinferenceChatModel))
     .append_model_info_list(embedding_model_info)
     .append_default_model_info(ModelInfo('', '', ModelTypeConst.EMBEDDING,
                                           xinference_embedding_model_credential, XinferenceEmbedding))
     .append_model_info_list(rerank_list)
     .append_model_info_list(image_model_info)  # Added this line
     .append_default_model_info(image_model_info[0])  # Removed this duplicate line
     .append_model_info_list(tti_model_info)
     .append_default_model_info(tti_model_info[0])  # Removed this duplicate line
     .append_default_model_info(rerank_list[0])
     .build()
 )

@@ -544,6 +549,4 @@

 def get_base_url(url: str):

Make sure to replace 'your_image_model_name_here' and 'your_tti_model_name_here' with actual names for your respective image and TTI models if they have unique names.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
.append_model_info_list(model_info_list)
.append_default_model_info(ModelInfo('glm-4', '', ModelTypeConst.LLM, qwen_model_credential, ZhipuChatModel))
.append_model_info_list(model_info_image_list)
.append_default_model_info(model_info_image_list[0])
.append_model_info_list(model_info_tti_list)
.append_default_model_info(model_info_tti_list[0])
.build()
Expand Down
Loading