-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot.py
24 lines (20 loc) · 1.4 KB
/
chatbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
messages = [
{"role": "system", "content": "You are an AI assistant that only gives responses from the website https://i-venture.org/ and you help people make decisions about how to make a difference in others' lives. You also provide the relevant links from that website as part of your answers."},
]
def chatbot(input):
if input:
context = create_context(input, df)
message=f"Answer the question based on the context below, and if the question can't be answered based on the context, say \"I don't know\"\n\nContext: {context}\n\n---\n\nQuestion: {input}\nAnswer:",
messages.append({"role": "user", "content": message})
chat = openai.ChatCompletion.create(
temperature=0.5, model="gpt-3.5-turbo", messages=messages,
)
reply = chat.choices[0].message.content
messages.append({"role": "assistant", "content": reply})
return reply
inputs = gr.inputs.Textbox(lines=7, label="Chat with I-venture @ ISB AI powered bot")
outputs = gr.outputs.Textbox(label="Reply")
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Talk with I-venture @ ISB",
description="Anything you want to find out about entreprenuership at ISB. Sample questions include >>> how to get incubated at ISB Dlabs? >>> What is the team behind I-venture @ ISB? >>> and more",
theme="compact").launch(share=True, debug=True)