intc-lsp


Nameintc-lsp JSON
Version 0.1.0b0 PyPI version JSON
download
home_pagehttps://github.com/cstsunfu/intc
Summaryintc-lsp: intc language server
upload_time2024-04-07 12:14:53
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseApache License 2.0
keywords intc lsp intc-lsp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <h2 align="center"> Python Intelligence Config Manager</h2>
</p>

<p align="center">
A Python Config Manager for Humans
</p>


<div style="text-align:center">
<span style="width:70%;display:inline-block">

![main](./pics/vsc_main.png)

</div>

<h4 align="center">
    <p>
        <b>简体中文</b> |
        <a href="https://github.com/cstsunfu/dlk/blob/main/README_en.md">English</a>
    </p>
</h4>

* [安装](#安装)
* [Feature List](#feature-list)
* [Intc Use Case](#intc-use-case)
    * [参数引用及lambda语法](#参数引用及lambda语法)
    * [参数搜索](#参数搜索)
    * [DataClass && Json Schema](#dataclass-json-schema)
* [Intc-LSP](#intc-lsp)
    * [Hover Document](#hover-document)
    * [Diagnostic](#diagnostic)
    * [Completion](#completion)
    * [Goto/Peek Definition](#gotopeek-definition)


`intc`是一个功能强大的智能config配置管理工具,它不仅为我们的配置文件提供模块继承、模块嵌套、参数引用、超参搜索,还支持基于`lambda`表达式的复杂参数动态计算等功能。

而`intc`的配套Language Server Protocol(`intc-lsp`)则让我们的编辑浏览体验更加丝滑,它将配置文件与`python`代码紧密联合,`intc-lsp`可以帮助你在书写和阅读`intc`文件时方便的获取`python`的语义信息,提供错误提示、参数补全、智能跳转和参数帮助文档展示的功能。

除了用于`config`,`intc`还可以直接作为`dataclass`使用,它可以将我们使用`intc`定义的`dataclass`转化为`json schema`用于如`LLM`的数据类型约束,还可以对如`LLM`返回值在内的`json`数据进行数据检查并生成错误提示用于`LLM`的迭代优化。

### 安装

1. 准备`python`环境,要求`python>=3.8`,且目前只在`Linux`和`Mac`上面进行了测试,`Windows`的支持可能存在问题
2. 安装`intc`和`intc-lsp`,如果不需要使用智能补全等功能可以只安装`intc`

```bash
# install from pypi
pip install intc
pip install intc-lsp
```

或直接源码安装
```bash
cd intc/
pip install .
cd ../lsp
pip install .
```

3. 安装智能补全插件(Plugins)

`intc`提供了一个通用的Language Server Protocol(`LSP`),理论上只要你使用的编辑器或`IDE`支持`LSP`就可以使用,但是我平时主要使用`(neo)vim`,偶尔用一下`vscode`,因此目前只在这两种编辑器上做了适配

* neovim

`neovim`功能强大且易于扩展,社区已经对`LSP`提供了非常友好的支持,具体参考`plugins/neovim`

* vscode
  `vscode`也可以通过安装`intc-lsp`对应的插件来获取`lsp`的支持,具体参考 `plugins/vscode`

* 其他IDE与编辑器

  需要有相关经验的同学帮忙完善文档

### Feature List

下面是一些主要功能的简单介绍,具体用法可以跳转到对应的use case进行查看

* 模块继承
    * intc的python类之间可以和正常的python类一样进行继承
    * intc的config文件则是python类的实例化参数,同样可以看做是继承自Python类
    * 除此之外在一些复杂的config文件中config之间也可以存在继承关系.
* 模块嵌套,模块之间可以进行嵌套,一个更高级别的模块除了自己的参数之外还可以包含其他子模块,如在训练神经网络的任务中一个trainer除了自己的一些参数之外还可以包含model、optimizer和schedule等子模块
* 参数引用,一个参数可以依赖一个或多个其他参数的值,支持lambda动态计算参数的值
* 参数搜索,在很多任务中我们有多种参数组合,intc以笛卡尔积的形式展开所有的参数组合
* dataclass,作为dataclass可以直接作为某个模块的参数类、可以生成json schema、可以对参数进行检查

* config帮助文档,intc-lsp提供参数hover提示,当指针放到参数上时展示参数的帮助文档
* config错误提示,intc-lsp检查你的参数填写是否正确
* config参数补全,intc-lsp在你编辑config文件时进行语义补全
* config参数跳转,intc-lsp为你在浏览或编辑config文件时提供`goto/peek definition` python源码提供支持

* etc.

### Intc Use Case

我们将以`intc/examples/exp1`中的例子开始来介绍intc的基本用法

样例结构:

```
├── config                         -- config文件,目前支持json和jsonc文件,需要在.intc.json中指定config所在目录
│   ├── model.json
│   └── model_search.jsonc
├── .intc.json                     -- intc需要的meta数据
├── run.py                         -- your own code
└── src                            -- your project
    └── __init__.py
```

和一个普通的python项目相比,intc项目需要一个`.intc.json` 文件来描述项目的一些`meta`数据, 下面是这个exp中的配置:

```.intc.json
{
    // "module": ["config/module"],  // submodule所在目录, 相对于当前目录, 这个exp中没有submodule
    "entry": ["config"],                 // config所在目录, 相对于当前目录
    "src": [                           // config文件中用到的python模块,需要可以直接通过python import
        "src"
    ]
}

```

而使用intc的python代码则与dataclass非常相似,相比于python自带的dataclass提供了如数值检查、模型注册、生成json schema等功能

```python
from intc import (
    MISSING,            # MISSING是一个常量(在intc中的值为`???`)表示参数缺失,需要在实例化config时提供
    Base,               # 所有的intc dataclass 都继承该类(可以隐式继承)
    BoolField,          # 这些bool field
    DictField,          # dict field
    FloatField,         # ...
    IntField,
    AnyField,
    ListField,
    NestField,          # 嵌套field,相比dict可以提供更多的类型检查、智能补全等功能
    StrField,
    SubModule,
    cregister,          # cregister注册intc实例(支持二级命名, <module_type, module_name> ),用于实例的索引(通过<module_type, module_name>直接获取对应的model类,config中也会使用注册名来定位对应的model类
)


@cregister("model", "simple_cls")  # cregister将Model注册为intc类,`module_type`为`model`, `module_name`为`simple_cls`
class Model(Base):                 # 显式继承自Base,这里也可以不显式继承,register过程会自动执行这个过程,显式的继承可以提供更好的语义补全
    embedding_combine_method = StrField( # dataclass的属性定义
        value="concat",                  # 默认值
        options=["concat", "concat_linear"], # options 表示值必须是这几个里面的一个
        help="the combine method, just `concat` or use `linear` on the concated embedding",
    )
    embedding_size = IntField(
        value=MISSING, help="the sum of bert and glove embedding size" # 这里的default value为MISSING,需要在实例化时提供
    )
    active = StrField(
        value="relu",
        options=["relu", "tanh", "sigmoid", "none"],
        help="the activation function",
    )
    submodule = SubModule(   # 子模型,可以嵌套其他模型的定义,这里的子模型可以有多个,引用子模型需要用到这些子模型的注册名
        value={},
        suggestions=[        # suggestions 表示推荐的一些值, 对于代码阅读和intc-lsp的语义解析有帮助
            "embedding",
            "decode",
        ],
        help="submodules for basic model",
    )

@cregister("embedding", "bert")
class BertEmbedding:
    hidden_size = IntField(
        value=MISSING,
        minimum=1,
        help="the input/output/hidden size for bert, must >= 1",
    )
    dropout_rate = FloatField(
        value=0.0, minimum=0.0, maximum=1.0, help="the dropout rate for bert"  #
    )
....
```
实际开发过程中,我们往往使用config文件对业务逻辑进行配置,而json(及其衍生格式,如jsonc)非常适合用来编辑配置文件,`intc`配合`intc-lsp`对此提供了非常好的支持, 下面是针对已有的dataclass进行配置的例子:

```jsonc
// 文件 config/model.jsonc
{
    "@model@simple_cls": {  // 表明是对谁进行配置,格式为@module_type@module_name @model@simple_cls 对应被注册为这个名称的`Model`
        "active": "none",
        "embedding_size": "@$.@glove.hidden_size, @$.@bert.hidden_size @lambda x, y: x+y", // 这里的值为动态的lambda计算的,喊一声 embedding_size的值为@embedding@glove.hidden_size和@embedding@bert.hidden_size 的和, 关于lambda的语法请看本说明里面关于lambda的介绍
        "@embedding@glove": { // submodule, submodule 同样以@module_type@module_name作为标识
            "hidden_size": 300,
            "vocab_size": 5000
        },
        "@embedding@bert": {
            "hidden_size": 768
        }
    }
}
```
```python
# 文件 main.py
import exp

```
#### 参数引用及lambda语法

我们经常会遇到如一个encode模块的输出和decode模块的输入的维度相同,在配置文件中我们希望这两个参数的值始终保持一致,intc支持一个参数是另一个参数的引用,这样我们只需要修改其中的一个参数另一个参数的值也同步被修改了。



有时我们的一个参数的值依赖于多个其他参数,如在一个多encode的模型中,decode模块的输入维度是所有encode模型输出的维度的和,针对这种复杂的引用,intc提供`lambda`支持复杂的动态值计算.

在介绍`lambda`表达式之前,我们先对参数的引用规则进行介绍:

我们以下面的config为例:
```json
{
    "@parent@p": {
        "para_p_a": "value_p_a"
        "@wang@lao": {
            "para_lao": "value_lao"
        },
        "@children@wang": {
            "_anchor": "cwang",
            "para_wang_a": "value_wang_a",
        },
        "@children@li": {
            "para_li_a": "value_li_a",
            "para_li_b": "..."
        },
        "para_p_b": "..."
    },
    "para_a": "value_a"
}
```

我们想要在计算`para_p_b`时引用其他位置的值:

朴素的方式:

* 如果我们想要引用`para_p_a`的值,`para_p_a`与当前位置处于同级,我们用`$`来表示同级,那`para_p_a`的值在`para_p_b`位置的引用应该写为`$.para_p_a`
* 如果我们想要引用`para_a`的值,`para_a`处于当前位置的上一级,我们用`$$`来表示上一个级别(相信聪明的你已经发现每多一个`$`则表示往上多回溯一个级别),那`para_a`的值在`para_p_b`位置的引用应该写为`$$.para_a`
* 如果我们想要引用`para_li_a`的值,则我们可以发现`para_li_a`位于当前位置同级的`@children@li`的下一级,所以`para_li_a`的值在`para_p_b`位置的引用应该写为`$.@children@li.para_li_a`

简化表达:

由于作为模块名的如`@children@li`的表达往往很长,书写起来不方便,而往往我们仅需要这个模块名的前缀或后缀就能区分一个模块,因此上面的最后例子在`para_p_b`处引用`para_li_a`的值哈可以写为`$.@li.para_li_a`, 这里将`@children@li`简化成了`@li`而不带来歧义,需要注意的是这里的简化必须为原表达的前缀或后缀,且只能用于模块名(也就是说只能以`@`等特殊符号进行阶段),这么做是为了降低阅读难度,减少歧义的发生。

锚点:

而如果我们在`para_p_b`处想要引用`para_wang_a`的值,这里的路径同样要经过一个模块名`@children@wang`我们就不能使用上面的简化表达的技巧,这是因为无论我们选择前缀`@children`(`@children@li`的前缀)还是后缀`@wang`(`@wang@old`的前缀是`@wang`)都会产生歧义,那我们只能老老实实的写下全名了吗? 并非如此,intc为了让一些长距离的引用更加方便,还支持`全局锚点`来为远程依赖提供方便,在这个例子中,我们看到 `@children@wang`内部有一个`_anchor`关键词,我们可以在任意位置引用`_anchor`所在位置的值来引用它所在位置的同级元素,因此,在`para_p_b`处我们可以通过`cwang.value_wang_a`来引用`para_wang_a`的值。

需要注意的是`_anchor`可以有多个,但是不得出现同名`_anchor`每一个的值必须是全局唯一的, 因此不要在子模块中设置`_anchor`

值引用的语法:
intc的引用是通过`@lambda`表达式来实现的,引用规则为:
```
{
    "para1": "value1",
    "para2": "@lambda @$.para1"
}
```


`lambda`除了用于值引用以外,还可以用于非常复杂的情况,下面是intc支持的`lambda`语法类型及使用示例:

1. 通用语法

intc 的`lambda`最通用的语法是

```
@para_1, @para_2, ...@para_n  @lambda x1, x2, ...xn: use x1 to xn calc the value
|__________________________|  |________________________________________________|
             │                                     │
  这里是要传个lambda的参数         这里的lambda表达式遵循python的lambda语法规则
  与后面lambda表达式的参数         传入的参数就是前面对应的参数名
  一一对应<para_1 -> x1>..
  这里的每个para的表示遵循
  引用规则
```

```json
{
    "para1": 1,
    "para2": 2,
    "para3": "@$.para1, @$.para2 @lambda x, y: x+y"
}
```
这里的`para3`是一个需要`lambda`计算的值,计算结果为`para1`与`para2`的值和`3`

2. `lambda` 计算
有些时候我们单纯的只是想通过`lambda`来计算一个值,而不需要引用其他参数,那我们可以这么写:
```json
{
    "para1": "@lambda _: list(range(100))"
}
```

此时`para1`的值仍然是一个`lambda`表达式,但是这个表达式的输入参数是空的,这个表达式的值为`[0, 1, 2..., 98, 99]`

3. 通过lambda进行值引用

语法已在参数引用部分进行介绍


#### 参数搜索

在做实验时,我们需要验证多种参数的组合,`intc`为我们提供了参数grid search的能力,针对每个搜索条件以笛卡尔积的形式进行组合,返回一个config list

```jsonc
// data.json
{
    "para1": 1,
    "para2": 100,
    "@children":{
        "cpara1": 1000,
        "cpara2": "a",
        "_search": {
            "cpara1": "@lambda _: list(range(1000, 1003))"
        }
    },
    "_search": {
        "para1": [1, 2, 3],
        "para2": "@lambda _: [100, 200, 300]",
        "@children.cpara2": ['a', 'b', 'c']
    }
}

```

```python
import json
from intc import Parser
assert len(Parser(json.load(open('data.json')).parser())) == 81
```

如示例中所示,`intc`的参数搜索的值可以是一个`list`也可以是一个`lambda`表达式返回一个`list`,但是目前在`_search`中使用的`lambda`表达式目前只支持值计算,不可以引用其他的参数参与计算,有这个限制的原因是`_search`本身有可能改变config的结构,而引用必须在config结构固定时才可以。所以实际引用的计算是在`_search`生成固定的config之后发生

#### DataClass && Json Schema

`intc`除了可以作为config管理工具使用之外,也可以当做`dataclass`来使用,特别是`intc`除了支持一般的`json`数据的导入导出之外,还可以根据定义导出`json schema`,这对于一些特定的场景如约定大模型的输入输出格式时非常有用


```python
import json

from intc import MISSING, Base, IntField, NestField, StrField, dataclass


@dataclass
class LLMOutput(Base):
    """The output of the LLM model"""

    user_name = StrField(value=MISSING, help="Name of the person")

    class Info:
        age = IntField(value=MISSING, minimum=1, maximum=150, help="Age of the person")
        blood_type = StrField(
            value=MISSING, options=["A", "B", "AB", "O"], help="Blood type"
        )

    user_info = NestField(value=Info, help="User information")
    lines = IntField(value=MISSING, help="Number of lines in the output")
print(json.dumps(LLMOutput._json_schema(), indent=4))
```

Json Schema Output:
```json
{
    "properties": {
        "user_name": {
            "description": "Name of the person",
            "type": "string",
            "deprecated": false
        },
        "user_info": {
            "description": "User information",
            "type": "object",
            "properties": {
                "age": {
                    "description": "Age of the person",
                    "type": "integer",
                    "deprecated": false,
                    "minimum": 1,
                    "maximum": 150
                },
                "blood_type": {
                    "description": "Blood type",
                    "type": "string",
                    "enum": [
                        "A",
                        "B",
                        "AB",
                        "O"
                    ],
                    "deprecated": false
                }
            }
        }
    },
    "type": "object",
    "description": "The output of the LLM model",
    "$schema": "https://json-schema.org/draft/2020-12/schema"
}
```
### Intc-LSP
#### Hover Document

<div style="text-align:center">
<span style="width:47%;display:inline-block">

![nvim hover](./pics/nvim_hover.png)

</span>
<span style="width:47%;display:inline-block">

![vsc hover](./pics/vsc_hover.png)

</span>
</div>

#### Diagnostic

<div style="text-align:center">
<span style="width:47%;display:inline-block">

![nvim diag](./pics/nvim_diag.png)

</span>
<span style="width:47%;display:inline-block">

![vsc diag](./pics/vsc_diag.png)

</span>
</div>

#### Completion

<div style="text-align:center">
<span style="width:47%;display:inline-block">

![nvim comp](./pics/nvim_comp.png)

</span>
<span style="width:47%;display:inline-block">

![vsc comp](./pics/vsc_comp.png)

</span>
</div>

#### Goto/Peek Definition

<div style="text-align:center">
<span style="width:47%;display:inline-block">

![nvim goto](./pics/nvim_goto.png)

</span>
<span style="width:47%;display:inline-block">

![vsc goto](./pics/vsc_goto.png)

</span>
</div>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cstsunfu/intc",
    "name": "intc-lsp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "intc, lsp, intc-lsp",
    "author": null,
    "author_email": "cstsunfu <cstsunfu@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/b3/db/31148fd3bbf865942a5397a75c3b957aaeb564a096d8a23c4e1ef94f8489/intc_lsp-0.1.0b0.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <h2 align=\"center\"> Python Intelligence Config Manager</h2>\n</p>\n\n<p align=\"center\">\nA Python Config Manager for Humans\n</p>\n\n\n<div style=\"text-align:center\">\n<span style=\"width:70%;display:inline-block\">\n\n![main](./pics/vsc_main.png)\n\n</div>\n\n<h4 align=\"center\">\n    <p>\n        <b>\u7b80\u4f53\u4e2d\u6587</b> |\n        <a href=\"https://github.com/cstsunfu/dlk/blob/main/README_en.md\">English</a>\n    </p>\n</h4>\n\n* [\u5b89\u88c5](#\u5b89\u88c5)\n* [Feature List](#feature-list)\n* [Intc Use Case](#intc-use-case)\n    * [\u53c2\u6570\u5f15\u7528\u53calambda\u8bed\u6cd5](#\u53c2\u6570\u5f15\u7528\u53calambda\u8bed\u6cd5)\n    * [\u53c2\u6570\u641c\u7d22](#\u53c2\u6570\u641c\u7d22)\n    * [DataClass && Json Schema](#dataclass-json-schema)\n* [Intc-LSP](#intc-lsp)\n    * [Hover Document](#hover-document)\n    * [Diagnostic](#diagnostic)\n    * [Completion](#completion)\n    * [Goto/Peek Definition](#gotopeek-definition)\n\n\n`intc`\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u667a\u80fdconfig\u914d\u7f6e\u7ba1\u7406\u5de5\u5177\uff0c\u5b83\u4e0d\u4ec5\u4e3a\u6211\u4eec\u7684\u914d\u7f6e\u6587\u4ef6\u63d0\u4f9b\u6a21\u5757\u7ee7\u627f\u3001\u6a21\u5757\u5d4c\u5957\u3001\u53c2\u6570\u5f15\u7528\u3001\u8d85\u53c2\u641c\u7d22\uff0c\u8fd8\u652f\u6301\u57fa\u4e8e`lambda`\u8868\u8fbe\u5f0f\u7684\u590d\u6742\u53c2\u6570\u52a8\u6001\u8ba1\u7b97\u7b49\u529f\u80fd\u3002\n\n\u800c`intc`\u7684\u914d\u5957Language Server Protocol\uff08`intc-lsp`\uff09\u5219\u8ba9\u6211\u4eec\u7684\u7f16\u8f91\u6d4f\u89c8\u4f53\u9a8c\u66f4\u52a0\u4e1d\u6ed1\uff0c\u5b83\u5c06\u914d\u7f6e\u6587\u4ef6\u4e0e`python`\u4ee3\u7801\u7d27\u5bc6\u8054\u5408\uff0c`intc-lsp`\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u4e66\u5199\u548c\u9605\u8bfb`intc`\u6587\u4ef6\u65f6\u65b9\u4fbf\u7684\u83b7\u53d6`python`\u7684\u8bed\u4e49\u4fe1\u606f\uff0c\u63d0\u4f9b\u9519\u8bef\u63d0\u793a\u3001\u53c2\u6570\u8865\u5168\u3001\u667a\u80fd\u8df3\u8f6c\u548c\u53c2\u6570\u5e2e\u52a9\u6587\u6863\u5c55\u793a\u7684\u529f\u80fd\u3002\n\n\u9664\u4e86\u7528\u4e8e`config`\uff0c`intc`\u8fd8\u53ef\u4ee5\u76f4\u63a5\u4f5c\u4e3a`dataclass`\u4f7f\u7528\uff0c\u5b83\u53ef\u4ee5\u5c06\u6211\u4eec\u4f7f\u7528`intc`\u5b9a\u4e49\u7684`dataclass`\u8f6c\u5316\u4e3a`json schema`\u7528\u4e8e\u5982`LLM`\u7684\u6570\u636e\u7c7b\u578b\u7ea6\u675f\uff0c\u8fd8\u53ef\u4ee5\u5bf9\u5982`LLM`\u8fd4\u56de\u503c\u5728\u5185\u7684`json`\u6570\u636e\u8fdb\u884c\u6570\u636e\u68c0\u67e5\u5e76\u751f\u6210\u9519\u8bef\u63d0\u793a\u7528\u4e8e`LLM`\u7684\u8fed\u4ee3\u4f18\u5316\u3002\n\n### \u5b89\u88c5\n\n1. \u51c6\u5907`python`\u73af\u5883\uff0c\u8981\u6c42`python>=3.8`\uff0c\u4e14\u76ee\u524d\u53ea\u5728`Linux`\u548c`Mac`\u4e0a\u9762\u8fdb\u884c\u4e86\u6d4b\u8bd5\uff0c`Windows`\u7684\u652f\u6301\u53ef\u80fd\u5b58\u5728\u95ee\u9898\n2. \u5b89\u88c5`intc`\u548c`intc-lsp`\uff0c\u5982\u679c\u4e0d\u9700\u8981\u4f7f\u7528\u667a\u80fd\u8865\u5168\u7b49\u529f\u80fd\u53ef\u4ee5\u53ea\u5b89\u88c5`intc`\n\n```bash\n# install from pypi\npip install intc\npip install intc-lsp\n```\n\n\u6216\u76f4\u63a5\u6e90\u7801\u5b89\u88c5\n```bash\ncd intc/\npip install .\ncd ../lsp\npip install .\n```\n\n3. \u5b89\u88c5\u667a\u80fd\u8865\u5168\u63d2\u4ef6(Plugins)\n\n`intc`\u63d0\u4f9b\u4e86\u4e00\u4e2a\u901a\u7528\u7684Language Server Protocol\uff08`LSP`\uff09\uff0c\u7406\u8bba\u4e0a\u53ea\u8981\u4f60\u4f7f\u7528\u7684\u7f16\u8f91\u5668\u6216`IDE`\u652f\u6301`LSP`\u5c31\u53ef\u4ee5\u4f7f\u7528\uff0c\u4f46\u662f\u6211\u5e73\u65f6\u4e3b\u8981\u4f7f\u7528`(neo)vim`\uff0c\u5076\u5c14\u7528\u4e00\u4e0b`vscode`\uff0c\u56e0\u6b64\u76ee\u524d\u53ea\u5728\u8fd9\u4e24\u79cd\u7f16\u8f91\u5668\u4e0a\u505a\u4e86\u9002\u914d\n\n* neovim\n\n`neovim`\u529f\u80fd\u5f3a\u5927\u4e14\u6613\u4e8e\u6269\u5c55\uff0c\u793e\u533a\u5df2\u7ecf\u5bf9`LSP`\u63d0\u4f9b\u4e86\u975e\u5e38\u53cb\u597d\u7684\u652f\u6301\uff0c\u5177\u4f53\u53c2\u8003`plugins/neovim`\n\n* vscode\n  `vscode`\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5`intc-lsp`\u5bf9\u5e94\u7684\u63d2\u4ef6\u6765\u83b7\u53d6`lsp`\u7684\u652f\u6301\uff0c\u5177\u4f53\u53c2\u8003 `plugins/vscode`\n\n* \u5176\u4ed6IDE\u4e0e\u7f16\u8f91\u5668\n\n  \u9700\u8981\u6709\u76f8\u5173\u7ecf\u9a8c\u7684\u540c\u5b66\u5e2e\u5fd9\u5b8c\u5584\u6587\u6863\n\n### Feature List\n\n\u4e0b\u9762\u662f\u4e00\u4e9b\u4e3b\u8981\u529f\u80fd\u7684\u7b80\u5355\u4ecb\u7ecd\uff0c\u5177\u4f53\u7528\u6cd5\u53ef\u4ee5\u8df3\u8f6c\u5230\u5bf9\u5e94\u7684use case\u8fdb\u884c\u67e5\u770b\n\n* \u6a21\u5757\u7ee7\u627f\n    * intc\u7684python\u7c7b\u4e4b\u95f4\u53ef\u4ee5\u548c\u6b63\u5e38\u7684python\u7c7b\u4e00\u6837\u8fdb\u884c\u7ee7\u627f\n    * intc\u7684config\u6587\u4ef6\u5219\u662fpython\u7c7b\u7684\u5b9e\u4f8b\u5316\u53c2\u6570\uff0c\u540c\u6837\u53ef\u4ee5\u770b\u505a\u662f\u7ee7\u627f\u81eaPython\u7c7b\n    * \u9664\u6b64\u4e4b\u5916\u5728\u4e00\u4e9b\u590d\u6742\u7684config\u6587\u4ef6\u4e2dconfig\u4e4b\u95f4\u4e5f\u53ef\u4ee5\u5b58\u5728\u7ee7\u627f\u5173\u7cfb.\n* \u6a21\u5757\u5d4c\u5957\uff0c\u6a21\u5757\u4e4b\u95f4\u53ef\u4ee5\u8fdb\u884c\u5d4c\u5957\uff0c\u4e00\u4e2a\u66f4\u9ad8\u7ea7\u522b\u7684\u6a21\u5757\u9664\u4e86\u81ea\u5df1\u7684\u53c2\u6570\u4e4b\u5916\u8fd8\u53ef\u4ee5\u5305\u542b\u5176\u4ed6\u5b50\u6a21\u5757\uff0c\u5982\u5728\u8bad\u7ec3\u795e\u7ecf\u7f51\u7edc\u7684\u4efb\u52a1\u4e2d\u4e00\u4e2atrainer\u9664\u4e86\u81ea\u5df1\u7684\u4e00\u4e9b\u53c2\u6570\u4e4b\u5916\u8fd8\u53ef\u4ee5\u5305\u542bmodel\u3001optimizer\u548cschedule\u7b49\u5b50\u6a21\u5757\n* \u53c2\u6570\u5f15\u7528\uff0c\u4e00\u4e2a\u53c2\u6570\u53ef\u4ee5\u4f9d\u8d56\u4e00\u4e2a\u6216\u591a\u4e2a\u5176\u4ed6\u53c2\u6570\u7684\u503c\uff0c\u652f\u6301lambda\u52a8\u6001\u8ba1\u7b97\u53c2\u6570\u7684\u503c\n* \u53c2\u6570\u641c\u7d22\uff0c\u5728\u5f88\u591a\u4efb\u52a1\u4e2d\u6211\u4eec\u6709\u591a\u79cd\u53c2\u6570\u7ec4\u5408\uff0cintc\u4ee5\u7b1b\u5361\u5c14\u79ef\u7684\u5f62\u5f0f\u5c55\u5f00\u6240\u6709\u7684\u53c2\u6570\u7ec4\u5408\n* dataclass\uff0c\u4f5c\u4e3adataclass\u53ef\u4ee5\u76f4\u63a5\u4f5c\u4e3a\u67d0\u4e2a\u6a21\u5757\u7684\u53c2\u6570\u7c7b\u3001\u53ef\u4ee5\u751f\u6210json schema\u3001\u53ef\u4ee5\u5bf9\u53c2\u6570\u8fdb\u884c\u68c0\u67e5\n\n* config\u5e2e\u52a9\u6587\u6863\uff0cintc-lsp\u63d0\u4f9b\u53c2\u6570hover\u63d0\u793a\uff0c\u5f53\u6307\u9488\u653e\u5230\u53c2\u6570\u4e0a\u65f6\u5c55\u793a\u53c2\u6570\u7684\u5e2e\u52a9\u6587\u6863\n* config\u9519\u8bef\u63d0\u793a\uff0cintc-lsp\u68c0\u67e5\u4f60\u7684\u53c2\u6570\u586b\u5199\u662f\u5426\u6b63\u786e\n* config\u53c2\u6570\u8865\u5168\uff0cintc-lsp\u5728\u4f60\u7f16\u8f91config\u6587\u4ef6\u65f6\u8fdb\u884c\u8bed\u4e49\u8865\u5168\n* config\u53c2\u6570\u8df3\u8f6c\uff0cintc-lsp\u4e3a\u4f60\u5728\u6d4f\u89c8\u6216\u7f16\u8f91config\u6587\u4ef6\u65f6\u63d0\u4f9b`goto/peek definition` python\u6e90\u7801\u63d0\u4f9b\u652f\u6301\n\n* etc.\n\n### Intc Use Case\n\n\u6211\u4eec\u5c06\u4ee5`intc/examples/exp1`\u4e2d\u7684\u4f8b\u5b50\u5f00\u59cb\u6765\u4ecb\u7ecdintc\u7684\u57fa\u672c\u7528\u6cd5\n\n\u6837\u4f8b\u7ed3\u6784\uff1a\n\n```\n\u251c\u2500\u2500 config                         -- config\u6587\u4ef6\uff0c\u76ee\u524d\u652f\u6301json\u548cjsonc\u6587\u4ef6\uff0c\u9700\u8981\u5728.intc.json\u4e2d\u6307\u5b9aconfig\u6240\u5728\u76ee\u5f55\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 model.json\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 model_search.jsonc\n\u251c\u2500\u2500 .intc.json                     -- intc\u9700\u8981\u7684meta\u6570\u636e\n\u251c\u2500\u2500 run.py                         -- your own code\n\u2514\u2500\u2500 src                            -- your project\n    \u2514\u2500\u2500 __init__.py\n```\n\n\u548c\u4e00\u4e2a\u666e\u901a\u7684python\u9879\u76ee\u76f8\u6bd4\uff0cintc\u9879\u76ee\u9700\u8981\u4e00\u4e2a`.intc.json` \u6587\u4ef6\u6765\u63cf\u8ff0\u9879\u76ee\u7684\u4e00\u4e9b`meta`\u6570\u636e, \u4e0b\u9762\u662f\u8fd9\u4e2aexp\u4e2d\u7684\u914d\u7f6e:\n\n```.intc.json\n{\n    // \"module\": [\"config/module\"],  // submodule\u6240\u5728\u76ee\u5f55, \u76f8\u5bf9\u4e8e\u5f53\u524d\u76ee\u5f55, \u8fd9\u4e2aexp\u4e2d\u6ca1\u6709submodule\n    \"entry\": [\"config\"],                 // config\u6240\u5728\u76ee\u5f55, \u76f8\u5bf9\u4e8e\u5f53\u524d\u76ee\u5f55\n    \"src\": [                           // config\u6587\u4ef6\u4e2d\u7528\u5230\u7684python\u6a21\u5757\uff0c\u9700\u8981\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7python import\n        \"src\"\n    ]\n}\n\n```\n\n\u800c\u4f7f\u7528intc\u7684python\u4ee3\u7801\u5219\u4e0edataclass\u975e\u5e38\u76f8\u4f3c\uff0c\u76f8\u6bd4\u4e8epython\u81ea\u5e26\u7684dataclass\u63d0\u4f9b\u4e86\u5982\u6570\u503c\u68c0\u67e5\u3001\u6a21\u578b\u6ce8\u518c\u3001\u751f\u6210json schema\u7b49\u529f\u80fd\n\n```python\nfrom intc import (\n    MISSING,            # MISSING\u662f\u4e00\u4e2a\u5e38\u91cf(\u5728intc\u4e2d\u7684\u503c\u4e3a`???`)\u8868\u793a\u53c2\u6570\u7f3a\u5931\uff0c\u9700\u8981\u5728\u5b9e\u4f8b\u5316config\u65f6\u63d0\u4f9b\n    Base,               # \u6240\u6709\u7684intc dataclass \u90fd\u7ee7\u627f\u8be5\u7c7b\uff08\u53ef\u4ee5\u9690\u5f0f\u7ee7\u627f\uff09\n    BoolField,          # \u8fd9\u4e9bbool field\n    DictField,          # dict field\n    FloatField,         # ...\n    IntField,\n    AnyField,\n    ListField,\n    NestField,          # \u5d4c\u5957field\uff0c\u76f8\u6bd4dict\u53ef\u4ee5\u63d0\u4f9b\u66f4\u591a\u7684\u7c7b\u578b\u68c0\u67e5\u3001\u667a\u80fd\u8865\u5168\u7b49\u529f\u80fd\n    StrField,\n    SubModule,\n    cregister,          # cregister\u6ce8\u518cintc\u5b9e\u4f8b(\u652f\u6301\u4e8c\u7ea7\u547d\u540d, <module_type, module_name> )\uff0c\u7528\u4e8e\u5b9e\u4f8b\u7684\u7d22\u5f15\uff08\u901a\u8fc7<module_type, module_name>\u76f4\u63a5\u83b7\u53d6\u5bf9\u5e94\u7684model\u7c7b\uff0cconfig\u4e2d\u4e5f\u4f1a\u4f7f\u7528\u6ce8\u518c\u540d\u6765\u5b9a\u4f4d\u5bf9\u5e94\u7684model\u7c7b\n)\n\n\n@cregister(\"model\", \"simple_cls\")  # cregister\u5c06Model\u6ce8\u518c\u4e3aintc\u7c7b\uff0c`module_type`\u4e3a`model`, `module_name`\u4e3a`simple_cls`\nclass Model(Base):                 # \u663e\u5f0f\u7ee7\u627f\u81eaBase\uff0c\u8fd9\u91cc\u4e5f\u53ef\u4ee5\u4e0d\u663e\u5f0f\u7ee7\u627f\uff0cregister\u8fc7\u7a0b\u4f1a\u81ea\u52a8\u6267\u884c\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u663e\u5f0f\u7684\u7ee7\u627f\u53ef\u4ee5\u63d0\u4f9b\u66f4\u597d\u7684\u8bed\u4e49\u8865\u5168\n    embedding_combine_method = StrField( # dataclass\u7684\u5c5e\u6027\u5b9a\u4e49\n        value=\"concat\",                  # \u9ed8\u8ba4\u503c\n        options=[\"concat\", \"concat_linear\"], # options \u8868\u793a\u503c\u5fc5\u987b\u662f\u8fd9\u51e0\u4e2a\u91cc\u9762\u7684\u4e00\u4e2a\n        help=\"the combine method, just `concat` or use `linear` on the concated embedding\",\n    )\n    embedding_size = IntField(\n        value=MISSING, help=\"the sum of bert and glove embedding size\" # \u8fd9\u91cc\u7684default value\u4e3aMISSING\uff0c\u9700\u8981\u5728\u5b9e\u4f8b\u5316\u65f6\u63d0\u4f9b\n    )\n    active = StrField(\n        value=\"relu\",\n        options=[\"relu\", \"tanh\", \"sigmoid\", \"none\"],\n        help=\"the activation function\",\n    )\n    submodule = SubModule(   # \u5b50\u6a21\u578b\uff0c\u53ef\u4ee5\u5d4c\u5957\u5176\u4ed6\u6a21\u578b\u7684\u5b9a\u4e49\uff0c\u8fd9\u91cc\u7684\u5b50\u6a21\u578b\u53ef\u4ee5\u6709\u591a\u4e2a\uff0c\u5f15\u7528\u5b50\u6a21\u578b\u9700\u8981\u7528\u5230\u8fd9\u4e9b\u5b50\u6a21\u578b\u7684\u6ce8\u518c\u540d\n        value={},\n        suggestions=[        # suggestions \u8868\u793a\u63a8\u8350\u7684\u4e00\u4e9b\u503c, \u5bf9\u4e8e\u4ee3\u7801\u9605\u8bfb\u548cintc-lsp\u7684\u8bed\u4e49\u89e3\u6790\u6709\u5e2e\u52a9\n            \"embedding\",\n            \"decode\",\n        ],\n        help=\"submodules for basic model\",\n    )\n\n@cregister(\"embedding\", \"bert\")\nclass BertEmbedding:\n    hidden_size = IntField(\n        value=MISSING,\n        minimum=1,\n        help=\"the input/output/hidden size for bert, must >= 1\",\n    )\n    dropout_rate = FloatField(\n        value=0.0, minimum=0.0, maximum=1.0, help=\"the dropout rate for bert\"  #\n    )\n....\n```\n\u5b9e\u9645\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u5f80\u5f80\u4f7f\u7528config\u6587\u4ef6\u5bf9\u4e1a\u52a1\u903b\u8f91\u8fdb\u884c\u914d\u7f6e\uff0c\u800cjson(\u53ca\u5176\u884d\u751f\u683c\u5f0f\uff0c\u5982jsonc)\u975e\u5e38\u9002\u5408\u7528\u6765\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\uff0c`intc`\u914d\u5408`intc-lsp`\u5bf9\u6b64\u63d0\u4f9b\u4e86\u975e\u5e38\u597d\u7684\u652f\u6301, \u4e0b\u9762\u662f\u9488\u5bf9\u5df2\u6709\u7684dataclass\u8fdb\u884c\u914d\u7f6e\u7684\u4f8b\u5b50:\n\n```jsonc\n// \u6587\u4ef6 config/model.jsonc\n{\n    \"@model@simple_cls\": {  // \u8868\u660e\u662f\u5bf9\u8c01\u8fdb\u884c\u914d\u7f6e\uff0c\u683c\u5f0f\u4e3a@module_type@module_name @model@simple_cls \u5bf9\u5e94\u88ab\u6ce8\u518c\u4e3a\u8fd9\u4e2a\u540d\u79f0\u7684`Model`\n        \"active\": \"none\",\n        \"embedding_size\": \"@$.@glove.hidden_size, @$.@bert.hidden_size @lambda x, y: x+y\", // \u8fd9\u91cc\u7684\u503c\u4e3a\u52a8\u6001\u7684lambda\u8ba1\u7b97\u7684\uff0c\u558a\u4e00\u58f0 embedding_size\u7684\u503c\u4e3a@embedding@glove.hidden_size\u548c@embedding@bert.hidden_size \u7684\u548c\uff0c \u5173\u4e8elambda\u7684\u8bed\u6cd5\u8bf7\u770b\u672c\u8bf4\u660e\u91cc\u9762\u5173\u4e8elambda\u7684\u4ecb\u7ecd\n        \"@embedding@glove\": { // submodule, submodule \u540c\u6837\u4ee5@module_type@module_name\u4f5c\u4e3a\u6807\u8bc6\n            \"hidden_size\": 300,\n            \"vocab_size\": 5000\n        },\n        \"@embedding@bert\": {\n            \"hidden_size\": 768\n        }\n    }\n}\n```\n```python\n# \u6587\u4ef6 main.py\nimport exp\n\n```\n#### \u53c2\u6570\u5f15\u7528\u53calambda\u8bed\u6cd5\n\n\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u5982\u4e00\u4e2aencode\u6a21\u5757\u7684\u8f93\u51fa\u548cdecode\u6a21\u5757\u7684\u8f93\u5165\u7684\u7ef4\u5ea6\u76f8\u540c\uff0c\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6211\u4eec\u5e0c\u671b\u8fd9\u4e24\u4e2a\u53c2\u6570\u7684\u503c\u59cb\u7ec8\u4fdd\u6301\u4e00\u81f4\uff0cintc\u652f\u6301\u4e00\u4e2a\u53c2\u6570\u662f\u53e6\u4e00\u4e2a\u53c2\u6570\u7684\u5f15\u7528\uff0c\u8fd9\u6837\u6211\u4eec\u53ea\u9700\u8981\u4fee\u6539\u5176\u4e2d\u7684\u4e00\u4e2a\u53c2\u6570\u53e6\u4e00\u4e2a\u53c2\u6570\u7684\u503c\u4e5f\u540c\u6b65\u88ab\u4fee\u6539\u4e86\u3002\n\n\n\n\u6709\u65f6\u6211\u4eec\u7684\u4e00\u4e2a\u53c2\u6570\u7684\u503c\u4f9d\u8d56\u4e8e\u591a\u4e2a\u5176\u4ed6\u53c2\u6570\uff0c\u5982\u5728\u4e00\u4e2a\u591aencode\u7684\u6a21\u578b\u4e2d\uff0cdecode\u6a21\u5757\u7684\u8f93\u5165\u7ef4\u5ea6\u662f\u6240\u6709encode\u6a21\u578b\u8f93\u51fa\u7684\u7ef4\u5ea6\u7684\u548c\uff0c\u9488\u5bf9\u8fd9\u79cd\u590d\u6742\u7684\u5f15\u7528\uff0cintc\u63d0\u4f9b`lambda`\u652f\u6301\u590d\u6742\u7684\u52a8\u6001\u503c\u8ba1\u7b97.\n\n\u5728\u4ecb\u7ecd`lambda`\u8868\u8fbe\u5f0f\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u5bf9\u53c2\u6570\u7684\u5f15\u7528\u89c4\u5219\u8fdb\u884c\u4ecb\u7ecd\uff1a\n\n\u6211\u4eec\u4ee5\u4e0b\u9762\u7684config\u4e3a\u4f8b\uff1a\n```json\n{\n    \"@parent@p\": {\n        \"para_p_a\": \"value_p_a\"\n        \"@wang@lao\": {\n            \"para_lao\": \"value_lao\"\n        },\n        \"@children@wang\": {\n            \"_anchor\": \"cwang\",\n            \"para_wang_a\": \"value_wang_a\",\n        },\n        \"@children@li\": {\n            \"para_li_a\": \"value_li_a\",\n            \"para_li_b\": \"...\"\n        },\n        \"para_p_b\": \"...\"\n    },\n    \"para_a\": \"value_a\"\n}\n```\n\n\u6211\u4eec\u60f3\u8981\u5728\u8ba1\u7b97`para_p_b`\u65f6\u5f15\u7528\u5176\u4ed6\u4f4d\u7f6e\u7684\u503c:\n\n\u6734\u7d20\u7684\u65b9\u5f0f\uff1a\n\n* \u5982\u679c\u6211\u4eec\u60f3\u8981\u5f15\u7528`para_p_a`\u7684\u503c\uff0c`para_p_a`\u4e0e\u5f53\u524d\u4f4d\u7f6e\u5904\u4e8e\u540c\u7ea7\uff0c\u6211\u4eec\u7528`$`\u6765\u8868\u793a\u540c\u7ea7\uff0c\u90a3`para_p_a`\u7684\u503c\u5728`para_p_b`\u4f4d\u7f6e\u7684\u5f15\u7528\u5e94\u8be5\u5199\u4e3a`$.para_p_a`\n* \u5982\u679c\u6211\u4eec\u60f3\u8981\u5f15\u7528`para_a`\u7684\u503c\uff0c`para_a`\u5904\u4e8e\u5f53\u524d\u4f4d\u7f6e\u7684\u4e0a\u4e00\u7ea7\uff0c\u6211\u4eec\u7528`$$`\u6765\u8868\u793a\u4e0a\u4e00\u4e2a\u7ea7\u522b\uff08\u76f8\u4fe1\u806a\u660e\u7684\u4f60\u5df2\u7ecf\u53d1\u73b0\u6bcf\u591a\u4e00\u4e2a`$`\u5219\u8868\u793a\u5f80\u4e0a\u591a\u56de\u6eaf\u4e00\u4e2a\u7ea7\u522b)\uff0c\u90a3`para_a`\u7684\u503c\u5728`para_p_b`\u4f4d\u7f6e\u7684\u5f15\u7528\u5e94\u8be5\u5199\u4e3a`$$.para_a`\n* \u5982\u679c\u6211\u4eec\u60f3\u8981\u5f15\u7528`para_li_a`\u7684\u503c\uff0c\u5219\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0`para_li_a`\u4f4d\u4e8e\u5f53\u524d\u4f4d\u7f6e\u540c\u7ea7\u7684`@children@li`\u7684\u4e0b\u4e00\u7ea7\uff0c\u6240\u4ee5`para_li_a`\u7684\u503c\u5728`para_p_b`\u4f4d\u7f6e\u7684\u5f15\u7528\u5e94\u8be5\u5199\u4e3a`$.@children@li.para_li_a`\n\n\u7b80\u5316\u8868\u8fbe\uff1a\n\n\u7531\u4e8e\u4f5c\u4e3a\u6a21\u5757\u540d\u7684\u5982`@children@li`\u7684\u8868\u8fbe\u5f80\u5f80\u5f88\u957f\uff0c\u4e66\u5199\u8d77\u6765\u4e0d\u65b9\u4fbf\uff0c\u800c\u5f80\u5f80\u6211\u4eec\u4ec5\u9700\u8981\u8fd9\u4e2a\u6a21\u5757\u540d\u7684\u524d\u7f00\u6216\u540e\u7f00\u5c31\u80fd\u533a\u5206\u4e00\u4e2a\u6a21\u5757\uff0c\u56e0\u6b64\u4e0a\u9762\u7684\u6700\u540e\u4f8b\u5b50\u5728`para_p_b`\u5904\u5f15\u7528`para_li_a`\u7684\u503c\u54c8\u53ef\u4ee5\u5199\u4e3a`$.@li.para_li_a`, \u8fd9\u91cc\u5c06`@children@li`\u7b80\u5316\u6210\u4e86`@li`\u800c\u4e0d\u5e26\u6765\u6b67\u4e49\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\u8fd9\u91cc\u7684\u7b80\u5316\u5fc5\u987b\u4e3a\u539f\u8868\u8fbe\u7684\u524d\u7f00\u6216\u540e\u7f00\uff0c\u4e14\u53ea\u80fd\u7528\u4e8e\u6a21\u5757\u540d\uff08\u4e5f\u5c31\u662f\u8bf4\u53ea\u80fd\u4ee5`@`\u7b49\u7279\u6b8a\u7b26\u53f7\u8fdb\u884c\u9636\u6bb5\uff09\uff0c\u8fd9\u4e48\u505a\u662f\u4e3a\u4e86\u964d\u4f4e\u9605\u8bfb\u96be\u5ea6\uff0c\u51cf\u5c11\u6b67\u4e49\u7684\u53d1\u751f\u3002\n\n\u951a\u70b9\uff1a\n\n\u800c\u5982\u679c\u6211\u4eec\u5728`para_p_b`\u5904\u60f3\u8981\u5f15\u7528`para_wang_a`\u7684\u503c\uff0c\u8fd9\u91cc\u7684\u8def\u5f84\u540c\u6837\u8981\u7ecf\u8fc7\u4e00\u4e2a\u6a21\u5757\u540d`@children@wang`\u6211\u4eec\u5c31\u4e0d\u80fd\u4f7f\u7528\u4e0a\u9762\u7684\u7b80\u5316\u8868\u8fbe\u7684\u6280\u5de7\uff0c\u8fd9\u662f\u56e0\u4e3a\u65e0\u8bba\u6211\u4eec\u9009\u62e9\u524d\u7f00`@children`(`@children@li`\u7684\u524d\u7f00)\u8fd8\u662f\u540e\u7f00`@wang`(`@wang@old`\u7684\u524d\u7f00\u662f`@wang`)\u90fd\u4f1a\u4ea7\u751f\u6b67\u4e49\uff0c\u90a3\u6211\u4eec\u53ea\u80fd\u8001\u8001\u5b9e\u5b9e\u7684\u5199\u4e0b\u5168\u540d\u4e86\u5417? \u5e76\u975e\u5982\u6b64\uff0cintc\u4e3a\u4e86\u8ba9\u4e00\u4e9b\u957f\u8ddd\u79bb\u7684\u5f15\u7528\u66f4\u52a0\u65b9\u4fbf\uff0c\u8fd8\u652f\u6301`\u5168\u5c40\u951a\u70b9`\u6765\u4e3a\u8fdc\u7a0b\u4f9d\u8d56\u63d0\u4f9b\u65b9\u4fbf\uff0c\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u770b\u5230 `@children@wang`\u5185\u90e8\u6709\u4e00\u4e2a`_anchor`\u5173\u952e\u8bcd\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u4efb\u610f\u4f4d\u7f6e\u5f15\u7528`_anchor`\u6240\u5728\u4f4d\u7f6e\u7684\u503c\u6765\u5f15\u7528\u5b83\u6240\u5728\u4f4d\u7f6e\u7684\u540c\u7ea7\u5143\u7d20\uff0c\u56e0\u6b64\uff0c\u5728`para_p_b`\u5904\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7`cwang.value_wang_a`\u6765\u5f15\u7528`para_wang_a`\u7684\u503c\u3002\n\n\u9700\u8981\u6ce8\u610f\u7684\u662f`_anchor`\u53ef\u4ee5\u6709\u591a\u4e2a\uff0c\u4f46\u662f\u4e0d\u5f97\u51fa\u73b0\u540c\u540d`_anchor`\u6bcf\u4e00\u4e2a\u7684\u503c\u5fc5\u987b\u662f\u5168\u5c40\u552f\u4e00\u7684, \u56e0\u6b64\u4e0d\u8981\u5728\u5b50\u6a21\u5757\u4e2d\u8bbe\u7f6e`_anchor`\n\n\u503c\u5f15\u7528\u7684\u8bed\u6cd5\uff1a\nintc\u7684\u5f15\u7528\u662f\u901a\u8fc7`@lambda`\u8868\u8fbe\u5f0f\u6765\u5b9e\u73b0\u7684\uff0c\u5f15\u7528\u89c4\u5219\u4e3a\uff1a\n```\n{\n    \"para1\": \"value1\",\n    \"para2\": \"@lambda @$.para1\"\n}\n```\n\n\n`lambda`\u9664\u4e86\u7528\u4e8e\u503c\u5f15\u7528\u4ee5\u5916\uff0c\u8fd8\u53ef\u4ee5\u7528\u4e8e\u975e\u5e38\u590d\u6742\u7684\u60c5\u51b5\uff0c\u4e0b\u9762\u662fintc\u652f\u6301\u7684`lambda`\u8bed\u6cd5\u7c7b\u578b\u53ca\u4f7f\u7528\u793a\u4f8b:\n\n1. \u901a\u7528\u8bed\u6cd5\n\nintc \u7684`lambda`\u6700\u901a\u7528\u7684\u8bed\u6cd5\u662f\n\n```\n@para_1, @para_2, ...@para_n  @lambda x1, x2, ...xn: use x1 to xn calc the value\n|__________________________|  |________________________________________________|\n             \u2502                                     \u2502\n  \u8fd9\u91cc\u662f\u8981\u4f20\u4e2alambda\u7684\u53c2\u6570         \u8fd9\u91cc\u7684lambda\u8868\u8fbe\u5f0f\u9075\u5faapython\u7684lambda\u8bed\u6cd5\u89c4\u5219\n  \u4e0e\u540e\u9762lambda\u8868\u8fbe\u5f0f\u7684\u53c2\u6570         \u4f20\u5165\u7684\u53c2\u6570\u5c31\u662f\u524d\u9762\u5bf9\u5e94\u7684\u53c2\u6570\u540d\n  \u4e00\u4e00\u5bf9\u5e94<para_1 -> x1>..\n  \u8fd9\u91cc\u7684\u6bcf\u4e2apara\u7684\u8868\u793a\u9075\u5faa\n  \u5f15\u7528\u89c4\u5219\n```\n\n```json\n{\n    \"para1\": 1,\n    \"para2\": 2,\n    \"para3\": \"@$.para1, @$.para2 @lambda x, y: x+y\"\n}\n```\n\u8fd9\u91cc\u7684`para3`\u662f\u4e00\u4e2a\u9700\u8981`lambda`\u8ba1\u7b97\u7684\u503c\uff0c\u8ba1\u7b97\u7ed3\u679c\u4e3a`para1`\u4e0e`para2`\u7684\u503c\u548c`3`\n\n2. `lambda` \u8ba1\u7b97\n\u6709\u4e9b\u65f6\u5019\u6211\u4eec\u5355\u7eaf\u7684\u53ea\u662f\u60f3\u901a\u8fc7`lambda`\u6765\u8ba1\u7b97\u4e00\u4e2a\u503c\uff0c\u800c\u4e0d\u9700\u8981\u5f15\u7528\u5176\u4ed6\u53c2\u6570\uff0c\u90a3\u6211\u4eec\u53ef\u4ee5\u8fd9\u4e48\u5199\uff1a\n```json\n{\n    \"para1\": \"@lambda _: list(range(100))\"\n}\n```\n\n\u6b64\u65f6`para1`\u7684\u503c\u4ecd\u7136\u662f\u4e00\u4e2a`lambda`\u8868\u8fbe\u5f0f\uff0c\u4f46\u662f\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u7684\u8f93\u5165\u53c2\u6570\u662f\u7a7a\u7684\uff0c\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u7684\u503c\u4e3a`[0, 1, 2..., 98, 99]`\n\n3. \u901a\u8fc7lambda\u8fdb\u884c\u503c\u5f15\u7528\n\n\u8bed\u6cd5\u5df2\u5728\u53c2\u6570\u5f15\u7528\u90e8\u5206\u8fdb\u884c\u4ecb\u7ecd\n\n\n#### \u53c2\u6570\u641c\u7d22\n\n\u5728\u505a\u5b9e\u9a8c\u65f6\uff0c\u6211\u4eec\u9700\u8981\u9a8c\u8bc1\u591a\u79cd\u53c2\u6570\u7684\u7ec4\u5408\uff0c`intc`\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u53c2\u6570grid search\u7684\u80fd\u529b\uff0c\u9488\u5bf9\u6bcf\u4e2a\u641c\u7d22\u6761\u4ef6\u4ee5\u7b1b\u5361\u5c14\u79ef\u7684\u5f62\u5f0f\u8fdb\u884c\u7ec4\u5408\uff0c\u8fd4\u56de\u4e00\u4e2aconfig list\n\n```jsonc\n// data.json\n{\n    \"para1\": 1,\n    \"para2\": 100,\n    \"@children\":{\n        \"cpara1\": 1000,\n        \"cpara2\": \"a\",\n        \"_search\": {\n            \"cpara1\": \"@lambda _: list(range(1000, 1003))\"\n        }\n    },\n    \"_search\": {\n        \"para1\": [1, 2, 3],\n        \"para2\": \"@lambda _: [100, 200, 300]\",\n        \"@children.cpara2\": ['a', 'b', 'c']\n    }\n}\n\n```\n\n```python\nimport json\nfrom intc import Parser\nassert len(Parser(json.load(open('data.json')).parser())) == 81\n```\n\n\u5982\u793a\u4f8b\u4e2d\u6240\u793a\uff0c`intc`\u7684\u53c2\u6570\u641c\u7d22\u7684\u503c\u53ef\u4ee5\u662f\u4e00\u4e2a`list`\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a`lambda`\u8868\u8fbe\u5f0f\u8fd4\u56de\u4e00\u4e2a`list`\uff0c\u4f46\u662f\u76ee\u524d\u5728`_search`\u4e2d\u4f7f\u7528\u7684`lambda`\u8868\u8fbe\u5f0f\u76ee\u524d\u53ea\u652f\u6301\u503c\u8ba1\u7b97\uff0c\u4e0d\u53ef\u4ee5\u5f15\u7528\u5176\u4ed6\u7684\u53c2\u6570\u53c2\u4e0e\u8ba1\u7b97\uff0c\u6709\u8fd9\u4e2a\u9650\u5236\u7684\u539f\u56e0\u662f`_search`\u672c\u8eab\u6709\u53ef\u80fd\u6539\u53d8config\u7684\u7ed3\u6784\uff0c\u800c\u5f15\u7528\u5fc5\u987b\u5728config\u7ed3\u6784\u56fa\u5b9a\u65f6\u624d\u53ef\u4ee5\u3002\u6240\u4ee5\u5b9e\u9645\u5f15\u7528\u7684\u8ba1\u7b97\u662f\u5728`_search`\u751f\u6210\u56fa\u5b9a\u7684config\u4e4b\u540e\u53d1\u751f\n\n#### DataClass && Json Schema\n\n`intc`\u9664\u4e86\u53ef\u4ee5\u4f5c\u4e3aconfig\u7ba1\u7406\u5de5\u5177\u4f7f\u7528\u4e4b\u5916\uff0c\u4e5f\u53ef\u4ee5\u5f53\u505a`dataclass`\u6765\u4f7f\u7528\uff0c\u7279\u522b\u662f`intc`\u9664\u4e86\u652f\u6301\u4e00\u822c\u7684`json`\u6570\u636e\u7684\u5bfc\u5165\u5bfc\u51fa\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u6839\u636e\u5b9a\u4e49\u5bfc\u51fa`json schema`\uff0c\u8fd9\u5bf9\u4e8e\u4e00\u4e9b\u7279\u5b9a\u7684\u573a\u666f\u5982\u7ea6\u5b9a\u5927\u6a21\u578b\u7684\u8f93\u5165\u8f93\u51fa\u683c\u5f0f\u65f6\u975e\u5e38\u6709\u7528\n\n\n```python\nimport json\n\nfrom intc import MISSING, Base, IntField, NestField, StrField, dataclass\n\n\n@dataclass\nclass LLMOutput(Base):\n    \"\"\"The output of the LLM model\"\"\"\n\n    user_name = StrField(value=MISSING, help=\"Name of the person\")\n\n    class Info:\n        age = IntField(value=MISSING, minimum=1, maximum=150, help=\"Age of the person\")\n        blood_type = StrField(\n            value=MISSING, options=[\"A\", \"B\", \"AB\", \"O\"], help=\"Blood type\"\n        )\n\n    user_info = NestField(value=Info, help=\"User information\")\n    lines = IntField(value=MISSING, help=\"Number of lines in the output\")\nprint(json.dumps(LLMOutput._json_schema(), indent=4))\n```\n\nJson Schema Output:\n```json\n{\n    \"properties\": {\n        \"user_name\": {\n            \"description\": \"Name of the person\",\n            \"type\": \"string\",\n            \"deprecated\": false\n        },\n        \"user_info\": {\n            \"description\": \"User information\",\n            \"type\": \"object\",\n            \"properties\": {\n                \"age\": {\n                    \"description\": \"Age of the person\",\n                    \"type\": \"integer\",\n                    \"deprecated\": false,\n                    \"minimum\": 1,\n                    \"maximum\": 150\n                },\n                \"blood_type\": {\n                    \"description\": \"Blood type\",\n                    \"type\": \"string\",\n                    \"enum\": [\n                        \"A\",\n                        \"B\",\n                        \"AB\",\n                        \"O\"\n                    ],\n                    \"deprecated\": false\n                }\n            }\n        }\n    },\n    \"type\": \"object\",\n    \"description\": \"The output of the LLM model\",\n    \"$schema\": \"https://json-schema.org/draft/2020-12/schema\"\n}\n```\n### Intc-LSP\n#### Hover Document\n\n<div style=\"text-align:center\">\n<span style=\"width:47%;display:inline-block\">\n\n![nvim hover](./pics/nvim_hover.png)\n\n</span>\n<span style=\"width:47%;display:inline-block\">\n\n![vsc hover](./pics/vsc_hover.png)\n\n</span>\n</div>\n\n#### Diagnostic\n\n<div style=\"text-align:center\">\n<span style=\"width:47%;display:inline-block\">\n\n![nvim diag](./pics/nvim_diag.png)\n\n</span>\n<span style=\"width:47%;display:inline-block\">\n\n![vsc diag](./pics/vsc_diag.png)\n\n</span>\n</div>\n\n#### Completion\n\n<div style=\"text-align:center\">\n<span style=\"width:47%;display:inline-block\">\n\n![nvim comp](./pics/nvim_comp.png)\n\n</span>\n<span style=\"width:47%;display:inline-block\">\n\n![vsc comp](./pics/vsc_comp.png)\n\n</span>\n</div>\n\n#### Goto/Peek Definition\n\n<div style=\"text-align:center\">\n<span style=\"width:47%;display:inline-block\">\n\n![nvim goto](./pics/nvim_goto.png)\n\n</span>\n<span style=\"width:47%;display:inline-block\">\n\n![vsc goto](./pics/vsc_goto.png)\n\n</span>\n</div>\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "intc-lsp: intc language server",
    "version": "0.1.0b0",
    "project_urls": {
        "Homepage": "https://github.com/cstsunfu/intc"
    },
    "split_keywords": [
        "intc",
        " lsp",
        " intc-lsp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e6ae23075af787b8dcd5b6815ac7f150311b8b2d4a9ea66b923090f2f29d14dc",
                "md5": "46d2e897587e5d1aabcf42895644e8bc",
                "sha256": "9eb61b5503346afaa6b3dff9f0fb0c7fcd003416b6e51dc94f415c1970855f3e"
            },
            "downloads": -1,
            "filename": "intc_lsp-0.1.0b0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "46d2e897587e5d1aabcf42895644e8bc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 367488,
            "upload_time": "2024-04-07T12:14:51",
            "upload_time_iso_8601": "2024-04-07T12:14:51.161455Z",
            "url": "https://files.pythonhosted.org/packages/e6/ae/23075af787b8dcd5b6815ac7f150311b8b2d4a9ea66b923090f2f29d14dc/intc_lsp-0.1.0b0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b3db31148fd3bbf865942a5397a75c3b957aaeb564a096d8a23c4e1ef94f8489",
                "md5": "375e8d6249fc0ad25dfc6133680b75b9",
                "sha256": "f2be35c8030cdb2949a70bbb2dfc5a7062394c850380f638d6262c87eea6ec1b"
            },
            "downloads": -1,
            "filename": "intc_lsp-0.1.0b0.tar.gz",
            "has_sig": false,
            "md5_digest": "375e8d6249fc0ad25dfc6133680b75b9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 251688,
            "upload_time": "2024-04-07T12:14:53",
            "upload_time_iso_8601": "2024-04-07T12:14:53.767304Z",
            "url": "https://files.pythonhosted.org/packages/b3/db/31148fd3bbf865942a5397a75c3b957aaeb564a096d8a23c4e1ef94f8489/intc_lsp-0.1.0b0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-07 12:14:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cstsunfu",
    "github_project": "intc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "intc-lsp"
}
        
Elapsed time: 0.21241s