File size: 1,236 Bytes
8677234 0f465e7 8677234 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import openai
def get_completion(transcript, question):
"""
Generate a text completion using OpenAI's GPT-3 model.
Args:
prompt (str): The input text prompt for text generation.
model (str, optional): The GPT-3 model to use. Default is "gpt-3.5-turbo-16k".
Returns:
str: The generated text based on the prompt.
"""
messages = [
{
"role": "system",
"content": f"""
Transcript:
```
{transcript}
```
Provided is a video transcript enclosed within triple backticks. Your task is to respond to questions that are either based on or directly related to the content of the video transcript. If the question does not pertain to or is not in the context of the video transcript, please reply with "Please ask questions related to the video only."
Note:
- Do not include `video transcript` in your response, refer it as `video`.
Question: {question}
"""
}
]
print("messages", messages)
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k",
messages=messages,
temperature=0.2, # This is the degree of randomness of the model's output
)
return response.choices[0].message["content"] |