powerful-horse-58724
06/17/2024, 10:13 PMpowerful-horse-58724
06/18/2024, 7:17 PMfrom openai import OpenAI
client = OpenAI(
api_key="your-apikeystring"
)
def summarize_text(user_prompt, system_prompt=None):
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": system_prompt},
{"role": "user",
"content": user_prompt}
]
)
prompt_and_response = {
"prompt": user_prompt,
"response": response.choices[0].message.content
}
return prompt_and_response
powerful-horse-58724
06/18/2024, 7:18 PMpowerful-horse-58724
06/18/2024, 7:18 PM# prompt: use the function above to summarize some text
summary = summarize_text(test_prompt, instructions)
print(summary["response"])
powerful-horse-58724
06/18/2024, 7:18 PM# Set system prompt to change Summarization behavior
instructions = "Summarize this text. Use only 3 bullet points. explain like I'm 5 wordings "
# Spoiler alert for the first episode of DEVs
test_prompt = """The dominant sequence transduction models are based on complex recurrent or convolutional
neural networks in an encoder-decoder configuration. The best performing models also connect the encoder
and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer,
based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on
two machine translation tasks show these models to be superior in quality while being more parallelizable
and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German
translation task, improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014
English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8
after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the
literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English
constituency parsing both with large and limited training data.
"""