-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added short example of embeddings generation
- Loading branch information
Showing
1 changed file
with
15 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import csv | ||
from openai import OpenAI | ||
|
||
document1 = 'This is a example about a dress for a formal event with a nice floral design. The dress has a slim fit size and its made of a light material.' | ||
document2 = 'The image contains a dress with a open neckline and it has a casual style. It is mainly used in warm weather and it is very convenient for every day use' | ||
client = OpenAI(base_url="http://tentris-ml.cs.upb.de:8502/v1", api_key="token-tentris-upb") | ||
with open("embeddings_short2.csv", mode="w", newline="") as file: | ||
writer = csv.writer(file) | ||
|
||
embd1 = client.embeddings.create(input=[document1], model="tentris").data[0].embedding | ||
embd2 = client.embeddings.create(input=[document2], model="tentris").data[0].embedding | ||
|
||
writer.writerow(["IRI"] + [f"{i}" for i in range(len(embd1))]) | ||
writer.writerow(["https://example/iri1"] + embd1) | ||
writer.writerow(["https://example/iri2"] + embd2) |