Skip to content

Commit

Permalink
Merge pull request #1045 from quarkiverse/#1044
Browse files Browse the repository at this point in the history
Improve model download progress logging
  • Loading branch information
geoand authored Nov 4, 2024
2 parents adf9f0d + b476e73 commit 4c72522
Show file tree
Hide file tree
Showing 5 changed files with 453 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private void handleModels(List<DevServicesChatModelRequiredBuildItem> devService
for (String model : modelsToPull) {
// we pull one model at a time and provide progress updates to the user via logging
LOGGER.info("Pulling model " + model);
AtomicReference<Long> LAST_UPDATE_REF = new AtomicReference<>();

CompletableFuture<Void> cf = new CompletableFuture<>();
client.pullAsync(model).subscribe(new Flow.Subscriber<>() {
Expand All @@ -109,18 +110,39 @@ public void onNext(OllamaClient.PullAsyncLine line) {
clientThreadName.compareAndSet(null, Thread.currentThread().getName());
if ((line.total() != null) && (line.completed() != null) && (line.status() != null)
&& line.status().contains("pulling")) {
if (!logUpdate(LAST_UPDATE_REF.get())) {
return;
}

LAST_UPDATE_REF.set(System.nanoTime());
BigDecimal percentage = new BigDecimal(line.completed()).divide(new BigDecimal(line.total()), 4,
RoundingMode.HALF_DOWN).multiply(ONE_HUNDRED);
BigDecimal progress = percentage.setScale(2, RoundingMode.HALF_DOWN);
if (progress.compareTo(ONE_HUNDRED) >= 0) {
// avoid showing 100% for too long
LOGGER.infof("Verifying and cleaning up\n", progress);
} else {
LOGGER.infof("Progress: %s%%\n", progress);
LOGGER.infof("%s - Progress: %s%%\n", model, progress);
}
}
}

/**
* @param lastUpdate The last update time in nanoseconds
* Determines whether we should log an update.
* This is done in order to not overwhelm the console with updates which might make
* canceling the download difficult. See
* <a href="https://github.com/quarkiverse/quarkus-langchain4j/issues/1044">this</a>
*/
private boolean logUpdate(Long lastUpdate) {
if (lastUpdate == null) {
return true;
} else {
return TimeUnit.NANOSECONDS.toMillis(System.nanoTime())
- TimeUnit.NANOSECONDS.toMillis(lastUpdate) > 1_000;
}
}

@Override
public void onError(Throwable throwable) {
cf.completeExceptionally(throwable);
Expand Down
187 changes: 187 additions & 0 deletions docs/modules/ROOT/pages/includes/quarkus-langchain4j-tavily.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,193 @@ a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-exclude-domains]] [.p
A list of domains to specifically exclude from the search results. Default is ++[]++, which doesn't exclude any domains.


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_EXCLUDE_DOMAINS+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_TAVILY_EXCLUDE_DOMAINS+++`
endif::add-copy-button-to-env-var[]
--
|list of string
|`[]`

a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-base-url]] [.property-path]##link:#quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-base-url[`quarkus.langchain4j.tavily.base-url`]##

[.description]
--
Base URL of the Tavily API


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_BASE_URL+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_TAVILY_BASE_URL+++`
endif::add-copy-button-to-env-var[]
--
|string
|`https://api.tavily.com`

a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-api-key]] [.property-path]##link:#quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-api-key[`quarkus.langchain4j.tavily.api-key`]##

[.description]
--
API key for the Tavily API


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_API_KEY+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_TAVILY_API_KEY+++`
endif::add-copy-button-to-env-var[]
--
|string
|required icon:exclamation-circle[title=Configuration property is required]

a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-max-results]] [.property-path]##link:#quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-max-results[`quarkus.langchain4j.tavily.max-results`]##

[.description]
--
Maximum number of results to return


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_MAX_RESULTS+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_TAVILY_MAX_RESULTS+++`
endif::add-copy-button-to-env-var[]
--
|int
|`5`

a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-timeout]] [.property-path]##link:#quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-timeout[`quarkus.langchain4j.tavily.timeout`]##

[.description]
--
The timeout duration for Tavily requests.


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_TIMEOUT+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_TAVILY_TIMEOUT+++`
endif::add-copy-button-to-env-var[]
--
|link:https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Duration.html[Duration] link:#duration-note-anchor-{summaryTableId}[icon:question-circle[title=More information about the Duration format]]
|`60S`

a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-log-requests]] [.property-path]##link:#quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-log-requests[`quarkus.langchain4j.tavily.log-requests`]##

[.description]
--
Whether requests to Tavily should be logged


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_LOG_REQUESTS+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_TAVILY_LOG_REQUESTS+++`
endif::add-copy-button-to-env-var[]
--
|boolean
|`false`

a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-log-responses]] [.property-path]##link:#quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-log-responses[`quarkus.langchain4j.tavily.log-responses`]##

[.description]
--
Whether responses from Tavily should be logged


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_LOG_RESPONSES+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_TAVILY_LOG_RESPONSES+++`
endif::add-copy-button-to-env-var[]
--
|boolean
|`false`

a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-search-depth]] [.property-path]##link:#quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-search-depth[`quarkus.langchain4j.tavily.search-depth`]##

[.description]
--
The search depth to use. This can be "basic" or "advanced". Basic is the default.


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_SEARCH_DEPTH+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_TAVILY_SEARCH_DEPTH+++`
endif::add-copy-button-to-env-var[]
--
a|SearchDepth
|`basic`

a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-include-answer]] [.property-path]##link:#quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-include-answer[`quarkus.langchain4j.tavily.include-answer`]##

[.description]
--
Include a short answer to original query. Default is false.


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_INCLUDE_ANSWER+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_TAVILY_INCLUDE_ANSWER+++`
endif::add-copy-button-to-env-var[]
--
|boolean
|`false`

a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-include-raw-content]] [.property-path]##link:#quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-include-raw-content[`quarkus.langchain4j.tavily.include-raw-content`]##

[.description]
--
Include the cleaned and parsed HTML content of each search result. Default is false.


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_INCLUDE_RAW_CONTENT+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_TAVILY_INCLUDE_RAW_CONTENT+++`
endif::add-copy-button-to-env-var[]
--
|boolean
|`false`

a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-include-domains]] [.property-path]##link:#quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-include-domains[`quarkus.langchain4j.tavily.include-domains`]##

[.description]
--
A list of domains to specifically include in the search results. Default is ++[]++, which includes all domains.


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_INCLUDE_DOMAINS+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_TAVILY_INCLUDE_DOMAINS+++`
endif::add-copy-button-to-env-var[]
--
|list of string
|`[]`

a| [[quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-exclude-domains]] [.property-path]##link:#quarkus-langchain4j-tavily_quarkus-langchain4j-tavily-exclude-domains[`quarkus.langchain4j.tavily.exclude-domains`]##

[.description]
--
A list of domains to specifically exclude from the search results. Default is ++[]++, which doesn't exclude any domains.


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_TAVILY_EXCLUDE_DOMAINS+++[]
endif::add-copy-button-to-env-var[]
Expand Down
Loading

0 comments on commit 4c72522

Please sign in to comment.