feat(stage): add player2 api support (#205)
This commit is contained in:
@@ -370,6 +370,9 @@ settings:
|
||||
perplexity:
|
||||
description: perplexity.ai
|
||||
title: Perplexity
|
||||
player2:
|
||||
description: player2.game
|
||||
title: Player2 API
|
||||
together:
|
||||
description: together.ai
|
||||
title: Together.ai
|
||||
|
||||
@@ -370,6 +370,9 @@ settings:
|
||||
perplexity:
|
||||
description: perplexity.ai
|
||||
title: Perplexity
|
||||
player2:
|
||||
description: player2.game
|
||||
title: Player2 API
|
||||
together:
|
||||
description: together.ai
|
||||
title: Together.ai
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ProviderBaseUrlInput,
|
||||
ProviderSettingsContainer,
|
||||
ProviderSettingsLayout,
|
||||
} from '@proj-airi/stage-ui/components'
|
||||
import { useProvidersStore } from '@proj-airi/stage-ui/stores'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { computed, onMounted, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const { t } = useI18n()
|
||||
const router = useRouter()
|
||||
const providersStore = useProvidersStore()
|
||||
const { providers } = storeToRefs(providersStore)
|
||||
|
||||
// Get provider metadata
|
||||
const providerId = 'player2-api'
|
||||
const providerMetadata = computed(() => providersStore.getProviderMetadata(providerId))
|
||||
|
||||
const baseUrl = computed({
|
||||
get: () => providers.value[providerId]?.baseUrl || '',
|
||||
set: (value) => {
|
||||
if (!providers.value[providerId])
|
||||
providers.value[providerId] = {}
|
||||
|
||||
providers.value[providerId].baseUrl = value
|
||||
},
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
// Initialize provider if it doesn't exist
|
||||
providersStore.initializeProvider(providerId)
|
||||
|
||||
// Initialize refs with current values
|
||||
baseUrl.value = providers.value[providerId]?.baseUrl || ''
|
||||
})
|
||||
|
||||
// Watch settings and update the provider configuration
|
||||
watch([baseUrl], () => {
|
||||
providers.value[providerId] = {
|
||||
...providers.value[providerId],
|
||||
baseUrl: baseUrl.value || '',
|
||||
}
|
||||
})
|
||||
|
||||
function handleResetSettings() {
|
||||
providers.value[providerId] = {
|
||||
...(providerMetadata.value?.defaultOptions as any),
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ProviderSettingsLayout
|
||||
:provider-name="providerMetadata?.localizedName" :provider-icon="providerMetadata?.icon"
|
||||
:on-back="() => router.back()"
|
||||
>
|
||||
<ProviderSettingsContainer>
|
||||
<ProviderBasicSettings
|
||||
:title="t('settings.pages.providers.common.section.basic.title')"
|
||||
:description="t('settings.pages.providers.common.section.basic.description')"
|
||||
:on-reset="handleResetSettings"
|
||||
>
|
||||
<ProviderBaseUrlInput v-model="baseUrl" placeholder="http://localhost:4315/v1/" />
|
||||
</ProviderBasicSettings>
|
||||
</ProviderSettingsContainer>
|
||||
</ProviderSettingsLayout>
|
||||
</template>
|
||||
|
||||
<route lang="yaml">
|
||||
meta:
|
||||
layout: settings
|
||||
stageTransition:
|
||||
name: slide
|
||||
</route>
|
||||
@@ -58,10 +58,25 @@ export const useConsciousnessStore = defineStore('consciousness', () => {
|
||||
}
|
||||
}
|
||||
|
||||
let player2Interval: ReturnType<typeof setInterval> | undefined
|
||||
// Watch for provider changes and load models
|
||||
watch(activeProvider, async (newProvider) => {
|
||||
await loadModelsForProvider(newProvider)
|
||||
resetModelSelection()
|
||||
|
||||
if (newProvider === 'player2-api') {
|
||||
// Ping heal check every 60 seconds if Player2 is being used
|
||||
player2Interval = setInterval(() => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Sending Player2 Health check if it is being used')
|
||||
fetch('http://localhost:4315/v1/health').catch(() => {})
|
||||
}, 60_000)
|
||||
}
|
||||
else {
|
||||
if (player2Interval)
|
||||
clearInterval(player2Interval)
|
||||
player2Interval = undefined
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
import type {
|
||||
ChatProvider,
|
||||
ChatProviderWithExtraOptions,
|
||||
EmbedProvider,
|
||||
EmbedProviderWithExtraOptions,
|
||||
SpeechProvider,
|
||||
SpeechProviderWithExtraOptions,
|
||||
TranscriptionProvider,
|
||||
TranscriptionProviderWithExtraOptions,
|
||||
} from '@xsai-ext/shared-providers'
|
||||
import type { ChatProvider, ChatProviderWithExtraOptions, EmbedProvider, EmbedProviderWithExtraOptions, SpeechProvider, SpeechProviderWithExtraOptions, TranscriptionProvider, TranscriptionProviderWithExtraOptions } from '@xsai-ext/shared-providers'
|
||||
import type {
|
||||
UnAlibabaCloudOptions,
|
||||
UnElevenLabsOptions,
|
||||
@@ -32,7 +23,7 @@ import {
|
||||
createWorkersAI,
|
||||
createXAI,
|
||||
} from '@xsai-ext/providers-cloud'
|
||||
import { createOllama } from '@xsai-ext/providers-local'
|
||||
import { createOllama, createPlayer2 } from '@xsai-ext/providers-local'
|
||||
import { listModels } from '@xsai/model'
|
||||
import { defineStore } from 'pinia'
|
||||
import {
|
||||
@@ -900,6 +891,37 @@ export const useProvidersStore = defineStore('providers', () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
'player2-api': {
|
||||
id: 'player2-api',
|
||||
category: 'chat',
|
||||
tasks: ['text-generation'],
|
||||
nameKey: 'settings.pages.providers.provider.player2.title',
|
||||
name: 'Player2 API',
|
||||
descriptionKey: 'settings.pages.providers.provider.player2.description',
|
||||
description: 'player2.game',
|
||||
defaultOptions: {
|
||||
baseUrl: 'http://localhost:4315/v1/',
|
||||
},
|
||||
createProvider: (config) => {
|
||||
return createPlayer2((config.baseURL as string).trim())
|
||||
},
|
||||
capabilities: {
|
||||
listModels: async () => [
|
||||
{
|
||||
id: 'player2-model',
|
||||
name: 'Player2 Model',
|
||||
provider: 'player2-api',
|
||||
},
|
||||
],
|
||||
},
|
||||
validators: {
|
||||
validateProviderConfig: (config) => {
|
||||
const url: string = config.baseUrl ? config.baseUrl as string : 'http://localhost:4315/v1/'
|
||||
// checks if health status is there, so it green if and only if you actually have the player2 app running
|
||||
return (fetch(`${url}health`).then(r => r.status === 200).catch(() => false))
|
||||
},
|
||||
},
|
||||
},
|
||||
'cloudflare-workers-ai': {
|
||||
id: 'cloudflare-workers-ai',
|
||||
category: 'chat',
|
||||
|
||||
Reference in New Issue
Block a user