( model: JSONModelDescription, role?: keyof ExperimentalModelRoles, )
| 24 | } |
| 25 | |
| 26 | export function addModel( |
| 27 | model: JSONModelDescription, |
| 28 | role?: keyof ExperimentalModelRoles, |
| 29 | ) { |
| 30 | editConfigFile( |
| 31 | (config) => { |
| 32 | if (config.models?.some((m) => stringify(m) === stringify(model))) { |
| 33 | return config; |
| 34 | } |
| 35 | |
| 36 | const numMatches = config.models?.reduce( |
| 37 | (prev, curr) => (curr.title.startsWith(model.title) ? prev + 1 : prev), |
| 38 | 0, |
| 39 | ); |
| 40 | if (numMatches !== undefined && numMatches > 0) { |
| 41 | model.title = `${model.title} (${numMatches})`; |
| 42 | } |
| 43 | |
| 44 | config.models.push(model); |
| 45 | |
| 46 | // Set the role for the model |
| 47 | if (role) { |
| 48 | if (!config.experimental) { |
| 49 | config.experimental = {}; |
| 50 | } |
| 51 | if (!config.experimental.modelRoles) { |
| 52 | config.experimental.modelRoles = {}; |
| 53 | } |
| 54 | config.experimental.modelRoles[role] = model.title; |
| 55 | } |
| 56 | |
| 57 | return config; |
| 58 | }, |
| 59 | (config) => { |
| 60 | const numMatches = config.models?.reduce( |
| 61 | (prev, curr) => |
| 62 | "name" in curr && curr.name.startsWith(model.title) ? prev + 1 : prev, |
| 63 | 0, |
| 64 | ); |
| 65 | if (numMatches !== undefined && numMatches > 0) { |
| 66 | model.title = `${model.title} (${numMatches})`; |
| 67 | } |
| 68 | |
| 69 | if (!config.models) { |
| 70 | config.models = []; |
| 71 | } |
| 72 | |
| 73 | const capabilities: string[] = []; |
| 74 | if (model.capabilities?.tools) capabilities.push("tool_use"); |
| 75 | if (model.capabilities?.uploadImage) capabilities.push("image_input"); |
| 76 | |
| 77 | const desc: ModelConfig = { |
| 78 | name: model.title, |
| 79 | provider: model.provider, |
| 80 | model: model.model, |
| 81 | apiKey: model.apiKey, |
| 82 | apiBase: model.apiBase, |
| 83 | contextLength: model.contextLength, |
no test coverage detected