Skip to content

Commit

Permalink
Add ollama based local model services in AgentScope. (#60)
Browse files Browse the repository at this point in the history
* Add ollama api

* bug fix

* include ollama in __init__.py (agentscope.models package)

* bug fix

* Add unit test for ollama

* bug fix and reformat

* add package ollama

* reformat

* add logging directory management

* reformat

* re-correct ollama test with single instance

* re-correct ollama test with single instance

* reformat
  • Loading branch information
DavdGao authored Mar 14, 2024
1 parent c493416 commit 197d597
Show file tree
Hide file tree
Showing 4 changed files with 560 additions and 2 deletions.
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@
"tiktoken",
"Pillow",
"requests",
"openai>=1.3.0",
"numpy",
"Flask==3.0.0",
"Flask-Cors==4.0.0",
"Flask-SocketIO==5.3.6",
# TODO: move into other requires
"dashscope==1.14.1",
"openai>=1.3.0",
"ollama>=0.1.7",
]

distribute_requires = minimal_requires + rpc_requires
Expand Down
13 changes: 12 additions & 1 deletion src/agentscope/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
DashScopeImageSynthesisWrapper,
DashScopeTextEmbeddingWrapper,
)
from .ollama_model import (
OllamaChatWrapper,
OllamaEmbeddingWrapper,
OllamaGenerationWrapper,
)


__all__ = [
Expand All @@ -39,6 +44,9 @@
"DashScopeChatWrapper",
"DashScopeImageSynthesisWrapper",
"DashScopeTextEmbeddingWrapper",
"OllamaChatWrapper",
"OllamaEmbeddingWrapper",
"OllamaGenerationWrapper",
]

_MODEL_CONFIGS: dict[str, dict] = {}
Expand Down Expand Up @@ -97,7 +105,10 @@ def load_model_by_config_name(config_name: str) -> ModelWrapperBase:
)

model_type = config.model_type
return _get_model_wrapper(model_type=model_type)(**config)

kwargs = {k: v for k, v in config.items() if k != "model_type"}

return _get_model_wrapper(model_type=model_type)(**kwargs)


def clear_model_configs() -> None:
Expand Down
Loading

0 comments on commit 197d597

Please sign in to comment.