forked from RooCodeInc/Roo-Code
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathusePearAiModels.ts
More file actions
32 lines (27 loc) · 1.04 KB
/
usePearAiModels.ts
File metadata and controls
32 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { useState, useEffect } from "react"
import { ModelInfo, pearAiDefaultModelId, pearAiDefaultModelInfo, PEARAI_URL } from "../../../src/shared/api"
import type { ApiConfiguration } from "../../../src/shared/api"
export const usePearAiModels = (apiConfiguration?: ApiConfiguration) => {
const [pearAiModels, setPearAiModels] = useState<Record<string, ModelInfo>>({
[pearAiDefaultModelId]: pearAiDefaultModelInfo,
})
useEffect(() => {
if (apiConfiguration?.apiProvider === "pearai") {
const fetchPearAiModels = async () => {
try {
const res = await fetch(`${PEARAI_URL}/getPearAIAgentModels`)
if (!res.ok) throw new Error("Failed to fetch models")
const config = await res.json()
if (config.models && Object.keys(config.models).length > 0) {
console.log("Models successfully loaded from server")
setPearAiModels(config.models)
}
} catch (error) {
console.error("Error fetching PearAI models:", error)
}
}
fetchPearAiModels()
}
}, [apiConfiguration?.apiProvider])
return pearAiModels
}