import{eV as ie,ay as A,j as e,L,b$ as t,f as $,bo as O,aP as K,a1 as U,b as a,U as oe,a2 as ae,fi as ce,B as o,c_ as y,c5 as le,bh as de,fv as ue,r as D,fw as xe,fc as _,f7 as B,fx as J,fy as X,fz as Y,c as P,bV as N,fA as he,fB as je,fC as pe,ah as G,ai as S,fD as me,bR as Z,bJ as H,u as q,s as R,dX as ge,d as F,cE as fe,bQ as ee,b4 as V,fu as f,p as se,fE as be,k as Ce,bU as Ee,fF as W,fG as De,cG as ve,fH as we,be as Te,bs as ke,b6 as Le,fI as z,fq as Ie,y as k}from"./index-C1DmWO_C.js";import{A as Se,a as w}from"./Anchor-DFXOcnPw.js";import{C as T}from"./CardBoundary-D6CluE0K.js";import{M as Ne}from"./ModelSchema-CIA3ZkA1.js";import{u as re}from"./useProjectId-Cio5B8Wh.js";import{d as Re}from"./index-DMOJMCC5.js";import{s as j}from"./styles-C5ly0pQK.js";import{P as Pe}from"./Panel-Z-sMb6LN.js";import{u as Me,a as _e,S as Ae,D as ne}from"./useDeploymentKibanaLink-BAuVGozv.js";import{G as ye}from"./GrafanaDashboard-DSm1z0fH.js";import{K as Ve}from"./KubernetesProjectView-Bel69CN9.js";import"./NoData-Y_e6mfNf.js";import"./Deprecated-BQWZLUTP.js";var $e=ie(function(r,n,i){r=r<i.length&&r>=0?r:i.length;var u=Array.prototype.slice.call(i,0);return u.splice(r,0,n),u});const Oe=({deployment:s})=>{const{isLoading:r,project:n}=A(),i=()=>{const c=["Serving tool","API protocol","Inference logging","Kafka topic","Request batching"];return $(O(()=>s.batchingConfiguration.batchingEnabled,K(U,["Maximum batch size","Maximum latency (ms)","Timeout (s)"])))(c)},u=()=>{var x,b,m,h;const c=[e.jsx(t.Cell,{children:e.jsx(a,{children:s.servingTool})},"ac.servingTool"),e.jsx(t.Cell,{children:e.jsx(a,{children:oe(s.apiProtocol,ae(ce))})},"ac.apiProtocol"),e.jsx(t.Cell,{children:e.jsx(a,{color:(x=s.inferenceLogging)!=null&&x.toLowerCase()?"black":"gray",children:((b=s.inferenceLogging)==null?void 0:b.toLowerCase())??"disabled"})},"ac.inferenceLogging"),e.jsx(t.Cell,{children:e.jsx(a,{sx:{userSelect:"all"},color:(m=s.kafkaTopicDTO)!=null&&m.name?"black":"gray",children:((h=s.kafkaTopicDTO)==null?void 0:h.name)??"disabled"})},"ac.kafkaTopic"),e.jsx(t.Cell,{children:e.jsx(a,{color:s.batchingConfiguration.batchingEnabled?"black":"gray",children:s.batchingConfiguration.batchingEnabled?"enabled":"disabled"})},"ac.batchingEnabled")],l=[e.jsx(t.Cell,{children:e.jsx(a,{children:s.batchingConfiguration.maxBatchSize})},"ac.maxBatchSize"),e.jsx(t.Cell,{children:e.jsx(a,{children:s.batchingConfiguration.maxLatency})},"ac.maxLatency"),e.jsx(t.Cell,{children:e.jsx(a,{children:s.batchingConfiguration.timeout})},"ac.timeout")];return $(O(()=>s.batchingConfiguration.batchingEnabled,K(U,l)))(c)};return r||!n?e.jsx(L,{}):e.jsx(t,{bordered:!1,padded:!1,hoverable:!1,middleColumn:s.batchingConfiguration.batchingEnabled?7:4,legend:i(),children:e.jsx(t.Row,{children:u()})})},Be=({deployment:s})=>{const{isLoading:r,project:n}=A();return r||!n?e.jsx(L,{}):e.jsxs(o,{flexDirection:"column",sx:{gap:"20px"},p:"20px",children:[e.jsxs(o,{sx:{gap:"20px"},children:[e.jsx(y,{copyButton:!0,title:"Get deployment",language:"python",content:Ge({projectName:n==null?void 0:n.projectName,deploymentName:s.name})}),e.jsx(y,{copyButton:!0,title:"Start or stop deployment",language:"python",content:Fe({projectName:n==null?void 0:n.projectName,deploymentName:s.name})})]}),e.jsx(y,{copyButton:!0,title:"Make predictions with input example",language:"python",content:He({projectName:n==null?void 0:n.projectName,deploymentName:s.name})})]})},Ge=s=>`import hopsworks

# connect with Hopsworks.
# NOTE: to connect from an external environment, see ${le("/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("${s.deploymentName}")
`,Fe=s=>`# print deployment info
deployment.describe()

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

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