Skip to content

Commit 946e21c

Browse files
author
James Zhu
committed
feat(goose): make engine type determination dynamic instead of hardcoded to openai
- Add _determine_engine_type method to dynamically select appropriate engine type based on endpoint configuration - Check for explicit engine configuration in endpoint settings - Try to determine engine type from supported_client field and endpoint URL patterns - Support common engine types: openai, anthropic, gemini, ollama, llama, huggingface - Maintain backward compatibility by defaulting to 'openai' for existing configurations - Update tests to ensure functionality remains intact
1 parent 6ce127b commit 946e21c

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

code_assistant_manager/tools/goose.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,56 @@ def _sanitize_provider_name(self, endpoint_name: str) -> str:
2222
"""Sanitize endpoint name to be used as provider name."""
2323
return endpoint_name.replace(":", "_").replace("-", "_").replace(".", "_").lower()
2424

25+
def _determine_engine_type(self, endpoint_config: Dict[str, str], endpoint_name: str) -> str:
26+
"""Determine appropriate engine type based on endpoint configuration.
27+
28+
Args:
29+
endpoint_config: Configuration for the endpoint
30+
endpoint_name: Name of the endpoint
31+
32+
Returns:
33+
Appropriate engine type string
34+
"""
35+
# Check if endpoint has an explicit engine configuration
36+
engine_from_config = endpoint_config.get("engine", "")
37+
if engine_from_config:
38+
return engine_from_config
39+
40+
# Try to determine from supported_client field
41+
supported_client = endpoint_config.get("supported_client", "").lower()
42+
if supported_client:
43+
# Common patterns for different engine types
44+
if "openai" in supported_client or "gpt" in supported_client:
45+
return "openai"
46+
elif "anthropic" in supported_client or "claude" in supported_client:
47+
return "anthropic"
48+
elif "gemini" in supported_client or "vertexai" in supported_client:
49+
return "gemini"
50+
elif "ollama" in supported_client:
51+
return "ollama"
52+
elif "llama" in supported_client or "llama2" in supported_client or "llama3" in supported_client:
53+
return "llama"
54+
elif "huggingface" in supported_client:
55+
return "huggingface"
56+
57+
# Try to determine from endpoint URL
58+
endpoint_url = endpoint_config.get("endpoint", "").lower()
59+
if endpoint_url:
60+
if "openai" in endpoint_url or "azure" in endpoint_url and "openai" in endpoint_url:
61+
return "openai"
62+
elif "anthropic" in endpoint_url or "claude" in endpoint_url:
63+
return "anthropic"
64+
elif "gemini" in endpoint_url or "generativelanguage" in endpoint_url:
65+
return "gemini"
66+
elif "ollama" in endpoint_url:
67+
return "ollama"
68+
elif "huggingface" in endpoint_url:
69+
return "huggingface"
70+
71+
# Default to "openai" as it's the most common case in CAM
72+
# But make it more generic for other compatible APIs
73+
return "openai"
74+
2575
def _get_filtered_endpoints(self) -> List[str]:
2676
"""Collect endpoints that support the goose client."""
2777
endpoints = self.config.get_sections(exclude_common=True)
@@ -304,10 +354,13 @@ def _write_goose_config(self, selected_models_by_endpoint: Dict[str, List[str]])
304354
api_key_env_var = f"CAM_GOOSE_{provider_name.upper()}_KEY"
305355
extra_env_vars[api_key_env_var] = endpoint_config["actual_api_key"]
306356

357+
# Determine appropriate engine based on endpoint configuration
358+
engine_type = self._determine_engine_type(endpoint_config, endpoint_name)
359+
307360
# Construct provider config
308361
provider_config = {
309362
"name": provider_name,
310-
"engine": "openai", # Assuming OpenAI-compatible for now as CAM mostly deals with those
363+
"engine": engine_type,
311364
"display_name": endpoint_config.get("description", endpoint_name),
312365
"description": f"Configured via Code Assistant Manager from {endpoint_name}",
313366
"base_url": endpoint_config["endpoint"],

0 commit comments

Comments
 (0)