当前位置:   article > 正文

Openai python调用gpt测试代码_gpt4-1106-preview 对应的openai_api_version

gpt4-1106-preview 对应的openai_api_version
import openai
import os
import os
from openai import OpenAI
def openai_reply(content, apikey):

    client = OpenAI(
        # This is the default and can be omitted
        api_key=apikey,
    )

    chat_completion = client.chat.completions.create(
        messages=[
            {
                "role": "user",
                "content": content,
            }
        ],
        model="gpt-4-1106-preview",
    )
   # print(chat_completion)
    return chat_completion.choices[0].message.content
    
if __name__ == '__main__':
    while True:
        content = input("人类:")
        apikey='your Key'
        text1=openai_reply(content, apikey)

        print("AI:"+text1)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/199367
推荐阅读
相关标签
  

闽ICP备14008679号