Yasu777 commited on
Commit
ce381eb
·
verified ·
1 Parent(s): 65b33ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -31
app.py CHANGED
@@ -21,34 +21,6 @@ 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
- 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アシスタントです。以下の指示に従ってください:
@@ -67,6 +39,19 @@ system_message_japanese = """
67
  生成されたテキストを日本語に翻訳する際、ファイル名やスクリプトの具体的な情報も省略せずに翻訳してください。詳細情報が失われないようにしてください。
68
  """
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  # ユーザー入力の受付
71
  if prompt := st.chat_input("質問を入力してください:"):
72
  st.session_state['conversation_history'].append({"role": "user", "content": prompt})
@@ -92,13 +77,13 @@ if prompt := st.chat_input("質問を入力してください:"):
92
  top_p=0.92
93
  )
94
 
95
- # 日本語の質問を英語に翻訳(表示しない)
96
  for chunk in translation_response:
97
  if hasattr(chunk.choices[0].delta, 'content'):
98
  chunk_text = chunk.choices[0].delta.content
99
  if chunk_text:
100
  translated_prompt += chunk_text
101
-
102
  # 英語に翻訳された質問をllama3-70b-8192で応答生成
103
  response = client.chat.completions.create(
104
  model="llama3-70b-8192",
@@ -115,7 +100,7 @@ if prompt := st.chat_input("質問を入力してください:"):
115
  if chunk_text:
116
  response_text += chunk_text
117
 
118
- # 応答を日本語に翻訳
119
  final_translation_response = client.chat.completions.create(
120
  model="gemma2-9b-it",
121
  messages=[
 
21
  for entry in st.session_state['conversation_history']:
22
  st.chat_message(entry['role']).markdown(entry['content'])
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # 日本語の応答を生成するためのシステムメッセージ
25
  system_message_japanese = """
26
  あなたは流暢な日本語を話すAIアシスタントです。以下の指示に従ってください:
 
39
  生成されたテキストを日本語に翻訳する際、ファイル名やスクリプトの具体的な情報も省略せずに翻訳してください。詳細情報が失われないようにしてください。
40
  """
41
 
42
+ # 英語の応答を生成するためのシステムメッセージ
43
+ system_message_english = """
44
+ 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.
45
+
46
+ 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.
47
+
48
+ 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.
49
+
50
+ 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.
51
+
52
+ Respond to the user's input in a helpful, intelligent, and versatile manner.
53
+ """
54
+
55
  # ユーザー入力の受付
56
  if prompt := st.chat_input("質問を入力してください:"):
57
  st.session_state['conversation_history'].append({"role": "user", "content": prompt})
 
77
  top_p=0.92
78
  )
79
 
80
+ # 英語に翻訳された質問を蓄積
81
  for chunk in translation_response:
82
  if hasattr(chunk.choices[0].delta, 'content'):
83
  chunk_text = chunk.choices[0].delta.content
84
  if chunk_text:
85
  translated_prompt += chunk_text
86
+
87
  # 英語に翻訳された質問をllama3-70b-8192で応答生成
88
  response = client.chat.completions.create(
89
  model="llama3-70b-8192",
 
100
  if chunk_text:
101
  response_text += chunk_text
102
 
103
+ # 英語の応答を日本語に翻訳
104
  final_translation_response = client.chat.completions.create(
105
  model="gemma2-9b-it",
106
  messages=[