Python AI 速成课:快速打造高效AI

这个文章主要是对python AI 小白的 。实用性很强,不用太多复杂步骤。

第一步:先到Try NVIDIA NIM APIs这个网站

然后使用邮箱注册,很简单和快捷。

第二步:点击微软的phi-3模型,这个API是免费的

第三步: 获取完该API的密钥 ,点击复制

 第四步:直接复制就行,密钥在生成的时候就自动添在代码中了。

 第五步:复制到pycharm中运行效果

第六步:有兴趣的可以改一下代码,做个图形界面版的。如下:

 注意改成自己的API密钥!

import tkinter as tk
from openai import OpenAI

def get_response():
    demo = input_box.get()
    completion = client.chat.completions.create(
        model="microsoft/phi-3-mini-128k-instruct",
        messages=[{"role": "user", "content": demo}],
        temperature=0.2,
        top_p=0.7,
        max_tokens=1024,
        stream=True
    )
    response = ""
    for chunk in completion:
        if chunk.choices[0].delta.content is not None:
            response += chunk.choices[0].delta.content
    output_box.delete(1.0, tk.END)
    output_box.insert(tk.END, response)

client = OpenAI(
    base_url="https://integrate.api.nvidia.com/v1",
    api_key="API接口密钥"                                #输入自己的API密钥
)

root = tk.Tk()
root.title("微软的phi-3 AI大模型")

input_label = tk.Label(root, text="请输入你的内容:")
input_label.pack()

input_box = tk.Entry(root, width=50)
input_box.pack()

submit_button = tk.Button(root, text="提交", command=get_response)
submit_button.pack()

output_label = tk.Label(root, text="输出结果:")
output_label.pack()

output_box = tk.Text(root, wrap=tk.WORD, width=50, height=10)
output_box.pack()

root.mainloop()

下面是效果图:

如果喜欢的话可以给我赞!谢谢支持! 

  • 11
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值