我使用自己的数据在 OpenAI 上微调了引擎。我可以毫无问题地访问 Playground 中的引擎,但是,当我尝试使用 Node 和 openai Node 库以编程方式访问它时,我收到“找不到引擎”错误。奇怪的是,我发誓它以前就有效。
无论如何,这是我的代码:
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
async function getDream() {
const completion = await openai.createCompletion("davinci:ft-personal-2022-04-09-19-12-54", {
prompt: "I dreamed",
});
console.log(completion.data.choices[0].text);
}
getDream();
Run Code Online (Sandbox Code Playgroud)
这是错误:
error: {
message: 'Engine not found',
type: 'invalid_request_error',
param: null,
code: null
}
Run Code Online (Sandbox Code Playgroud)
我尝试运行相同的代码,但使用常规引擎(davinci)。这样效果很好。我仔细检查了我的微调引擎的名称是否正确,并使用引擎 ID 进行了尝试,以防万一。似乎什么都不起作用。
PS - 我已经使用 OpenAI CLI 运行了这个程序,并且openai api completions.create -m davinci:ft-personal-2022-04-09-19-12-54 -p "I dreamed"运行得很好。
我在使用 OpenAI API 时遇到了问题,基本上我想做的是流式传输从 openai API 响应流回的每个数据节点,并在从 API 调用流入时一次输出一个数据节点,但我不知道这是如何完成的,我研究了几个小时,但找不到任何关于如何使用 PHP 实现这一点的信息。
如何让我的代码在 API 流式传输数据时实时输出每个数据节点?
以下是我能想到的最好的,它在调用完成后立即输出所有数据,但它不会流入数据。
function openAI(){
$OPENAI_API_KEY="API_KEY_GOES_HERE";
$user_id="1"; // users id optional
$prompt="tell me what you can do for me.";
$temperature=0.5; // 1 adds complete randomness 0 no randomness 0.0
$max_tokens=30;
$data = array('model'=>'text-davinci-002',
'prompt'=>$prompt,
'temperature'=>$temperature,
'max_tokens'=>$max_tokens,
'top_p'=>1.0,
'stream'=>TRUE,// stream back response
'frequency_penalty'=>0.0,
'presence_penalty'=>0.0,
'user' => $user_id);
$post_json= json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, …Run Code Online (Sandbox Code Playgroud) 我只是使用 OpenAI API 在 Python 中尝试一些简单的函数,但遇到了错误:
我有一个正在使用的有效 API 密钥。
代码:
>>> import os
>>> import openai
>>> openai.api_key = os.getenv("I have placed the key here")
>>> response = openai.Completion.create(model="text-davinci-003", prompt="Say this is a test", temperature=0, max_tokens=7)
Run Code Online (Sandbox Code Playgroud)
在 GPT-3 API 的文档中,它说:
需要记住的一个限制是,对于大多数模型来说,单个 API 请求在提示和完成之间最多只能处理 2,048 个令牌(大约 1,500 个单词)。
在微调模型的文档中,它说:
训练样本越多越好。我们建议至少有几百个例子。一般来说,我们发现数据集大小每增加一倍都会导致模型质量线性增加。
我的问题是,1,500 字的限制是否也适用于微调模型?“数据集大小加倍”是否意味着训练数据集的数量而不是每个训练数据集的大小?
我正在编写一个简单的 PHP 脚本,没有依赖项来访问 ChatGPT API,但它抛出了一个我不明白的错误:
这是到目前为止的脚本:
$apiKey = "Your-API-Key";
$url = 'https://api.openai.com/v1/chat/completions';
$headers = array(
"Authorization: Bearer {$apiKey}",
"OpenAI-Organization: YOUR-ORG-STRING",
"Content-Type: application/json"
);
// Define messages
$messages = array();
$messages["role"] = "user";
$messages["content"] = "Hello future overlord!";
// Define data
$data = array();
$data["model"] = "gpt-3.5-turbo";
$data["messages"] = $messages;
$data["max_tokens"] = 50;
// init curl
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if (curl_errno($curl)) {
echo 'Error:' . curl_error($curl); …Run Code Online (Sandbox Code Playgroud) 我想根据每行语音的内容将视频脚本分割成章节。脚本将用于为每一章生成一系列开始和结束时间戳。这类似于 YouTube 现在“自动章节”视频的方式。
.srt 转录本示例:
...
70
00:02:53,640 --> 00:02:54,760
All right, coming in at number five,
71
00:02:54,760 --> 00:02:57,640
we have another habit that saves me around 15 minutes a day
...
Run Code Online (Sandbox Code Playgroud)
我在使用 ChatGPT 时运气不佳,因为它发现很难按主题进行分段并准确地重新收集开始和结束时间戳。我现在正在探索是否还有其他选择可以做到这一点。
我知道一些 python 库可以实现基于时间序列的主题建模。我还阅读了有关文本平铺作为另一种选择的内容。有哪些选择可以实现这样的结果?
注意:上面的格式 (.srt) 不是必需的。这只是输入是带有开始和结束时间戳的文本内容列表的想法。
python nlp machine-learning openai-api automatic-speech-recognition
我正在使用 Python 3.10 和 FastAPI0.92.0编写服务器发送事件 (SSE) 流 api。Python 代码如下所示:
from fastapi import APIRouter, FastAPI, Header
from src.chat.completions import chat_stream
from fastapi.responses import StreamingResponse
router = APIRouter()
@router.get("/v1/completions",response_class=StreamingResponse)
def stream_chat(q: str, authorization: str = Header(None)):
auth_mode, auth_token = authorization.split(' ')
if auth_token is None:
return "Authorization token is missing"
answer = chat_stream(q, auth_token)
return StreamingResponse(answer, media_type="text/event-stream")
Run Code Online (Sandbox Code Playgroud)
这是chat_stream函数:
import openai
def chat_stream(question: str, key: str):
openai.api_key = key
# create a completion
completion = openai.Completion.create(model="text-davinci-003",
prompt=question,
stream=True)
return …Run Code Online (Sandbox Code Playgroud) 这是完整的代码。它在https://learn.deeplearning.ai/笔记本上运行得非常好。但是当我在本地计算机上运行它时,出现以下错误
ImportError:无法导入 docarray python 包
我尝试过重新安装/强制安装 langchain 和 lanchain[docarray] (pip 和 pip3)。我使用迷你 conda 虚拟环境。蟒蛇版本3.11.4
from langchain.vectorstores import DocArrayInMemorySearch
from langchain.schema import Document
from langchain.indexes import VectorstoreIndexCreator
import openai
import os
os.environ['OPENAI_API_KEY'] = "xxxxxx" #not needed in DLAI
docs = [
Document(
page_content="""[{"API_Name":"get_invoice_transactions","API_Description":"This API when called will provide the list of transactions","API_Inputs":[],"API_Outputs":[]}]"""
),
Document(
page_content="""[{"API_Name":"get_invoice_summary_year","API_Description":"this api summarizes the invoices by vendor, product and year","API_Inputs":[{"API_Input":"Year","API_Input_Type":"Text"}],"API_Outputs":[{"API_Output":"Purchase Volume","API_Output_Type":"Float"},{"API_Output":"Vendor Name","API_Output_Type":"Text"},{"API_Output":"Year","API_Output_Type":"Text"},{"API_Output":"Item","API_Output_Type":"Text"}]}]"""
),
Document(
page_content="""[{"API_Name":"loan_payment","API_Description":"This API calculates the monthly payment for a loan","API_Inputs":[{"API_Input":"Loan_Amount","API_Input_Type":"Float"},{"API_Input":"Interest_Rate","API_Input_Type":"Float"},{"API_Input":"Loan_Term","API_Input_Type":"Integer"}],"API_Outputs":[{"API_Output":"Monthly_Payment","API_Output_Type":"Float"},{"API_Output":"Total_Interest","API_Output_Type":"Float"}]}]"""
),
Document( …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 MERN 构建 AI 图像生成网站,但收到此错误:
请求的模块“openai”不提供名为“Configuration”的导出。
file:///C:/Users/Rashmika%20Satish/ai_website/server/routes/dalleRoutes.js:3 从“openai”导入{配置,OpenAIApi};^^^^^^^^^^^^^ 语法错误:请求的模块“openai”未在 ModuleJob._instantiate(节点:internal/modules/esm/module_job:124:21)处提供名为“Configuration”的导出异步 ModuleJob.run (节点:内部/模块/esm/module_job:190:5)
Node.js v18.15.0 [nodemon] 应用程序崩溃 - 启动前等待文件更改...
这是 dalleRoutes.js 页面:
import express from 'express';
import * as dotenv from 'dotenv';
import {Configuration, OpenAIApi} from 'openai';
dotenv.config();
const router = express.Router();
Run Code Online (Sandbox Code Playgroud)
这是index.js页面:
import express from 'express'
import * as dotenv from 'dotenv';
import cors from 'cors';
import connectDB from './mongodb/connect.js';
import postRoutes from './routes/postRoutes.js';
import dalleRoutes from './routes/dalleRoutes.js';
dotenv.config();
const app = express();
app.use(cors());
app.use(express.json({limit: '50mb'}));
app.use('/api/v1/post', postRoutes);
app.use('/api/v1/dalle', dalleRoutes); …Run Code Online (Sandbox Code Playgroud) openai-api ×10
python ×3
chatgpt-api ×2
gpt-3 ×2
streaming ×2
automatic-speech-recognition ×1
express ×1
fastapi ×1
github ×1
gpt-4 ×1
javascript ×1
langchain ×1
mern ×1
nlp ×1
node.js ×1
php ×1
python-3.x ×1
reactjs ×1