Skip to content

Commit

Permalink
Merge pull request #1 from nikolas-rauscher/patch-1
Browse files Browse the repository at this point in the history
Update OpenAI API Call freedmand#71
  • Loading branch information
nikolas-rauscher authored Mar 1, 2024
2 parents 7c24bbe + 09b7085 commit 064e5ab
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/semantra/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from abc import ABC, abstractmethod

import numpy as np
import openai
from openai import OpenAI
import tiktoken
import torch
from dotenv import load_dotenv
Expand Down Expand Up @@ -114,7 +114,7 @@ def __init__(
"OpenAI API key not set. Please set the OPENAI_API_KEY environment variable or create a `.env` file with the key in the current working directory or the Semantra directory, which is revealed by running `semantra --show-semantra-dir`."
)

openai.api_key = os.getenv("OPENAI_API_KEY")
self.client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

self.model_name = model_name
self.num_dimensions = num_dimensions
Expand All @@ -141,8 +141,8 @@ def get_text_chunks(self, _: str, tokens) -> "list[str]":

def embed(self, tokens, offsets, _is_query=False) -> "list[list[float]]":
texts = [tokens[i:j] for i, j in offsets]
response = openai.Embedding.create(model=self.model_name, input=texts)
return np.array([data["embedding"] for data in response["data"]])
response = self.client.embeddings.create(model=self.model_name, input=texts)
return np.array([embedding.embedding for embedding in response.data])


def zero_if_none(x):
Expand Down

0 comments on commit 064e5ab

Please sign in to comment.