Skip to content

Instantly share code, notes, and snippets.

@john-adeojo
Created July 24, 2023 18:52
Show Gist options
  • Save john-adeojo/d90431d2d6847c01af3fbe497b1267ad to your computer and use it in GitHub Desktop.
Save john-adeojo/d90431d2d6847c01af3fbe497b1267ad to your computer and use it in GitHub Desktop.
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