Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ollama Client (with tool calling) #3056

Merged
merged 26 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c82650c
Ollama client! With function calling. Initial commit, client, no docs…
marklysze Jul 1, 2024
42cfe21
Tidy comments
marklysze Jul 1, 2024
292a167
Cater for missing prompt token count
marklysze Jul 2, 2024
4c6eb1e
Removed use of eval, added json parsing support library
marklysze Jul 2, 2024
c75155b
Fix to the use of the JSON fix library, handling of Mixtral escape se…
marklysze Jul 2, 2024
bdfc9b1
Fixed 'name' in JSON bug, catered for single function call JSON witho…
marklysze Jul 3, 2024
ec124c1
removing role='tool' from inner tool result to reduce token usage.
marklysze Jul 3, 2024
3cf5efc
Merge remote-tracking branch 'origin/main' into ollamaclient
marklysze Jul 3, 2024
e905f73
Merge remote-tracking branch 'origin/main' into ollamaclient
marklysze Jul 25, 2024
513b59e
Added Ollama documentation and updated library versions
marklysze Jul 26, 2024
b0e098c
Merge remote-tracking branch 'origin/main' into ollamaclient
marklysze Jul 26, 2024
0821e83
Added Native Ollama tool calling (v0.3.0 req.) as well as hide/show t…
marklysze Jul 27, 2024
c0f5f6d
Added native tool calling and hide_tools parameter to documentation
marklysze Jul 27, 2024
49f4c19
Merge branch 'main' into ollamaclient
marklysze Jul 27, 2024
f118d0e
Update to Ollama 0.3.1, added tests
marklysze Jul 30, 2024
63d9a0f
Merge remote-tracking branch 'origin/main' into ollamaclient
marklysze Jul 30, 2024
00a699f
Merge remote-tracking branch 'origin/main' into ollamaclient
marklysze Jul 30, 2024
a43dac4
Tweak to manual function calling prompt to improve number handling.
marklysze Jul 30, 2024
cc74546
Merge remote-tracking branch 'origin/main' into ollamaclient
marklysze Aug 7, 2024
143def8
Merge branch 'main' into ollamaclient
marklysze Aug 29, 2024
e859a7b
Merge branch 'main' into ollamaclient
ekzhu Oct 1, 2024
1e59d39
Fix formatting
ekzhu Oct 1, 2024
1291d92
Fix formatting
ekzhu Oct 1, 2024
00d2a58
Better error message
ekzhu Oct 1, 2024
59d2a4e
Merge branch 'main' into ollamaclient
ekzhu Oct 1, 2024
ed10b0c
Merge branch 'main' into ollamaclient
ekzhu Oct 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/contrib-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -709,3 +709,35 @@ jobs:
with:
file: ./coverage.xml
flags: unittests

OllamaTest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.9", "3.10", "3.11", "3.12"]
exclude:
- os: macos-latest
python-version: "3.9"
steps:
- uses: actions/checkout@v4
with:
lfs: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install packages and dependencies for all tests
run: |
python -m pip install --upgrade pip wheel
pip install pytest-cov>=5
- name: Install packages and dependencies for Ollama
run: |
pip install -e .[ollama,test]
pytest test/oai/test_ollama.py --skip-openai
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
2 changes: 2 additions & 0 deletions autogen/logger/file_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from autogen.oai.gemini import GeminiClient
from autogen.oai.groq import GroqClient
from autogen.oai.mistral import MistralAIClient
from autogen.oai.ollama import OllamaClient
from autogen.oai.together import TogetherClient

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -218,6 +219,7 @@ def log_new_client(
| TogetherClient
| GroqClient
| CohereClient
| OllamaClient
| BedrockClient
),
wrapper: OpenAIWrapper,
Expand Down
2 changes: 2 additions & 0 deletions autogen/logger/sqlite_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from autogen.oai.gemini import GeminiClient
from autogen.oai.groq import GroqClient
from autogen.oai.mistral import MistralAIClient
from autogen.oai.ollama import OllamaClient
from autogen.oai.together import TogetherClient

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -405,6 +406,7 @@ def log_new_client(
TogetherClient,
GroqClient,
CohereClient,
OllamaClient,
BedrockClient,
],
wrapper: OpenAIWrapper,
Expand Down
12 changes: 12 additions & 0 deletions autogen/oai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@
except ImportError as e:
cohere_import_exception = e

try:
from autogen.oai.ollama import OllamaClient

ollama_import_exception: Optional[ImportError] = None
except ImportError as e:
ollama_import_exception = e

try:
from autogen.oai.bedrock import BedrockClient

Expand Down Expand Up @@ -545,6 +552,11 @@ def _register_default_client(self, config: Dict[str, Any], openai_config: Dict[s
raise ImportError("Please install `cohere` to use the Cohere API.")
client = CohereClient(**openai_config)
self._clients.append(client)
elif api_type is not None and api_type.startswith("ollama"):
if ollama_import_exception:
raise ImportError("Please install with `[ollama]` option to use the Ollama API.")
client = OllamaClient(**openai_config)
self._clients.append(client)
elif api_type is not None and api_type.startswith("bedrock"):
self._configure_openai_config_for_bedrock(config, openai_config)
if bedrock_import_exception:
Expand Down
Loading
Loading