-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
922 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Add directories or file patterns to ignore during indexing (e.g. foo/ or *.csv) | ||
node_modules | ||
drizzle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
version: 0.0 | ||
Resources: | ||
- TargetService: | ||
Type: AWS::ECS::Service | ||
Properties: | ||
TaskDefinition: arn:aws:ecs:eu-central-1:442420265876:task-definition/LatitudeLLMTaskFamily:91 | ||
LoadBalancerInfo: | ||
ContainerName: "LatitudeLLMAppContainer" | ||
ContainerPort: 8080 | ||
- TargetService: | ||
Type: AWS::ECS::Service | ||
Properties: | ||
TaskDefinition: arn:aws:ecs:eu-central-1:442420265876:task-definition/LatitudeLLMTaskFamily:92 | ||
LoadBalancerInfo: | ||
ContainerName: 'LatitudeLLMAppContainer' | ||
ContainerPort: 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
'use server' | ||
|
||
import { | ||
ChainObjectResponse, | ||
Dataset, | ||
StreamEventTypes, | ||
} from '@latitude-data/core/browser' | ||
import { BadRequestError } from '@latitude-data/core/lib/errors' | ||
import { createDataset } from '@latitude-data/core/services/datasets/create' | ||
import { ChainEventDto } from '@latitude-data/sdk' | ||
import slugify from '@sindresorhus/slugify' | ||
import { createSdk } from '$/app/(private)/_lib/createSdk' | ||
import env from '$/env' | ||
import { getCurrentUser } from '$/services/auth/getCurrentUser' | ||
import { createStreamableValue } from 'ai/rsc' | ||
|
||
type GenerateDatasetActionProps = { | ||
parameters: Record<string, unknown> | ||
description: string | ||
rowCount: number | ||
name: string | ||
} | ||
|
||
export async function generateDatasetAction({ | ||
parameters, | ||
description, | ||
rowCount, | ||
name, | ||
}: GenerateDatasetActionProps) { | ||
if (!env.DATASET_GENERATOR_PROJECT_ID) { | ||
throw new BadRequestError('DATASET_GENERATOR_PROJECT_ID is not set') | ||
} | ||
if (!env.DATASET_GENERATOR_DOCUMENT_PATH) { | ||
throw new BadRequestError('DATASET_GENERATOR_DOCUMENT_PATH is not set') | ||
} | ||
if (!env.DATASET_GENERATOR_WORKSPACE_APIKEY) { | ||
throw new BadRequestError('DATASET_GENERATOR_WORKSPACE_APIKEY is not set') | ||
} | ||
|
||
let response: Dataset | undefined | ||
const { user, workspace } = await getCurrentUser() | ||
const stream = createStreamableValue< | ||
{ event: StreamEventTypes; data: ChainEventDto }, | ||
Error | ||
>() | ||
const sdk = await createSdk({ | ||
apiKey: env.DATASET_GENERATOR_WORKSPACE_APIKEY, | ||
projectId: env.DATASET_GENERATOR_PROJECT_ID, | ||
}).then((r) => r.unwrap()) | ||
const sdkResponse = await sdk.run(env.DATASET_GENERATOR_DOCUMENT_PATH, { | ||
parameters: { | ||
row_count: rowCount, | ||
parameters, | ||
user_message: description, | ||
}, | ||
onError: (error) => { | ||
stream.error({ | ||
name: error.name, | ||
message: error.message, | ||
stack: error.stack, | ||
}) | ||
}, | ||
}) | ||
|
||
try { | ||
const sdkResult = await sdkResponse | ||
const csv = (sdkResult?.response! as ChainObjectResponse).object.csv | ||
const result = await createDataset({ | ||
author: user, | ||
workspace, | ||
data: { | ||
name, | ||
file: new File([csv], `${slugify(name)}.csv`, { type: 'text/csv' }), | ||
csvDelimiter: ',', | ||
}, | ||
}) | ||
if (result.error) { | ||
stream.error({ | ||
name: result.error.name, | ||
message: result.error.message, | ||
stack: result.error.stack, | ||
}) | ||
} else { | ||
response = result.value | ||
stream.done() | ||
} | ||
} catch (error) { | ||
stream.error({ | ||
name: (error as Error).name, | ||
message: (error as Error).message, | ||
stack: (error as Error).stack, | ||
}) | ||
} | ||
|
||
return { | ||
output: stream.value, | ||
response, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use server' | ||
|
||
import { StreamEventTypes } from '@latitude-data/core/browser' | ||
import { BadRequestError } from '@latitude-data/core/lib/errors' | ||
import { ChainEventDto } from '@latitude-data/sdk' | ||
import { createSdk } from '$/app/(private)/_lib/createSdk' | ||
import env from '$/env' | ||
import { createStreamableValue } from 'ai/rsc' | ||
|
||
type RunDocumentActionProps = { | ||
projectId: number | ||
documentUuid: string | ||
parameters: Record<string, unknown> | ||
description: string | ||
} | ||
|
||
export async function generateDatasetPreviewAction({ | ||
parameters, | ||
description, | ||
}: RunDocumentActionProps) { | ||
const stream = createStreamableValue< | ||
{ event: StreamEventTypes; data: ChainEventDto }, | ||
Error | ||
>() | ||
if (!env.DATASET_GENERATOR_PROJECT_ID) { | ||
throw new BadRequestError('DATASET_GENERATOR_PROJECT_ID is not set') | ||
} | ||
if (!env.DATASET_GENERATOR_DOCUMENT_PATH) { | ||
throw new BadRequestError('DATASET_GENERATOR_DOCUMENT_PATH is not set') | ||
} | ||
if (!env.DATASET_GENERATOR_WORKSPACE_APIKEY) { | ||
throw new BadRequestError('DATASET_GENERATOR_WORKSPACE_APIKEY is not set') | ||
} | ||
|
||
const sdk = await createSdk({ | ||
apiKey: env.DATASET_GENERATOR_WORKSPACE_APIKEY, | ||
projectId: env.DATASET_GENERATOR_PROJECT_ID, | ||
}).then((r) => r.unwrap()) | ||
const response = await sdk.run(env.DATASET_GENERATOR_DOCUMENT_PATH, { | ||
parameters: { | ||
row_count: 10, | ||
parameters, | ||
user_message: description, | ||
}, | ||
onEvent: (event) => { | ||
stream.update(event) | ||
}, | ||
onError: (error) => { | ||
stream.error({ | ||
name: error.name, | ||
message: error.message, | ||
stack: error.stack, | ||
}) | ||
}, | ||
onFinished: () => { | ||
stream.done() | ||
}, | ||
}) | ||
|
||
return { | ||
output: stream.value, | ||
response, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
apps/web/src/app/(private)/datasets/generate/CsvPreviewTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
Text, | ||
} from '@latitude-data/web-ui' | ||
|
||
interface CsvPreviewTableProps { | ||
csvData: { | ||
headers: string[] | ||
data: { | ||
record: Record<string, string> | ||
info: { columns: { name: string }[] } | ||
}[] | ||
} | ||
} | ||
|
||
export function CsvPreviewTable({ csvData }: CsvPreviewTableProps) { | ||
return ( | ||
<Table> | ||
<TableHeader> | ||
<TableRow> | ||
{csvData.headers.map((header, index) => ( | ||
<TableHead key={index}> | ||
<Text.H5>{header}</Text.H5> | ||
</TableHead> | ||
))} | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{csvData.data.map(({ record }, rowIndex) => ( | ||
<TableRow key={rowIndex} hoverable={false}> | ||
{csvData.headers.map((header, cellIndex) => ( | ||
<TableCell key={cellIndex}> | ||
<div className='py-1'> | ||
<Text.H5>{record[header]}</Text.H5> | ||
</div> | ||
</TableCell> | ||
))} | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
) | ||
} |
Oops, something went wrong.