-
Notifications
You must be signed in to change notification settings - Fork 163
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
21 changed files
with
644 additions
and
15 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,99 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Box.V2.Models; | ||
using Box.V2.Test.Integration.Configuration; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Box.V2.Test.Integration | ||
{ | ||
[TestClass] | ||
public class BoxAIManagerIntegrationTests : TestInFolder | ||
{ | ||
[TestMethod] | ||
public async Task SendAIQuestionAsync_ForSingleItem_ReturnsValidResponse() | ||
{ | ||
var fileName = "[Single Item AI] Test File.txt"; | ||
var fileContent = "Test file"; | ||
var uploadedFile = await CreateSmallFromMemoryStream(FolderId, fileName, fileContent); | ||
|
||
var request = new BoxAIAskRequest | ||
{ | ||
Prompt = "What is the name of the file?", | ||
Items = new List<BoxAIAskItem>() { new BoxAIAskItem() { Id = uploadedFile.Id } }, | ||
Mode = AiAskMode.single_item_qa | ||
}; | ||
|
||
await Retry(async () => | ||
{ | ||
var response = await UserClient.BoxAIManager.SendAIQuestionAsync(request); | ||
|
||
Assert.IsTrue(response.Answer.Contains(fileContent)); | ||
Assert.IsTrue(response.CreatedAt < DateTimeOffset.Now); | ||
Assert.AreEqual(response.CompletionReason, "done"); | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public async Task SendAIQuestionAsync_ForMultipleItems_ReturnsValidResponse() | ||
{ | ||
var fileContent = "Test file"; | ||
|
||
var fileName1 = "[Multi Item AI] First Test File.txt"; | ||
var uploadedFile1 = await CreateSmallFromMemoryStream(FolderId, fileName1, fileContent); | ||
|
||
var fileName2 = "[Multi Item AI] Second test file.txt"; | ||
var uploadedFile2 = await CreateSmallFromMemoryStream(FolderId, fileName2, fileContent); | ||
|
||
var request = new BoxAIAskRequest | ||
{ | ||
Prompt = "What is the content of these files?", | ||
Items = new List<BoxAIAskItem>() | ||
{ | ||
new BoxAIAskItem() { Id = uploadedFile1.Id }, | ||
new BoxAIAskItem() { Id = uploadedFile2.Id } | ||
}, | ||
Mode = AiAskMode.multiple_item_qa | ||
}; | ||
|
||
await Retry(async () => | ||
{ | ||
var response = await UserClient.BoxAIManager.SendAIQuestionAsync(request); | ||
|
||
Assert.IsTrue(response.Answer.Contains(fileContent)); | ||
Assert.IsTrue(response.CreatedAt < DateTimeOffset.Now); | ||
Assert.AreEqual(response.CompletionReason, "done"); | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public async Task SendTextGenRequestAsync_ForValidPayload_ReturnsValidResponse() | ||
{ | ||
var fileName = "[AI Text Gen] Test File.txt"; | ||
var fileContent = "Test File"; | ||
var uploadedFile = await CreateSmallFromMemoryStream(FolderId, fileName, fileContent); | ||
var date1 = DateTimeOffset.Parse("2013-05-16T15:27:57-07:00"); | ||
var date2 = DateTimeOffset.Parse("2013-05-16T15:26:57-07:00"); | ||
|
||
var request = new BoxAITextGenRequest | ||
{ | ||
Prompt = "What is the name of the file?", | ||
Items = new List<BoxAITextGenItem>() { new BoxAITextGenItem() { Id = uploadedFile.Id } }, | ||
DialogueHistory = new List<BoxAIDialogueHistory>() | ||
{ | ||
new BoxAIDialogueHistory() { Prompt = "What is the name of the file?", Answer = fileContent, CreatedAt = date1 }, | ||
new BoxAIDialogueHistory() { Prompt = "What is the size of the file?", Answer = "10kb", CreatedAt = date2 } | ||
} | ||
}; | ||
|
||
await Retry(async () => | ||
{ | ||
var response = await UserClient.BoxAIManager.SendAITextGenRequestAsync(request); | ||
|
||
Assert.IsTrue(response.Answer.Contains(fileContent)); | ||
Assert.IsTrue(response.CreatedAt < DateTimeOffset.Now); | ||
Assert.AreEqual(response.CompletionReason, "done"); | ||
}); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Box.V2.Managers; | ||
using Box.V2.Models; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
|
||
namespace Box.V2.Test | ||
{ | ||
[TestClass] | ||
public class BoxAIManagerTest : BoxResourceManagerTest | ||
{ | ||
private readonly BoxAIManager _aiManager; | ||
|
||
public BoxAIManagerTest() | ||
{ | ||
_aiManager = new BoxAIManager(Config.Object, Service, Converter, AuthRepository); | ||
} | ||
|
||
[TestMethod] | ||
public async Task SendAiQuestionAsync_Success() | ||
{ | ||
/** Arrange **/ | ||
IBoxRequest boxRequest = null; | ||
Handler.Setup(h => h.ExecuteAsync<BoxAIResponse>(It.IsAny<IBoxRequest>())) | ||
.Returns(Task.FromResult<IBoxResponse<BoxAIResponse>>(new BoxResponse<BoxAIResponse>() | ||
{ | ||
Status = ResponseStatus.Success, | ||
ContentString = LoadFixtureFromJson("Fixtures/BoxAI/SendAiQuestion200.json") | ||
})) | ||
.Callback<IBoxRequest>(r => boxRequest = r); | ||
|
||
var requestBody = new BoxAIAskRequest() | ||
{ | ||
Mode = AiAskMode.single_item_qa, | ||
Prompt = "What is the value provided by public APIs based on this document?", | ||
Items = new System.Collections.Generic.List<BoxAIAskItem>() | ||
{ | ||
new BoxAIAskItem() { Id = "9842787262" } | ||
} | ||
}; | ||
|
||
/*** Act ***/ | ||
BoxAIResponse response = await _aiManager.SendAIQuestionAsync(requestBody); | ||
|
||
/*** Assert ***/ | ||
// Request check | ||
Assert.IsNotNull(boxRequest); | ||
Assert.AreEqual(RequestMethod.Post, boxRequest.Method); | ||
Assert.AreEqual(new Uri("https://api.box.com/2.0/ai/ask"), boxRequest.AbsoluteUri); | ||
|
||
// Response check | ||
Assert.AreEqual("Public APIs are important because of key and important reasons.", response.Answer); | ||
Assert.AreEqual("done", response.CompletionReason); | ||
Assert.AreEqual(DateTimeOffset.Parse("2012-12-12T10:53:43-08:00"), response.CreatedAt); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public async Task SendAiGenerateTextRequestAsync_Success() | ||
{ | ||
/** Arrange **/ | ||
IBoxRequest boxRequest = null; | ||
Handler.Setup(h => h.ExecuteAsync<BoxAIResponse>(It.IsAny<IBoxRequest>())) | ||
.Returns(Task.FromResult<IBoxResponse<BoxAIResponse>>(new BoxResponse<BoxAIResponse>() | ||
{ | ||
Status = ResponseStatus.Success, | ||
ContentString = LoadFixtureFromJson("Fixtures/BoxAI/SendAITextGenRequestSuccess200.json") | ||
})) | ||
.Callback<IBoxRequest>(r => boxRequest = r); | ||
|
||
var requestBody = new BoxAITextGenRequest() | ||
{ | ||
Prompt = "Write an email to a client about the importance of public APIs", | ||
Items = new List<BoxAITextGenItem>() | ||
{ | ||
new BoxAITextGenItem() { Id = "12345678", Content = "More information about public APIs" } | ||
}, | ||
DialogueHistory = new List<BoxAIDialogueHistory>() | ||
{ | ||
new BoxAIDialogueHistory() | ||
{ | ||
Prompt = "Make my email about public APIs sound more professional", | ||
Answer = "Here is the first draft of your professional email about public APIs", | ||
CreatedAt = DateTimeOffset.Parse("2013-12-12T10:53:43-08:00") | ||
}, | ||
new BoxAIDialogueHistory() | ||
{ | ||
Prompt = "Can you add some more information?", | ||
Answer = "Public API schemas provide necessary information to integrate with APIs...", | ||
CreatedAt = DateTimeOffset.Parse("2013-12-12T11:20:43-08:00") | ||
} | ||
} | ||
}; | ||
|
||
/*** Act ***/ | ||
BoxAIResponse response = await _aiManager.SendAITextGenRequestAsync(requestBody); | ||
|
||
/*** Assert ***/ | ||
// Request check | ||
Assert.IsNotNull(boxRequest); | ||
Assert.AreEqual(RequestMethod.Post, boxRequest.Method); | ||
Assert.AreEqual(new Uri("https://api.box.com/2.0/ai/text_gen"), boxRequest.AbsoluteUri); | ||
|
||
// Response check | ||
Assert.AreEqual("Public APIs are important because of key and important reasons.", response.Answer); | ||
Assert.AreEqual("done", response.CompletionReason); | ||
Assert.AreEqual(DateTimeOffset.Parse("2012-12-12T10:53:43-08:00"), response.CreatedAt); | ||
} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"answer": "Public APIs are important because of key and important reasons.", | ||
"completion_reason": "done", | ||
"created_at": "2012-12-12T10:53:43-08:00" | ||
} |
5 changes: 5 additions & 0 deletions
5
Box.V2.Test/Fixtures/BoxAI/SendAITextGenRequestSuccess200.json
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,5 @@ | ||
{ | ||
"answer": "Public APIs are important because of key and important reasons.", | ||
"completion_reason": "done", | ||
"created_at": "2012-12-12T10:53:43-08:00" | ||
} |
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.