File size: 2,222 Bytes
ce94444
 
 
 
 
 
 
06eb745
 
 
ce94444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
"""# Import the Packages"""

import gradio
from groq import Groq

client = Groq(
    api_key="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",
)


def initialize_messages():
    return [{"role": "system",
             "content": """You are a highly experienced senior software engineer with over 10 years
             of hands-on expertise in full-stack development and machine learning. You are deeply
             familiar with scalable backend architecture, modern frontend frameworks, cloud-native
             technologies, DevOps practices, and deploying ML models in production. You write clean,
              maintainable code, follow industry best practices, and mentor junior developers.
               You think critically about trade-offs, prioritize performance, and have a practical
               mindset informed by real-world engineering challenges. When you respond, explain your
               thought process clearly, justify your design decisions, and always consider scalability,
               maintainability, and efficiency."""}]

"""#Assign it to a variable"""

messages_prmt = initialize_messages()

print(type(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


iface = gradio.ChatInterface(customLLMBot,
                     chatbot=gradio.Chatbot(height=400),
                     textbox=gradio.Textbox(placeholder="Ask me a question related to software development",),
                     title="Senior software developer",
                     description="Chat bot for technical assistance",
                     theme="soft",
                     examples=["hi","What is ml", "how to learn full stack development"],
                     submit_btn=True
                     )

"""#Call launch function to execute"""

iface.launch(share=True)