OpenAI - Getting Started
https://www.mediabiznet.com.au/the-openai-codex-translates-english-into-programming-code/

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:

  1. Account Setup: Create an OpenAI account or sign in if you already have one. Navigate to the API key page and generate a new secret key. Remember to keep this key secure and avoid sharing it with anyone.
  2. Choose Your Language: You can use either Python, curl, or Node.js to interact with the OpenAI API. I will be using Python for the demo since I am most comfortable with the language.
  3. Setting Up Python: Install Python if you haven’t already. Optionally, set up a virtual environment (recommended for better isolation). Install the OpenAI Python library using pip.
  4. Configure Your API Key: Set up your API key for all projects (recommended) or for a specific project.
  5. Sending Your First API Request: Create a Python file (e.g., openaitest.py) and paste the following example code:

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.

  1. System: This helps in providing context to what the system is like, In the above example we set it as a poetic assistant and set the context for its capabilities. In short it allows you to specify the way the model answers questions.
  2. User: This helps in providing context to user query, setting up the users' expectations for the reply.
  3. Assistant: This helps give context to how the system replies regarding the query. Eg: {"role": "assistant", "content": "Hi, how may I help you today"}

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.

  1. Objective: Clearly define what you want to achieve as a result information, creativity or problem solving.
  2. Clarity: Clarity helps AI better understand the context.
  3. Context Matters: Provide enough background for AI to understand the scenario without making it overly complex.
  4. Iterate: Iteration helps in finding the best prompt that can get the job done.
  5. Evaluate: Assess the effectiveness of your prompt and adapt.

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.

DALL-E 3 generated Image
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!! :)

要查看或添加评论,请登录

社区洞察

其他会员也浏览了