{"id":27111108,"url":"https://github.com/wangle201210/chat-history","last_synced_at":"2025-04-07T00:55:42.363Z","repository":{"id":285727550,"uuid":"959050225","full_name":"wangle201210/chat-history","owner":"wangle201210","description":"chat-history","archived":false,"fork":false,"pushed_at":"2025-04-02T10:47:26.000Z","size":22,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T11:26:34.983Z","etag":null,"topics":["chat-history","chat-history-database","eino","llm"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wangle201210.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-04-02T07:28:09.000Z","updated_at":"2025-04-02T10:49:06.000Z","dependencies_parsed_at":"2025-04-02T11:37:05.854Z","dependency_job_id":null,"html_url":"https://github.com/wangle201210/chat-history","commit_stats":null,"previous_names":["wangle201210/chat-history"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangle201210%2Fchat-history","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangle201210%2Fchat-history/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangle201210%2Fchat-history/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangle201210%2Fchat-history/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wangle201210","download_url":"https://codeload.github.com/wangle201210/chat-history/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247574072,"owners_count":20960495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chat-history","chat-history-database","eino","llm"],"created_at":"2025-04-07T00:55:41.407Z","updated_at":"2025-04-07T00:55:42.351Z","avatar_url":"https://github.com/wangle201210.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chat-history\n聊天历史记录管理\n\n## 为什么需要\n目前eino提供了快捷接入大模型的方法但是聊天历史记录的功能没有提供，导致没法进行对轮对话，及对话管理\n\n## 怎么接入\n可以参照 [example](./example)\n1. 安装依赖 `go get github.com/wangle201210/chat-history` \n\n2. 初始化 EinoHistory\n```go\nvar eh = eino.NewEinoHistory(\"root:123456@tcp(127.0.0.1:3306)/chat_history\")\n```\n\n3. 在原来获取messages的地方添加 add start -- add end 之间的代码 \n```go\nfunc createMessagesFromTemplate(ctx context.Context, convID, question string) (messages []*schema.Message, err error) {\n\ttemplate := createTemplate(ctx)\n\t/* add start */\n\tchatHistory, err := eh.GetHistory(convID, 100)\n\tif err != nil {\n\t\treturn\n\t}\n\t// 插入一条用户数据\n\terr = eh.SaveMessage(\u0026schema.Message{\n\t\tRole:    schema.User,\n\t\tContent: question,\n\t}, convID)\n\tif err != nil {\n\t\treturn\n\t}\n\t/* add end */\n\t// 使用模板生成消息\n\tmessages, err = template.Format(context.Background(), map[string]any{\n\t\t\"role\":         \"程序员鼓励师\",\n\t\t\"style\":        \"积极、温暖且专业\",\n\t\t\"question\":     question,\n\t\t\"chat_history\": chatHistory,\n\t})\n\tif err != nil {\n\t\treturn\n\t}\n\treturn\n}\n```\n4. 在返回消息的地方添加 add start -- add end 之间的代码 \n```go\n    messages, err := createMessagesFromTemplate(ctx, convID, s)\n    if err != nil {\n        log.Fatalf(\"create messages failed: %v\", err)\n        return\n    }\n    result := generate(ctx, cm, messages)\n    /* add start */\n    err = eh.SaveMessage(result, convID)\n    if err != nil {\n        log.Fatalf(\"save assistant message err: %v\", err)\n        return\n    }\n    /* add end */\n    log.Printf(\"result: %+v\\n\\n\", result)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangle201210%2Fchat-history","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwangle201210%2Fchat-history","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangle201210%2Fchat-history/lists"}