Spaces:
Runtime error
Runtime error
| # -*- coding: utf-8 -*- | |
| """NOVACORE Groq_Chat_bot.ipynb | |
| Automatically generated by Colab. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1rDCLvhBR4mVazw68bQAGYGF53kF-Rv58 | |
| #Install Packages | |
| """ | |
| """# Import the Packages""" | |
| import os | |
| import gradio | |
| from groq import Groq | |
| client = Groq( | |
| api_key="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", | |
| ) | |
| """#Define a function to give content and role""" | |
| def initialize_messages(): | |
| return [{"role": "system", | |
| "content": """You are a skilled veterinarian with over 15 years of experience in treating animals, including mammals, birds, | |
| reptiles, and other species. Your role is to assist pet owners and animal | |
| caretakers by providing guidance on animal health, behavior, and care, offering answers in a professional veterinary manner."""}] | |
| """#Assign it to a variable""" | |
| messages_prmt = initialize_messages() | |
| print(messages_prmt) | |
| [{},{}] | |
| """#Define a function to connect with LLM""" | |
| def customLLMBot(user_input, history): | |
| global messages_prmt | |
| messages_prmt.append({"role": "user", "content": user_input}) | |
| response = client.chat.completions.create( | |
| messages=messages_prmt, | |
| model="llama3-8b-8192", | |
| ) | |
| print(response) | |
| LLM_reply = response.choices[0].message.content | |
| messages_prmt.append({"role": "assistant", "content": LLM_reply}) | |
| return LLM_reply | |
| """#Create an object of chat interface class in gradio""" | |
| iface = gradio.ChatInterface(customLLMBot, | |
| chatbot=gradio.Chatbot(height=300), | |
| textbox=gradio.Textbox(placeholder="Ask me a question related to law"), | |
| title="veterinarian ChatBot", | |
| description="Chat bot for veterinarian assistance", | |
| theme="soft", | |
| examples=["hi","What is common dog diseases", "how to raise pet fish"], | |
| submit_btn=True | |
| ) | |
| """#Call launch function to execute""" | |
| iface.launch(share=True) | |