smileBeda
11/11/2024, 1:06 PMimport typesense
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# Retrieve environment variables
host = os.getenv('TYPESENSE_HOST')
api_key = os.getenv('TYPESENSE_API_KEY')
protocol = os.getenv('TYPESENSE_PROTOCOL', 'https')
port = os.getenv('TYPESENSE_PORT', '443')
timeout_seconds = int(os.getenv('TYPESENSE_TIMEOUT_SECONDS', 3600))
openai_api_key = os.getenv('OPENAI_API_KEY')
openai_model_name = os.getenv('OPENAI_MODEL_NAME')
client = typesense.Client({
'nodes': [{
'host': host, # For Typesense Cloud use <http://xxx.a1.typesense.net|xxx.a1.typesense.net>
'port': port, # For Typesense Cloud use 443
'protocol': protocol, # For Typesense Cloud use https
'path': '/api'
}],
'api_key': api_key,
'connection_timeout_seconds': timeout_seconds
})
filepath = input("JSONL: ")
with open(filepath) as jsonl_file:
print(client.collections['my_posts'].documents.import_(jsonl_file.read().encode('utf-8'), {'batch_size': 100}))