@@ -64,19 +64,23 @@ import type { ModelRecord, RouterModels } from "@roo/api"
64
64
import { useRouterModels } from "./useRouterModels"
65
65
import { useOpenRouterModelProviders } from "./useOpenRouterModelProviders"
66
66
import { useLmStudioModels } from "./useLmStudioModels"
67
+ import { useOllamaModels } from "./useOllamaModels"
67
68
68
69
export const useSelectedModel = ( apiConfiguration ?: ProviderSettings ) => {
69
70
const provider = apiConfiguration ?. apiProvider || "anthropic"
70
71
const openRouterModelId = provider === "openrouter" ? apiConfiguration ?. openRouterModelId : undefined
71
72
const lmStudioModelId = provider === "lmstudio" ? apiConfiguration ?. lmStudioModelId : undefined
73
+ const ollamaModelId = provider === "ollama" ? apiConfiguration ?. ollamaModelId : undefined
72
74
73
75
const routerModels = useRouterModels ( )
74
76
const openRouterModelProviders = useOpenRouterModelProviders ( openRouterModelId )
75
77
const lmStudioModels = useLmStudioModels ( lmStudioModelId )
78
+ const ollamaModels = useOllamaModels ( ollamaModelId )
76
79
77
80
const { id, info } =
78
81
apiConfiguration &&
79
82
( typeof lmStudioModelId === "undefined" || typeof lmStudioModels . data !== "undefined" ) &&
83
+ ( typeof ollamaModelId === "undefined" || typeof ollamaModels . data !== "undefined" ) &&
80
84
typeof routerModels . data !== "undefined" &&
81
85
typeof openRouterModelProviders . data !== "undefined"
82
86
? getSelectedModel ( {
@@ -85,6 +89,7 @@ export const useSelectedModel = (apiConfiguration?: ProviderSettings) => {
85
89
routerModels : routerModels . data ,
86
90
openRouterModelProviders : openRouterModelProviders . data ,
87
91
lmStudioModels : lmStudioModels . data ,
92
+ ollamaModels : ollamaModels . data ,
88
93
} )
89
94
: { id : anthropicDefaultModelId , info : undefined }
90
95
@@ -109,12 +114,14 @@ function getSelectedModel({
109
114
routerModels,
110
115
openRouterModelProviders,
111
116
lmStudioModels,
117
+ ollamaModels,
112
118
} : {
113
119
provider : ProviderName
114
120
apiConfiguration : ProviderSettings
115
121
routerModels : RouterModels
116
122
openRouterModelProviders : Record < string , ModelInfo >
117
123
lmStudioModels : ModelRecord | undefined
124
+ ollamaModels : ModelRecord | undefined
118
125
} ) : { id : string ; info : ModelInfo | undefined } {
119
126
// the `undefined` case are used to show the invalid selection to prevent
120
127
// users from seeing the default model if their selection is invalid
@@ -255,7 +262,7 @@ function getSelectedModel({
255
262
}
256
263
case "ollama" : {
257
264
const id = apiConfiguration . ollamaModelId ?? ""
258
- const info = routerModels . ollama && routerModels . ollama [ id ]
265
+ const info = ollamaModels && ollamaModels [ apiConfiguration . ollamaModelId ! ]
259
266
return {
260
267
id,
261
268
info : info || undefined ,
0 commit comments