没有项目描述
qai的Python项目详细描述
library.qai.utilities
第二版!rest服务器和helper函数和类,用于与qordoba平台的其余部分交互。
有关1.x文档,请参见github历史记录。
升级到v2
升级到v2确实需要一些更改。一些值得注意的:
get_config
将断开。对不起,你必须自己处理这个问题QConnect
已不存在,而QRest
将更显式地导入- 不再有
qai
Docker图像。你可以随意使用任何你想要的基本图像。我可以推荐qsam/spacy_alpine
。 qai
现在是pip依赖,因此必须在您的requirements.txt
然而!有人帮忙。遵循以下步骤:
cd qai_v1_service vactivate # or however you go into a virtualenv pip uninstall -y qai # uninstalls old qai pip install qai # installs qai from PyPi python -m qai.upgrade . # shows you how it would change your files to make the project ready for v2# n to reject, y to accept
现在剩下的就是看你是否使用了get_configs
,如果是的话:passget_configs
一个绝对路径(v2),而不是分割成一个列表(v1)的相对路径。
注意:我走得有点快,长话短说,版本2.0.x和2.1.x是无法挽救的。只需使用2.2.0+。
要知道的事情
有关详细信息,请参见The Changelog。
必需的“约定”
所有项目必须有一个config.json
,并且配置必须指定SUPPORTED_LANGUAGES
,这是一个字符串或字符串列表,格式为"en"
或["en", "de", "zh"]
(iso代码的前缀)。qai不会让您的服务启动,除非它认为您有一个有效的SUPPORTED_LANGUAGES
字段。默认情况下,qai将在conf/config.json
中查找此项。这是可重写的。以下是最小配置:
{"SUPPORTED_LANGUAGES":"en"}
您可以在配置文件中使用
{"SUPPORTED_LANGUAGES":"en","SERVICE_NAME":"hey look at me service",}
例如,要将配置路径更改为./my_config_dir/a_sub_dir/my_wacky_config.json
:
QRest(analyzer,category='service name, e.g. formality',white_lister=white_lister,config_path=['my_config_dir','a_sub_dir','my_wacky_config.json'])
用法
您可以显式地创建这样的rest连接:
fromappimportAnalyzer,whitelistfromqai.qconnect.qrestimportQRestSERVICE_NAME='service_name'host='0.0.0.0'port=5000if__name__=='__main__':analyzer=Analyzer()rest_connection=QRest(analyzer,category=category,white_lister=white_lister,host=host,port=port)# create a blocking connection:rest_connection.connect()
上面的代码将创建尽可能多的工作线程。这很好,除非使用automl。有一个已知的错误,如果使用多个工作进程,automl将崩溃。
因此,如果您使用的是automl,那么上面的代码看起来像:
fromappimportAnalyzer,whitelistfromqai.qconnect.qrestimportQRestSERVICE_NAME='service_name'host='0.0.0.0'port=5000workers=1if__name__=='__main__':analyzer=Analyzer()rest_connection=QRest(analyzer,category=category,white_lister=white_lister,host=host,port=port,workers=workers)# create a blocking connection:rest_connection.connect()
还有一个helper类,用于将spacySpan
转换为平台其余部分可以处理的问题:
fromspacy.tokensimportSpanfromapp.factorimportSpacyFactorSOV=SpacyFactor("subject_object_verb_spacing","Keep the subject, verb, and object of a sentence close together to help the reader understand the sentence.")Span.set_extension("score",default=0)Span.set_extension("suggestions",default=[])doc=nlp("Holders of the Class A and Class B-1 certificates will be entitled to receive on each Payment Date, to the extent monies are available therefor (but not more than the Class A Certificate Balance or Class B-1 Certificate Balance then outstanding), a distribution.")score=analyze(doc)ifscoreisnotNone:span=Span(doc,0,len(doc))# or whichever TOKENS are the issue (don't have to worry about character indexes)span._.score=scorespan._.suggestions=get_suggestions(doc)issues=SOV(span)
安装
皮普?
测试
有关输入格式期望的文档,请参见合流。
scripts/test_qai.sh
具有一些有用的测试功能。
开发
真相的来源是VERSION
文件,由setup.py
和Jenkinsfile
读取。当您运行python setup.py sdist/bdist
时,这将创建qai/version.py
,在qai/__init__.py
中读取。这是因为python的模块系统令人沮丧。它允许在运行时不必知道文件的绝对路径,这在python中是一个很大的优点。总之,这意味着VERSION
是真理的源泉。
许可证
此软件未经授权。如果您不在Qordoba工作,则在法律上不允许您使用它。而且,只是帮助函数对您没有帮助。如果其中的某些内容看起来确实有趣,并且您希望访问,请打开一个问题。