Spaces:
Runtime error
Runtime error
File size: 539 Bytes
4fe5752 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# app/openai_integration.py
import openai
import os
# Set your OpenAI API key from environment variables
openai.api_key = os.getenv("OPENAI_API_KEY")
def generate_summary(text: str) -> str:
"""
Generate a summary of the given text using GPT-4.
"""
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[{"role": "user", "content": f"Please summarize the following text:\n\n{text}"}],
temperature=0.3
)
summary = response.choices[0].message["content"].strip()
return summary
|