forked from microsoft/kernel-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenAIEmbeddingsConfig.cs
More file actions
60 lines (51 loc) · 1.76 KB
/
OpenAIEmbeddingsConfig.cs
File metadata and controls
60 lines (51 loc) · 1.76 KB
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
// Copyright (c) Microsoft. All rights reserved.
using System.Text.Json.Serialization;
using KernelMemory.Core.Config.Enums;
using KernelMemory.Core.Config.Validation;
namespace KernelMemory.Core.Config.Embeddings;
/// <summary>
/// OpenAI embeddings provider configuration
/// </summary>
public sealed class OpenAIEmbeddingsConfig : EmbeddingsConfig
{
/// <inheritdoc />
[JsonIgnore]
public override EmbeddingsTypes Type => EmbeddingsTypes.OpenAI;
/// <summary>
/// OpenAI model name (e.g., "text-embedding-ada-002", "text-embedding-3-small")
/// </summary>
[JsonPropertyName("model")]
public string Model { get; set; } = string.Empty;
/// <summary>
/// OpenAI API key
/// </summary>
[JsonPropertyName("apiKey")]
public string ApiKey { get; set; } = string.Empty;
/// <summary>
/// Optional custom base URL (for OpenAI-compatible APIs)
/// </summary>
[JsonPropertyName("baseUrl")]
public string? BaseUrl { get; set; }
/// <inheritdoc />
public override void Validate(string path)
{
if (string.IsNullOrWhiteSpace(this.Model))
{
throw new ConfigException($"{path}.Model", "OpenAI model name is required");
}
if (string.IsNullOrWhiteSpace(this.ApiKey))
{
throw new ConfigException($"{path}.ApiKey", "OpenAI API key is required");
}
if (this.BatchSize < 1)
{
throw new ConfigException($"{path}.BatchSize", "BatchSize must be >= 1");
}
if (!string.IsNullOrWhiteSpace(this.BaseUrl) &&
!Uri.TryCreate(this.BaseUrl, UriKind.Absolute, out _))
{
throw new ConfigException($"{path}.BaseUrl",
$"Invalid OpenAI base URL: {this.BaseUrl}");
}
}
}