Skip to content

Commit

Permalink
update: NCP CLOVA Summary API
Browse files Browse the repository at this point in the history
- NCP CLOVA Summary API 추가
  • Loading branch information
WooilJeong committed Feb 10, 2023
1 parent ce8cbcc commit 4646b5c
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 1 deletion.
49 changes: 49 additions & 0 deletions PyNaver/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,55 @@ def directions15(self, start, goal, **kwargs):
else:
return res

def clova_summary(self,
content=None,
title=None,
language="ko",
model="general",
tone=0,
summaryCount=3,
):
"""
Clova Summary API
Parameters
----------
content : string, REQUIRED
요약할 내용
title : string, OPTIONAL
요약할 제목
language : string, REQUIRED (ko: 한국어, ja: 일본어) (미지정 시 기본 값: ko)
언어
model : string, OPTIONAL
모델 (general: 일반 문서 요약, news: 뉴스 요약) (미지정 시 기본 값: general)
tone : int, OPTIONAL
톤 (0: 원문의 어투를 유지, 1: 해요체, 2: 정중체, 3: 명사형 종결체) (미지정 시 기본 값: 0)
summaryCount : int, OPTIONAL
요약문 개수 (미지정 시 기본 값: 3)
"""
url = "https://naveropenapi.apigw.ntruss.com/text-summary/v1/summarize"
params = {
"document": {
"content": content,
"title": title,
},
"option": {
"language": language,
"model": model,
"tone": tone,
"summaryCount": summaryCount,
},
}
headers = self.headers.copy()
headers.update({
"Content-Type": "application/json",
})
res = requests.post(url, headers=headers, json=params)
if res.status_code == 200:
return res.json()
else:
return res


class Map:
"""
Expand Down
2 changes: 1 addition & 1 deletion PyNaver/config/info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.9"
__version__ = "0.0.10"
__author__ = "정우일(Wooil Jeong)"
__contact__ = "wooil@kakao.com"
__github__ = "https://github.com/WooilJeong/PyNaver"
84 changes: 84 additions & 0 deletions test/test2.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"from pathlib import Path\n",
"some_path = \"D:/github/PyNaver\"\n",
"sys.path.append(some_path)\n",
"\n",
"from config import KEYS"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"_id = KEYS['NCP']['id']\n",
"_pw = KEYS['NCP']['pw']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from PyNaver import NaverCloudPlatform\n",
"\n",
"api = NaverCloudPlatform(_id, _pw)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Parameters\n",
"content = \"\"\"간편송금 이용금액이 하루 평균 2000억원을 넘어섰다. 한국은행이 17일 발표한 '2019년 상반기중 전자지급서비스 이용 현황'에 따르면 올해 상반기 간편송금서비스 이용금액(일평균)은 지난해 하반기 대비 60.7% 증가한 2005억원으로 집계됐다. 같은 기간 이용건수(일평균)는 34.8% 늘어난 218만건이었다. 간편 송금 시장에는 선불전자지급서비스를 제공하는 전자금융업자와 금융기관 등이 참여하고 있다. 이용금액은 전자금융업자가 하루평균 1879억원, 금융기관이 126억원이었다. 한은은 카카오페이, 토스 등 간편송금 서비스를 제공하는 업체 간 경쟁이 심화되면서 이용규모가 크게 확대됐다고 분석했다. 국회 정무위원회 소속 바른미래당 유의동 의원에 따르면 카카오페이, 토스 등 선불전자지급서비스 제공업체는 지난해 마케팅 비용으로 1000억원 이상을 지출했다. 마케팅 비용 지출규모는 카카오페이가 491억원, 비바리퍼블리카(토스)가 134억원 등 순으로 많았다.\"\"\"\n",
"tone = 3\n",
"summaryCount = 3\n",
"\n",
"result = api.clova_summary(content=content,\n",
" tone=3,\n",
" summaryCount=3)['summary']\n",
"result"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "d92cf83b93649b0f2aacc8932dcad5ad7e41ac873487e7b924d6de635e19277f"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 4646b5c

Please sign in to comment.