想要使用文心一言,首先要登录百度智能云千帆控制台
https://cloud.baidu.com/product/wenxinworkshop?track=developer_qianfan_tanchuang
1.在控制台找到应用接入 - 然后点击创建应用
2.填写应用信息
3.创建之后,记下API Key 和 Secret Key,等会会用到
4.打开Unity,建一个简单的聊天场景
5.加入测试代码
public class ChatAI: MonoBehaviour
{
public string token;
//这里填写百度千帆大模型里的应用api key
public string api_key = "xxxxxx";
//这里填写百度千帆大模型里的应用secret key
public string secret_key = "xxxxxxxxx";
//发送按钮
public Button sendBtn;
//输入框
public TMP_InputField info;
//AI回应
public TextMeshProUGUI responseText;
// 历史对话
private List<message> historyList = new List<message>();
public void Awake()
{
//初始化文心一言,获取token
StartCoroutine(GetToken());
sendBtn.onClick.AddListener(OnSend);
}
public void OnSend()
{
OnSpeak(info.text);
}
//开始对话
public void OnSpeak(string talk )
{
StartCoroutine(Request(talk));
}
private IEnumerator GetToken()
{
//获取token的api地址
string _token_url = string.Format("https://aip.baidubce.com/oauth/2.0/token" + "?client_id={0}&client_secret={1}&grant_type=client_credentials" , api_key, secret_key);
u