Spaces:
Runtime error
Runtime error
# 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 | |