text.replace function #5725
Replies: 1 comment
-
The error Here's how you can fix it:
Here's the updated async function generateEmbeddings(text) {
if (typeof text !== 'string') {
throw new TypeError('Input text must be a string');
}
const embeddings = new OpenAIEmbeddings({ apiKey: process.env.OPENAI_API_KEY });
return await embeddings.embedQuery(text);
} Additionally, ensure that the Here's the relevant part of your code with the necessary checks: async function main() {
try {
const specFilePath = './swagger.json';
const jsonData = fs.readFileSync(specFilePath, 'utf8');
console.log("This is json data:", jsonData);
const hash = generateHash(jsonData);
const textChunks = await splitTextIntoChunks(jsonData);
const client = (weaviate).client({
scheme: process.env.WEAVIATE_SCHEME || "https",
host: "swagger-as4wyy7e.weaviate.network",
apiKey: new ApiKey('yEhKKW4MLmbvVJT2yw7mlTYutuz5zl22U2p1'),
});
await WeaviateStore.fromTexts(
textChunks,
textChunks.map(chunk => ({ hash })),
new OpenAIEmbeddings(),
{
client,
indexName: "Test",
textKey: "text",
metadataKeys: ["hash"],
}
);
const query = "Can you give the api url for whitelist investor and then fetch all wallet?";
const queryEmbedding = await generateEmbeddings(query);
console.log("This is query embedding", queryEmbedding);
const similarEmbeddings = await getNearbyEmbeddings(queryEmbedding);
console.log("This is similar embedding", similarEmbeddings);
const apiUrlPrompt = await API_URL_PROMPT_TEMPLATE.format({
api_docs: similarEmbeddings,
question: query,
});
const apiUrlResponse = await model.generate([apiUrlPrompt]);
console.log("API URL Response:", JSON.stringify(apiUrlResponse, null, 2));
const apiUrl = apiUrlResponse.generations[0][0]?.text;
console.log("Generated API URL:", apiUrl);
} catch (error) {
console.error('Error:', error);
}
}
main(); This should resolve the |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I am getting error Error: TypeError: text.replace is not a function
at OpenAIEmbeddings.embedQuery (file:///C:/Users/LakshyaTambi/Desktop/try/node_modules/@langchain/openai/dist/embeddings.js:219:46)
at WeaviateStore.similaritySearch (file:///C:/Users/LakshyaTambi/Desktop/try/node_modules/@langchain/core/dist/vectorstores.js:104:90)
at getNearbyEmbeddings (file:///C:/Users/LakshyaTambi/Desktop/try/test27.js:58:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async main (file:///C:/Users/LakshyaTambi/Desktop/try/test27.js:92:35)
System Info
ok
Beta Was this translation helpful? Give feedback.
All reactions