Skip to content

Commit

Permalink
Rename "requestId" to "documentId"
Browse files Browse the repository at this point in the history
  • Loading branch information
dluc committed Jul 28, 2023
1 parent f2082ed commit 4ddf980
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
12 changes: 6 additions & 6 deletions clients/curl/upload-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Usage:
-f file path Path to the document to upload.
-u userId User ID.
-c "coll1 coll2 .." List of collection IDs separated by a space.
-i uploadId Unique identifier for the upload.
-i document ID Unique identifier for the document uploaded.
-s web service URL Semantic Memory web service URL.
-h Print this help content.
Expand Down Expand Up @@ -50,7 +50,7 @@ readParameters() {
;;
-i)
shift
REQUEST_ID=$1
DOCUMENT_ID=$1
;;
-s)
shift
Expand Down Expand Up @@ -91,8 +91,8 @@ validatePrameters() {
echo "Please specify the list of collection IDs"
exit 3
fi
if [ -z "$REQUEST_ID" ]; then
echo "Please specify a unique upload request ID"
if [ -z "$DOCUMENT_ID" ]; then
echo "Please specify a unique document ID"
exit 4
fi
if [ -z "$SERVICE_URL" ]; then
Expand All @@ -103,7 +103,7 @@ validatePrameters() {

# Remove variables and functions from the environment, in case the script was sourced
cleanupEnv() {
unset FILENAME USER_ID COLLECTIONS REQUEST_ID SERVICE_URL
unset FILENAME USER_ID COLLECTIONS DOCUMENT_ID SERVICE_URL
unset -f help readParameters validatePrameters cleanupEnv exitScript
}

Expand All @@ -127,6 +127,6 @@ done
curl -v \
-F 'file1=@"'"${FILENAME}"'"' \
-F 'user="'"${USER_ID}"'"' \
-F 'requestId="'"${REQUEST_ID}"'"' \
-F 'documentId="'"${DOCUMENT_ID}"'"' \
$COLLECTIONS_FIELD \
$SERVICE_URL
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private async Task ImportFilesInternalAsync(string[] files, ImportFileOptions op
InProcessPipelineOrchestrator orchestrator = await this.Orchestrator.ConfigureAwait(false);

var pipeline = orchestrator
.PrepareNewFileUploadPipeline(options.RequestId, options.UserId, options.CollectionIds);
.PrepareNewFileUploadPipeline(options.DocumentId, options.UserId, options.CollectionIds);

// Include all files
for (int index = 0; index < files.Length; index++)
Expand Down
4 changes: 2 additions & 2 deletions clients/dotnet/MemoryWebClient/MemoryWebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ private async Task ImportFilesInternalAsync(string[] files, ImportFileOptions op
// Populate form with values and files from disk
using var formData = new MultipartFormDataContent();

using var requestIdContent = new StringContent(options.RequestId);
using var documentIdContent = new StringContent(options.DocumentId);
using (var userContent = new StringContent(options.UserId))
{
List<IDisposable> disposables = new();
formData.Add(requestIdContent, "requestId");
formData.Add(documentIdContent, "documentId");
formData.Add(userContent, "user");
foreach (var collectionId in options.CollectionIds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public static async Task RunAsync()
var memory = new MemoryPipelineClient(config);

await memory.ImportFileAsync("file1.txt",
new ImportFileOptions(userId: "user1", collectionId: "collection01", requestId: "upload1"));
new ImportFileOptions(userId: "user1", collectionId: "collection01", documentId: "upload1"));

await memory.ImportFilesAsync(new[] { "file2.txt", "file3.docx", "file4.pdf" },
new ImportFileOptions(userId: "user2", collectionId: "collection01", requestId: "upload2"));
new ImportFileOptions(userId: "user2", collectionId: "collection01", documentId: "upload2"));

await memory.ImportFileAsync("5.docx",
new ImportFileOptions(userId: "user3", collectionId: "collection01", requestId: "upload1"));
new ImportFileOptions(userId: "user3", collectionId: "collection01", documentId: "upload1"));

var owner = "user3";

Expand Down
14 changes: 7 additions & 7 deletions lib/dotnet/Core.NetStandard20/ImportFileOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ImportFileOptions
{
public string UserId { get; set; } = string.Empty;
public List<string> CollectionIds { get; set; } = new();
public string RequestId { get; set; } = string.Empty;
public string DocumentId { get; set; } = string.Empty;

public ImportFileOptions()
{
Expand All @@ -21,26 +21,26 @@ public ImportFileOptions(string userId, string collectionId)
{
}

public ImportFileOptions(string userId, string collectionId, string requestId)
public ImportFileOptions(string userId, string collectionId, string documentId)
{
this.UserId = userId;
this.CollectionIds.Add(collectionId);
this.RequestId = requestId;
this.DocumentId = documentId;
}

public ImportFileOptions(string userId, List<string> collectionIds, string requestId)
public ImportFileOptions(string userId, List<string> collectionIds, string documentId)
{
this.UserId = userId;
this.CollectionIds = collectionIds;
this.RequestId = requestId;
this.DocumentId = documentId;
}

public void Sanitize()
{
if (string.IsNullOrEmpty(this.RequestId))
if (string.IsNullOrEmpty(this.DocumentId))
{
// note: the ID doesn't include the full date, to avoid "personal" details
this.RequestId = Guid.NewGuid().ToString("D") + "-" + DateTimeOffset.UtcNow.ToString("ss.fffffff", CultureInfo.InvariantCulture);
this.DocumentId = Guid.NewGuid().ToString("D") + "-" + DateTimeOffset.UtcNow.ToString("ss.fffffff", CultureInfo.InvariantCulture);
}
}

Expand Down
12 changes: 6 additions & 6 deletions lib/dotnet/Core/WebService/UploadRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.SemanticMemory.Core.WebService;

public class UploadRequest
{
public string RequestId { get; set; } = string.Empty;
public string DocumentId { get; set; } = string.Empty;
public string UserId { get; set; } = string.Empty;
public IEnumerable<string> CollectionIds { get; set; } = new List<string>();
public IEnumerable<IFormFile> Files { get; set; } = new List<IFormFile>();
Expand All @@ -27,7 +27,7 @@ public class UploadRequest
{
const string UserField = "user";
const string CollectionsField = "collections";
const string RequestIdField = "requestId";
const string DocumentIdField = "documentId";

var result = new UploadRequest();

Expand Down Expand Up @@ -59,13 +59,13 @@ public class UploadRequest
return (result, false, $"Invalid or missing collection ID, '{CollectionsField}' list is empty or contains empty values");
}

if (form.TryGetValue(RequestIdField, out StringValues requestIds) && requestIds.Count > 1)
if (form.TryGetValue(DocumentIdField, out StringValues documentIds) && documentIds.Count > 1)
{
return (result, false, $"Invalid request ID, '{RequestIdField}' must be a single value, not a list");
return (result, false, $"Invalid document ID, '{DocumentIdField}' must be a single value, not a list");
}

// Request Id is optional, e.g. the client wants to retry the same upload, otherwise we generate a random/unique one
result.RequestId = requestIds.FirstOrDefault() ?? DateTimeOffset.Now.ToString("yyyyMMdd.HHmmss.", CultureInfo.InvariantCulture) + Guid.NewGuid().ToString("N");
// Document Id is optional, e.g. used if the client wants to retry the same upload, otherwise we generate a random/unique one
result.DocumentId = documentIds.FirstOrDefault() ?? DateTimeOffset.Now.ToString("yyyyMMdd.HHmmss.", CultureInfo.InvariantCulture) + Guid.NewGuid().ToString("N");

result.UserId = userIds[0]!;
result.CollectionIds = collectionIds;
Expand Down
4 changes: 2 additions & 2 deletions server/combinedservices-dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
return Results.BadRequest(errMsg);
}

log.LogInformation("Queueing upload of {0} files for further processing [request {1}]", input.Files.Count(), input.RequestId);
var containerId = $"usr.{input.UserId}.op.{input.RequestId}";
log.LogInformation("Queueing upload of {0} files for further processing [request {1}]", input.Files.Count(), input.DocumentId);
var containerId = $"usr.{input.UserId}.op.{input.DocumentId}";

// Define all the steps in the pipeline
var pipeline = orchestrator
Expand Down
4 changes: 2 additions & 2 deletions server/webservice-dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
return Results.BadRequest(errMsg);
}

log.LogInformation("Queueing upload of {0} files for further processing [request {1}]", input.Files.Count(), input.RequestId);
var containerId = $"usr.{input.UserId}.op.{input.RequestId}";
log.LogInformation("Queueing upload of {0} files for further processing [request {1}]", input.Files.Count(), input.DocumentId);
var containerId = $"usr.{input.UserId}.op.{input.DocumentId}";

// Define all the steps in the pipeline
var pipeline = orchestrator
Expand Down

0 comments on commit 4ddf980

Please sign in to comment.