合併: 本機或區網的模型看不到圖時,可以請雲端模型看截圖和附件
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha4mzWbjJAWAsDVuBun
This commit is contained in:
commit
ec7a9ba77d
|
|
@ -426,7 +426,9 @@ def main():
|
|||
for name in ["chats", "oplog"] + (["skills"] if skills else []):
|
||||
shutil.rmtree(os.path.join(a.data, name), ignore_errors=True)
|
||||
for name in os.listdir(a.data):
|
||||
if name.startswith("memory.db"):
|
||||
# The 看圖小幫手's notes too (a model that can't see pictures has them described): each
|
||||
# task's pictures are described anew, and counted.
|
||||
if name.startswith("memory.db") or name == "image-notes.json":
|
||||
os.remove(os.path.join(a.data, name))
|
||||
forget(skills=True)
|
||||
# A box of its own that doesn't exist yet: one plain question first makes it (the first task's
|
||||
|
|
@ -482,6 +484,12 @@ def main():
|
|||
r["check_error"] = str(e)
|
||||
r["skills"] = [{"name": k.get("name"), "steps": len(k.get("steps", []))} for k in st.get("skills", [])]
|
||||
r["replayed"] = "replay_skill" in r.get("tools", [])
|
||||
# Pictures another model described for this one (it can't see them): their cost isn't in
|
||||
# the meter's count, which is the bot's own model only.
|
||||
try:
|
||||
r["described"] = len(json.load(open(os.path.join(a.data, "image-notes.json"))))
|
||||
except (OSError, ValueError):
|
||||
r["described"] = 0
|
||||
if meter:
|
||||
r["usage"] = meter.take()
|
||||
r.update({"id": t["id"], "name": t["name"], "expected_route": t["route"], "ok": ok, "run": run + 1, "label": a.label,
|
||||
|
|
|
|||
|
|
@ -40,5 +40,6 @@
|
|||
- 問題卡只在 AnyBot 裡出現:訊息管道(Slack、Telegram…)來的對話沒有 `ask_person`;例行任務裡等人回答(或允許)超過 15 分鐘,那次執行會被結束。密碼、卡號、驗證碼不要用問題卡問。
|
||||
- 使用者不按卡片、直接在輸入框打字送出,問題卡就算沒回答,Bot 照打的字做。
|
||||
- `react` 按在使用者最近一則自己寫的訊息上;例行任務、別的 Bot 叫醒的訊息不算。
|
||||
- 模型看不到圖(「看圖小幫手」):截圖和附件改請帳號裡看得懂圖的模型描述成文字。Bot 用的是本機或區網的模型(Ollama、這個網路或 Tailscale 上的伺服器)時,圖片預設不送出去,只找同樣在本機的;要送給雲端模型(例如 Grok),在 設定 › 模型 › 那個供應商 打開「看不到圖時,請雲端模型看截圖和附件」。沒有幫手時 Bot 只拿到「看不到圖片」的說明,只能用編號清單和文字做。
|
||||
- `look_image` 要帳號裡有看得懂圖的模型。對話太長時 AnyBot 會先把圖片拿掉(「對話太長了,先拿掉 N 張截圖再試一次…」),拿掉的看不回來,要重新截圖或請使用者再傳。
|
||||
- 生活卡片的 link 要是 http 或 https 開頭才會顯示。
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
- Bot:時區,例行任務和提醒用([routines](routines.md))。
|
||||
- 帳戶:「登入」或「管理帳戶」打開「手機與帳號」頁;資料放在哪。
|
||||
- 「手機與帳號」頁(從 一般 › 帳戶 進去,[phone](phone.md)):「AnyBot 帳號」(登入、備份、還原)、大腦和「加一台電腦」([computers](computers.md))、「同一個網路直接連」、「手機可以做什麼」、「直接連線的裝置」、「分享給團隊」([team](team.md))、「帳號裡的電腦」。
|
||||
- 「模型」:每家 AI 供應商的 API 金鑰、服務網址、新 Bot 預設模型、「測試連線並取得模型清單」([bots](bots.md))。
|
||||
- 「模型」:每家 AI 供應商的 API 金鑰、服務網址、新 Bot 預設模型、「測試連線並取得模型清單」([bots](bots.md));本機或區網的供應商多一個「看不到圖時,請雲端模型看截圖和附件」(預設關,[chat](chat.md))。
|
||||
- 「整合」,三個小分頁:
|
||||
- 訊息管道:Slack、Discord、Telegram、Teams…([channels](channels.md))。
|
||||
- 連接器:「連接器(MCP)」清單、「可以用的工具」、「連接器市集」、「新增連接器」([connectors](connectors.md))。
|
||||
|
|
|
|||
|
|
@ -1553,6 +1553,7 @@ impl App {
|
|||
crate::profile::trim_tools(&b, &mut tool_specs);
|
||||
// 看圖小幫手: the person's models that may see pictures, for a bot whose model can't.
|
||||
providers::set_eyes(self.eyes());
|
||||
providers::set_cloud_eyes_for(ALL_PROVIDERS.into_iter().filter(|k| self.state.provider(*k).cloud_eyes).map(|k| providers::resolve_base(k, &self.state.provider(k).base_url)).collect());
|
||||
let req = ChatRequest {
|
||||
kind: b.provider,
|
||||
base_url: providers::resolve_base(b.provider, &ps.base_url),
|
||||
|
|
@ -5147,6 +5148,12 @@ impl App {
|
|||
changed |= ui.add(egui::TextEdit::singleline(&mut ps.base_url).hint_text(k.default_base_url()).desired_width(w)).changed();
|
||||
field_label(ui, "新 Bot 預設模型", p);
|
||||
changed |= ui.add(egui::TextEdit::singleline(&mut ps.default_model).hint_text(k.suggested_model()).desired_width(w)).changed();
|
||||
// 看圖小幫手 for a local or LAN model: off, its pictures never leave.
|
||||
if providers::is_local_model(k, &providers::resolve_base(k, &ps.base_url)) {
|
||||
ui.add_space(8.0);
|
||||
changed |= ui.checkbox(&mut ps.cloud_eyes, t("看不到圖時,請雲端模型看截圖和附件")).changed();
|
||||
hint(ui, "這是本機或區網的模型,圖片預設不會離開。打開後,它看不到的截圖和附件會送給你設定好的雲端模型(例如 xAI Grok)看,換成文字描述給它。", p);
|
||||
}
|
||||
let count = ps.known_models.len();
|
||||
if changed {
|
||||
self.dirty = true;
|
||||
|
|
|
|||
|
|
@ -179,6 +179,8 @@ pub const ROWS: &[(&str, &str, &str)] = &[
|
|||
("新增", "Add", "追加"),
|
||||
("新增規則", "Add rule", "ルールを追加"),
|
||||
("測試連線並取得模型清單", "Test connection and fetch models", "接続をテストしてモデル一覧を取得"),
|
||||
("看不到圖時,請雲端模型看截圖和附件", "When it can't see pictures, let a cloud model look at screenshots and attachments", "画像が見られないとき、スクリーンショットと添付をクラウドのモデルに見てもらう"),
|
||||
("這是本機或區網的模型,圖片預設不會離開。打開後,它看不到的截圖和附件會送給你設定好的雲端模型(例如 xAI Grok)看,換成文字描述給它。", "This model runs on this computer or your network, so pictures stay here by default. Turned on, the screenshots and attachments it can't see go to a cloud model you've set up (such as xAI Grok), which describes them in words.", "このモデルはこのコンピュータかローカルネットワーク上にあるため、画像は既定では外に出ません。オンにすると、見られないスクリーンショットや添付は設定済みのクラウドモデル(xAI Grok など)に送られ、文章で説明されます。"),
|
||||
("重新傳送", "Send again", "再送信"),
|
||||
("複製", "Copy", "コピー"),
|
||||
("引用", "Quote", "引用"),
|
||||
|
|
|
|||
|
|
@ -625,6 +625,11 @@ pub struct ProviderSettings {
|
|||
/// Models fetched from the provider's model list.
|
||||
#[serde(default)]
|
||||
pub known_models: Vec<String>,
|
||||
/// 看圖小幫手 for a local or LAN model (Ollama, a server on this network or Tailscale):
|
||||
/// pictures it can't see may go to a cloud model of the person's to be described. Off, they
|
||||
/// never leave (a model of one's own is often chosen so that they don't).
|
||||
#[serde(default)]
|
||||
pub cloud_eyes: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
|
|
|
|||
|
|
@ -796,7 +796,7 @@ fn mark_blind(req: &ChatRequest) {
|
|||
pub fn image_refused(msg: &str) -> bool {
|
||||
let l = msg.to_lowercase();
|
||||
let about_images = l.contains("image") || l.contains("vision") || l.contains("multimodal") || l.contains("圖片") || l.contains("图片");
|
||||
about_images && ["at most 0", "not support", "unsupported", "doesn't support", "does not support", "no vision", "not a vision", "not multimodal", "unknown variant", "invalid type", "only text", "text-only", "不支援", "不支持"].iter().any(|k| l.contains(k))
|
||||
about_images && ["at most 0", "not support", "unsupported", "doesn't support", "does not support", "no vision", "not a vision", "not multimodal", "not a multimodal", "unknown variant", "invalid type", "only text", "text-only", "不支援", "不支持"].iter().any(|k| l.contains(k))
|
||||
}
|
||||
|
||||
/// Every tool call needs its result right after it (providers refuse the conversation
|
||||
|
|
@ -869,6 +869,7 @@ pub fn vision_test_guard() -> std::sync::MutexGuard<'static, ()> {
|
|||
notes().lock().unwrap().clear();
|
||||
failed_eyes().lock().unwrap().clear();
|
||||
set_eyes(vec![]);
|
||||
set_cloud_eyes_for(vec![]);
|
||||
g
|
||||
}
|
||||
|
||||
|
|
@ -917,6 +918,21 @@ pub(crate) fn is_local_model(kind: ProviderKind, base_url: &str) -> bool {
|
|||
!crate::web::is_private_browser_url(base_url).eq(&false)
|
||||
}
|
||||
|
||||
/// The local or LAN servers (their addresses) whose pictures a cloud model may describe: the
|
||||
/// person turned it on for that provider (設定 › 模型, ProviderSettings::cloud_eyes).
|
||||
static CLOUD_EYES_FOR: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());
|
||||
|
||||
pub fn set_cloud_eyes_for(bases: Vec<String>) {
|
||||
*CLOUD_EYES_FOR.lock().unwrap() = bases;
|
||||
}
|
||||
|
||||
/// Pictures of a bot on this model stay with local helpers only: a local or LAN model, unless
|
||||
/// the person let a cloud model look for it.
|
||||
fn keeps_pictures_here(kind: ProviderKind, base_url: &str) -> bool {
|
||||
let same = |a: &str| a.trim().trim_end_matches('/') == base_url.trim().trim_end_matches('/');
|
||||
is_local_model(kind, base_url) && !CLOUD_EYES_FOR.lock().unwrap().iter().any(|b| same(b))
|
||||
}
|
||||
|
||||
/// Ask the first helper that can see pictures to describe this one: (description, model).
|
||||
/// Every picture is looked at once: the note is kept by the picture's own hash, so the same
|
||||
/// picture in a later send costs nothing. A bot that needs more than the note gives it a fresh,
|
||||
|
|
@ -945,11 +961,12 @@ pub fn describe_fresh(picture: &str, ask: &str, not: &ChatRequest, cancel: &Atom
|
|||
}
|
||||
|
||||
fn ask_eyes(picture: &str, ask: &str, not: &ChatRequest, cancel: &AtomicBool) -> Option<(String, String)> {
|
||||
let keep_local = is_local_model(not.kind, ¬.base_url);
|
||||
let keep_local = keeps_pictures_here(not.kind, ¬.base_url);
|
||||
let helpers: Vec<Eyes> = EYES.lock().unwrap().clone();
|
||||
for e in helpers {
|
||||
// Privacy boundary: when the bot's own model is local/private (Ollama or LAN server),
|
||||
// never send its screenshots or attachments out to an external cloud provider behind the person's back.
|
||||
// never send its screenshots or attachments out to an external cloud provider behind the
|
||||
// person's back (only when they said so for that provider).
|
||||
if keep_local && !is_local_model(e.kind, &e.base_url) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1948,6 +1965,7 @@ mod tests {
|
|||
assert!(image_refused("錯誤 400:At most 0 image(s) may be provided in one prompt. (parameter=image)"));
|
||||
assert!(image_refused("This model does not support image input"));
|
||||
assert!(image_refused("unknown variant `image_url`, expected `text`"));
|
||||
assert!(image_refused("錯誤 400:spark-x2.6-4b is not a multimodal model"));
|
||||
assert!(!image_refused("錯誤 400:Invalid credential"));
|
||||
// The first request fails like the user's model did; the retry has no picture.
|
||||
let l = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
|
|
@ -2093,6 +2111,27 @@ mod tests {
|
|||
set_eyes(vec![]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_local_models_pictures_stay_unless_the_person_lets_a_cloud_model_look() {
|
||||
let _g = vision_test_guard();
|
||||
let lan = "http://100.82.106.34:54088/v1";
|
||||
// A server on Tailscale, Ollama, this computer: kept here; a cloud model's: may go out.
|
||||
assert!(keeps_pictures_here(ProviderKind::Custom, lan));
|
||||
assert!(keeps_pictures_here(ProviderKind::Ollama, "http://localhost:11434/v1"));
|
||||
assert!(!keeps_pictures_here(ProviderKind::Xai, "https://api.x.ai/v1"));
|
||||
// Turned on for that server (設定 › 模型): its pictures may go to a cloud helper.
|
||||
set_cloud_eyes_for(vec![format!("{lan}/")]);
|
||||
assert!(!keeps_pictures_here(ProviderKind::Custom, lan));
|
||||
assert!(keeps_pictures_here(ProviderKind::Custom, "http://192.168.1.20:8000/v1"), "only the one turned on");
|
||||
set_cloud_eyes_for(vec![]);
|
||||
assert!(keeps_pictures_here(ProviderKind::Custom, lan));
|
||||
// Off, a cloud helper is never asked (nothing is sent: no description comes back).
|
||||
set_eyes(vec![Eyes { kind: ProviderKind::Xai, base_url: "https://api.x.ai/v1".into(), api_key: "k".into(), model: "grok-4".into() }]);
|
||||
let not = ChatRequest { kind: ProviderKind::Custom, base_url: lan.into(), api_key: String::new(), model: "husky".into(), system: String::new(), history: vec![], tools: vec![], session: String::new(), effort: String::new() };
|
||||
assert!(ask_eyes("UElDVFVSRS1PTkU=", "看", ¬, &AtomicBool::new(false)).is_none());
|
||||
set_eyes(vec![]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steps_without_results_are_closed() {
|
||||
let mut a = Message::assistant("", "");
|
||||
|
|
|
|||
Loading…
Reference in New Issue