videoChat / lib /services /openai.py
ns-devel
Added about and sample questions
0f465e7
raw
history blame
1.24 kB
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"]