summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Ollama.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-05-05 23:51:40 +0200
committerGitHub <noreply@github.com>2024-05-05 23:51:40 +0200
commit1d02a06456f2a05bd88782949ba28c9244fa1e6a (patch)
tree7d2505b4220f7b83adfa5cb81f076ed779176067 /g4f/Provider/Ollama.py
parentMerge pull request #1923 from Hydra566/patch-2 (diff)
parentAdd Ollama provider, Add vision support to Openai (diff)
downloadgpt4free-1d02a06456f2a05bd88782949ba28c9244fa1e6a.tar
gpt4free-1d02a06456f2a05bd88782949ba28c9244fa1e6a.tar.gz
gpt4free-1d02a06456f2a05bd88782949ba28c9244fa1e6a.tar.bz2
gpt4free-1d02a06456f2a05bd88782949ba28c9244fa1e6a.tar.lz
gpt4free-1d02a06456f2a05bd88782949ba28c9244fa1e6a.tar.xz
gpt4free-1d02a06456f2a05bd88782949ba28c9244fa1e6a.tar.zst
gpt4free-1d02a06456f2a05bd88782949ba28c9244fa1e6a.zip
Diffstat (limited to 'g4f/Provider/Ollama.py')
-rw-r--r--g4f/Provider/Ollama.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/g4f/Provider/Ollama.py b/g4f/Provider/Ollama.py
new file mode 100644
index 00000000..a44aaacd
--- /dev/null
+++ b/g4f/Provider/Ollama.py
@@ -0,0 +1,33 @@
+from __future__ import annotations
+
+import requests
+
+from .needs_auth.Openai import Openai
+from ..typing import AsyncResult, Messages
+
+class Ollama(Openai):
+ label = "Ollama"
+ url = "https://ollama.com"
+ needs_auth = False
+ working = True
+
+ @classmethod
+ def get_models(cls):
+ if not cls.models:
+ url = 'http://127.0.0.1:11434/api/tags'
+ models = requests.get(url).json()["models"]
+ cls.models = [model['name'] for model in models]
+ cls.default_model = cls.models[0]
+ return cls.models
+
+ @classmethod
+ def create_async_generator(
+ cls,
+ model: str,
+ messages: Messages,
+ api_base: str = "http://localhost:11434/v1",
+ **kwargs
+ ) -> AsyncResult:
+ return super().create_async_generator(
+ model, messages, api_base=api_base, **kwargs
+ ) \ No newline at end of file