mirror of
https://github.com/Monadical-SAS/cubbi.git
synced 2025-12-20 20:29:06 +00:00
feat(llm): add default model/provider to auto configure the driver (#7)
This commit is contained in:
@@ -163,6 +163,10 @@ def create_session(
|
|||||||
gid: Optional[int] = typer.Option(
|
gid: Optional[int] = typer.Option(
|
||||||
None, "--gid", help="Group ID to run the container as (defaults to host user)"
|
None, "--gid", help="Group ID to run the container as (defaults to host user)"
|
||||||
),
|
),
|
||||||
|
model: Optional[str] = typer.Option(None, "--model", "-m", help="Model to use"),
|
||||||
|
provider: Optional[str] = typer.Option(
|
||||||
|
None, "--provider", "-p", help="Provider to use"
|
||||||
|
),
|
||||||
ssh: bool = typer.Option(False, "--ssh", help="Start SSH server in the container"),
|
ssh: bool = typer.Option(False, "--ssh", help="Start SSH server in the container"),
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create a new MC session
|
"""Create a new MC session
|
||||||
@@ -269,6 +273,8 @@ def create_session(
|
|||||||
uid=target_uid,
|
uid=target_uid,
|
||||||
gid=target_gid,
|
gid=target_gid,
|
||||||
ssh=ssh,
|
ssh=ssh,
|
||||||
|
model=model,
|
||||||
|
provider=provider,
|
||||||
)
|
)
|
||||||
|
|
||||||
if session:
|
if session:
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ class ContainerManager:
|
|||||||
container_id=container_id,
|
container_id=container_id,
|
||||||
created_at=container.attrs["Created"],
|
created_at=container.attrs["Created"],
|
||||||
project=labels.get("mc.project"),
|
project=labels.get("mc.project"),
|
||||||
|
model=labels.get("mc.model"),
|
||||||
|
provider=labels.get("mc.provider"),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get port mappings
|
# Get port mappings
|
||||||
@@ -148,6 +150,8 @@ class ContainerManager:
|
|||||||
run_command: Optional[str] = None,
|
run_command: Optional[str] = None,
|
||||||
uid: Optional[int] = None,
|
uid: Optional[int] = None,
|
||||||
gid: Optional[int] = None,
|
gid: Optional[int] = None,
|
||||||
|
model: Optional[str] = None,
|
||||||
|
provider: Optional[str] = None,
|
||||||
ssh: bool = False,
|
ssh: bool = False,
|
||||||
) -> Optional[Session]:
|
) -> Optional[Session]:
|
||||||
"""Create a new MC session
|
"""Create a new MC session
|
||||||
@@ -456,8 +460,8 @@ class ContainerManager:
|
|||||||
|
|
||||||
# Determine container command and entrypoint
|
# Determine container command and entrypoint
|
||||||
container_command = None
|
container_command = None
|
||||||
entrypoint = None # Keep this initially None to mean "use Dockerfile default unless overridden"
|
entrypoint = None
|
||||||
target_shell = "/bin/bash" # Default final shell
|
target_shell = "/bin/bash"
|
||||||
|
|
||||||
if run_command:
|
if run_command:
|
||||||
# Set environment variable for mc-init.sh to pick up
|
# Set environment variable for mc-init.sh to pick up
|
||||||
@@ -477,6 +481,14 @@ class ContainerManager:
|
|||||||
"Using default container entrypoint/command for interactive shell."
|
"Using default container entrypoint/command for interactive shell."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Set default model/provider from user config if not explicitly provided
|
||||||
|
env_vars["MC_MODEL"] = model or self.user_config_manager.get(
|
||||||
|
"defaults.model", ""
|
||||||
|
)
|
||||||
|
env_vars["MC_PROVIDER"] = provider or self.user_config_manager.get(
|
||||||
|
"defaults.provider", ""
|
||||||
|
)
|
||||||
|
|
||||||
# Create container
|
# Create container
|
||||||
container = self.client.containers.create(
|
container = self.client.containers.create(
|
||||||
image=driver.image,
|
image=driver.image,
|
||||||
@@ -605,10 +617,12 @@ class ContainerManager:
|
|||||||
created_at=container.attrs["Created"],
|
created_at=container.attrs["Created"],
|
||||||
ports=ports,
|
ports=ports,
|
||||||
mcps=mcp_names,
|
mcps=mcp_names,
|
||||||
run_command=run_command, # Store the command
|
run_command=run_command,
|
||||||
uid=uid,
|
uid=uid,
|
||||||
gid=gid,
|
gid=gid,
|
||||||
ssh=ssh, # Store SSH setting
|
model=model,
|
||||||
|
provider=provider,
|
||||||
|
ssh=ssh,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Save session to the session manager
|
# Save session to the session manager
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ if [ -d /root/.local/bin ]; then
|
|||||||
echo "Copying /root/.local/bin to /home/mcuser/.local/bin..."
|
echo "Copying /root/.local/bin to /home/mcuser/.local/bin..."
|
||||||
mkdir -p /home/mcuser/.local/bin
|
mkdir -p /home/mcuser/.local/bin
|
||||||
cp -r /root/.local/bin/* /home/mcuser/.local/bin/
|
cp -r /root/.local/bin/* /home/mcuser/.local/bin/
|
||||||
chown -R $MC_USER_ID:$MC_GROUP_ID /home/mcuser/.local/bin
|
chown -R $MC_USER_ID:$MC_GROUP_ID /home/mcuser/.local
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start SSH server only if explicitly enabled
|
# Start SSH server only if explicitly enabled
|
||||||
@@ -158,16 +158,16 @@ else
|
|||||||
echo "Warning: update-goose-config.py script not found. Goose configuration will not be updated."
|
echo "Warning: update-goose-config.py script not found. Goose configuration will not be updated."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Mark initialization as complete
|
|
||||||
echo "=== MC Initialization completed at $(date) ==="
|
|
||||||
echo "INIT_COMPLETE=true" > /init.status
|
|
||||||
|
|
||||||
# Run the user command first, if set, as mcuser
|
# Run the user command first, if set, as mcuser
|
||||||
if [ -n "$MC_RUN_COMMAND" ]; then
|
if [ -n "$MC_RUN_COMMAND" ]; then
|
||||||
echo '--- Executing initial command: $MC_RUN_COMMAND ---';
|
echo "--- Executing initial command: $MC_RUN_COMMAND ---";
|
||||||
gosu mcuser sh -c "$MC_RUN_COMMAND"; # Run user command as mcuser
|
gosu mcuser sh -c "$MC_RUN_COMMAND"; # Run user command as mcuser
|
||||||
COMMAND_EXIT_CODE=$?;
|
COMMAND_EXIT_CODE=$?;
|
||||||
echo "--- Initial command finished (exit code: $COMMAND_EXIT_CODE) ---";
|
echo "--- Initial command finished (exit code: $COMMAND_EXIT_CODE) ---";
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
# Mark initialization as complete
|
||||||
|
echo "=== MC Initialization completed at $(date) ==="
|
||||||
|
echo "INIT_COMPLETE=true" > /init.status
|
||||||
|
|
||||||
exec gosu mcuser "$@"
|
exec gosu mcuser "$@"
|
||||||
|
|||||||
@@ -30,6 +30,26 @@ def update_config():
|
|||||||
if "extensions" not in config_data:
|
if "extensions" not in config_data:
|
||||||
config_data["extensions"] = {}
|
config_data["extensions"] = {}
|
||||||
|
|
||||||
|
# Add default developer extension
|
||||||
|
config_data["extensions"]["developer"] = {
|
||||||
|
"enabled": True,
|
||||||
|
"name": "developer",
|
||||||
|
"timeout": 300,
|
||||||
|
"type": "builtin",
|
||||||
|
}
|
||||||
|
|
||||||
|
# Update goose configuration with model and provider from environment variables
|
||||||
|
goose_model = os.environ.get("MC_MODEL")
|
||||||
|
goose_provider = os.environ.get("MC_PROVIDER")
|
||||||
|
|
||||||
|
if goose_model:
|
||||||
|
config_data["GOOSE_MODEL"] = goose_model
|
||||||
|
print(f"Set GOOSE_MODEL to {goose_model}")
|
||||||
|
|
||||||
|
if goose_provider:
|
||||||
|
config_data["GOOSE_PROVIDER"] = goose_provider
|
||||||
|
print(f"Set GOOSE_PROVIDER to {goose_provider}")
|
||||||
|
|
||||||
# Get MCP information from environment variables
|
# Get MCP information from environment variables
|
||||||
mcp_count = int(os.environ.get("MCP_COUNT", "0"))
|
mcp_count = int(os.environ.get("MCP_COUNT", "0"))
|
||||||
mcp_names_str = os.environ.get("MCP_NAMES", "[]")
|
mcp_names_str = os.environ.get("MCP_NAMES", "[]")
|
||||||
|
|||||||
@@ -104,11 +104,13 @@ class Session(BaseModel):
|
|||||||
project: Optional[str] = None
|
project: Optional[str] = None
|
||||||
created_at: str
|
created_at: str
|
||||||
ports: Dict[int, int] = Field(default_factory=dict)
|
ports: Dict[int, int] = Field(default_factory=dict)
|
||||||
mcps: List[str] = Field(default_factory=list) # List of MCP server names
|
mcps: List[str] = Field(default_factory=list)
|
||||||
run_command: Optional[str] = None # Command executed on start
|
run_command: Optional[str] = None
|
||||||
uid: Optional[int] = None # Store UID used
|
uid: Optional[int] = None
|
||||||
gid: Optional[int] = None # Store GID used
|
gid: Optional[int] = None
|
||||||
ssh: bool = False # Whether SSH server is enabled
|
model: Optional[str] = None
|
||||||
|
provider: Optional[str] = None
|
||||||
|
ssh: bool = False
|
||||||
|
|
||||||
|
|
||||||
class Config(BaseModel):
|
class Config(BaseModel):
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ class UserConfigManager:
|
|||||||
"networks": [], # Default networks to connect to (besides mc-network)
|
"networks": [], # Default networks to connect to (besides mc-network)
|
||||||
"volumes": [], # Default volumes to mount, format: "source:dest"
|
"volumes": [], # Default volumes to mount, format: "source:dest"
|
||||||
"mcps": [], # Default MCP servers to connect to
|
"mcps": [], # Default MCP servers to connect to
|
||||||
|
"model": "claude-3-5-sonnet-latest", # Default LLM model to use
|
||||||
|
"provider": "anthropic", # Default LLM provider to use
|
||||||
},
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"langfuse": {},
|
"langfuse": {},
|
||||||
|
|||||||
Reference in New Issue
Block a user