Basic application of large language model LLM

ChatGPT is a new chat robot model released by the artificial intelligence research laboratory OpenAI on November 30, 2022. It is a natural language processing tool driven by artificial intelligence technology. It can conduct conversations by learning and understanding human language, and can also interact according to the context of the chat. It can truly chat and communicate like a human being, and can even complete tasks such as writing emails, video scripts, copywriting, translation, and code.

DALL-E is a generative pretrained transformer (GPT) model developed by OpenAI that can generate images from textual descriptions. It is trained on text and image datasets, enabling it to understand the relationship between the two and generate images that match a given textual description.

Description of Chatbot Interface Parameters

  • model : model noun
  • prompt : your question to the bot
  • temperature : A parameter to customize the behavior of the model, which controls the level of randomness of the generated text. Higher temperatures result in more varied and possibly less coherent responses, while lower temperatures result in more predictable and possibly coherent responses
  • max_tokens : the length of the response sentence

Let's introduce a simple and practical ChatGPT chat applet based on the windows command line window through python. First we need to install the openai package on the command line:

pip install openai

Next, you can start writing the chat program chat.py based on the windows command line window:

import openai
import os
os.system('')

#注册的api_key
openai.api_key = "sk-xxxxxxxxxx"
def get_answer(question):
    response = openai.Completion.create(
    model="text-davinci-003",
    prompt=question,
    temperature=0.5, 
    max_tokens=1024 )    
    return response.choices[0].text

def ask_question():
    flag=True
    greeting="\033[1;31m我是ChatGPT聊天机器人,我可以回答您的任何问题!如果您想退出,请输入:quit\033[0m"
    print()
    print(greeting)
    print()
    while(flag==True):
        question = input()
        if(question!='quit'):
            answer=get_answer(question)
            answer = answer[2:]
            print()
            print(f"\033[1;31m机器人:{answer}\033[0m")
            print()

        else:
            flag=False
            print()
            print("\033[1;31m机器人:后会有期,bye!\033[0m")   
           
ask_question()

Next we copy the chat.py file to d:\, and then we execute the chat program in the windows command line:

python d:\chat.py

Here's an interesting conversation between me and the bot:

 

 

 

 DALL-E's AI drawing  interface parameter description

  • model : DALL-E model for image generation.
  • prompt : the text prompt you want to use to generate the image
  • response_format : The format of the response - in this case "url".
  • n : the number of generated pictures, the default is 1
  • size : The size of the generated image is 256×256, 512×512, 1024×1024

import openai
from PIL import Image
from io import BytesIO
import requests as req

#注册的api_key
openai.api_key="sk-jWpXXXXXXXXXX" 

#用来生成图像的文本提示
prompt="一只坐在椅子上仰望星空的猫" 
#生成图像
response=openai.Image.create(prompt=prompt,
              n=3,
              model="image-alpha-001",
              size="512x512",
              response_format="url") 

#第一张图片
image_rul=response["data"][0]["url"]
res=req.get(image_rul)
Image.open(BytesIO(res.content))

 

#第二张图片
image_rul=response["data"][1]["url"]
res=req.get(image_rul)
Image.open(BytesIO(res.content))

 

#第三张图片
image_rul=response["data"][2]["url"]
res=req.get(image_rul)
Image.open(BytesIO(res.content))

 summary

The ChatGPT chat robot is relatively effective. The robot has a wide range of knowledge, and there are almost no questions that cannot be answered. It can even write code for you, but the disadvantage is that the robot can only answer the current question and cannot refer to the content of the context. Answer questions accurately, such as if you ask the robot for its name multiple times, the robot will give a different name each time, and sometimes the robot will give obviously wrong answers. Personally, I feel that the biggest advantage of ChatGPT is that it has a wide range of knowledge, like an encyclopedia, it knows everything, but the energy of combining context is relatively poor.

DALL-E is an AI painting model of openai. This model is a little immature, and there is still a gap compared with the more mature AI painting models in the industry. DALL-E's painting effect is still relatively rough, the picture lacks aesthetic feeling, and the shape and outline of the object are not very ideal, so there is still a lot of room for improvement in this model.

Supongo que te gusta

Origin blog.csdn.net/weixin_42608414/article/details/128857410
Recomendado
Clasificación