@@ -10,34 +10,28 @@ internal static class VisionTestHelper
10
10
{
11
11
public static async Task RunSimpleVisionTest ( IOpenAIService sdk )
12
12
{
13
- ConsoleExtensions . WriteLine ( "VIsion Testing is starting:" , ConsoleColor . Cyan ) ;
13
+ ConsoleExtensions . WriteLine ( "Vision Testing is starting:" , ConsoleColor . Cyan ) ;
14
14
15
15
try
16
16
{
17
17
ConsoleExtensions . WriteLine ( "Vision Test:" , ConsoleColor . DarkCyan ) ;
18
18
19
- var completionResult = await sdk . ChatCompletion . CreateCompletion (
20
- new ChatCompletionCreateRequest
19
+ var completionResult = await sdk . ChatCompletion . CreateCompletion ( new ( )
20
+ {
21
+ Messages = new List < ChatMessage >
21
22
{
22
- Messages = new List < ChatMessage >
23
+ ChatMessage . FromSystem ( "You are an image analyzer assistant." ) ,
24
+ ChatMessage . FromUser ( new List < MessageContent >
23
25
{
24
- ChatMessage . FromSystem ( "You are an image analyzer assistant." ) ,
25
- ChatMessage . FromUser (
26
- new List < MessageContent >
27
- {
28
- MessageContent . TextContent ( "What is on the picture in details?" ) ,
29
- MessageContent . ImageUrlContent (
30
- "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" ,
31
- ImageStatics . ImageDetailTypes . High
32
- )
33
- }
34
- ) ,
35
- } ,
36
- MaxTokens = 300 ,
37
- Model = Models . Gpt_4_vision_preview ,
38
- N = 1
39
- }
40
- ) ;
26
+ MessageContent . TextContent ( "What is on the picture in details?" ) ,
27
+ MessageContent . ImageUrlContent ( "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" ,
28
+ ImageStatics . ImageDetailTypes . High )
29
+ } )
30
+ } ,
31
+ MaxTokens = 300 ,
32
+ Model = Models . Gpt_4_vision_preview ,
33
+ N = 1
34
+ } ) ;
41
35
42
36
if ( completionResult . Successful )
43
37
{
@@ -47,12 +41,10 @@ public static async Task RunSimpleVisionTest(IOpenAIService sdk)
47
41
{
48
42
if ( completionResult . Error == null )
49
43
{
50
- throw new Exception ( "Unknown Error" ) ;
44
+ throw new ( "Unknown Error" ) ;
51
45
}
52
46
53
- Console . WriteLine (
54
- $ "{ completionResult . Error . Code } : { completionResult . Error . Message } "
55
- ) ;
47
+ Console . WriteLine ( $ "{ completionResult . Error . Code } : { completionResult . Error . Message } ") ;
56
48
}
57
49
}
58
50
catch ( Exception e )
@@ -69,28 +61,22 @@ public static async Task RunSimpleVisionStreamTest(IOpenAIService sdk)
69
61
{
70
62
ConsoleExtensions . WriteLine ( "Vision Stream Test:" , ConsoleColor . DarkCyan ) ;
71
63
72
- var completionResult = sdk . ChatCompletion . CreateCompletionAsStream (
73
- new ChatCompletionCreateRequest
64
+ var completionResult = sdk . ChatCompletion . CreateCompletionAsStream ( new ( )
65
+ {
66
+ Messages = new List < ChatMessage >
74
67
{
75
- Messages = new List < ChatMessage >
68
+ ChatMessage . FromSystem ( "You are an image analyzer assistant." ) ,
69
+ ChatMessage . FromUser ( new List < MessageContent >
76
70
{
77
- ChatMessage . FromSystem ( "You are an image analyzer assistant." ) ,
78
- ChatMessage . FromUser (
79
- new List < MessageContent >
80
- {
81
- MessageContent . TextContent ( "What’s in this image?" ) ,
82
- MessageContent . ImageUrlContent (
83
- "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" ,
84
- ImageStatics . ImageDetailTypes . Low
85
- )
86
- }
87
- ) ,
88
- } ,
89
- MaxTokens = 300 ,
90
- Model = Models . Gpt_4_vision_preview ,
91
- N = 1
92
- }
93
- ) ;
71
+ MessageContent . TextContent ( "What’s in this image?" ) ,
72
+ MessageContent . ImageUrlContent ( "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" ,
73
+ ImageStatics . ImageDetailTypes . Low )
74
+ } )
75
+ } ,
76
+ MaxTokens = 300 ,
77
+ Model = Models . Gpt_4_vision_preview ,
78
+ N = 1
79
+ } ) ;
94
80
95
81
await foreach ( var completion in completionResult )
96
82
{
@@ -102,12 +88,10 @@ public static async Task RunSimpleVisionStreamTest(IOpenAIService sdk)
102
88
{
103
89
if ( completion . Error == null )
104
90
{
105
- throw new Exception ( "Unknown Error" ) ;
91
+ throw new ( "Unknown Error" ) ;
106
92
}
107
93
108
- Console . WriteLine (
109
- $ "{ completion . Error . Code } : { completion . Error . Message } "
110
- ) ;
94
+ Console . WriteLine ( $ "{ completion . Error . Code } : { completion . Error . Message } ") ;
111
95
}
112
96
}
113
97
@@ -127,39 +111,26 @@ public static async Task RunSimpleVisionTestUsingBase64EncodedImage(IOpenAIServi
127
111
128
112
try
129
113
{
130
- ConsoleExtensions . WriteLine (
131
- "Vision with base64 encoded image Test:" ,
132
- ConsoleColor . DarkCyan
133
- ) ;
114
+ ConsoleExtensions . WriteLine ( "Vision with base64 encoded image Test:" , ConsoleColor . DarkCyan ) ;
134
115
135
116
const string originalFileName = "image_edit_original.png" ;
136
- var originalFile = await FileExtensions . ReadAllBytesAsync (
137
- $ "SampleData/{ originalFileName } "
138
- ) ;
117
+ var originalFile = await FileExtensions . ReadAllBytesAsync ( $ "SampleData/{ originalFileName } ") ;
139
118
140
- var completionResult = await sdk . ChatCompletion . CreateCompletion (
141
- new ChatCompletionCreateRequest
119
+ var completionResult = await sdk . ChatCompletion . CreateCompletion ( new ( )
120
+ {
121
+ Messages = new List < ChatMessage >
142
122
{
143
- Messages = new List < ChatMessage >
123
+ ChatMessage . FromSystem ( "You are an image analyzer assistant." ) ,
124
+ ChatMessage . FromUser ( new List < MessageContent >
144
125
{
145
- ChatMessage . FromSystem ( "You are an image analyzer assistant." ) ,
146
- ChatMessage . FromUser (
147
- new List < MessageContent >
148
- {
149
- MessageContent . TextContent ( "What is on the picture in details?" ) ,
150
- MessageContent . ImageBinaryContent (
151
- originalFile ,
152
- ImageStatics . ImageFileTypes . Png ,
153
- ImageStatics . ImageDetailTypes . High
154
- )
155
- }
156
- ) ,
157
- } ,
158
- MaxTokens = 300 ,
159
- Model = Models . Gpt_4_vision_preview ,
160
- N = 1
161
- }
162
- ) ;
126
+ MessageContent . TextContent ( "What is on the picture in details?" ) ,
127
+ MessageContent . ImageBinaryContent ( originalFile , ImageStatics . ImageFileTypes . Png , ImageStatics . ImageDetailTypes . High )
128
+ } )
129
+ } ,
130
+ MaxTokens = 300 ,
131
+ Model = Models . Gpt_4_vision_preview ,
132
+ N = 1
133
+ } ) ;
163
134
164
135
if ( completionResult . Successful )
165
136
{
@@ -169,12 +140,10 @@ public static async Task RunSimpleVisionTestUsingBase64EncodedImage(IOpenAIServi
169
140
{
170
141
if ( completionResult . Error == null )
171
142
{
172
- throw new Exception ( "Unknown Error" ) ;
143
+ throw new ( "Unknown Error" ) ;
173
144
}
174
145
175
- Console . WriteLine (
176
- $ "{ completionResult . Error . Code } : { completionResult . Error . Message } "
177
- ) ;
146
+ Console . WriteLine ( $ "{ completionResult . Error . Code } : { completionResult . Error . Message } ") ;
178
147
}
179
148
}
180
149
catch ( Exception e )
@@ -183,4 +152,4 @@ public static async Task RunSimpleVisionTestUsingBase64EncodedImage(IOpenAIServi
183
152
throw ;
184
153
}
185
154
}
186
- }
155
+ }
0 commit comments