-
Notifications
You must be signed in to change notification settings - Fork 124
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
Add support for Ollama #218
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -36,6 +36,8 @@ | |||||||||||||||||||||||||||||||||||||||||
GetNodesFromTags, | ||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||
from app.modules.intelligence.tools.tool_schema import ToolInfo | ||||||||||||||||||||||||||||||||||||||||||
from langchain_ollama import Ollama | ||||||||||||||||||||||||||||||||||||||||||
from app.core.config_provider import config_provider | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
class ToolService: | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -65,8 +67,18 @@ def _initialize_tools(self) -> Dict[str, Any]: | |||||||||||||||||||||||||||||||||||||||||
"get_node_neighbours_from_node_id": GetNodeNeighboursFromNodeIdTool( | ||||||||||||||||||||||||||||||||||||||||||
self.db | ||||||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||||||
"ollama_tool": Ollama( | ||||||||||||||||||||||||||||||||||||||||||
base_url=self._get_ollama_endpoint(), | ||||||||||||||||||||||||||||||||||||||||||
model=self._get_ollama_model(), | ||||||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
def _get_ollama_endpoint(self) -> str: | ||||||||||||||||||||||||||||||||||||||||||
return config_provider.get_ollama_config()["endpoint"] | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
def _get_ollama_model(self) -> str: | ||||||||||||||||||||||||||||||||||||||||||
return config_provider.get_ollama_config()["model"] | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+76
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add validation and error handling to configuration methods. The methods should validate the configuration values and handle missing or malformed config gracefully. Consider this implementation: def _get_ollama_endpoint(self) -> str:
- return config_provider.get_ollama_config()["endpoint"]
+ config = config_provider.get_ollama_config()
+ if not config or "endpoint" not in config:
+ raise ValueError("Ollama endpoint configuration is missing")
+ endpoint = config["endpoint"]
+ if not endpoint.startswith(("http://", "https://")):
+ raise ValueError(f"Invalid Ollama endpoint URL format: {endpoint}")
+ return endpoint
def _get_ollama_model(self) -> str:
- return config_provider.get_ollama_config()["model"]
+ config = config_provider.get_ollama_config()
+ if not config or "model" not in config:
+ raise ValueError("Ollama model configuration is missing")
+ return config["model"] 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
async def run_tool(self, tool_id: str, params: Dict[str, Any]) -> Dict[str, Any]: | ||||||||||||||||||||||||||||||||||||||||||
tool = self.tools.get(tool_id) | ||||||||||||||||||||||||||||||||||||||||||
if not tool: | ||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling and description for the Ollama tool.
Two improvements needed:
Consider this implementation:
"ollama_tool": Ollama( base_url=self._get_ollama_endpoint(), model=self._get_ollama_model(), + description="Local LLM powered by Ollama", ),
Also, add error handling: