Created
July 24, 2023 18:52
-
-
Save john-adeojo/d90431d2d6847c01af3fbe497b1267ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openai | |
def generate_response(topic, API_KEY): | |
""" | |
Generates a random news headline for a given ticker | |
""" | |
openai.api_key = API_KEY | |
content = "You generate news headlines" | |
prompt = f"generate a random news headline based on the f{topic}" | |
response = openai.ChatCompletion.create( | |
model="gpt-3.5-turbo-0613", | |
messages=[ | |
{"role": "system", "content": content}, | |
{"role": "user", "content": prompt} | |
], | |
n=1, | |
stop=None, | |
temperature=0.5, | |
) | |
return response.choices[0].message['content'].strip() | |
def get_current_news(topic): | |
"""Get the latest news on a given topic""" | |
headline = generate_response(topic, API_KEY) | |
news_round = { | |
"topic": topic, | |
"headline": headline | |
} | |
return json.dumps(news_round) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment