# -*- coding: utf-8 -*-
import openai
import pandas as pd
import docx

def read_word_file(file_path):
    doc = docx.Document(file_path)
    full_text = []
    for para in doc.paragraphs:
        full_text.append(para.text)
    return '\n'.join(full_text)

file_path = "entity.docx"
text = read_word_file(file_path)
#print(text)

openai.api_key = "填写自己的账号的api-key,在chatCPT中找"

model_engine = "text-davinci-002"

prompt = "1+1等于几"


completion = openai.Completion.create(
    engine=model_engine,
    prompt=prompt,
    max_tokens=1024,
    n=1,
    stop=None,
    temperature=0.5,
)

message = completion.choices[0].text
print(message)

输出结果:

更多推荐

chatGPT导入到python中