Azure OpenAI API使用示例
import os
import openai
openai.api_type = "azure"
openai.api_version = "2023-05-15"
openai.api_base = "https://xxx -chatgpt-pg.openai.azure.com/"
openai.api_key = "xxxxxxxxxxx"
input_text = "大海"
chat_response = openai.ChatCompletion.create(
engine="my_model",
temperature=0,
max_tokens=800,
top_p=0.95,
frequency_penalty=0,
presence_penalty=0,
stop=None,
messages = [{
"role":"user",
"content": f"假如你是一个调色专家,请根据我的提示返回相关联的8个颜色。数据以python JSON元组的形式返回,数组中每个元素是RBG16进制的字符串,数组总长度为8。请参考格式, [\"#1b2b3b\" ,\"#1c2c3c\" ], 我的提示是:{input_text},请返回相关颜色"
}]
)
print(chat_response.choices[0]['message']['content'])
[ "#0077be" , "#008cba" , "#00a0d1" , "#00bfff" , "#1e90ff" , "#4169e1" , "#6495ed" , "#87ceeb" ]