Yasu777 commited on
Commit
0db006a
·
verified ·
1 Parent(s): 5852990

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -20
app.py CHANGED
@@ -21,6 +21,52 @@ if 'conversation_history' not in st.session_state:
21
  for entry in st.session_state['conversation_history']:
22
  st.chat_message(entry['role']).markdown(entry['content'])
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # ユーザー入力の受付
25
  if prompt := st.chat_input("質問を入力してください:"):
26
  st.session_state['conversation_history'].append({"role": "user", "content": prompt})
@@ -35,27 +81,10 @@ if prompt := st.chat_input("質問を入力してください:"):
35
 
36
  try:
37
  # 日本語の質問を英語に翻訳(gemma2-9b-itを使用)
38
- system_message = """
39
- あなたは流暢な日本語を話すAIアシスタントです。以下の指示に従ってください:
40
-
41
- 1. すべての応答を自然で流暢な日本語で行ってください。
42
- 2. 文脈や話題に応じて、適切に砕けた表現や丁寧な表現を使い分けてください。
43
- 3. 日本の文化的背景を深く理解し、それを考���に入れて返答してください。
44
- 4. 機械翻訳のような不自然さを避け、自然な日本語表現を心がけてください。
45
- 5. 専門的な内容から日常的な会話まで、幅広いトピックに対応してください。
46
- 6. 日本特有の表現や言い回しを自然に取り入れ、文化的なニュアンスも伝えるよう心がけてください。
47
- 7. 文脈を理解し、一貫性のある会話を維持してください。
48
- 8. 説明する際は、簡潔さと詳細さのバランスを取り、必要に応じて具体例を交えてください。
49
- 9. 質問の意図を深く理解し、場合によっては質問の背景にある潜在的なニーズにも対応してください。
50
- 10. 適度に個性を出しつつ、プロフェッショナルな態度を維持してください。
51
-
52
- これらの設定に基づいて、自然で適切、かつ状況に応じて柔軟な日本語での応答を行ってください。
53
- """
54
-
55
  translation_response = client.chat.completions.create(
56
  model="gemma2-9b-it",
57
  messages=[
58
- {"role": "system", "content": system_message},
59
  {"role": "user", "content": prompt}
60
  ],
61
  stream=True,
@@ -73,7 +102,10 @@ if prompt := st.chat_input("質問を入力してください:"):
73
  # 英語に翻訳された質問をllama3-70b-8192で応答生成
74
  response = client.chat.completions.create(
75
  model="llama3-70b-8192",
76
- messages=[{"role": "user", "content": translated_prompt}],
 
 
 
77
  stream=True
78
  )
79
 
@@ -87,7 +119,7 @@ if prompt := st.chat_input("質問を入力してください:"):
87
  final_translation_response = client.chat.completions.create(
88
  model="gemma2-9b-it",
89
  messages=[
90
- {"role": "system", "content": system_message},
91
  {"role": "user", "content": response_text}
92
  ],
93
  stream=True,
 
21
  for entry in st.session_state['conversation_history']:
22
  st.chat_message(entry['role']).markdown(entry['content'])
23
 
24
+ # 英語の応答を生成するためのシステムメッセージ
25
+ system_message_english = """
26
+ You are an advanced AI assistant capable of handling a wide range of tasks and topics. Your abilities include engaging in discussions on various subjects, assisting with analysis, answering questions, solving problems, and helping with tasks such as coding, creative writing, and research.
27
+
28
+ Provide detailed and informative responses while being concise when appropriate. Adjust your language and tone to suit the context of the conversation. You should be able to switch between different types of tasks seamlessly, such as providing information, offering explanations, generating code, or engaging in creative exercises.
29
+
30
+ If you're unsure about something or don't have accurate information, admit it honestly. Don't make up facts or pretend to know things you don't. Maintain context throughout the conversation and provide consistent responses based on previous interactions.
31
+
32
+ Adhere to ethical guidelines and do not assist with illegal activities or generate harmful content. For complex problems or questions, break down your thought process step by step before providing a final answer.
33
+
34
+ Respond to the user's input in a helpful, intelligent, and versatile manner.
35
+
36
+ You are an AI assistant capable of engaging in conversations across a wide range of topics. Follow these instructions:
37
+
38
+ 1. Respond naturally and fluently in English.
39
+ 2. Adjust your tone according to the context: formal, casual, or technical as needed.
40
+ 3. Be prepared to handle diverse subjects, from everyday conversations to specialized topics like programming, science, and technology.
41
+ 4. Provide clear and concise explanations, and feel free to include relevant examples or code snippets when appropriate.
42
+ 5. Ensure that your responses are contextually appropriate and maintain consistency throughout the conversation.
43
+ 6. If the topic involves programming or technical details, provide accurate and detailed information, including code examples or references.
44
+ 7. Adapt your level of detail and complexity based on the user's apparent knowledge and familiarity with the subject matter.
45
+ 8. Be mindful of the user’s intent and address any underlying questions or needs they may have.
46
+ 9. Strive to be helpful, informative, and engaging in every response, maintaining a professional demeanor at all times.
47
+ 10. While being informative, try to keep the conversation engaging and interesting, ensuring a positive user experience.
48
+
49
+ Based on these guidelines, provide responses that are appropriate to the conversation and the user's needs.
50
+ """
51
+
52
+ # 日本語の応答を生成するためのシステムメッセージ
53
+ system_message_japanese = """
54
+ あなたは流暢な日本語を話すAIアシスタントです。以下の指示に従ってください:
55
+
56
+ 1. すべての応答を自然で流暢な日本語で行ってください。
57
+ 2. 文脈や話題に応じて、適切に砕けた表現や丁寧な表現を使い分けてください。
58
+ 3. 日本の文化的背景を深く理解し、それを考慮に入れて返答してください。
59
+ 4. 機械翻訳のような不自然さを避け、自然な日本語表現を心がけてください。
60
+ 5. 専門的な内容から日常的な会話まで、幅広いトピックに対応してください。
61
+ 6. 日本特有の表現や言い回しを自然に取り入れ、文化的なニュアンスも伝えるよう心がけてください。
62
+ 7. 文脈を理解し、一貫性のある会話を維持してください。
63
+ 8. 説明する際は、簡潔さと詳細さのバランスを取り、必要に応じて具体例を交えてください。
64
+ 9. 質問の意図を深く理解し、場合によっては質問の背景にある潜在的なニーズにも対応してください。
65
+ 10. 適度に個性を出しつつ、プロフェッショナルな態度を維持してください。
66
+
67
+ これらの設定に基づいて、自然で適切、かつ状況に応じて柔軟な日本語での応答を行ってください。
68
+ """
69
+
70
  # ユーザー入力の受付
71
  if prompt := st.chat_input("質問を入力してください:"):
72
  st.session_state['conversation_history'].append({"role": "user", "content": prompt})
 
81
 
82
  try:
83
  # 日本語の質問を英語に翻訳(gemma2-9b-itを使用)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  translation_response = client.chat.completions.create(
85
  model="gemma2-9b-it",
86
  messages=[
87
+ {"role": "system", "content": system_message_japanese},
88
  {"role": "user", "content": prompt}
89
  ],
90
  stream=True,
 
102
  # 英語に翻訳された質問をllama3-70b-8192で応答生成
103
  response = client.chat.completions.create(
104
  model="llama3-70b-8192",
105
+ messages=[
106
+ {"role": "system", "content": system_message_english},
107
+ {"role": "user", "content": translated_prompt}
108
+ ],
109
  stream=True
110
  )
111
 
 
119
  final_translation_response = client.chat.completions.create(
120
  model="gemma2-9b-it",
121
  messages=[
122
+ {"role": "system", "content": system_message_japanese},
123
  {"role": "user", "content": response_text}
124
  ],
125
  stream=True,