class SegmentationExecutor:
def __init__(self, host, api_key, api_key_primary_val, request_id):
self._host = host
self._api_key = api_key
self._api_key_primary_val = api_key_primary_val
self._request_id = request_id
def _send_request(self, completion_request):
headers = {
"Content-Type": "application/json; charset=utf-8",
"X-NCP-CLOVASTUDIO-API-KEY": self._api_key,
"X-NCP-APIGW-API-KEY": self._api_key_primary_val,
"X-NCP-CLOVASTUDIO-REQUEST-ID": self._request_id
}
conn = http.client.HTTPSConnection(self._host)
conn.request(
"POST",
"/testapp/v1/api-tools/segmentation/-",
json.dumps(completion_request),
headers
)
response = conn.getresponse()
result = json.loads(response.read().decode(encoding="utf-8"))
conn.close()
return result
def execute(self, completion_request):
res = self._send_request(completion_request)
if res["status"]["code"] == "20000":
return res["result"]["topicSeg"]
else:
return "Error"
if __name__ == "__main__":
segmentation_executor = SegmentationExecutor(
host="clovastudio.apigw.ntruss.com",
api_key='-',
api_key_primary_val='-',
request_id='-'
)
chunked_html = []
for htmldata in tqdm(clovastudiodatas_flattened):
request_data = {
"postProcessMaxSize": 100,
"alpha": 1.5,
"segCnt": -1,
"postProcessMinSize": 0,
"text": htmldata.page_content,
"postProcess": False
}
request_json_string = json.dumps(request_data)
request_data = json.loads(request_json_string, strict=False)
print(request_data)
response_data = segmentation_executor.execute(request_data)
# 반환된 각 문단에 대해 source(주소) 포함하여 chunked_documents에 추가
for paragraph in response_data:
chunked_document = {
"source": htmldata.metadata["source"],
"text": paragraph
}
chunked_html.append(chunked_document)
문단 나누기 api를 게시물과 똑같이 호출했음에도 응답값이 제대로 돌아오지 않습니다. code는 40000으로 나오고, messegae는 ' '라고만 출력되네요. 혹시 문단 나누기 api에 변경이 생겼을까요?