12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/jekyll/embeddings-generator/embeddings/generate.rb', line 12
def generate_embeddings(text)
config = Jekyll::EmbeddingsGenerator.config
api_key = config["openai_api_key"]
response = HTTParty.post(
"https://api.openai.com/v1/embeddings",
:headers => {
"Authorization" => "Bearer #{api_key}",
"Content-Type" => "application/json",
},
:body => {
:model => "text-embedding-3-small",
:input => text,
}.to_json
)
raise "OpenAI API error: #{response.parsed_response["error"]["message"]}" unless response.success?
response.parsed_response["data"][0]["embedding"]
end
|