-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathParameters.cs
133 lines (114 loc) · 4.72 KB
/
Parameters.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
using Grasshopper.Kernel.Types;
using Grasshopper.Kernel;
using OpenAI.GPT3.Managers;
using OpenAI.GPT3.ObjectModels.ResponseModels;
using System.Drawing;
namespace OpenAI_for_Grasshopper
{
public class Goo_OpenAIService : Goo_Base<OpenAIService>
{
public Goo_OpenAIService() : base() { }
public Goo_OpenAIService(OpenAIService value) : base(value) { }
public Goo_OpenAIService(Goo_OpenAIService other) : this(other.Value) { }
public override IGH_Goo Duplicate()
{
return new Goo_OpenAIService(this);
}
}
public class Param_OpenAIService : GH_Param<Goo_OpenAIService>
{
public override Guid ComponentGuid => new Guid("57a1127f-91ce-4ea4-82a2-21b871fd268a");
public override GH_Exposure Exposure => GH_Exposure.hidden;
protected override Bitmap Icon => Properties.Resources.OpenAI_logo_24x24;
public Param_OpenAIService() : base("Open AI Service", "OS", "The Open AI client service", "Extra", "OpenAI", GH_ParamAccess.item) { }
}
public class Goo_BaseResponse : Goo_Base<BaseResponse>
{
public Goo_BaseResponse() : base() { }
public Goo_BaseResponse(BaseResponse value) : base(value) { }
public Goo_BaseResponse(Goo_BaseResponse other) : this(other.Value) { }
public override IGH_Goo Duplicate()
{
return new Goo_BaseResponse(this);
}
}
public class Param_BaseResponse : GH_Param<Goo_BaseResponse>
{
public override Guid ComponentGuid => new Guid("4a0b09e3-81e3-47e1-872c-51cdc0fd4913");
public override GH_Exposure Exposure => GH_Exposure.hidden;
protected override Bitmap Icon => Properties.Resources.OpenAI_logo_24x24;
public Param_BaseResponse() : base("Open AI Response", "R", "The resulting response", "Extra", "OpenAI", GH_ParamAccess.item) { }
}
public class Goo_ChatMessage : GH_Goo<OpenAI.GPT3.ObjectModels.RequestModels.ChatMessage>
{
public override bool IsValid => m_value != null;
public override string TypeName => "ChatMessage";
public override string TypeDescription => "ChatGPT message";
public Goo_ChatMessage() : base() { }
public Goo_ChatMessage(OpenAI.GPT3.ObjectModels.RequestModels.ChatMessage value) : base(value) { }
public Goo_ChatMessage(Goo_ChatMessage other) : this(other.Value) { }
public override IGH_Goo Duplicate()
{
return new Goo_ChatMessage(this);
}
public override string ToString()
{
if(m_value != null) {
return $"({m_value.Role}) {m_value.Content}";
} else {
return "Null " + TypeName;
}
}
public override bool CastFrom(object source)
{
if(source is OpenAI.GPT3.ObjectModels.RequestModels.ChatMessage cm) {
m_value = cm;
return true;
}
if(source is Goo_ChatMessage gcm) {
m_value = gcm.Value;
return true;
}
if(source is IGH_Goo goo) {
return CastFrom(goo.ScriptVariable());
}
if(source is string s) {
m_value = OpenAI.GPT3.ObjectModels.RequestModels.ChatMessage.FromUser(s);
return true;
}
return base.CastFrom(source);
}
public override bool CastTo<Q>(ref Q target)
{
var typeOfQ = typeof(Q);
if(typeOfQ == typeof(OpenAI.GPT3.ObjectModels.RequestModels.ChatMessage)) {
if (m_value != null) {
target = (Q)(object)m_value;
}
return true;
}
if (typeOfQ == typeof(string)) {
if (m_value != null) {
target = (Q)(object)m_value.Content;
}
return true;
}
return base.CastTo(ref target);
}
}
public class Param_ChatMessage : GH_PersistentParam<Goo_ChatMessage>
{
public override Guid ComponentGuid => new Guid("297cfb51-5e41-48b6-a7fc-3c3f9c614481");
public override GH_Exposure Exposure => GH_Exposure.hidden;
protected override Bitmap Icon => Properties.Resources.OpenAI_logo_24x24;
public Param_ChatMessage() : base(new GH_InstanceDescription("ChatGPT Message", "M", "A role-based message for ChatGPT", "Extra", "OpenAI")) { }
protected override GH_GetterResult Prompt_Singular(ref Goo_ChatMessage value)
{
return GH_GetterResult.cancel;
}
protected override GH_GetterResult Prompt_Plural(ref List<Goo_ChatMessage> values)
{
return GH_GetterResult.cancel;
}
}
}