匠心精神 - 良心品质腾讯认可的专业机构-IT人的高薪实战学院

咨询电话:4000806560

chagpt的用法

async def generate_article(request):
    data = await request.json()
    title = data["title"]
    api_key = data["api_key"]
    print(f"接受到title {title} api_key {api_key}")
    #
    openai.api_key = api_key
    messages = [{'role': 'system', 'content': '你是一个资深的技术和文学专家,很擅长写一些运维类和编程类的技术文章'},
                {'role': 'user', 'content': f'以{title},写一篇技术文章!'}]
    response = openai.ChatCompletion.create(
        model='gpt-3.5-turbo',
        messages=messages,
        temperature=0.9,
        max_tokens=4000,
    )

    response = response.choices[0]["message"]["content"]
    print(f"response {response}")
    return web.json_response({"status": 200, "content": f"{response}"})