当前位置: 首页 > news >正文

chatgpt 接口使用(一)

使用api实现功能

参考链接:https://platform.openai.com/examples

安装库:
pip3 install openai

例如:

import os
import openaiopenai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=[{"role": "system","content": "You will be provided with unstructured data, and your task is to parse it into CSV format."},{"role": "user","content": "There are many fruits that were found on the recently discovered planet Goocrux. There are neoskizzles that grow there, which are purple and taste like candy. There are also loheckles, which are a grayish blue fruit and are very tart, a little bit like a lemon. Pounits are a bright green color and are more savory than sweet. There are also plenty of loopnovas which are a neon pink flavor and taste like cotton candy. Finally, there are fruits called glowls, which have a very sour and bitter taste which is acidic and caustic, and a pale orange tinge to them."}],temperature=0,max_tokens=256
)print(response)

输出:

{"id": "chatcmpl-7hwS9AKlAdarpkhXq3vHJAqnAETvz","object": "chat.completion","created": 1690707153,"model": "gpt-3.5-turbo-0613","choices": [{"index": 0,"message": {"role": "assistant","content": "Fruit,Color,Taste\nneoskizzles,purple,candy\nloheckles,grayish blue,tart\npounits,bright green,savory\nloopnovas,neon pink,cotton candy\nglowls,pale orange,sour and bitter"},"finish_reason": "stop"}],"usage": {"prompt_tokens": 161,"completion_tokens": 58,"total_tokens": 219}
}

利用私有数据

参考:
https://github.com/langchain-ai/langchain
https://github.com/techleadhd/chatgpt-retrieval

pip3 install langchain openai chromadb tiktoken unstructured

在chatgpt-retrieval测试:

python3 chatgpt.py "what is my dog's name"

出现错误:

Chroma requires sqlite3 >= 3.35.0

解决方法:
1、安装

pip3 install pysqlite3-binary

2、根据出错的引用文件,找到
修改如下:
在这里插入图片描述

再次执行:
在这里插入图片描述

http://www.lryc.cn/news/104532.html

相关文章:

  • 【个人笔记】Linux 服务管理两种方式service和systemctl
  • HCIP中期考试实验
  • 【WebRTC---源码篇】(二十二)WebRTC的混音处理
  • MTK system_server 卡死导致手机重启案例分析
  • 加强 Kubernetes 能力:利用 CRD 定义多版本资源的实现方式
  • 区块链应用 DApp 开发需要掌握的技能
  • 关于新版本selenium定位元素报错:‘WebDriver‘ object has no attribute ‘find_element_by_id‘等问题
  • c++通过自然语言处理技术分析语音信号音高
  • [pymc3][python]pymc3安装后测试代码2
  • Go语言time库,时间和日期相关的操作方法
  • JVM总结笔记
  • C++ 缓存再排序,解决多线程处理后的乱序问题,不知道思路对不对[挠下巴]
  • 华为数通HCIA-地址分类及子网划分
  • Linux第七章之gdb与makefile使用
  • Mycat-Balance使用指南
  • 玩转顺序表——【数据结构】
  • SSE(Server-Sent Events,服务器推送事件)和sockets(套接字)通信区别
  • 【设计模式——学习笔记】23种设计模式——代理模式Proxy(原理讲解+应用场景介绍+案例介绍+Java代码实现)
  • 大学英语四新视野 课后习题+答案翻译 Unit1~Unit8
  • Java入门指南:Java语言优势及其特点
  • Jenkins 节点该如何管理?
  • hugging face下载数据集
  • 解决Django报错 : No module named ‘MySQLdb‘
  • 【Docker】Docker的优势、与虚拟机技术的区别、三个重要概念和架构及工作原理详细讲解
  • 【论文笔记】RCM-Fusion: Radar-Camera Multi-Level Fusion for 3D Object Detection
  • STM32-风速传感器(ADC)
  • 【conda】配置国内镜像源
  • python森林生物量(蓄积量)数据处理到随机森林估算全流程
  • 使用Freemarker模版导出xls文件使用excel打开提示文件损坏
  • 初识Linux