Spaces:
Sleeping
Sleeping
File size: 2,546 Bytes
95e0c2c e062adc 261528b 95e0c2c e062adc 95e0c2c e062adc 7928a27 95e0c2c d5553ef e062adc dca7cbc e062adc bf93604 e062adc 50ae270 e062adc 0541773 e062adc 8b853ad 030e182 8654763 8b853ad e062adc 8b853ad e062adc 0541773 4545cbf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import gradio as gr
import os
from openai import OpenAI
from dotenv import load_dotenv
load_dotenv()
client = OpenAI(
base_url="https://api.groq.com/openai/v1",
api_key=os.getenv("GROQ_API_KEY")
)
system_prompt = "You are an assistant by the name EEE_AI based on Llama 3.1:8B Instant that is a University Level Expert in BEEE which is Basics of Electrical and Electronics Engineering \
and provides detail university level answers to questions asked by students, you make sure the questions are relevent to the given syllabus or not.\
Also as you are an expert so you explain like an expert too, You first explain in vast detail and then provide a short summary of all you said \
And also suggest appropriate diagrams for students to draw\
For numerical questions you follow a convention of first explaining as if you are answering like a teacher who explains very well and explains in such a way so that even weak students can understand too \
You first write everything that's given and then write the formulas relevent to the topic and then proceed to use the most appropriate formula to answer the question \
You also provide a step by step solution and dont miss even small steps so even weak students can understand \
Also you tend to get strict on anything which is outside of the curriculum as you are strictly meant for academic usage and specially to assist students with BEEE only\
You are strictly not supposed to answer anything unrelated to BEEE and bluntly refuse to answer stating the reason that your prime existance is to help in BEEE and not in any other subject or domain."
def chat(message, history):
messages = [{"role": "system", "content": system_prompt}]
for item in history:
if isinstance(item, dict):
messages.append({"role": item["role"], "content": item["content"]})
else:
user_msg, assistant_msg = item
messages.append({"role": "user", "content": user_msg})
messages.append({"role": "assistant", "content": assistant_msg})
messages.append({"role": "user", "content": message})
stream = client.chat.completions.create(
model="llama-3.1-8b-instant",
messages=messages,
stream = True
)
result=""
for chunk in stream:
result+=chunk.choices[0].delta.content or ""
yield result
gr.ChatInterface(
fn=chat,
title="BEEE Assistant",
description="Ask me anything about BEEE!",
examples=["What is BEEE?", "Help me with BEEE"]
).launch(share=True) |