资讯详情

资讯详情

Continue SDK Python 客户端 GetFreeTrialStatus200Response 模型详解:免费试用额度与用量查询

Continue SDK Python 客户端 GetFreeTrialStatus200Response 模型详解免费试用额度与用量查询【免费下载链接】continueopen-source coding agent项目地址: https://gitcode.com/GitHub_Trending/co/continueGetFreeTrialStatus200Response是 Continue Hub IDE APIOpenAPI 版本 1.0.0中GET /ide/free-trial-status接口的 200 响应模型由 OpenAPI Generator 自动生成并随 Continue 官方 Python SDKopenapi_client包分发。它承载用户在 Continue Hub 免费试用期内的订阅状态、聊天与自动补全autocomplete的已用量及上限数据。本文基于仓库内的 模型文档、接口定义、Pydantic 模型实现 与 API 客户端实现完整讲解该模型的全部字段语义、类型约束、序列化行为与端到端调用方法读完即可在自己的 Python 项目中正确解析和消费免费试用状态数据。模型定位免费试用状态查询的响应载体Continue SDK 的 Python 包为 IDE 扩展VS Code、JetBrains访问 Continue Hub 提供了程序化接口其 OpenAPI 客户端由 OpenAPI Generator 中查看API 版本 1.0.0、生成器版本 7.12.0、要求 Python 3.8。GetFreeTrialStatus200Response正是免费试用状态查询的唯一成功响应类型。调用 DefaultApi.get_free_trial_status 方法对应GET /ide/free-trial-status后SDK 会把响应 JSON 反序列化为该模型的实例开发者无需手工解析字典。注意Continue SDK 目前处于实验阶段详见 SDK README 的 EXPERIMENTAL 提示接口与模型可能在没有预告的情况下发生破坏性变更集成时建议锁定版本。模型属性全览原文档定义了 5 个字段其中 3 个为必填required2 个为可选optional并标注了对应的 JSON 别名aliasNameTypeDescriptionNotesopted_in_to_free_trialboolWhether the user has opted into the free trial必填chat_countfloatCurrent number of chat messages used可选nullableautocomplete_countfloatCurrent number of autocomplete requests used可选nullablechat_limitfloatMaximum number of chat messages allowed in free trial必填autocomplete_limitfloatMaximum number of autocomplete requests allowed in free trial必填对照 OpenAPI 原始定义可以确认必填字段为optedInToFreeTrial、chatLimit、autocompleteLimit三个若响应缺少它们Pydantic 校验会直接失败可选字段chatCount、autocompleteCount在 schema 中标记为nullable: true表示服务端可能显式返回null五个字段在 JSON 层面均使用camelCase 别名optedInToFreeTrial、chatCount、autocompleteCount、chatLimit、autocompleteLimit而 Python 模型属性为snake_case。各字段语义解读opted_in_to_free_trialbool必填用户是否已主动选择加入免费试用。它是判断免费试用资格的总开关如果为false通常意味着后续计数字段无实际意义。chat_countfloat可选当前已消耗的聊天消息条数。类型声明为float但实际底层约束是“数字”number既可以是整数也可以是浮点数详见下文模型实现。autocomplete_countfloat可选当前已消耗的自动补全请求次数。chat_limitfloat必填免费试用期内允许的聊天消息条数上限用于与chat_count相减得到剩余额度。autocomplete_limitfloat必填免费试用期内允许的自动补全请求次数上限。源码视角Pydantic 模型实现细节模型的完整实现位于 get_free_trial_status200_response.py其中几处细节值得注意1. 字段声明与 JSON 别名class GetFreeTrialStatus200Response(BaseModel): opted_in_to_free_trial: StrictBool Field( descriptionWhether the user has opted into the free trial, aliasoptedInToFreeTrial, ) chat_count: Optional[Union[StrictFloat, StrictInt]] Field( defaultNone, descriptionCurrent number of chat messages used, aliaschatCount ) autocomplete_count: Optional[Union[StrictFloat, StrictInt]] Field( defaultNone, descriptionCurrent number of autocomplete requests used, aliasautocompleteCount, ) chat_limit: Union[StrictFloat, StrictInt] Field( descriptionMaximum number of chat messages allowed in free trial, aliaschatLimit ) autocomplete_limit: Union[StrictFloat, StrictInt] Field( descriptionMaximum number of autocomplete requests allowed in free trial, aliasautocompleteLimit, )数字字段类型是Union[StrictFloat, StrictInt]即 JSON 中的整数如42和浮点数如42.5都会被接受并保持原样这解释了为何文档中类型标注为float但实际接受整数可选字段显式设置defaultNone在响应未携带该字段时不会触发校验错误model_config开启了populate_by_nameTrue意味着构造实例时既可以用 snake_casechat_count也可以用 camelCasechatCount作为关键字参数validate_assignmentTrue保证实例创建后的属性赋值同样经过类型校验。2. 可选字段的 null 处理to_dict()方法对两个可空字段做了特殊处理正常情况下None值会被exclude_noneTrue过滤掉但如果用户显式将chat_count或autocomplete_count赋值为None即该字段被设置过to_dict()仍会在输出字典中保留chatCount: None这一键。这一行为保证客户端可以区分“字段缺失”与“服务端明确返回 null”两种情况。从 JSON 与字典创建实例官方示例逐行解析原文档给出了完整的模型使用示例位于 GetFreeTrialStatus200Response.md完整继承了该示例并补充注释如下from openapi_client.models.get_free_trial_status200_response import GetFreeTrialStatus200Response # 用一个 JSON 字符串创建模型实例 json {} # TODO: 将上面的 json 字符串替换为真实的响应体例如 # json {optedInToFreeTrial: true, chatCount: 3, chatLimit: 50, autocompleteCount: 12, autocompleteLimit: 100} get_free_trial_status200_response_instance GetFreeTrialStatus200Response.from_json(json) # 打印模型的 JSON 字符串表示输出使用 camelCase 别名 print(GetFreeTrialStatus200Response.to_json()) # 将模型对象转换为 dict get_free_trial_status200_response_dict get_free_trial_status200_response_instance.to_dict() # 从 dict 创建模型实例 get_free_trial_status200_response_from_dict GetFreeTrialStatus200Response.from_dict(get_free_trial_status200_response_dict)调用链说明可对照 模型源码from_json(json_str)内部先json.loads解析字符串再委托给from_dictfrom_dict(obj)通过cls.model_validate({...})按 camelCase 键逐一取值并交给 Pydantic 校验缺失的可选字段自动取Noneto_json()/to_dict()都使用by_aliasTrue输出键为 camelCase 形式与服务端响应保持一致可直接用于调试或二次传输。端到端实战完整调用免费试用状态接口模型通常不会独立使用而是作为get_free_trial_status接口的返回值被消费。完整调用流程如下整理自 DefaultApi.md 与 API README 的示例import os import openapi_client from openapi_client.models.get_free_trial_status200_response import GetFreeTrialStatus200Response from openapi_client.rest import ApiException from pprint import pprint # 1. 配置服务端地址可选默认 https://api.continue.dev configuration openapi_client.Configuration( hosthttps://api.continue.dev ) # 2. 配置 Bearer 认证apiKeyAuth configuration openapi_client.Configuration( access_tokenos.environ[BEARER_TOKEN] ) # 3. 进入 API 客户端上下文并调用接口 with openapi_client.ApiClient(configuration) as api_client: api_instance openapi_client.DefaultApi(api_client) try: # 该方法不需要任何参数 api_response api_instance.get_free_trial_status() print(The response of DefaultApi-get_free_trial_status:\n) pprint(api_response) # 直接访问模型属性 print(opted in:, api_response.opted_in_to_free_trial) print(chat used:, api_response.chat_count, /, api_response.chat_limit) print(autocomplete used:, api_response.autocomplete_count, /, api_response.autocomplete_limit) # 计算剩余额度 if api_response.opted_in_to_free_trial and api_response.chat_count is not None: remaining_chat api_response.chat_limit - api_response.chat_count print(remaining chat messages:, remaining_chat) except Exception as e: print(Exception when calling DefaultApi-get_free_trial_status: %s\n % e)接口契约要点HTTP 方法与路径GET /ide/free-trial-status可在 default_api.py 的_get_free_trial_status_serialize中确认resource_path/ide/free-trial-status认证方式apiKeyAuthBearer token通过Configuration.access_token注入未认证会返回 401请求参数无成功响应200反序列化为GetFreeTrialStatus200Response错误响应404User not found客户端会尝试反序列化为ListAssistants404Response见 default_api.py响应头Accept: application/json请求体类型未定义。典型业务场景拿到模型实例后常见的业务判断逻辑包括展示试用状态用opted_in_to_free_trial决定是否在界面上显示免费试用入口额度预警当chat_count / chat_limit接近 1 时提示用户即将用尽额度用量统计看板将chat_count、autocomplete_count与各自 limit 组合成进度条。测试佐证字段的可选性契约仓库内置的单元测试桩 test_get_free_trial_status200_response.py 中make_instance(include_optionalFalse)仅构造三个必填字段opted_in_to_free_trial、chat_limit、autocomplete_limit而include_optionalTrue时才补齐chat_count、autocomplete_count。这一测试结构与 OpenAPI schema 的required列表完全一致印证了两个 count 字段缺省时模型依然合法开发者在消费数据时必须对其可能为None的情况做防御性处理例如上例中的is not None判断。小结GetFreeTrialStatus200Response虽然只是 Continue Hub IDE API 中的一个响应模型却是理解 Continue 免费试用配额机制的最小入口。通过本文可以掌握五个字段两个必填布尔开关 两对 usage/limit的完整语义、camelCase 别名与 snake_case 属性之间的映射、nullable 字段在to_dict()中的特殊行为以及从鉴权配置到get_free_trial_status()调用的完整代码路径。相关源码与文档可进一步查阅模型实现、接口定义、DefaultApi 文档。【免费下载链接】continueopen-source coding agent项目地址: https://gitcode.com/GitHub_Trending/co/continue创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
觉得有用,分享给同行:

为您的企业打造数字门面

稳重轻奢商务风格,端正雅致视觉,长效耐看不易过时。

立即咨询 →