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) #3

Merged
merged 22 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 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
2ec7100
Merge branch 'main' into ollamaclient
marklysze Sep 1, 2024
a90cfd5
Update client.py fix indent
marklysze Sep 1, 2024
d4d665d
Update setup.py - Ollama package version correction
marklysze Sep 2, 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
40 changes: 40 additions & 0 deletions .github/workflows/contrib-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,46 @@ jobs:
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]
- name: Set AUTOGEN_USE_DOCKER based on OS
shell: bash
run: |
if [[ ${{ matrix.os }} != ubuntu-latest ]]; then
echo "AUTOGEN_USE_DOCKER=False" >> $GITHUB_ENV
fi
- name: Coverage
run: |
pytest test/oai/test_ollama.py --skip-openai
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests

BedrockTest:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
2 changes: 2 additions & 0 deletions autogen/logger/file_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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 @@ -222,6 +223,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 @@ -30,6 +30,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 @@ -409,6 +410,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 @@ -90,6 +90,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 @@ -535,6 +542,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 `ollama` 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