openai 代理

 import openai

# openai.api_key = "abc"
# openai.api_base = "http://172.30.48.1:8085/openai/v1"

openai.proxy = {
    "http":"http://172.30.48.1:7890",
    "https":"http://172.30.48.1:7890"
}
openai.api_key="sk-"
#获取模型名称
model_list= [item['id'] for item in openai.Model.list()['data']]


# response = openai.ChatCompletion.create(
#             model="gpt-3.5-turbo",
#             messages=[
#                 {"role": "system", "content": "Describe a short paragraph about tamil."},
#             ]
#         )

# for solution in response.choices:
#     print(solution.message.content)


def get_completion(prompt,model='gpt-3.5-turbo'):
    messages=[{'role':"user","content":prompt}]
    if model in model_list:
        response=openai.ChatCompletion.create(
            model=model,
            messages=messages,
            temperature=0.5,
        )
        return response.choices[0].message["content"]
    else:
        return "模型名称错误!"

prompt = f"""Describe a short paragraph about hib vaccine"""
# get_completion(prompt,model='xxx')

get_completion(prompt)

评论

此博客中的热门博文

V2ray websocket(ws)+tls+nginx分流

Rstudio 使用代理