Skip to content

Commit

Permalink
Merge branch 'main' into build/add-arm64-docker-images
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt authored Apr 17, 2024
2 parents bbf5e72 + b8bd902 commit 7ea42c3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
1 change: 1 addition & 0 deletions packages/backend/src/api/v1/runs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function processParams(params: any) {

const formatRun = (run: any) => ({
id: run.id,
projectId: run.projectId,
isPublic: run.isPublic,
feedback: run.feedback,
parentFeedback: run.parentFeedback,
Expand Down
51 changes: 32 additions & 19 deletions packages/frontend/pages/logs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ import Empty from "@/components/layout/Empty"
import analytics from "@/utils/analytics"
import { formatDateTime } from "@/utils/format"
import { fetcher } from "@/utils/fetcher"
import { useProject, useOrg, useProjectInfiniteSWR } from "@/utils/dataHooks"
import {
useProject,
useOrg,
useProjectInfiniteSWR,
useRun,
} from "@/utils/dataHooks"
import { useDebouncedState, useDidUpdate } from "@mantine/hooks"
import { ProjectContext } from "@/utils/context"
import { CheckLogic, deserializeLogic, serializeLogic } from "shared"
import { useRouter } from "next/router"
import useSWR from "swr"

const columns = {
llm: [
Expand Down Expand Up @@ -138,15 +144,15 @@ const editCheck = (filters, id, params) => {
export default function Logs() {
const router = useRouter()
const { projectId } = useContext(ProjectContext)
const { project, isLoading: projectLoading } = useProject()
const { project, isLoading: projectLoading, setProjectId } = useProject()
const { org } = useOrg()

const [filters, setChecks] = useState<CheckLogic>([
"AND",
{ id: "type", params: { type: "llm" } },
])
const [showCheckBar, setShowCheckBar] = useState(false)
const [selectedId, setSelectedId] = useState<string | null>(null)
const [selectedRunId, setSelectedRunId] = useState<string | null>(null)
const [serializedChecks, setSerializedChecks] = useState<string>("")
const [type, setType] = useState<"llm" | "trace" | "thread">("llm")

Expand All @@ -159,15 +165,22 @@ export default function Logs() {
loadMore,
} = useProjectInfiniteSWR(`/runs?${serializedChecks}`)

const selectedLog = logs?.filter(({ id }) => id === selectedId)[0]
const { run: selectedRun, loading: runLoading } = useRun(selectedRunId)

console.log(selectedRun?.projectId)
useEffect(() => {
if (selectedRun && selectedRun.projectId !== projectId) {
setProjectId(selectedRun.projectId)
}
}, [selectedRun?.projectId])

useDidUpdate(() => {
let serialized = serializeLogic(filters)

if (typeof serialized === "string") {
setSerializedChecks(serialized)
if (selectedId) {
serialized += `&selected=${selectedId}`
if (selectedRunId) {
serialized += `&selected=${selectedRunId}`
}
router.replace(`/logs?${serialized}`)
}
Expand All @@ -179,7 +192,7 @@ export default function Logs() {
const urlParams = new URLSearchParams(window.location.search)

const selectedId = urlParams.get("selected")
setSelectedId(selectedId)
setSelectedRunId(selectedId)

const type = urlParams.get("type")
if (type === "llm" || type === "trace" || type === "thread") {
Expand All @@ -202,10 +215,10 @@ export default function Logs() {
}, [])

useEffect(() => {
if (selectedId) {
if (selectedRunId) {
router.push({
pathname: router.pathname,
query: { ...router.query, selected: selectedId },
query: { ...router.query, selected: selectedRunId },
})
} else {
const { selected, ...query } = router.query
Expand All @@ -215,7 +228,7 @@ export default function Logs() {
query,
})
}
}, [selectedId])
}, [selectedRunId])

useDidUpdate(() => {
// Change type filter and remove filters imcompatible with type
Expand Down Expand Up @@ -380,26 +393,26 @@ export default function Logs() {
</Stack>

<Drawer
opened={!!selectedId}
opened={!!selectedRunId}
size="xl"
keepMounted
position="right"
title={selectedLog ? formatDateTime(selectedLog.createdAt) : ""}
onClose={() => setSelectedId(null)}
title={selectedRun ? formatDateTime(selectedRun.createdAt) : ""}
onClose={() => setSelectedRunId(null)}
>
{loading ? (
{runLoading ? (
<Loader />
) : (
<>
{selectedLog?.type === "llm" && (
{selectedRun?.type === "llm" && (
<RunInputOutput
initialRun={selectedLog}
initialRun={selectedRun}
withPlayground={true}
withShare={true}
/>
)}
{selectedLog?.type === "thread" && (
<ChatReplay run={selectedLog} />
{selectedRun?.type === "thread" && (
<ChatReplay run={selectedRun} />
)}
</>
)}
Expand All @@ -413,7 +426,7 @@ export default function Logs() {
router.push(`/traces/${row.id}`)
} else {
analytics.trackOnce("OpenRun")
setSelectedId(row.id)
setSelectedRunId(row.id)
}
}}
loading={loading || validating}
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/utils/dataHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export function useLogs(params: any) {
return useProjectInfiniteSWR(buildLogsAPIUrl(params))
}

export function useRun(id: string, initialData?: any) {
export function useRun(id: string | null, initialData?: any) {
const {
data: run,
isLoading,
Expand Down

0 comments on commit 7ea42c3

Please sign in to comment.