This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
OnnxRuntimeGenAIPromptExecutionSettings.cs
138 lines (120 loc) · 3.4 KB
/
OnnxRuntimeGenAIPromptExecutionSettings.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.SemanticKernel;
namespace feiyun0112.SemanticKernel.Connectors.OnnxRuntimeGenAI;
/// <summary>
/// OnnxRuntimeGenAI Execution Settings.
/// </summary>
public sealed class OnnxRuntimeGenAIPromptExecutionSettings : PromptExecutionSettings
{
public static OnnxRuntimeGenAIPromptExecutionSettings FromExecutionSettings(PromptExecutionSettings? executionSettings)
{
switch (executionSettings)
{
case OnnxRuntimeGenAIPromptExecutionSettings settings:
return settings;
default:
return new OnnxRuntimeGenAIPromptExecutionSettings();
}
}
private int _topK = 50;
private float _topP = 0.9f;
private float _temperature = 1;
private float _repetitionPenalty = 1;
private bool _pastPresentShareBuffer = false;
private int _numReturnSequences = 1;
private int _numBeams = 1;
private int _noRepeatNgramSize = 0;
private int _minLength = 0;
private int _maxLength = 200;
private float _lengthPenalty = 1;
private bool _earlyStopping = true;
private bool _doSample = false;
private float _diversityPenalty = 0;
[JsonPropertyName("top_k")]
public int TopK
{
get { return _topK; }
set { _topK = value; }
}
[JsonPropertyName("top_p")]
public float TopP
{
get { return _topP; }
set { _topP = value; }
}
[JsonPropertyName("temperature")]
public float Temperature
{
get { return _temperature; }
set { _temperature = value; }
}
[JsonPropertyName("repetition_penalty")]
public float RepetitionPenalty
{
get { return _repetitionPenalty; }
set { _repetitionPenalty = value; }
}
[JsonPropertyName("past_present_share_buffer")]
public bool PastPresentShareBuffer
{
get { return _pastPresentShareBuffer; }
set { _pastPresentShareBuffer = value; }
}
[JsonPropertyName("num_return_sequences")]
public int NumReturnSequences
{
get { return _numReturnSequences; }
set { _numReturnSequences = value; }
}
[JsonPropertyName("num_beams")]
public int NumBeams
{
get { return _numBeams; }
set { _numBeams = value; }
}
[JsonPropertyName("no_repeat_ngram_size")]
public int NoRepeatNgramSize
{
get { return _noRepeatNgramSize; }
set { _noRepeatNgramSize = value; }
}
[JsonPropertyName("min_length")]
public int MinLength
{
get { return _minLength; }
set { _minLength = value; }
}
[JsonPropertyName("max_length")]
public int MaxLength
{
get { return _maxLength; }
set { _maxLength = value; }
}
[JsonPropertyName("length_penalty")]
public float LengthPenalty
{
get { return _lengthPenalty; }
set { _lengthPenalty = value; }
}
[JsonPropertyName("diversity_penalty")]
public float DiversityPenalty
{
get { return _diversityPenalty; }
set { _diversityPenalty = value; }
}
[JsonPropertyName("early_stopping")]
public bool EarlyStopping
{
get { return _earlyStopping; }
set { _earlyStopping = value; }
}
[JsonPropertyName("do_sample")]
public bool DoSample
{
get { return _doSample; }
set { _doSample = value; }
}
}