| import openai |
| from openai import OpenAI |
| import os |
|
|
| |
| openai.api_key = os.getenv("OPENAI_KEY") |
|
|
| |
| client = OpenAI(api_key=openai.api_key) |
|
|
| def model_api(input, prompt_type): |
| return prompt_type(input) |
|
|
| def sentiment(text): |
| print(text) |
| |
| prompt = f"""You are trained to analyze and detect the sentiment of the given text. |
| If you are unsure of an answer, you can say "not sure" and recommend the user review manually. |
| Analyze the following text and determine if the sentiment is: POSITIVE, NEGATIVE or NEUTRAL. |
| Reply in single word. |
| Examples |
| Input: dress was beautiful. Output: POSITIVE |
| Input: pizza had weird smell. Output: NEGATIVE |
| Input: {text}. Output:""" |
|
|
| |
| response = client.chat.completions.create( |
| model="gpt-3.5-turbo", |
| messages=[ |
| {"role": "system", "content": "You are a helpful assistant."}, |
| {"role": "user", "content": prompt} |
| ], |
| |
| temperature=0 |
| ) |
| print(response) |
| |
| sentiment = response.choices[0].message.content.strip() |
|
|
| return sentiment |
|
|
| def image_gen(text): |
| print(text) |
| response = client.images.generate( |
| model="dall-e-3", |
| prompt= text, |
| size="1024x1024", |
| quality="standard", |
| n=1, |
| ) |
|
|
| image_url = response.data[0].url |
| return image_url |