def basilica_api_client(): connection = Connection(BASILICA_API_KEY) print(type(connection)) #> <class 'basilica.Connection'> return connection # embeddings = list(connection.embed_sentences(sentences)) # # embeddings = list(c.embed_sentence(sentence)) for one sentence # print(embeddings) # # st()
def _text2mat(text): sentences = text2sentences(text) if len(sentences) == 0: raise FailedExtraction bkey = environ["BASILICA_KEY"] assert ( bkey ), "Set the environment variable BASILICA_KEY to a key obtained from basilica.ai" if sentences: with Connection(bkey) as conn: return array(list(conn.embed_sentences(sentences))) else: raise FailedExtraction
# web_app/services/basilica_service.py import os from dotenv import load_dotenv from basilica import Connection load_dotenv() BASILICA_API_KEY = os.getenv("BASILICA_API_KEY", default="OOPS") # Create connection to Basilica API object connection = Connection(BASILICA_API_KEY) print(type(connection)) if __name__ == "__main__": embedding = connection.embed_sentence("HELLO WORLD") print(embedding) sentences = [ "This is a sentence!", "This is a similar sentence!", "I don't think this sentence is very similar at all...", ] embeddings = list(connection.embed_sentences(sentences)) for embed in embeddings: print("----------") # a list with 768 floats from -1 to 1 print(embed)
from basilica import Connection from dotenv import load_dotenv from os import getenv load_dotenv() API_KEY = getenv('BASILICA_API_KEY') connection = Connection(API_KEY) if __name__ == "__main__": connection = connection
from basilica import Connection import os from dotenv import load_dotenv load_dotenv() #API_KEY = os.getenv("BASILICA_API_KEY") API_KEY = "48acc3c8-00c7-1aec-b41b-7d916bc7a5f4" # could use a function here to return our connection # could use a class connection = Connection(API_KEY) print("CONNECTION", type(connection)) if __name__ == "__main__": sentences = [ "This is a sentence!", "This is a similar sentence!", "I don't think this sentence is very similar at all...", ] embeddings = list(connection.embed_sentences(sentences)) print(embeddings) embedding = connection.embed_sentence("Hello world!!!", model="twitter") print(type(embedding)) #> <class 'list'> print(type(embedding[0])) #> <class 'float'> print(len(embedding)) #> 768
from basilica import Connection import os from dotenv import load_dotenv load_dotenv() API_KEY = os.getenv("BASILICA_API_KEY") connection = Connection(API_KEY) print("connection", type(connection)) if __name__ == "__main__": sentences = [ "This is a sentence!" "This is a similar sentence" "I don't think this sentence is very similar at all..." ] connection = Connection(API_KEY) print("connection", type(connection)) embeddings = list(connection.embed_sentences(sentences)) print(embeddings) embedding = list(connection.embed_sentences('Hello World!')) print(embedding)
def get_embedding(jpg: str) -> List[float]: with Connection(BASILICA_KEY) as c: x = c.embed_image_file(jpg) return x
from basilica import Connection import os from dotenv import load_dotenv load_dotenv() BASILICA_API_KEY = os.getenv("BASILICA_API_KEY", default="OOPS") connection = Connection(BASILICA_API_KEY) if __name__ == "__main__": pass #embeddings = list(connection.embed_sentences(sentences)) # print(embeddings) # sentences = [ # "This is a sentence!", # "This is a similar sentence!", # "I don't think this sentence is very similar at all...", # ]
def basilica_api_client(): connection = Connection(API_KEY) print(type(connection)) return connection
from basilica import Connection import os from dotenv import load_dotenv load_dotenv API_KEY = os.getenv("BASILICA_API_KEY") # could use a function here to return our connection # could use a class connection = Connection(API_KEY) def basilica_api_client(): connection = Connection(API_KEY) print(type(connection)) return connection if __name__ == "__main__": print("---------") connection = basilica_api_client print("---------") sentence = "Hello again" sent_embeddings = connection.embed_sentence(sentence) print(list(sent_embeddings)) print("---------") sentences = ["Hello world!", "How are you?"]
from basilica import Connection import os from dotenv import load_dotenv load_dotenv API_KEY = os.getenv('BASILICA_API_KEY') # could use a function here to return our connection # could use a class connection = Connection(API_KEY) print('CONNECTION', type(connection)) if __name__ == "__main__": pass sentences = [ "This is a sentence!", "This is a similar sentence!", "I don't think this sentence is very similar at all...", ] embeddings = list(connection.embed_sentences(sentences)) print(embeddings) embedding = connection.embed_sentence('Hello World!', model='twitter') print(type(embedding)) # <class 'list'> print(type(embedding[0])) # <class 'float'> print(len(embedding)) # 768
# # embeddings = c.embed_sentences(["Hello world!", "How are you?"]) # sentences = [ # 'This is a sentence!', # "this is a similar sentence!", # "I don't think this sentence is very similar at all..." # ] # embeddings = c.embed_sentences(sentences) # print(list(embeddings)) # [[0.8556405305862427, ...], ...] # embedding = c.embed_sentence("Hello World!!!") # breakpoint() # at the top we imported the Connection object directly connection = Connection(BASILICA_API_KEY) print("CONNECTION", type(connection)) if __name__ == "__main__": sentences = [ 'This is a sentence!', "this is a similar sentence!", "I don't think this sentence is very similar at all..." ] embeddings = connection.embed_sentences(sentences) print(list(embeddings)) # [[0.8556405305862427, ...], ...] embedding = connection.embed_sentence("Hello World!!!", model="twitter") print(type(embedding)) # <class 'list'> print(type(embedding[0])) # <class "float">
from basilica import Connection import os from dotenv import load_dotenv load_dotenv() BASILICA_API_KEY = os.getenv("BASILICA_API_KEY", default="OOPS") basilica_api_client = Connection(BASILICA_API_KEY) print(type(basilica_api_client)) if __name__ == "__main__": sentences = [ "This is a sentence!", "This is a similar sentence!", "I don't think this sentence is very similar at all...", ] embeddings = list(connection.embed_sentences(sentences)) for embed in embeddings: print("-------------") print(embed) #> list with 768 floats from -1 to 1 embedding = connection.embed_sentence("Hello World") print(embedding) #> list with 768 floats from -1 to 1
def basilica_api_client(): connection = Connection(BASILICA_API_KEY) print(type(connection)) #> <class 'basilica.Connection'> return connection
from basilica import Connection import os from dotenv import load_dotenv load_dotenv() API_KEY = os.getenv('BASILICA_API_KEY') if __name__ == "__main__": connection = Connection(API_KEY) print('CONNECTION', type(connection)) embeddings = list(connection.embed_sentences(tweets) print(embeddings) breakpoint
# twitter_app/services/basilica_service.py import os from basilica import Connection from dotenv import load_dotenv load_dotenv() # API_KEY stored in .env BASILICA_API_KEY = os.getenv("BASILICA_API_KEY") # Making an API connection and printing the type basilica_conn = Connection(BASILICA_API_KEY) print(type(basilica_conn)) #> <class 'basilica.Connection'> ## Basilica Function # def basilica_api_client(): # connection = basilica.Connection(API_KEY) # print(type(connection)) #> <class 'basilica.Connection'> # return connection # if __name__ == "__main__": # # Sentences # sentences = [ # "This is a sentence!", # "This is a similar sentence!", # "I don't think this sentence is very similar at all...", # ] # # Embeddings # embeddings = list(conn.embed_sentences(sentences))