Created
February 4, 2025 08:38
-
-
Save TrejGun/7d485aa7bf07fec814f6f81040a0a5ab to your computer and use it in GitHub Desktop.
Generate embeddings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { OpenAI } from "openai"; | |
const openai = new OpenAI({ apiKey: "your-api-key" }); | |
async function getEmbedding(text: string): Promise<number[]> { | |
const response = await openai.embeddings.create({ | |
model: "text-embedding-ada-002", | |
input: text, | |
}); | |
return response.data[0].embedding; // Вектор (1536 чисел) | |
} | |
(async () => { | |
const embedding = await getEmbedding("Hello world!"); | |
console.log(embedding); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment