Today we are going to learn how to create with the new GPT-4 version a chat bot that is able to read Reuters.com and use the info as an output in the chat, instead to use old 2021 info
Here is the code created by GPT
import openai
import os
import feedparser
api_key = "your api key here"
openai.api_key = api_key
# Fetch latest news from Reuters RSS feed
def fetch_reuters_news():
url = "[ Ссылка ]"
feed = feedparser.parse(url)
news_items = []
for entry in feed.entries:
headline = entry.title
summary = entry.summary
news_items.append((headline, summary))
return news_items
def ask_gpt_with_news(question, news_items):
news_prompt = "\n".join([f"{headline}\n{summary}" for headline, summary in news_items])
prompt = f"Latest news from Reuters:\n{news_prompt}\n\nQuestion: {question}\nAnswer:"
response = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
max_tokens=150,
n=1,
stop=None,
temperature=0.5,
)
answer = response.choices[0].text.strip()
return answer
news_items = fetch_reuters_news()
while True:
user_question = input("You: ")
if user_question.lower() == "exit":
break
gpt_answer = ask_gpt_with_news(user_question, news_items)
print("GPT-3.5: " + gpt_answer)
AWS Load Balancer Controller with EKS, our free webinar: [ Ссылка ]
Check out mkdev dispatch, a bi-weekly newsletter about DevOps and Cloud-Native - [ Ссылка ]
DevOps Accents is our monthly podcast, where 3 mkdev founders chat about DevOps, Cloud, and Life: [ Ссылка ]
If you or your company need consulting around Kubernetes, GitOps, and similar topics, reach out to us via email - at team@mkdev.me or check out our website: [ Ссылка ]
#GPT #GPT4 #GPT3 #chat #chatbot #pyhton
![](https://i.ytimg.com/vi/PM_rKVJ91Is/maxresdefault.jpg)