budhadityac24 commited on
Commit
fd4da4e
1 Parent(s): 6541326

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -42
app.py CHANGED
@@ -12,13 +12,13 @@ client = Groq(
12
  api_key=os.getenv("GROQ_API_KEY"),
13
  )
14
 
15
- st.title("Weather App with Chat Interface")
16
 
17
- input_text = st.text_input("Hi, I am a weather chatbot. Ask me anything!")
18
 
19
- if st.button("Ask me"):
20
- if not input_text:
21
- st.error("Please enter a location!")
22
 
23
  # ### Define Dummy Function
24
 
@@ -42,7 +42,29 @@ def get_current_weather(location):
42
 
43
 
44
  # # define a function as tools
45
- tools = [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  {
47
  "type": "function",
48
  "function": {
@@ -61,45 +83,42 @@ tools = [
61
  }
62
  },
63
  ]
64
-
65
-
66
-
67
- response = client.chat.completions.create(
68
- model="mixtral-8x7b-32768",
69
- messages=[
70
- {
71
  "role": "user",
72
  "content": input_text,
73
- }
74
- ],
75
- temperature=0,
76
- max_tokens=300,
77
- tools=tools,
78
- tool_choice="auto"
79
- )
80
- # print(response)
81
- # print(response.choices[0].message.content)
82
 
83
- # print(response['choices'][0]['message']['tool_calls'][0]['function']['arguments'])
84
 
85
- groq_response = response.choices[0].message
86
- # print(groq_response)
87
 
88
 
89
- # response.tool_calls[0].function.arguments
90
 
91
- # We can now capture the arguments:
92
 
93
 
94
- args = json.loads(groq_response.tool_calls[0].function.arguments)
95
- # print(args)
96
 
97
- output=get_current_weather(**args)
98
- # print(output)
99
- from groq import Groq
100
 
101
- client = Groq()
102
- completion = client.chat.completions.create(
103
  model="mixtral-8x7b-32768",
104
  messages=[
105
  {
@@ -116,11 +135,31 @@ completion = client.chat.completions.create(
116
  top_p=1,
117
  stream=True,
118
  stop=None,
119
- )
120
- output=""
121
- st.write("Response:")
122
- for chunk in completion:
123
- output+=chunk.choices[0].delta.content or ""
124
-
125
-
126
- st.write(output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  api_key=os.getenv("GROQ_API_KEY"),
13
  )
14
 
15
+ # st.title("Weather App with Chat Interface")
16
 
17
+ # input_text = st.text_input("Hi, I am a weather chatbot. Ask me anything!")
18
 
19
+ # if st.button("Ask me"):
20
+ # if not input_text:
21
+ # st.error("Please enter a location!")
22
 
23
  # ### Define Dummy Function
24
 
 
42
 
43
 
44
  # # define a function as tools
45
+ # tools = [
46
+ # {
47
+ # "type": "function",
48
+ # "function": {
49
+ # "name": "get_current_weather",
50
+ # "description": "Get the current weather in a given location",
51
+ # "parameters": {
52
+ # "type": "object",
53
+ # "properties": {
54
+ # "location": {
55
+ # "type": "string",
56
+ # "description": "The city and state, e.g. San Francisco, CA"
57
+ # }
58
+ # },
59
+ # "required": ["location"]
60
+ # }
61
+ # }
62
+ # },
63
+ # ]
64
+
65
+
66
+ def get_response(input_text):
67
+ tools = [
68
  {
69
  "type": "function",
70
  "function": {
 
83
  }
84
  },
85
  ]
86
+ response = client.chat.completions.create(
87
+ model="mixtral-8x7b-32768",
88
+ messages=[
89
+ {
 
 
 
90
  "role": "user",
91
  "content": input_text,
92
+ }
93
+ ],
94
+ temperature=0,
95
+ max_tokens=300,
96
+ tools=tools,
97
+ tool_choice="auto"
98
+ )
99
+ # print(response)
100
+ # print(response.choices[0].message.content)
101
 
102
+ # print(response['choices'][0]['message']['tool_calls'][0]['function']['arguments'])
103
 
104
+ groq_response = response.choices[0].message
105
+ # print(groq_response)
106
 
107
 
108
+ # response.tool_calls[0].function.arguments
109
 
110
+ # We can now capture the arguments:
111
 
112
 
113
+ args = json.loads(groq_response.tool_calls[0].function.arguments)
114
+ # print(args)
115
 
116
+ output=get_current_weather(**args)
117
+ # print(output)
118
+ from groq import Groq
119
 
120
+ client = Groq()
121
+ completion = client.chat.completions.create(
122
  model="mixtral-8x7b-32768",
123
  messages=[
124
  {
 
135
  top_p=1,
136
  stream=True,
137
  stop=None,
138
+ )
139
+ output=""
140
+ # st.write("Response:")
141
+ for chunk in completion:
142
+ output+=chunk.choices[0].delta.content or ""
143
+ # output+="\n"
144
+ return output
145
+
146
+ def main():
147
+ st.title("Weather Chatbot")
148
+
149
+ # User input
150
+ st.write("Hi, I am a weather chatbot. Ask me anything!")
151
+ location = st.text_input("Type in your question")
152
+
153
+ # Ask me button
154
+ if st.button("Ask me"):
155
+ # Check if location is provided
156
+ if location:
157
+ # Get current weather
158
+ response = get_response(location)
159
+ # Display weather details
160
+ st.json(response)
161
+ else:
162
+ st.warning("Please enter a city name.")
163
+
164
+ if __name__ == "__main__":
165
+ main()