-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from teknologi-umum/ai-overhaul
Add vision bot
- Loading branch information
Showing
12 changed files
with
305 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,62 @@ | ||
namespace BotNet.Services.OpenAI.Models { | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BotNet.Services.OpenAI.Models { | ||
public record ChatMessage( | ||
string Role, | ||
string Content | ||
List<ChatContent> Content | ||
) { | ||
public static ChatMessage FromText(string role, string text) => new( | ||
Role: role, | ||
Content: [ | ||
new ChatContent( | ||
Type: "text", | ||
Text: text ?? throw new ArgumentNullException(nameof(text)), | ||
ImageUrl: null | ||
) | ||
] | ||
); | ||
|
||
public static ChatMessage FromTextWithImageBase64(string role, string text, string imageBase64) => new( | ||
Role: role, | ||
Content: [ | ||
new ChatContent( | ||
Type: "text", | ||
Text: text ?? throw new ArgumentNullException(nameof(text)), | ||
ImageUrl: null | ||
), | ||
new ChatContent( | ||
Type: "image_url", | ||
Text: null, | ||
ImageUrl: new( | ||
Url: $"data:image/jpeg;base64,{imageBase64 ?? throw new ArgumentNullException(nameof(imageBase64))}" | ||
) | ||
) | ||
] | ||
); | ||
|
||
public static ChatMessage FromImageBase64(string role, string imageBase64) => new( | ||
Role: role, | ||
Content: [ | ||
new ChatContent( | ||
Type: "image_url", | ||
Text: null, | ||
ImageUrl: new( | ||
Url: $"data:image/jpeg;base64,{imageBase64 ?? throw new ArgumentNullException(nameof(imageBase64))}" | ||
) | ||
) | ||
] | ||
); | ||
} | ||
|
||
public record ChatContent( | ||
string Type, | ||
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] string? Text, | ||
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] ImageUrl? ImageUrl | ||
); | ||
|
||
public record ImageUrl( | ||
string Url | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.