Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,27 +2,24 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
| 4 |
|
| 5 |
-
#
|
| 6 |
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
| 7 |
|
| 8 |
ASSISTANT_NAME = "Viateur"
|
| 9 |
|
| 10 |
def chat(user_message, history):
|
| 11 |
-
"""
|
| 12 |
-
Function yo gusubiza ubutumwa bw'umukoresha
|
| 13 |
-
history: ibika ibiganiro by'iyi session gusa
|
| 14 |
-
"""
|
| 15 |
prompt = f"""
|
| 16 |
Witwa {ASSISTANT_NAME}, uri AI Assistant ikoresha Kinyarwanda.
|
| 17 |
Subiza ibibazo byose mu Kinyarwanda neza kandi witonze.
|
| 18 |
Ubutumwa bw'umukoresha: {user_message}
|
| 19 |
"""
|
| 20 |
|
| 21 |
-
#
|
| 22 |
response = client.chat.completions.create(
|
| 23 |
model="gpt-4o-mini",
|
| 24 |
messages=[{"role": "user", "content": prompt}]
|
| 25 |
)
|
|
|
|
| 26 |
answer = response.choices[0].message.content
|
| 27 |
|
| 28 |
# Bika mu history y'iyi session gusa
|
|
|
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
| 4 |
|
| 5 |
+
# Fata API Key ya OpenAI muri Hugging Face Secrets
|
| 6 |
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
| 7 |
|
| 8 |
ASSISTANT_NAME = "Viateur"
|
| 9 |
|
| 10 |
def chat(user_message, history):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
prompt = f"""
|
| 12 |
Witwa {ASSISTANT_NAME}, uri AI Assistant ikoresha Kinyarwanda.
|
| 13 |
Subiza ibibazo byose mu Kinyarwanda neza kandi witonze.
|
| 14 |
Ubutumwa bw'umukoresha: {user_message}
|
| 15 |
"""
|
| 16 |
|
| 17 |
+
# Kohereza request kuri OpenAI
|
| 18 |
response = client.chat.completions.create(
|
| 19 |
model="gpt-4o-mini",
|
| 20 |
messages=[{"role": "user", "content": prompt}]
|
| 21 |
)
|
| 22 |
+
|
| 23 |
answer = response.choices[0].message.content
|
| 24 |
|
| 25 |
# Bika mu history y'iyi session gusa
|