-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpenAIClientHyperlinkHelper.cs
35 lines (33 loc) · 1.26 KB
/
OpenAIClientHyperlinkHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using Azure;
using Azure.AI.OpenAI;
using DevExpress.Drawing;
using DevExpress.Office.Utils;
namespace RichEditOpenAIWebApi.BusinessObjects
{
public class OpenAIClientHyperlinkHelper
{
OpenAIClient client;
internal OpenAIClientHyperlinkHelper(string openAIApiKey)
{
client = new OpenAIClient(openAIApiKey, new OpenAIClientOptions());
}
internal async Task<string> DescribeHyperlinkAsync(string link)
{
ChatCompletionsOptions chatCompletionsOptions = new()
{
DeploymentName = "gpt-4-vision-preview",
Messages =
{
new ChatRequestSystemMessage("You are a helpful assistant that describes images."),
new ChatRequestUserMessage(
new ChatMessageTextContentItem("Give a description of this hyperlink URI in 10-20 words"),
new ChatMessageTextContentItem(link))
},
MaxTokens = 300
};
Response<ChatCompletions> chatResponse = await client.GetChatCompletionsAsync(chatCompletionsOptions);
ChatChoice choice = chatResponse.Value.Choices[0];
return choice.Message.Content;
}
}
}