返回提交历史
Modified
docker-compose.yml
+3
-1
Modified
g4f/Provider/Ollama.py
+10
-3
XFEstudio/gpt4free
get ollama address from env
+ docker compose configuration
ec983c1d
代码差异
2 个文件
+13
-4
@@ -12,4 +12,6 @@ services:
12
12
ports:
13
13
- '8080:8080'
14
14
- '1337:1337'
15
- '7900:7900'
15
- '7900:7900'
16
environment:
17
- OLLAMA_HOST=host.docker.internal
@@ -1,6 +1,7 @@
1
1
from __future__ import annotations
2
2
3
3
import requests
4
import os
4
5
5
6
from .needs_auth.Openai import Openai
6
7
from ..typing import AsyncResult, Messages
@@ -14,9 +15,11 @@ class Ollama(Openai):
14
15
@classmethod
15
16
def get_models(cls):
16
17
if not cls.models:
17
url = 'http://127.0.0.1:11434/api/tags'
18
host = os.getenv("OLLAMA_HOST", "127.0.0.1")
19
port = os.getenv("OLLAMA_PORT", "11434")
20
url = f"http://{host}:{port}/api/tags"
18
21
models = requests.get(url).json()["models"]
19
cls.models = [model['name'] for model in models]
22
cls.models = [model["name"] for model in models]
20
23
cls.default_model = cls.models[0]
21
24
return cls.models
22
25
@@ -25,9 +28,13 @@ class Ollama(Openai):
25
28
cls,
26
29
model: str,
27
30
messages: Messages,
28
api_base: str = "http://localhost:11434/v1",
31
api_base: str = None,
29
32
**kwargs
30
33
) -> AsyncResult:
34
if not api_base:
35
host = os.getenv("OLLAMA_HOST", "localhost")
36
port = os.getenv("OLLAMA_PORT", "11434")
37
api_base: str = f"http://{host}:{port}/v1"
31
38
return super().create_async_generator(
32
39
model, messages, api_base=api_base, **kwargs
33
40
)