File size: 737 Bytes
5ecde30 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import openai
import pandas as pd
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
import os
from dotenv import load_dotenv
# Initialize OpenAI client (replace with your API key)
load_dotenv() # take environment variables from .env.
api_key = os.getenv('OPENAI_API_KEY')
# Function to get OpenAI embeddings for a text input
def get_embedding(text, model="text-embedding-ada-002"):
text = text.replace("\n", " ")
response = openai.Embedding.create(input=[text], model=model) # Correct API call
return response['data'][0]['embedding']
example_text = "How much do I have to pay for the current bill?"
example_embedding = get_embedding(example_text) # Correct function call
print(example_embedding) |