LuisModel.cs
1 //
2 // Copyright (c) Microsoft. All rights reserved.
3 // Licensed under the MIT license.
4 //
5 // Microsoft Bot Framework: http://botframework.com
6 //
7 // Bot Builder SDK GitHub:
8 // https://github.com/Microsoft/BotBuilder
9 //
10 // Copyright (c) Microsoft Corporation
11 // All rights reserved.
12 //
13 // MIT License:
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33 
34 using System;
35 using System.Collections.Generic;
37 
38 namespace Microsoft.Bot.Builder.Luis
39 {
43  public enum LuisApiVersion
44  {
45  [Obsolete]
46  V1,
47  V2
48  }
49 
53  public interface ILuisModel
54  {
58  string ModelID { get; }
59 
63  string SubscriptionKey { get; }
64 
68  Uri UriBase { get; }
69 
73  LuisApiVersion ApiVersion { get; }
74  }
75 
79  [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Method, AllowMultiple = true)]
80  [Serializable]
81  public class LuisModelAttribute : Attribute, ILuisModel, IEquatable<ILuisModel>
82  {
83  private readonly string modelID;
84  public string ModelID => modelID;
85 
86  private readonly string subscriptionKey;
87  public string SubscriptionKey => subscriptionKey;
88 
89  private readonly Uri uriBase;
90  public Uri UriBase => uriBase;
91 
92  private readonly LuisApiVersion apiVersion;
93  public LuisApiVersion ApiVersion => apiVersion;
94 
95  public static readonly IReadOnlyDictionary<LuisApiVersion, Uri> LuisEndpoints = new Dictionary<LuisApiVersion, Uri>()
96  {
97  #pragma warning disable CS0612
98  {LuisApiVersion.V1, new Uri("https://api.projectoxford.ai/luis/v1/application")},
99  #pragma warning restore CS0612
100  {LuisApiVersion.V2, new Uri("https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/")}
101  };
102 
109  public LuisModelAttribute(string modelID, string subscriptionKey, LuisApiVersion apiVersion = LuisApiVersion.V2)
110  {
111  SetField.NotNull(out this.modelID, nameof(modelID), modelID);
112  SetField.NotNull(out this.subscriptionKey, nameof(subscriptionKey), subscriptionKey);
113  this.apiVersion = apiVersion;
114  this.uriBase = LuisEndpoints[this.apiVersion];
115  }
116 
117  public bool Equals(ILuisModel other)
118  {
119  return other != null
120  && object.Equals(this.ModelID, other.ModelID)
121  && object.Equals(this.SubscriptionKey, other.SubscriptionKey)
122  && object.Equals(this.ApiVersion, other.ApiVersion)
123  && object.Equals(this.UriBase, other.UriBase)
124  ;
125  }
126 
127  public override bool Equals(object other)
128  {
129  return this.Equals(other as ILuisModel);
130  }
131 
132  public override int GetHashCode()
133  {
134  return ModelID.GetHashCode()
135  ^ SubscriptionKey.GetHashCode()
136  ^ UriBase.GetHashCode()
137  ^ ApiVersion.GetHashCode();
138  }
139  }
140 }
LuisModelAttribute(string modelID, string subscriptionKey, LuisApiVersion apiVersion=LuisApiVersion.V2)
Construct the LUIS model information.
Definition: LuisModel.cs:109
LuisApiVersion
Luis api version.
Definition: LuisModel.cs:43
Uri UriBase
The base Uri for accessing LUIS.
Definition: LuisModel.cs:68
string SubscriptionKey
The LUIS subscription key.
Definition: LuisModel.cs:63
Namespace for internal machinery that is not useful for most developers and may change in the future...
override bool Equals(object other)
Definition: LuisModel.cs:127
LuisApiVersion ApiVersion
Luis Api Version.
Definition: LuisModel.cs:73
The LUIS model information.
Definition: LuisModel.cs:81
A mockable interface for the LUIS model.
Definition: LuisModel.cs:53
Namespace for the internal fibers machinery that is not useful for most developers and may change in ...
string ModelID
The LUIS model ID.
Definition: LuisModel.cs:58
Root namespace for the Microsoft Bot Builder SDK.