|
| 1 | +import os |
| 2 | +from typing import Optional |
| 3 | +from cog import BaseModel, Input, Path as CogPath, Secret |
| 4 | + |
| 5 | +# We return a path to our trained adapter weights |
| 6 | +class TrainingOutput(BaseModel): |
| 7 | + weights: CogPath |
| 8 | + |
| 9 | +def train( |
| 10 | + # Basic input |
| 11 | + some_input: str = Input( |
| 12 | + description="A basic string input to satisfy minimum requirements.", |
| 13 | + default="default value", |
| 14 | + ), |
| 15 | + # String input with None default (problematic) |
| 16 | + hf_repo_id: Optional[str] = Input( |
| 17 | + description="String with None default - this causes issues.", |
| 18 | + default=None, |
| 19 | + ), |
| 20 | + # Secret with None default (problematic) |
| 21 | + hf_token: Optional[Secret] = Input( |
| 22 | + description="Secret with None default - this also causes issues.", |
| 23 | + default=None, |
| 24 | + ), |
| 25 | + # String input with empty string default (works) |
| 26 | + working_repo_id: str = Input( |
| 27 | + description="String with empty string default - this works.", |
| 28 | + default="", |
| 29 | + ), |
| 30 | + # Secret with empty string default (works) |
| 31 | + working_token: Secret = Input( |
| 32 | + description="Secret with empty string default - this works.", |
| 33 | + default="", |
| 34 | + ), |
| 35 | +) -> TrainingOutput: |
| 36 | + """ |
| 37 | + Minimal example to demonstrate issues with Secret inputs. |
| 38 | + """ |
| 39 | + print("\n=== Minimal Cog Secret Test ===") |
| 40 | + print(f"cog version: {os.environ.get('COG_VERSION', 'unknown')}") |
| 41 | + |
| 42 | + # Inputs with None defaults |
| 43 | + print("\n-- Inputs with None defaults (problematic) --") |
| 44 | + print(f"hf_repo_id: {hf_repo_id}") |
| 45 | + if hf_token: |
| 46 | + print(f"hf_token: [PROVIDED]") |
| 47 | + try: |
| 48 | + value = hf_token.get_secret_value() |
| 49 | + print("Secret access successful") |
| 50 | + except Exception as e: |
| 51 | + print(f"Error accessing secret: {e}") |
| 52 | + else: |
| 53 | + print("hf_token: None") |
| 54 | + |
| 55 | + # Inputs with empty string defaults |
| 56 | + print("\n-- Inputs with empty string defaults (works) --") |
| 57 | + print(f"working_repo_id: {working_repo_id if working_repo_id else '(empty)'}") |
| 58 | + if working_token and working_token.get_secret_value(): |
| 59 | + print(f"working_token: [PROVIDED]") |
| 60 | + try: |
| 61 | + value = working_token.get_secret_value() |
| 62 | + print("Secret access successful") |
| 63 | + except Exception as e: |
| 64 | + print(f"Error accessing secret: {e}") |
| 65 | + else: |
| 66 | + print("working_token: (empty)") |
| 67 | + |
| 68 | + # Create a dummy output file |
| 69 | + output_path = "dummy_output.txt" |
| 70 | + with open(output_path, "w") as f: |
| 71 | + f.write("This is a dummy output file.") |
| 72 | + |
| 73 | + print("\n=== Test Complete ===") |
| 74 | + |
| 75 | + # Return the dummy output path |
| 76 | + return TrainingOutput(weights=CogPath(output_path)) |
0 commit comments