Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
bit-pm
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
燕伟桐
bit-pm
Commits
b6fd985d
Unverified
提交
b6fd985d
authored
7月 08, 2025
作者:
Will Chen
提交者:
GitHub
7月 08, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix OLLAMA_HOST support (#598)
Fixes #411
上级
badab05a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
181 行增加
和
1 行删除
+181
-1
parseOllamaHost.test.ts
src/__tests__/parseOllamaHost.test.ts
+147
-0
local_model_ollama_handler.ts
src/ipc/handlers/local_model_ollama_handler.ts
+34
-1
没有找到文件。
src/__tests__/parseOllamaHost.test.ts
0 → 100644
浏览文件 @
b6fd985d
import
{
parseOllamaHost
}
from
"@/ipc/handlers/local_model_ollama_handler"
;
import
{
describe
,
it
,
expect
}
from
"vitest"
;
describe
(
"parseOllamaHost"
,
()
=>
{
it
(
"should return default URL when no host is provided"
,
()
=>
{
const
result
=
parseOllamaHost
();
expect
(
result
).
toBe
(
"http://localhost:11434"
);
});
it
(
"should return default URL when host is undefined"
,
()
=>
{
const
result
=
parseOllamaHost
(
undefined
);
expect
(
result
).
toBe
(
"http://localhost:11434"
);
});
it
(
"should return default URL when host is empty string"
,
()
=>
{
const
result
=
parseOllamaHost
(
""
);
expect
(
result
).
toBe
(
"http://localhost:11434"
);
});
describe
(
"full URLs with protocol"
,
()
=>
{
it
(
"should return http URLs as-is"
,
()
=>
{
const
input
=
"http://localhost:11434"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://localhost:11434"
);
});
it
(
"should return https URLs as-is"
,
()
=>
{
const
input
=
"https://example.com:11434"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"https://example.com:11434"
);
});
it
(
"should return http URLs with custom ports as-is"
,
()
=>
{
const
input
=
"http://192.168.1.100:8080"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://192.168.1.100:8080"
);
});
it
(
"should return https URLs with paths as-is"
,
()
=>
{
const
input
=
"https://api.example.com:443/ollama"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"https://api.example.com:443/ollama"
);
});
});
describe
(
"hostname with port"
,
()
=>
{
it
(
"should add http protocol to IPv4 host with port"
,
()
=>
{
const
input
=
"192.168.1.100:8080"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://192.168.1.100:8080"
);
});
it
(
"should add http protocol to localhost with custom port"
,
()
=>
{
const
input
=
"localhost:8080"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://localhost:8080"
);
});
it
(
"should add http protocol to domain with port"
,
()
=>
{
const
input
=
"ollama.example.com:11434"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://ollama.example.com:11434"
);
});
it
(
"should add http protocol to 0.0.0.0 with port"
,
()
=>
{
const
input
=
"0.0.0.0:1234"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://0.0.0.0:1234"
);
});
it
(
"should handle IPv6 with port"
,
()
=>
{
const
input
=
"[::1]:8080"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://[::1]:8080"
);
});
});
describe
(
"hostname only"
,
()
=>
{
it
(
"should add http protocol and default port to IPv4 host"
,
()
=>
{
const
input
=
"192.168.1.100"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://192.168.1.100:11434"
);
});
it
(
"should add http protocol and default port to localhost"
,
()
=>
{
const
input
=
"localhost"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://localhost:11434"
);
});
it
(
"should add http protocol and default port to domain"
,
()
=>
{
const
input
=
"ollama.example.com"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://ollama.example.com:11434"
);
});
it
(
"should add http protocol and default port to 0.0.0.0"
,
()
=>
{
const
input
=
"0.0.0.0"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://0.0.0.0:11434"
);
});
it
(
"should handle IPv6 hostname"
,
()
=>
{
const
input
=
"::1"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://[::1]:11434"
);
});
it
(
"should handle full IPv6 hostname"
,
()
=>
{
const
input
=
"2001:db8:85a3:0:0:8a2e:370:7334"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://[2001:db8:85a3:0:0:8a2e:370:7334]:11434"
);
});
it
(
"should handle compressed IPv6 hostname"
,
()
=>
{
const
input
=
"2001:db8::1"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://[2001:db8::1]:11434"
);
});
});
describe
(
"edge cases"
,
()
=>
{
it
(
"should handle hostname with unusual characters"
,
()
=>
{
const
input
=
"my-ollama-server"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://my-ollama-server:11434"
);
});
it
(
"should handle hostname with dots"
,
()
=>
{
const
input
=
"my.ollama.server"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://my.ollama.server:11434"
);
});
it
(
"should handle port 80"
,
()
=>
{
const
input
=
"example.com:80"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://example.com:80"
);
});
it
(
"should handle port 443"
,
()
=>
{
const
input
=
"example.com:443"
;
const
result
=
parseOllamaHost
(
input
);
expect
(
result
).
toBe
(
"http://example.com:443"
);
});
});
});
src/ipc/handlers/local_model_ollama_handler.ts
浏览文件 @
b6fd985d
...
@@ -4,7 +4,40 @@ import { LocalModelListResponse, LocalModel } from "../ipc_types";
...
@@ -4,7 +4,40 @@ import { LocalModelListResponse, LocalModel } from "../ipc_types";
const
logger
=
log
.
scope
(
"ollama_handler"
);
const
logger
=
log
.
scope
(
"ollama_handler"
);
const
OLLAMA_API_URL
=
process
.
env
.
OLLAMA_HOST
||
"http://localhost:11434"
;
export
function
parseOllamaHost
(
host
?:
string
):
string
{
if
(
!
host
)
{
return
"http://localhost:11434"
;
}
// If it already has a protocol, use as-is
if
(
host
.
startsWith
(
"http://"
)
||
host
.
startsWith
(
"https://"
))
{
return
host
;
}
// Check for bracketed IPv6 with port: [::1]:8080
if
(
host
.
startsWith
(
"["
)
&&
host
.
includes
(
"]:"
))
{
return
`http://
${
host
}
`
;
}
// Check for regular host:port (but not plain IPv6)
if
(
host
.
includes
(
":"
)
&&
!
host
.
includes
(
"::"
)
&&
host
.
split
(
":"
).
length
===
2
)
{
return
`http://
${
host
}
`
;
}
// Check if it's a plain IPv6 address (contains :: or multiple colons)
if
(
host
.
includes
(
"::"
)
||
host
.
split
(
":"
).
length
>
2
)
{
return
`http://[
${
host
}
]:11434`
;
}
// If it's just a hostname, add default port
return
`http://
${
host
}
:11434`
;
}
const
OLLAMA_API_URL
=
parseOllamaHost
(
process
.
env
.
OLLAMA_HOST
);
interface
OllamaModel
{
interface
OllamaModel
{
name
:
string
;
name
:
string
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论