-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathEmbeddingDemo.cs
93 lines (79 loc) · 3.2 KB
/
EmbeddingDemo.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using LlmTornado.Embedding;
using LlmTornado.Embedding.Models;
using LlmTornado.Embedding.Vendors.Cohere;
namespace LlmTornado.Demo;
public static class EmbeddingDemo
{
[TornadoTest]
public static async Task Embed()
{
EmbeddingResult? result = await Program.ConnectMulti().Embeddings.CreateEmbedding(EmbeddingModel.OpenAi.Gen2.Ada, "lorem ipsum");
float[]? data = result?.Data.FirstOrDefault()?.Embedding;
if (data is not null)
{
for (int i = 0; i < Math.Min(data.Length, 10); i++)
{
Console.WriteLine(data[i]);
}
}
}
[TornadoTest]
public static async Task EmbedVector()
{
EmbeddingResult? result = await Program.ConnectMulti().Embeddings.CreateEmbedding(EmbeddingModel.OpenAi.Gen2.Ada, [ "how are you", "how are you doing" ]);
Console.WriteLine(result?.Data.Count ?? 0);
}
[TornadoTest]
public static async Task EmbedCohere()
{
EmbeddingResult? result = await Program.ConnectMulti().Embeddings.CreateEmbedding(EmbeddingModel.Cohere.Gen3.Multilingual, "lorem ipsum");
Console.WriteLine($"Count: {result?.Data.Count ?? 0}, dims: {result?.Data.FirstOrDefault()?.Embedding.Length ?? 0}");
if (result is not null)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(result.Data[0].Embedding[i]);
}
Console.WriteLine("...");
}
}
[TornadoTest]
public static async Task EmbedCohereExtensions()
{
foreach (EmbeddingVendorCohereExtensionInputTypes mode in Enum.GetValues<EmbeddingVendorCohereExtensionInputTypes>())
{
EmbeddingResult? result = await Program.ConnectMulti().Embeddings.CreateEmbedding(EmbeddingModel.Cohere.Gen3.Multilingual, "lorem ipsum", new EmbeddingRequestVendorExtensions
{
Cohere = new EmbeddingRequestVendorCohereExtensions
{
InputType = mode,
Truncate = EmbeddingVendorCohereExtensionTruncation.End
}
});
Console.WriteLine($"Mode: {mode}");
Console.WriteLine($"Count: {result?.Data.Count ?? 0}, dims: {result?.Data.FirstOrDefault()?.Embedding.Length ?? 0}");
if (result is not null)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(result.Data[0].Embedding[i]);
}
Console.WriteLine("...");
}
}
}
[TornadoTest]
public static async Task EmbedCohereVector()
{
EmbeddingResult? result = await Program.ConnectMulti().Embeddings.CreateEmbedding(EmbeddingModel.Cohere.Gen3.Multilingual, [ "lorem ipsum", "dolor sit amet" ]);
Console.WriteLine($"Count: {result?.Data.Count ?? 0}, dims: {result?.Data.FirstOrDefault()?.Embedding.Length ?? 0}");
if (result is not null)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(result.Data[0].Embedding[i]);
}
Console.WriteLine("...");
}
}
}