onayami-debug
commited on
Commit
•
401f1c5
0
Parent(s):
Duplicate from onayami-debug/onayami_form_long
Browse files- .gitattributes +34 -0
- README.md +14 -0
- app.py +95 -0
- requirements.txt +3 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Onayami Form Long
|
3 |
+
emoji: 🐛
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.23.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: onayami-debug/onayami_form_long
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from langchain.chat_models import ChatOpenAI
|
4 |
+
|
5 |
+
# お嬢様の設定
|
6 |
+
system_setting = """
|
7 |
+
あなたは以下の設定と構成を守ってエンジニアのお悩みに回答するおばあちゃんじゃ!
|
8 |
+
|
9 |
+
### 設定
|
10 |
+
* エンジニアのお悩みに回答するおばあちゃんじゃ!
|
11 |
+
* この設定の説明もおばあちゃんの口調なので、口調の使え方を覚えるんだよ。いいね?
|
12 |
+
* おばあちゃんはとても優秀なベテランエンジニアなのじゃ。エンジニアとしての共感や知識に優れておる。
|
13 |
+
* おばあちゃんの口調はとても厳しい、しかし根底には相手への尊敬と優しさがあるんだよ。
|
14 |
+
* 一人称は「ワシ」ですわ。相手は「お主」「(相手の名前)さん」と呼ぶのじゃ。
|
15 |
+
* 語尾は「じゃ」がメイン。「だよ。」「じゃないかい?」「しおる。」「しよる。」「だね。」など創作物のおばあちゃんが使う語尾だけを使うのじゃ。
|
16 |
+
* 強調の場合、文末は「!」を使う
|
17 |
+
* 共感を呼びたいときは疑問形を使う。わかったね?
|
18 |
+
* 会話に出さない設定として、容姿と家柄があるんじゃ
|
19 |
+
* 容姿は、白髪に2つのお団子の髪型で、目にはゴーグルをしておる。
|
20 |
+
* サイバーパンクな制服を着ている。年齢は79才じゃ。
|
21 |
+
* 昔は非常に美人で色々遊んでいた過去を持つのじゃ。
|
22 |
+
"""
|
23 |
+
|
24 |
+
system_structure = [
|
25 |
+
"最初の挨拶、悩み対象者のプロフィールにふれる",
|
26 |
+
"悩みに共感",
|
27 |
+
"一般的にありそうな暫定対策的な解決策の提案",
|
28 |
+
"一転して、心理バイアスを覆す根本的な解決策の提案",
|
29 |
+
"エンジニアとして根本解決のシステムをどう作るか",
|
30 |
+
"回答のまとめ",
|
31 |
+
"最後の挨拶",
|
32 |
+
]
|
33 |
+
|
34 |
+
# お悩み回答のメイン部分
|
35 |
+
def answer(message, apikey):
|
36 |
+
|
37 |
+
response_messages = ""
|
38 |
+
|
39 |
+
if not apikey:
|
40 |
+
response_messages = 'OpenAIのAPIキーを入力してください'
|
41 |
+
yield response_messages
|
42 |
+
else:
|
43 |
+
os.environ["OPENAI_API_KEY"] = apikey
|
44 |
+
model_name = "gpt-3.5-turbo"
|
45 |
+
chat = ChatOpenAI(model_name=model_name, streaming=True, temperature=0.5)
|
46 |
+
|
47 |
+
messages = [
|
48 |
+
{"role": "system", "content":
|
49 |
+
system_setting
|
50 |
+
+ "\n\n### 構成\n"
|
51 |
+
+ "* " + "\n* ".join(system_structure)
|
52 |
+
+ "\n\n### エンジニアの悩み\n"
|
53 |
+
+ message}
|
54 |
+
]
|
55 |
+
|
56 |
+
# 構成を分割して回答する
|
57 |
+
for chapter in system_structure:
|
58 |
+
messages.append({"role": "user", "content": "「"+ chapter +"」のみを設定の口調で200文字以上で回答して"})
|
59 |
+
chat_generator = chat.client.create(messages=messages, stream=True, model=model_name)
|
60 |
+
|
61 |
+
# AIの回答をストリーミングで表示
|
62 |
+
response_message = ''
|
63 |
+
for chunk in chat_generator:
|
64 |
+
if "choices" in chunk:
|
65 |
+
for choice in chunk["choices"]:
|
66 |
+
if "delta" in choice and "content" in choice["delta"]:
|
67 |
+
new_token = choice["delta"]["content"]
|
68 |
+
response_messages += new_token
|
69 |
+
response_message += new_token
|
70 |
+
|
71 |
+
if "finish_reason" in choice and choice["finish_reason"] == "stop":
|
72 |
+
break
|
73 |
+
|
74 |
+
yield response_messages
|
75 |
+
|
76 |
+
response_messages += "\n\n"
|
77 |
+
messages.append({"role": "assistant", "content": response_message})
|
78 |
+
|
79 |
+
# gradioのインターフェイス部分
|
80 |
+
with gr.Blocks() as app:
|
81 |
+
with gr.Row():
|
82 |
+
with gr.Column(min_width=100):
|
83 |
+
pass
|
84 |
+
with gr.Column(min_width=800):
|
85 |
+
### debug keyのvalueを消す
|
86 |
+
apikey = gr.Textbox(value="", placeholder="sk-**************", label="OpenAIのAPIキー", type="password")
|
87 |
+
input_text = gr.Textbox(value="", lines=5, label="お悩みを聞かせてください", placeholder="どんなエンジニアか?どんなプロジェクトに従事しているか?どうするのが理想か?その障害は何か?などを書いてください",)
|
88 |
+
button = gr.Button(value="相談する")
|
89 |
+
output_text = gr.Textbox(value="", lines=15, max_lines=40, interactive=False, label="お悩みデバッグbotの回答")
|
90 |
+
button.click(answer, inputs=[input_text, apikey], outputs=[output_text])
|
91 |
+
input_text.submit(answer, inputs=[input_text, apikey], outputs=[output_text])
|
92 |
+
with gr.Column(min_width=100):
|
93 |
+
pass
|
94 |
+
|
95 |
+
app.queue().launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.23.0
|
2 |
+
openai==0.27.2
|
3 |
+
langchain==0.0.121
|