2023-03-31 00:20:45 +08:00
|
|
|
import { atom, selector } from 'recoil';
|
|
|
|
|
|
2023-04-01 14:33:07 +08:00
|
|
|
const endpointsConfig = atom({
|
|
|
|
|
key: 'endpointsConfig',
|
2023-03-31 00:20:45 +08:00
|
|
|
default: {
|
2023-04-01 14:33:07 +08:00
|
|
|
azureOpenAI: null,
|
|
|
|
|
openAI: null,
|
|
|
|
|
bingAI: null,
|
|
|
|
|
chatGPTBrowser: null
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const endpointsFilter = selector({
|
|
|
|
|
key: 'endpointsFilter',
|
|
|
|
|
get: ({ get }) => {
|
|
|
|
|
const config = get(endpointsConfig) || {};
|
|
|
|
|
|
|
|
|
|
let filter = {};
|
|
|
|
|
for (const key of Object.keys(config)) filter[key] = !!config[key];
|
|
|
|
|
return filter;
|
2023-03-31 00:20:45 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const availableEndpoints = selector({
|
|
|
|
|
key: 'availableEndpoints',
|
|
|
|
|
get: ({ get }) => {
|
|
|
|
|
const endpoints = ['azureOpenAI', 'openAI', 'bingAI', 'chatGPTBrowser'];
|
|
|
|
|
const f = get(endpointsFilter);
|
|
|
|
|
return endpoints.filter(endpoint => f[endpoint]);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// const modelAvailable
|
|
|
|
|
|
|
|
|
|
export default {
|
2023-04-01 14:33:07 +08:00
|
|
|
endpointsConfig,
|
2023-03-31 00:20:45 +08:00
|
|
|
endpointsFilter,
|
|
|
|
|
availableEndpoints
|
|
|
|
|
};
|