litellm/ui/litellm-dashboard/out/_next/static/chunks/app/page-cf0440186224a114.js
2024-02-01 12:58:49 -08:00

1 line
No EOL
6.2 KiB
JavaScript

(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{8598:function(e,t,r){Promise.resolve().then(r.t.bind(r,5250,23)),Promise.resolve().then(r.bind(r,3239))},3239:function(e,t,r){"use strict";r.r(t),r.d(t,{default:function(){return F}});var l=r(3827),s=r(4090),a=r(588);let n=async(e,t,r)=>{try{if(console.log("Form Values in keyCreateCall:",r),r.metadata)try{r.metadata=JSON.parse(r.metadata)}catch(e){a.ZP.error("Failed to parse metadata: "+e)}let l=await fetch("/key/generate",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t,...r})});if(!l.ok){let e=await l.text();throw a.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await l.json();return console.log("API Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},o=async(e,t)=>{try{let r=await fetch("/key/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:[t]})});if(!r.ok)throw Error("Network response was not ok");let l=await r.json();return console.log(l),l}catch(e){throw console.error("Failed to create key:",e),e}},i=async(e,t)=>{try{let r=await fetch("/user/info?user_id=".concat(t),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!r.ok)throw Error("Network response was not ok");let l=await r.json();return console.log(l),l}catch(e){throw console.error("Failed to create key:",e),e}};var c=r(384),d=r(6453),h=r(2179),u=r(1801),x=r(6776),m=r(2902),j=r(7171),y=r(9714),Z=r(8707),p=r(1861);let{Option:k}=x.default;var g=e=>{let{userID:t,accessToken:r,data:o,setData:i}=e,[x]=m.Z.useForm(),[k,g]=(0,s.useState)(!1),[f,w]=(0,s.useState)(null),b=()=>{g(!1),x.resetFields()},C=()=>{g(!1),w(null),x.resetFields()},S=async e=>{try{a.ZP.info("Making API Call"),e.models&&""!==e.models.trim()?e.models=e.models.split(",").map(e=>e.trim()):e.models=[],g(!0);let l=await n(r,t,e);i(e=>e?[...e,l]:[l]),w(l.key),a.ZP.success("API Key Created"),x.resetFields()}catch(e){console.error("Error creating the key:",e)}};return(0,l.jsxs)("div",{children:[(0,l.jsx)(h.Z,{className:"mx-auto",onClick:()=>g(!0),children:"+ Create New Key"}),(0,l.jsx)(j.Z,{title:"Create Key",visible:k,width:800,footer:null,onOk:b,onCancel:C,children:(0,l.jsxs)(m.Z,{form:x,onFinish:S,labelCol:{span:6},wrapperCol:{span:16},labelAlign:"left",children:[(0,l.jsx)(m.Z.Item,{label:"Key Name",name:"key_alias",children:(0,l.jsx)(y.Z,{})}),(0,l.jsx)(m.Z.Item,{label:"Models (Comma Separated). Eg: gpt-3.5-turbo,gpt-4",name:"models",children:(0,l.jsx)(y.Z,{placeholder:"gpt-4,gpt-3.5-turbo"})}),(0,l.jsx)(m.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,l.jsx)(Z.Z,{step:.01,precision:2,width:200})}),(0,l.jsx)(m.Z.Item,{label:"Duration (eg: 30s, 30h, 30d)",name:"duration",children:(0,l.jsx)(y.Z,{})}),(0,l.jsx)(m.Z.Item,{label:"Team ID",name:"team_id",children:(0,l.jsx)(y.Z,{placeholder:"ai_team"})}),(0,l.jsx)(m.Z.Item,{label:"Metadata",name:"metadata",children:(0,l.jsx)(y.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(p.ZP,{htmlType:"submit",children:"Create Key"})})]})}),f&&(0,l.jsx)(j.Z,{title:"Save your key",visible:k,onOk:b,onCancel:C,footer:null,children:(0,l.jsxs)(d.Z,{numItems:1,className:"gap-2 w-full",children:[(0,l.jsx)(c.Z,{numColSpan:1,children:(0,l.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,l.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,l.jsx)(c.Z,{numColSpan:1,children:null!=f?(0,l.jsxs)(u.Z,{children:["API Key: ",f]}):(0,l.jsx)(u.Z,{children:"Key being created, this might take 30s"})})]})})]})},f=r(3393),w=r(3810),b=r(1244),C=r(827),S=r(3851),I=r(2044),N=r(4167),E=r(4480),v=r(2287),_=r(2440),P=e=>{let{userID:t,accessToken:r,data:s,setData:a}=e,n=async e=>{if(null!=s)try{await o(r,e);let t=s.filter(t=>t.token!==e);a(t)}catch(e){console.error("Error deleting the key:",e)}};if(null!=s)return console.log("RERENDER TRIGGERED"),(0,l.jsxs)(w.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4",children:[(0,l.jsx)(_.Z,{children:"API Keys"}),(0,l.jsxs)(C.Z,{className:"mt-5",children:[(0,l.jsx)(N.Z,{children:(0,l.jsxs)(v.Z,{children:[(0,l.jsx)(E.Z,{children:"Secret Key"}),(0,l.jsx)(E.Z,{children:"Spend (USD)"}),(0,l.jsx)(E.Z,{children:"Key Budget (USD)"}),(0,l.jsx)(E.Z,{children:"Team ID"}),(0,l.jsx)(E.Z,{children:"Metadata"}),(0,l.jsx)(E.Z,{children:"Expires"})]})}),(0,l.jsx)(S.Z,{children:s.map(e=>(console.log(e),(0,l.jsxs)(v.Z,{children:[(0,l.jsx)(I.Z,{children:null!=e.key_alias?(0,l.jsx)(u.Z,{children:e.key_alias}):(0,l.jsx)(u.Z,{children:e.token})}),(0,l.jsx)(I.Z,{children:(0,l.jsx)(u.Z,{children:e.spend})}),(0,l.jsx)(I.Z,{children:null!=e.max_budget?(0,l.jsx)(u.Z,{children:e.max_budget}):(0,l.jsx)(u.Z,{children:"Unlimited Budget"})}),(0,l.jsx)(I.Z,{children:(0,l.jsx)(u.Z,{children:e.team_id})}),(0,l.jsx)(I.Z,{children:(0,l.jsx)(u.Z,{children:JSON.stringify(e.metadata)})}),(0,l.jsx)(I.Z,{children:null!=e.expires?(0,l.jsx)(u.Z,{children:e.expires}):(0,l.jsx)(u.Z,{children:"Never expires"})}),(0,l.jsx)(I.Z,{children:(0,l.jsx)(b.Z,{onClick:()=>n(e.token),icon:f.Z,size:"xs"})})]},e.token)))})]})]})},D=r(7907),T=r(7963),F=()=>{let[e,t]=(0,s.useState)(null),r=(0,D.useSearchParams)(),a=r.get("userID"),n=r.get("token"),[o,h]=(0,s.useState)(null);return((0,s.useEffect)(()=>{if(n){let e=(0,T.o)(n);e&&(console.log("Decoded token:",e),console.log("Decoded key:",e.key),h(e.key))}a&&o&&!e&&(async()=>{try{let e=await i(o,a);t(e.keys)}catch(e){console.error("There was an error fetching the data",e)}})()},[a,n,o,e]),null==a||null==n)?(window.location.href="/sso/key/generate",null):null==o?null:(0,l.jsx)(d.Z,{numItems:1,className:"gap-0 p-10 h-[75vh] w-full",children:(0,l.jsxs)(c.Z,{numColSpan:1,children:[(0,l.jsx)(P,{userID:a,accessToken:o,data:e,setData:t}),(0,l.jsx)(g,{userID:a,accessToken:o,data:e,setData:t})]})})}}},function(e){e.O(0,[448,971,69,744],function(){return e(e.s=8598)}),_N_E=e.O()}]);