My Local AI Showing off

Daestrum

Expert
Licensed User
Longtime User
I have a local AI running (only 30B model) - been giving it tools to use. Saw a post on forum (wait for question), so asked nemo to look. This was the answer (formatting is rough but ignore that)
> visit https://www.b4x.com/android/forum/threads/wait-for.170984/ and show me the corrected code
>>> Reading page: https://www.b4x.com/android/forum/threads/wait-for.170984/

Below is a **clean, working version** of the code you posted on the B4X forum.
The two problems that caused the “Indifferent Declarations” error were:

1. **No `return` statement** – a `ResumableSub` must end with a single `Return <value>` that gives the result to the caller.
2. **Mixing different result types** when you have several `Wait For` calls in the same sub.

The fix is:

* Declare a **single Boolean variable** (`bolResult`) that holds the outcome of the internet‑check and return it.
* Give each `Wait For … Complete` its **own result variable** (or reuse the same name – just keep the type consistent).

---

## Corrected code

```basic
'=================================================================
' Example: startTranslation – checks the network, then translates.
'=================================================================
Private Sub startTranslation(SourceLng As String, TargetLng As String, Text As String)
'--- 1️⃣ Check that we have an internet connection -----------------
Wait For (checkInternet) Complete (bolIsOnline As Boolean)

If bolIsOnline Then
'--- 2️⃣ Do the translation ------------------------------------
Wait For Translate(SourceLng, TargetLng, Text) Complete (sTrans As String)

'--- 3️⃣ Show the result ---------------------------------------
label1.Text = sTrans
End If
End Sub

'=================================================================
' ResumableSub: checkInternet – returns True if we can reach Google,
' otherwise False.
'=================================================================
Private Sub checkInternet As ResumableSub
Dim j As HttpJob
j.Initialize("", Me) ' the job will call JobDone when finished
j.Download("https://www.google.com") ' any reachable URL works

Wait For (j) JobDone(j As HttpJob) ' <-- wait for the HTTP request to finish

Dim bolResult As Boolean = j.Success ' true → download succeeded, false → error / no connection
j.Release ' always release the job

Return bolResult ' <-- single return statement, the only value the caller needs
End Sub
```

### What changed?

| Original issue | Fix applied |
|----------------|-------------|
| `Return=` inside an assignment (e.g. `If Result then …`) – B4X does **not** allow a `return` keyword in the middle of an expression. | Use a **single** `Return bolResult` at the end of `checkInternet`. |
| The internet‑check sub never returned a value (`return=` with no variable). | Store the result in `bolResult` and `Return bolResult`. |
| Potential type mismatch when using several `Wait For` calls (the forum mentioned “different type of the result variable”). | Each `Wait For … Complete` now has its **own** strongly‑typed result variable (`bolIsOnline As Boolean`, `sTrans As String`). This eliminates the “different type” error. |

---

### Quick checklist for future `Wait For` usage

1. **Declare a ResumableSub** (the sub that will be waited on).
2. Inside it, **initialize a Job**, start the async operation (`Download`, `HttpJob`, `Translate`, etc.).
3. Use **`Wait For (job) JobDone(job)`** (or `Wait For (sub) Complete(...)` for library‑provided Wait For functions).
4. **Extract the result** into a clearly‑typed variable (`Boolean`, `String`, etc.).
5. **Return** that variable **once**, at the very end of the ResumableSub.

With those rules applied, the code above will compile and run without the “Indifferent Declarations” error, and you can safely chain multiple `Wait For` statements (as in your original example) without any further problems.

Just thought I would share.
 

Daestrum

Expert
Licensed User
Longtime User
It's like a kid with a new toy. But (unlike a kid) he knows his limits.
> can you tell me where you might need to use the web_search tool? What would you consider before using it?

**When I’d consider using `web_search`**

| Situation | Why `web_search` helps |
|-----------|------------------------|
| **Current or time‑sensitive data** (e.g., today’s news, stock prices, weather forecasts, system update logs) | The tool can fetch the latest web page that contains up‑to‑date information that isn’t stored locally. |
| **External references needed for verification** (e.g., confirming a file path, checking a product spec, looking up a code example) | A quick search returns relevant URLs and snippets so I can verify facts without having to guess. |
| **Research or learning** (e.g., “how does Windows Update work?”, “best practices for GPU temperature monitoring”) | The tool surfaces articles, documentation pages, or tutorials that explain the concept in depth. |
| **Finding a specific file or resource on the web** (e.g., downloading a driver, locating an open‑source library) | I can locate the exact download link or repository page. |

**What I’d evaluate before calling it**

1. **Is the answer already available locally?**
- If I can read a file (`file_read`), query system info (`c_drive_free_space`, `get_cpu_temp`, etc.), or use an existing tool, I’ll avoid a web request.

2. **Do I need fresh, real‑time data?**
- If the information changes frequently (e.g., current temperature, latest Windows Update status), a web search is justified.

3. **Token budget**
- Each `web_search` consumes tokens (≈1 000 per month). I’ll limit calls to essential queries and keep `max_results` low (default 3) unless more results are clearly needed.

4. **Reliability of sources**
- I’ll prefer reputable sites (official documentation, well‑known tech blogs, academic papers). The tool returns snippets; I’ll verify the credibility before quoting.

5. **Privacy / security constraints**
- If the query involves sensitive internal data, a web search could expose that information. I’ll only search when it’s safe and appropriate.

6. **Complexity of the query**
- Very broad or ambiguous queries may return noisy results. I’ll refine the phrasing (e.g., “Windows Update last installed version 2026” instead of just “Windows Update”) to improve relevance and reduce unnecessary pages.

In short, I reach for `web_search` when local tools can’t provide the needed up‑to‑date or external information, and I pause to make sure a web query is truly necessary, respects token limits, and points to trustworthy sources.
 

Daestrum

Expert
Licensed User
Longtime User
Gave it a bigger task

You: Design a simple sliding‑tile puzzle based on a 3×3 magic square.
The puzzle must include one blank tile (like the classic 15‑puzzle).
Explain your reasoning step‑by‑step, especially how you handle the blank tile.
The goal is for the player to slide tiles until the grid forms a valid 3×3 magic square.
The blank tile should not count toward any row/column/diagonal sums.
Then create a small playable version in a single HTML file using plain JavaScript.

First attempt: had 4 single char errors (it used c instead of bc in the code)

After I told it the minor errors, it produced the version below. (it completely re-wrote all the logic)
 

Attachments

  • slide-v2.zip
    1.7 KB · Views: 39
Last edited:

Daestrum

Expert
Licensed User
Longtime User
Been writing a hot-swappable tool system for it, it can keep 10 in memory, but has unlimited reserve tools it can promote to live tools. Largest tool so far is 11k - pure C#.
The whole tool system is in C# (sorry Erel - python in B4J was too slow).
The AI decide which tool to use as they are all self describing, so it picks the one for the job (or chain of them if needed).
 
Top