Skip to content

Commit

Permalink
Merge branch 'main' into feat/markdown-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt authored Jun 21, 2024
2 parents 0f240e3 + 974550d commit 2d66e44
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 52 deletions.
24 changes: 3 additions & 21 deletions packages/backend/src/api/v1/runs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,39 +150,21 @@ runs.get("/", async (ctx: Context) => {
eu.last_seen as user_last_seen,
eu.props as user_props,
t.slug as template_slug,
rpfc.feedback as parent_feedback,
coalesce(array_agg(
jsonb_build_object(
'evaluatorName', e.name,
'evaluatorSlug', e.slug,
'evaluatorId', e.id,
'result', er.result,
'createdAt', er.created_at,
'updatedAt', er.updated_at
)
) filter (where er.run_id is not null), '{}') as evaluation_results
rpfc.feedback as parent_feedback
from
public.run r
run r
left join external_user eu on r.external_user_id = eu.id
left join run_parent_feedback_cache rpfc on r.id = rpfc.id
left join template_version tv on r.template_version_id = tv.id
left join template t on tv.template_id = t.id
left join evaluation_result_v2 er on r.id = er.run_id
left join evaluator e on er.evaluator_id = e.id
where
r.project_id = ${projectId}
${parentRunCheck}
and (${filtersQuery})
group by
r.id,
eu.id,
t.slug,
rpfc.feedback
order by
r.created_at desc
limit ${exportType ? 10000 : Number(limit)}
offset ${Number(page) * Number(limit)}
`
offset ${Number(page) * Number(limit)}`

const runs = rows.map(formatRun)

Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/checks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ export const CHECK_RUNNERS: CheckRunner[] = [
{
id: "search",
sql: ({ query }) =>
sql`(to_tsvector('simple', substring(r.input_text, 1, 948575)) @@ plainto_tsquery('simple', ${query})
or to_tsvector('simple', substring(r.output_text, 1, 948575)) @@ plainto_tsquery('simple', ${query}))`,
sql`(r.input_text ilike ${`%${query}%`} or r.output_text ilike ${`%${query}%`})`,
},
{
id: "string",
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ function debugFn(
parameters: any[],
paramTypes: any[],
) {
// for (let i = 0; i <= parameters.length; i++) {
// let regex = new RegExp(`\\$${i + 1}`, "g")
// query = query.replace(regex, `'${parameters[i]}'`)
// }

console.log("connection:", connection)
console.log("query:", query)
console.log("parameters:", parameters)
Expand Down
2 changes: 2 additions & 0 deletions packages/db/0021.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create index on run using gin (input_text gin_trgm_ops);
create index on run using gin (output_text gin_trgm_ops);
10 changes: 8 additions & 2 deletions packages/frontend/components/analytics/BarList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ type BarListProps = {
data: any[]
filterZero?: boolean
columns: {
key: string
name?: string
key?: string
main?: boolean // Use this column for the bar chart calculations?
bar?: boolean // Bar chart column ?
render?: (value, row?) => React.ReactNode
Expand Down Expand Up @@ -37,7 +37,7 @@ function BarList({ data, columns, filterZero = true }: BarListProps) {
<Table.Thead style={{ textAlign: "left" }}>
<Table.Tr>
{columns.map(({ name }, i) => (
<th style={{ width: i === 0 ? "50%" : "25%" }} key={i}>
<th style={{ width: i === 0 ? "60%" : "25%" }} key={i}>
{name || ""}
</th>
))}
Expand Down Expand Up @@ -77,6 +77,7 @@ function BarList({ data, columns, filterZero = true }: BarListProps) {
</Progress.Root>
<Flex
w="90%"
px="sm"
h="25px"
pos="absolute"
align="center"
Expand All @@ -88,7 +89,12 @@ function BarList({ data, columns, filterZero = true }: BarListProps) {
size="12px"
style={{
textAlign: "center",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
overflow: "hidden",
padding: ".3rem",
}}
title={item.value}
>
{item.value}
</Text>
Expand Down
47 changes: 20 additions & 27 deletions packages/frontend/components/prompts/PromptVariableEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import {
Badge,
Box,
Group,
Stack,
Text,
Textarea,
Tooltip,
} from "@mantine/core"
import { Badge, Box, Group, Stack, Text, Tooltip } from "@mantine/core"
import { IconInfoCircle } from "@tabler/icons-react"
import { TemplateVariables } from "shared"
import VariableTextarea from "./VariableTextarea"

export default function PromptVariableEditor({
value = {},
value: templateVariables = {},
onChange,
}: {
value: TemplateVariables
onChange: (value: TemplateVariables) => void
}) {
const hasVariables = Object.keys(value).length > 0
const hasVariables = Object.keys(templateVariables).length > 0

return (
<Box>
<Group mb="md" align="center" justify="space-between">
Expand All @@ -35,40 +29,39 @@ export default function PromptVariableEditor({
</Text>
)}
<Stack mt="sm">
{Object.keys(value)
.sort()
.map((variable) => (
{Object.entries(templateVariables)
.sort(([nameA], [nameB]) => nameA.localeCompare(nameB))
.map(([name, value]) => (
<Group
key={variable}
key={name}
align="center"
wrap="nowrap"
justify="space-between"
gap="lg"
>
<Badge
key={variable}
miw={30}
maw="34%"
miw={70}
px={0}
key={name}
miw={50}
maw={90}
px="sm"
variant="outline"
tt="none"
>
{variable}
{name}
</Badge>
<Textarea
<VariableTextarea
size="xs"
w="100%"
required={true}
radius="sm"
rows={1}
autosize
maxRows={4}
defaultValue={value[variable]}
maxRows={1}
name={name}
value={value}
onChange={(e) =>
onChange({
...value,
[variable]: e.currentTarget.value,
...templateVariables,
[name]: e.currentTarget.value,
})
}
/>
Expand Down
73 changes: 73 additions & 0 deletions packages/frontend/components/prompts/VariableTextarea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
ActionIcon,
Box,
Button,
Modal,
Text,
Textarea,
TextareaProps,
Title,
} from "@mantine/core"
import { useDisclosure } from "@mantine/hooks"
import { IconArrowsMaximize } from "@tabler/icons-react"

type VariableTextareaProps = TextareaProps & {
name: string
value: string
}

export default function VariableTextarea({
name,
value,
onChange,
...props
}: VariableTextareaProps) {
const [opened, { open, close }] = useDisclosure(false)

return (
<>
<Modal
opened={opened}
onClose={close}
title={<Title order={3}>Edit variable</Title>}
overlayProps={{
backgroundOpacity: 0.55,
blur: 3,
}}
size="xl"
>
<Textarea
size="md"
radius="sm"
minRows={2}
rows={10}
autosize
value={value}
onChange={onChange}
/>

<Button my="md" style={{ float: "right" }} onClick={close}>
Save
</Button>
</Modal>

<Box style={{ position: "relative" }}>
<Textarea {...props} onChange={onChange} value={value} />
<ActionIcon
size="xs"
onClick={open}
aria-label="expand textarea"
variant="transparent"
style={{
position: "absolute",
right: "5%",
bottom: "5%",
marginBottom: "0.3rem",
}}
>
<IconArrowsMaximize />
</ActionIcon>
</Box>
</>
)
}

0 comments on commit 2d66e44

Please sign in to comment.