- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Openai 提供了一个 API,允许您实现 ChaGPT 或 DAL-E 等 AI 服务。对于 Ruby on Rails 应用程序,有几个可用的 gem,其中有 ruby-openai
。
它工作得很好,但唯一的问题是它没有流对话功能,这意味着您一次只能发送一个问题请求,而没有任何对话历史记录。换句话说,API 会忘记您在发送回复后提出的每个问题。
那么我们该如何解决这个问题呢?
最佳答案
基本上,您需要自己实现整个行为。以下是所有实现步骤,包括 dal-e
ai 的实现,其响应包含多张图片而不是一张。
您还可以找到我的整个存储库 HERE 并克隆应用程序!!!
查看Doug伯克利的Notion Page API的基本实现
默认情况下,openai
gem 不具备该功能,因此必须自己实现
# schema.rb
ActiveRecord::Schema[7.0].define(version: 2023_05_29_194913) do
create_table "answers", force: :cascade do |t|
t.text "content"
t.integer "question_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["question_id"], name: "index_answers_on_question_id"
end
create_table "conversations", force: :cascade do |t|
t.text "initial_question"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "historic"
end
create_table "questions", force: :cascade do |t|
t.text "content"
t.integer "conversation_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["conversation_id"], name: "index_questions_on_conversation_id"
end
add_foreign_key "answers", "questions"
add_foreign_key "questions", "conversations"
end
Rails.application.routes.draw do
root "pages#home" # supposes that you have a pages controller with a home action
resources :conversations, only: [:create, :show]
post "question", to: "conversations#ask_question"
end
<h1>Let's talk</h1>
<%= button_to "Create New Conversation", conversations_path, method: :post, class: "btn btn-primary my-3" %>
app/controllers/conversations_controller.rb
class ConversationsController < ApplicationController
def create
@convo = Conversation.create
redirect_to conversation_path(@convo)
end
def show
@convo = Conversation.find(params[:id])
end
def ask_question
@question = Question.new(content: params[:entry])
conversation = Conversation.find(params[:conversation])
@question.conversation = conversation
@question.save
if conversation.historic.nil?
response = OpenaiService.new(params[:entry]).call
conversation.historic = "#{@question.content}\n#{response}"
else
response = OpenaiService.new("#{conversation.historic}\n#{params[:entry]}").call
conversation.historic += "\n#{@question.content}\n#{response}"
end
conversation.save
@answer = Answer.create(content: response, question: @question)
redirect_to conversation_path(conversation)
end
end
app/views/conversations/show.html.erb
<h1>This is your conversation</h1>
<p>Ask your question</p>
<form action="<%= question_path %>", method="post">
<input type="hidden" name="conversation" value="<%= @convo.id %>">
<textarea rows="5" cols="33" name="entry"></textarea>
<input type="submit" class="btn btn-primary">
</form>
<br>
<ul>
<% @convo.questions.each do |question| %>
<li>
Q: <%= question.content.capitalize %> <%= "?" if question.content.strip.last != "?" %>
</li>
<li>
A: <%= question.answers.first.content %>
</li>
<% end %>
</ul>
<%= link_to "Back", root_path %>
关于ruby-on-rails - Ruby on Rails 中的 ruby-openai api gem : how to implement a streaming conversation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76383308/
我收到以下错误:模块“openai”没有属性“ChatCompletion” 我检查了其他帖子。都在说升级OpenAI Python包或者升级Python。我都做了,但没有修复它。 Python:3.
我收到以下错误:模块“openai”没有属性“ChatCompletion” 我检查了其他帖子。都在说升级OpenAI Python包或者升级Python。我都做了,但没有修复它。 Python:3.
我有一个用例,非常需要来自 OpenAI API 的完全确定性响应。然而,玩弄温度似乎无法产生完全的决定论。 import openai openai.organization = "org-..."
OpenAI api 包含一个微调服务,将任务分为“提示”和“完成” https://platform.openai.com/docs/guides/fine-tuning 文档说准确度指标是根据完成
我通过openai的text-davinci-003可以正常返回对话信息,但是目前无法实现上下文关联功能。我搜索了一下,发现有一个“conversation_id”参数,但是添加该参数后,API返回“
我有一个用例,非常需要来自 OpenAI API 的完全确定性响应。然而,玩弄温度似乎无法产生完全的决定论。 import openai openai.organization = "org-..."
OpenAI api 包含一个微调服务,将任务分为“提示”和“完成” https://platform.openai.com/docs/guides/fine-tuning 文档说准确度指标是根据完成
我通过openai的text-davinci-003可以正常返回对话信息,但是目前无法实现上下文关联功能。我搜索了一下,发现有一个“conversation_id”参数,但是添加该参数后,API返回“
我想使用 openai.embeddings_utils import get_embeddings所以已经安装了openai Name: openai Version: 0.26.5 Summary
当我使用 GPT3 的 playground 时,我经常得到带有编号列表和段落格式的结果,如下所示: Here's what the above class is doing: 1. It creat
当我使用 GPT3 的 playground 时,我经常得到带有编号列表和段落格式的结果,如下所示: Here's what the above class is doing: 1. It creat
我想使用 openai.embeddings_utils import get_embeddings所以已经安装了openai Name: openai Version: 0.26.5 Summary
OpenAI/chat GPT也支持docx/pdf文件上传吗?。我想上传多个文件到openAI/chatGPT。我在https://platform.openai.com/docs/api-refe
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
如果我们查看环境的预览,它们会在右下角的动画中显示剧集的增加。 https://gym.openai.com/envs/CartPole-v1/ .是否有明确显示的命令? 最佳答案 我认为 Ope
是否有人从使用 text-embedding-ada-002 的 Azure OpenAI 嵌入部署中获得的结果与 OpenAI 的结果不同?相同的文本,相同的模型,结果在向量空间中相差相当远。 对于
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我正在学习gpt微调 我成功运行了这个命令:pip install --upgrade openai 我无法运行此命令:export OPENAI_API_KEY="sk-xxxxxxxxxxxxxx
如何解决Openai API 不断输出的问题,比如让gpt api 写一篇文章。如果内容中断,可以继续提问,从而继续输出以上内容。这在ChatGPT中很容易做到,但是Openai API加上上面的提示
我是一名优秀的程序员,十分优秀!