20
20
using IBM . Watson . DeveloperCloud . Utilities ;
21
21
using IBM . Watson . DeveloperCloud . Logging ;
22
22
using System ;
23
+ using System . Collections . Generic ;
24
+ using System . Collections ;
25
+ using IBM . Watson . DeveloperCloud . DataTypes ;
26
+ using System . Reflection ;
23
27
24
28
public class ExampleConversation : MonoBehaviour
25
29
{
@@ -33,75 +37,146 @@ void Start()
33
37
LogSystem . InstallDefaultReactors ( ) ;
34
38
m_WorkspaceID = Config . Instance . GetVariableValue ( "ConversationV1_ID" ) ;
35
39
36
- Debug . Log ( "**********User: Hello!" ) ;
37
- MessageWithOnlyInput ( "Hello!" ) ;
38
- }
40
+ //Debug.Log("**********User: Hello!");
41
+ // MessageWithOnlyInput("Hello!");
39
42
40
- private void MessageWithOnlyInput ( string input )
41
- {
42
- if ( string . IsNullOrEmpty ( input ) )
43
- throw new ArgumentNullException ( "input" ) ;
44
-
45
- m_Conversation . Message ( OnMessageWithOnlyInput , m_WorkspaceID , input ) ;
46
- }
47
-
48
-
49
- private void OnMessageWithOnlyInput ( MessageResponse resp , string customData )
50
- {
51
- if ( resp != null )
52
- {
53
- foreach ( Intent mi in resp . intents )
54
- Debug . Log ( "Message Only intent: " + mi . intent + ", confidence: " + mi . confidence ) ;
55
-
56
- if ( resp . output != null && resp . output . text . Length > 0 )
57
- foreach ( string txt in resp . output . text )
58
- Debug . Log ( "Message Only output: " + txt ) ;
59
-
60
- string questionStr = questionArray [ UnityEngine . Random . Range ( 0 , questionArray . Length - 1 ) ] ;
61
- Debug . Log ( string . Format ( "**********User: {0}" , questionStr ) ) ;
62
-
63
- MessageRequest messageRequest = new MessageRequest ( ) ;
64
- messageRequest . InputText = questionStr ;
65
- messageRequest . alternate_intents = m_UseAlternateIntents ;
66
- messageRequest . ContextData = resp . context ;
67
-
68
- MessageWithFullMessageRequest ( messageRequest ) ;
43
+ GetRawOutput ( "Hello" ) ;
69
44
}
70
- else
45
+
46
+ private void GetRawOutput ( string input )
71
47
{
72
- Debug . Log ( "Message Only: Failed to invoke Message();" ) ;
48
+ m_Conversation . Message ( OnGetRawOutput , m_WorkspaceID , input ) ;
73
49
}
74
- }
75
-
76
- private void MessageWithFullMessageRequest ( MessageRequest messageRequest )
77
- {
78
- if ( messageRequest == null )
79
- throw new ArgumentNullException ( "messageRequest" ) ;
80
- m_Conversation . Message ( OnMessageWithFullRequest , m_WorkspaceID , messageRequest ) ;
81
- }
82
50
83
- private void OnMessageWithFullRequest ( MessageResponse resp , string customData )
84
- {
85
- if ( resp != null )
51
+ private void OnGetRawOutput ( object resp , string customData )
86
52
{
87
- foreach ( Intent mi in resp . intents )
88
- Debug . Log ( "Full Request intent: " + mi . intent + ", confidence: " + mi . confidence ) ;
89
-
90
- if ( resp . output != null && resp . output . text . Length > 0 )
91
- foreach ( string txt in resp . output . text )
92
- Debug . Log ( "Full Request output: " + txt ) ;
53
+ if ( ! string . IsNullOrEmpty ( customData ) )
54
+ Debug . Log ( customData ) ;
55
+ else
56
+ Debug . Log ( "No raw data was received." ) ;
57
+
58
+ if ( resp != null )
59
+ {
60
+ Dictionary < string , object > respDict = resp as Dictionary < string , object > ;
61
+ object intents ;
62
+ respDict . TryGetValue ( "intents" , out intents ) ;
63
+
64
+ foreach ( var intentObj in ( intents as List < object > ) )
65
+ {
66
+ Dictionary < string , object > intentDict = intentObj as Dictionary < string , object > ;
67
+
68
+ object intentString ;
69
+ intentDict . TryGetValue ( "intent" , out intentString ) ;
70
+
71
+ object confidenceString ;
72
+ intentDict . TryGetValue ( "confidence" , out confidenceString ) ;
73
+
74
+ Log . Debug ( "ExampleConversation" , "intent: {0} | confidence {1}" , intentString . ToString ( ) , confidenceString . ToString ( ) ) ;
75
+ }
76
+ }
77
+ }
93
78
94
- string questionStr = questionArray [ UnityEngine . Random . Range ( 0 , questionArray . Length - 1 ) ] ;
95
- Debug . Log ( string . Format ( "**********User: {0}" , questionStr ) ) ;
79
+ //private void MessageWithOnlyInput(string input)
80
+ //{
81
+ // if (string.IsNullOrEmpty(input))
82
+ // throw new ArgumentNullException("input");
83
+
84
+ // m_Conversation.Message(OnMessageWithOnlyInput, m_WorkspaceID, input);
85
+ //}
86
+
87
+
88
+ //private void OnMessageWithOnlyInput(object resp, string customData)
89
+ //{
90
+ // if (resp != null)
91
+ // {
92
+ // foreach (Intent mi in resp.intents)
93
+ // Debug.Log("Message Only intent: " + mi.intent + ", confidence: " + mi.confidence);
94
+
95
+ // if (resp.output != null && resp.output.text.Length > 0)
96
+ // foreach (string txt in resp.output.text)
97
+ // Debug.Log("Message Only output: " + txt);
98
+
99
+ // if (resp.context != null)
100
+ // {
101
+ // if (!string.IsNullOrEmpty(resp.context.conversation_id))
102
+ // Log.Debug("ExampleConversation", "Conversation ID: {0}", resp.context.conversation_id);
103
+ // else
104
+ // Log.Debug("ExampleConversation", "Conversation ID is null.");
105
+
106
+ // if (resp.context.system != null)
107
+ // {
108
+ // Log.Debug("ExampleConversation", "dialog_request_counter: {0}", resp.context.system.dialog_request_counter);
109
+ // Log.Debug("ExampleConversation", "dialog_turn_counter: {0}", resp.context.system.dialog_turn_counter);
110
+
111
+ // if (resp.context.system.dialog_stack != null)
112
+ // {
113
+ // foreach (Dictionary<string, string> dialogNode in resp.context.system.dialog_stack)
114
+ // foreach(KeyValuePair<string, string> node in dialogNode)
115
+ // Log.Debug("ExampleConversation", "dialogNode: {0}", node.Value);
116
+ // }
117
+ // else
118
+ // {
119
+ // Log.Debug("ExampleConversation", "dialog stack is null");
120
+ // }
121
+
122
+ // }
123
+ // else
124
+ // {
125
+ // Log.Debug("ExampleConversation", "system is null.");
126
+ // }
127
+
128
+ // }
129
+ // else
130
+ // {
131
+ // Log.Debug("ExampleConversation", "Context is null");
132
+ // }
133
+
134
+ // string questionStr = questionArray[UnityEngine.Random.Range(0, questionArray.Length - 1)];
135
+ // Debug.Log(string.Format("**********User: {0}", questionStr));
136
+
137
+ // MessageRequest messageRequest = new MessageRequest();
138
+ // messageRequest.InputText = questionStr;
139
+ // messageRequest.alternate_intents = m_UseAlternateIntents;
140
+ // messageRequest.ContextData = resp.context;
141
+
142
+ // MessageWithFullMessageRequest(messageRequest);
143
+ // }
144
+ // else
145
+ // {
146
+ // Debug.Log("Message Only: Failed to invoke Message();");
147
+ // }
148
+ //}
149
+
150
+ //private void MessageWithFullMessageRequest(MessageRequest messageRequest)
151
+ //{
152
+ // if (messageRequest == null)
153
+ // throw new ArgumentNullException("messageRequest");
154
+ // m_Conversation.Message(OnMessageWithFullRequest, m_WorkspaceID, messageRequest);
155
+ //}
156
+
157
+ //private void OnMessageWithFullRequest(MessageResponse resp, string customData)
158
+ //{
159
+ // if (resp != null)
160
+ // {
161
+ // foreach (Intent mi in resp.intents)
162
+ // Debug.Log("Full Request intent: " + mi.intent + ", confidence: " + mi.confidence);
163
+
164
+ // if (resp.output != null && resp.output.text.Length > 0)
165
+ // foreach (string txt in resp.output.text)
166
+ // Debug.Log("Full Request output: " + txt);
167
+
168
+ // string questionStr = questionArray[UnityEngine.Random.Range(0, questionArray.Length - 1)];
169
+ // Debug.Log(string.Format("**********User: {0}", questionStr));
170
+
171
+ // MessageRequest messageRequest = new MessageRequest();
172
+ // messageRequest.InputText = questionStr;
173
+ // messageRequest.alternate_intents = m_UseAlternateIntents;
174
+ // messageRequest.ContextData = resp.context;
175
+ // }
176
+ // else
177
+ // {
178
+ // Debug.Log("Full Request: Failed to invoke Message();");
179
+ // }
180
+ //}
96
181
97
- MessageRequest messageRequest = new MessageRequest ( ) ;
98
- messageRequest . InputText = questionStr ;
99
- messageRequest . alternate_intents = m_UseAlternateIntents ;
100
- messageRequest . ContextData = resp . context ;
101
- }
102
- else
103
- {
104
- Debug . Log ( "Full Request: Failed to invoke Message();" ) ;
105
- }
106
- }
107
182
}
0 commit comments