**已关闭。**此问题为not about programming or software development。目前不接受回答。
此问题似乎与a specific programming problem, a software algorithm, or software tools primarily used by programmers无关。如果您认为此问题与another Stack Exchange site的主题相关,可以发表评论,说明在何处可以回答此问题。
3天前关闭。
Improve this question的
我希望你能帮助我解决这个问题.我正在测试聊天GPT API,与支付选项.这里是我的机器人回来的代码.前面是正确的工作:这是在节点与llamaindex包在节点我运行的代码
export OPENAI_API_KEY=sk-etc && node bot.js
字符串
聊天gpt API返回给我:您超过了当前配额,请检查您的计划和账单详细信息。
我在chat GPT上只花了0.01美元。
const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const { join } = require('node:path');
const fs = require("fs/promises");
const { MetadataMode, IndexDict,Document, VectorStoreIndex, TextNode,OpenAI,serviceContextFromDefaults, getNodesFromDocument , RetrieverQueryEngine, SentenceSplitter} = require("llamaindex");
app.get('/', (req, res) => {
res.sendFile(join(__dirname, 'index.html'));
});
async function init() {
const essay = await fs.readFile(
"cv.txt",
"utf-8",
);
// Create Document object with essay
const document = new Document({text: essay});
const nodes = getNodesFromDocument(
new Document({text: essay}),
new SentenceSplitter({chunkSize: 1024, chunkOverlap: 20}),
);
const nodesWithEmbeddings = await VectorStoreIndex.getNodeEmbeddingResults(
nodes,
serviceContextFromDefaults(),
true,
);
const _nodesWithEmbedding = nodesWithEmbeddings.map((nodeWithEmbedding) => ({
text: nodeWithEmbedding.getContent(MetadataMode.NONE),
embedding: nodeWithEmbedding.getEmbedding(),
}))
const embeddingResults = _nodesWithEmbedding.map((config) => {
return new TextNode({text: config.text, embedding: config.embedding});
});
const indexDict = new IndexDict();
for (const node of embeddingResults) {
indexDict.addNode(node);
}
// Split text and create embeddings. Store them in a VectorStoreIndex
const index = await VectorStoreIndex.init({
indexStruct: indexDict,
serviceContext: serviceContextFromDefaults({
llm: new OpenAI({
model: "gpt-4",
temperature: 0.5,
topP: 0.8,
}),
}),
});
await index.vectorStore.add(embeddingResults);
if (!index.vectorStore.storesText) {
await index.docStore.addDocuments(embeddingResults, true);
}
await index.indexStore?.addIndexStruct(indexDict);
index.indexStruct = indexDict;
const retriever = index.asRetriever();
retriever.similarityTopK = 20 ?? 2;
const queryEngine = new RetrieverQueryEngine(retriever);
const io = new Server(server, {
cors: {
origin: "*",
methods: ["GET", "POST"],
//allowedHeaders: ["my-custom-header"],
//credentials: true
},
path: '/'
});
io.on('connection', async (socket) => {
// Query the index
// queryEngine = index.asQueryEngine();
socket.on('userMessage', async (msg) => {
const response = await queryEngine.query(msg);
io.emit('botMessage', response.toString());
});
});
server.listen(3000, () => {
console.log('listening on *:3000');
});
}
init();
型
希望有人能帮助我!
1条答案
按热度按时间q9yhzks01#
假警报,您需要添加一个支付方式到API聊天GPT订阅聊天GPT Web的事实是不够的,现在我有我的支付方式here它的工作原理就像一个魅力.