import{j as e,a$ as k,bd as i,g as c,Q as o,cR as y,cj as X,p as Z,dm as ee,dl as se,aL as re,r as f,fW as N,x as R,bf as L,a3 as F,a4 as S,g3 as ne,b9 as U,b2 as q,u as H,dJ as te,o as B,cs as ie,b8 as K,aU as P,g2 as j,fj as O,b as $,Y as W,bb as oe,g4 as ae,cu as ce,fS as le,bg as de,cY as ue,f$ as xe,b1 as he,b3 as me,br as pe,bs as E,E as T}from"./index-ea7817a2.js";import{C as v}from"./CardBoundary-ba893294.js";import{s as je,M as ge}from"./modelVersion.selector-d59012b3.js";import{u as z}from"./useProjectId-fe5627bf.js";import{b as fe,I as be,D as _,s as m,c as Ce,d as De,e as Ee}from"./utils-8f90da1d.js";import{u as M}from"./useCurrentProject-0132f110.js";import{P as Te}from"./Panel-041c5d61.js";import{u as Y}from"./useDownload-09eaf3eb.js";import{u as ve,a as ke,S as we,D as J}from"./useDeploymentKibanaLink-61cd1390.js";import{G as Ie}from"./GrafanaDashboard-28e0dd4b.js";import{f as Q}from"./file-utils-a5f053e8.js";import"./NoData-8733f606.js";import"./useProject-77619fff.js";import"./Deprecated-9bfe2e44.js";import"./CardActionButton-6aa39bc1.js";const Se=({deployment:s})=>{const{isLoading:n,project:r}=M(),a=()=>{const t=["Serving tool","Inference logging","Kafka topic","Request batching"];return s.batchingConfiguration.batchingEnabled?t.concat(["Maximum batch size","Maximum latency (ms)","Timeout (s)"]):t},u=()=>{var l,x;const t=[e.jsx(i.Cell,{children:e.jsx(c,{children:s.servingTool??"-"})},"ac.servingTool"),e.jsx(i.Cell,{children:e.jsx(c,{children:((l=s.inferenceLogging)==null?void 0:l.toLowerCase())??"none"})},"ac.inferenceLogging"),e.jsx(i.Cell,{children:e.jsx(c,{sx:{userSelect:"all"},children:((x=s.kafkaTopicDTO)==null?void 0:x.name)??"-"})},"ac.kafkaTopic"),e.jsx(i.Cell,{children:e.jsx(c,{children:s.batchingConfiguration.batchingEnabled?"yes":"no"})},"ac.batchingEnabled")];return s.batchingConfiguration.batchingEnabled?t.concat([e.jsx(i.Cell,{children:e.jsx(c,{children:s.batchingConfiguration.maxBatchSize})},"ac.maxBatchSize"),e.jsx(i.Cell,{children:e.jsx(c,{children:s.batchingConfiguration.maxLatency})},"ac.maxLatency"),e.jsx(i.Cell,{children:e.jsx(c,{children:s.batchingConfiguration.timeout})},"ac.timeout")]):t};return n||!r?e.jsx(k,{}):e.jsx(i,{bordered:!1,padded:!1,hoverable:!1,middleColumn:s.batchingConfiguration.batchingEnabled?6:3,legend:a(),children:e.jsx(i.Row,{children:u()})})},Le=({deployment:s})=>{const{isLoading:n,project:r}=M();return n||!r?e.jsx(k,{}):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:Ne({projectName:r==null?void 0:r.projectName,deploymentName:s.name})}),e.jsx(y,{copyButton:!0,title:"Start or stop deployment",language:"python",content:Pe({projectName:r==null?void 0:r.projectName,deploymentName:s.name})})]}),e.jsx(y,{copyButton:!0,title:"Make predictions with input example",language:"python",content:Re({projectName:r==null?void 0:r.projectName,deploymentName:s.name})})]})},Ne=s=>`import hsml

# connect with Hopsworks.
# NOTE: to connect from an external environment, see https://docs.hopsworks.ai/${X.docsVersion}/user_guides/projects/api_key/create_api_key/
conn = hsml.connection()

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

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

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

# check deployment status
state = deployment.get_state()
state.describe()
  `,Re=s=>`# get Hopsworks Model Registry
mr = conn.get_model_registry(project="${s.projectName}")
  
# get model
model = mr.get_model(deployment.model_name, deployment.model_version)

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