Skip to content

Commit 9f012fd

Browse files
committed
chore: ollama baseurl v1 suffix
1 parent 6412825 commit 9f012fd

File tree

1 file changed

+13
-1
lines changed
  • apps/setting/models_provider/impl/ollama_model_provider/model

1 file changed

+13
-1
lines changed

apps/setting/models_provider/impl/ollama_model_provider/model/image.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Dict
2+
from urllib.parse import urlparse, ParseResult
23

34
from langchain_openai.chat_models import ChatOpenAI
45

@@ -11,14 +12,25 @@ def custom_get_token_ids(text: str):
1112
return tokenizer.encode(text)
1213

1314

15+
def get_base_url(url: str):
16+
parse = urlparse(url)
17+
result_url = ParseResult(scheme=parse.scheme, netloc=parse.netloc, path=parse.path, params='',
18+
query='',
19+
fragment='').geturl()
20+
return result_url[:-1] if result_url.endswith("/") else result_url
21+
22+
1423
class OllamaImage(MaxKBBaseModel, ChatOpenAI):
1524

1625
@staticmethod
1726
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
27+
api_base = model_credential.get('api_base', '')
28+
base_url = get_base_url(api_base)
29+
base_url = base_url if base_url.endswith('/v1') else (base_url + '/v1')
1830
optional_params = MaxKBBaseModel.filter_optional_params(model_kwargs)
1931
return OllamaImage(
2032
model_name=model_name,
21-
openai_api_base=model_credential.get('api_base'),
33+
openai_api_base=base_url,
2234
openai_api_key=model_credential.get('api_key'),
2335
# stream_options={"include_usage": True},
2436
streaming=True,

0 commit comments

Comments
 (0)