import React, {useState, useEffect} from "react"; import Image from "next/image"; import {openNewTab, modelIcon, modelGetAuth} from "@/utils/utils"; import {fetchApiKey, storeModel} from "@/pages/api/DashboardService"; import {toast} from "react-toastify"; export default function AddModelMarketPlace({ template, getModels, sendModelData }){ const [modelTokenLimit, setModelTokenLimit] = useState(4096); const [modelVersion, setModelVersion] = useState(''); const [modelEndpoint, setModelEndpoint] = useState(''); const [tokenError, setTokenError] = useState(false); const [templateData, setTemplateData] = useState(template); const [isLoading, setIsLoading] = useState(false); const [providerId, setProviderId] = useState(1); const [disableInstall, setDisableInstall] = useState(false); useEffect(() => { if(modelVersion === '' && modelEndpoint === '') setDisableInstall(true) else setDisableInstall(false) },[modelVersion, modelEndpoint]) useEffect(()=>{ console.log(templateData) checkModelProvider().then().catch(); },[]) const checkModelProvider = async () => { if(templateData){ const response = await fetchApiKey(templateData.provider); console.log(response.data) if(response.data.length === 0) { setTokenError(true) return true } else { setTokenError(false) setProviderId(response.data[0].id) return false } } } const storeModelDetails = () => { storeModel(templateData.model_name, templateData.description, modelEndpoint, providerId, modelTokenLimit, "Marketplace", modelVersion).then((response) =>{ setIsLoading(false) let data = response.data if (data.error) { toast.error(data.error,{autoClose: 1800}); } else if (data.success) { toast.success(data.success,{autoClose: 1800}); getModels() console.log(data) handleModelSuccess({id: data.model_id, name: templateData.model_name}) } }).catch((error) => { console.log("SORRY, There was an error storing the model details" + error); setIsLoading(false) }); } const handleModelSuccess = (model) => { model.contentType = 'Model' sendModelData(model) } return(
{templateData &&
Add Model
{templateData.model_name}
By {templateData.model_name.includes('/') ? templateData.model_name.split('/')[0] : templateData.provider}ยท logo-icon {templateData.provider}
{templateData.provider === 'Hugging Face' &&
{templateData.provider} Model Endpoint setModelEndpoint(event.target.value)}/>
} {templateData.provider === 'Replicate' &&
{templateData.provider} Version setModelVersion(event.target.value)}/>
} Token Limit setModelTokenLimit(+event.target.value)} /> {tokenError &&
error-icon
The {templateData.provider} auth token is not added to your settings. In order to start using the model, you need to add the auth token to your settings. You can find the auth token in the {templateData.provider} dashboard.
} {templateData.provider === 'Hugging Face' &&
error-icon
In order to get the endpoint for this model, you will need to deploy it on your Replicate dashboard. Once you have deployed your model on Hugging Face, you will be able to access the endpoint through the Hugging Face dashboard. The endpoint is a URL that you can use to send requests to your model.
}
}
) }