Spaces:
Sleeping
Sleeping
created findCity.py It takes the user input as string and returns the city mentioned in the query.
Browse files- findCity.py +24 -0
findCity.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from groq import Groq
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
load_dotenv()
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def find_city(input_string):
|
| 8 |
+
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
| 9 |
+
completion = client.chat.completions.create(
|
| 10 |
+
model="llama3-8b-8192",
|
| 11 |
+
messages=[
|
| 12 |
+
{
|
| 13 |
+
"role": "system",
|
| 14 |
+
"content": "you are a geography expert. return just a one word city name from the sentence given to you"
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"role": "user",
|
| 18 |
+
"content": input_string,
|
| 19 |
+
}
|
| 20 |
+
],
|
| 21 |
+
max_tokens=100,
|
| 22 |
+
)
|
| 23 |
+
city = completion.choices[0].message.content
|
| 24 |
+
return city
|