|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# This file is auto-generated, don't edit it. Thanks. |
| 3 | +from typing import Dict |
| 4 | +from Tea.core import TeaCore |
| 5 | + |
| 6 | +from alibabacloud_tea_openapi.client import Client as OpenApiClient |
| 7 | +from alibabacloud_tea_openapi import models as open_api_models |
| 8 | +from alibabacloud_tea_util.client import Client as UtilClient |
| 9 | +from alibabacloud_endpoint_util.client import Client as EndpointUtilClient |
| 10 | +from alibabacloud_bailianchatbot20241105 import models as bailian_chat_bot_20241105_models |
| 11 | +from alibabacloud_tea_util import models as util_models |
| 12 | +from alibabacloud_openapi_util.client import Client as OpenApiUtilClient |
| 13 | + |
| 14 | + |
| 15 | +class Client(OpenApiClient): |
| 16 | + """ |
| 17 | + *\ |
| 18 | + """ |
| 19 | + def __init__( |
| 20 | + self, |
| 21 | + config: open_api_models.Config, |
| 22 | + ): |
| 23 | + super().__init__(config) |
| 24 | + self._endpoint_rule = '' |
| 25 | + self.check_config(config) |
| 26 | + self._endpoint = self.get_endpoint('bailianchatbot', self._region_id, self._endpoint_rule, self._network, self._suffix, self._endpoint_map, self._endpoint) |
| 27 | + |
| 28 | + def get_endpoint( |
| 29 | + self, |
| 30 | + product_id: str, |
| 31 | + region_id: str, |
| 32 | + endpoint_rule: str, |
| 33 | + network: str, |
| 34 | + suffix: str, |
| 35 | + endpoint_map: Dict[str, str], |
| 36 | + endpoint: str, |
| 37 | + ) -> str: |
| 38 | + if not UtilClient.empty(endpoint): |
| 39 | + return endpoint |
| 40 | + if not UtilClient.is_unset(endpoint_map) and not UtilClient.empty(endpoint_map.get(region_id)): |
| 41 | + return endpoint_map.get(region_id) |
| 42 | + return EndpointUtilClient.get_endpoint_rules(product_id, region_id, endpoint_rule, network, suffix) |
| 43 | + |
| 44 | + def sse_chat_with_options( |
| 45 | + self, |
| 46 | + request: bailian_chat_bot_20241105_models.SseChatRequest, |
| 47 | + runtime: util_models.RuntimeOptions, |
| 48 | + ) -> bailian_chat_bot_20241105_models.SseChatResponse: |
| 49 | + """ |
| 50 | + @summary SSE问答接口 |
| 51 | + |
| 52 | + @param request: SseChatRequest |
| 53 | + @param runtime: runtime options for this request RuntimeOptions |
| 54 | + @return: SseChatResponse |
| 55 | + """ |
| 56 | + UtilClient.validate_model(request) |
| 57 | + query = {} |
| 58 | + if not UtilClient.is_unset(request.app_id): |
| 59 | + query['AppId'] = request.app_id |
| 60 | + if not UtilClient.is_unset(request.command): |
| 61 | + query['Command'] = request.command |
| 62 | + if not UtilClient.is_unset(request.sender_id): |
| 63 | + query['SenderId'] = request.sender_id |
| 64 | + if not UtilClient.is_unset(request.sender_nick): |
| 65 | + query['SenderNick'] = request.sender_nick |
| 66 | + if not UtilClient.is_unset(request.session_id): |
| 67 | + query['SessionId'] = request.session_id |
| 68 | + if not UtilClient.is_unset(request.utterance): |
| 69 | + query['Utterance'] = request.utterance |
| 70 | + if not UtilClient.is_unset(request.vendor_param): |
| 71 | + query['VendorParam'] = request.vendor_param |
| 72 | + if not UtilClient.is_unset(request.workspace_id): |
| 73 | + query['WorkspaceId'] = request.workspace_id |
| 74 | + req = open_api_models.OpenApiRequest( |
| 75 | + query=OpenApiUtilClient.query(query) |
| 76 | + ) |
| 77 | + params = open_api_models.Params( |
| 78 | + action='SseChat', |
| 79 | + version='2024-11-05', |
| 80 | + protocol='HTTPS', |
| 81 | + pathname='/', |
| 82 | + method='POST', |
| 83 | + auth_type='AK', |
| 84 | + style='RPC', |
| 85 | + req_body_type='formData', |
| 86 | + body_type='json' |
| 87 | + ) |
| 88 | + if UtilClient.is_unset(self._signature_version) or not UtilClient.equal_string(self._signature_version, 'v4'): |
| 89 | + return TeaCore.from_map( |
| 90 | + bailian_chat_bot_20241105_models.SseChatResponse(), |
| 91 | + self.call_api(params, req, runtime) |
| 92 | + ) |
| 93 | + else: |
| 94 | + return TeaCore.from_map( |
| 95 | + bailian_chat_bot_20241105_models.SseChatResponse(), |
| 96 | + self.execute(params, req, runtime) |
| 97 | + ) |
| 98 | + |
| 99 | + async def sse_chat_with_options_async( |
| 100 | + self, |
| 101 | + request: bailian_chat_bot_20241105_models.SseChatRequest, |
| 102 | + runtime: util_models.RuntimeOptions, |
| 103 | + ) -> bailian_chat_bot_20241105_models.SseChatResponse: |
| 104 | + """ |
| 105 | + @summary SSE问答接口 |
| 106 | + |
| 107 | + @param request: SseChatRequest |
| 108 | + @param runtime: runtime options for this request RuntimeOptions |
| 109 | + @return: SseChatResponse |
| 110 | + """ |
| 111 | + UtilClient.validate_model(request) |
| 112 | + query = {} |
| 113 | + if not UtilClient.is_unset(request.app_id): |
| 114 | + query['AppId'] = request.app_id |
| 115 | + if not UtilClient.is_unset(request.command): |
| 116 | + query['Command'] = request.command |
| 117 | + if not UtilClient.is_unset(request.sender_id): |
| 118 | + query['SenderId'] = request.sender_id |
| 119 | + if not UtilClient.is_unset(request.sender_nick): |
| 120 | + query['SenderNick'] = request.sender_nick |
| 121 | + if not UtilClient.is_unset(request.session_id): |
| 122 | + query['SessionId'] = request.session_id |
| 123 | + if not UtilClient.is_unset(request.utterance): |
| 124 | + query['Utterance'] = request.utterance |
| 125 | + if not UtilClient.is_unset(request.vendor_param): |
| 126 | + query['VendorParam'] = request.vendor_param |
| 127 | + if not UtilClient.is_unset(request.workspace_id): |
| 128 | + query['WorkspaceId'] = request.workspace_id |
| 129 | + req = open_api_models.OpenApiRequest( |
| 130 | + query=OpenApiUtilClient.query(query) |
| 131 | + ) |
| 132 | + params = open_api_models.Params( |
| 133 | + action='SseChat', |
| 134 | + version='2024-11-05', |
| 135 | + protocol='HTTPS', |
| 136 | + pathname='/', |
| 137 | + method='POST', |
| 138 | + auth_type='AK', |
| 139 | + style='RPC', |
| 140 | + req_body_type='formData', |
| 141 | + body_type='json' |
| 142 | + ) |
| 143 | + if UtilClient.is_unset(self._signature_version) or not UtilClient.equal_string(self._signature_version, 'v4'): |
| 144 | + return TeaCore.from_map( |
| 145 | + bailian_chat_bot_20241105_models.SseChatResponse(), |
| 146 | + await self.call_api_async(params, req, runtime) |
| 147 | + ) |
| 148 | + else: |
| 149 | + return TeaCore.from_map( |
| 150 | + bailian_chat_bot_20241105_models.SseChatResponse(), |
| 151 | + await self.execute_async(params, req, runtime) |
| 152 | + ) |
| 153 | + |
| 154 | + def sse_chat( |
| 155 | + self, |
| 156 | + request: bailian_chat_bot_20241105_models.SseChatRequest, |
| 157 | + ) -> bailian_chat_bot_20241105_models.SseChatResponse: |
| 158 | + """ |
| 159 | + @summary SSE问答接口 |
| 160 | + |
| 161 | + @param request: SseChatRequest |
| 162 | + @return: SseChatResponse |
| 163 | + """ |
| 164 | + runtime = util_models.RuntimeOptions() |
| 165 | + return self.sse_chat_with_options(request, runtime) |
| 166 | + |
| 167 | + async def sse_chat_async( |
| 168 | + self, |
| 169 | + request: bailian_chat_bot_20241105_models.SseChatRequest, |
| 170 | + ) -> bailian_chat_bot_20241105_models.SseChatResponse: |
| 171 | + """ |
| 172 | + @summary SSE问答接口 |
| 173 | + |
| 174 | + @param request: SseChatRequest |
| 175 | + @return: SseChatResponse |
| 176 | + """ |
| 177 | + runtime = util_models.RuntimeOptions() |
| 178 | + return await self.sse_chat_with_options_async(request, runtime) |
0 commit comments