Bootstrap

AI Python for Beginners-Andrew吴恩达-study notes(1)

1 Instroduction

        python becomes more and more important since AI era has come ,  no matter which career you have , you can mostly benefit by using python to write codes for your daily work.

2 What is computer programming?

        python actually seeps into our life ,not only data scientist uses it but some secretaries also use it , and python has a big community itself,so when you meet some problems about python , you can just ask python learners for all over the world for help. 

3 Writing code with chatbots

 completion:the chatbot's response to the prompt

        there will be a chatbot for us in this class to ask questions about python , although it can not write complex questions but it can definitely write some simple code if needs , and we are encouraged to try to learn python with this chatbot.

4 Nevigating the learning platform

5 running your first program

6 how to succeed in coding

        keep on understanding the code and try to think it in another way

7 data in python

(1)different types of data in Python

①strings

②Multiline strings

 

type() function

 To check the data type, you can use the type() function. 

Since there are no quotes("") around the number Python assumes this is numerical data, and since there is no decimal place on this number, it interprets it as an integer. 

as a calculator

8 combining text and calculations

formatted string

9  variables

10 building LLM prompts with variables

by importing the following content , you can just chat with the AI bot in python , and get its reponse in two ways.

11 Functions:Actions on Data

(1)len()

(2)round()

(3)Using functions in AI programs

1. print_llm_response:

  • Purpose: This function would generate a response from the Language Model and print it directly to the console.
  • Use Case: Use this function when you want to see the response immediately and do not need to use the response for further processing within your code.
import openai

openai.api_key = 'your-api-key-here'

def print_llm_response(prompt):
    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt=prompt,
        max_tokens=100
    )
    print(response.choices[0].text.strip())

# Example usage
print_llm_response("Can you recommend a new song for me to listen to?")

2.get_llm_response:

  • Purpose: This function would generate a response from the Language Model and return it as a value, which you can then use in your program.
  • Use Case: Use this function when you need to use the response for further processing, storage, or any other manipulation within your code.
import openai

openai.api_key = 'your-api-key-here'

def get_llm_response(prompt):
    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt=prompt,
        max_tokens=100
    )
    return response.choices[0].text.strip()

# Example usage
response = get_llm_response("Can you recommend a new song for me to listen to?")
print(response)

 

To interact with a Language Model (LLM) like OpenAI's GPT, you typically use an API. Here are some basic functions and steps you can use to request help from such models:

1.Install the necessary package: If you're using OpenAI's GPT, you'll need the openai package.

pip install openai

2.Import the package and set your API key: Import the openai package and set your API key to authenticate.

import openai

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

3.Create a function to ask the LLM for help: You can create a function that sends a request to the model and returns the response.

import openai

# Set your API key here
openai.api_key = 'your-api-key-here'

def ask_llm(prompt):
    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt=prompt,
        max_tokens=100  # Adjust the max tokens as needed
    )
    return response.choices[0].text.strip()

# Example usage
prompt = "Can you recommend a good book based on my favorite movie, 'Inception'?"
response = ask_llm(prompt)
print(response)

学习网站:

https://learn.deeplearning.ai/courses/ai-python-for-beginners/lesson/1/introduction

;