xiaothink


Namexiaothink JSON
Version 1.0.2 PyPI version JSON
download
home_pageNone
Summary一个AI工具包,帮助用户快速调用小思框架(Xiaothink)相关接口。
upload_time2024-12-22 03:18:33
maintainerNone
docs_urlNone
authorEricsjq
requires_python>=3
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Xiaothink Python 模块使用文档

Xiaothink 是一个以自然语言处理(NLP)为核心的AI研究组织,致力于提供高效、灵活的工具来满足各种应用场景的需求。Xiaothink Python 模块是该组织提供的核心工具包,涵盖了图像生成、文本续写、颜值评分以及对话模型等多种功能。以下是详细的使用指南和代码示例。

## 目录
1. [安装](#安装)
2. [图像生成](#图像生成)
3. [文本续写](#文本续写)
4. [颜值评分](#颜值评分)
5. [在线AI对话](#在线ai对话)
6. [本地对话模型](#本地对话模型)

---

## 安装

首先,您需要通过 pip 安装 Xiaothink 模块:

```bash
pip install xiaothink
```

---

## 图像生成

Xiaothink 提供了强大的图像生成功能,可以通过简单的 API 调用来生成高质量的图像。

### 示例代码

```python
import xiaothink as xt

drawer = xt.openapi.drawer.Drawer(return_type='bytes')
with open('a.jpg', 'wb') as f:
    f.write(drawer.draw('两只猫', style=6))
```

---

## 文本续写

您可以使用 Xiaothink 的文本续写功能来生成连贯且有意义的文本内容。

### 示例代码

```python
import xiaothink as xt

text = '从前,由一位老人,'
out_ = xt.openapi.writer.write(text)
print('续写内容:', out_)
```

---

## 颜值评分

Xiaothink 提供了基于 Web URL 的颜值评分服务。请注意,该服务仅支持传入网络图片 URL,不支持本地路径。

### 示例代码

```python
import xiaothink as xt

image_url = "https://example.com/image.jpg"
num = xt.openapi.yanzhi.get_score(image_url)
print('颜值得分:', num)
```

**重要提示**:`xt.openapi.yanzhi.get_score` 函数只支持传入 Web URL,不支持传入本地路径。

---

## 在线AI对话

Xiaothink 提供了一个简便易用的在线 AI 对话接口。设置用户名后即可进行多轮对话。


### 示例代码

```python
import xiaothink as xt

xt.openapi.set_conf.set_user('YOUR_USERNAME')

while True:
    inp = input('【问】:')
    re = xt.openapi.chatbot_old.chat(inp)
    print('\n【答】:', re, '\n')
```

**重要提示**:在线 AI 对话与本地模型对话是两个完全不同的系统,毫无关系。`xt.openapi.chatbot_old.chat` 函数设置用户名后便支持多轮对话。

---

## 本地对话模型

对于本地加载的对话模型,根据模型类型的不同,应调用相应的函数来进行对话。

### 单轮对话

适用于单轮对话场景。

### 示例代码

```python
import xiaothink.llm.inference.test_formal as tf

model = tf.QianyanModel(
    ckpt_dir=r'E:\小思框架\论文\ganskchat\ckpt_test_40_2_3_1_formal_open',
    MT=40.231,
    vocab=r'E:\小思框架\论文\ganskchat\vocab_lx3.txt'
)

while True:
    inp = input('【问】:')
    if inp == '[CLEAN]':
        print('【清空上下文】\n\n')
        model.clean_his()
        continue
    re = model.chat_SingleTurn(inp)  # 使用 chat_SingleTurn 进行单轮对话
    print('\n【答】:', re, '\n')
```

### 多轮对话

适用于多轮对话场景。

### 示例代码

```python
import xiaothink.llm.inference.test as test

MT = 40.231
m, d = test.load(
    ckpt_dir=r'E:\小思框架\论文\ganskchat\ckpt_test_40_2_3_1_qas',
    model_type=MT,
    vocab=r'E:\小思框架\论文\ganskchat\vocab_lx3.txt',
)

b_chat = {
    1: '给定一个数字列表,找出其中的最大值和最小值。\n数字列表:[3, 9, 2, 7, 5, 1, 8, 4, 6, 0]',
    2: '请生成一段关于“春风”为主题的短故事,提供完整的答案。\n',
    3: '请回答下列问题:“什么是全球变暖?”\n',
    4: '请创建一个简单的Python程序,用于计算两数乘积\n',
    5: '创建一个简单的计算器,并提供任何必需的数学原理。\n',
    6: '根据给定的单词,生成与该单词相关的五个同义词。\n单词:友谊\n',
}[6]

belle_chat = '{"instruction": "{b_chat}", "input": "", "output": "'.replace('{b_chat}', b_chat)
inp_m = belle_chat

ret = test.generate_texts_loop(m, d, inp_m,
                               num_generate=100,
                               every=lambda a: print(a, end='', flush=True),
                               temperature=0.55,
                               pass_char=['▩'])
```

**重要提示**:对于本地模型,单论对话模型应调用 `model.chat_SingleTurn` 函数,多轮对话模型应调用 `model.chat` 函数。

---

以上就是 Xiaothink Python 模块的主要功能及使用方法。

如有任何疑问或建议,请随时联系我们:xiaothink@foxmail.com。


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "xiaothink",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": null,
    "keywords": null,
    "author": "Ericsjq",
    "author_email": "xiaothink@foxmail.com",
    "download_url": "https://files.pythonhosted.org/packages/42/5a/75f5d198d9aa5b157b9c5b61f5f4d47e619ca3deb8ad8479e08836243dee/xiaothink-1.0.2.tar.gz",
    "platform": null,
    "description": "# Xiaothink Python \u6a21\u5757\u4f7f\u7528\u6587\u6863\n\nXiaothink \u662f\u4e00\u4e2a\u4ee5\u81ea\u7136\u8bed\u8a00\u5904\u7406\uff08NLP\uff09\u4e3a\u6838\u5fc3\u7684AI\u7814\u7a76\u7ec4\u7ec7\uff0c\u81f4\u529b\u4e8e\u63d0\u4f9b\u9ad8\u6548\u3001\u7075\u6d3b\u7684\u5de5\u5177\u6765\u6ee1\u8db3\u5404\u79cd\u5e94\u7528\u573a\u666f\u7684\u9700\u6c42\u3002Xiaothink Python \u6a21\u5757\u662f\u8be5\u7ec4\u7ec7\u63d0\u4f9b\u7684\u6838\u5fc3\u5de5\u5177\u5305\uff0c\u6db5\u76d6\u4e86\u56fe\u50cf\u751f\u6210\u3001\u6587\u672c\u7eed\u5199\u3001\u989c\u503c\u8bc4\u5206\u4ee5\u53ca\u5bf9\u8bdd\u6a21\u578b\u7b49\u591a\u79cd\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u4f7f\u7528\u6307\u5357\u548c\u4ee3\u7801\u793a\u4f8b\u3002\n\n## \u76ee\u5f55\n1. [\u5b89\u88c5](#\u5b89\u88c5)\n2. [\u56fe\u50cf\u751f\u6210](#\u56fe\u50cf\u751f\u6210)\n3. [\u6587\u672c\u7eed\u5199](#\u6587\u672c\u7eed\u5199)\n4. [\u989c\u503c\u8bc4\u5206](#\u989c\u503c\u8bc4\u5206)\n5. [\u5728\u7ebfAI\u5bf9\u8bdd](#\u5728\u7ebfai\u5bf9\u8bdd)\n6. [\u672c\u5730\u5bf9\u8bdd\u6a21\u578b](#\u672c\u5730\u5bf9\u8bdd\u6a21\u578b)\n\n---\n\n## \u5b89\u88c5\n\n\u9996\u5148\uff0c\u60a8\u9700\u8981\u901a\u8fc7 pip \u5b89\u88c5 Xiaothink \u6a21\u5757\uff1a\n\n```bash\npip install xiaothink\n```\n\n---\n\n## \u56fe\u50cf\u751f\u6210\n\nXiaothink \u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u56fe\u50cf\u751f\u6210\u529f\u80fd\uff0c\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u7684 API \u8c03\u7528\u6765\u751f\u6210\u9ad8\u8d28\u91cf\u7684\u56fe\u50cf\u3002\n\n### \u793a\u4f8b\u4ee3\u7801\n\n```python\nimport xiaothink as xt\n\ndrawer = xt.openapi.drawer.Drawer(return_type='bytes')\nwith open('a.jpg', 'wb') as f:\n    f.write(drawer.draw('\u4e24\u53ea\u732b', style=6))\n```\n\n---\n\n## \u6587\u672c\u7eed\u5199\n\n\u60a8\u53ef\u4ee5\u4f7f\u7528 Xiaothink \u7684\u6587\u672c\u7eed\u5199\u529f\u80fd\u6765\u751f\u6210\u8fde\u8d2f\u4e14\u6709\u610f\u4e49\u7684\u6587\u672c\u5185\u5bb9\u3002\n\n### \u793a\u4f8b\u4ee3\u7801\n\n```python\nimport xiaothink as xt\n\ntext = '\u4ece\u524d\uff0c\u7531\u4e00\u4f4d\u8001\u4eba\uff0c'\nout_ = xt.openapi.writer.write(text)\nprint('\u7eed\u5199\u5185\u5bb9\uff1a', out_)\n```\n\n---\n\n## \u989c\u503c\u8bc4\u5206\n\nXiaothink \u63d0\u4f9b\u4e86\u57fa\u4e8e Web URL \u7684\u989c\u503c\u8bc4\u5206\u670d\u52a1\u3002\u8bf7\u6ce8\u610f\uff0c\u8be5\u670d\u52a1\u4ec5\u652f\u6301\u4f20\u5165\u7f51\u7edc\u56fe\u7247 URL\uff0c\u4e0d\u652f\u6301\u672c\u5730\u8def\u5f84\u3002\n\n### \u793a\u4f8b\u4ee3\u7801\n\n```python\nimport xiaothink as xt\n\nimage_url = \"https://example.com/image.jpg\"\nnum = xt.openapi.yanzhi.get_score(image_url)\nprint('\u989c\u503c\u5f97\u5206\uff1a', num)\n```\n\n**\u91cd\u8981\u63d0\u793a**\uff1a`xt.openapi.yanzhi.get_score` \u51fd\u6570\u53ea\u652f\u6301\u4f20\u5165 Web URL\uff0c\u4e0d\u652f\u6301\u4f20\u5165\u672c\u5730\u8def\u5f84\u3002\n\n---\n\n## \u5728\u7ebfAI\u5bf9\u8bdd\n\nXiaothink \u63d0\u4f9b\u4e86\u4e00\u4e2a\u7b80\u4fbf\u6613\u7528\u7684\u5728\u7ebf AI \u5bf9\u8bdd\u63a5\u53e3\u3002\u8bbe\u7f6e\u7528\u6237\u540d\u540e\u5373\u53ef\u8fdb\u884c\u591a\u8f6e\u5bf9\u8bdd\u3002\n\n\n### \u793a\u4f8b\u4ee3\u7801\n\n```python\nimport xiaothink as xt\n\nxt.openapi.set_conf.set_user('YOUR_USERNAME')\n\nwhile True:\n    inp = input('\u3010\u95ee\u3011\uff1a')\n    re = xt.openapi.chatbot_old.chat(inp)\n    print('\\n\u3010\u7b54\u3011\uff1a', re, '\\n')\n```\n\n**\u91cd\u8981\u63d0\u793a**\uff1a\u5728\u7ebf AI \u5bf9\u8bdd\u4e0e\u672c\u5730\u6a21\u578b\u5bf9\u8bdd\u662f\u4e24\u4e2a\u5b8c\u5168\u4e0d\u540c\u7684\u7cfb\u7edf\uff0c\u6beb\u65e0\u5173\u7cfb\u3002`xt.openapi.chatbot_old.chat` \u51fd\u6570\u8bbe\u7f6e\u7528\u6237\u540d\u540e\u4fbf\u652f\u6301\u591a\u8f6e\u5bf9\u8bdd\u3002\n\n---\n\n## \u672c\u5730\u5bf9\u8bdd\u6a21\u578b\n\n\u5bf9\u4e8e\u672c\u5730\u52a0\u8f7d\u7684\u5bf9\u8bdd\u6a21\u578b\uff0c\u6839\u636e\u6a21\u578b\u7c7b\u578b\u7684\u4e0d\u540c\uff0c\u5e94\u8c03\u7528\u76f8\u5e94\u7684\u51fd\u6570\u6765\u8fdb\u884c\u5bf9\u8bdd\u3002\n\n### \u5355\u8f6e\u5bf9\u8bdd\n\n\u9002\u7528\u4e8e\u5355\u8f6e\u5bf9\u8bdd\u573a\u666f\u3002\n\n### \u793a\u4f8b\u4ee3\u7801\n\n```python\nimport xiaothink.llm.inference.test_formal as tf\n\nmodel = tf.QianyanModel(\n    ckpt_dir=r'E:\\\u5c0f\u601d\u6846\u67b6\\\u8bba\u6587\\ganskchat\\ckpt_test_40_2_3_1_formal_open',\n    MT=40.231,\n    vocab=r'E:\\\u5c0f\u601d\u6846\u67b6\\\u8bba\u6587\\ganskchat\\vocab_lx3.txt'\n)\n\nwhile True:\n    inp = input('\u3010\u95ee\u3011\uff1a')\n    if inp == '[CLEAN]':\n        print('\u3010\u6e05\u7a7a\u4e0a\u4e0b\u6587\u3011\\n\\n')\n        model.clean_his()\n        continue\n    re = model.chat_SingleTurn(inp)  # \u4f7f\u7528 chat_SingleTurn \u8fdb\u884c\u5355\u8f6e\u5bf9\u8bdd\n    print('\\n\u3010\u7b54\u3011\uff1a', re, '\\n')\n```\n\n### \u591a\u8f6e\u5bf9\u8bdd\n\n\u9002\u7528\u4e8e\u591a\u8f6e\u5bf9\u8bdd\u573a\u666f\u3002\n\n### \u793a\u4f8b\u4ee3\u7801\n\n```python\nimport xiaothink.llm.inference.test as test\n\nMT = 40.231\nm, d = test.load(\n    ckpt_dir=r'E:\\\u5c0f\u601d\u6846\u67b6\\\u8bba\u6587\\ganskchat\\ckpt_test_40_2_3_1_qas',\n    model_type=MT,\n    vocab=r'E:\\\u5c0f\u601d\u6846\u67b6\\\u8bba\u6587\\ganskchat\\vocab_lx3.txt',\n)\n\nb_chat = {\n    1: '\u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57\u5217\u8868\uff0c\u627e\u51fa\u5176\u4e2d\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u3002\\n\u6570\u5b57\u5217\u8868\uff1a[3, 9, 2, 7, 5, 1, 8, 4, 6, 0]',\n    2: '\u8bf7\u751f\u6210\u4e00\u6bb5\u5173\u4e8e\u201c\u6625\u98ce\u201d\u4e3a\u4e3b\u9898\u7684\u77ed\u6545\u4e8b\uff0c\u63d0\u4f9b\u5b8c\u6574\u7684\u7b54\u6848\u3002\\n',\n    3: '\u8bf7\u56de\u7b54\u4e0b\u5217\u95ee\u9898\uff1a\u201c\u4ec0\u4e48\u662f\u5168\u7403\u53d8\u6696\uff1f\u201d\\n',\n    4: '\u8bf7\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Python\u7a0b\u5e8f\uff0c\u7528\u4e8e\u8ba1\u7b97\u4e24\u6570\u4e58\u79ef\\n',\n    5: '\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u5668\uff0c\u5e76\u63d0\u4f9b\u4efb\u4f55\u5fc5\u9700\u7684\u6570\u5b66\u539f\u7406\u3002\\n',\n    6: '\u6839\u636e\u7ed9\u5b9a\u7684\u5355\u8bcd\uff0c\u751f\u6210\u4e0e\u8be5\u5355\u8bcd\u76f8\u5173\u7684\u4e94\u4e2a\u540c\u4e49\u8bcd\u3002\\n\u5355\u8bcd\uff1a\u53cb\u8c0a\\n',\n}[6]\n\nbelle_chat = '{\"instruction\": \"{b_chat}\", \"input\": \"\", \"output\": \"'.replace('{b_chat}', b_chat)\ninp_m = belle_chat\n\nret = test.generate_texts_loop(m, d, inp_m,\n                               num_generate=100,\n                               every=lambda a: print(a, end='', flush=True),\n                               temperature=0.55,\n                               pass_char=['\u25a9'])\n```\n\n**\u91cd\u8981\u63d0\u793a**\uff1a\u5bf9\u4e8e\u672c\u5730\u6a21\u578b\uff0c\u5355\u8bba\u5bf9\u8bdd\u6a21\u578b\u5e94\u8c03\u7528 `model.chat_SingleTurn` \u51fd\u6570\uff0c\u591a\u8f6e\u5bf9\u8bdd\u6a21\u578b\u5e94\u8c03\u7528 `model.chat` \u51fd\u6570\u3002\n\n---\n\n\u4ee5\u4e0a\u5c31\u662f Xiaothink Python \u6a21\u5757\u7684\u4e3b\u8981\u529f\u80fd\u53ca\u4f7f\u7528\u65b9\u6cd5\u3002\n\n\u5982\u6709\u4efb\u4f55\u7591\u95ee\u6216\u5efa\u8bae\uff0c\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\uff1axiaothink@foxmail.com\u3002\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "\u4e00\u4e2aAI\u5de5\u5177\u5305\uff0c\u5e2e\u52a9\u7528\u6237\u5feb\u901f\u8c03\u7528\u5c0f\u601d\u6846\u67b6\uff08Xiaothink\uff09\u76f8\u5173\u63a5\u53e3\u3002",
    "version": "1.0.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f1a46c719e77403b7611a46569567721dad84d7073ac1357de690b2d1e37deb9",
                "md5": "3116e74885a497e4c345316ee42c7721",
                "sha256": "74f9504a36cf1da3700b5170c8884dbf58b7fd1f0ba2094fa1486c2ed1473238"
            },
            "downloads": -1,
            "filename": "xiaothink-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3116e74885a497e4c345316ee42c7721",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3",
            "size": 48196,
            "upload_time": "2024-12-22T03:18:32",
            "upload_time_iso_8601": "2024-12-22T03:18:32.496133Z",
            "url": "https://files.pythonhosted.org/packages/f1/a4/6c719e77403b7611a46569567721dad84d7073ac1357de690b2d1e37deb9/xiaothink-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "425a75f5d198d9aa5b157b9c5b61f5f4d47e619ca3deb8ad8479e08836243dee",
                "md5": "2178518ac8b5397e085274ca0bc1ce2b",
                "sha256": "167c12571bfcb8428eb616341b3ac7b0c5c77dda73d6f74a6d999ddaea8c624a"
            },
            "downloads": -1,
            "filename": "xiaothink-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "2178518ac8b5397e085274ca0bc1ce2b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 46930,
            "upload_time": "2024-12-22T03:18:33",
            "upload_time_iso_8601": "2024-12-22T03:18:33.919099Z",
            "url": "https://files.pythonhosted.org/packages/42/5a/75f5d198d9aa5b157b9c5b61f5f4d47e619ca3deb8ad8479e08836243dee/xiaothink-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-22 03:18:33",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "xiaothink"
}
        
Elapsed time: 0.70082s