Skip to content

Commit 4646b5c

Browse files
committed
update: NCP CLOVA Summary API
- NCP CLOVA Summary API 추가
1 parent ce8cbcc commit 4646b5c

File tree

3 files changed

+134
-1
lines changed

3 files changed

+134
-1
lines changed

PyNaver/api.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,55 @@ def directions15(self, start, goal, **kwargs):
10451045
else:
10461046
return res
10471047

1048+
def clova_summary(self,
1049+
content=None,
1050+
title=None,
1051+
language="ko",
1052+
model="general",
1053+
tone=0,
1054+
summaryCount=3,
1055+
):
1056+
"""
1057+
Clova Summary API
1058+
1059+
Parameters
1060+
----------
1061+
content : string, REQUIRED
1062+
요약할 내용
1063+
title : string, OPTIONAL
1064+
요약할 제목
1065+
language : string, REQUIRED (ko: 한국어, ja: 일본어) (미지정 시 기본 값: ko)
1066+
언어
1067+
model : string, OPTIONAL
1068+
모델 (general: 일반 문서 요약, news: 뉴스 요약) (미지정 시 기본 값: general)
1069+
tone : int, OPTIONAL
1070+
톤 (0: 원문의 어투를 유지, 1: 해요체, 2: 정중체, 3: 명사형 종결체) (미지정 시 기본 값: 0)
1071+
summaryCount : int, OPTIONAL
1072+
요약문 개수 (미지정 시 기본 값: 3)
1073+
"""
1074+
url = "https://naveropenapi.apigw.ntruss.com/text-summary/v1/summarize"
1075+
params = {
1076+
"document": {
1077+
"content": content,
1078+
"title": title,
1079+
},
1080+
"option": {
1081+
"language": language,
1082+
"model": model,
1083+
"tone": tone,
1084+
"summaryCount": summaryCount,
1085+
},
1086+
}
1087+
headers = self.headers.copy()
1088+
headers.update({
1089+
"Content-Type": "application/json",
1090+
})
1091+
res = requests.post(url, headers=headers, json=params)
1092+
if res.status_code == 200:
1093+
return res.json()
1094+
else:
1095+
return res
1096+
10481097

10491098
class Map:
10501099
"""

PyNaver/config/info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.0.9"
1+
__version__ = "0.0.10"
22
__author__ = "정우일(Wooil Jeong)"
33
__contact__ = "[email protected]"
44
__github__ = "https://github.com/WooilJeong/PyNaver"

test/test2.ipynb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import os\n",
10+
"import sys\n",
11+
"from pathlib import Path\n",
12+
"some_path = \"D:/github/PyNaver\"\n",
13+
"sys.path.append(some_path)\n",
14+
"\n",
15+
"from config import KEYS"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": null,
21+
"metadata": {},
22+
"outputs": [],
23+
"source": [
24+
"_id = KEYS['NCP']['id']\n",
25+
"_pw = KEYS['NCP']['pw']"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"from PyNaver import NaverCloudPlatform\n",
35+
"\n",
36+
"api = NaverCloudPlatform(_id, _pw)"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"# Parameters\n",
46+
"content = \"\"\"간편송금 이용금액이 하루 평균 2000억원을 넘어섰다. 한국은행이 17일 발표한 '2019년 상반기중 전자지급서비스 이용 현황'에 따르면 올해 상반기 간편송금서비스 이용금액(일평균)은 지난해 하반기 대비 60.7% 증가한 2005억원으로 집계됐다. 같은 기간 이용건수(일평균)는 34.8% 늘어난 218만건이었다. 간편 송금 시장에는 선불전자지급서비스를 제공하는 전자금융업자와 금융기관 등이 참여하고 있다. 이용금액은 전자금융업자가 하루평균 1879억원, 금융기관이 126억원이었다. 한은은 카카오페이, 토스 등 간편송금 서비스를 제공하는 업체 간 경쟁이 심화되면서 이용규모가 크게 확대됐다고 분석했다. 국회 정무위원회 소속 바른미래당 유의동 의원에 따르면 카카오페이, 토스 등 선불전자지급서비스 제공업체는 지난해 마케팅 비용으로 1000억원 이상을 지출했다. 마케팅 비용 지출규모는 카카오페이가 491억원, 비바리퍼블리카(토스)가 134억원 등 순으로 많았다.\"\"\"\n",
47+
"tone = 3\n",
48+
"summaryCount = 3\n",
49+
"\n",
50+
"result = api.clova_summary(content=content,\n",
51+
" tone=3,\n",
52+
" summaryCount=3)['summary']\n",
53+
"result"
54+
]
55+
}
56+
],
57+
"metadata": {
58+
"kernelspec": {
59+
"display_name": "venv",
60+
"language": "python",
61+
"name": "python3"
62+
},
63+
"language_info": {
64+
"codemirror_mode": {
65+
"name": "ipython",
66+
"version": 3
67+
},
68+
"file_extension": ".py",
69+
"mimetype": "text/x-python",
70+
"name": "python",
71+
"nbconvert_exporter": "python",
72+
"pygments_lexer": "ipython3",
73+
"version": "3.9.12"
74+
},
75+
"orig_nbformat": 4,
76+
"vscode": {
77+
"interpreter": {
78+
"hash": "d92cf83b93649b0f2aacc8932dcad5ad7e41ac873487e7b924d6de635e19277f"
79+
}
80+
}
81+
},
82+
"nbformat": 4,
83+
"nbformat_minor": 2
84+
}

0 commit comments

Comments
 (0)