- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 gpt-3.5-turbo
模型并向 OpenAI API 发送以下消息:哪个国家最美丽?
我将其作为 JSON 对象发送:{"role":"user","content":"哪个是最美丽的国家?"}
我以为它会返回 prompt_tokens
的 7
个 token ,但事实并非如此。它返回 prompt_tokens
的 15
个 token 。即使仅发送 .
,它也会返回 prompt_tokens
的 9
token 。
正确吗?
最佳答案
如果您发送{"role": "user", "content": "What is the most beautiful country?"}
作为messages
参数,不仅仅是What is the most beautiful country?
发送到 OpenAI API 端点,但看起来像是整个 "role": "user", "content": "What is the most beautiful country?"
.
我能够使用 tiktoken 确认这一点.
如果你运行get_tokens_long_example.py
您将得到以下输出:
14
get_tokens_long_example.py
import tiktoken
def num_tokens_from_string(string: str, encoding_name: str) -> int:
"""Returns the number of tokens in a text string."""
encoding = tiktoken.get_encoding(encoding_name)
num_tokens = len(encoding.encode(string))
return num_tokens
print(num_tokens_from_string("'role':'user','content':'What is the most beautiful country?'", "cl100k_base"))
如果你运行get_tokens_short_example.py
您将得到以下输出:
8
get_tokens_short_example.py
import tiktoken
def num_tokens_from_string(string: str, encoding_name: str) -> int:
"""Returns the number of tokens in a text string."""
encoding = tiktoken.get_encoding(encoding_name)
num_tokens = len(encoding.encode(string))
return num_tokens
print(num_tokens_from_string("'role':'user','content':'.'", "cl100k_base"))
您说 OpenAI API 报告 15
第一个示例中使用的 token 和 9
第二个示例中使用的标记。您可能注意到我得到了 14
和8
使用 tiktoken 的代币(即两个示例中都少了 1 个代币)。这似乎是一个known tiktoken problem那应该是solved .
无论如何,我并没有深入研究为什么我仍然少了 1 个代币,但我能够证明这不仅仅是 What is the most beautiful country?
发送到 OpenAI API 端点。
更多关于tiktoken的信息,请参见 this answer .
关于openai-api - OpenAI ChatGPT (GPT-3.5) API : Why does the API report more prompt_tokens used for the messages parameter than I thought it would?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76347639/
ChatGPT 以其强大的信息整合和对话能力惊艳了全球,在自然语言处理上面表现出了惊人的能力。这么强大的工具我们都想体验一下,那么 ChatGPT 怎么用呢?本文将给你逐步详细介绍。 Chat GPT
我有一个想法创建一个应用程序,可以通过chatgpt api绘制chatgpt讨论的思维导图。但是,如何编写一个提示来控制chatgpt写出固定格式的思维导图以便于解析呢? 最佳答案 这可以使用 Me
我有一个想法创建一个应用程序,可以通过chatgpt api绘制chatgpt讨论的思维导图。但是,如何编写一个提示来控制chatgpt写出固定格式的思维导图以便于解析呢? 最佳答案 这可以使用 Me
openAI/chatGPT也支持docx/pdf文件上传吗? 我想上传多个文件到 openAI/chatGPT。我尝试了 https://platform.openai.com/docs/api-r
openAI/chatGPT也支持docx/pdf文件上传吗? 我想上传多个文件到 openAI/chatGPT。我尝试了 https://platform.openai.com/docs/api-r
OpenAI/chat GPT也支持docx/pdf文件上传吗?。我想上传多个文件到openAI/chatGPT。我在https://platform.openai.com/docs/api-refe
1.概述 OpenAI 持续突破人工智能的边界,推出了其最新模型 ChatGPT-4o,作为 ChatGPT-4 的继承者,该模型有望带来显著的提升和创新功能。本文将深入解析 ChatGPT-4 与
ChatGPT 是OpenAI 发布的一个全新的聊天机器人模型。它到底有多厉害呢?我注册后体验了一下,你会感觉背后有个真人跟你在聊天。例如: 代码不仅可以运行,还特么有每行带有中文注释,这完全是降维打
ChatGPT+Mermaid语言实现技术概念可视化 本文旨在介绍如何使用ChatGPT和Mermaid语言生成流程图的技术。在现代软件开发中,流程图是一种重要的工具,用于可视化和呈现各种流程
当谈到人工智能技术的时候,我们会经常听到GPT这个术语。它代表“Generative Pre-trained Transformer”,是一种机器学习模型,采用了神经网络来模拟人类语言的理解
作者:京东科技 赵龙波 “贾维斯,你在吗?” “随时待命,先生。” 类似《钢铁侠》里的人工智能助理贾维斯,ChatGPT或许是你的随时待命的助手。ChatGPT在大量文本数据上进行
ChatGPT 火爆出圈,但是 OpenAI(开发 ChatGPT 的公司)却不对国内用户正式开放使用。但是,我们仍然有办法可以在第一时间体验到这个超强 AI。下面我来教你如何
最近的热门话题,OpenAI 推出的ChatGPT绝对榜上有名!但是不说注册难度,只说每次需要一些不可抗力的原因才能访问使用就很麻烦,大部分人无法体验到,本文介绍的方式直接对接个人微信(不是公众号)非
我正在从 ChatGPT API 中提取与单词列表相对应的单词嵌入。我想知道是否有一种类似于Gensimmost_similar方法的方法来提取整个模型中与我想要的术语最相似的n个单词。 最佳答案 是
有谁知道我是否可以使用 streamlit_chat 消息在 Streamlit 中显示类似 chatgpt 的流响应? 我需要类似 message(streaming=True) 或任何其他替代方案
我正在构建一个平台,用户可以在其中上传自定义数据并构建聊天机器人。 我正在考虑使用 lanchain + open ai embeddings + chat gpt api + pinecone 来管
我正在尝试设置函数来调用我最近一直在从事的一个项目,但我似乎无法让它工作 我查找了文档,但只找到了无法很好地解释它的 YouTube 视频。我尝试过运行各种示例,但没有任何效果对我有用。这就是我所拥有
我正在研究将 html 页面从一种语言翻译成另一种语言的想法——翻译可见文本(如果更具体的话)。我已经将 html 拆分为标记和文本 block ,现在我需要通过 ChatGPT 翻译文本。但对于我的
我正在研究将 html 页面从一种语言翻译成另一种语言的想法——翻译可见文本(如果更具体的话)。我已经将 html 拆分为标记和文本 block ,现在我需要通过 ChatGPT 翻译文本。但对于我的
我正在从 ChatGPT API 中提取与单词列表相对应的单词嵌入。我想知道是否有一种类似于Gensimmost_similar方法的方法来提取整个模型中与我想要的术语最相似的n个单词。 最佳答案 是
我是一名优秀的程序员,十分优秀!