Compare commits
4 Commits
v0.5.1
...
95db5f877d
| Author | SHA1 | Date | |
|---|---|---|---|
| 95db5f877d | |||
| 7e2ddd846e | |||
| ab113acde5 | |||
| 7391f0f2ce |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name = "GeneralUtils"
|
name = "GeneralUtils"
|
||||||
uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe"
|
uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe"
|
||||||
version = "0.5.1"
|
version = "0.5.3"
|
||||||
authors = ["tonaerospace <tonaerospace.etc@gmail.com>"]
|
authors = ["tonaerospace <tonaerospace.etc@gmail.com>"]
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|||||||
@@ -8,6 +8,87 @@ using ..util
|
|||||||
#[PENDING] update code to use JSON
|
#[PENDING] update code to use JSON
|
||||||
# ---------------------------------------------- 100 --------------------------------------------- #
|
# ---------------------------------------------- 100 --------------------------------------------- #
|
||||||
|
|
||||||
|
""" Execute SQL against a PostgreSQL database using LibPQ connection string.
|
||||||
|
|
||||||
|
# Arguments
|
||||||
|
- `pg_conn_str::AbstractString`: PostgreSQL connection string in format "host=... port=... dbname=... user=... password=..."
|
||||||
|
- `sql::AbstractString`: SQL query to execute
|
||||||
|
|
||||||
|
# Returns
|
||||||
|
- `LibPQ.Result` on success, `nothing` on failure
|
||||||
|
|
||||||
|
# Example
|
||||||
|
```julia
|
||||||
|
pg_conn_str = "host=localhost port=5432 dbname=mydb user=myuser password=mypass"
|
||||||
|
sql = "SELECT * FROM wine;"
|
||||||
|
result = execute_postgres_sql(pg_conn_str, sql)
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
function execute_postgres_sql(pg_conn_str::T, sql::T) where {T<:AbstractString}
|
||||||
|
db_connection = LibPQ.Connection(pg_conn_str)
|
||||||
|
result = nothing
|
||||||
|
try
|
||||||
|
result = LibPQ.execute(db_connection, sql)
|
||||||
|
catch e
|
||||||
|
@error e
|
||||||
|
LibPQ.close(db_connection)
|
||||||
|
end
|
||||||
|
|
||||||
|
LibPQ.close(db_connection)
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
"""
|
||||||
|
get_embedding_nats(nats_server_url::String, texts::Vector{String})
|
||||||
|
|
||||||
|
Fetch embeddings for a list of texts from a NATS-based embedding service.
|
||||||
|
|
||||||
|
# Arguments
|
||||||
|
- `nats_server_url::String`: NATS server connection URL
|
||||||
|
- `texts::Vector{String}`: List of text strings to generate embeddings for
|
||||||
|
|
||||||
|
# Returns
|
||||||
|
- `Vector` of embeddings, where each embedding is a vector of floats (Vector{Float32} or Vector{Float64})
|
||||||
|
|
||||||
|
# Example
|
||||||
|
```julia
|
||||||
|
nats_server_url = "nats://localhost:4222"
|
||||||
|
texts = ["Hello world", "Another text"]
|
||||||
|
embeddings = get_embedding_nats(nats_server_url, texts)
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
function get_embedding_nats(nats_server_url::String, texts::Vector{String})
|
||||||
|
nats_conn = NATS.connect(nats_server_url)
|
||||||
|
return get_embedding_nats(nats_conn, texts)
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_embedding_nats(nats_conn::NATS.Connection, texts::Vector{String})
|
||||||
|
println("Generating embeddings for $(length(texts)) texts...")
|
||||||
|
documents_dict = Dict("documents" => texts)
|
||||||
|
payloads = [("documents", documents_dict, "dictionary")]
|
||||||
|
_, msg_envelope_json_str = msghandler.smartpack(
|
||||||
|
config["externalservice"]["servicesloadbalancer"]["nats"],
|
||||||
|
payloads;
|
||||||
|
msg_purpose="embedding",
|
||||||
|
broker_url=config["nats_server_info"]["url"],
|
||||||
|
fileserver_url=config["externalservice"]["fileserver"]["url"])
|
||||||
|
|
||||||
|
reply = NATS.request(nats_conn,
|
||||||
|
config["externalservice"]["servicesloadbalancer"]["nats"],
|
||||||
|
msg_envelope_json_str, timeout=300)
|
||||||
|
incoming_env_json_str = String(reply.payload)
|
||||||
|
incoming_env = msghandler.smartunpack(incoming_env_json_str)
|
||||||
|
embedding_response = incoming_env["payloads"][1][2]
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for i in embedding_response["data"]
|
||||||
|
embedding_vector = i["embedding"]
|
||||||
|
push!(result, embedding_vector)
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
dictToPostgresKeyValueString - Convert dictionary to PostgreSQL key-value string format
|
dictToPostgresKeyValueString - Convert dictionary to PostgreSQL key-value string format
|
||||||
|
|||||||
Reference in New Issue
Block a user