Skip to content

Commit

Permalink
DH-4917/fix the embedding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadrezaPourreza committed Oct 31, 2023
1 parent f08225d commit b828efa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions dataherald/sql_generator/dataherald_sqlagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
CallbackManagerForToolRun,
)
from langchain.chains.llm import LLMChain
from langchain.embeddings import OpenAIEmbeddings
from langchain.schema import AgentAction
from langchain.tools.base import BaseTool
from overrides import override
Expand Down Expand Up @@ -205,9 +206,10 @@ def get_embedding(
self, text: str, model: str = "text-embedding-ada-002"
) -> List[float]:
text = text.replace("\n", " ")
return openai.Embedding.create(input=[text], model=model)["data"][0][
"embedding"
]
embedding = OpenAIEmbeddings(
openai_api_key=os.environ.get("OPENAI_API_KEY"), model=model
)
return embedding.embed_query(text)

def cosine_similarity(self, a: List[float], b: List[float]) -> float:
return round(np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b)), 4)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ sphinx-book-theme==1.0.1
boto3==1.28.38
botocore==1.31.38
PyAthena==3.0.6
tiktoken==0.5.1

0 comments on commit b828efa

Please sign in to comment.