File size: 1,030 Bytes
3009d0e
 
 
 
 
 
 
 
6f4239f
 
3009d0e
 
 
c3bef02
6f4239f
3009d0e
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""
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