import{j as e,a_ as k,bc as i,f as c,a as o,cO as y,ci as X,v as Z,di as ee,dj as re,aK as se,r as f,fQ as N,c as P,be as L,a3 as F,a4 as S,f_ as ne,b8 as Q,b1 as q,u as H,dF as te,O,cr as ie,b7 as U,aT as M,fZ as j,ff as B,e as $,M as W,ba as oe,f$ as ae,ct as ce,fM as le,bf as de,cV as ue,fW as xe,b0 as he,b2 as me,bq as pe,br as E,K as T}from"./index-d6499a22.js";import{C as v}from"./CardBoundary-898d91f9.js";import{s as je,M as ge}from"./modelVersion.selector-975bf538.js";import{u as z}from"./useProjectId-6028b5ae.js";import{b as fe,I as be,D as _,s as m,c as Ce,d as De,e as Ee}from"./utils-b5e8f9a5.js";import{u as R}from"./useCurrentProject-b23444be.js";import{P as Te}from"./Panel-b19e8cc0.js";import{u as J}from"./useDownload-7167ff3b.js";import{u as ve,a as ke,S as we,D as Y}from"./useDeploymentKibanaLink-1bce4c7a.js";import{G as Ie}from"./GrafanaDashboard-d51b4440.js";import{f as K}from"./file-utils-b5704e1c.js";import"./NoData-789df290.js";import"./useProject-0d0fdeb3.js";import"./Deprecated-ec8916ed.js";import"./CardActionButton-ccf1bc35.js";const Se=({deployment:r})=>{const{isLoading:n,project:s}=R(),a=()=>{const t=["Serving tool","Inference logging","Kafka topic","Request batching"];return r.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:r.servingTool??"-"})},"ac.servingTool"),e.jsx(i.Cell,{children:e.jsx(c,{children:((l=r.inferenceLogging)==null?void 0:l.toLowerCase())??"none"})},"ac.inferenceLogging"),e.jsx(i.Cell,{children:e.jsx(c,{sx:{userSelect:"all"},children:((x=r.kafkaTopicDTO)==null?void 0:x.name)??"-"})},"ac.kafkaTopic"),e.jsx(i.Cell,{children:e.jsx(c,{children:r.batchingConfiguration.batchingEnabled?"yes":"no"})},"ac.batchingEnabled")];return r.batchingConfiguration.batchingEnabled?t.concat([e.jsx(i.Cell,{children:e.jsx(c,{children:r.batchingConfiguration.maxBatchSize})},"ac.maxBatchSize"),e.jsx(i.Cell,{children:e.jsx(c,{children:r.batchingConfiguration.maxLatency})},"ac.maxLatency"),e.jsx(i.Cell,{children:e.jsx(c,{children:r.batchingConfiguration.timeout})},"ac.timeout")]):t};return n||!s?e.jsx(k,{}):e.jsx(i,{bordered:!1,padded:!1,hoverable:!1,middleColumn:r.batchingConfiguration.batchingEnabled?6:3,legend:a(),children:e.jsx(i.Row,{children:u()})})},Le=({deployment:r})=>{const{isLoading:n,project:s}=R();return n||!s?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:s==null?void 0:s.projectName,deploymentName:r.name})}),e.jsx(y,{copyButton:!0,title:"Start or stop deployment",language:"python",content:Me({projectName:s==null?void 0:s.projectName,deploymentName:r.name})})]}),e.jsx(y,{copyButton:!0,title:"Make predictions with input example",language:"python",content:Pe({projectName:s==null?void 0:s.projectName,deploymentName:r.name})})]})},Ne=r=>`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("${r.deploymentName}")
`,Me=r=>`# print deployment info
deployment.describe()

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

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

# make predictions
predictions = deployment.predict({"instances": [model.input_example]})
print(predictions)
`,Re=Z.injectEndpoints({endpoints:r=>({runTestDeployment:r.mutation({async queryFn({host:n,deployment:s,verb:a,content:u},t,l,x){return await new ee("",n).rtkQuery({url:fe(s,a,!n),data:u,headers:{"Content-Type":"application/json"},method:re.post},t,l)}}),getInferenceEndpoints:r.query({query:({projectId:n})=>({url:`project/${n}/inference/endpoints`})})})}),{useRunTestDeploymentMutation:Ae,useGetInferenceEndpointsQuery:ye}=Re,$e=({deployment:r})=>{const{id:n,project:s,isLoading:a}=R(),{data:u,isLoading:t}=se("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(()=>r.servingTool===N.KSERVE?[_[0]]:_,[r]);return a||t||x||!s?e.jsx(k,{}):e.jsxs(o,{flexDirection:"column",p:20,sx:m.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%"}})]}),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(r,w)})]},w)),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 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(r,"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(s.projectName,r.name,u)})]},"HostHeader")]})]})},_e=r=>r.status===void 0?S.neutral:r.status?r.type===ne.READY?S.valid:S.neutral:S.error,Ve=({deployment:r})=>r.condition?e.jsx(o,{flexDirection:"column",children:e.jsx(F,{mb:"2px",content:r.condition.reason,type:_e(r.condition)})}):null,{DATE_TIME_FULL:Ge}=Q.DATE_TIME,Fe=({deployment:r})=>{const n=q(),s=ve(),a=ke(),{id:u}=H(),l=(()=>{let D;switch(r.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===r.status?{text:r.status,variant:"green"}:{text:r.status,variant:D}})(),x=J(),b=async()=>{const D=`${r.modelPath}/${r.modelVersion}/Artifacts/${r.artifactVersion}/${r.modelName}_${r.modelVersion}_${r.artifactVersion}.zip`;x(Number(u),D,B.DATASET)},C=f.useCallback(()=>{window.open(s(r.name),"_blank")},[s,r.name]),h=f.useCallback(()=>{window.open(a(r.name),"_blank")},[a,r.name]),[w,V]=r.creator.split(" "),G=()=>{n($.deployments.edit,{dId:r.id})};return e.jsxs(e.Fragment,{children:[e.jsx(Te,{type:te.deployment,data:r,title:r.name,version:r.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(O,{children:e.jsx(ie,{firstName:w,lastName:V})}),e.jsx(Oe,{ml:"-5px",label:"Created at",date:new Date(r.created)}),e.jsxs(o,{flexDirection:"column",sx:{gap:"4px"},children:[e.jsx(L,{gray:!0,children:"Serving tool"}),e.jsx(c,{color:"black",children:r.servingTool})]}),r.deployed&&e.jsxs(o,{flexDirection:"column",sx:{gap:"4px"},children:[e.jsx(L,{gray:!0,children:"Deployed at"}),e.jsx(c,{color:"black",children:U(new Date(r.deployed),Ge)})]})]}),e.jsxs(o,{sx:{gap:"20px"},children:[e.jsx(we,{ml:"10px",mt:"6px",status:r.status}),e.jsx(Y,{deployment:r})]})]}),r.description&&e.jsx(o,{children:e.jsx(P,{children:r.description})}),e.jsx(Ve,{deployment:r}),e.jsxs(o,{justifyContent:"space-between",children:[e.jsxs(o,{sx:{gap:"8px"},children:[e.jsx(M,{onClick:h,variant:"secondary",children:"See Metrics ↗"}),e.jsx(M,{onClick:C,variant:"secondary",children:"See Logs ↗"})]}),r.artifactVersion!=null&&e.jsx(M,{onClick:b,intent:"ghost",children:"Download artifacts"})]})]})]})},Oe=({label:r,date:n,primary:s,...a})=>{const{DATE_TIME_FULL:u}=Q.DATE_TIME;return e.jsxs(o,{flexDirection:"column",...a,children:[e.jsx(L,{mb:"3px",gray:!0,children:r}),e.jsx(c,{primary:s,children:U(n,u)})]})},Be=({deployment:r})=>{var l;const{project:n,isLoading:s}=R(),a="grafana/d-solo/kserve/deployment-metrics",u=[{name:"configuration",value:`${r.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 s||!n?e.jsx(k,{}):r.status===j.CREATING||r.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:r,deployment:n})=>{const{id:s}=H(),a=q(),u=()=>{a($.models.overview,{mId:r.name})},t=()=>{a($.models.versionView,{mId:r.name,vId:r.version})},l=J(),x=()=>{const h=`${n.modelPath}/${n.modelVersion}/Artifacts/${n.artifactVersion}/predictor-${n.predictor}`;l(Number(s),h,B.DATASET)},b=()=>{const h=`${n.modelPath}/${n.modelVersion}/Artifacts/${n.artifactVersion}/transformer-${n.transformer}`;l(Number(s),h,B.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:!r.name,onClick:u,children:`${r.name} ->`})}),e.jsx(i.Cell,{children:e.jsx(A,{shouldFallback:!r.version,onClick:t,children:`${r.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:r,children:n,onClick:s})=>r?e.jsx(c,{children:"-"}):e.jsx(c,{primary:!0,sx:{...oe,textDecoration:"underline",cursor:"pointer",maxWidth:"300px"},onClick:s,children:n}),He=({deployment:r})=>{const{isLoading:n,project:s}=R();return n||!s?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:`${r.availableInstances} running out of ${r.requestedInstances}`}),r.requestedInstances===0&&e.jsx(P,{mt:"4px",bold:!0,gray:!0,children:"scale-to-zero"})]}),e.jsx(i.Cell,{children:e.jsx(c,{children:`${r.predictorResources.requests.cores??"-"} -> ${r.predictorResources.limits.cores??"-"}`})}),e.jsx(i.Cell,{children:e.jsx(c,{children:`${r.predictorResources.requests.memory??"-"} -> ${r.predictorResources.limits.memory??"-"}`})}),e.jsx(i.Cell,{children:e.jsx(c,{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(c,{minWidth:"135px",children:r.transformer&&r.requestedTransformerInstances!==void 0?`${r.availableTransformerInstances} running out of ${r.requestedTransformerInstances}`:"-"}),r.transformer&&r.requestedTransformerInstances===0&&e.jsx(P,{mt:"4px",bold:!0,gray:!0,children:"scale-to-zero"})]}),e.jsx(i.Cell,{children:e.jsx(c,{children:`${r.transformerResources.requests.cores??"-"} -> ${r.transformerResources.limits.cores??"-"}`})}),e.jsx(i.Cell,{children:e.jsx(c,{children:`${r.transformerResources.requests.memory??"-"} -> ${r.transformerResources.limits.memory??"-"}`})}),e.jsx(i.Cell,{children:e.jsx(c,{children:`${r.transformerResources.requests.gpus??"-"} -> ${r.transformerResources.limits.gpus??"-"}`})})]})})]})]})},Ke=({deployment:r})=>{const n=z(),s=q(),{data:a,isLoading:u}=ae({projectId:n,model:r.modelName,status:"Running"},{refetchOnMountOrArgChange:!0});if(u||!a)return e.jsx(k,{});const t=x=>()=>{s($.deployments.overview,{dId:x})},l=a.all.filter(x=>x.id!==r.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(M,{intent:"secondary",height:"31px",onClick:t(x.id),children:`${x.name} ->`},x.id))})]})},Qe=({deployment:r,model:n})=>{const s=f.useMemo(()=>{if(r.servingTool===N.KSERVE){const d={..._[0]};return d.key="test",[d]}return _},[r]),[a,u]=f.useState(s[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 r.modelServer===le.TENSORFLOW_SERVING?JSON.stringify({signature_name:"serving_default",instances:d}):r.servingTool===N.DEFAULT||r.servingTool===N.KSERVE?JSON.stringify({instances:[d]}):""},[r,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=K(d.replaceAll(`
`,""))}catch(p){console.warn(p),g=d}l({...t,input:g})},G=(d,g)=>{let p="";if(d)try{p=K(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:r,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 r.status!==j.RUNNING&&r.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(Y,{title:"Run deployment",deployment:r})]}):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:s,onChange:h,mr:"20px"}),e.jsx(M,{type:"submit",intent:"primary",isLoading:C,onClick:D,children:"Run test"})]}),t.error&&e.jsxs(O,{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(O,{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})})]})},lr=()=>{const{dId:r}=H(),n=z(),{data:s}=xe({projectId:n,id:r},{pollingInterval:5e3,refetchOnFocus:!0}),a=he(),{isLoading:u,data:t}=me(je);return f.useEffect(()=>(s!=null&&s.modelName&&(s!=null&&s.modelVersion)&&a.modelVersion.fetch({projectId:+n,modelName:s.modelName,modelVersion:s.modelVersion}),()=>{a.modelVersion.clear()}),[a,n,s==null?void 0:s.modelName,s==null?void 0:s.modelVersion]),!t||!s?e.jsx(k,{}):e.jsx(Ue,{deployment:s,model:t})},Ue=({deployment:r,model:n})=>{var s,a;return e.jsxs(o,{flexDirection:"column",pb:"20px",sx:m.defaultGap,children:[e.jsx(Fe,{deployment:r}),e.jsx(Ke,{deployment:r}),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:r,model:n})})})})}),r.servingTool===N.KSERVE&&e.jsx(E,{name:"metrics",children:e.jsx(v,{children:e.jsx(T,{title:"Metrics",contentProps:m.card,children:e.jsx(Be,{deployment:r})})})}),e.jsx(E,{name:"test-deployment",children:e.jsx(v,{children:e.jsx(T,{title:"Test deployment",contentProps:m.card,children:e.jsx(Qe,{deployment:r,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:r})})})}),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=(s=n.modelSchema)==null?void 0:s.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:r})})})}),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:r})})})})}),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:r})})})})})]})]})};export{lr as Overview,lr as default};
