{"id":16759403,"url":"https://github.com/cleoold/markov_cn_node","last_synced_at":"2026-02-26T07:44:40.954Z","repository":{"id":42095168,"uuid":"245939651","full_name":"cleoold/Markov_CN_node","owner":"cleoold","description":"Backend creating random Chinese sentences based on chat history / 根据消息记录生成随机句子","archived":false,"fork":false,"pushed_at":"2022-12-06T16:26:17.000Z","size":328,"stargazers_count":3,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T15:01:57.366Z","etag":null,"topics":["chinese","jieba","markov"],"latest_commit_sha":null,"homepage":"https://cleoold.github.io/Markov_CN_node","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cleoold.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}},"created_at":"2020-03-09T03:56:28.000Z","updated_at":"2022-10-18T23:53:42.000Z","dependencies_parsed_at":"2023-01-24T04:45:44.558Z","dependency_job_id":null,"html_url":"https://github.com/cleoold/Markov_CN_node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cleoold%2FMarkov_CN_node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cleoold%2FMarkov_CN_node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cleoold%2FMarkov_CN_node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cleoold%2FMarkov_CN_node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cleoold","download_url":"https://codeload.github.com/cleoold/Markov_CN_node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248261916,"owners_count":21074225,"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":["chinese","jieba","markov"],"created_at":"2024-10-13T04:08:03.853Z","updated_at":"2026-02-26T07:44:35.930Z","avatar_url":"https://github.com/cleoold.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### construction site!\n\n### Markov-Chinese\n\nGenerates random text based on the input sentences. Simple, one process, no database.\n\n### Intro\n\nThe program will start a server that only does two things:\n* receive sentences to build/update models and \n* output new random Chinese sentences using the Markov chain algorithm, upon calling. \n\nIt can be served as a minimalist backend of a Markov chat bot just by using the http request. Each model must have a name (`string`) that can be differentiated among others and the generated text will be generated using the model with this name.\n\n### Usage\n\nType `npm run start` in the *project root folder* to run the app. By default it runs on `127.0.0.1:6758`, however this can be changed in config.ts.\n\nThe app manages multiple models. Let us assume that the name is `erika`.\n\n#### Insert sentences / modify table\n\nSend the following POST request to the endpoint `/sentence`:\n```\nPOST /sentence HTTP/1.1\nHost: 127.0.0.1:6758\nContent-Type: application/json\n\n{\"id\":\"erika\",\"message\":\"你好，我是马尔可夫机器人\"}\n// OR\n{\"id\":\"erika\",\"message\":[\"你好，我是马尔可夫机器人\", \"哈喽\", \"楼上是群龙王\"]}\n```\nThe posted json must be in a json format:\n* field `id`: the name of the model, it cannot contain any of `/\\?%*:|\"\u003c\u003e`. \n* field `message`: the message passed to the model. This field can be an array of strings, indicating that all of the content will be added.\n\nIf everything works, a folder `models/erika` will be created which contains the history. `conversation.txt` records all the messages sent, while the `json` files contain the actual Markov model. Also a status code `200` is returned. Otherwise codes `400` or `500` are returned, and information is logged to the console.\n\n#### Generate sentence\n\nAfter repeating the above steps many times, one can send a GET request to the endpoint `/sentence` to retrieve a sentence:\n```\nGET /sentence?id=erika\u0026wc=20 HTTP/1.1\nHost: 127.0.0.1:6758\n```\n* parameter `id`: specify the name of the model\n* parameter `wc`: *maximum* word count of the sentence. 10 will be used if this option is not present.\n\nIf the model does not exist, a status code of `404` is returned, otherwise the result json is returned and it looks like\n```\n{\n    \"status\": 200,\n    \"message\": \"楼上是马尔可夫机器人\"\n}\n```\nplus a status code of `200`.\n\nYes, that's all.\n\n#### Scripts\n\n* `npm run start`\n\nStarts server at 127.0.0.1:6758.\n\n* `npm run dict`\n\nThis command will regenerate all the dictionaries based on `conversations.txt`. It is good to run this script every time after a breaking update.\n\n### Thanks to\nThanks to [nodejieba](https://github.com/yanyiwu/nodejieba) for providing such a wonderful word cut library.\n\n### TODO list\n* Complete API readme docs.\n* Improve English sentences (probably necessary).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcleoold%2Fmarkov_cn_node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcleoold%2Fmarkov_cn_node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcleoold%2Fmarkov_cn_node/lists"}