您可以将上面的请求改为以下代码:

public class chatRWKV : LLM
{
    public chatRWKV()
    {
        url = "https://rwkv.ai-creator.net/chntuned/v1/chat/completions";
    }

    // ...

    public override IEnumerator Request(string _postWord, System.Action<string> _callback)
    {
        stopwatch.Restart();
        using (UnityWebRequest request = UnityWebRequest.Post(url, ""))
        {
            PostData _postData = new PostData
            {
                model = m_gptModel,
                messages = m_DataList
            };

            string _jsonText = JsonUtility.ToJson(_postData);
            byte[] data = System.Text.Encoding.UTF8.GetBytes(_jsonText);
            request.uploadHandler = (UploadHandler)new UploadHandlerRaw(data);
            request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();

            request.SetRequestHeader("Content-Type", "application/json");

            yield return request.SendWebRequest();

            if (request.result == UnityWebRequest.Result.Success)
            {
                string _msgBack = request.downloadHandler.text;
                MessageBack _textback = JsonUtility.FromJson<MessageBack>(_msgBack);
                if (_textback != null && _textback.choices.Count > 0)
                {
                    string _backMsg = _textback.choices[0].message.content;
                    m_DataList.Add(new SendData("assistant", _backMsg));
                    _callback(_backMsg);
                }
            }

            stopwatch.Stop();
            Debug.Log("RWKV耗时:" + stopwatch.Elapsed.TotalSeconds);
        }
    }

    // ...
}

这样就将请求改为使用UnityWebRequest发送POST请求,并将URL改为目标API的URL。

model rwkv-world-7b messages role system content role user content 你扮演 + selectedSpeaker + 是我的好朋友。 role assistant content 你好旅行者。 r

原文地址: https://www.cveoy.top/t/topic/i5dK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录