100 lines
3.1 KiB
C#
100 lines
3.1 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using TMPro;
|
||
|
||
public class PuzzleQuestionBoard : MonoBehaviour
|
||
{
|
||
|
||
public Button QuestionButton;
|
||
public Button[] RecQuestionButtons;
|
||
public TMP_InputField InputQuestions;
|
||
public Button questionBoardReturnButton;
|
||
public bool isDebugging = false;
|
||
|
||
[HideInInspector]
|
||
public PuzzleCardExplainItem cardExplainItem;
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
foreach (var recQuestionButton in RecQuestionButtons)
|
||
{
|
||
recQuestionButton.onClick.AddListener(delegate
|
||
{
|
||
InputQuestions.text = recQuestionButton.GetComponentInChildren<TMP_Text>().text;
|
||
});
|
||
}
|
||
|
||
QuestionButton.onClick.AddListener(SendQuestion);
|
||
|
||
questionBoardReturnButton.onClick.AddListener(delegate
|
||
{
|
||
cardExplainItem.canvasGroup.gameObject.SetActive(true);
|
||
gameObject.SetActive(false);
|
||
});
|
||
}
|
||
|
||
void SendQuestion()
|
||
{
|
||
if (isDebugging)
|
||
{
|
||
StartCoroutine(TestCoroutine());
|
||
}
|
||
else
|
||
{
|
||
StartCoroutine(SendQuestionRequest());
|
||
}
|
||
}
|
||
|
||
|
||
ChatGPTRequestStruct GenerateMessages(WishCard card)
|
||
{
|
||
var s = new ChatGPTRequestStruct();
|
||
string q1 = string.Format("Answer the input question with regard to the following Tarot card:\n {0}", card.CardFrontText.text);
|
||
string q2 = InputQuestions.text;
|
||
s.messages = new ChatGPTMessageStruct[2]
|
||
{
|
||
new ChatGPTMessageStruct("system", q1),
|
||
new ChatGPTMessageStruct("user", q2)
|
||
};
|
||
return s;
|
||
}
|
||
|
||
WenXinRequestStruct GenerateWenXinMessages()
|
||
{
|
||
var s = new WenXinRequestStruct();
|
||
s.system = string.Format("Answer the input question with regard to the following Tarot card:\n {0}", cardExplainItem.m_explainText.text);
|
||
string q2 = InputQuestions.text;
|
||
s.messages = new List<WenXinRequestMessage>
|
||
{
|
||
WenXinRequestMessage.UserMessage(q2),
|
||
};
|
||
return s;
|
||
}
|
||
|
||
IEnumerator TestCoroutine()
|
||
{
|
||
string answer = "Test answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\nTest answer!\n";
|
||
|
||
|
||
yield return new WaitForSeconds(2.0f);
|
||
cardExplainItem.m_explainText.SetText(answer);
|
||
gameObject.SetActive(false);
|
||
cardExplainItem.canvasGroup.gameObject.SetActive(true);
|
||
}
|
||
|
||
IEnumerator SendQuestionRequest()
|
||
{
|
||
string response;
|
||
var wenXinParam = GenerateWenXinMessages();
|
||
WenXinRequest rs = new WenXinRequest();
|
||
yield return rs.Post(this, wenXinParam);
|
||
response = rs.Response;
|
||
|
||
cardExplainItem.m_explainText.SetText(response);
|
||
gameObject.SetActive(false);
|
||
cardExplainItem.canvasGroup.gameObject.SetActive(true);
|
||
}
|
||
}
|