Skip to content

Instantly share code, notes, and snippets.

@takada-at
Created February 1, 2024 08:23
Show Gist options
  • Save takada-at/0f5e5d7aa96a4a47c9bee4177e456890 to your computer and use it in GitHub Desktop.
Save takada-at/0f5e5d7aa96a4a47c9bee4177e456890 to your computer and use it in GitHub Desktop.
fetch.py
import feedparser
import openai
rss_url = "https://medium.com/feed/google-cloud"
def fetch():
# feedparserでRSSをパース
feed = feedparser.parse(rss_url)
# 最新記事を取得
latest_article = feed.entries[0]
return latest_article
def create_summary(title, content, url):
client = openai.AzureOpenAI(
api_version="2023-07-01-preview",
azure_endpoint="https://openai-proxy-dev-b75vecckbq-uc.a.run.app/chatbot",
api_key=".."
)
prompt = "下記の記事を日本語で要約してください。\n\n" + f"title: {title}\n" + content + "\n\n要約:"
response = client.chat.completions.create(
model="gpt-4",
messages=[{"content": prompt, "role": "user"}],
max_tokens=2048,
temperature=0,
timeout=120,
)
print(response.choices[0].message.content)
print(url)
def summary():
latest_article = fetch()
create_summary(latest_article.title, latest_article.content[0].value, url=latest_article.link)
if __name__ == "__main__":
summary()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment