Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- app.py +55 -38
- prompt_dict.pkl +3 -0
- prompts.py +148 -19
- report.py +89 -44
- request_gpt.py +26 -0
app.py
CHANGED
|
@@ -7,118 +7,135 @@ Original file is located at
|
|
| 7 |
https://colab.research.google.com/drive/10O8RqzRNTUw5fZd-V7dCvS22oAFkTc1i
|
| 8 |
"""
|
| 9 |
|
| 10 |
-
# env
|
| 11 |
-
# !pip install -qqq gradio openai tenacity
|
| 12 |
-
|
| 13 |
-
# !cp "/content/drive/MyDrive/Colab Notebooks/risk/gpt_request.py" /content/
|
| 14 |
-
# !cp "/content/drive/MyDrive/Colab Notebooks/risk/prompts.py" /content/
|
| 15 |
-
# !cp "/content/drive/MyDrive/Colab Notebooks/risk/report.py" /content/
|
| 16 |
-
|
| 17 |
import gradio as gr
|
| 18 |
import time
|
| 19 |
import json
|
| 20 |
import random
|
| 21 |
|
| 22 |
-
from prompts import *
|
| 23 |
from report import *
|
|
|
|
| 24 |
|
| 25 |
GPT_MODEL_DICT = {"GPT3.5":"gpt-3.5-turbo-0125",
|
| 26 |
"GPT4":"gpt-4-0125-preview"}
|
| 27 |
|
| 28 |
-
def gen_report(text, gpt, progress=gr.Progress()):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
timestamp = time.time()
|
| 30 |
current_time = time.ctime(timestamp)
|
| 31 |
print("time:",current_time)
|
| 32 |
gpt_model = GPT_MODEL_DICT[gpt]
|
| 33 |
print("GPT:",gpt)
|
|
|
|
|
|
|
|
|
|
| 34 |
progress(0, desc="Starting")
|
| 35 |
-
ex_t_rnd = list(range(1,len(risk_ex_t)+1))
|
| 36 |
-
ex_f_rnd = list(range(1,len(risk_ex_f)+1))
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
if risk_response[0]["risk"] != "yes":
|
| 40 |
print(risk_response[0])
|
| 41 |
-
print(text)
|
| 42 |
print("completion_tokens_num:",risk_response[1])
|
| 43 |
print("prompt_tokens_num:",risk_response[2])
|
| 44 |
print("*"*20)
|
| 45 |
return "### ノーリスク"
|
| 46 |
progress(0.3, desc="title")
|
| 47 |
-
title_response = title(text, ex_t_rnd, risk_response[0]["risk_key"], gpt_model)
|
| 48 |
progress(0.5, desc="summary")
|
| 49 |
summary_response = summary(text, ex_t_rnd, gpt_model)
|
| 50 |
progress(0.7, desc="alert")
|
| 51 |
-
alert_response = alert(text, ex_t_rnd, risk_response[0]["risk_key"], gpt_model)
|
| 52 |
res_dict = {
|
| 53 |
'title':title_response[0]['title'],
|
| 54 |
'summary':summary_response[0]['summary'],
|
| 55 |
'alert':alert_response[0]['alert'],
|
| 56 |
'news':text,
|
| 57 |
-
'
|
| 58 |
-
'reason':risk_response[0]['reason']
|
|
|
|
| 59 |
}
|
| 60 |
# save
|
| 61 |
|
| 62 |
-
progress(0.85, desc="
|
| 63 |
translate_response = translate(res_dict, gpt_model)
|
| 64 |
progress(0.90, desc="over")
|
| 65 |
-
res_msg = report_msg.format(
|
| 66 |
title=translate_response[0]['title'],
|
| 67 |
summary=translate_response[0]['summary'],
|
| 68 |
alert=translate_response[0]['alert'],
|
| 69 |
news=translate_response[0]['news'],
|
| 70 |
risk=translate_response[0]['risk_key'],
|
| 71 |
-
reason=translate_response[0]['reason']
|
|
|
|
| 72 |
)
|
| 73 |
print(translate_response[0])
|
| 74 |
-
completion_tokens_num = [i[1] for i in [risk_response,title_response,summary_response,alert_response,translate_response]]
|
| 75 |
-
prompt_tokens_num = [i[2] for i in [risk_response,title_response,summary_response,alert_response,translate_response]]
|
| 76 |
print("completion_tokens_num:",completion_tokens_num)
|
| 77 |
print("prompt_tokens_num:",prompt_tokens_num)
|
| 78 |
print("*"*20)
|
| 79 |
return res_msg
|
| 80 |
|
| 81 |
-
def example_f(input,choice):
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
| 88 |
else:
|
| 89 |
print("error")
|
| 90 |
|
| 91 |
-
res_msg = report_msg.format(
|
| 92 |
title=json.loads(res['title'])['title'],
|
| 93 |
summary=json.loads(res['summary'])['summary'],
|
| 94 |
alert=json.loads(res['alert'])['alert'],
|
| 95 |
news=res['news'],
|
| 96 |
risk=json.loads(res['risk'])['risk_key'],
|
| 97 |
-
reason=json.loads(res['risk'])['reason']
|
|
|
|
| 98 |
)
|
| 99 |
return res_msg
|
| 100 |
|
| 101 |
with gr.Blocks(title="アラート生成demo", theme="bethecloud/storj_theme") as demo:
|
| 102 |
gr.Markdown("# アラート生成demo")
|
| 103 |
gr.Markdown("gptを通じてアラートメッセージを生成する")
|
|
|
|
|
|
|
| 104 |
with gr.Row():
|
| 105 |
with gr.Column():
|
| 106 |
choice = gr.Radio(choices = ["GPT3.5", "GPT4"], value="GPT3.5",label = "GPTモデル")
|
| 107 |
input = gr.Textbox(label="INPUT",lines=7)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
with gr.Column():
|
| 109 |
gr.Markdown("OUTPUT")
|
| 110 |
output = gr.Markdown(label="report")
|
| 111 |
|
| 112 |
gen_btn = gr.Button("生成")
|
| 113 |
-
gr.ClearButton([input,output],"クリア")
|
| 114 |
gr.Examples(
|
| 115 |
-
examples = [[risk_ex_t['ex1']['news'],"GPT3.5"
|
| 116 |
-
|
|
|
|
|
|
|
| 117 |
outputs = [output],
|
| 118 |
fn=example_f,
|
| 119 |
cache_examples = True
|
| 120 |
)
|
| 121 |
|
| 122 |
-
gen_btn.click(fn=gen_report, inputs=[input,choice], outputs=output)
|
| 123 |
-
|
| 124 |
-
demo.launch()
|
|
|
|
| 7 |
https://colab.research.google.com/drive/10O8RqzRNTUw5fZd-V7dCvS22oAFkTc1i
|
| 8 |
"""
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
import gradio as gr
|
| 11 |
import time
|
| 12 |
import json
|
| 13 |
import random
|
| 14 |
|
|
|
|
| 15 |
from report import *
|
| 16 |
+
from prompts import load_dict,save_dict
|
| 17 |
|
| 18 |
GPT_MODEL_DICT = {"GPT3.5":"gpt-3.5-turbo-0125",
|
| 19 |
"GPT4":"gpt-4-0125-preview"}
|
| 20 |
|
| 21 |
+
def gen_report(text, gpt, risk_dict, company_info, progress=gr.Progress()):
|
| 22 |
+
prompt_dict = load_dict()
|
| 23 |
+
if risk_dict == prompt_dict["risk_dict"]:
|
| 24 |
+
prompt_dict["risk_dict"]=risk_dict
|
| 25 |
+
save_dict(prompt_dict)
|
| 26 |
timestamp = time.time()
|
| 27 |
current_time = time.ctime(timestamp)
|
| 28 |
print("time:",current_time)
|
| 29 |
gpt_model = GPT_MODEL_DICT[gpt]
|
| 30 |
print("GPT:",gpt)
|
| 31 |
+
print("input:",text)
|
| 32 |
+
print("company_info:",company_info)
|
| 33 |
+
print("risk_dict:",risk_dict)
|
| 34 |
progress(0, desc="Starting")
|
| 35 |
+
ex_t_rnd = list(range(1,len(prompt_dict["risk_ex_t"])+1))
|
| 36 |
+
ex_f_rnd = list(range(1,len(prompt_dict["risk_ex_f"])+1))
|
| 37 |
+
random.shuffle(ex_t_rnd)
|
| 38 |
+
random.shuffle(ex_f_rnd)
|
| 39 |
+
print("seed:",ex_t_rnd,ex_f_rnd)
|
| 40 |
+
progress(0.05, desc="company analysis")
|
| 41 |
+
com_response = company_analysis(ex_t_rnd, risk_dict, company_info, gpt_model)
|
| 42 |
+
progress(0.2, desc="risk")
|
| 43 |
+
risk_response = risk(text, company_info,com_response[0], ex_t_rnd, ex_f_rnd, gpt_model)
|
| 44 |
if risk_response[0]["risk"] != "yes":
|
| 45 |
print(risk_response[0])
|
|
|
|
| 46 |
print("completion_tokens_num:",risk_response[1])
|
| 47 |
print("prompt_tokens_num:",risk_response[2])
|
| 48 |
print("*"*20)
|
| 49 |
return "### ノーリスク"
|
| 50 |
progress(0.3, desc="title")
|
| 51 |
+
title_response = title(text, company_info, ex_t_rnd, risk_response[0]["risk_key"], gpt_model)
|
| 52 |
progress(0.5, desc="summary")
|
| 53 |
summary_response = summary(text, ex_t_rnd, gpt_model)
|
| 54 |
progress(0.7, desc="alert")
|
| 55 |
+
alert_response = alert(text, company_info, ex_t_rnd, risk_response[0]["risk_key"], gpt_model)
|
| 56 |
res_dict = {
|
| 57 |
'title':title_response[0]['title'],
|
| 58 |
'summary':summary_response[0]['summary'],
|
| 59 |
'alert':alert_response[0]['alert'],
|
| 60 |
'news':text,
|
| 61 |
+
'risk_key':risk_response[0]['risk_key'],
|
| 62 |
+
'reason':risk_response[0]['reason'],
|
| 63 |
+
'company_risk':json.dumps(com_response[0],ensure_ascii=False)
|
| 64 |
}
|
| 65 |
# save
|
| 66 |
|
| 67 |
+
progress(0.85, desc="check")
|
| 68 |
translate_response = translate(res_dict, gpt_model)
|
| 69 |
progress(0.90, desc="over")
|
| 70 |
+
res_msg = prompt_dict["report_msg"].format(
|
| 71 |
title=translate_response[0]['title'],
|
| 72 |
summary=translate_response[0]['summary'],
|
| 73 |
alert=translate_response[0]['alert'],
|
| 74 |
news=translate_response[0]['news'],
|
| 75 |
risk=translate_response[0]['risk_key'],
|
| 76 |
+
reason=translate_response[0]['reason'],
|
| 77 |
+
company_risk=translate_response[0]['company_risk']
|
| 78 |
)
|
| 79 |
print(translate_response[0])
|
| 80 |
+
completion_tokens_num = [i[1] for i in [com_response,risk_response,title_response,summary_response,alert_response,translate_response]]
|
| 81 |
+
prompt_tokens_num = [i[2] for i in [com_response,risk_response,title_response,summary_response,alert_response,translate_response]]
|
| 82 |
print("completion_tokens_num:",completion_tokens_num)
|
| 83 |
print("prompt_tokens_num:",prompt_tokens_num)
|
| 84 |
print("*"*20)
|
| 85 |
return res_msg
|
| 86 |
|
| 87 |
+
def example_f(input,choice,risk,info):
|
| 88 |
+
prompt_dict = load_dict()
|
| 89 |
+
if input == prompt_dict["risk_ex_t"]['ex1']['news']:
|
| 90 |
+
res = prompt_dict["risk_ex_t"]['ex1']
|
| 91 |
+
elif input == prompt_dict["risk_ex_t"]['ex2']['news']:
|
| 92 |
+
res = prompt_dict["risk_ex_t"]['ex2']
|
| 93 |
+
elif input == prompt_dict["risk_ex_t"]['ex3']['news']:
|
| 94 |
+
res = prompt_dict["risk_ex_t"]['ex3']
|
| 95 |
else:
|
| 96 |
print("error")
|
| 97 |
|
| 98 |
+
res_msg = prompt_dict["report_msg"].format(
|
| 99 |
title=json.loads(res['title'])['title'],
|
| 100 |
summary=json.loads(res['summary'])['summary'],
|
| 101 |
alert=json.loads(res['alert'])['alert'],
|
| 102 |
news=res['news'],
|
| 103 |
risk=json.loads(res['risk'])['risk_key'],
|
| 104 |
+
reason=json.loads(res['risk'])['reason'],
|
| 105 |
+
company_risk = res['risk_list']
|
| 106 |
)
|
| 107 |
return res_msg
|
| 108 |
|
| 109 |
with gr.Blocks(title="アラート生成demo", theme="bethecloud/storj_theme") as demo:
|
| 110 |
gr.Markdown("# アラート生成demo")
|
| 111 |
gr.Markdown("gptを通じてアラートメッセージを生成する")
|
| 112 |
+
# get prompt dict
|
| 113 |
+
prompt_dict = load_dict()
|
| 114 |
with gr.Row():
|
| 115 |
with gr.Column():
|
| 116 |
choice = gr.Radio(choices = ["GPT3.5", "GPT4"], value="GPT3.5",label = "GPTモデル")
|
| 117 |
input = gr.Textbox(label="INPUT",lines=7)
|
| 118 |
+
risk_dict = gr.Textbox(label="リスクリスト",lines=10,
|
| 119 |
+
value=prompt_dict["risk_dict"])
|
| 120 |
+
company_info = gr.Textbox(label="会社情報",lines=10)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
with gr.Column():
|
| 124 |
gr.Markdown("OUTPUT")
|
| 125 |
output = gr.Markdown(label="report")
|
| 126 |
|
| 127 |
gen_btn = gr.Button("生成")
|
| 128 |
+
gr.ClearButton([input,output,company_info],value="クリア")
|
| 129 |
gr.Examples(
|
| 130 |
+
examples = [[prompt_dict["risk_ex_t"]['ex1']['news'],"GPT3.5",prompt_dict["company_risk_list"],prompt_dict["risk_ex_t"]['ex1']['company_info']],
|
| 131 |
+
[prompt_dict["risk_ex_t"]['ex2']['news'],"GPT3.5",prompt_dict["company_risk_list"],prompt_dict["risk_ex_t"]['ex2']['company_info']],
|
| 132 |
+
[prompt_dict["risk_ex_t"]['ex3']['news'],"GPT3.5",prompt_dict["company_risk_list"],prompt_dict["risk_ex_t"]['ex3']['company_info']]],
|
| 133 |
+
inputs = [input,choice,risk_dict,company_info],
|
| 134 |
outputs = [output],
|
| 135 |
fn=example_f,
|
| 136 |
cache_examples = True
|
| 137 |
)
|
| 138 |
|
| 139 |
+
gen_btn.click(fn=gen_report, inputs=[input,choice,risk_dict,company_info], outputs=output)
|
| 140 |
+
demo.launch(inline=False, share=True, debug=True)
|
| 141 |
+
# demo.launch()
|
prompt_dict.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:30cce426f24138da77a0b4f25fc050c0cc12e54b1b260d7f356014bf94af53e5
|
| 3 |
+
size 15583
|
prompts.py
CHANGED
|
@@ -10,84 +10,165 @@ risk_list ="""
|
|
| 10 |
"投資活動":"投資活動の失敗による損失など",
|
| 11 |
"""
|
| 12 |
|
|
|
|
|
|
|
| 13 |
# risk list ex
|
| 14 |
risk_ex_t = {
|
| 15 |
"ex1":{
|
| 16 |
"news":"台風7号はきょう11日午前3時、「強い」台風から、「非常に強い」勢力に変わりました。きょう11日の夕方にかけて小笠原諸島に最接近し、小笠原諸島は大荒れの天気でしょう。14日(月)には勢力は一つランクを下げるものの、「強い」勢力で暴風域を伴って本州に接近し、15日(火)頃から16日(水)にかけて東日本や西日本にかなり接近、上陸する恐れがあります。",
|
|
|
|
|
|
|
| 17 |
"risk":'{"ja": "yes", "risk": "yes", "risk_key":"自然災害","reason":"台風7号はきょう11日午前3時、「強い」台風から、「非常に強い」勢力に変わりました。"}',
|
| 18 |
-
"title":'{"title":"[自然災害]台風7
|
| 19 |
"summary":'{"summary":"台風7号はきょう11日午前3時、「強い」台風から、「非常に強い」勢力に変わりました。15日(火)頃から16日(水)にかけて東日本や西日本にかなり接近、上陸する恐れがあります。"}',
|
| 20 |
-
"alert":'{"alert":"!!台風7
|
| 21 |
},
|
| 22 |
"ex2":{
|
| 23 |
"news":"JetBrainsが提供するCI/CDツール「TeamCity」に深刻な脆弱性「CVE-2024-23917」が明らかとなった。悪用されるとリモートよりコードを実行されるおそれがある。同製品に認証回避の脆弱性「CVE-2024-23917」が明らかとなったもの。HTTP経由でアクセスできる場合、認証をバイパスして「TeamCityサーバ」の管理を行うことが可能となり、リモートよりコードを実行されるおそれがある。",
|
|
|
|
|
|
|
| 24 |
"risk":'{"ja": "yes", "risk": "yes", "risk_key":"サイバーセキュリティ","reason":"JetBrainsが提供するCI/CDツール「TeamCity」に深刻な脆弱性「CVE-2024-23917」が明らかとなった。"}',
|
| 25 |
-
"title":'{"title":"[サイバーセキュリティ] JetBrainsのCI/CDツール「TeamCity
|
| 26 |
"summary":'{"summary":"JetBrainsのCI/CDツール「TeamCity」に深刻な脆弱性「CVE-2024-23917」が発見されました。 この脆弱性を悪用すると、リモートからコードが実行される危険性があります。"}',
|
| 27 |
-
"alert":'{"alert":"!!重要!!JetBrainsのCI/CDツール「TeamCity」に深刻な脆弱性「CVE-2024-23917
|
| 28 |
|
| 29 |
},
|
| 30 |
"ex3":{
|
| 31 |
"news":"2024年1月1日16時10分頃、石川県能登地方を震源とするマグニチュード7.6(最大震度7)の地震が発生しました。 被災された方々には謹んでお見舞い申し上げます。 本地震における本投資法人の保有物件所在地の最大震度は4であり、現在のところ人的被害や運用状況に重要な影響を及ぼす被害等は確認されておりません。",
|
|
|
|
|
|
|
| 32 |
"risk":'{"ja": "yes", "risk": "yes", "risk_key":"自然災害","reason":"2024年1月1日16時10分頃、石川県能登地方を震源とするマグニチュード7.6(最大震度7)の地震が発生しました。"}',
|
| 33 |
-
"title":'{"title":"[自然災害]
|
| 34 |
"summary":'{"summary":"2024年1月1日16時10分頃、石川県能登地方を震源とするマグニチュード7.6(最大震度7)の地震が発生しました。保有物件の最大震度は4で、本地震における本投資法人の保有物件所在地の最大震度は4であり、現在のところ人的被害や運用状況に重要な影響を及ぼす被害等は確認されておりません。"}',
|
| 35 |
-
"alert":'{"alert":"!!石川県能登地方で発生したM7.6の地震、最大震度7
|
| 36 |
}
|
| 37 |
}
|
| 38 |
risk_ex_f = {
|
| 39 |
"ex1":{
|
| 40 |
"news":"花巻東高(岩手)で通算140本塁打を放った佐々木麟太郎内野手が、米スタンフォード大学へ進学することが決まった。同大学が公式ホームページで発表した。",
|
|
|
|
|
|
|
| 41 |
"risk":'{"ja": "yes", "risk": "no", "risk_key":"","reason":""}'
|
| 42 |
},
|
| 43 |
"ex2":{
|
| 44 |
"news":"「ももいろクローバーZ」百田夏菜子(29)が14日、東京・渋谷で行われた「カラダうごかせ!ニッポン!」プロジェクト発足記者発表会に登場。「KinKi Kids」堂本剛(44)と結婚発表後、初めての公の場で、左手に指輪はしていなかったが、幸せいっぱいの笑顔を見せた。",
|
|
|
|
|
|
|
| 45 |
"risk":'{"ja": "yes", "risk": "no", "risk_key":"","reason":""}'
|
| 46 |
},
|
| 47 |
}
|
| 48 |
|
| 49 |
# prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
## risk list
|
| 51 |
risk_sys_msg = """
|
| 52 |
You are a helpful business analyst expert designed to \
|
| 53 |
provide me with the information on risks appearing in the news, formatted in JSON.
|
| 54 |
"""
|
| 55 |
-
|
| 56 |
-
Enter the news and risks that
|
| 57 |
Determine whether there is risk information in the news. \
|
| 58 |
If there is, output yes, the risk information contained, \
|
| 59 |
-
and the original text basis that can be judged. \
|
| 60 |
If there is no, only output no.
|
| 61 |
Determine if the news is written in Japanese. Output the results in JSON format. \
|
| 62 |
like {{'ja': determine if the news is written in Japanese ,'risk': Is there any risk , 'risk_key': Risk type ,'reason': The basis of the original text}} \
|
| 63 |
Think about it a few more steps \n\n \
|
| 64 |
news: {n1} \n
|
| 65 |
-
|
|
|
|
| 66 |
output:{o1} \n\n
|
| 67 |
news: {n2} \n
|
| 68 |
-
|
|
|
|
| 69 |
output:{o2} \n\n
|
| 70 |
news: {n3} \n
|
| 71 |
-
|
|
|
|
| 72 |
output:{o3} \n\n
|
| 73 |
news: {n4}\n
|
| 74 |
-
|
|
|
|
| 75 |
output:
|
| 76 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
## title
|
| 78 |
title_usr_msg = """
|
| 79 |
-
I need a compelling and insightful title for a report based on input news. \
|
| 80 |
The news highlights potential risks or challenges in the {risk} sector. Generate a concise, \
|
| 81 |
attention-grabbing title that encapsulates the essence of the risks discussed in the news article. \
|
| 82 |
-
frame the title to capture the attention of decision-makers. Output the results in JSON format. \
|
| 83 |
like {{'title':generated title}} \
|
| 84 |
Think about it a few more steps \n\n \
|
|
|
|
|
|
|
| 85 |
news: {n1} \n
|
|
|
|
| 86 |
output:{o1} \n\n
|
| 87 |
news: {n2} \n
|
|
|
|
| 88 |
output:{o2} \n\n
|
|
|
|
|
|
|
|
|
|
| 89 |
news: {n3} \n
|
|
|
|
| 90 |
output:
|
|
|
|
| 91 |
"""
|
| 92 |
## sum
|
| 93 |
summary_usr_msg ="""
|
|
@@ -96,27 +177,41 @@ Please craft a brief summary that highlights potential risks associated with the
|
|
| 96 |
Output the results in JSON format. \
|
| 97 |
like {{'summary':generated summary}} \
|
| 98 |
Think about it a few more steps \n\n \
|
|
|
|
|
|
|
| 99 |
news: {n1} \n
|
| 100 |
output:{o1} \n\n
|
| 101 |
news: {n2} \n
|
| 102 |
output:{o2} \n\n
|
|
|
|
|
|
|
|
|
|
| 103 |
news: {n3} \n
|
| 104 |
output:
|
| 105 |
"""
|
| 106 |
## alert msg
|
| 107 |
alert_usr_msg ="""
|
| 108 |
-
I need assistance in creating an alert message based on the risk-related content of the entered news. \
|
| 109 |
-
As a risk analyst, guide me in generating a concise and informative alert message summarizing the potential {risk} risk highlighted in the news. \
|
| 110 |
This alert is crucial for making timely decisions and assessing the impact of the information. \
|
| 111 |
Output the results in JSON format.\
|
| 112 |
like {{'alert':generated alert message}} \
|
| 113 |
Think about it a few more steps \n\n \
|
|
|
|
|
|
|
| 114 |
news: {n1} \n
|
|
|
|
| 115 |
output:{o1} \n\n
|
| 116 |
news: {n2} \n
|
|
|
|
| 117 |
output:{o2} \n\n
|
|
|
|
|
|
|
|
|
|
| 118 |
news: {n3} \n
|
|
|
|
| 119 |
output:
|
|
|
|
| 120 |
"""
|
| 121 |
## report
|
| 122 |
report_msg = """
|
|
@@ -138,6 +233,9 @@ report_msg = """
|
|
| 138 |
|
| 139 |
#### [根拠]
|
| 140 |
{reason}
|
|
|
|
|
|
|
|
|
|
| 141 |
"""
|
| 142 |
## japanese
|
| 143 |
translate_sys_msg = """
|
|
@@ -151,7 +249,7 @@ Do not translate proper nouns. \
|
|
| 151 |
If text is Japanese, return unchanged. \
|
| 152 |
Ensure the correctness of grammar and vocabulary. \
|
| 153 |
Output the results in JSON format.
|
| 154 |
-
like {{'title':translated title,'summary':translated summary,'alert':translated alert,'news':translated news,'risk_key':translated risk_key,'reason':translated reason}}
|
| 155 |
input: {dictionary}
|
| 156 |
output:
|
| 157 |
"""
|
|
@@ -161,4 +259,35 @@ news1 = "14日午後6時33分ごろ、鹿児島市の桜島・南岳山頂火口
|
|
| 161 |
news2 = "岸田首相(自民党総裁)は14日午前の衆院予算委員会集中審議で、自民党派閥の政治資金規正法違反事件を受け、規正法違反で会計責任者が逮捕・起訴された場合に議員本人も処分できるよう党則を改正する考えを明らかにした。3月17日の党大会で決定する意向だ。"
|
| 162 |
news3 = "楽天グループの去年1年間の連結決算は3394億円の最終赤字になりました。赤字額は過去最大だったおととしより縮小したものの、赤字は5年連続で、その大きな要因となっているのがモバイル事業です。これまで、携帯電話の基地局建設には1兆円以上を投じていますが、その一方で、去年12月時点での契約者数は609万件と大手3社の10分の1以下です。また、基地局建設にあたって発行した社債、いわゆる借金の返済額は今年と来年の2年間でおよそ8000億円に上りますが、三木谷社長は「資金繰りは心配ない」と強調しました。"
|
| 163 |
news4 = "LINEヤフーは14日、新たに従業員などの個人情報13万件以上が流出した可能性があると発表した。LINEヤフーは2023年11月に大株主である韓国ネット大手・NAVERがサイバー攻撃を受けたことでLINE利用者の個人情報44万件が不正アクセスを受けた可能性があると発表していた。追加調査の結果、NAVERのサーバー経由で従業員などの氏名や顔写真など、個人情報が追加で約8万件、また、他の委託先経由で従業員などの個人データが6万件近く、あわせて13万件以上が流出した可能性が確認された。"
|
| 164 |
-
news5 = "韓国人俳優のマ・ドンソクが14日、都内で行われた主演映画『犯罪都市 NO WAY OUT』(2月23日公開)のジャパンプレミアにイ・サンヨン監督、青木崇高、國村隼とともに出席。初の公式来日を果たした。"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
"投資活動":"投資活動の失敗による損失など",
|
| 11 |
"""
|
| 12 |
|
| 13 |
+
company_risk_list = risk_list
|
| 14 |
+
|
| 15 |
# risk list ex
|
| 16 |
risk_ex_t = {
|
| 17 |
"ex1":{
|
| 18 |
"news":"台風7号はきょう11日午前3時、「強い」台風から、「非常に強い」勢力に変わりました。きょう11日の夕方にかけて小笠原諸島に最接近し、小笠原諸島は大荒れの天気でしょう。14日(月)には勢力は一つランクを下げるものの、「強い」勢力で暴風域を伴って本州に接近し、15日(火)頃から16日(水)にかけて東日本や西日本にかなり接近、上陸する恐れがあります。",
|
| 19 |
+
"company_info":"株式会社ブルーオーシャンフーズ\n\n事業内容:\nブルーオーシャンフーズは、持続可能な海洋資源を利用した健康食品の開発・販売を行っています。特に、高品質な海藻類を使用した商品が高い評価を受けています。\n\n市場情報:\n健康志向と環境保護意識の高まりにより、持続可能な食品市場が拡大しています。ブルーオーシャンフーズは、このトレンドに乗じて市場シェアを拡大しています。\n\nビジネス展開:\n国内販売に加え、アジア圏への輸出を強化しています。2024年度には、新たな健康食品のラインナップを市場に投入する予定です。",
|
| 20 |
+
"risk_list":'{"自然災害":"持続可能な海洋資源を利用した健康食品の開発・販売を行っているため、地震、洪水、台風、異常気象による海洋資源への被害がリスクとなる。","感染症":"国内販売及びアジア圏への輸出を強化しているため、新型ウイルスのパンデミックが業務やサプライチェーンに影響を与えるリスクがある。","環境問題":"持続可能な海洋資源を利用している企業であり、環境保護意識の高まりの中で工場排水の不適切な処理などが発覚すると企業イメージに損害を与える可能性がある。","調達価格":"高品質な海藻類などの原材料を使用しているため、原材料価格の高騰がコスト増加につながり、収益性に影響を与えるリスクがある。"}',
|
| 21 |
"risk":'{"ja": "yes", "risk": "yes", "risk_key":"自然災害","reason":"台風7号はきょう11日午前3時、「強い」台風から、「非常に強い」勢力に変わりました。"}',
|
| 22 |
+
"title":'{"title":"[自然災害]台風7号接近、持続可能な海洋資源企業への影響、ご確認お願い致します。"}',
|
| 23 |
"summary":'{"summary":"台風7号はきょう11日午前3時、「強い」台風から、「非常に強い」勢力に変わりました。15日(火)頃から16日(水)にかけて東日本や西日本にかなり接近、上陸する恐れがあります。"}',
|
| 24 |
+
"alert":'{"alert":"!!台風7号接近、非常に悪天候、潜在的な被害、および混乱の高いリスク。海洋資源の確保と物流に影響が出る恐れがあります。企業は、暴風域の影響を受ける前に、対策を講じる必要があります。!!"}'
|
| 25 |
},
|
| 26 |
"ex2":{
|
| 27 |
"news":"JetBrainsが提供するCI/CDツール「TeamCity」に深刻な脆弱性「CVE-2024-23917」が明らかとなった。悪用されるとリモートよりコードを実行されるおそれがある。同製品に認証回避の脆弱性「CVE-2024-23917」が明らかとなったもの。HTTP経由でアクセスできる場合、認証をバイパスして「TeamCityサーバ」の管理を行うことが可能となり、リモートよりコードを実行されるおそれがある。",
|
| 28 |
+
"company_info":"株式会社サクラテクノロジー\n\n事業内容:\nサクラテクノロジーは、最先端のAI技術を活用して、製造業向けの自動化ソリューションを提供しています。特に、ロボティクスとデータ分析を組み合わせた製品で市場をリードしています。\n\n市場情報:\n製造業の自動化ニーズの増加に伴い、サクラテクノロジーの市場は年平均15%の成長が見込まれています。特に、自動車および電子機器製造業界からの強い需要があります。\n\nビジネス展開:\n国内市場に加えて、北米とヨーロッパ市場への進出を計画しており、2025年までに全世界での事業展開を目指しています。また、新しいAI技術の研究開発にも力を入れており、次世代製品の開発に注力しています。",
|
| 29 |
+
"risk_list":'{"サイバーセキュリティ": "最先端のAI技術を活用しているため、サイバー攻撃やデータ漏洩のリスクがある。","不正会計": "拡大する事業規模と複雑化する経営状況における粉飾決算や横領などの財務不正リスク。","投資活動": "新しいAI技術の研究開発に力を入れており、次世代製品の開発に注力していることから、投資活動の失敗による損失が発生するリスクがある。"}',
|
| 30 |
"risk":'{"ja": "yes", "risk": "yes", "risk_key":"サイバーセキュリティ","reason":"JetBrainsが提供するCI/CDツール「TeamCity」に深刻な脆弱性「CVE-2024-23917」が明らかとなった。"}',
|
| 31 |
+
"title":'{"title":"[サイバーセキュリティ] JetBrainsのCI/CDツール「TeamCity」に深刻な脆弱性発覚、サクラテクノロジーの製造自動化への影響"}',
|
| 32 |
"summary":'{"summary":"JetBrainsのCI/CDツール「TeamCity」に深刻な脆弱性「CVE-2024-23917」が発見されました。 この脆弱性を悪用すると、リモートからコードが実行される危険性があります。"}',
|
| 33 |
+
"alert":'{"alert":"!!重要!!JetBrainsのCI/CDツール「TeamCity」に深刻な脆弱性「CVE-2024-23917」が発見されました。このツールを使用している場合、直ちに対策を講じる必要があります。これは、同社のAIと自動化ソリューションの安全性および信頼性に直接的な影響を及ぼす可能性があります。!!"}'
|
| 34 |
|
| 35 |
},
|
| 36 |
"ex3":{
|
| 37 |
"news":"2024年1月1日16時10分頃、石川県能登地方を震源とするマグニチュード7.6(最大震度7)の地震が発生しました。 被災された方々には謹んでお見舞い申し上げます。 本地震における本投資法人の保有物件所在地の最大震度は4であり、現在のところ人的被害や運用状況に重要な影響を及ぼす被害等は確認されておりません。",
|
| 38 |
+
"company_info":"株式会社ブルーオーシャンフーズ\n\n事業内容:\nブルーオーシャンフーズは、持続可能な海洋資源を利用した健康食品の開発・販売を行っています。特に、高品質な海藻類を使用した商品が高い評価を受けています。\n\n市場情報:\n健康志向と環境保護意識の高まりにより、持続可能な食品市場が拡大しています。ブルーオーシャンフーズは、このトレンドに乗じて市場シェアを拡大しています。\n\nビジネス展開:\n国内販売に加え、アジア圏への輸出を強化しています。2024年度には、新たな健康食品のラインナップを市場に投入する予定です。",
|
| 39 |
+
"risk_list":'{"自然災害":"持続可能な海洋資源を利用した健康食品の開発・販売を行っているため、地震、洪水、台風、異常気象による海洋資源への被害がリスクとなる。","感染症":"国内販売及びアジア圏への輸出を強化しているため、新型ウイルスのパンデミックが業務やサプライチェーンに影響を与えるリスクがある。","環境問題":"持続可能な海洋資源を利用している企業であり、環境保護意識の高まりの中で工場排水の不適切な処理などが発覚すると企業イメージに損害を与える可能性がある。","調達価格":"高品質な海藻類などの原材料を使用しているため、原材料価格の高騰がコスト増加につながり、収益性に影響を与えるリスクがある。"}',
|
| 40 |
"risk":'{"ja": "yes", "risk": "yes", "risk_key":"自然災害","reason":"2024年1月1日16時10分頃、石川県能登地方を震源とするマグニチュード7.6(最大震度7)の地震が発生しました。"}',
|
| 41 |
+
"title":'{"title":"[自然災害]震度4の警鐘:持続可能な食品市場における災害リスク"}',
|
| 42 |
"summary":'{"summary":"2024年1月1日16時10分頃、石川県能登地方を震源とするマグニチュード7.6(最大震度7)の地震が発生しました。保有物件の最大震度は4で、本地震における本投資法人の保有物件所在地の最大震度は4であり、現在のところ人的被害や運用状況に重要な影響を及ぼす被害等は確認されておりません。"}',
|
| 43 |
+
"alert":'{"alert":"!!石川県能登地方で発生したM7.6の地震、最大震度7。事業活動への直接的な影響は現時点で報告されていませんが、地震が持続可能な海洋資源へ及ぼす可能性のある影響に注意が必要です。震度4の揺れが報告された地域に保有物件が存在するため、引き続き状況を注視し、必要に応じた措置を講じることを推奨します。"}'
|
| 44 |
}
|
| 45 |
}
|
| 46 |
risk_ex_f = {
|
| 47 |
"ex1":{
|
| 48 |
"news":"花巻東高(岩手)で通算140本塁打を放った佐々木麟太郎内野手が、米スタンフォード大学へ進学することが決まった。同大学が公式ホームページで発表した。",
|
| 49 |
+
"company_info":"株式会社ブルーオーシャンフーズ \n 事業内容: \n ブルーオーシャンフーズは、持続可能な海洋資源を利用した健康食品の開発・販売を行っています。特に、高品質な海藻類を使用した商品が高い評価を受けています。 \n 市場情報: \n 健康志向と環境保護意識の高まりにより、持続可能な食品市場が拡大しています。ブルーオーシャンフーズは、このトレンドに乗じて市場シェアを拡大しています。 \n ビジネス展開: \n 国内販売に加え、アジア圏への輸出を強化しています。2024年度には、新たな健康食品のラインナップを市場に投入する予定です。",
|
| 50 |
+
"risk_list":'{"自然災害":"持続可能な海洋資源を利用した健康食品の開発・販売を行っているため、地震、洪水、台風、異常気象による海洋資源への被害がリスクとなる。","感染症":"国内販売及びアジア圏への輸出を強化しているため、新型ウイルスのパンデミックが業務やサプライチェーンに影響を与えるリスクがある。","環境問題":"持続可能な海洋資源を利用している企業であり、環境保護意識の高まりの中で工場排水の不適切な処理などが発覚すると企業イメージに損害を与える可能性がある。","調達価格":"高品質な海藻類などの原材料を使用しているため、原材料価格の高騰がコスト増加につながり、収益性に影響を与えるリスクがある。"}',
|
| 51 |
"risk":'{"ja": "yes", "risk": "no", "risk_key":"","reason":""}'
|
| 52 |
},
|
| 53 |
"ex2":{
|
| 54 |
"news":"「ももいろクローバーZ」百田夏菜子(29)が14日、東京・渋谷で行われた「カラダうごかせ!ニッポン!」プロジェクト発足記者発表会に登場。「KinKi Kids」堂本剛(44)と結婚発表後、初めての公の場で、左手に指輪はしていなかったが、幸せいっぱいの笑顔を見せた。",
|
| 55 |
+
"company_info":"株式会社サクラテクノロジー \n 事業内容: サクラテクノロジーは、最先端のAI技術を活用して、製造業向けの自動化ソリューションを提供しています。特に、ロボティクスとデータ分析を組み合わせた製品で市場をリードしています。 \n 市場情報: \n 製造業の自動化ニーズの増加に伴い、サクラテクノロジーの市場は年平均15%の成長が見込まれています。特に、自動車および電子機器製造業界からの強い需要があります。 \n ビジネス展開: \n 国内市場に加えて、北米とヨーロッパ市場への進出を計画しており、2025年までに全世界での事業展開を目指しています。また、新しいAI技術の研究開発にも力を入れており、次世代製品の開発に注力しています。",
|
| 56 |
+
"risk_list":'{"サイバーセキュリティ": "最先端のAI技術を活用しているため、サイバー攻撃やデータ漏洩のリスクがある。","不正会計": "拡大する事業規模と複雑化する経営状況における粉飾決算や横領などの財務不正リスク。","投資活動": "新しいAI技術の研究開発に力を入れており、次世代製品の開発に注力していることから、投資活動の失敗による損失が発生するリスクがある。"}',
|
| 57 |
"risk":'{"ja": "yes", "risk": "no", "risk_key":"","reason":""}'
|
| 58 |
},
|
| 59 |
}
|
| 60 |
|
| 61 |
# prompt
|
| 62 |
+
## company
|
| 63 |
+
com_sys_msg = """
|
| 64 |
+
You are a helpful business analyst expert designed to \
|
| 65 |
+
provide me with the information on risks appearing in the company information and the risk list, \
|
| 66 |
+
formatted in JSON.
|
| 67 |
+
"""
|
| 68 |
+
com_usr_msg = """
|
| 69 |
+
Based on the entered company information and the risks provided, \
|
| 70 |
+
I want you to select the risks that may occur in the risk list for the entered company. \
|
| 71 |
+
This risks should include, but not be limited to, financial, operational, market, and compliance risks associated with the company's specific industry, size, and geographic location. \
|
| 72 |
+
Find the original text on which the risk was judged. Output the results in JSON format.
|
| 73 |
+
like {{"risk1" : "reason1","risk2":"reason2"}}
|
| 74 |
+
Think about it a few more steps \n\n
|
| 75 |
+
example:
|
| 76 |
+
***
|
| 77 |
+
company_information: {c1} \n
|
| 78 |
+
risk_list: {r1} \n
|
| 79 |
+
output: {o1} \n\n
|
| 80 |
+
***
|
| 81 |
+
question:
|
| 82 |
+
***
|
| 83 |
+
company_information: {c2} \n
|
| 84 |
+
risk_list: {r2} \n
|
| 85 |
+
output:
|
| 86 |
+
***
|
| 87 |
+
"""
|
| 88 |
## risk list
|
| 89 |
risk_sys_msg = """
|
| 90 |
You are a helpful business analyst expert designed to \
|
| 91 |
provide me with the information on risks appearing in the news, formatted in JSON.
|
| 92 |
"""
|
| 93 |
+
risk_usr_msg_old ="""
|
| 94 |
+
Enter the news and risks company information that company can refer to. \
|
| 95 |
Determine whether there is risk information in the news. \
|
| 96 |
If there is, output yes, the risk information contained, \
|
| 97 |
+
and the original news text basis that can be judged. \
|
| 98 |
If there is no, only output no.
|
| 99 |
Determine if the news is written in Japanese. Output the results in JSON format. \
|
| 100 |
like {{'ja': determine if the news is written in Japanese ,'risk': Is there any risk , 'risk_key': Risk type ,'reason': The basis of the original text}} \
|
| 101 |
Think about it a few more steps \n\n \
|
| 102 |
news: {n1} \n
|
| 103 |
+
company_information: {c1} \n
|
| 104 |
+
risk_list:{r1}\n
|
| 105 |
output:{o1} \n\n
|
| 106 |
news: {n2} \n
|
| 107 |
+
company_information: {c2} \n
|
| 108 |
+
risk_list:{r2}\n
|
| 109 |
output:{o2} \n\n
|
| 110 |
news: {n3} \n
|
| 111 |
+
company_information: {c3} \n
|
| 112 |
+
risk_list:{r3}\n
|
| 113 |
output:{o3} \n\n
|
| 114 |
news: {n4}\n
|
| 115 |
+
company_information: {c4} \n
|
| 116 |
+
risk_list:{r4}\n
|
| 117 |
output:
|
| 118 |
"""
|
| 119 |
+
|
| 120 |
+
risk_usr_msg ="""
|
| 121 |
+
Enter the news and risks company information that company can refer to. \
|
| 122 |
+
Determine whether there is risk information in the news. \
|
| 123 |
+
If there is, output yes, the risk information contained, \
|
| 124 |
+
and the original news text basis that can be judged. \
|
| 125 |
+
If there is no, only output no.
|
| 126 |
+
Determine if the news is written in Japanese. Output the results in JSON format. \
|
| 127 |
+
like {{'ja': determine if the news is written in Japanese ,'risk': Is there any risk , 'risk_key': Risk type ,'reason': The basis of the original text}} \
|
| 128 |
+
Think about it a few more steps \n\n \
|
| 129 |
+
example:
|
| 130 |
+
***
|
| 131 |
+
news: {n1} \n
|
| 132 |
+
company_information: {c1} \n
|
| 133 |
+
risk_list:{r1}\n
|
| 134 |
+
output:{o1} \n\n
|
| 135 |
+
news: {n3} \n
|
| 136 |
+
company_information: {c3} \n
|
| 137 |
+
risk_list:{r3}\n
|
| 138 |
+
output:{o3} \n\n
|
| 139 |
+
***
|
| 140 |
+
question:
|
| 141 |
+
***
|
| 142 |
+
news: {n4}\n
|
| 143 |
+
company_information: {c4} \n
|
| 144 |
+
risk_list:{r4}\n
|
| 145 |
+
output:
|
| 146 |
+
***
|
| 147 |
+
"""
|
| 148 |
+
|
| 149 |
## title
|
| 150 |
title_usr_msg = """
|
| 151 |
+
I need a compelling and insightful title for a report based on input news and company information. \
|
| 152 |
The news highlights potential risks or challenges in the {risk} sector. Generate a concise, \
|
| 153 |
attention-grabbing title that encapsulates the essence of the risks discussed in the news article. \
|
| 154 |
+
frame the title to capture the attention of company decision-makers. Output the results in JSON format. \
|
| 155 |
like {{'title':generated title}} \
|
| 156 |
Think about it a few more steps \n\n \
|
| 157 |
+
example:
|
| 158 |
+
***
|
| 159 |
news: {n1} \n
|
| 160 |
+
company_information: {c1} \n
|
| 161 |
output:{o1} \n\n
|
| 162 |
news: {n2} \n
|
| 163 |
+
company_information: {c2} \n
|
| 164 |
output:{o2} \n\n
|
| 165 |
+
***
|
| 166 |
+
question:
|
| 167 |
+
***
|
| 168 |
news: {n3} \n
|
| 169 |
+
company_information: {c3} \n
|
| 170 |
output:
|
| 171 |
+
***
|
| 172 |
"""
|
| 173 |
## sum
|
| 174 |
summary_usr_msg ="""
|
|
|
|
| 177 |
Output the results in JSON format. \
|
| 178 |
like {{'summary':generated summary}} \
|
| 179 |
Think about it a few more steps \n\n \
|
| 180 |
+
example:
|
| 181 |
+
***
|
| 182 |
news: {n1} \n
|
| 183 |
output:{o1} \n\n
|
| 184 |
news: {n2} \n
|
| 185 |
output:{o2} \n\n
|
| 186 |
+
***
|
| 187 |
+
question:
|
| 188 |
+
***
|
| 189 |
news: {n3} \n
|
| 190 |
output:
|
| 191 |
"""
|
| 192 |
## alert msg
|
| 193 |
alert_usr_msg ="""
|
| 194 |
+
I need assistance in creating an alert message based on the risk-related content of the entered news and company information. \
|
| 195 |
+
As a risk analyst, guide me in generating a concise and informative alert message summarizing the potential {risk} risk highlighted for company in the news. \
|
| 196 |
This alert is crucial for making timely decisions and assessing the impact of the information. \
|
| 197 |
Output the results in JSON format.\
|
| 198 |
like {{'alert':generated alert message}} \
|
| 199 |
Think about it a few more steps \n\n \
|
| 200 |
+
example:
|
| 201 |
+
***
|
| 202 |
news: {n1} \n
|
| 203 |
+
company_information: {c1} \n
|
| 204 |
output:{o1} \n\n
|
| 205 |
news: {n2} \n
|
| 206 |
+
company_information: {c2} \n
|
| 207 |
output:{o2} \n\n
|
| 208 |
+
***
|
| 209 |
+
question:
|
| 210 |
+
***
|
| 211 |
news: {n3} \n
|
| 212 |
+
company_information: {c3} \n
|
| 213 |
output:
|
| 214 |
+
***
|
| 215 |
"""
|
| 216 |
## report
|
| 217 |
report_msg = """
|
|
|
|
| 233 |
|
| 234 |
#### [根拠]
|
| 235 |
{reason}
|
| 236 |
+
|
| 237 |
+
### [会社リスク]
|
| 238 |
+
{company_risk}
|
| 239 |
"""
|
| 240 |
## japanese
|
| 241 |
translate_sys_msg = """
|
|
|
|
| 249 |
If text is Japanese, return unchanged. \
|
| 250 |
Ensure the correctness of grammar and vocabulary. \
|
| 251 |
Output the results in JSON format.
|
| 252 |
+
like {{'title':translated title,'summary':translated summary,'alert':translated alert,'news':translated news,'risk_key':translated risk_key,'reason':translated reason,'company_risk':translated company_risk}}
|
| 253 |
input: {dictionary}
|
| 254 |
output:
|
| 255 |
"""
|
|
|
|
| 259 |
news2 = "岸田首相(自民党総裁)は14日午前の衆院予算委員会集中審議で、自民党派閥の政治資金規正法違反事件を受け、規正法違反で会計責任者が逮捕・起訴された場合に議員本人も処分できるよう党則を改正する考えを明らかにした。3月17日の党大会で決定する意向だ。"
|
| 260 |
news3 = "楽天グループの去年1年間の連結決算は3394億円の最終赤字になりました。赤字額は過去最大だったおととしより縮小したものの、赤字は5年連続で、その大きな要因となっているのがモバイル事業です。これまで、携帯電話の基地局建設には1兆円以上を投じていますが、その一方で、去年12月時点での契約者数は609万件と大手3社の10分の1以下です。また、基地局建設にあたって発行した社債、いわゆる借金の返済額は今年と来年の2年間でおよそ8000億円に上りますが、三木谷社長は「資金繰りは心配ない」と強調しました。"
|
| 261 |
news4 = "LINEヤフーは14日、新たに従業員などの個人情報13万件以上が流出した可能性があると発表した。LINEヤフーは2023年11月に大株主である韓国ネット大手・NAVERがサイバー攻撃を受けたことでLINE利用者の個人情報44万件が不正アクセスを受けた可能性があると発表していた。追加調査の結果、NAVERのサーバー経由で従業員などの氏名や顔写真など、個人情報が追加で約8万件、また、他の委託先経由で従業員などの個人データが6万件近く、あわせて13万件以上が流出した可能性が確認された。"
|
| 262 |
+
news5 = "韓国人俳優のマ・ドンソクが14日、都内で行われた主演映画『犯罪都市 NO WAY OUT』(2月23日公開)のジャパンプレミアにイ・サンヨン監督、青木崇高、國村隼とともに出席。初の公式来日を果たした。"
|
| 263 |
+
|
| 264 |
+
com1 = "ネクストエナジーソリューション株式会社\n\n事業内容:\n再生可能エネルギーの普及と利用促進を目的として設立されたネクストエナジーソリューションは、太陽光発電や風力発電などの設置・運営を手掛けています。また、エネルギー管理システムの開発にも注力しています。\n\n市場情報:\n再生可能エネルギーへの関心が高まる中、同社の事業領域は急速に成長しています。特に、企業のCO2排出量削減ニーズが事業拡大の大きなドライバーとなっています。\n\nビジネス展開:\n国内市場での成功を基に、東南アジア市場への展開を進めています。また、エネルギー貯蔵技術の研究開発により、新たなビジネスモデルの構築を目指しています。"
|
| 265 |
+
com2 = "アドバンストヘルスケア株式会社\n\n事業内容:\nアドバンストヘルスケアは、医療機器とデジタルヘルスソリューションを融合させた製品を提供しています。特に、在宅医療を支援するデバイスの開発に力を入れています。\n\n市場情報:\n高齢化社会の進展と共に、在宅医療市場は拡大傾向にあります。同社の提供する革新的な製品は、この市場での需要を捉えています。\n\nビジネス展開:\n国内市場での実績を基に、北米およびヨーロッパ市場への進出を計画しています。また、新しい医療技術の研究開発に投資を続け、市場のリーダーとしての地位を確立することを目指しています。"
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
prompt_dict = {
|
| 269 |
+
"risk_dict":risk_list,
|
| 270 |
+
"company_risk_list":company_risk_list,
|
| 271 |
+
"risk_ex_t":risk_ex_t,
|
| 272 |
+
"risk_ex_f":risk_ex_f,
|
| 273 |
+
"com_sys_msg":com_sys_msg,
|
| 274 |
+
"com_usr_msg":com_usr_msg,
|
| 275 |
+
"risk_sys_msg":risk_sys_msg,
|
| 276 |
+
"risk_usr_msg":risk_usr_msg,
|
| 277 |
+
"title_usr_msg":title_usr_msg,
|
| 278 |
+
"summary_usr_msg":summary_usr_msg,
|
| 279 |
+
"alert_usr_msg":alert_usr_msg,
|
| 280 |
+
"report_msg":report_msg,
|
| 281 |
+
"translate_sys_msg":translate_sys_msg,
|
| 282 |
+
"translate_usr_msg":translate_usr_msg,
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
import pickle
|
| 286 |
+
def save_dict(prompt_dict):
|
| 287 |
+
with open('prompt_dict.pkl', 'wb') as fi:
|
| 288 |
+
pickle.dump(prompt_dict,fi)
|
| 289 |
+
|
| 290 |
+
def load_dict():
|
| 291 |
+
with open('prompt_dict.pkl', 'rb') as fi:
|
| 292 |
+
prompt_dict = pickle.load(fi)
|
| 293 |
+
return prompt_dict
|
report.py
CHANGED
|
@@ -1,67 +1,112 @@
|
|
| 1 |
import json
|
| 2 |
-
from prompts import
|
| 3 |
-
from
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
messages = []
|
| 6 |
-
messages.append({"role": "system", "content": risk_sys_msg})
|
| 7 |
-
messages.append({"role": "user", "content": risk_usr_msg.format(
|
| 8 |
-
n1=risk_ex_t[f"ex{ex_t_rnd[0]}"]["news"],
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
o3=risk_ex_f[f"ex{ex_f_rnd[0]}"]["risk"],
|
| 17 |
n4=news_text,
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
return risk_response
|
| 21 |
|
| 22 |
-
def title(news_text, ex_t_rnd, risk, model):
|
| 23 |
messages = []
|
| 24 |
-
messages.append({"role": "system", "content": risk_sys_msg})
|
| 25 |
-
messages.append({"role": "user", "content": title_usr_msg.format(
|
| 26 |
risk=risk,
|
| 27 |
-
n1=risk_ex_t[f"ex{ex_t_rnd[0]}"]["news"],
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
return title_response
|
| 34 |
|
| 35 |
def summary(news_text, ex_t_rnd, model):
|
| 36 |
messages = []
|
| 37 |
-
messages.append({"role": "system", "content": risk_sys_msg})
|
| 38 |
-
messages.append({"role": "user", "content": summary_usr_msg.format(
|
| 39 |
-
n1=risk_ex_t[f"ex{ex_t_rnd[0]}"]["news"],
|
| 40 |
-
o1=risk_ex_t[f"ex{ex_t_rnd[0]}"]["summary"],
|
| 41 |
-
n2=risk_ex_t[f"ex{ex_t_rnd[1]}"]["news"],
|
| 42 |
-
o2=risk_ex_t[f"ex{ex_t_rnd[1]}"]["summary"],
|
| 43 |
n3=news_text)})
|
| 44 |
-
summary_response = chat_completion_request(messages,model=model)
|
| 45 |
return summary_response
|
| 46 |
|
| 47 |
-
def alert(news_text, ex_t_rnd, risk, model):
|
| 48 |
messages = []
|
| 49 |
-
messages.append({"role": "system", "content": risk_sys_msg})
|
| 50 |
-
messages.append({"role": "user", "content": alert_usr_msg.format(
|
| 51 |
risk=risk,
|
| 52 |
-
n1=risk_ex_t[f"ex{ex_t_rnd[0]}"]["news"],
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
return alert_response
|
| 59 |
|
| 60 |
def translate(report_dict,model):
|
| 61 |
messages = []
|
| 62 |
-
messages.append({"role": "system", "content": translate_sys_msg})
|
| 63 |
-
messages.append({"role": "user", "content": translate_usr_msg.format(dictionary=json.dumps(report_dict))})
|
| 64 |
-
translate_response = chat_completion_request(messages,model=model)
|
| 65 |
return translate_response
|
| 66 |
|
| 67 |
|
|
|
|
| 1 |
import json
|
| 2 |
+
from prompts import load_dict
|
| 3 |
+
from request_gpt import chat_completion_request
|
| 4 |
+
prompt_dict = load_dict()
|
| 5 |
+
|
| 6 |
+
show = True
|
| 7 |
+
def company_analysis(ex_t_rnd, risk_dict, company_info, model):
|
| 8 |
+
messages = []
|
| 9 |
+
messages.append({"role": "system", "content": prompt_dict["com_sys_msg"]})
|
| 10 |
+
messages.append({"role": "user", "content": prompt_dict["com_usr_msg"].format(
|
| 11 |
+
c1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["company_info"],
|
| 12 |
+
r1=prompt_dict["company_risk_list"],
|
| 13 |
+
o1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["risk_list"],
|
| 14 |
+
c2=company_info,
|
| 15 |
+
r2=risk_dict
|
| 16 |
+
)})
|
| 17 |
+
com_response = chat_completion_request(messages, model=model, name="com_response", show=show)
|
| 18 |
+
return com_response
|
| 19 |
+
def risk_old(news_text, company_info, com_risk, ex_t_rnd, ex_f_rnd, model):
|
| 20 |
+
messages = []
|
| 21 |
+
messages.append({"role": "system", "content": prompt_dict["risk_sys_msg"]})
|
| 22 |
+
messages.append({"role": "user", "content": prompt_dict["risk_usr_msg"].format(
|
| 23 |
+
n1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["news"],
|
| 24 |
+
c1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["company_info"],
|
| 25 |
+
r1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["risk_list"],
|
| 26 |
+
o1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["risk"],
|
| 27 |
+
n2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["news"],
|
| 28 |
+
c2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["company_info"],
|
| 29 |
+
r2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["risk_list"],
|
| 30 |
+
o2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["risk"],
|
| 31 |
+
n3=prompt_dict["risk_ex_f"][f"ex{ex_f_rnd[0]}"]["news"],
|
| 32 |
+
c3=prompt_dict["risk_ex_f"][f"ex{ex_f_rnd[0]}"]["company_info"],
|
| 33 |
+
r3=prompt_dict["risk_ex_f"][f"ex{ex_f_rnd[0]}"]["risk_list"],
|
| 34 |
+
o3=prompt_dict["risk_ex_f"][f"ex{ex_f_rnd[0]}"]["risk"],
|
| 35 |
+
n4=news_text,
|
| 36 |
+
c4=company_info,
|
| 37 |
+
r4=json.dumps(com_risk,ensure_ascii=False))})
|
| 38 |
+
risk_response = chat_completion_request(messages, model=model,name="risk_response", show=show)
|
| 39 |
+
return risk_response
|
| 40 |
+
|
| 41 |
+
def risk(news_text, company_info, com_risk, ex_t_rnd, ex_f_rnd, model):
|
| 42 |
messages = []
|
| 43 |
+
messages.append({"role": "system", "content": prompt_dict["risk_sys_msg"]})
|
| 44 |
+
messages.append({"role": "user", "content": prompt_dict["risk_usr_msg"].format(
|
| 45 |
+
n1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["news"],
|
| 46 |
+
c1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["company_info"],
|
| 47 |
+
r1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["risk_list"],
|
| 48 |
+
o1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["risk"],
|
| 49 |
+
n3=prompt_dict["risk_ex_f"][f"ex{ex_f_rnd[0]}"]["news"],
|
| 50 |
+
c3=prompt_dict["risk_ex_f"][f"ex{ex_f_rnd[0]}"]["company_info"],
|
| 51 |
+
r3=prompt_dict["risk_ex_f"][f"ex{ex_f_rnd[0]}"]["risk_list"],
|
| 52 |
+
o3=prompt_dict["risk_ex_f"][f"ex{ex_f_rnd[0]}"]["risk"],
|
|
|
|
| 53 |
n4=news_text,
|
| 54 |
+
c4=company_info,
|
| 55 |
+
r4=json.dumps(com_risk,ensure_ascii=False))})
|
| 56 |
+
risk_response = chat_completion_request(messages, model=model,name="risk_response", show=show)
|
| 57 |
return risk_response
|
| 58 |
|
| 59 |
+
def title(news_text, company_info, ex_t_rnd, risk, model):
|
| 60 |
messages = []
|
| 61 |
+
messages.append({"role": "system", "content": prompt_dict["risk_sys_msg"]})
|
| 62 |
+
messages.append({"role": "user", "content": prompt_dict["title_usr_msg"].format(
|
| 63 |
risk=risk,
|
| 64 |
+
n1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["news"],
|
| 65 |
+
c1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["company_info"],
|
| 66 |
+
o1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["title"],
|
| 67 |
+
n2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["news"],
|
| 68 |
+
c2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["company_info"],
|
| 69 |
+
o2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["title"],
|
| 70 |
+
n3=news_text,
|
| 71 |
+
c3=company_info,
|
| 72 |
+
)})
|
| 73 |
+
title_response = chat_completion_request(messages, model=model,name="title_response", show=show)
|
| 74 |
return title_response
|
| 75 |
|
| 76 |
def summary(news_text, ex_t_rnd, model):
|
| 77 |
messages = []
|
| 78 |
+
messages.append({"role": "system", "content": prompt_dict["risk_sys_msg"]})
|
| 79 |
+
messages.append({"role": "user", "content": prompt_dict["summary_usr_msg"].format(
|
| 80 |
+
n1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["news"],
|
| 81 |
+
o1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["summary"],
|
| 82 |
+
n2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["news"],
|
| 83 |
+
o2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["summary"],
|
| 84 |
n3=news_text)})
|
| 85 |
+
summary_response = chat_completion_request(messages,model=model,name="summary_response", show=show)
|
| 86 |
return summary_response
|
| 87 |
|
| 88 |
+
def alert(news_text, company_info, ex_t_rnd, risk, model):
|
| 89 |
messages = []
|
| 90 |
+
messages.append({"role": "system", "content": prompt_dict["risk_sys_msg"]})
|
| 91 |
+
messages.append({"role": "user", "content": prompt_dict["alert_usr_msg"].format(
|
| 92 |
risk=risk,
|
| 93 |
+
n1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["news"],
|
| 94 |
+
c1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["company_info"],
|
| 95 |
+
o1=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[0]}"]["alert"],
|
| 96 |
+
n2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["news"],
|
| 97 |
+
c2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["company_info"],
|
| 98 |
+
o2=prompt_dict["risk_ex_t"][f"ex{ex_t_rnd[1]}"]["alert"],
|
| 99 |
+
n3=news_text,
|
| 100 |
+
c3=company_info
|
| 101 |
+
)})
|
| 102 |
+
alert_response = chat_completion_request(messages,model=model,name="alert_response", show=show)
|
| 103 |
return alert_response
|
| 104 |
|
| 105 |
def translate(report_dict,model):
|
| 106 |
messages = []
|
| 107 |
+
messages.append({"role": "system", "content": prompt_dict["translate_sys_msg"]})
|
| 108 |
+
messages.append({"role": "user", "content": prompt_dict["translate_usr_msg"].format(dictionary=json.dumps(report_dict,ensure_ascii=False))})
|
| 109 |
+
translate_response = chat_completion_request(messages,model=model,name="translate_response", show=show)
|
| 110 |
return translate_response
|
| 111 |
|
| 112 |
|
request_gpt.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from openai import OpenAI
|
| 2 |
+
from tenacity import retry, wait_random_exponential, stop_after_attempt
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
client = OpenAI()
|
| 6 |
+
|
| 7 |
+
# openai sent
|
| 8 |
+
@retry(wait=wait_random_exponential(multiplier=1, max=40), stop=stop_after_attempt(3))
|
| 9 |
+
def chat_completion_request(messages, tools=None, tool_choice=None, model="gpt-3.5-turbo-0125", temperature=0.6,name="test",show=False):
|
| 10 |
+
try:
|
| 11 |
+
response = client.chat.completions.create(
|
| 12 |
+
model=model,
|
| 13 |
+
messages=messages,
|
| 14 |
+
temperature=temperature,
|
| 15 |
+
tools=tools,
|
| 16 |
+
tool_choice=tool_choice,
|
| 17 |
+
response_format={ "type": "json_object" }
|
| 18 |
+
)
|
| 19 |
+
if show:
|
| 20 |
+
print(f"input {name} = {messages}")
|
| 21 |
+
print(f"output {name} = {response.choices[0].message.content}")
|
| 22 |
+
return json.loads(response.choices[0].message.content),response.usage.completion_tokens,response.usage.prompt_tokens
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print("Unable to generate ChatCompletion response")
|
| 25 |
+
print(f"Exception: {e}")
|
| 26 |
+
return e
|