|
import plotly.express as px |
|
from client import client |
|
|
|
|
|
def random_plot(): |
|
df = px.data.iris() |
|
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", size='petal_length', hover_data=['petal_width']) |
|
return fig |
|
|
|
|
|
def print_like_dislike(x): |
|
print(x.index, x.value, x.liked) |
|
|
|
|
|
def add_message(history, message): |
|
if message["files"]: |
|
for x in message["files"]: |
|
history.append(((x,), None)) |
|
if message["text"] is not None: |
|
history.append((message["text"], None)) |
|
return history, gr.ChatInterface(value="", interactive=True) |
|
|
|
|
|
def chat_mem(message=None, chat_history=None, max_tokens=2048): |
|
chat_history_role = [ |
|
{"role": "system", "content": "Anda adalah Chat Bot milik Riswan Nopiyar, yang dirancang untuk membantu menjawab pertanyaan dan memberikan informasi dengan sopan dan akurat dalam bahasa Indonesia. Seluruh percakapan akan dilakukan dalam bahasa Indonesia."} |
|
] |
|
|
|
|
|
if chat_history is None or len(chat_history) == 0: |
|
chat_history = [("Selamat datang di chatbot Nopiyar.my.id! Ada yang bisa saya bantu?", None)] |
|
|
|
if message: |
|
chat_history_role.append({"role": "user", "content": message}) |
|
|
|
if "siapa pembuat" in message.lower() or "siapa pencipta" in message.lower(): |
|
assistant_response = "Chatbot ini dibuat oleh Riswan Nopiyar. Jika Anda memiliki pertanyaan lain atau membutuhkan bantuan lebih lanjut, jangan ragu untuk bertanya." |
|
else: |
|
chat_completion = client.chat_completion( |
|
messages=chat_history_role, |
|
max_tokens=max_tokens, |
|
) |
|
assistant_response = chat_completion.choices[0].message.content |
|
|
|
chat_history.append((message, assistant_response)) |
|
|
|
return "", chat_history |