hivemind的工作流包装器
hivemind-plus的Python项目详细描述
hivemind plus是一个python库,用于帮助创建 hivemind平台上的实例和结果处理。在你面前 使用这个库,您需要通过 网站。
安装
$ pip install hivemind-plus
用法
要使用HiveMind Plus,必须创建实例配置, 结果配置或两者兼有。每种配置都带有 ConfigBuilder类,帮助您组装配置。
实例配置
fromhivemindplusimportinstanceinstance_config=(instance.ConfigBuilder().with_connection_string('DRIVER={SQL Server};SERVER=localhost;DATABASE=DB;')# ODBC style connection string.with_query('SELECT PeopleId, FullName FROM dbo.People')# Query to drive instances.with_key('PeopleId')# Column name to use as unique identifier for an instance.with_name('FullName')# Column name to use as a human readable identifier.with_tags(['FullName'])# (Optional) Columns to tag instances with.with_data(['FullName','PeopleId'])# (Optional) Columns to populate the data field on an instance with.with_instructions('instructions.md',['FullName'])# (Optional) Template markdown file and values.with_schema('schema.json',['Id','FullName'])# (Optional) Schema template json file and values.with_qualifications_query('SELECT PeopleId, Qualification FROM dbo.Qualifications')# (Optional) Query for qualifications.build())
结果配置
fromhivemindplusimportresult# Executed for every agreed upon resultdefoutput_fn(res):print('Output function')print(str(res))# Custom agreement function that compares two resultsdefagreement_fn(a,b):returna['data']==b['data']result_config=(result.ConfigBuilder().with_connection_string('DRIVER={SQL Server};SERVER=localhost;DATABASE=DB;')# ODBC style connection string.with_instance_table('dbo.InstanceResults')# (Optional) Override default name of instance results table.with_iteration_table('dbo.IterationResults')# (Optional) Override default name of iteration results table.with_output_function(output_fn)# (Optional) Function to execute on agreed upon result.with_agreement_function(agreement_fn,0.51)# (Optional) Function to determine agreement.with_feedback_function(feedback_fn)# (Optional) Function executed with instance/iteration results for integration of feedback.with_max_iterations(5)# (Optional) Max number of iterations to retry agreement checking with.with_process_all_results(True)# (Optional) Whether to process all results, regardless if created by HM+.build())
工作流配置
fromhivemindplusimportworkflowflow=(workflow.Builder().with_api_url('https://client.sandbox.hvmd.io')# URL of the API without a trailing /.with_api_key('API-KEY')# Personal API key.with_task_id(0)# Task that you want to manage.with_instance_config(instance_config)# (Optional) instance configuration.with_result_config(result_config)# (Optional) result configuration.with_auto_submission()# (Optional) submit task if not already submitted.build())# Start the workflowflow.start()
示例
在/examples目录中可以找到一整套示例。
调试
hivemind plus可以在调试模式下运行,该模式将打印出不在调试模式下要执行的所有操作。
fromhivemindplusimportworkflowflow=(workflow.Builder().with_debug_enabled().build())
开发
要开始开发,您需要安装所有必需的 开发包。
$ pip install .[test]
所有源代码都位于/hivemindplus目录中,并且 测试可以从项目根目录运行,如下所示。
python -m pytest