5:"$Sreact.fragment" 6:I[7192,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","356","static/chunks/356-d1f63c392b75ec65.js","763","static/chunks/763-0f277b20cff78e1f.js","177","static/chunks/app/layout-e2605612ca64d1d4.js"],"ThemeProvider"] 7:I[3306,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","356","static/chunks/356-d1f63c392b75ec65.js","763","static/chunks/763-0f277b20cff78e1f.js","499","static/chunks/app/docs/layout-763aaf626694b420.js"],"Sheet"] 8:I[3306,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","356","static/chunks/356-d1f63c392b75ec65.js","763","static/chunks/763-0f277b20cff78e1f.js","499","static/chunks/app/docs/layout-763aaf626694b420.js"],"SheetTrigger"] 9:I[3306,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","356","static/chunks/356-d1f63c392b75ec65.js","763","static/chunks/763-0f277b20cff78e1f.js","499","static/chunks/app/docs/layout-763aaf626694b420.js"],"SheetContent"] a:I[3569,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","356","static/chunks/356-d1f63c392b75ec65.js","763","static/chunks/763-0f277b20cff78e1f.js","499","static/chunks/app/docs/layout-763aaf626694b420.js"],"DialogTitle"] b:I[3306,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","356","static/chunks/356-d1f63c392b75ec65.js","763","static/chunks/763-0f277b20cff78e1f.js","499","static/chunks/app/docs/layout-763aaf626694b420.js"],"SheetHeader"] c:I[3306,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","356","static/chunks/356-d1f63c392b75ec65.js","763","static/chunks/763-0f277b20cff78e1f.js","499","static/chunks/app/docs/layout-763aaf626694b420.js"],"SheetClose"] d:I[459,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","686","static/chunks/686-b7d2cd287b15961f.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","32","static/chunks/32-fc39ad8e07d133c3.js","870","static/chunks/app/docs/%5B%5B...slug%5D%5D/page-30c266826d66b2cc.js"],""] e:I[3115,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","356","static/chunks/356-d1f63c392b75ec65.js","763","static/chunks/763-0f277b20cff78e1f.js","499","static/chunks/app/docs/layout-763aaf626694b420.js"],"default"] f:I[5218,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","356","static/chunks/356-d1f63c392b75ec65.js","763","static/chunks/763-0f277b20cff78e1f.js","499","static/chunks/app/docs/layout-763aaf626694b420.js"],"default"] 10:I[8986,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","356","static/chunks/356-d1f63c392b75ec65.js","763","static/chunks/763-0f277b20cff78e1f.js","499","static/chunks/app/docs/layout-763aaf626694b420.js"],"default"] 11:I[6658,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","356","static/chunks/356-d1f63c392b75ec65.js","763","static/chunks/763-0f277b20cff78e1f.js","499","static/chunks/app/docs/layout-763aaf626694b420.js"],"ModeToggle"] 12:I[6312,[],""] 13:I[9417,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","39","static/chunks/app/error-05a83bd475a75953.js"],"default"] 14:I[958,[],""] 15:I[4548,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","686","static/chunks/686-b7d2cd287b15961f.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","32","static/chunks/32-fc39ad8e07d133c3.js","870","static/chunks/app/docs/%5B%5B...slug%5D%5D/page-30c266826d66b2cc.js"],"ScrollArea"] 17:I[4969,[],"OutletBoundary"] 19:I[4969,[],"MetadataBoundary"] 1b:I[4969,[],"ViewportBoundary"] 1d:I[647,[],""] 1:HL["/_next/static/media/7ab9c4cba5a6d4c2-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}] 2:HL["/_next/static/media/fc727f226c737876-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}] 3:HL["/_next/static/css/0790576569b8c287.css","style"] 4:HL["/_next/static/css/2a797d424d7a344c.css","style"] 0:{"P":null,"b":"wX-EG0lj4TM92v30RFng-","p":"","c":["","docs","getting-started","guide","components"],"i":false,"f":[[["",{"children":["docs",{"children":[["slug","getting-started/guide/components","oc"],{"children":["__PAGE__",{}]}]}]},"$undefined","$undefined",true],["",["$","$5","c",{"children":[[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/0790576569b8c287.css","precedence":"next","crossOrigin":"$undefined","nonce":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/_next/static/css/2a797d424d7a344c.css","precedence":"next","crossOrigin":"$undefined","nonce":"$undefined"}]],["$","html",null,{"lang":"en","suppressHydrationWarning":true,"children":[["$","head",null,{"children":["$","link",null,{"rel":"stylesheet","type":"text/css","href":"https://cdn.jsdelivr.net/gh/devicons/devicon@latest/devicon.min.css"}]}],["$","body",null,{"className":"__variable_b3b596 __variable_33c22e font-regular antialiased tracking-wide","suppressHydrationWarning":true,"children":["$","$L6",null,{"attribute":"class","defaultTheme":"system","enableSystem":true,"disableTransitionOnChange":true,"children":[["$","nav",null,{"className":"w-full border-b h-16 sticky top-0 z-50 bg-background","children":["$","div",null,{"className":"sm:container mx-auto w-[95vw] h-full flex items-center sm:justify-between md:gap-2","children":[["$","div",null,{"className":"flex items-center sm:gap-5 gap-2.5","children":[["$","$L7",null,{"children":[["$","$L8",null,{"asChild":true,"children":["$","button",null,{"className":"items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground h-9 w-9 md:hidden flex","ref":"$undefined","children":["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-align-left","children":[["$","line","1fp77t",{"x1":"21","x2":"3","y1":"6","y2":"6"}],["$","line","v6grx8",{"x1":"15","x2":"3","y1":"12","y2":"12"}],["$","line","1awlsn",{"x1":"17","x2":"3","y1":"18","y2":"18"}],"$undefined"]}]}]}],["$","$L9",null,{"className":"flex flex-col gap-4 px-0","side":"left","children":[["$","$La",null,{"className":"sr-only","children":"Menu"}],["$","$Lb",null,{"children":["$","$Lc",null,{"className":"px-5","asChild":true,"children":["$","$Ld",null,{"href":"/","className":"flex items-center gap-2.5","children":[["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-radius w-6 h-6 text-muted-foreground","children":[["$","path","fydyku",{"d":"M20.34 17.52a10 10 0 1 0-2.82 2.82"}],["$","circle","17f5cg",{"cx":"19","cy":"19","r":"2"}],["$","path","1gqbwc",{"d":"m13.41 13.41 4.18 4.18"}],["$","circle","1c9p78",{"cx":"12","cy":"12","r":"2"}],"$undefined"]}],["$","h2",null,{"className":"text-md font-bold font-code","children":"Optimas"}]]}]}]}],["$","div",null,{"className":"flex flex-col gap-4 overflow-y-auto","children":[["$","div",null,{"className":"flex flex-col gap-2.5 mt-3 mx-2 px-5","children":[["$","$Lc","Documentation/docs/getting-started/introduction",{"asChild":true,"children":["$","$Le","Documentation/docs/getting-started/introduction",{"activeClassName":"!text-primary dark:font-medium font-semibold","absolute":true,"className":"flex items-center gap-1 sm:text-sm text-[14.5px] dark:text-stone-300/85 text-stone-800","href":"/docs/getting-started/introduction","children":"Documentation"}]}],["$","$Lc","Blogs/blogs",{"asChild":true,"children":["$","$Le","Blogs/blogs",{"activeClassName":"!text-primary dark:font-medium font-semibold","absolute":true,"className":"flex items-center gap-1 sm:text-sm text-[14.5px] dark:text-stone-300/85 text-stone-800","href":"/blogs","children":"Blogs"}]}],["$","$Lc","GitHubhttps://github.com/snap-stanford/optimas",{"asChild":true,"children":["$","$Le","GitHubhttps://github.com/snap-stanford/optimas",{"activeClassName":"!text-primary dark:font-medium font-semibold","absolute":true,"className":"flex items-center gap-1 sm:text-sm text-[14.5px] dark:text-stone-300/85 text-stone-800","href":"https://github.com/snap-stanford/optimas","children":"GitHub"}]}],["$","$Lc","Team/team",{"asChild":true,"children":["$","$Le","Team/team",{"activeClassName":"!text-primary dark:font-medium font-semibold","absolute":true,"className":"flex items-center gap-1 sm:text-sm text-[14.5px] dark:text-stone-300/85 text-stone-800","href":"/team","children":"Team"}]}]]}],["$","div",null,{"className":"ml-2 pl-5","children":["$","$Lf",null,{"isSheet":true}]}],["$","div",null,{"className":"p-6 pb-4 flex gap-2.5","children":"$undefined"}]]}]]}]]}],["$","div",null,{"className":"flex items-center gap-6","children":[["$","div",null,{"className":"lg:flex hidden","children":["$","$Ld",null,{"href":"/","className":"flex items-center gap-2.5","children":[["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-radius w-6 h-6 text-muted-foreground","children":[["$","path","fydyku",{"d":"M20.34 17.52a10 10 0 1 0-2.82 2.82"}],["$","circle","17f5cg",{"cx":"19","cy":"19","r":"2"}],["$","path","1gqbwc",{"d":"m13.41 13.41 4.18 4.18"}],["$","circle","1c9p78",{"cx":"12","cy":"12","r":"2"}],"$undefined"]}],["$","h2",null,{"className":"text-md font-bold font-code","children":"Optimas"}]]}]}],["$","div",null,{"className":"md:flex hidden items-center gap-4 text-sm font-medium text-muted-foreground","children":[["$","$Le","Documentation/docs/getting-started/introduction",{"activeClassName":"!text-primary dark:font-medium font-semibold","absolute":true,"className":"flex items-center gap-1 sm:text-sm text-[14.5px] dark:text-stone-300/85 text-stone-800","href":"/docs/getting-started/introduction","children":"Documentation"}],["$","$Le","Blogs/blogs",{"activeClassName":"!text-primary dark:font-medium font-semibold","absolute":true,"className":"flex items-center gap-1 sm:text-sm text-[14.5px] dark:text-stone-300/85 text-stone-800","href":"/blogs","children":"Blogs"}],["$","$Le","GitHubhttps://github.com/snap-stanford/optimas",{"activeClassName":"!text-primary dark:font-medium font-semibold","absolute":true,"className":"flex items-center gap-1 sm:text-sm text-[14.5px] dark:text-stone-300/85 text-stone-800","href":"https://github.com/snap-stanford/optimas","children":"GitHub"}],["$","$Le","Team/team",{"activeClassName":"!text-primary dark:font-medium font-semibold","absolute":true,"className":"flex items-center gap-1 sm:text-sm text-[14.5px] dark:text-stone-300/85 text-stone-800","href":"/team","children":"Team"}]]}]]}]]}],["$","div",null,{"className":"flex items-center sm:justify-normal justify-between sm:gap-3 ml-1 sm:w-fit w-[90%]","children":[["$","$L10",null,{"appId":"$undefined","indexName":"$undefined","apiKey":"$undefined"}],["$","div",null,{"className":"flex items-center justify-between sm:gap-2","children":["$","div",null,{"className":"flex ml-4 sm:ml-0","children":[["$","$Ld",null,{"href":"https://x.com/ShirleyYXWu/status/1943325591190593983","className":"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground h-9 w-9","children":["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-twitter h-[1.1rem] w-[1.1rem]","children":[["$","path","pff0z6",{"d":"M22 4s-.7 2.1-2 3.4c1.6 10-9.4 17.3-18 11.6 2.2.1 4.4-.6 6-2C3 15.5.5 9.6 3 5c2.2 2.6 5.6 4.1 9 4-.9-4.2 4-6.6 7-3.8 1.1 0 3-1.2 3-1.2z"}],"$undefined"]}]}],["$","$Ld",null,{"href":"https://www.linkedin.com/feed/update/urn:li:activity:7349090121251504128/","className":"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground h-9 w-9","children":["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-linkedin h-[1.1rem] w-[1.1rem]","children":[["$","path","c2jq9f",{"d":"M16 8a6 6 0 0 1 6 6v7h-4v-7a2 2 0 0 0-2-2 2 2 0 0 0-2 2v7h-4v-7a6 6 0 0 1 6-6z"}],["$","rect","mk3on5",{"width":"4","height":"12","x":"2","y":"9"}],["$","circle","bt5ra8",{"cx":"4","cy":"4","r":"2"}],"$undefined"]}]}],["$","$Ld",null,{"href":"mailto:shirwu@cs.stanford.edu","className":"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground h-9 w-9","children":["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-mail h-[1.1rem] w-[1.1rem]","children":[["$","rect","18n3k1",{"width":"20","height":"16","x":"2","y":"4","rx":"2"}],["$","path","1ocrg3",{"d":"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"}],"$undefined"]}]}],["$","$L11",null,{}]]}]}]]}]]}]}],["$","main",null,{"className":"sm:container mx-auto w-[90vw] h-auto scroll-smooth","children":["$","$L12",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$13","errorStyles":[],"errorScripts":[],"template":["$","$L14",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":["$","div",null,{"className":"min-h-[87vh] px-2 sm:py-28 py-36 flex flex-col gap-4 items-center","children":[["$","div",null,{"className":"text-center flex flex-col items-center justify-center w-fit gap-2","children":[["$","h2",null,{"className":"text-7xl font-bold pr-1","children":"404"}],["$","p",null,{"className":"text-muted-foreground text-md font-medium","children":["Page not found ",":("]}],["$","p",null,{"children":"Oops! The page you're looking for doesn't exist."}]]}],["$","$Ld",null,{"href":"/","className":"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2","children":"Back to homepage"}]]}],"notFoundStyles":[]}]}],["$","footer",null,{"className":"border-t w-full h-16","children":["$","div",null,{"className":"container flex items-center sm:justify-between justify-center sm:gap-0 gap-4 h-full text-muted-foreground text-sm flex-wrap sm:py-0 py-3 max-sm:px-4","children":[["$","div",null,{"className":"flex items-center gap-3","children":[["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-radius sm:block hidden w-5 h-5 text-muted-foreground","children":[["$","path","fydyku",{"d":"M20.34 17.52a10 10 0 1 0-2.82 2.82"}],["$","circle","17f5cg",{"cx":"19","cy":"19","r":"2"}],["$","path","1gqbwc",{"d":"m13.41 13.41 4.18 4.18"}],["$","circle","1c9p78",{"cx":"12","cy":"12","r":"2"}],"$undefined"]}],["$","p",null,{"className":"text-center","children":["Build by"," ",["$","$Ld",null,{"className":"px-1 underline underline-offset-2","href":"/team","children":"Optimas team."}]]}]]}],["$","div",null,{"className":"gap-4 items-center hidden md:flex","children":"$undefined"}]]}]}]]}]}]]}]]}],{"children":["docs",["$","$5","c",{"children":[null,["$","div",null,{"className":"flex items-start gap-8","children":[["$","aside","leftbar",{"className":"md:flex hidden w-[20rem] sticky top-16 flex-col h-[93.75vh] overflow-y-auto","children":["$","$L15",null,{"className":"py-4 px-2","children":["$","$Lf",null,{}]}]}],["$","div",null,{"className":"flex-[5.25]","children":["$","$L12",null,{"parallelRouterKey":"children","segmentPath":["children","docs","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L14",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]}]]}]]}],{"children":[["slug","getting-started/guide/components","oc"],["$","$5","c",{"children":[null,["$","$L12",null,{"parallelRouterKey":"children","segmentPath":["children","docs","children","$0:f:0:1:2:children:2:children:0","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L14",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]]}],{"children":["__PAGE__",["$","$5","c",{"children":["$L16",null,["$","$L17",null,{"children":"$L18"}]]}],{},null]},null]},null]},null],["$","$5","h",{"children":[null,["$","$5","LpyM2M-8HeoXZ_KgnBJaO",{"children":[["$","$L19",null,{"children":"$L1a"}],["$","$L1b",null,{"children":"$L1c"}],["$","meta",null,{"name":"next-size-adjust"}]]}]]}]]],"m":"$undefined","G":["$1d","$undefined"],"s":false,"S":true} 1c:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}]] 1e:I[2500,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","686","static/chunks/686-b7d2cd287b15961f.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","32","static/chunks/32-fc39ad8e07d133c3.js","870","static/chunks/app/docs/%5B%5B...slug%5D%5D/page-30c266826d66b2cc.js"],"default"] 1f:I[9603,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","686","static/chunks/686-b7d2cd287b15961f.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","32","static/chunks/32-fc39ad8e07d133c3.js","870","static/chunks/app/docs/%5B%5B...slug%5D%5D/page-30c266826d66b2cc.js"],"Tabs"] 20:I[9603,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","686","static/chunks/686-b7d2cd287b15961f.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","32","static/chunks/32-fc39ad8e07d133c3.js","870","static/chunks/app/docs/%5B%5B...slug%5D%5D/page-30c266826d66b2cc.js"],"TabsList"] 21:I[9603,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","686","static/chunks/686-b7d2cd287b15961f.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","32","static/chunks/32-fc39ad8e07d133c3.js","870","static/chunks/app/docs/%5B%5B...slug%5D%5D/page-30c266826d66b2cc.js"],"TabsTrigger"] 22:I[9603,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","686","static/chunks/686-b7d2cd287b15961f.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","32","static/chunks/32-fc39ad8e07d133c3.js","870","static/chunks/app/docs/%5B%5B...slug%5D%5D/page-30c266826d66b2cc.js"],"TabsContent"] 23:T56d,from optimas.arch.base import BaseComponent import litellm class RAGAnswerGenerator(BaseComponent): def __init__(self, model: str = "gpt-4o-mini", temperature: float = 0.0): super().__init__( description="RAG answer generator", input_fields=["query", "retrieved_content"], output_fields=["answer"], variable="Answer the question using the context below.", config={"model": model, "temperature": temperature}, ) def forward(self, **inputs): messages = [ # use self.variable here to optimize system prompt {"role": "system", "content": self.variable}, { "role": "user", "content": ( f"Context:\n{inputs['retrieved_content']}\n\n" f"Question: {inputs['query']}\nAnswer:" ), }, ] resp = litellm.completion( model=self.config.model, messages=messages, temperature=self.config.temperature, ) answer = resp["choices"][0]["message"]["content"].strip() return {"answer": answer} rag = RAGAnswerGenerator() out = rag( query="Who wrote 'Pride and Prejudice'?", retrieved_content="'Pride and Prejudice' was written by Jane Austen and first published in 1813.", ) print(out["answer"]) 24:T44d,import dspy from optimas.arch.base import BaseComponent class WikipediaRetriever(BaseComponent): def __init__(self, k, variable_search_space): super().__init__( description="Retrieve content from Wikipedia.", input_fields=["search_keywords"], output_fields=["retrieve_content"], variable={"k": k}, variable_search_space=variable_search_space, ) colbert = dspy.ColBERTv2(url="http://20.102.90.50:2017/wiki17_abstracts") dspy.settings.configure(rm=colbert) def forward(self, **inputs): keywords = inputs.get("search_keywords") if not keywords: raise ValueError("Missing input: 'search_keywords'") # use self.variable here to optimize the number of retrieved passages passages = dspy.Retrieve(k=self.variable["k"])(keywords).passages return {"retrieve_content": "\n".join(passages)} retriever = WikipediaRetriever(k=1, variable_search_space={'k': [1, 3, 5, 10]}) print(retriever(search_keywords="Pride and Prejudice")["retrieve_content"]) 25:T6eb,from optimas.arch.base import BaseComponent from pathlib import Path import requests import json class LocalModelComponent(BaseComponent): def __init__(self, model_path: str): super().__init__( description="Text generation with local model", input_fields=["text"], output_fields=["generated_text"], variable=Path(model_path), # Input Path object to be identified as optimizing model weights ) self.api_url = "http://localhost:8877/v1/completions" # vllm endpoint self.headers = {"Content-Type": "application/json"} def on_variable_update_end(self): """Called when the model path is updated during optimization""" from optimas.utils.lora import load_lora_adapter # You can customize this method to load LoRA adapters or other model weights load_lora_adapter(self.__class__.__name__, self.variable, "localhost", 8877) def forward(self, **inputs): text = inputs["text"] # Need to use self.variable here payload = { "model": str(self.variable), # Convert Path to string "prompt": text, "max_tokens": 100 } response = requests.post(self.api_url, headers=self.headers, json=payload) result = response.json()["choices"][0]["text"].strip() return {"generated_text": result} # Usage component = LocalModelComponent("local_lm/qwen-1_5b/base") output = component(text="Hello, how are you?") print(output["generated_text"]) # Update to a different model path during optimization component.update(Path("local_lm/qwen-1_5b/fine_tuned")) output2 = component(text="Hello, how are you?") print(output2["generated_text"]) 16:["$","div",null,{"className":"flex items-start gap-10","children":[["$","div",null,{"className":"flex-[4.5] py-10 mx-auto","children":["$","div",null,{"className":"w-full mx-auto","children":[["$","div",null,{"className":"pb-5","children":["$","nav",null,{"ref":"$undefined","aria-label":"breadcrumb","children":["$","ol",null,{"ref":"$undefined","className":"flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground sm:gap-2.5","children":[["$","li",null,{"ref":"$undefined","className":"inline-flex items-center gap-1.5","children":["$","a",null,{"ref":"$undefined","className":"transition-colors hover:text-foreground","children":"Docs"}]}],[["$","$5","getting-started",{"children":[["$","li",null,{"role":"presentation","aria-hidden":"true","className":"[&>svg]:size-3.5","children":["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-chevron-right","children":[["$","path","mthhwq",{"d":"m9 18 6-6-6-6"}],"$undefined"]}]}],["$","li",null,{"ref":"$undefined","className":"inline-flex items-center gap-1.5","children":["$","a",null,{"ref":"$undefined","className":"transition-colors hover:text-foreground a","children":"Getting Started"}]}]]}],["$","$5","guide",{"children":[["$","li",null,{"role":"presentation","aria-hidden":"true","className":"[&>svg]:size-3.5","children":["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-chevron-right","children":[["$","path","mthhwq",{"d":"m9 18 6-6-6-6"}],"$undefined"]}]}],["$","li",null,{"ref":"$undefined","className":"inline-flex items-center gap-1.5","children":["$","a",null,{"ref":"$undefined","className":"transition-colors hover:text-foreground a","children":"Guide"}]}]]}],["$","$5","components",{"children":[["$","li",null,{"role":"presentation","aria-hidden":"true","className":"[&>svg]:size-3.5","children":["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-chevron-right","children":[["$","path","mthhwq",{"d":"m9 18 6-6-6-6"}],"$undefined"]}]}],["$","li",null,{"ref":"$undefined","className":"inline-flex items-center gap-1.5","children":["$","span",null,{"ref":"$undefined","role":"link","aria-disabled":"true","aria-current":"page","className":"font-normal text-foreground b","children":"Components"}]}]]}]]]}]}]}],["$","div",null,{"className":"prose sm:prose-base prose-sm prose-zinc dark:prose-invert prose-code:font-normal prose-code:font-code dark:prose-code:bg-stone-900/25 prose-code:bg-stone-50 prose-pre:bg-background prose-headings:scroll-m-20 w-[85vw] sm:w-full sm:mx-auto prose-code:text-sm prose-code:leading-6 dark:prose-code:text-white prose-code:text-stone-800 prose-code:p-[0.085rem] prose-code:rounded-md prose-code:border pt-2 !min-w-full prose-img:rounded-md prose-img:border prose-code:before:content-none prose-code:after:content-none prose-code:px-1.5 prose-code:overflow-x-auto !max-w-[500px] prose-img:my-3 prose-h2:my-4 prose-h2:mt-8 prose-code:break-all md:prose-code:break-normal prose-td:px-4","children":[["$","h1",null,{"className":"sm:text-3xl text-2xl !-mt-0.5","children":"Build Components"}],["$","p",null,{"className":"-mt-4 text-muted-foreground sm:text-[16.5px] text-[14.5px]","children":"Construct the building blocks of compound AI systems."}],["$","div",null,{"children":[["$","h2",null,{"id":"define-a-component","children":[["$","$Ld",null,{"href":"#define-a-component","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"Define a Component"]}],"\n",["$","p",null,{"children":["Components are the building blocks in Optimas. Each component inherits from ",["$","$Ld",null,{"href":"https://github.com/snap-stanford/optimas/blob/main/optimas/arch/base.py","children":["$","code",null,{"children":"BaseComponent"}],"target":"_blank","rel":"noopener noreferrer"}]," and represents a module that can be optimized and composed together."]}],"\n",["$","p",null,{"children":"Abstract example:"}],"\n",["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"from optimas.arch.base import BaseComponent\n\nclass MyComponent(BaseComponent):\n def __init__(self):\n super().__init__(\n description=\"Component description\",\n input_fields=[\"input1\", \"input2\"],\n output_fields=[\"output1\"],\n variable=, # This configuration gets optimized\n config={\"param\": \"value\"}, # Fixed configurations\n ... # Other optional parameters depends on the variable type\n )\n \n def forward(self, **inputs):\n # IMPORTANT: Make sure self.variable and self.config\n # are used in this forward component logic here. \n # Otherwise a warning will be raised.\n input1, input2 = inputs.get(\"input1\"), inputs.get(\"input2\")\n ...\n return {\"output1\": result}\n"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," optimas",["$","span",null,{"className":"token punctuation","children":"."}],"arch",["$","span",null,{"className":"token punctuation","children":"."}],"base ",["$","span",null,{"className":"token keyword","children":"import"}]," BaseComponent\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"class"}]," ",["$","span",null,{"className":"token class-name","children":"MyComponent"}],["$","span",null,{"className":"token punctuation","children":"("}],"BaseComponent",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"__init__"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token builtin","children":"super"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],"__init__",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" description",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Component description\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" input_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"input1\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"input2\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" output_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"output1\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" variable",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token operator","children":"<"}],"optimizable_config",["$","span",null,{"className":"token operator","children":">"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token comment","children":"# This configuration gets optimized"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" config",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"param\""}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"value\""}],["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token comment","children":"# Fixed configurations"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":"."}]," ",["$","span",null,{"className":"token comment","children":"# Other optional parameters depends on the variable type"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":" \n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"forward"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token operator","children":"**"}],"inputs",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token comment","children":"# IMPORTANT: Make sure self.variable and self.config"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token comment","children":"# are used in this forward component logic here. "}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token comment","children":"# Otherwise a warning will be raised."}],"\n"]}],["$","span",null,{"className":"code-line","children":[" input1",["$","span",null,{"className":"token punctuation","children":","}]," input2 ",["$","span",null,{"className":"token operator","children":"="}]," inputs",["$","span",null,{"className":"token punctuation","children":"."}],"get",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token string","children":"\"input1\""}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}]," inputs",["$","span",null,{"className":"token punctuation","children":"."}],"get",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token string","children":"\"input2\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":"."}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"return"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"output1\""}],["$","span",null,{"className":"token punctuation","children":":"}]," result",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}]]}]}]}]]}],"\n",["$","h3",null,{"id":"1-required-fields","children":[["$","$Ld",null,{"href":"#1-required-fields","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"(1) Required Fields"]}],"\n",["$","p",null,{"children":"To define a component, you need to specify these key fields:"}],"\n",["$","div",null,{"className":"relative max-w-full overflow-auto","children":["$","table",null,{"ref":"$undefined","className":"w-full caption-bottom text-sm","children":[["$","thead",null,{"ref":"$undefined","className":"[&_tr]:border-b","children":["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","th",null,{"ref":"$undefined","className":"h-12 !px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0","children":"Field"}],["$","th",null,{"ref":"$undefined","className":"h-12 !px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0","children":"Type"}],["$","th",null,{"ref":"$undefined","className":"h-12 !px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0","children":"Description"}]]}]}],["$","tbody",null,{"ref":"$undefined","className":"[&_tr:last-child]:border-0","children":[["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","td",null,{"children":["$","code",null,{"children":"description"}]}],["$","td",null,{"children":["$","code",null,{"children":"str"}]}],["$","td",null,{"children":"Short description of what the component does"}]]}],["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","td",null,{"children":["$","code",null,{"children":"input_fields"}]}],["$","td",null,{"children":["$","code",null,{"children":"List[str]"}]}],["$","td",null,{"children":"Names of the input fields the component expects"}]]}],["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","td",null,{"children":["$","code",null,{"children":"output_fields"}]}],["$","td",null,{"children":["$","code",null,{"children":"List[str]"}]}],["$","td",null,{"children":"Names of the output fields the component produces"}]]}],["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","td",null,{"children":["$","code",null,{"children":"variable"}]}],["$","td",null,{"children":["$","code",null,{"children":"Any"}]}],["$","td",null,{"children":"Optimizable configuration (e.g., prompts, hyperparameters)"}]]}],["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","td",null,{"children":["$","code",null,{"children":"config"}]}],["$","td",null,{"children":["$","code",null,{"children":"Dict[str, Any]"}]}],["$","td",null,{"children":"Other fixed configurations (e.g., temperature)"}]]}]]}]]}]}],"\n",["$","h3",null,{"id":"2-required-method","children":[["$","$Ld",null,{"href":"#2-required-method","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"(2) Required Method"]}],"\n",["$","p",null,{"children":"Every component needs a forward method that defines the computation logic."}],"\n",["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"def forward(self, **inputs: Any) -> Dict[str, Any]:\n ...\n"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"forward"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token operator","children":"**"}],"inputs",["$","span",null,{"className":"token punctuation","children":":"}]," Any",["$","span",null,{"className":"token punctuation","children":")"}]," ",["$","span",null,{"className":"token operator","children":"-"}],["$","span",null,{"className":"token operator","children":">"}]," Dict",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token builtin","children":"str"}],["$","span",null,{"className":"token punctuation","children":","}]," Any",["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":"."}],"\n"]}]]}]}]}]]}],"\n",["$","p",null,{"children":"This method defines the computation logic. It must:"}],"\n",["$","ul",null,{"children":["\n",["$","li",null,{"children":["Use values from ",["$","code",null,{"children":"inputs"}]," corresponding to ",["$","code",null,{"children":"input_fields"}]]}],"\n",["$","li",null,{"children":["Return a dictionary with keys matching ",["$","code",null,{"children":"output_fields"}]]}],"\n",["$","li",null,{"children":["Use ",["$","code",null,{"children":"self.variable"}]," and ",["$","code",null,{"children":"self.config"}]," inside (or a warning will be issued)"]}],"\n"]}],"\n",["$","hr",null,{}],"\n",["$","h2",null,{"id":"examples","children":[["$","$Ld",null,{"href":"#examples","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"Examples"]}],"\n",["$","p",null,{"children":"Here're a few examples (click a tab) to construct components with different types of variables to optimize."}],"\n",["$","$L1f",null,{"defaultValue":"prompt","className":"pt-5 pb-1","children":[["$","$L20",null,{"children":[["$","$L21",null,{"value":"prompt","children":"[Prompt]"}],["$","$L21",null,{"value":"hyperparameter","children":"[Hyperparameters]"}],["$","$L21",null,{"value":"parameters","children":"[Model Parameters]"}],["$","$L21",null,{"value":"router","children":"[Model Router]"}]]}],["$","$L22",null,{"value":"prompt","children":["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"$23"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," optimas",["$","span",null,{"className":"token punctuation","children":"."}],"arch",["$","span",null,{"className":"token punctuation","children":"."}],"base ",["$","span",null,{"className":"token keyword","children":"import"}]," BaseComponent\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"import"}]," litellm\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"class"}]," ",["$","span",null,{"className":"token class-name","children":"RAGAnswerGenerator"}],["$","span",null,{"className":"token punctuation","children":"("}],"BaseComponent",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"__init__"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":","}]," model",["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token builtin","children":"str"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token string","children":"\"gpt-4o-mini\""}],["$","span",null,{"className":"token punctuation","children":","}]," temperature",["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token builtin","children":"float"}]," ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token number","children":"0.0"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token builtin","children":"super"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],"__init__",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" description",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"RAG answer generator\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" input_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"query\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"retrieved_content\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" output_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"answer\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" variable",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Answer the question using the context below.\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" config",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"model\""}],["$","span",null,{"className":"token punctuation","children":":"}]," model",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"temperature\""}],["$","span",null,{"className":"token punctuation","children":":"}]," temperature",["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"forward"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token operator","children":"**"}],"inputs",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" messages ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token punctuation","children":"["}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token comment","children":"# use self.variable here to optimize system prompt"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"role\""}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"system\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"content\""}],["$","span",null,{"className":"token punctuation","children":":"}]," self",["$","span",null,{"className":"token punctuation","children":"."}],"variable",["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string","children":"\"role\""}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"user\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string","children":"\"content\""}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string-interpolation","children":[["$","span",null,{"className":"token string","children":"f\"Context:\\n"}],["$","span",null,{"className":"token interpolation","children":[["$","span",null,{"className":"token punctuation","children":"{"}],"inputs",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"'retrieved_content'"}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":"}"}]]}],["$","span",null,{"className":"token string","children":"\\n\\n\""}]]}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string-interpolation","children":[["$","span",null,{"className":"token string","children":"f\"Question: "}],["$","span",null,{"className":"token interpolation","children":[["$","span",null,{"className":"token punctuation","children":"{"}],"inputs",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"'query'"}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":"}"}]]}],["$","span",null,{"className":"token string","children":"\\nAnswer:\""}]]}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"]"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" resp ",["$","span",null,{"className":"token operator","children":"="}]," litellm",["$","span",null,{"className":"token punctuation","children":"."}],"completion",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" model",["$","span",null,{"className":"token operator","children":"="}],"self",["$","span",null,{"className":"token punctuation","children":"."}],"config",["$","span",null,{"className":"token punctuation","children":"."}],"model",["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" messages",["$","span",null,{"className":"token operator","children":"="}],"messages",["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" temperature",["$","span",null,{"className":"token operator","children":"="}],"self",["$","span",null,{"className":"token punctuation","children":"."}],"config",["$","span",null,{"className":"token punctuation","children":"."}],"temperature",["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" answer ",["$","span",null,{"className":"token operator","children":"="}]," resp",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"choices\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token number","children":"0"}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"message\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"content\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":"."}],"strip",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"return"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"answer\""}],["$","span",null,{"className":"token punctuation","children":":"}]," answer",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":["rag ",["$","span",null,{"className":"token operator","children":"="}]," RAGAnswerGenerator",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":["out ",["$","span",null,{"className":"token operator","children":"="}]," rag",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" query",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Who wrote 'Pride and Prejudice'?\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" retrieved_content",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"'Pride and Prejudice' was written by Jane Austen and first published in 1813.\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"out",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"answer\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}]]}]}]}]]}]}],["$","$L22",null,{"value":"router","children":["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"from optimas.arch.base import BaseComponent\n\n# Define a diverse list of LLMs across vendors\nAVAILABLE_MODELS = [\n \"gpt-4o\",\n \"claude-3-5-sonnet-latest\",\n \"gemini-2.5-pro\",\n \"grok-3-latest\"\n]\n\nclass ModelRouter(BaseComponent):\n def __init__(self):\n super().__init__(\n description=\"Select the most appropriate model for the given task.\",\n input_fields=[\"question\"],\n output_fields=[\"selected_model\"],\n variable={\"model_selection\": \"gpt-4o\"}, # Default model\n variable_search_space={\"model_selection\": AVAILABLE_MODELS},\n )\n\n def forward(self, **inputs):\n # Use the selected model from self.variable\n return {\"selected_model\": self.variable[\"model_selection\"]}\n\n# Instantiate and run the router\nrouter = ModelRouter()\nout = router(question=\"What is the capital of Australia?\")\nprint(out[\"selected_model\"])\n"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," optimas",["$","span",null,{"className":"token punctuation","children":"."}],"arch",["$","span",null,{"className":"token punctuation","children":"."}],"base ",["$","span",null,{"className":"token keyword","children":"import"}]," BaseComponent\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Define a diverse list of LLMs across vendors"}],"\n"]}],["$","span",null,{"className":"code-line","children":["AVAILABLE_MODELS ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token punctuation","children":"["}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string","children":"\"gpt-4o\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string","children":"\"claude-3-5-sonnet-latest\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string","children":"\"gemini-2.5-pro\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string","children":"\"grok-3-latest\""}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":"]"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"class"}]," ",["$","span",null,{"className":"token class-name","children":"ModelRouter"}],["$","span",null,{"className":"token punctuation","children":"("}],"BaseComponent",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"__init__"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token builtin","children":"super"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],"__init__",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" description",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Select the most appropriate model for the given task.\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" input_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"question\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" output_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"selected_model\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" variable",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"model_selection\""}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"gpt-4o\""}],["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token comment","children":"# Default model"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" variable_search_space",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"model_selection\""}],["$","span",null,{"className":"token punctuation","children":":"}]," AVAILABLE_MODELS",["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"forward"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token operator","children":"**"}],"inputs",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token comment","children":"# Use the selected model from self.variable"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"return"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"selected_model\""}],["$","span",null,{"className":"token punctuation","children":":"}]," self",["$","span",null,{"className":"token punctuation","children":"."}],"variable",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"model_selection\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Instantiate and run the router"}],"\n"]}],["$","span",null,{"className":"code-line","children":["router ",["$","span",null,{"className":"token operator","children":"="}]," ModelRouter",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":["out ",["$","span",null,{"className":"token operator","children":"="}]," router",["$","span",null,{"className":"token punctuation","children":"("}],"question",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"What is the capital of Australia?\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"out",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"selected_model\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}]]}]}]}]]}]}],["$","$L22",null,{"value":"hyperparameter","children":["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"$24"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"import"}]," dspy\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," optimas",["$","span",null,{"className":"token punctuation","children":"."}],"arch",["$","span",null,{"className":"token punctuation","children":"."}],"base ",["$","span",null,{"className":"token keyword","children":"import"}]," BaseComponent\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"class"}]," ",["$","span",null,{"className":"token class-name","children":"WikipediaRetriever"}],["$","span",null,{"className":"token punctuation","children":"("}],"BaseComponent",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"__init__"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":","}]," k",["$","span",null,{"className":"token punctuation","children":","}]," variable_search_space",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token builtin","children":"super"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],"__init__",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" description",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Retrieve content from Wikipedia.\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" input_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"search_keywords\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" output_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"retrieve_content\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" variable",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"k\""}],["$","span",null,{"className":"token punctuation","children":":"}]," k",["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" variable_search_space",["$","span",null,{"className":"token operator","children":"="}],"variable_search_space",["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" colbert ",["$","span",null,{"className":"token operator","children":"="}]," dspy",["$","span",null,{"className":"token punctuation","children":"."}],"ColBERTv2",["$","span",null,{"className":"token punctuation","children":"("}],"url",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"http://20.102.90.50:2017/wiki17_abstracts\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" dspy",["$","span",null,{"className":"token punctuation","children":"."}],"settings",["$","span",null,{"className":"token punctuation","children":"."}],"configure",["$","span",null,{"className":"token punctuation","children":"("}],"rm",["$","span",null,{"className":"token operator","children":"="}],"colbert",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"forward"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token operator","children":"**"}],"inputs",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" keywords ",["$","span",null,{"className":"token operator","children":"="}]," inputs",["$","span",null,{"className":"token punctuation","children":"."}],"get",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token string","children":"\"search_keywords\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"if"}]," ",["$","span",null,{"className":"token keyword","children":"not"}]," keywords",["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"raise"}]," ValueError",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token string","children":"\"Missing input: 'search_keywords'\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":" \n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token comment","children":"# use self.variable here to optimize the number of retrieved passages"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" passages ",["$","span",null,{"className":"token operator","children":"="}]," dspy",["$","span",null,{"className":"token punctuation","children":"."}],"Retrieve",["$","span",null,{"className":"token punctuation","children":"("}],"k",["$","span",null,{"className":"token operator","children":"="}],"self",["$","span",null,{"className":"token punctuation","children":"."}],"variable",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"k\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"("}],"keywords",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],"passages\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"return"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"retrieve_content\""}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"\\n\""}],["$","span",null,{"className":"token punctuation","children":"."}],"join",["$","span",null,{"className":"token punctuation","children":"("}],"passages",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":["retriever ",["$","span",null,{"className":"token operator","children":"="}]," WikipediaRetriever",["$","span",null,{"className":"token punctuation","children":"("}],"k",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token number","children":"1"}],["$","span",null,{"className":"token punctuation","children":","}]," variable_search_space",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"'k'"}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token number","children":"1"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"3"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"5"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"10"}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"retriever",["$","span",null,{"className":"token punctuation","children":"("}],"search_keywords",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Pride and Prejudice\""}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"retrieve_content\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}]]}]}]}]]}]}],["$","$L22",null,{"value":"parameters","children":["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"$25"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," optimas",["$","span",null,{"className":"token punctuation","children":"."}],"arch",["$","span",null,{"className":"token punctuation","children":"."}],"base ",["$","span",null,{"className":"token keyword","children":"import"}]," BaseComponent\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," pathlib ",["$","span",null,{"className":"token keyword","children":"import"}]," Path\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"import"}]," requests\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"import"}]," json\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"class"}]," ",["$","span",null,{"className":"token class-name","children":"LocalModelComponent"}],["$","span",null,{"className":"token punctuation","children":"("}],"BaseComponent",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"__init__"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":","}]," model_path",["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token builtin","children":"str"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token builtin","children":"super"}],["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"."}],"__init__",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" description",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Text generation with local model\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" input_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"text\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" output_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"generated_text\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" variable",["$","span",null,{"className":"token operator","children":"="}],"Path",["$","span",null,{"className":"token punctuation","children":"("}],"model_path",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token comment","children":"# Input Path object to be identified as optimizing model weights"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":" \n"}],["$","span",null,{"className":"code-line","children":[" self",["$","span",null,{"className":"token punctuation","children":"."}],"api_url ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token string","children":"\"http://localhost:8877/v1/completions\""}]," ",["$","span",null,{"className":"token comment","children":"# vllm endpoint"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" self",["$","span",null,{"className":"token punctuation","children":"."}],"headers ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"Content-Type\""}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token string","children":"\"application/json\""}],["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"on_variable_update_end"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token triple-quoted-string string","children":"\"\"\"Called when the model path is updated during optimization\"\"\""}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"from"}]," optimas",["$","span",null,{"className":"token punctuation","children":"."}],"utils",["$","span",null,{"className":"token punctuation","children":"."}],"lora ",["$","span",null,{"className":"token keyword","children":"import"}]," load_lora_adapter\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token comment","children":"# You can customize this method to load LoRA adapters or other model weights"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" load_lora_adapter",["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":"."}],"__class__",["$","span",null,{"className":"token punctuation","children":"."}],"__name__",["$","span",null,{"className":"token punctuation","children":","}]," self",["$","span",null,{"className":"token punctuation","children":"."}],"variable",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token string","children":"\"localhost\""}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token number","children":"8877"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":" \n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"def"}]," ",["$","span",null,{"className":"token function","children":"forward"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token operator","children":"**"}],"inputs",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" text ",["$","span",null,{"className":"token operator","children":"="}]," inputs",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"text\""}],["$","span",null,{"className":"token punctuation","children":"]"}],"\n"]}],["$","span",null,{"className":"code-line","children":" \n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token comment","children":"# Need to use self.variable here"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" payload ",["$","span",null,{"className":"token operator","children":"="}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string","children":"\"model\""}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token builtin","children":"str"}],["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":"."}],"variable",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":","}]," ",["$","span",null,{"className":"token comment","children":"# Convert Path to string"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string","children":"\"prompt\""}],["$","span",null,{"className":"token punctuation","children":":"}]," text",["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token string","children":"\"max_tokens\""}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token number","children":"100"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":" \n"}],["$","span",null,{"className":"code-line","children":[" response ",["$","span",null,{"className":"token operator","children":"="}]," requests",["$","span",null,{"className":"token punctuation","children":"."}],"post",["$","span",null,{"className":"token punctuation","children":"("}],"self",["$","span",null,{"className":"token punctuation","children":"."}],"api_url",["$","span",null,{"className":"token punctuation","children":","}]," headers",["$","span",null,{"className":"token operator","children":"="}],"self",["$","span",null,{"className":"token punctuation","children":"."}],"headers",["$","span",null,{"className":"token punctuation","children":","}]," json",["$","span",null,{"className":"token operator","children":"="}],"payload",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" result ",["$","span",null,{"className":"token operator","children":"="}]," response",["$","span",null,{"className":"token punctuation","children":"."}],"json",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"choices\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token number","children":"0"}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"text\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":"."}],"strip",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":" \n"}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token keyword","children":"return"}]," ",["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"generated_text\""}],["$","span",null,{"className":"token punctuation","children":":"}]," result",["$","span",null,{"className":"token punctuation","children":"}"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Usage"}],"\n"]}],["$","span",null,{"className":"code-line","children":["component ",["$","span",null,{"className":"token operator","children":"="}]," LocalModelComponent",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token string","children":"\"local_lm/qwen-1_5b/base\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":["output ",["$","span",null,{"className":"token operator","children":"="}]," component",["$","span",null,{"className":"token punctuation","children":"("}],"text",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Hello, how are you?\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"output",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"generated_text\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Update to a different model path during optimization"}],"\n"]}],["$","span",null,{"className":"code-line","children":["component",["$","span",null,{"className":"token punctuation","children":"."}],"update",["$","span",null,{"className":"token punctuation","children":"("}],"Path",["$","span",null,{"className":"token punctuation","children":"("}],["$","span",null,{"className":"token string","children":"\"local_lm/qwen-1_5b/fine_tuned\""}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":["output2 ",["$","span",null,{"className":"token operator","children":"="}]," component",["$","span",null,{"className":"token punctuation","children":"("}],"text",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Hello, how are you?\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"output2",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"generated_text\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}]]}]}]}]]}]}]]}],"\n",["$","p",null,{"children":["That's it! Remember to always use ",["$","code",null,{"children":"self.variable"}]," and ",["$","code",null,{"children":"self.config"}]," in your ",["$","code",null,{"children":"forward()"}]," method to ensure proper optimization behavior later on."]}],"\n",["$","h2",null,{"id":"create-from-external-frameworks","children":[["$","$Ld",null,{"href":"#create-from-external-frameworks","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"Create From External Frameworks"]}],"\n",["$","p",null,{"children":"You can easily integrate external modules as optimizable components within Optimas, through the build-in adapters. The following frameworks are supported:"}],"\n",["$","h3",null,{"id":"dspy","children":[["$","$Ld",null,{"href":"#dspy","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"DSPy"]}],"\n",["$","p",null,{"children":"Optimas adapts DSPy signatures by extracting their configuration, input/output fields, and converting them into optimizable components that maintain DSPy's structured prompting capabilities."}],"\n",["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"import dspy\nfrom optimas.adapt.dspy import create_component_from_dspy\n\nclass HintGenerator(dspy.Signature):\n \"\"\"Generate useful hints to answer the query.\"\"\"\n question: str = dspy.InputField(prefix=\"Query: \")\n hints: str = dspy.OutputField(prefix=\"Hints: \")\n\nlm = dspy.LM(\n model='openai/gpt-4o-mini',\n max_tokens=1024,\n temperature=0.6\n)\ndspy.settings.configure(lm=lm)\nhint_generator = create_component_from_dspy(HintGenerator)\n\nprint(hint_generator.variable) \n# \"Generate useful hints to answer the query.\"\n\nprint(hint_generator.config) \n# namespace(temperature=0.6, max_tokens=1024, model='openai/gpt-4o-mini')\n\nprint(hint_generator.input_fields, hint_generator.output_fields) \n# ['question'] ['hints']\n"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"import"}]," dspy\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," optimas",["$","span",null,{"className":"token punctuation","children":"."}],"adapt",["$","span",null,{"className":"token punctuation","children":"."}],"dspy ",["$","span",null,{"className":"token keyword","children":"import"}]," create_component_from_dspy\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"class"}]," ",["$","span",null,{"className":"token class-name","children":"HintGenerator"}],["$","span",null,{"className":"token punctuation","children":"("}],"dspy",["$","span",null,{"className":"token punctuation","children":"."}],"Signature",["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" ",["$","span",null,{"className":"token triple-quoted-string string","children":"\"\"\"Generate useful hints to answer the query.\"\"\""}],"\n"]}],["$","span",null,{"className":"code-line","children":[" question",["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token builtin","children":"str"}]," ",["$","span",null,{"className":"token operator","children":"="}]," dspy",["$","span",null,{"className":"token punctuation","children":"."}],"InputField",["$","span",null,{"className":"token punctuation","children":"("}],"prefix",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Query: \""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" hints",["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token builtin","children":"str"}]," ",["$","span",null,{"className":"token operator","children":"="}]," dspy",["$","span",null,{"className":"token punctuation","children":"."}],"OutputField",["$","span",null,{"className":"token punctuation","children":"("}],"prefix",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Hints: \""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":["lm ",["$","span",null,{"className":"token operator","children":"="}]," dspy",["$","span",null,{"className":"token punctuation","children":"."}],"LM",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" model",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"'openai/gpt-4o-mini'"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" max_tokens",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token number","children":"1024"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" temperature",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token number","children":"0.6"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":["dspy",["$","span",null,{"className":"token punctuation","children":"."}],"settings",["$","span",null,{"className":"token punctuation","children":"."}],"configure",["$","span",null,{"className":"token punctuation","children":"("}],"lm",["$","span",null,{"className":"token operator","children":"="}],"lm",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":["hint_generator ",["$","span",null,{"className":"token operator","children":"="}]," create_component_from_dspy",["$","span",null,{"className":"token punctuation","children":"("}],"HintGenerator",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"hint_generator",["$","span",null,{"className":"token punctuation","children":"."}],"variable",["$","span",null,{"className":"token punctuation","children":")"}]," \n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# \"Generate useful hints to answer the query.\""}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"hint_generator",["$","span",null,{"className":"token punctuation","children":"."}],"config",["$","span",null,{"className":"token punctuation","children":")"}]," \n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# namespace(temperature=0.6, max_tokens=1024, model='openai/gpt-4o-mini')"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"hint_generator",["$","span",null,{"className":"token punctuation","children":"."}],"input_fields",["$","span",null,{"className":"token punctuation","children":","}]," hint_generator",["$","span",null,{"className":"token punctuation","children":"."}],"output_fields",["$","span",null,{"className":"token punctuation","children":")"}]," \n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# ['question'] ['hints']"}],"\n"]}]]}]}]}]]}],"\n",["$","h3",null,{"id":"crewai","children":[["$","$Ld",null,{"href":"#crewai","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"CrewAI"]}],"\n",["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"import crewai\nfrom optimas.adapt.crewai import create_component_from_crewai\n\n# Define the CrewAI agent\ncrewai_agent = crewai.Agent(\n role=\"Hint Generator\",\n goal=\"Generate useful hints to answer the query.\",\n backstory=\"You're an agent that generates hints based on the query.\",\n llm=\"gpt-4o\",\n)\n\n# Convert to an optimizable component\nhint_generator = create_component_from_crewai(\n crewai_agent,\n input_fields=[\"question\"],\n output_fields=[\"hints\"]\n)\n\n# Run the component\noutput = hint_generator(question=\"How to compute the eigenvector of any matrix?\")\nprint(output[\"hints\"])\n\n"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"import"}]," crewai\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," optimas",["$","span",null,{"className":"token punctuation","children":"."}],"adapt",["$","span",null,{"className":"token punctuation","children":"."}],"crewai ",["$","span",null,{"className":"token keyword","children":"import"}]," create_component_from_crewai\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Define the CrewAI agent"}],"\n"]}],["$","span",null,{"className":"code-line","children":["crewai_agent ",["$","span",null,{"className":"token operator","children":"="}]," crewai",["$","span",null,{"className":"token punctuation","children":"."}],"Agent",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" role",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Hint Generator\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" goal",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Generate useful hints to answer the query.\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" backstory",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"You're an agent that generates hints based on the query.\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" llm",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"gpt-4o\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Convert to an optimizable component"}],"\n"]}],["$","span",null,{"className":"code-line","children":["hint_generator ",["$","span",null,{"className":"token operator","children":"="}]," create_component_from_crewai",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" crewai_agent",["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" input_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"question\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" output_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"hints\""}],["$","span",null,{"className":"token punctuation","children":"]"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Run the component"}],"\n"]}],["$","span",null,{"className":"code-line","children":["output ",["$","span",null,{"className":"token operator","children":"="}]," hint_generator",["$","span",null,{"className":"token punctuation","children":"("}],"question",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"How to compute the eigenvector of any matrix?\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"output",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"hints\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}]]}]}]}]]}],"\n",["$","h3",null,{"id":"autogen","children":[["$","$Ld",null,{"href":"#autogen","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"AutoGen"]}],"\n",["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"from autogen_agentchat.agents import AssistantAgent\nfrom autogen_ext.models.openai import OpenAIChatCompletionClient\nfrom optimas.adapt.autogen import create_component_from_autogen\n\n# Set up model client\nmodel_client = OpenAIChatCompletionClient(model=\"gpt-4o\")\n\n# Define the AutoGen agent\nautogen_agent = AssistantAgent(\n name=\"HintGenerator\",\n model_client=model_client,\n description=\"Generate useful hints to answer the query.\",\n system_message=\"You are a helpful assistant that generates hints to answer the query.\"\n)\n\n# Wrap as an Optimas component\nhint_generator = create_component_from_autogen(\n autogen_agent,\n input_fields=[\"question\"],\n output_fields=[\"hints\"]\n)\n\n# Run the component\noutput = hint_generator(question=\"How to compute the eigenvector of any matrix?\")\nprint(output[\"hints\"])\n"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," autogen_agentchat",["$","span",null,{"className":"token punctuation","children":"."}],"agents ",["$","span",null,{"className":"token keyword","children":"import"}]," AssistantAgent\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," autogen_ext",["$","span",null,{"className":"token punctuation","children":"."}],"models",["$","span",null,{"className":"token punctuation","children":"."}],"openai ",["$","span",null,{"className":"token keyword","children":"import"}]," OpenAIChatCompletionClient\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," optimas",["$","span",null,{"className":"token punctuation","children":"."}],"adapt",["$","span",null,{"className":"token punctuation","children":"."}],"autogen ",["$","span",null,{"className":"token keyword","children":"import"}]," create_component_from_autogen\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Set up model client"}],"\n"]}],["$","span",null,{"className":"code-line","children":["model_client ",["$","span",null,{"className":"token operator","children":"="}]," OpenAIChatCompletionClient",["$","span",null,{"className":"token punctuation","children":"("}],"model",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"gpt-4o\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Define the AutoGen agent"}],"\n"]}],["$","span",null,{"className":"code-line","children":["autogen_agent ",["$","span",null,{"className":"token operator","children":"="}]," AssistantAgent",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" name",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"HintGenerator\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" model_client",["$","span",null,{"className":"token operator","children":"="}],"model_client",["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" description",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Generate useful hints to answer the query.\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" system_message",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"You are a helpful assistant that generates hints to answer the query.\""}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Wrap as an Optimas component"}],"\n"]}],["$","span",null,{"className":"code-line","children":["hint_generator ",["$","span",null,{"className":"token operator","children":"="}]," create_component_from_autogen",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" autogen_agent",["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" input_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"question\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" output_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"hints\""}],["$","span",null,{"className":"token punctuation","children":"]"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Run the component"}],"\n"]}],["$","span",null,{"className":"code-line","children":["output ",["$","span",null,{"className":"token operator","children":"="}]," hint_generator",["$","span",null,{"className":"token punctuation","children":"("}],"question",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"How to compute the eigenvector of any matrix?\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"output",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"hints\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}]]}]}]}]]}],"\n",["$","h3",null,{"id":"textgrad","children":[["$","$Ld",null,{"href":"#textgrad","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"TextGrad"]}],"\n",["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"import textgrad as tg\nfrom optimas.adapt.textgrad import create_component_from_textgrad\n\n# Define a BlackboxLLM agent\nagent = tg.BlackboxLLM(\n engine=\"gpt-4o\",\n system_prompt=\"Generate useful hints to answer the query.\"\n)\n\n# Wrap as an Optimas component\nhint_generator = create_component_from_textgrad(\n agent,\n input_fields=[\"question\"],\n output_fields=[\"hints\"]\n)\n\n# Run the component\noutput = hint_generator(question=\"How to compute the eigenvector of any matrix?\")\nprint(output[\"hints\"])\n"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"import"}]," textgrad ",["$","span",null,{"className":"token keyword","children":"as"}]," tg\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," optimas",["$","span",null,{"className":"token punctuation","children":"."}],"adapt",["$","span",null,{"className":"token punctuation","children":"."}],"textgrad ",["$","span",null,{"className":"token keyword","children":"import"}]," create_component_from_textgrad\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Define a BlackboxLLM agent"}],"\n"]}],["$","span",null,{"className":"code-line","children":["agent ",["$","span",null,{"className":"token operator","children":"="}]," tg",["$","span",null,{"className":"token punctuation","children":"."}],"BlackboxLLM",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" engine",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"gpt-4o\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" system_prompt",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Generate useful hints to answer the query.\""}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Wrap as an Optimas component"}],"\n"]}],["$","span",null,{"className":"code-line","children":["hint_generator ",["$","span",null,{"className":"token operator","children":"="}]," create_component_from_textgrad",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" agent",["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" input_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"question\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" output_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"hints\""}],["$","span",null,{"className":"token punctuation","children":"]"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Run the component"}],"\n"]}],["$","span",null,{"className":"code-line","children":["output ",["$","span",null,{"className":"token operator","children":"="}]," hint_generator",["$","span",null,{"className":"token punctuation","children":"("}],"question",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"How to compute the eigenvector of any matrix?\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"output",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"hints\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}]]}]}]}]]}],"\n",["$","h3",null,{"id":"openai-agent-sdk","children":[["$","$Ld",null,{"href":"#openai-agent-sdk","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"OpenAI Agent SDK"]}],"\n",["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"from agents import Agent\nfrom optimas.adapt.openai import create_component_from_openai\n\n# Define a simple OpenAI agent\nopenai_agent = Agent(\n name=\"HintGenerator\",\n model=\"gpt-4o\",\n instructions=\"Generate useful hints to answer the query.\",\n)\n\n# Wrap as an Optimas component\nhint_generator = create_component_from_openai(\n openai_agent,\n input_fields=[\"question\"],\n output_fields=[\"hints\"]\n)\n\n# Run the component\noutput = hint_generator(question=\"How to compute the eigenvector of any matrix?\")\nprint(output[\"hints\"])\n"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," agents ",["$","span",null,{"className":"token keyword","children":"import"}]," Agent\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"from"}]," optimas",["$","span",null,{"className":"token punctuation","children":"."}],"adapt",["$","span",null,{"className":"token punctuation","children":"."}],"openai ",["$","span",null,{"className":"token keyword","children":"import"}]," create_component_from_openai\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Define a simple OpenAI agent"}],"\n"]}],["$","span",null,{"className":"code-line","children":["openai_agent ",["$","span",null,{"className":"token operator","children":"="}]," Agent",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" name",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"HintGenerator\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" model",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"gpt-4o\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" instructions",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"Generate useful hints to answer the query.\""}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Wrap as an Optimas component"}],"\n"]}],["$","span",null,{"className":"code-line","children":["hint_generator ",["$","span",null,{"className":"token operator","children":"="}]," create_component_from_openai",["$","span",null,{"className":"token punctuation","children":"("}],"\n"]}],["$","span",null,{"className":"code-line","children":[" openai_agent",["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" input_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"question\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":","}],"\n"]}],["$","span",null,{"className":"code-line","children":[" output_fields",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"hints\""}],["$","span",null,{"className":"token punctuation","children":"]"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":"\n"}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# Run the component"}],"\n"]}],["$","span",null,{"className":"code-line","children":["output ",["$","span",null,{"className":"token operator","children":"="}]," hint_generator",["$","span",null,{"className":"token punctuation","children":"("}],"question",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"How to compute the eigenvector of any matrix?\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"output",["$","span",null,{"className":"token punctuation","children":"["}],["$","span",null,{"className":"token string","children":"\"hints\""}],["$","span",null,{"className":"token punctuation","children":"]"}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}]]}]}]}]]}],"\n",["$","h2",null,{"id":"cheat-sheet-core-functionalities","children":[["$","$Ld",null,{"href":"#cheat-sheet-core-functionalities","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"Cheat Sheet: Core Functionalities"]}],"\n",["$","p",null,{"children":"A concise guide for implementing, running, and debugging Optimas components."}],"\n",["$","hr",null,{}],"\n",["$","h3",null,{"id":"accessing-variables-and-configuration","children":[["$","$Ld",null,{"href":"#accessing-variables-and-configuration","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"Accessing Variables and Configuration"]}],"\n",["$","div",null,{"className":"relative max-w-full overflow-auto","children":["$","table",null,{"ref":"$undefined","className":"w-full caption-bottom text-sm","children":[["$","thead",null,{"ref":"$undefined","className":"[&_tr]:border-b","children":["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","th",null,{"ref":"$undefined","className":"h-12 !px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0","children":"Property"}],["$","th",null,{"ref":"$undefined","className":"h-12 !px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0","children":"Description"}]]}]}],["$","tbody",null,{"ref":"$undefined","className":"[&_tr:last-child]:border-0","children":[["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","td",null,{"children":["$","code",null,{"children":"self.variable"}]}],["$","td",null,{"children":"Optimizable content (e.g., prompt, routing decision, numeric hyperparameter)"}]]}],["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","td",null,{"children":["$","code",null,{"children":"self.config"}]}],["$","td",null,{"children":"Thread-local fixed settings (e.g., model name, temperature)"}]]}]]}]]}]}],"\n",["$","hr",null,{}],"\n",["$","h3",null,{"id":"executing-a-component","children":[["$","$Ld",null,{"href":"#executing-a-component","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"Executing a Component"]}],"\n",["$","p",null,{"children":"Call a component directly like a function:"}],"\n",["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"output = my_component(input1=..., input2=...)\n"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":["$","span",null,{"className":"code-line","children":["output ",["$","span",null,{"className":"token operator","children":"="}]," my_component",["$","span",null,{"className":"token punctuation","children":"("}],"input1",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":","}]," input2",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":"."}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}]}]}]}]]}],"\n",["$","p",null,{"children":"This triggers:"}],"\n",["$","ul",null,{"children":["\n",["$","li",null,{"children":["Validation of ",["$","code",null,{"children":"self.variable"}]," and ",["$","code",null,{"children":"self.config"}]," usage"]}],"\n",["$","li",null,{"children":["Optional random sampling from ",["$","code",null,{"children":"variable_search_space"}]]}],"\n",["$","li",null,{"children":["Retry logic (",["$","code",null,{"children":"num_retry"}],", ",["$","code",null,{"children":"retry_after"}],") on failure"]}],"\n",["$","li",null,{"children":"Logging of the full execution trajectory"}],"\n"]}],"\n",["$","hr",null,{}],"\n",["$","h3",null,{"id":"contextual-overrides","children":[["$","$Ld",null,{"href":"#contextual-overrides","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"Contextual Overrides"]}],"\n",["$","p",null,{"children":"Temporarily override the component's variable or config:"}],"\n",["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"with my_component.context(variable={\"k\": 10}, temperature=0.7):\n output = my_component(input1=\"...\")\n"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"with"}]," my_component",["$","span",null,{"className":"token punctuation","children":"."}],"context",["$","span",null,{"className":"token punctuation","children":"("}],"variable",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token punctuation","children":"{"}],["$","span",null,{"className":"token string","children":"\"k\""}],["$","span",null,{"className":"token punctuation","children":":"}]," ",["$","span",null,{"className":"token number","children":"10"}],["$","span",null,{"className":"token punctuation","children":"}"}],["$","span",null,{"className":"token punctuation","children":","}]," temperature",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token number","children":"0.7"}],["$","span",null,{"className":"token punctuation","children":")"}],["$","span",null,{"className":"token punctuation","children":":"}],"\n"]}],["$","span",null,{"className":"code-line","children":[" output ",["$","span",null,{"className":"token operator","children":"="}]," my_component",["$","span",null,{"className":"token punctuation","children":"("}],"input1",["$","span",null,{"className":"token operator","children":"="}],["$","span",null,{"className":"token string","children":"\"...\""}],["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}]]}]}]}]]}],"\n",["$","p",null,{"children":"Useful for evaluation, debugging, or ablation studies without modifying the global state."}],"\n",["$","hr",null,{}],"\n",["$","h3",null,{"id":"programmatic-updates","children":[["$","$Ld",null,{"href":"#programmatic-updates","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"Programmatic Updates"]}],"\n",["$","div",null,{"className":"relative max-w-full overflow-auto","children":["$","table",null,{"ref":"$undefined","className":"w-full caption-bottom text-sm","children":[["$","thead",null,{"ref":"$undefined","className":"[&_tr]:border-b","children":["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","th",null,{"ref":"$undefined","className":"h-12 !px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0","children":"Method"}],["$","th",null,{"ref":"$undefined","className":"h-12 !px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0","children":"Description"}]]}]}],["$","tbody",null,{"ref":"$undefined","className":"[&_tr:last-child]:border-0","children":[["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","td",null,{"children":["$","code",null,{"children":"update(new_variable)"}]}],["$","td",null,{"children":["Replace the component's ",["$","code",null,{"children":"variable"}]]}]]}],["$","tr",null,{"ref":"$undefined","className":"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted","children":[["$","td",null,{"children":["$","code",null,{"children":"update_config(**kwargs)"}]}],["$","td",null,{"children":["Modify keys in the component's ",["$","code",null,{"children":"config"}]]}]]}]]}]]}]}],"\n",["$","p",null,{"children":"Both methods are thread-safe and apply immediately."}],"\n",["$","hr",null,{}],"\n",["$","h3",null,{"id":"trajectory-logging","children":[["$","$Ld",null,{"href":"#trajectory-logging","aria-hidden":"true","tabIndex":"-1","children":["$","span",null,{"className":"icon icon-link"}],"target":"_blank","rel":"noopener noreferrer"}],"Trajectory Logging"]}],"\n",["$","p",null,{"children":"Each call logs a complete trace of the component's behavior:"}],"\n",["$","div",null,{"className":"my-5 relative group","children":[["$","div",null,{"className":"absolute top-3 right-2.5 z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-200","children":["$","$L1e",null,{"content":"print(my_component.traj)\n# {\n# \"input\": {...},\n# \"output\": {...},\n# \"variable\": {...} # if applicable\n# }\n"}]}],["$","div",null,{"className":"relative","children":["$","pre",null,{"className":"language-python","children":["$","code",null,{"className":"language-python code-highlight","children":[["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token keyword","children":"print"}],["$","span",null,{"className":"token punctuation","children":"("}],"my_component",["$","span",null,{"className":"token punctuation","children":"."}],"traj",["$","span",null,{"className":"token punctuation","children":")"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# {"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# \"input\": {...},"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# \"output\": {...},"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# \"variable\": {...} # if applicable"}],"\n"]}],["$","span",null,{"className":"code-line","children":[["$","span",null,{"className":"token comment","children":"# }"}],"\n"]}]]}]}]}]]}],"\n",["$","p",null,{"children":"This is useful for introspection, analysis, and optimization diagnostics."}],"\n",["$","hr",null,{}]]}],["$","div",null,{"className":"grid grid-cols-2 flex-grow sm:py-10 sm:py-7 py-4 pt-5 gap-5","children":[["$","div",null,{"children":["$","$Ld",null,{"className":"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2 no-underline w-full flex flex-col sm:pl-7 pl-3 sm:py-10 py-8 !items-start text-xs sm:text-sm","href":"/docs/getting-started/guide","children":[["$","span",null,{"className":"flex items-center text-muted-foreground text-xs","children":[["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-chevron-left w-[1rem] h-[1rem] mr-1","children":[["$","path","1wnfg3",{"d":"m15 18-6-6 6-6"}],"$undefined"]}],"Previous"]}],["$","span",null,{"className":"mt-1 ml-1","children":"Quick Start Guide"}]]}]}],["$","div",null,{"children":["$","$Ld",null,{"className":"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2 no-underline w-full flex flex-col sm:pr-7 pr-3 sm:py-10 py-8 !items-end text-xs sm:text-sm","href":"/docs/getting-started/guide/systems","children":[["$","span",null,{"className":"flex items-center text-muted-foreground text-xs","children":["Next",["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-chevron-right w-[1rem] h-[1rem] ml-1","children":[["$","path","mthhwq",{"d":"m9 18 6-6-6-6"}],"$undefined"]}]]}],["$","span",null,{"className":"mt-1 mr-1","children":"Build Systems"}]]}]}]]}]]}]]}]}],"$L26"]}] 1a:[["$","meta","0",{"charSet":"utf-8"}],["$","title","1",{"children":"Build Components"}],["$","meta","2",{"name":"description","content":"Construct the building blocks of compound AI systems."}],["$","meta","3",{"property":"og:title","content":"Build Components"}],["$","meta","4",{"property":"og:description","content":"Construct the building blocks of compound AI systems."}],["$","meta","5",{"property":"og:image:type","content":"image/jpeg"}],["$","meta","6",{"property":"og:image:width","content":"1340"}],["$","meta","7",{"property":"og:image:height","content":"720"}],["$","meta","8",{"property":"og:image","content":"https://optimas.stanford.edu/opengraph-image.jpg?c4738cb8ee63c0c8"}],["$","meta","9",{"name":"twitter:card","content":"summary_large_image"}],["$","meta","10",{"name":"twitter:title","content":"Build Components"}],["$","meta","11",{"name":"twitter:description","content":"Construct the building blocks of compound AI systems."}],["$","meta","12",{"name":"twitter:image:type","content":"image/jpeg"}],["$","meta","13",{"name":"twitter:image:width","content":"1340"}],["$","meta","14",{"name":"twitter:image:height","content":"720"}],["$","meta","15",{"name":"twitter:image","content":"https://optimas.stanford.edu/opengraph-image.jpg?c4738cb8ee63c0c8"}],["$","link","16",{"rel":"icon","href":"/favicon.ico","type":"image/x-icon","sizes":"48x48"}]] 18:null 27:I[257,["459","static/chunks/459-6a59cf064f43bdab.js","933","static/chunks/933-babf0e5c20edcd6a.js","686","static/chunks/686-b7d2cd287b15961f.js","829","static/chunks/829-a236f9036c7c0b48.js","495","static/chunks/495-5ab92bfcd5f906c2.js","32","static/chunks/32-fc39ad8e07d133c3.js","870","static/chunks/app/docs/%5B%5B...slug%5D%5D/page-30c266826d66b2cc.js"],"default"] 26:["$","div",null,{"className":"xl:flex toc hidden w-[20rem] py-9 sticky top-16 h-[96.95vh] pl-6","children":["$","div",null,{"className":"flex flex-col gap-3 w-full pl-2","children":[["$","h3",null,{"className":"font-medium text-sm","children":"On this page"}],["$","$L15",null,{"className":"pb-2 pt-0.5 overflow-y-auto","children":["$","$L27",null,{"data":[{"level":2,"text":"Define a Component","href":"#define-a-component"},{"level":3,"text":"(1) Required Fields","href":"#1-required-fields"},{"level":3,"text":"(2) Required Method","href":"#2-required-method"},{"level":2,"text":"Examples","href":"#examples"},{"level":2,"text":"Create From External Frameworks","href":"#create-from-external-frameworks"},{"level":3,"text":"DSPy","href":"#dspy"},{"level":3,"text":"CrewAI","href":"#crewai"},{"level":3,"text":"AutoGen","href":"#autogen"},{"level":3,"text":"TextGrad","href":"#textgrad"},{"level":3,"text":"OpenAI Agent SDK","href":"#openai-agent-sdk"},{"level":2,"text":"Cheat Sheet: Core Functionalities","href":"#cheat-sheet-core-functionalities"},{"level":3,"text":"Accessing Variables and Configuration","href":"#accessing-variables-and-configuration"},{"level":3,"text":"Executing a Component","href":"#executing-a-component"},{"level":3,"text":"Contextual Overrides","href":"#contextual-overrides"},{"level":3,"text":"Programmatic Updates","href":"#programmatic-updates"},{"level":3,"text":"Trajectory Logging","href":"#trajectory-logging"}]}]}]]}]}]