Metadata-Version: 2.4
Name: skk
Version: 2026.3.2
Summary: 本项目封装了一些Python开发中常用的功能，帮助你更高效地开发应用。
Author-email: 许灿标 <canbiaoxu@outlook.com>
Requires-Python: >=3.12
Description-Content-Type: text/markdown
Classifier: License :: OSI Approved :: Apache Software License
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: pymysql
Requires-Dist: aiomysql
Requires-Dist: pymongo
Requires-Dist: motor
Requires-Dist: tornado
Requires-Dist: openai
Requires-Dist: asyncpg

# SKK

本项目封装了一些Python开发中常用的功能，帮助你更高效地开发应用。

## 项目链接

- [贡献者列表](https://github.com/canbiaoxu/skk/graphs/contributors)
- [GitHub](https://github.com/canbiaoxu/skk)
- [PyPI](https://pypi.org/project/skk)

## 安装

```bash
pip install skk
```

## 功能分类

### AI

* [micro_cognition -- 基于微范式的 AI 推理模型](https://github.com/canbiaoxu/skk/tree/main/skk/micro_cognition)
* [ollama -- 在 windows 平台上部署 deepseek 本地版，并用 python 调用](https://github.com/canbiaoxu/skk/tree/main/skk/ollama)
* [openai -- 访问ChatGPT](https://github.com/canbiaoxu/skk/tree/main/skk/openai)

### 数据库

* [mysql -- 访问MySQL数据库](https://github.com/canbiaoxu/skk/tree/main/skk/mysql)
* [mongo -- 访问MongoDB数据库](https://github.com/canbiaoxu/skk/tree/main/skk/mongo)
* [postgre -- 访问PostgreSQL数据库](https://github.com/canbiaoxu/skk/tree/main/skk/postgre)
* [objdb -- 访问ObjDB数据库](https://github.com/canbiaoxu/skk/tree/main/skk/objdb)

# 邀请贡献

欢迎有志之士一起完善这个软件包。贡献步骤：

1. Fork仓库。
2. 新增或修订内容。
3. 提交Commit并推送到你的仓库。
4. 发起PR说明修改内容。

# micro_cognition -- 基于微范式的 AI 推理模型

## 导入

```python
from skk.micro_cognition import (
    Paradigm,  # 范式类
    Obj,  # 对象类
    reasoning,  # 推理引擎
)
```

## 尝试推理: `把水泼脸上`

```python
question = '把水泼脸上'
print(reasoning(question))  # >>> None
```

由于我们尚未创建任何范式和对象, 所以推理结果为None.

## 建模并推理: `把水泼脸上`

```python
# 创建水对象
class 水(Obj):
    keywords = [
        ['水'],
        ['H2O'],
    ]

# 创建脸对象
class 脸(Obj):
    keywords = [
        ['脸'],
    ]

# 创建范式
class 接触(Paradigm):
    keywords = [
        ['泼'],
    ]
    @classmethod
    def reason(cls, obj1, obj2):
        if {obj1, obj2} == {水, 脸}:
            return '脸会变湿'

# 推理
print(reasoning('把水泼脸上'))  # >>> '脸会变湿'
print(reasoning('泼脸上, 用水'))  # >>> '脸会变湿'
```

## 增量建模并推理: `把沸腾的水泼脸上`

```python
# 创建沸水对象
class 沸腾的水(Obj):
    keywords = [
        ['沸水'],
        ['沸腾', '水'],
        ['沸腾', 'H2O'],
    ]

# 更新接触范式
class 接触(Paradigm):
    keywords = [
        ['泼'],
    ]
    @classmethod
    def reason(cls, obj1, obj2):
        if {obj1, obj2} == {水, 脸}:
            return '脸会变湿'
        # 新增以下代码
        if {obj1, obj2} == {沸腾的水, 脸}:
            return '脸会被烫伤'

print(reasoning('把沸腾的水泼脸上'))  # >>> '脸会被烫伤'
print(reasoning('泼脸上, 用沸腾的水'))  # >>> '脸会被烫伤'
```

## 尝试推理: `把水加热, 然后泼脸上`

```python
print(reasoning('把水加热, 然后泼脸上'))  # >>> '脸会变湿'
```

由于我们尚未创建 `水->加热->沸水` 的范式, 所以推理结果仍为 `脸会变湿` .

## 增量建模并推理: `把水加热, 然后泼脸上`

```python
# 创建加热范式
class 加热(Paradigm):
    keywords = [
        ['加热'],
        ['加温度'],
        ['提高温度'],
    ]
    @classmethod
    def reason(cls, obj):
        if issubclass(obj, 水): 
            return 沸腾的水

print(reasoning('把水加热, 然后泼脸上'))  # >>> '脸会被烫伤'
print(reasoning('加热水, 然后泼脸上'))  # >>> '脸会被烫伤'
```

# 交流

添加我的微信，并备注“进群”，拉你进微信交流群：

<img src="https://raw.githubusercontent.com/canbiaoxu/skk/refs/heads/main/skk/wechat_qr_code.jpg" alt="二维码" style="width: 15rem;" />

