Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

functions

Vasek Mlejnsky03becb107aa9
diff --git a/components/AgentFunctions.tsx b/components/AgentFunctions.tsx
new file mode 100644
index 000000000..138a4e5bf
--- /dev/null
+++ b/components/AgentFunctions.tsx
@@ -0,0 +1,125 @@
+import {
+ useState,
+} from 'react'
+import clsx from 'clsx'
+import {
+ ChevronRight,
+} from 'lucide-react'
+
+import { AgentFunction } from 'utils/agentLogs'
+
+export interface Props {
+ functions: AgentFunction[]
+}
+function AgentFunctions({
+ functions,
+}: Props) {
+ const [opened, setOpened] = useState<number[]>([])
+
+ function open(idx: number) {
+ setOpened(opened => [...opened, idx])
+ }
+
+ function close(idx: number) {
+ setOpened(opened => opened.filter(i => i !== idx))
+ }
+
+ function toggle(idx: number) {
+ if (opened.includes(idx)) {
+ close(idx)
+ } else {
+ open(idx)
+ }
+ }
+
+ function sortAlphabetically(fns: AgentFunction[]) {
+ return fns.sort((a, b) => {
+ if (a.name < b.name) {
+ return -1
+ }
+ if (a.name > b.name) {
+ return 1
+ }
+
+ return 0
+ })
+ }
+
+ console.log('functions', functions)
+
+ return (
+ <div className="flex-1 flex flex-col space-y-2 max-w-full w-full overflow-hidden">
+ <h2 className="font-bold text-gray-500">Functions</h2>
+
+ <div className="flex-1 flex flex-col space-y-3 max-w-full w-full overflow-auto">
+ {sortAlphabetically([...functions]).map((fn, idx) => (
+ <div key={idx} className="flex flex-col space-y-2">
+ <div className="group flex items-center space-x-2">
+ <div
+ className={clsx(
+ 'p-1 cursor-pointer hover:bg-gray-700 transition-all rounded-md',
+ opened.includes(idx) && 'bg-gray-700',
+ !opened.includes(idx) && 'bg-gray-800',
+ )}
+ onClick={() => toggle(idx)}
+ >
+ <ChevronRight size={15} className={clsx(
+ 'text-gray-400',
+ 'transition-all',
+ 'select-none',
+ opened.includes(idx) && 'rotate-90',
+ )} />
+ </div>
+
+ <span
+ className={clsx(
+ 'rounded-md',
+ 'py-0.5',
+ 'px-2',
+ 'hover:bg-gray-800',
+ 'transition-all',
+ 'w-full',
+ 'text-sm',
+ 'cursor-pointer',
+ 'font-mono',
+ opened.includes(idx) && 'bg-gray-800',
+ opened.includes(idx) && 'font-semibold',
+ )}
+ onClick={() => toggle(idx)}
+ >
+ {fn.name}
+ </span>
+ </div>
+
+ {opened.includes(idx) && (
+ <div className="px-[12px] flex items-start space-x-5 w-full">
+ <div className="w-px self-stretch border-r border-gray-800 rounded" />
+ <div className="flex flex-col space-y-3 w-full">
+ {!fn.description && !fn.parameters && (
+ <span className="text-sm text-gray-300">No description or parameters</span>
+ )}
+
+ {fn.description && (
+ <div className="flex flex-col space-y-1">
+ <span className="text-sm font-bold text-gray-400">Description</span>
+ <span className="text-sm text-gray-200">{fn.description}</span>
+ </div>
+ )}
+
+ {fn.parameters && (
+ <div className="flex flex-col space-y-1">
+ <span className="text-sm font-bold text-gray-400">Parameters</span>
+ <span className="text-sm text-gray-200">{fn.description}</span>
+ </div>
+ )}
+ </div>
+ </div>
+ )}
+ </div>
+ ))}
+ </div>
+ </div>
+ )
+}
+
+export default AgentFunctions
\ No newline at end of file
diff --git a/pages/log/[logFileID].tsx b/pages/log/[logFileID].tsx
index 83990a78b..af5aeee59 100644
--- a/pages/log/[logFileID].tsx
+++ b/pages/log/[logFileID].tsx
@@ -10,6 +10,7 @@ import Link from 'next/link'
import { prisma } from 'db/prisma'
import { serverCreds } from 'db/credentials'
+import AgentFunctions from 'components/AgentFunctions'
interface PathProps extends ParsedUrlQuery {
@@ -131,7 +132,7 @@ function LogFile({ logFile }: Props) {
<h1 className="text-2xl font-semibold leading-7 text-white font-mono">{logFile.name}</h1>
</header>
- <div className="flex-1 flex items-start justify-start sm:p-6 lg:px-8">
+ <div className="flex-1 flex items-start justify-start sm:p-6 lg:px-8 overflow-hidden">
<Splitter
draggerClassName={clsx(
'bg-gray-700 group-hover:bg-[#6366F1] transition-all delay-75 duration-[400ms] w-0.5 h-full',
@@ -149,15 +150,9 @@ function LogFile({ logFile }: Props) {
}}
initialSizes={sizes}
>
- <div className="flex flex-col space-y-4 max-w-full overflow-auto">
- <h2 className="font-bold text-gray-500">Functions</h2>
- {logFile.content.functions.map((fn, idx) => (
- <div key={idx} className="shadow sm:rounded-md">
- {fn.name}
- </div>
- ))}
- </div>
-
+ <AgentFunctions
+ functions={logFile.content.functions}
+ />
<div className="flex flex-col space-y-4 max-w-full overflow-auto">
<h2 className="font-bold text-gray-500">Logs</h2>
{logFile.content.context.map((ctx, idx) => (
diff --git a/pages/log/logfile.json b/pages/log/logfile.json
deleted file mode 100644
index d15215f76..000000000
--- a/pages/log/logfile.json
+++ /dev/null
@@ -1,43 +0,0 @@
-{
- "context": [
- {
- "role": "assistant",
- "content": "this is content",
- "function_call": {
- "name": "human_feedback",
- "arguments": "{\"url\": \"https://www.floatplane.com\", \"question\": \"styling information\"}"
- }
- },
- {
- "role": "system",
- "content": "I just performed the previous task for you. Here is the result: Human feedback: try using curl or a similar function to retrieve the information"
- },
- {
- "role": "user",
- "content": "Determine one function to call. Respond using the JSON schema specified previously:"
- }
- ],
- "functions": [
- {
- "name": "execute_python_code",
- "description": "Create a Python file and execute it",
- "parameters": {
- "type": "object",
- "properties": {
- "code": {
- "type": "string",
- "description": "The Python code to run"
- },
- "name": {
- "type": "string",
- "description": "A name to be given to the python file"
- }
- },
- "required": [
- "code",
- "name"
- ]
- }
- }
- ]
-}
\ No newline at end of file