OpenAI - Getting Started
The world of AI has seen some significant changes in the recent time with the Large Language Model facilitating with content generation by predicting the next token based on the best fit for the prompt. Google Gemini is a great example of integrating LLM as a product by offering multimodal tasks by processing text, images, audio or video seamlessly and generating desired results. OpenAI being open source also provides this facility in the form of DALL-E for image generation, GPT-4 for text generation and SORA for video generation.
Although I am not sure how to go about building own generative AI platform from scratch like OpenAI, I have found API usage pretty simple and straight forward for any coder.
API:
from openai import OpenAI
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."},
{"role": "user", "content": "Compose a poem that explains the concept of recursion in programming."}
]
)
print(completion.choices[0].message)
Run the code using python openaitest.py in your terminal or IDE.
There are three major roles to be used for providing context to the prompt.
In my experience so far, user is the most powerful role of them all and carries most of the important bits of the information. For example, Let’s say I want to issue an instruction with a predefined string A, followed by the user input B. I can do this in two ways:
Method 1: role=user; message=A+B;
Method 2: role=system, message=A; role=user, message=B.
领英推荐
From the few tests I’ve done, it seems to give the same result. The only difference I saw is organizational - Method 2 is more structured and is probably better for scaling.
Effective prompting is the key to utilizing models like GPT 4 to its max potential helping in influencing the output quality and its relevance. below are few strategies you can keep in mind while writing prompts.
Introduction to DALL-E: Image generation API by OpenAI:
In a world where pixels are the new playgrounds, AI Instagram models are strutting their stuff and catching the attention of both fashionistas and technophiles alike. These digital divas, powered by artificial intelligence, are revolutionizing the influencer marketing scene with their impeccably curated feeds and flawless aesthetics. With their ever-present smiles and perfectly angled selfies, they are blurring the lines between reality and simulation, sparking conversations about authenticity and creativity in the digital age. Get ready to embrace the future of influencers, where algorithms rule and filters reign supreme.
I tried my hand at creating few AI generated models and after few failed attempts of creating unrealistic cartoonish images I finally got the below image which seems quite realistic to me.
import json
import openai
from openai import OpenAI
client = OpenAI()
# Your OpenAI API Key
openai.api_key = 'Your Key'
Prompt="A photorealistic portrait of a 26-year-old Indian woman with long, luxurious brunette hair and captivating black eyes. Her expression should be natural and inviting, illuminated by the soft, warm light of the golden hour. The setting for this portrait should be a picturesque outdoor scene, such as a sun-kissed park or beach. Generate this image and try to achieve a flattering and engaging perspective."
response = client.images.generate(
model="dall-e-3",
prompt = Prompt,
n=1, # Number of images to generate
quality="standard" # Image size, if applicable based on the API selection
)
# Assuming the response includes a URL to the generated image
image_url = response.data[0].url
print(f"Generated Image URL: {image_url}")
Now if I generate enough images of this AI from different angles and expression, I got myself an Instagram model who is not earning and taking all my money. Am I in a toxic relationship with my AI.
Anyways I will be expanding on this article as and when I dive deeper into the world of AI. Until then happy Prompting!! :)