Skip to content

Commit

Permalink
Fix custom hypha-workspaces bug
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Sep 4, 2024
1 parent 45de5fe commit 3c7c2b8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
58 changes: 55 additions & 3 deletions docs/operate-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ python3 -m hypha.server \
```

### Arguments:

- `--enable-s3`: Enables S3 object storage.
- `--access-key-id`: Access key for the S3 server.
- `--secret-access-key`: Secret key for the S3 server.
- `--endpoint-url`: The internal URL for Hypha to access the S3 server.
- `--endpoint-url-public`: Public URL for accessing the files (may be the same as `--endpoint-url`).
- `--s3-admin-type`: Specifies the S3 admin type (e.g., `minio`, `generic`).
- `--s3-admin-type`: Specifies the S3 admin type (e.g., `minio`, `generic`). If it's a minio server (not gateway mode), use `minio`, otherwise use `generic` would be enough for most cases.

After starting Hypha with these arguments, you can verify that the S3 service is available by visiting the following URL:

Expand Down Expand Up @@ -144,6 +143,57 @@ def operate_files_with_boto(info):
# operate_files_with_boto(info)
```

#### ** AWS SDK (JavaScript) **

```javascript
import { S3Client, PutObjectCommand, ListObjectsV2Command } from "@aws-sdk/client-s3";

const api = await connectToServer({ "server_url": "https://hypha.aicell.io" });
const s3Controller = await api.getService("public/s3-storage");
const info = await s3Controller.generateCredential();

const s3Client = new S3Client({
region: info.region_name,
endpoint: info.endpoint_url,
credentials: {
accessKeyId: info.access_key_id,
secretAccessKey: info.secret_access_key,
},
});

async function uploadFileToS3(file) {
try {
const uploadParams = {
Bucket: info.bucket,
Key: info.prefix + file.name,
Body: file,
};
const data = await s3Client.send(new PutObjectCommand(uploadParams));
console.log("File uploaded successfully:", data);
} catch (err) {
console.error("Error uploading file:", err);
}
}

async function listFilesInS3() {
try {
const listParams = {
Bucket: info.bucket,
Prefix: info.prefix,
};
const data = await s3Client.send(new ListObjectsV2Command(listParams));
data.Contents.forEach((obj) => console.log(obj.Key));
} catch (err) {
console.error("Error listing files:", err);
}
}

// Example usage:
// const fileInput = document.getElementById("fileInput").files[0];
// uploadFileToS3(fileInput);
// listFilesInS3();
```

<!-- tabs:end -->

### 2. Using Presigned URLs
Expand Down Expand Up @@ -185,7 +235,9 @@ async def upload_file(presigned_url: str, file_path: str):
response = await client.put(presigned_url, content=file)
print(response.status_code, response.reason_phrase)

# Example usage:
#

Example usage:
# asyncio.run(upload_file(upload_url, "myfile.txt"))
```

Expand Down
2 changes: 1 addition & 1 deletion helm-chart/hypha-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ image:
repository: ghcr.io/amun-ai/hypha
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "0.20.33.post2"
tag: "0.20.33.post3"

imagePullSecrets: []
nameOverride: ""
Expand Down
2 changes: 1 addition & 1 deletion hypha/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.20.33.post2"
"version": "0.20.33.post3"
}
3 changes: 3 additions & 0 deletions hypha/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def start_builtin_services(
endpoint_url=args.endpoint_url,
access_key_id=args.access_key_id,
secret_access_key=args.secret_access_key,
region_name=args.region_name,
workspace_bucket=args.workspace_bucket,
)

Expand All @@ -124,6 +125,8 @@ def start_builtin_services(
endpoint_url=args.endpoint_url,
access_key_id=args.access_key_id,
secret_access_key=args.secret_access_key,
region_name=args.region_name,
workspace_bucket=args.workspace_bucket,
base_path=args.base_path,
)

Expand Down

0 comments on commit 3c7c2b8

Please sign in to comment.