-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance external image hosting in agent configuration #4565
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
30ef522
Strengthen external image hosting in agent configuration
flvndvd a8bebec
:scissors:
flvndvd 21620f8
:scissors:
flvndvd a86e7f9
:scissors:
flvndvd dfd21f3
Apply new DFS logic to content fragment + refactor
flvndvd 55fd80f
Accept static hosted Dust Avatars
flvndvd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,15 @@ | ||
import { EnvironmentConfig } from "@dust-tt/types"; | ||
|
||
const config = { | ||
getServiceAccount: (): string => { | ||
return EnvironmentConfig.getEnvVariable("SERVICE_ACCOUNT"); | ||
}, | ||
getGcsPublicUploadBucket: (): string => { | ||
return EnvironmentConfig.getEnvVariable("DUST_UPLOAD_BUCKET"); | ||
}, | ||
getGcsPrivateUploadsBucket: (): string => { | ||
return EnvironmentConfig.getEnvVariable("DUST_PRIVATE_UPLOADS_BUCKET"); | ||
}, | ||
}; | ||
|
||
export default config; |
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,92 @@ | ||
import type { Bucket } from "@google-cloud/storage"; | ||
import { Storage } from "@google-cloud/storage"; | ||
import type formidable from "formidable"; | ||
import fs from "fs"; | ||
import { pipeline } from "stream/promises"; | ||
|
||
import config from "@app/lib/dfs/config"; | ||
|
||
type BucketKeyType = "PRIVATE_UPLOAD" | "PUBLIC_UPLOAD"; | ||
|
||
const storage = new Storage({ | ||
keyFilename: config.getServiceAccount(), | ||
}); | ||
|
||
const bucketKeysToBucket: Record<BucketKeyType, Bucket> = { | ||
PRIVATE_UPLOAD: storage.bucket(config.getGcsPrivateUploadsBucket()), | ||
PUBLIC_UPLOAD: storage.bucket(config.getGcsPublicUploadBucket()), | ||
}; | ||
|
||
class DFS { | ||
private readonly bucket: Bucket; | ||
|
||
constructor(bucketKey: BucketKeyType) { | ||
this.bucket = bucketKeysToBucket[bucketKey]; | ||
} | ||
|
||
/** | ||
* Upload functions. | ||
*/ | ||
|
||
async uploadFileToBucket(file: formidable.File, destPath: string) { | ||
const gcsFile = this.file(destPath); | ||
const fileStream = fs.createReadStream(file.filepath); | ||
|
||
await pipeline( | ||
fileStream, | ||
gcsFile.createWriteStream({ | ||
metadata: { | ||
contentType: file.mimetype, | ||
}, | ||
}) | ||
); | ||
} | ||
|
||
async uploadRawContentToBucket({ | ||
content, | ||
contentType, | ||
filePath, | ||
}: { | ||
content: string; | ||
contentType: string; | ||
filePath: string; | ||
}) { | ||
const gcsFile = this.file(filePath); | ||
|
||
await gcsFile.save(content, { | ||
contentType, | ||
}); | ||
} | ||
|
||
/** | ||
* Download functions. | ||
*/ | ||
|
||
async fetchFileContent(filePath: string) { | ||
const gcsFile = this.file(filePath); | ||
|
||
const [content] = await gcsFile.download(); | ||
|
||
return content.toString(); | ||
} | ||
|
||
async getFileContentType(filename: string): Promise<string | null> { | ||
const gcsFile = this.file(filename); | ||
|
||
const [metadata] = await gcsFile.getMetadata(); | ||
|
||
return metadata.contentType; | ||
} | ||
|
||
file(filename: string) { | ||
return this.bucket.file(filename); | ||
} | ||
|
||
get name() { | ||
return this.bucket.name; | ||
} | ||
} | ||
|
||
export const getPrivateUploadBucket = () => new DFS("PRIVATE_UPLOAD"); | ||
|
||
export const getPublicUploadBucket = () => new DFS("PUBLIC_UPLOAD"); |
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
50 changes: 20 additions & 30 deletions
50
front/pages/api/w/[wId]/assistant/agent_configurations/avatar.ts
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gcs
rather thandfs
in name no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stick with DFS for this file/class but all other occurrences will go with GCS.