Gen Ai Lab - DS
Gen Ai Lab - DS
Course Outcomes:
Page | 1
WEEK-1
1. Generate concise summaries using “prompts” with a maximum of 300 word count,
practicing different AI models(at least 4) .
Prompt Engineering Fundamentals
1. Prompt
A prompt is the initial input or instruction given to an AI model to generate a response. It guides
the AI on what to generate, how to structure the output, and the desired content or context.
2. Elements of a Prompt
Key elements that make up an effective prompt include:
Clarity: Clear and unambiguous instructions.
Specificity: Detailed requirements and constraints.
Context: Background information relevant to the task.
Format: Desired format of the output, such as length, style, or structure.
3. Tips for Designing Prompts
Be Specific: Provide detailed instructions to reduce ambiguity.
Use Examples: Include examples of desired outputs to guide the AI.
Iterate and Refine: Test and refine prompts based on the quality of the outputs.
Leverage Constraints: Use constraints to guide the AI in generating relevant responses.
Maintain Context: Ensure the AI has enough context to understand the task fully.
Generate Prompts for following Use Cases:
Use Case 1: Chatbot Interaction Improvement
Objective
Improve the interaction quality of a customer service chatbot by designing effective prompts.
Example Prompts:
Customer Greeting:
Prompt: "The customer says hello. Generate a friendly and professional greeting
response."
Context: Customer interaction.
Expected Response: "Hello! How can I assist you today?"
Order Status Inquiry:
Prompt: "The customer asks about the status of their order. Provide a response that
asks for their order number."
Context: Order tracking.
Expected Response: "Can you please provide your order number so I can check the
status for you?"
Page | 2
Laboratory Task:
Design prompts to handle various customer inquiries such as returns, shipping details,
and product information.
Test the prompts with a language model and refine based on the responses.
Use Case 2: Content Generation for Marketing
Objective: Generate engaging marketing content by designing effective prompts.
Page | 3
Page | 4
Page | 5
WEEK-2
Program:
import openai
messages = []
system_msg = input("What type of chatbot would you like to create?\n")
messages.append({"role": "system", "content": system_msg})
Page | 6
Output:
Page | 7
Page | 8
Page | 9
WEEK-3
3. Using AI tool create a website for students providing them with study materials.
Program:
import openai
import gradio
openai.api_key = "####"
messages = [{"role": "system", "content": "You are a financial experts that specializes in real
estate investment and negotiation"}]
def CustomChatGPT(user_input):
messages.append({"role": "user", "content": user_input})
response = openai.ChatCompletion.create(
model = "gpt-3.5-turbo",
messages = messages
)
ChatGPT_reply = response["choices"][0]["message"]["content"]
messages.append({"role": "assistant", "content": ChatGPT_reply})
return ChatGPT_reply
demo = gradio.Interface(fn=CustomChatGPT, inputs = "text", outputs = "text", title = "Real Estate Pro")
demo.launch(share=True)
Page | 10
Output:
Page | 11
Page | 12
Page | 13
WEEK-4
Program:
Page | 14
Output:
Page | 15
Page | 16
WEEK-5
Program:
# Step 1: Install necessary libraries
!pip install transformers gtts
# Step 6: Play the audio file (if running in a Jupyter notebook or Colab)
from IPython.display import Audio
Audio(audio_file)
Page | 17
Output:
Page | 18
Page | 19
WEEK-6
Program:
text_clips = []
for i, text in enumerate(generated_text):
generated_text_segment = text['generated_text']
txt_clip = TextClip(generated_text_segment, fontsize=50, color='white',
bg_color='black').set_duration(final_audio.duration)
text_clips.append(txt_clip)
final_clip = concatenate_videoclips(text_clips)
final_clip = final_clip.set_audio(final_audio)
Page | 21
Output:
Page | 22
Page | 23
Page | 24
Page | 25