MCPcopy
hub / github.com/continuedev/continue / addModel

Function addModel

core/config/util.ts:26–92  ·  view source on GitHub ↗
(
  model: JSONModelDescription,
  role?: keyof ExperimentalModelRoles,
)

Source from the content-addressed store, hash-verified

24}
25
26export 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,

Callers 1

Calls 3

editConfigFileFunction · 0.90
stringifyFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected