Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/ai/Azure.AI.Agents.Persistent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
- Fix issue with image block serialization [issue](https://github.com/Azure/azure-sdk-for-net/issues/52571)

### Other Changes

Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/Azure.AI.Agents.Persistent/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/ai/Azure.AI.Agents.Persistent",
"Tag": "net/ai/Azure.AI.Agents.Persistent_32145de83f"
"Tag": "net/ai/Azure.AI.Agents.Persistent_358ff70ace"
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public virtual Response<PersistentThreadMessage> CreateMessage(
}

// Now serialize the array of JsonElements into a single BinaryData for the request:
var jsonString = JsonSerializer.Serialize(contentBlocks, JsonElementSerializer.Default.ListJsonElement);
var jsonString = JsonSerializer.Serialize(jsonElements, JsonElementSerializer.Default.ListJsonElement);
BinaryData serializedBlocks = BinaryData.FromString(jsonString);

return CreateMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public class AIAgentsTestEnvironment : TestEnvironment
public string DEEP_RESEARCH_MODEL_DEPLOYMENT_NAME => GetRecordedOptionalVariable("DEEP_RESEARCH_MODEL_DEPLOYMENT_NAME");
public string BING_CONFIGURATION_NAME => GetRecordedOptionalVariable("BING_CONFIGURATION_NAME");
public string PLAYWRIGHT_CONNECTION_ID => GetRecordedOptionalVariable("AZURE_PLAYWRIGHT_CONNECTION_ID");
public string UPLOADED_IMAGE_ID => GetRecordedOptionalVariable("UPLOADED_IMAGE_ID");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,58 @@ await ValidateStream(
);
}

[RecordedTest]
[TestCase(true, "adani")]
//TODO: The Image URI is not supported, uncomment this text when the ICM 686545924 will be resolved.
//[TestCase(false, "trail")]
public async Task TestImageAsInput(bool useUploaded, string expectedWord)
{
PersistentAgentsClient client = GetClient();
PersistentAgent agent = await GetAgent(
client: client,
model: "gpt-4o",
instruction: "Analyze images from internally uploaded files."
);
PersistentAgentThread thread = client.Threads.CreateThread();
var contentBlocks = new List<MessageInputContentBlock>
{
new MessageInputTextBlock("Here is an uploaded file. Please describe it:"),
};
if (useUploaded)
{
// Note: To get the Image ID, please upload it using sample "Sample_PersistentAgents_ImageFileInputs."
contentBlocks.Add(new MessageInputImageFileBlock(new MessageImageFileParam(TestEnvironment.UPLOADED_IMAGE_ID)));
}
else
{
string uri = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg";
contentBlocks.Add(new MessageInputImageUriBlock(new MessageImageUriParam(uri)));
}

PersistentThreadMessage imageMessage = client.Messages.CreateMessage(
threadId: thread.Id,
role: MessageRole.User,
contentBlocks: contentBlocks
);
ThreadRun run = client.Runs.CreateRun(
threadId: thread.Id,
assistantId: agent.Id
);
run = await WaitForRun(client, run);
List<PersistentThreadMessage> messages = await client.Messages.GetMessagesAsync(threadId: run.ThreadId).ToListAsync();
Assert.Greater(messages.Count, 0);
StringBuilder sbResponse = new();
foreach (PersistentThreadMessage msg in messages)
{
if (msg.Role == MessageRole.Agent)
{
msg.ContentItems.Where(x => x is MessageTextContent).Select(x => ((MessageTextContent)x).Text).Aggregate(sbResponse, (sbResponse, next) => sbResponse.Append(next));
}
}
string response = sbResponse.ToString().ToLower();
Assert.That(response.Contains(expectedWord), $"The word {expectedWord} was not found in the response: {response}");
}

#region Helpers
private static async Task ValidateStream(
PersistentAgentsClient client,
Expand Down
Loading