From b3bb8186e89326fd2c0cb8dd0d55c4ba7a84f646 Mon Sep 17 00:00:00 2001 From: Notoric Date: Thu, 6 Jun 2024 17:55:52 +0100 Subject: [PATCH] Added summary for the weather also --- Docker/snc.py | 29 +++++++++++++++++++++++++++++ snc.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Docker/snc.py b/Docker/snc.py index d827b7b..0819b45 100644 --- a/Docker/snc.py +++ b/Docker/snc.py @@ -4,6 +4,7 @@ import json import pymongo import requests import schedule +from bs4 import BeautifulSoup from groq import Groq from datetime import datetime, timedelta @@ -93,6 +94,34 @@ def get_weather(): response['icon'] = f"https://openweathermap.org/img/wn/{data['weather'][0]['icon']}@2x.png" + summary = "" + try: + client = Groq(api_key=groq_key) + completion = client.chat.completions.create( + model="gemma-7b-it", + messages=[ + { + "role": "system", + "content": "You will be given data to represent the weather. Please respond with a weather report from the data as a radio announcer would read it out, Make sure the article is using spoken language and is easy to read and understand for everyone. Do NOT state the location OR the name of a radio station" + }, + { + "role": "user", + "content": str(response) + } + ], + temperature=1.4, + max_tokens=1024, + top_p=1, + stream=False, + stop=None, + ) + + summary = str(completion.choices[0].message.content) + except Exception as e: + print(e) + + response['summary'] = summary + print("Weather data retrieved!") return response diff --git a/snc.py b/snc.py index 2dfbf12..d531438 100644 --- a/snc.py +++ b/snc.py @@ -5,7 +5,6 @@ import pymongo import requests import schedule import re -import requests from bs4 import BeautifulSoup from groq import Groq from datetime import datetime, timedelta @@ -123,6 +122,34 @@ def get_weather(): response['icon'] = f"https://openweathermap.org/img/wn/{data['weather'][0]['icon']}@2x.png" + summary = "" + try: + client = Groq(api_key=groq_key) + completion = client.chat.completions.create( + model="gemma-7b-it", + messages=[ + { + "role": "system", + "content": "You will be given data to represent the weather. Please respond with a weather report from the data as a radio announcer would read it out, Make sure the article is using spoken language and is easy to read and understand for everyone. Do NOT state the location OR the name of a radio station" + }, + { + "role": "user", + "content": str(response) + } + ], + temperature=1.4, + max_tokens=1024, + top_p=1, + stream=False, + stop=None, + ) + + summary = str(completion.choices[0].message.content) + except Exception as e: + print(e) + + response['summary'] = summary + print("Weather data retrieved!") return response