以下是代码
public class RobotController : MonoBehaviour
{
public TMP_InputField inputField;
public TMP_Text TMP_Text;
public string prompt = @"How many planets are there?";
public AudioSource speechAudioSource;
private ChatHistory history;
private ChatMemory memory;
private readonly string template = "{history}\n{prompt}";
public ILargeLanguageModel ollamaChat;
// Start is called before the first frame update
void Start()
{
ollamaChat = new OllamaChat() { Model = "BobBot" };
history = new ChatHistory();
memory = new ChatBufferMemory() { ChatHistory = history};
inputField.onValueChanged.AddListener((str) => {
prompt = str;
});
}
public void OnClick() {
RunChainlocal();
}
public async UniTask RunChainlocal()
{
var chain = Chain.Set(prompt, "prompt")
| Chain.LoadMemory(memory,"history")
| Chain.Template(template)
| Chain.LLM(ollamaChat)
| Chain.UpdateHistory(history,requestKey:"prompt");
string result = await chain.Run<string>("text");
TMP_Text.text = result.Replace("\n", string.Empty).Trim();
// //AzureTTSStream.Instance.StartTTS(result, speechAudioSource);
// //AzureTTSNormal.Instance.StartTTS(result, speechAudioSource);
}
}
以下是log
[chain/start] [1:chain:StackChain > 9:chain:UpdateHistoryChain] Entering chain run with input:
{"prompt":"我叫什么名字","history":"User: 你好,我叫姚大哥,请你记住我\r\nBot: 好的,很高兴认识你!请告诉我你的名字是什么?\r\nUser: 我的名字是姚大哥\r\nBot: 好的,小姚大哥。很高兴与你交谈!有事可以随时找我聊天哦。\r\n","text":"很抱歉,我不知道你的名字。如果你告诉我,你就能听到我的回答了!"}
[chain/end] [1:chain:StackChain > 9:chain:UpdateHistoryChain] [1.0067ms] Exiting chain run with output:
{"prompt":"我叫什么名字","history":"User: 你好,我叫姚大哥,请你记住我\r\nBot: 好的,很高兴认识你!请告诉我你的名字是什么?\r\nUser: 我的名字是姚大哥\r\nBot: 好的,小姚大哥。很高兴与你交谈!有事可以随时找我聊天哦。\r\n","text":"很抱歉,我不知道你的名字。如果你告诉我,你就能听到我的回答了!"}
[chain/end] [1:chain:StackChain] [786.7143ms] Exiting chain run with output:
{"prompt":"我叫什么名字","history":"User: 你好,我叫姚大哥,请你记住我\r\nBot: 好的,很高兴认识你!请告诉我你的名字是什么?\r\nUser: 我的名字是姚大哥\r\nBot: 好的,小姚大哥。很高兴与你交谈!有事可以随时找我聊天哦。\r\n","text":"很抱歉,我不知道你的名字。如果你告诉我,你就能听到我的回答了!"}
以下是代码 public class RobotController : MonoBehaviour { public TMP_InputField inputField; public TMP_Text TMP_Text; public string prompt = @"How many planets are there?"; public AudioSource speechAudioSource;
} 以下是log [chain/start] [1:chain:StackChain > 9:chain:UpdateHistoryChain] Entering chain run with input: {"prompt":"我叫什么名字","history":"User: 你好,我叫姚大哥,请你记住我\r\nBot: 好的,很高兴认识你!请告诉我你的名字是什么?\r\nUser: 我的名字是姚大哥\r\nBot: 好的,小姚大哥。很高兴与你交谈!有事可以随时找我聊天哦。\r\n","text":"很抱歉,我不知道你的名字。如果你告诉我,你就能听到我的回答了!"}
[chain/end] [1:chain:StackChain > 9:chain:UpdateHistoryChain] [1.0067ms] Exiting chain run with output: {"prompt":"我叫什么名字","history":"User: 你好,我叫姚大哥,请你记住我\r\nBot: 好的,很高兴认识你!请告诉我你的名字是什么?\r\nUser: 我的名字是姚大哥\r\nBot: 好的,小姚大哥。很高兴与你交谈!有事可以随时找我聊天哦。\r\n","text":"很抱歉,我不知道你的名字。如果你告诉我,你就能听到我的回答了!"}
[chain/end] [1:chain:StackChain] [786.7143ms] Exiting chain run with output: {"prompt":"我叫什么名字","history":"User: 你好,我叫姚大哥,请你记住我\r\nBot: 好的,很高兴认识你!请告诉我你的名字是什么?\r\nUser: 我的名字是姚大哥\r\nBot: 好的,小姚大哥。很高兴与你交谈!有事可以随时找我聊天哦。\r\n","text":"很抱歉,我不知道你的名字。如果你告诉我,你就能听到我的回答了!"}