akikurisu / unichat Goto Github PK
View Code? Open in Web Editor NEW一个用于在Unity中开发在线和离线聊天机器人的管线。A pipeline designed to create online and offline chat-bot in Unity.
License: MIT License
一个用于在Unity中开发在线和离线聊天机器人的管线。A pipeline designed to create online and offline chat-bot in Unity.
License: MIT License
Suppose to implement more TTS chains.
A lot of api changed in Unity.Sentis 1.4-pre
.
When retrieval is enabled, bot will appear with duplicate answers.
Bot should not repeat its response in the same session.
Modify filter,or add a preprocessor before it. So we should only allocate tensors among answers that have not been answered.
Pipeline's encoder need load model and tokenizer, currently can only read file from UserData/models.
Suppose to implement STT chains such as whisper.
Langchain is a powerful tool to create agent-based workflow. It will be interesting to implement it in Unity for game AI usage.🥰
I will first create a tool use system for quick verification.
Consider to use finite state machine.
以下是代码
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":"很抱歉,我不知道你的名字。如果你告诉我,你就能听到我的回答了!"}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.