Skip to content

Latest commit

 

History

History
26 lines (20 loc) · 662 Bytes

README.md

File metadata and controls

26 lines (20 loc) · 662 Bytes

flask-app-gpt (sentiment) api

Template openai connect model

import openai

# Set your OpenAI API key
openai.api_key = "your-openai-api-key"

# Define the text you want to analyze or interact with
text = "I am very happy today!"

# Make a request to the OpenAI GPT-3.5 API
response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo-0125",
    messages=[
        {"role": "system", "content": "Analyze the sentiment of the following text:"},
        {"role": "user", "content": text}
    ]
)

# Extract the response text
response_text = response['choices'][0]['message']['content'].strip()

print("Response from GPT-3.5:", response_text)