mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
improvement(performance): added revalidation caches on ollama and openrouter models (#1872)
* improvement(performance): added revalidation caches on ollama and openrouter models * ack PR comments
This commit is contained in:
@@ -6,8 +6,6 @@ import type { ModelsObject } from '@/providers/ollama/types'
|
||||
const logger = createLogger('OllamaModelsAPI')
|
||||
const OLLAMA_HOST = env.OLLAMA_URL || 'http://localhost:11434'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
/**
|
||||
* Get available Ollama models
|
||||
*/
|
||||
@@ -21,6 +19,7 @@ export async function GET(request: NextRequest) {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
next: { revalidate: 60 },
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -4,8 +4,6 @@ import { filterBlacklistedModels } from '@/providers/utils'
|
||||
|
||||
const logger = createLogger('OpenRouterModelsAPI')
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
interface OpenRouterModel {
|
||||
id: string
|
||||
}
|
||||
@@ -18,7 +16,7 @@ export async function GET(_request: NextRequest) {
|
||||
try {
|
||||
const response = await fetch('https://openrouter.ai/api/v1/models', {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
cache: 'no-store',
|
||||
next: { revalidate: 300 },
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -81,6 +81,10 @@ export const useProvidersStore = create<ProvidersStore>((set, get) => ({
|
||||
logger.info(`${provider} model fetch already in progress`)
|
||||
return
|
||||
}
|
||||
if (currentState.models.length > 0) {
|
||||
logger.info(`Skipping ${provider} model fetch - models already loaded`)
|
||||
return
|
||||
}
|
||||
|
||||
logger.info(`Fetching ${provider} models from API`)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user