Skip to content

Commit

Permalink
♻️ refactor: improve knownModel matching
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhijie0327 authored Feb 13, 2025
1 parent 93647e4 commit d4bb784
Show file tree
Hide file tree
Showing 31 changed files with 31 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/ai360/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const LobeAi360AI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: model.total_tokens,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/anthropic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class LobeAnthropicAI implements LobeRuntimeAI {

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/baichuan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const LobeBaichuanAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.model === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.model.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: model.max_input_length,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/cloudflare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class LobeCloudflareAI implements LobeRuntimeAI {

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: model.properties?.max_total_tokens
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/deepseek/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const LobeDeepSeekAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/fireworksai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const LobeFireworksAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: model.context_length,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/giteeai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const LobeGiteeAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
49 changes: 0 additions & 49 deletions src/libs/agent-runtime/github/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,53 +210,4 @@ describe('LobeGithubAI', () => {
});
});
});

describe('models', () => {
beforeEach(() => {});

it('should return a list of models', async () => {
// Arrange
const arr = [
{
id: 'azureml://registries/azureml-cohere/models/Cohere-command-r/versions/3',
name: 'Cohere-command-r',
friendly_name: 'Cohere Command R',
model_version: 3,
publisher: 'cohere',
model_family: 'cohere',
model_registry: 'azureml-cohere',
license: 'custom',
task: 'chat-completion',
description:
"Command R is a highly performant generative large language model, optimized for a variety of use cases including reasoning, summarization, and question answering. \n\nThe model is optimized to perform well in the following languages: English, French, Spanish, Italian, German, Brazilian Portuguese, Japanese, Korean, Simplified Chinese, and Arabic.\n\nPre-training data additionally included the following 13 languages: Russian, Polish, Turkish, Vietnamese, Dutch, Czech, Indonesian, Ukrainian, Romanian, Greek, Hindi, Hebrew, Persian.\n\n## Resources\n\nFor full details of this model, [release blog post](https://aka.ms/cohere-blog).\n\n## Model Architecture\n\nThis is an auto-regressive language model that uses an optimized transformer architecture. After pretraining, this model uses supervised fine-tuning (SFT) and preference training to align model behavior to human preferences for helpfulness and safety.\n\n### Tool use capabilities\n\nCommand R has been specifically trained with conversational tool use capabilities. These have been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning, using a specific prompt template. Deviating from this prompt template will likely reduce performance, but we encourage experimentation.\n\nCommand R's tool use functionality takes a conversation as input (with an optional user-system preamble), along with a list of available tools. The model will then generate a json-formatted list of actions to execute on a subset of those tools. Command R may use one of its supplied tools more than once.\n\nThe model has been trained to recognise a special directly_answer tool, which it uses to indicate that it doesn't want to use any of its other tools. The ability to abstain from calling a specific tool can be useful in a range of situations, such as greeting a user, or asking clarifying questions. We recommend including the directly_answer tool, but it can be removed or renamed if required.\n\n### Grounded Generation and RAG Capabilities\n\nCommand R has been specifically trained with grounded generation capabilities. This means that it can generate responses based on a list of supplied document snippets, and it will include grounding spans (citations) in its response indicating the source of the information. This can be used to enable behaviors such as grounded summarization and the final step of Retrieval Augmented Generation (RAG).This behavior has been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning, using a specific prompt template. Deviating from this prompt template may reduce performance, but we encourage experimentation.\n\nCommand R's grounded generation behavior takes a conversation as input (with an optional user-supplied system preamble, indicating task, context and desired output style), along with a list of retrieved document snippets. The document snippets should be chunks, rather than long documents, typically around 100-400 words per chunk. Document snippets consist of key-value pairs. The keys should be short descriptive strings, the values can be text or semi-structured.\n\nBy default, Command R will generate grounded responses by first predicting which documents are relevant, then predicting which ones it will cite, then generating an answer. Finally, it will then insert grounding spans into the answer. See below for an example. This is referred to as accurate grounded generation.\n\nThe model is trained with a number of other answering modes, which can be selected by prompt changes . A fast citation mode is supported in the tokenizer, which will directly generate an answer with grounding spans in it, without first writing the answer out in full. This sacrifices some grounding accuracy in favor of generating fewer tokens.\n\n### Code Capabilities\n\nCommand R has been optimized to interact with your code, by requesting code snippets, code explanations, or code rewrites. It might not perform well out-of-the-box for pure code completion. For better performance, we also recommend using a low temperature (and even greedy decoding) for code-generation related instructions.\n",
summary:
'Command R is a scalable generative model targeting RAG and Tool Use to enable production-scale AI for enterprise.',
tags: ['rag', 'multilingual'],
},
];
vi.spyOn(instance['client'].models, 'list').mockResolvedValue({
body: arr,
} as any);

// Act & Assert
const models = await instance.models();

const modelsCount = models.length;
expect(modelsCount).toBe(arr.length);

for (let i = 0; i < arr.length; i++) {
const model = models[i];
expect(model).toEqual({
contextWindowTokens: undefined,
description: arr[i].description,
displayName: arr[i].friendly_name,
enabled: false,
functionCall: true,
id: arr[i].name,
reasoning: false,
vision: false,
});
}
});
});
});
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const LobeGithubAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/google/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class LobeGoogleAI implements LobeRuntimeAI {
.map((model) => {
const modelName = model.name.replace(/^models\//, '');

const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => modelName === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => modelName.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: model.inputTokenLimit + model.outputTokenLimit,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/groq/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const LobeGroq = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: model.context_window,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/higress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const LobeHigressAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: model.context_length,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/huggingface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const LobeHuggingFaceAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/hunyuan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const LobeHunyuanAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/internlm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const LobeInternLMAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/lmstudio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const LobeLMStudioAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/mistral/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const LobeMistralAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: model.max_context_length,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/moonshot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const LobeMoonshotAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/novita/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const LobeNovitaAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: model.context_size,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/ollama/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class LobeOllamaAI implements LobeRuntimeAI {

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/openai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const LobeOpenAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/openrouter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const LobeOpenRouterAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: model.context_length,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/qwen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const LobeQwenAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
3 changes: 2 additions & 1 deletion src/libs/agent-runtime/sensenova/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const LobeSenseNovaAI = LobeOpenAICompatibleFactory({
const { LOBE_DEFAULT_MODEL_LIST } = await import('@/config/aiModels');

const functionCallKeywords = [
'deepseek-v3',
'sensechat-5',
];

Expand All @@ -49,7 +50,7 @@ export const LobeSenseNovaAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/siliconcloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const LobeSiliconCloudAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/stepfun/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const LobeStepfunAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/tencentcloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const LobeTencentCloudAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/togetherai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const LobeTogetherAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/xai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const LobeXAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/zeroone/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const LobeZeroOneAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/agent-runtime/zhipu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const LobeZhipuAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.modelCode === m.id);
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.modelCode.toLowerCase() === m.id.toLowerCase());

return {
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
Expand Down

0 comments on commit d4bb784

Please sign in to comment.