1010class OpenaiEmbeddings :
1111 LIB_NAME = "openai"
1212
13- def __init__ (self , model = "text-embedding-ada-002 " ):
13+ def __init__ (self , model = "text-embedding-3-small " ):
1414 self .model = model
1515 self .api_key = os .environ .get ("OPENAI_API_KEY" )
1616 self .openai = None
1717 self ._check_openai_package ()
1818 if not self .api_key :
1919 raise ValueError (Errors .E032 ())
2020
21- self .openai .api_key = self .api_key
21+ # self.openai.api_key = self.api_key
2222
2323 def _check_openai_package (self ):
2424 """Check if the 'openai' package is installed and import the required functions.
@@ -44,13 +44,17 @@ def get_embedding(
4444 list[float]: A list of floating-point values representing the text's embedding.
4545 """
4646 if isinstance (text , list ):
47- response = self .openai .Embedding .create (input = text , model = self .model )
47+ response = self .openai .Client (api_key = self .api_key ).embedding .create (
48+ input = text , model = self .model
49+ )
4850 embedding = [
49- np .array (response [ " data" ] [i ][ " embedding" ] ).reshape (1 , - 1 )
51+ np .array (response . data [i ]. embedding ).reshape (1 , - 1 )
5052 for i in range (len (text ))
5153 ]
5254 return embedding
5355 else :
54- response = self .openai .Embedding .create (input = [text ], model = self .model )
55- embedding = np .array (response ["data" ][0 ]["embedding" ]).reshape (1 , - 1 )
56+ response = self .openai .Client (api_key = self .api_key ).embedding .create (
57+ input = [text ], model = self .model
58+ )
59+ embedding = np .array (response .data [0 ].embedding ).reshape (1 , - 1 )
5660 return embedding
0 commit comments