forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenAIModel.cs
More file actions
92 lines (79 loc) · 2.62 KB
/
OpenAIModel.cs
File metadata and controls
92 lines (79 loc) · 2.62 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
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Azure.Provisioning.CloudMachine;
using Azure.Provisioning.CognitiveServices;
using Azure.Provisioning.Primitives;
namespace Azure.CloudMachine.OpenAI;
public class OpenAIModel : CloudMachineFeature
{
public OpenAIModel(string model, string modelVersion, AIModelKind kind = AIModelKind.Chat) {
Kind = kind;
Model = model;
ModelVersion = modelVersion;
}
public string Model { get; }
public string ModelVersion { get; }
private AIModelKind Kind { get; }
internal OpenAIFeature Account { get; set; } = default!;
private OpenAIFeature GetOrCreateOpenAI(CloudMachineInfrastructure cm)
{
foreach (OpenAIFeature feature in cm.Features.FindAll<OpenAIFeature>())
{
return feature;
}
var openAI = new OpenAIFeature();
cm.AddFeature(openAI);
return openAI;
}
public override void AddTo(CloudMachineInfrastructure cm)
{
OpenAIFeature openAI = GetOrCreateOpenAI(cm);
openAI.AddModel(this);
}
protected override ProvisionableResource EmitCore(CloudMachineInfrastructure cm)
{
string name = Kind switch
{
AIModelKind.Chat => $"{cm.Id}_chat",
AIModelKind.Embedding => $"{cm.Id}_embedding",
_ => throw new NotImplementedException()
};
Debug.Assert(Account != null);
var emitted = Account!.Emitted;
if (emitted == null)
{
Account.Emit(cm);
}
CognitiveServicesAccount parent = (CognitiveServicesAccount)Account!.Emitted;
CognitiveServicesAccountDeployment deployment = new($"openai_{name}", "2024-06-01-preview") {
Parent = parent,
Name = name,
Properties = new CognitiveServicesAccountDeploymentProperties()
{
Model = new CognitiveServicesAccountDeploymentModel()
{
Name = Model,
Format = "OpenAI",
Version = ModelVersion
},
VersionUpgradeOption = DeploymentModelVersionUpgradeOption.OnceNewDefaultVersionAvailable,
RaiPolicyName = "Microsoft.DefaultV2",
},
Sku = new CognitiveServicesSku
{
Capacity = 120,
Name = "Standard"
}
};
cm.AddResource(deployment);
return deployment;
}
}
public enum AIModelKind
{
Chat,
Embedding,
}