-
Notifications
You must be signed in to change notification settings - Fork 1
feat: update photo's caption #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
9627c72
5d0a1fc
8f589d3
7bc2693
6a97220
d268df3
ac0f402
0545ed5
c35c174
bd0b637
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 2024-10-25 | ||
|
||
## Req call typesense API alway :timeout, but typesense was updated. | ||
|
||
```elixir | ||
** (MatchError) no match of right hand side value: {:error, %Req.TransportError{reason: :timeout}} | ||
(save_it 0.2.0-rc.1) lib/migration/typesense.ex:11: Migration.Typesense.create_collection!/1 | ||
priv/typesense/reset.exs:3: (file) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Typesense | ||
|
||
## Typesense API Errors | ||
|
||
``` | ||
# 400 Bad Request - The request could not be understood due to malformed syntax. | ||
# 401 Unauthorized - Your API key is wrong. | ||
# 404 Not Found - The requested resource is not found. | ||
# 409 Conflict - When a resource already exists. | ||
# 422 Unprocessable Entity - Request is well-formed, but cannot be processed. | ||
# 503 Service Unavailable - We’re temporarily offline. Please try again later. | ||
``` | ||
|
||
docs: https://typesense.org/docs/27.1/api/api-errors.html#api-errors |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule Migration.Typesense do | ||
def create_collection!(schema) do | ||
req = build_request("/collections") | ||
{:ok, res} = Req.post(req, json: schema) | ||
|
||
res.body | ||
end | ||
|
||
def delete_collection!(collection_name) do | ||
req = build_request("/collections/#{collection_name}") | ||
{:ok, res} = Req.delete(req) | ||
|
||
res.body | ||
end | ||
|
||
def list_collections() do | ||
req = build_request("/collections") | ||
{:ok, res} = Req.get(req) | ||
|
||
res.body | ||
end | ||
|
||
|
||
defp get_env() do | ||
url = Application.fetch_env!(:save_it, :typesense_url) | ||
api_key = Application.fetch_env!(:save_it, :typesense_api_key) | ||
|
||
{url, api_key} | ||
end | ||
|
||
defp build_request(path) do | ||
{url, api_key} = get_env() | ||
|
||
Req.new( | ||
base_url: url, | ||
url: path, | ||
headers: [ | ||
{"Content-Type", "application/json"}, | ||
{"X-TYPESENSE-API-KEY", api_key} | ||
] | ||
) | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule Migration.Typesense.Photo do | ||
alias Migration.Typesense | ||
|
||
@photos_schema %{ | ||
"name" => "photos", | ||
"fields" => [ | ||
# image: base64 encoded string | ||
%{"name" => "image", "type" => "image", "store" => false}, | ||
%{ | ||
"name" => "image_embedding", | ||
"type" => "float[]", | ||
"embed" => %{ | ||
"from" => ["image"], | ||
"model_config" => %{ | ||
"model_name" => "ts/clip-vit-b-p32" | ||
} | ||
} | ||
}, | ||
%{"name" => "caption", "type" => "string", "optional" => true}, | ||
%{"name" => "file_id", "type" => "string"}, | ||
%{"name" => "belongs_to_id", "type" => "string"}, | ||
%{"name" => "inserted_at", "type" => "int64"} | ||
], | ||
"default_sorting_field" => "inserted_at" | ||
} | ||
|
||
def create_collection!() do | ||
Typesense.create_collection!(@photos_schema) | ||
end | ||
|
||
def reset!() do | ||
Typesense.delete_collection!(@photos_schema["name"]) | ||
Typesense.create_collection!(@photos_schema) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enhance security guidance for configuration management.
The current setup instructions expose sensitive configuration details. Consider these security improvements:
start.sh
private and not committing it to version control.env
file instead of direct exportsHere's a suggested improvement: