faraz7123 commited on
Commit
7bc6f72
·
verified ·
1 Parent(s): 5d34c65

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +67 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from swarmauri.standard.llms.concrete.GroqModel import GroqModel
2
+ from swarmauri.standard.messages.concrete.SystemMessage import SystemMessage
3
+ from swarmauri.standard.agents.concrete.SimpleConversationAgent import SimpleConversationAgent
4
+ from swarmauri.standard.conversations.concrete.MaxSystemContextConversation import MaxSystemContextConversation
5
+ import gradio as gr
6
+ import os
7
+ from dotenv import load_dotenv
8
+ # Fetch the API key from environment variables
9
+
10
+ load_dotenv()
11
+
12
+ # Fetch the API key from environment variables
13
+ API_KEY = os.getenv("GROQ_API_KEY")
14
+
15
+
16
+ # Initialize the GroqModel with the API key to access allowed models
17
+ llm = GroqModel(api_key=API_KEY)
18
+
19
+ # Get the available models from the llm instance
20
+ allowed_models = llm.allowed_models
21
+
22
+ # Initialize a MaxSystemContextConversation instance
23
+ conversation = MaxSystemContextConversation()
24
+
25
+ # Define a function to dynamically change the model based on dropdown input
26
+ def load_model(selected_model):
27
+ return GroqModel(api_key=API_KEY, name=selected_model)
28
+
29
+ # Define the function to interact with the agent
30
+ def converse(input_text, history, system_context, model_name):
31
+ print(f"System context: {system_context}")
32
+ print(f"Selected model: {model_name}")
33
+
34
+ # Initialize the model dynamically based on user selection
35
+ llm = load_model(model_name)
36
+
37
+ # Initialize the agent with the new model
38
+ agent = SimpleConversationAgent(llm=llm, conversation=conversation)
39
+
40
+ # Set the system context for the agent
41
+ agent.conversation.system_context = SystemMessage(content=system_context)
42
+ # Ensure input text is a string
43
+ input_text = str(input_text)
44
+
45
+ print(conversation.history)
46
+
47
+ # Execute the input command with the agent
48
+ result = agent.exec(input_text)
49
+
50
+ print(result, type(result))
51
+
52
+ # Return the result as a string
53
+ return str(result)
54
+
55
+ # Set up the Gradio ChatInterface with a dropdown for model selection
56
+ interface = gr.ChatInterface(
57
+ fn=converse,
58
+ additional_inputs=[
59
+ gr.Textbox(label="System Context"),
60
+ gr.Dropdown(label="Model Name", choices=allowed_models, value=allowed_models[0])
61
+ ],
62
+ title="A system context conversation",
63
+ description="Interact with the agent using a selected model and system context."
64
+ )
65
+
66
+ # Start the Gradio interface
67
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ huggingface_hub==0.22.2
2
+ swarmauri[full]==0.4.1
3
+ python-dotenv