-
-
Notifications
You must be signed in to change notification settings - Fork 6
OpenAI.ImageRecognition
OpenAI.ImageRecognition
Protected Class ImageRecognition
Inherits OpenAI.ChatCompletion
This class represents an API image interpretation response. Refer to the OpenAI documentation on the /v1/chat/completions
endpoint with the gpt-4-vision-preview
model for further details.
To generate the AI assistant's first response, pass one or more images and a text prompt to the ImageRecognition.Create
shared method. This will return an instance of ImageRecognition
containing the response.
Chat conversations are stored as instances of the ChatCompletionData class. You can review and modify the conversation for any given ImageRecognition
by referring to its ChatLog As OpenAI.ChatCompletionData
property.
A chat message may be attributed to one of three entities: "user"
, "assistant"
, or "system"
. However, for image recognition chat sessions you will usually only use "user"
.
OpenAI.APIKey = "YOUR API KEY"
Dim url As String = "https://upload.wikimedia.org/wikipedia/commons/9/99/Aerial_view_of_the_White_House.jpg"
Dim response As OpenAI.ImageRecognition = OpenAI.ImageRecognition.Create("What is this a photo of?", url)
Dim answer As String = response.GetResult() ' This is an aerial photo of the the White House in Washington, DC.
Once you have created the initial response, you can continue the conversation in context by calling the GenerateNext()
method.
OpenAI.APIKey = "YOUR API KEY"
Dim url1 As String = "https://upload.wikimedia.org/wikipedia/commons/9/99/Aerial_view_of_the_White_House.jpg"
Dim url2 As String = "https://upload.wikimedia.org/wikipedia/commons/b/bd/Taj_Mahal%2C_Agra%2C_India_edit3.jpg"
Dim response As OpenAI.ImageRecognition = OpenAI.ImageRecognition.Create("What is this a photo of?", url1)
Dim answer As String = response.GetResult() ' This is an aerial photo of the the White House in Washington, DC.
response = response.GenerateNext("user", "What direction is the camera facing?")
answer = response.GetResult() ' The camera is facing northward.
response = response.GenerateNext("user", "Is this a picture of the same building?", url2)
answer = response.GetResult() ' No, this is a photo of the Taj Mahal located in Agra, India.
' etc.
You can include more than one image in a single request by using an array:
OpenAI.APIKey = "YOUR API KEY"
Dim urls() As String
urls.Append("https://upload.wikimedia.org/wikipedia/commons/9/99/Aerial_view_of_the_White_House.jpg")
urls.Append("https://upload.wikimedia.org/wikipedia/commons/b/bd/Taj_Mahal%2C_Agra%2C_India_edit3.jpg")
Dim response As OpenAI.ImageRecognition = OpenAI.ImageRecognition.Create("Are these photos of the same building?", urls)
Dim answer As String = response.GetResult() ' No, the first image is of the White House but the second image is of the Taj Mahal.
You may use either Xojo Picture
objects or URLs to pictures on the Internet. Using URLs will improve performance since the picture data doesn't have to be encoded directly into the request.
- Constructor
- GenerateNext
- GetResult
- GetResultRole
- GetResultAttribute
- HasResultAttribute
- Operator_Convert
- Tokens
- ToString
- ChatLog As OpenAI.ChatCompletionData
- Created As Date
- ID As String
- Model As OpenAI.Model
- OriginalRequest As OpenAI.Request
- PromptTokenCount As Integer
- ReplyTokenCount As Integer
- ResponseFormat As String
- ResultCount As Integer
- ResultType As OpenAI.ResultType
- TokenCount As Integer
- Examples
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2023-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.