Skip to content

Commit

Permalink
fix: update openai library to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkolenz committed Nov 7, 2023
1 parent ee8d45e commit 8493556
Show file tree
Hide file tree
Showing 3 changed files with 396 additions and 713 deletions.
5 changes: 3 additions & 2 deletions nlp_service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,12 @@ def vector(self, text: str) -> SpacyVector:
class OpenaiModel(ModelBase):
def __init__(self, model: EmbeddingModel):
self.model_name: str = model.model_name
self.client = openai.Client()

def vector(self, text: str) -> SpacyVector:
res: t.Any = openai.Embedding.create(input=[text], model=self.model_name)
res = self.client.embeddings.create(input=[text], model=self.model_name)

return t.cast(SpacyVector, np.array(res["data"][0]["embedding"]))
return t.cast(SpacyVector, np.array(res.data[0].embedding))

embedding_map[nlp_pb2.EmbeddingType.EMBEDDING_TYPE_OPENAI] = OpenaiModel

Expand Down

0 comments on commit 8493556

Please sign in to comment.