movie-chat / tools.py
leek2's picture
updated examples
6f4239f
raw
history blame contribute delete
No virus
1.03 kB
"""
External functions that the chatbot can use at its discretion.
"""
import os
import openai
openai.api_key = os.environ['OPENAI_API_KEY']
def get_movie_recs(context, K=5, min_year=1900, max_year=2024, allowed_movies=None):
allow_list = "" if allowed_movies is None else f"Restrict responses to movies in this list: {allowed_movies}."
system_prompt=f"""
Pretend you are a movie recommendation system. I will give you a conversation between a user
and you (a recommender system). Based on the conversation, reply to me with {K} recommendations
without extra sentences. Give the year the movie was released in your response, e.g. Inception (2010).
Give movies that were released between the years {min_year} and {max_year}. {allow_list}
"""
user_query=f"Here is the conversation:\n{context}"
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{'role': 'system', 'content': system_prompt}, {'role': 'user', 'content': user_query}],
)
return response.choices[0].message.content