Skip to content

Commit 400e15e

Browse files
committed
added vision support to large 3.2 meta models
1 parent f9f8191 commit 400e15e

10 files changed

+520
-32
lines changed

docs/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.2.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [0.26.0] - **BREAKING CHANGES**
8+
## [0.27.0] - **BREAKING CHANGES**
99

1010
- Module changes:
1111
- stability.ai
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Meta
2525
- `Invoke-MetaModel`
2626
- Added support for new 3.2 models: `meta.llama3-2-1b-instruct-v1:0`, `meta.llama3-2-3b-instruct-v1:0`, `meta.llama3-2-11b-instruct-v1:0`, `meta.llama3-2-90b-instruct-v1:0`
27+
- Added vision support for new large 3.2 models
2728
- minor corrections to debug output and help
2829
- Mistral
2930
- `Invoke-MistralAIModel` - minor corrections to debug output and help. Adjusted Max token limit validation.

docs/Invoke-MetaModel.md

+53-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Sends message(s) to a Meta model on the Amazon Bedrock platform and retrieves th
1212

1313
## SYNTAX
1414

15+
### MessageSet
1516
```
1617
Invoke-MetaModel -Message <String> -ModelID <String> [-ReturnFullObject] [-NoContextPersist]
1718
[-SystemPrompt <String>] [-MaxTokens <Int32>] [-Temperature <Single>] [-TopP <Single>] [-AccessKey <String>]
@@ -20,6 +21,15 @@ Invoke-MetaModel -Message <String> -ModelID <String> [-ReturnFullObject] [-NoCon
2021
[-SessionToken <String>] [<CommonParameters>]
2122
```
2223

24+
### ImageSet
25+
```
26+
Invoke-MetaModel -ImagePrompt <String> -MediaPath <String> -ModelID <String> [-ReturnFullObject]
27+
[-NoContextPersist] [-MaxTokens <Int32>] [-Temperature <Single>] [-TopP <Single>] [-AccessKey <String>]
28+
[-Credential <AWSCredentials>] [-EndpointUrl <String>] [-NetworkCredential <PSCredential>]
29+
[-ProfileLocation <String>] [-ProfileName <String>] [-Region <Object>] [-SecretKey <String>]
30+
[-SessionToken <String>] [<CommonParameters>]
31+
```
32+
2333
## DESCRIPTION
2434
Sends a message to a Meta model on the Amazon Bedrock platform and returns the model's response.
2535
By default the conversation context history is persisted to maintain a continuous interaction with the model.
@@ -67,14 +77,53 @@ Invoke-MetaModel @invokeMetaModelSplat
6777

6878
Sends a text message to the on-demand Meta model in the specified AWS region with a system prompt and a maximum token limit of 2000.
6979

80+
### EXAMPLE 5
81+
```
82+
Invoke-MetaModel -ImagePrompt -ImagePrompt 'Describe this image in two sentences.' -ModelID 'meta.llama3-2-11b-instruct-v1:0' -MediaPath 'C:\path\to\image.jpg' -Credential $awsCredential -Region 'us-west-2'
83+
```
84+
85+
Sends an image prompt to the Vision-Instruct Meta model in the specified AWS region and returns the response.
86+
7087
## PARAMETERS
7188

7289
### -Message
7390
The message to be sent to the model.
7491

7592
```yaml
7693
Type: String
77-
Parameter Sets: (All)
94+
Parameter Sets: MessageSet
95+
Aliases:
96+
97+
Required: True
98+
Position: Named
99+
Default value: None
100+
Accept pipeline input: False
101+
Accept wildcard characters: False
102+
```
103+
104+
### -ImagePrompt
105+
The prompt to the Vision-Instruct model.
106+
107+
```yaml
108+
Type: String
109+
Parameter Sets: ImageSet
110+
Aliases:
111+
112+
Required: True
113+
Position: Named
114+
Default value: None
115+
Accept pipeline input: False
116+
Accept wildcard characters: False
117+
```
118+
119+
### -MediaPath
120+
File path to local media file.
121+
The media files must adhere to the model's media requirements.
122+
Only large 3.2 vision models support media files.
123+
124+
```yaml
125+
Type: String
126+
Parameter Sets: ImageSet
78127
Aliases:
79128

80129
Required: True
@@ -137,7 +186,7 @@ If you do not provide a system prompt, the default Llama system prompt will be u
137186
138187
```yaml
139188
Type: String
140-
Parameter Sets: (All)
189+
Parameter Sets: MessageSet
141190
Aliases:
142191

143192
Required: False
@@ -381,6 +430,8 @@ Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/
381430
382431
[https://github.com/meta-llama/llama-models/blob/main/models/llama3_2/MODEL_CARD_VISION.md](https://github.com/meta-llama/llama-models/blob/main/models/llama3_2/MODEL_CARD_VISION.md)
383432
433+
[https://www.llama.com/docs/model-cards-and-prompt-formats/llama3_2/](https://www.llama.com/docs/model-cards-and-prompt-formats/llama3_2/)
434+
384435
[https://github.com/meta-llama/llama-models/blob/main/models/llama3_2/vision_prompt_format.md](https://github.com/meta-llama/llama-models/blob/main/models/llama3_2/vision_prompt_format.md)
385436
386437
[https://www.llama.com/docs/how-to-guides/vision-capabilities/](https://www.llama.com/docs/how-to-guides/vision-capabilities/)

docs/pwshBedrock.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Module Name: pwshBedrock
33
Module Guid: b4f9e4dc-0229-44ef-99a1-08be4c5e81f2
44
Download Help Link: NA
5-
Help Version: 0.26.0
5+
Help Version: 0.27.0
66
Locale: en-US
77
---
88

src/Tests/Unit/Private/Format-MetaTextMessage.Tests.ps1

+19
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,20 @@ You are a Star Trek trivia expert.
8686
8787
Who is the best captain in Star Trek?[/INST]Captain Picard</s>
8888
<s>[INST]Because of his fondness for Earl Grey?[/INST]
89+
'@
90+
91+
$expectedValue7 = @'
92+
<|begin_of_text|><|start_header_id|>user<|end_header_id|>
93+
94+
<|image|>Describe this image in two sentences<|eot_id|><|start_header_id|>assistant<|end_header_id|>
8995
'@
9096
$normalizedExpectedValue1 = $expectedValue1 -replace "`r`n", "`n"
9197
$normalizedExpectedValue2 = $expectedValue2 -replace "`r`n", "`n"
9298
$normalizedExpectedValue3 = $expectedValue3 -replace "`r`n", "`n"
9399
$normalizedExpectedValue4 = $expectedValue4 -replace "`r`n", "`n"
94100
$normalizedExpectedValue5 = $expectedValue5 -replace "`r`n", "`n"
95101
$normalizedExpectedValue6 = $expectedValue6 -replace "`r`n", "`n"
102+
$normalizedExpectedValue7 = $expectedValue7 -replace "`r`n", "`n"
96103
} #beforeEach
97104

98105
It 'should return a properly formatted initial message for Llama 2 model: <_>' -ForEach $llama2Models {
@@ -215,6 +222,18 @@ Who is the best captain in Star Trek?[/INST]Captain Picard</s>
215222
$normalizedResult | Should -Be $normalizedExpectedValue5
216223
} #it
217224

225+
It 'should handle an image prompt for Llama 3 model' {
226+
$formatMetaMessageSplat = @{
227+
ImagePrompt = 'Describe this image in two sentences'
228+
Role = 'User'
229+
ModelID = 'meta.llama3-2-11b-instruct-v1:0'
230+
}
231+
$result = Format-MetaTextMessage @formatMetaMessageSplat
232+
$result | Should -BeOfType 'System.String'
233+
$normalizedResult = $result -replace "`r`n", "`n"
234+
$normalizedResult | Should -Be $normalizedExpectedValue7
235+
} #it
236+
218237
It 'should populate context for the <_> model' -ForEach $metaModels {
219238
$formatMetaMessageSplat = @{
220239
Role = 'User'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
BeforeDiscovery {
2+
Set-Location -Path $PSScriptRoot
3+
$ModuleName = 'pwshBedrock'
4+
$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1")
5+
$script:assetPath = [System.IO.Path]::Combine('..', 'assets')
6+
#if the module is already in memory, remove it
7+
Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force
8+
Import-Module $PathToManifest -Force
9+
}
10+
$script:supportedMediaExtensions = @(
11+
'JPG'
12+
'JPEG'
13+
'PNG'
14+
'GIF'
15+
'WEBP'
16+
)
17+
18+
InModuleScope 'pwshBedrock' {
19+
Describe 'Test-MetaMedia Private Function Tests' -Tag Unit {
20+
BeforeAll {
21+
$WarningPreference = 'SilentlyContinue'
22+
$ErrorActionPreference = 'SilentlyContinue'
23+
24+
} #beforeAll
25+
26+
Context 'Error' {
27+
28+
It 'Should return false if an error is encountered running Test-Path' {
29+
Mock -CommandName Test-Path -MockWith { throw 'Test-Path Error' }
30+
$mediaPath = 'C:\path\to\image.jpg'
31+
$result = Test-MetaMedia -MediaPath $mediaPath
32+
$result | Should -Be $false
33+
} #it
34+
35+
It 'Should return false if an error is encountered running Get-Item' {
36+
Mock -CommandName Test-Path -MockWith { $true }
37+
Mock -CommandName Get-Item -MockWith { throw 'Get-Item Error' }
38+
$mediaPath = 'C:\path\to\image.jpg'
39+
$result = Test-MetaMedia -MediaPath $mediaPath
40+
$result | Should -Be $false
41+
} #it
42+
43+
It 'Should return false if the resolution of the image exceeds requirements' {
44+
Mock -CommandName Test-Path -MockWith { $true }
45+
Mock -CommandName Get-Item -Mockwith {
46+
[PSCustomObject]@{
47+
Length = 10000
48+
}
49+
} #endMock
50+
Mock -CommandName Get-ImageResolution -MockWith {
51+
[PSCustomObject]@{
52+
Width = 2000
53+
Height = 2000
54+
}
55+
} #endMock
56+
Mock Write-Warning {}
57+
$mediaPath = 'C:\path\to\image.jpg'
58+
$result = Test-MetaMedia -MediaPath $mediaPath
59+
$result | Should -Be $false
60+
} #it
61+
62+
} #context_Error
63+
64+
Context 'Success' {
65+
66+
It 'Should return true for <_> type if checks pass' -ForEach $supportedMediaExtensions {
67+
Mock -CommandName Test-Path -MockWith { $true }
68+
Mock -CommandName Get-Item -Mockwith {
69+
[PSCustomObject]@{
70+
Length = 10000
71+
}
72+
} #endMock
73+
Mock -CommandName Get-ImageResolution -MockWith {
74+
[PSCustomObject]@{
75+
Width = 100
76+
Height = 100
77+
}
78+
} #endMock
79+
$mediaPath = 'C:\path\to\image.' + $_.ToLower()
80+
$result = Test-MetaMedia -MediaPath $MediaPath
81+
$result | Should -Be $true
82+
} #it
83+
84+
It 'Should return false if file can not be found' {
85+
Mock -CommandName Test-Path -MockWith { $false }
86+
$mediaPath = 'C:\path\to\image.jpg'
87+
$result = Test-MetaMedia -MediaPath $mediaPath
88+
$result | Should -Be $false
89+
} #it
90+
91+
It 'Should return false if file type is not supported' {
92+
Mock -CommandName Test-Path -MockWith { $true }
93+
Mock -CommandName Get-ImageResolution -MockWith {
94+
[PSCustomObject]@{
95+
Width = 100
96+
Height = 100
97+
}
98+
} #endMock
99+
$mediaPath = 'C:\path\to\image.zip'
100+
$result = Test-MetaMedia -MediaPath $mediaPath
101+
$result | Should -Be $false
102+
} #it
103+
104+
It 'Should return false if the file is too large' {
105+
Mock -CommandName Test-Path -MockWith { $true }
106+
Mock -CommandName Get-Item -MockWith {
107+
[PSCustomObject]@{
108+
Length = 10000000
109+
}
110+
}
111+
Mock -CommandName Get-ImageResolution -MockWith {
112+
[PSCustomObject]@{
113+
Width = 100
114+
Height = 100
115+
}
116+
} #endMock
117+
$mediaPath = 'C:\path\to\image.jpg'
118+
$result = Test-MetaMedia -MediaPath $mediaPath
119+
$result | Should -Be $false
120+
} #it
121+
122+
} #context_Success
123+
124+
} #describe_Test-MetaMedia
125+
} #inModule

0 commit comments

Comments
 (0)