当前位置: 首页>>代码示例>>Python>>正文


Python hug.get方法代码示例

本文整理汇总了Python中hug.get方法的典型用法代码示例。如果您正苦于以下问题:Python hug.get方法的具体用法?Python hug.get怎么用?Python hug.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hug的用法示例。


在下文中一共展示了hug.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_home

# 需要导入模块: import hug [as 别名]
# 或者: from hug import get [as 别名]
def test_home(tracked_requests):
    with app_with_scout() as app:
        response = TestApp(app).get("/")

    assert response.status_int == 200
    assert response.text == '"Welcome home."'
    assert len(tracked_requests) == 1
    tracked_request = tracked_requests[0]
    assert tracked_request.tags["path"] == "/"
    assert tracked_request.active_spans == []
    assert len(tracked_request.complete_spans) == 2
    assert (
        tracked_request.complete_spans[0].operation
        == "Controller/tests.integration.test_hug.home"
    )
    assert tracked_request.complete_spans[1].operation == "Middleware" 
开发者ID:scoutapp,项目名称:scout_apm_python,代码行数:18,代码来源:test_hug.py

示例2: a_redis_call

# 需要导入模块: import hug [as 别名]
# 或者: from hug import get [as 别名]
def a_redis_call(rname, ape=1):
    """Simple redis call."""
    if ape == 1:
        return "no valid api key specified, nice try though".format(**locals())
    if r.sismember('ape', ape) != 1:
        return "no valid api key specified, nice try though".format(**locals())
    else:
        coolness = r.get(rname).decode('utf8')
        r.decr(ape)
        numleft = r.get(str(ape))
        print(numleft)
        return "Authenticated w {ape}. You have {numleft} queries left. This\
             is the {rname} value you requested: {coolness}".format(**locals()) 
开发者ID:jamesacampbell,项目名称:python-examples,代码行数:15,代码来源:hug_api_example.py

示例3: inference

# 需要导入模块: import hug [as 别名]
# 或者: from hug import get [as 别名]
def inference(request, body, response):
    """Makes an inference to a certain model"""
    print(body)
    if request.headers.get('CONTENT-TYPE') == 'application/gzip':
        try:
            original_data = gzip.decompress(request.stream.read())
            input_docs = json.loads(str(original_data, 'utf-8'))["docs"]
            model_name = json.loads(str(original_data, 'utf-8'))["model_name"]
        except Exception:
            response.status = hug.HTTP_500
            return {'status': 'unexpected gzip error'}
    elif request.headers.get('CONTENT-TYPE') == 'application/json':
        if isinstance(body, str):
            body = json.loads(body)
        model_name = body.get('model_name')
        input_docs = body.get('docs')
    else:
        response.status = status_codes.HTTP_400
        return {'status': 'Content-Type header must be application/json or application/gzip'}
    if not model_name:
        response.status = status_codes.HTTP_400
        return {'status': 'model_name is required'}
    # If we've already initialized it, no use in reinitializing
    if not services.get(model_name):
        services[model_name] = Service(model_name)
    if not isinstance(input_docs, list):  # check if it's an array instead
        response.status = status_codes.HTTP_400
        return {'status': 'request not in proper format '}
    headers = parse_headers(request.headers)
    parsed_doc = services[model_name].get_service_inference(input_docs, headers)
    resp_format = request.headers["RESPONSE-FORMAT"]
    ret = format_response(resp_format, parsed_doc)
    if request.headers.get('CONTENT-TYPE') == 'application/gzip':
        response.content_type = resp_format
        response.body = ret
        # no return due to the fact that hug seems to assume json type upon return
    else:
        return ret 
开发者ID:NervanaSystems,项目名称:nlp-architect,代码行数:40,代码来源:serve.py


注:本文中的hug.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。