import{er as ne,j as e,L as I,bw as i,f as O,b3 as F,aC as W,p as a,U as te,$ as ie,eZ as oe,d as o,cu as $,b$ as ae,K as ce,cD as le,cC as de,aU as ue,r as v,eW as R,y as A,br as y,aa as B,ab as N,f4 as xe,bm as X,bg as U,u as Q,dq as he,c as H,c8 as pe,bl as Y,b6 as V,f3 as b,en as q,q as M,a as Z,h as me,bp as je,f5 as ge,ca as fe,eR as be,bs as Ce,aX as De,f0 as ve,Q as T}from"./index-CK33qGU_.js";import{A as Ee,a as k}from"./Anchor-HBBcGDu5.js";import{C as w}from"./CardBoundary-DhvEI4pf.js";import{M as Te}from"./ModelSchema-Cj4IDoF6.js";import{u as ee}from"./useProjectId-CsRVHJQA.js";import{d as ke}from"./index-B4h3z62J.js";import{b as we,I as Ie,D as G,s as h,c as Le,d as Se,e as Ne}from"./utils-BLs53_9b.js";import{u as _,c as re,f as K}from"./useDownload-hrjXceJg.js";import{_ as z}from"./__-BIxbRvwe.js";import{P as ye}from"./Panel-q_vviXAK.js";import{u as Pe,a as Re,S as Me,D as se}from"./useDeploymentKibanaLink-DpvDLRRu.js";import{G as Ae}from"./GrafanaDashboard-CINcp9ef.js";import{B as _e}from"./ButtonWithRole-NHXEosto.js";import"./NoData-CuLyR2Bg.js";import"./useProject-BzBQtp4J.js";import"./length-fOfC3W0h.js";import"./Deprecated-D5xZ0QMJ.js";import"./CardActionButton-DcsFpjJz.js";var $e=ne(function(s,n,t){s=s<t.length&&s>=0?s:t.length;var u=Array.prototype.slice.call(t,0);return u.splice(s,0,n),u});const Ve=({deployment:r})=>{const{isLoading:s,project:n}=_(),t=()=>{const c=["Serving tool","API protocol","Inference logging","Kafka topic","Request batching"];return O(F(()=>r.batchingConfiguration.batchingEnabled,W(z,["Maximum batch size","Maximum latency (ms)","Timeout (s)"])))(c)},u=()=>{var x,g,f,p;const c=[e.jsx(i.Cell,{children:e.jsx(a,{children:r.servingTool})},"ac.servingTool"),e.jsx(i.Cell,{children:e.jsx(a,{children:te(r.apiProtocol,ie(oe))})},"ac.apiProtocol"),e.jsx(i.Cell,{children:e.jsx(a,{color:(x=r.inferenceLogging)!=null&&x.toLowerCase()?"black":"gray",children:((g=r.inferenceLogging)==null?void 0:g.toLowerCase())??"disabled"})},"ac.inferenceLogging"),e.jsx(i.Cell,{children:e.jsx(a,{sx:{userSelect:"all"},color:(f=r.kafkaTopicDTO)!=null&&f.name?"black":"gray",children:((p=r.kafkaTopicDTO)==null?void 0:p.name)??"disabled"})},"ac.kafkaTopic"),e.jsx(i.Cell,{children:e.jsx(a,{color:r.batchingConfiguration.batchingEnabled?"black":"gray",children:r.batchingConfiguration.batchingEnabled?"enabled":"disabled"})},"ac.batchingEnabled")],l=[e.jsx(i.Cell,{children:e.jsx(a,{children:r.batchingConfiguration.maxBatchSize})},"ac.maxBatchSize"),e.jsx(i.Cell,{children:e.jsx(a,{children:r.batchingConfiguration.maxLatency})},"ac.maxLatency"),e.jsx(i.Cell,{children:e.jsx(a,{children:r.batchingConfiguration.timeout})},"ac.timeout")];return O(F(()=>r.batchingConfiguration.batchingEnabled,W(z,l)))(c)};return s||!n?e.jsx(I,{}):e.jsx(i,{bordered:!1,padded:!1,hoverable:!1,middleColumn:r.batchingConfiguration.batchingEnabled?7:4,legend:t(),children:e.jsx(i.Row,{children:u()})})},Ge=({deployment:r})=>{const{isLoading:s,project:n}=_();return s||!n?e.jsx(I,{}):e.jsxs(o,{flexDirection:"column",sx:{gap:"20px"},p:"20px",children:[e.jsxs(o,{sx:{gap:"20px"},children:[e.jsx($,{copyButton:!0,title:"Get deployment",language:"python",content:Oe({projectName:n==null?void 0:n.projectName,deploymentName:r.name})}),e.jsx($,{copyButton:!0,title:"Start or stop deployment",language:"python",content:Fe({projectName:n==null?void 0:n.projectName,deploymentName:r.name})})]}),e.jsx($,{copyButton:!0,title:"Make predictions with input example",language:"python",content:Be({projectName:n==null?void 0:n.projectName,deploymentName:r.name})})]})},Oe=r=>`import hopsworks

# connect with Hopsworks.
# NOTE: to connect from an external environment, see ${ae("/user_guides/projects/api_key/create_api_key")} 
project = hopsworks.login()

# get Hopsworks Model Serving
ms = project.get_model_serving()

# get deployment object
deployment = ms.get_deployment("${r.deploymentName}")
`,Fe=r=>`# print deployment info
deployment.describe()

# start or stop the deployment
deployment.start()  # .stop()

# check deployment status
state = deployment.get_state()
state.describe()
  `,Be=r=>`# get Hopsworks Model Registry
mr = project.get_model_registry()
  
# get model
model = mr.get_model(deployment.model_name, deployment.model_version)

# make predictions
predictions = deployment.predict({"instances": [model.input_example]})
print(predictions)
`,He=ce.injectEndpoints({endpoints:r=>({runTestDeployment:r.mutation({async queryFn({host:s,deployment:n,verb:t,content:u},c,l,x){return await new de("",s).rtkQuery({url:we(n,t,!s),data:u,headers:{"Content-Type":"application/json"},method:le.post},c,l)}}),getInferenceEndpoints:r.query({query:({projectId:s})=>({url:`project/${s}/inference/endpoints`})})})}),{useRunTestDeploymentMutation:qe,useGetInferenceEndpointsQuery:Ue}=He,Qe=({deployment:r})=>{const{id:s,project:n,isLoading:t}=_(),{data:u,isLoading:c}=ue("kube_knative_domain_name"),{currentData:l,isLoading:x}=Ue({projectId:String(s)}),g=v.useMemo(()=>l==null?void 0:l.find(p=>p.type===Ie.LOAD_BALANCER),[l]),f=v.useMemo(()=>r.servingTool===R.KSERVE?[G[0]]:G,[r]);return t||c||x||!n?e.jsx(I,{}):e.jsxs(o,{flexDirection:"column",p:20,sx:h.defaultGap,children:[e.jsxs(o,{flexDirection:"column",children:[e.jsx(A,{mb:"0px",bold:!0,gray:!0,children:"Hopsworks REST API"}),e.jsx("hr",{style:{borderBottom:"none",borderLeft:"none",borderRight:"none",borderTop:"1px solid lightgray",width:"100%"}})]}),f.map(({label:p,key:E})=>e.jsxs(o,{flexDirection:"column",children:[e.jsx(y,{mb:"3px",gray:!0,children:p}),e.jsx(a,{primary:!0,fontFamily:"IBM Plex Mono",sx:{userSelect:"all"},children:Le(r,E)})]},E)),g&&e.jsxs(e.Fragment,{children:[e.jsxs(o,{flexDirection:"column",mt:"10px",children:[e.jsx(A,{mb:"0px",bold:!0,gray:!0,children:"Istio ingress gateway"}),e.jsx("hr",{style:{borderBottom:"none",borderLeft:"none",borderRight:"none",borderTop:"1px solid lightgray",width:"100%"}})]}),e.jsxs(o,{flexDirection:"column",children:[e.jsx(y,{mb:"3px",gray:!0,children:"Predict"}),e.jsx(a,{primary:!0,fontFamily:"IBM Plex Mono",sx:{userSelect:"all"},children:Se(r,"predict",g)})]},"ModelServerPredict"),e.jsxs(o,{flexDirection:"column",children:[e.jsx(y,{mb:"3px",gray:!0,children:"Host header"}),e.jsx(a,{fontFamily:"IBM Plex Mono",sx:{userSelect:"all"},children:Ne(n.projectName,r.name,u)})]},"HostHeader")]})]})},We=r=>r.status===void 0?N.neutral:r.status?r.type===xe.READY?N.valid:N.neutral:N.error,Ke=({deployment:r})=>r.condition?e.jsx(o,{flexDirection:"column",children:e.jsx(B,{mb:"2px",content:r.condition.reason,type:We(r.condition)})}):null,{DATE_TIME_FULL:ze}=X.DATE_TIME,Je=({deployment:r})=>{const s=U(),n=Pe(),t=Re(),{id:u}=Q(),l=(()=>{let D;switch(r.status){case b.RUNNING:case b.IDLE:D="green";break;case b.STOPPING:case b.STOPPED:D="black";break;case b.CREATING:case b.CREATED:case b.STARTING:D="white";break;default:D=void 0}return b.RUNNING===r.status?{text:r.status,variant:"green"}:{text:r.status,variant:D}})(),x=re(),g=async()=>{const D=`${r.modelPath}/${r.modelVersion}/Artifacts/${r.artifactVersion}/${r.modelName}_${r.modelVersion}_${r.artifactVersion}.zip`;x(Number(u),D,q.DATASET)},f=v.useCallback(()=>{window.open(n(r.name),"_blank")},[n,r.name]),p=v.useCallback(()=>{window.open(t(r.name),"_blank")},[t,r.name]),[E,L]=r.creator.split(" "),m=()=>{s(M.deployments.edit,{dId:r.id})};return e.jsxs(e.Fragment,{children:[e.jsx(ye,{type:he.deployment,data:r,title:r.name,version:r.artifactVersion,onClickEdit:m,idColor:"labels.blueShade1",status:l}),e.jsxs(o,{mt:"10px",flexDirection:"column",sx:{gap:"20px"},children:[e.jsxs(o,{justifyContent:"space-between",children:[e.jsxs(o,{sx:{gap:"30px"},children:[e.jsx(H,{children:e.jsx(pe,{firstName:E,lastName:L})}),e.jsx(Xe,{ml:"-5px",label:"Created at",date:new Date(r.created)}),e.jsxs(o,{flexDirection:"column",sx:{gap:"4px"},children:[e.jsx(y,{gray:!0,children:"Serving tool"}),e.jsx(a,{color:"black",children:r.servingTool})]}),r.deployed&&e.jsxs(o,{flexDirection:"column",sx:{gap:"4px"},children:[e.jsx(y,{gray:!0,children:"Deployed at"}),e.jsx(a,{color:"black",children:Y(new Date(r.deployed),ze)})]})]}),e.jsxs(o,{sx:{gap:"20px"},children:[e.jsx(Me,{ml:"10px",mt:"6px",status:r.status}),e.jsx(se,{deployment:r})]})]}),r.description&&e.jsx(o,{children:e.jsx(A,{children:r.description})}),e.jsx(Ke,{deployment:r}),e.jsxs(o,{justifyContent:"space-between",children:[e.jsxs(o,{sx:{gap:"8px"},children:[e.jsx(V,{onClick:p,variant:"secondary",children:"See Metrics ↗"}),e.jsx(V,{onClick:f,variant:"secondary",children:"See Logs ↗"})]}),r.artifactVersion!=null&&e.jsx(V,{onClick:g,intent:"ghost",children:"Download artifacts"})]})]})]})},Xe=({label:r,date:s,primary:n,...t})=>{const{DATE_TIME_FULL:u}=X.DATE_TIME;return e.jsxs(o,{flexDirection:"column",...t,children:[e.jsx(y,{mb:"3px",gray:!0,children:r}),e.jsx(a,{primary:n,children:Y(s,u)})]})},Ye=({deployment:r})=>{var l;const{project:s,isLoading:n}=_(),t="grafana/d-solo/kserve/deployment-metrics",u=[{name:"configuration",value:`${r.name}-.*`},{name:"revision",value:"All"},{name:"namespace",value:(l=s==null?void 0:s.projectName)==null?void 0:l.toLowerCase().replaceAll("_","-")}],c=[{title:"End to end Latencies",linkParams:{urlPath:t,variables:u,panelId:20}},{title:"Number of requests per second by Response Code Class",linkParams:{urlPath:t,variables:u,panelId:18}}];return n||!s?e.jsx(I,{}):r.status===b.CREATING||r.status===b.CREATED?e.jsx(o,{p:"20px",py:"40px",alignItems:"center",flexDirection:"column",sx:h.defaultGap,children:e.jsx(Z,{color:"grey",fontWeight:"100",children:"Metrics will be shown when the deployment is started"})}):e.jsx(Ae,{panels:c})},J=(r,s)=>{const n=r[s];return["Models",r.modelName,r.modelVersion,"Artifacts",r.artifactVersion,`${s}-${n}`].join("/")},Ze=({model:r,deployment:s})=>{var L;const{id:n}=Q(),t=U(),u=()=>{t(M.models.overview,{mId:r.name})},c=()=>{t(M.models.versionView,{mId:r.name,vId:r.version})},l=re(),x=()=>{const m=J(s,"predictor");l(Number(n),m,q.DATASET)},g=()=>{const m=J(s,"transformer");l(Number(n),m,q.DATASET)},f=m=>m!=null?m===0?"MODEL-ONLY":m:"-",p=!!s.environmentDTO,E=O(F(me(p),$e(5,"Environment")))(["Model","Version","Artifact version","Framework","Model server","Predictor script","Transformer script"]);return e.jsx(i,{bordered:!1,padded:!1,hoverable:!1,middleColumn:p?7:6,legend:E,children:e.jsxs(i.Row,{children:[e.jsx(i.Cell,{children:e.jsx(P,{onClick:u,children:`${r.name} ->`})}),e.jsx(i.Cell,{children:e.jsx(P,{onClick:c,children:`${r.version} ->`})}),e.jsx(i.Cell,{children:e.jsx(a,{children:f(s==null?void 0:s.artifactVersion)})}),e.jsx(i.Cell,{children:e.jsx(a,{children:s.modelFramework})}),e.jsx(i.Cell,{children:e.jsx(a,{children:s.modelServer})}),p&&e.jsx(i.Cell,{children:e.jsx(P,{onClick:()=>{var m;t(M.project.settings.pythonWithEnvironment,{version:(m=s.environmentDTO)==null?void 0:m.name})},children:`${(L=s.environmentDTO)==null?void 0:L.name} ->`})}),e.jsx(i.Cell,{children:e.jsx(P,{shouldFallback:!s.predictor,onClick:x,children:`${s.predictor} ↓`})}),e.jsx(i.Cell,{children:e.jsx(P,{shouldFallback:!s.transformer,onClick:g,children:`${s.transformer} ↓`})})]})})},P=({shouldFallback:r,children:s,onClick:n})=>r?e.jsx(a,{color:"gray",children:"not provided"}):e.jsx(a,{primary:!0,sx:{...je,textDecoration:"underline",cursor:"pointer",maxWidth:"300px"},onClick:n,children:s}),er=({deployment:r})=>{const{isLoading:s,project:n}=_();return s||!n?e.jsx(I,{}):e.jsxs(e.Fragment,{children:[e.jsx(i,{bordered:!1,padded:!1,hoverable:!1,middleColumn:3,legend:["Predictor instances","CPUs","Memory (MB)","GPUs"],children:e.jsxs(i.Row,{children:[e.jsxs(i.Cell,{children:[e.jsx(a,{minWidth:"135px",children:`${r.availableInstances} running out of ${r.requestedInstances}`}),r.requestedInstances===0&&e.jsx(A,{mt:"4px",bold:!0,gray:!0,children:"scale-to-zero"})]}),e.jsx(i.Cell,{children:e.jsx(a,{children:`${r.predictorResources.requests.cores??"-"} -> ${r.predictorResources.limits.cores??"-"}`})}),e.jsx(i.Cell,{children:e.jsx(a,{children:`${r.predictorResources.requests.memory??"-"} -> ${r.predictorResources.limits.memory??"-"}`})}),e.jsx(i.Cell,{children:e.jsx(a,{children:`${r.predictorResources.requests.gpus??"-"} -> ${r.predictorResources.limits.gpus??"-"}`})})]})}),r.transformer&&e.jsxs(e.Fragment,{children:[e.jsx("hr",{style:{borderBottom:"none",borderLeft:"none",borderRight:"none",borderTop:"1px solid lightgray",width:"100%",marginTop:"10px",marginBottom:"10px"}}),e.jsx(i,{bordered:!1,padded:!1,hoverable:!1,middleColumn:3,legend:["Transformer instances","CPUs","Memory (MB)","GPUs"],children:e.jsxs(i.Row,{children:[e.jsxs(i.Cell,{children:[e.jsx(a,{minWidth:"135px",children:r.transformer&&r.requestedTransformerInstances!==void 0?`${r.availableTransformerInstances} running out of ${r.requestedTransformerInstances}`:"-"}),r.transformer&&r.requestedTransformerInstances===0&&e.jsx(A,{mt:"4px",bold:!0,gray:!0,children:"scale-to-zero"})]}),e.jsx(i.Cell,{children:e.jsx(a,{children:`${r.transformerResources.requests.cores??"-"} -> ${r.transformerResources.limits.cores??"-"}`})}),e.jsx(i.Cell,{children:e.jsx(a,{children:`${r.transformerResources.requests.memory??"-"} -> ${r.transformerResources.limits.memory??"-"}`})}),e.jsx(i.Cell,{children:e.jsx(a,{children:`${r.transformerResources.requests.gpus??"-"} -> ${r.transformerResources.limits.gpus??"-"}`})})]})})]})]})},rr=({deployment:r})=>{const s=ee(),n=U(),{data:t,isLoading:u}=ge({projectId:s,model:r.modelName,status:"Running"},{refetchOnMountOrArgChange:!0});if(u||!t)return e.jsx(I,{});const c=x=>()=>{n(M.deployments.overview,{dId:x})},l=t.all.filter(x=>x.id!==r.id);return u||l.length===0?null:e.jsxs(o,{flexDirection:"column",sx:{gap:"8px"},children:[e.jsx(fe,{sx:h.divider}),e.jsx(a,{color:"gray",children:"Deploying the same model"}),e.jsx(o,{width:"100%",children:l.map(x=>e.jsx(V,{intent:"secondary",height:"31px",onClick:c(x.id),children:`${x.name} ->`},x.id))})]})},sr=({deployment:r,model:s})=>{const n=v.useMemo(()=>{if(r.servingTool===R.KSERVE){const d={...G[0]};return d.key="test",[d]}return G},[r]),[t,u]=v.useState(n[0].key),[c,l]=v.useState({input:"",output:"",error:""}),x=v.useMemo(()=>{var C,j,S;if(((C=s.inputExample)==null?void 0:C.preview)===void 0)return"";const d=JSON.parse((S=(j=s.inputExample)==null?void 0:j.preview)==null?void 0:S.content);return r.modelServer===be.TENSORFLOW_SERVING?JSON.stringify({signature_name:"serving_default",instances:d}):r.servingTool===R.DEFAULT||r.servingTool===R.KSERVE?JSON.stringify({instances:[d]}):""},[r,s]);v.useEffect(()=>{l({input:x,output:"",error:""})},[x]);const[g,{isLoading:f}]=qe(),p=d=>{Array.isArray(d)||u(d.key)},E=d=>{f||l({...c,input:d})},L=d=>{let C="";try{C=K(d.replaceAll(`
`,""))}catch(j){console.warn(j),C=d}l({...c,input:C})},m=(d,C)=>{let j="";if(d)try{j=K(JSON.stringify(d))}catch(S){console.warn(S),j=(d==null?void 0:d.toString())||""}l(S=>({...S,output:j,error:C}))},D=async()=>{if(!c.input)return;L(c.input);let d=null,C="";try{d=await g({host:"",deployment:r,verb:t,content:c.input}).unwrap()}catch(j){console.warn(j),C=(j==null?void 0:j.response.data.usrMsg)||"An error occurred"}m(d==null?void 0:d.predictions,C)};return r.status!==b.RUNNING&&r.status!==b.IDLE?e.jsxs(o,{p:"20px",py:"40px",alignItems:"center",flexDirection:"column",sx:h.defaultGap,children:[e.jsx(Z,{color:"grey",fontWeight:"100",children:"Deployment needs to be running to be tested"}),e.jsx(se,{title:"Run deployment",deployment:r})]}):e.jsxs(o,{flexDirection:"column",sx:h.defaultGap,p:"20px",children:[e.jsxs(o,{children:[e.jsx(Ce,{label:"verb",labelMode:"inline",name:"verb",placeholder:"pick a verb",value:t,disabled:f,options:n,onChange:p,mr:"20px"}),e.jsx(_e,{type:"submit",intent:"primary",isLoading:f,onClick:D,children:"Run test"})]}),c.error&&e.jsxs(H,{children:[e.jsx(B,{content:c.error,type:N.error}),e.jsx(B,{mt:"2px",content:"For more details, please check the deployment logs",type:N.neutral})]}),e.jsx(o,{sx:h.codeInput,flexDirection:"column",children:e.jsx(De,{mode:"json",label:"Model inputs",readOnly:!1,value:c.input,onChange:E})}),c.output&&e.jsx(H,{marginTop:"10px",children:e.jsx($,{width:"100%",height:"auto !important",css:{maxHeight:"300px",minHeight:"50px"},language:"json",wrapLongLines:!0,copyButton:!0,downloadButton:!0,showLineNumbers:!0,title:"Predictions",content:c.output})})]})},vr=()=>{const{dId:r}=Q(),s=ee(),{data:n}=ve({projectId:s,id:r},{pollingInterval:5e3,refetchOnFocus:!0}),{currentData:t}=ke({projectId:s,modelName:(n==null?void 0:n.modelName)??"",modelVersion:(n==null?void 0:n.modelVersion)??0},{skip:!(n!=null&&n.modelName)||!(n!=null&&n.modelVersion)});return!t||!n?e.jsx(I,{}):e.jsx(nr,{deployment:n,model:t})},nr=({deployment:r,model:s})=>{var n,t;return e.jsxs(o,{flexDirection:"column",pb:"20px",sx:h.defaultGap,children:[e.jsx(Je,{deployment:r}),e.jsx(rr,{deployment:r}),e.jsxs(Ee,{children:[e.jsx(k,{name:"models",children:e.jsx(w,{children:e.jsx(o,{sx:h.overflowX,children:e.jsx(T,{title:"Models",maxHeight:"400px",width:"100%",children:e.jsx(Ze,{deployment:r,model:s})})})})}),r.servingTool===R.KSERVE&&e.jsx(k,{name:"metrics",children:e.jsx(w,{children:e.jsx(T,{title:"Metrics",contentProps:h.card,children:e.jsx(Ye,{deployment:r})})})}),e.jsx(k,{name:"test-deployment",children:e.jsx(w,{children:e.jsx(T,{title:"Test deployment",contentProps:h.card,children:e.jsx(sr,{deployment:r,model:s})})})}),e.jsx(k,{name:"endpoints",children:e.jsx(w,{children:e.jsx(T,{title:"Endpoints",contentProps:h.card,children:e.jsx(Qe,{deployment:r})})})}),e.jsx(k,{name:"schema",children:e.jsx(w,{children:e.jsx(T,{title:"Deployment schema",contentProps:h.card,children:e.jsx(Te,{schema:(t=(n=s.modelSchema)==null?void 0:n.preview)==null?void 0:t.content})})})}),e.jsx(k,{name:"snippets",children:e.jsx(w,{children:e.jsx(T,{title:"Code snippets",contentProps:h.card,children:e.jsx(Ge,{deployment:r})})})}),e.jsx(k,{name:"configuration",children:e.jsx(w,{children:e.jsx(o,{sx:h.overflowX,children:e.jsx(T,{title:"Configuration",width:"100%",children:e.jsx(Ve,{deployment:r})})})})}),e.jsx(k,{name:"resourceAllocation",children:e.jsx(w,{children:e.jsx(o,{sx:h.overflowX,children:e.jsx(T,{title:"Resource allocation",width:"100%",children:e.jsx(er,{deployment:r})})})})})]})]})};export{vr as Overview,vr as default};
