Skip to content

Commit 7ae784c

Browse files
authored
add milvus, composer update (#49)
1 parent 099185a commit 7ae784c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1647
-592
lines changed

composer.lock

Lines changed: 39 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/OpenAIApi.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@ class OpenAIApi {
1616

1717
protected $cache;
1818

19-
protected $logger;
20-
21-
public function __construct($apiKey, $logger = NULL) {
22-
19+
public function __construct($apiKey) {
2320
// Initialize the cache
2421
$this->cache = cache('data'); // Using the 'data' cache bin
2522

2623
// Initialize the OpenAI client
2724
$this->client = $this->initializeClient($apiKey);
28-
29-
// Initialize the logger
30-
$this->logger = $logger ?: watchdog('openai', 'There was an issue obtaining a response from OpenAI construct.');
3125
}
3226

3327
private function initializeClient($apiKey) {

modules/openai_alt/js/openai_alt_autogenerate.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
(function ($) {
22
$(document).ready(function () {
3+
34
/**
4-
* Wrap ALT fields in a container if not already done.
5+
* 1) Wrap ALT fields in a container if not already done.
56
*/
67
function wrapAltTextFields() {
78
$("input[name$='[alt]']").each(function () {
@@ -13,69 +14,69 @@
1314
}
1415

1516
/**
16-
* Generate alt text for each item that was flagged in Backdrop.settings.openaiAlt.
17-
* (We only add items with empty alt in the PHP code, so we won't overwrite existing alt.)
17+
* 2) For each entry in Backdrop.settings.openaiAlt, generate alt text if needed.
18+
* We only add items in the PHP if alt == '', so each item is auto-generated once.
1819
*/
1920
function triggerAutoGenerationForAll() {
2021
if (Backdrop.settings.openaiAlt) {
2122
$.each(Backdrop.settings.openaiAlt, function (key, item) {
22-
// item = { fid, field_name, delta, target_id, ... }
23+
// item is { fid, field_name, delta, target_id } for each image
2324
if (item.fid && item.field_name !== undefined && item.delta !== undefined) {
24-
generateAltText(item.fid, item.field_name, item.delta);
25+
generateAltText(item.fid, item.field_name, item.delta, key);
2526
}
2627
});
2728
}
2829
}
2930

3031
/**
31-
* Helper: Actually call the endpoint, then place alt text in the correct input.
32+
* 3) Helper: Fire an AJAX request to get alt text, then store it in the correct <input>.
33+
* After success, remove that item from openaiAlt so it’s not re-run.
3234
*/
33-
function generateAltText(fid, fieldName, delta) {
35+
function generateAltText(fid, fieldName, delta, key) {
3436
$.ajax({
3537
url: Backdrop.settings.basePath + "openai-alt/generate-alt-text",
3638
type: "POST",
3739
data: { fid: fid, field_name: fieldName, delta: delta },
3840
success: function (response) {
3941
if (response.status === "success" && response.alt_text) {
40-
// 1) Insert the result into the <input> for this field/delta.
4142
var selector = "input[name='" + fieldName + "[und][" + delta + "][alt]']";
42-
$(selector).val(response.alt_text).trigger("change");
43+
$(selector).val(response.alt_text).trigger('change');
4344

44-
// 2) Remove this item from openaiAlt so it won't auto-regenerate again.
45-
var key = fieldName + ":" + delta;
46-
if (Backdrop.settings.openaiAlt && Backdrop.settings.openaiAlt[key]) {
45+
// Remove from openaiAlt so we don’t re-run
46+
if (Backdrop.settings.openaiAlt[key]) {
4747
delete Backdrop.settings.openaiAlt[key];
4848
}
4949
}
50+
},
51+
error: function (xhr, status, error) {
52+
console.error("❌ AJAX request failed:", status, error);
5053
}
5154
});
5255
}
5356

5457
/**
55-
* After any AJAX that includes "file/ajax" (i.e. new image added),
56-
* wait a moment, then try generating alt text for newly added items.
58+
* 4) On AJAX complete, if a new image was added, the form might reattach auto-generate.
59+
* So we re-run triggerAutoGenerationForAll to catch newly empty alt fields only.
5760
*/
5861
$(document).ajaxComplete(function (event, xhr, settings) {
62+
// If a file was uploaded
5963
if (settings.url.includes("file/ajax")) {
6064
setTimeout(triggerAutoGenerationForAll, 500);
6165
}
6266
});
6367

6468
/**
65-
* Optional: If you remove an image, you might want to remove
66-
* that item from openaiAlt. Only do so if you have data attributes
67-
* for the remove button. Otherwise, leaving them won't matter
68-
* because we only run alt generation for items with an empty alt
69-
* (and that item is gone entirely anyway).
69+
* 5) Optionally, handle remove button if you want to clear openaiAlt for that item.
70+
* You can do so if your remove button includes data-field-name, data-delta, etc.
7071
*/
7172
$(document).on("click", ".file-remove-button", function () {
72-
// For a multi-value field, you might parse the delta from $(this).data('delta').
73-
// For now, we can just do:
74-
// Backdrop.settings.openaiAlt = null;
75-
// But that nixes *all* items. So be careful.
73+
// If you have data attributes, parse them, then remove from openaiAlt if you wish.
74+
// For now, do nothing or the simplest approach might be:
75+
// Backdrop.settings.openaiAlt = {};
76+
// But that would remove all items, so be careful.
7677
});
7778

78-
// On page load, wrap all existing ALT fields, then generate for any that need it.
79+
// **Run initial setup**
7980
wrapAltTextFields();
8081
triggerAutoGenerationForAll();
8182
});

modules/openai_alt/openai_alt.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ backdrop = 1.x
55
package = OpenAI
66
configure = admin/config/openai/openai-alt
77
dependencies[] = openai
8-
dpendencies[] = image_effects
8+
dependencies[] = image_effects
99
dependencies[] = image_effects_coloractions

0 commit comments

Comments
 (0)