AkiKurisu / UniChat

一个用于在Unity中开发在线和离线聊天机器人的管线。A pipeline designed to create online and offline chat-bot in Unity.
MIT License
40 stars 7 forks source link

记忆没有正常产生 #13

Open busiyg opened 1 month ago

busiyg commented 1 month ago

以下是代码 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":"很抱歉,我不知道你的名字。如果你告诉我,你就能听到我的回答了!"}

AkiKurisu commented 1 month ago

你的ollama版本是多少?看起来是上下文模型侧没有接受/处理到。

busiyg commented 1 month ago

0.1.36,请问记忆功能目前只有这一种实现方式吗,token看不起不小

AkiKurisu commented 1 month ago

刚看出问题,你没有await task😂