|
| 1 | +import {Args, Command, Flags} from '@oclif/core' |
| 2 | + |
| 3 | +import type {OpenAIProfileConfig, WatsonxProfileConfig} from '../../lib/profile/types.js' |
| 4 | + |
| 5 | +import {saveProfile} from '../../lib/profile/storage.js' |
| 6 | + |
| 7 | +export default class ProfilesSet extends Command { |
| 8 | + static args = { |
| 9 | + name: Args.string({ |
| 10 | + description: 'Profile name', |
| 11 | + required: true, |
| 12 | + }), |
| 13 | + } |
| 14 | + static description = 'Create or update a profile' |
| 15 | + static examples = [ |
| 16 | + '<%= config.bin %> <%= command.id %> my-openai-profile --provider openai --api-key sk-... --model gpt-4o', |
| 17 | + '<%= config.bin %> <%= command.id %> my-watsonx-profile --provider watsonx --api-key ... --project-id ... --service-url https://... --model ibm/granite-3-8b-instruct', |
| 18 | + ] |
| 19 | + static flags = { |
| 20 | + 'api-key': Flags.string({ |
| 21 | + description: 'API key for the provider', |
| 22 | + required: true, |
| 23 | + }), |
| 24 | + model: Flags.string({ |
| 25 | + description: 'Model to use', |
| 26 | + required: true, |
| 27 | + }), |
| 28 | + 'project-id': Flags.string({ |
| 29 | + description: 'Watsonx project ID (required for watsonx)', |
| 30 | + required: false, |
| 31 | + }), |
| 32 | + provider: Flags.string({ |
| 33 | + description: 'LLM provider', |
| 34 | + options: ['openai', 'watsonx'], |
| 35 | + required: true, |
| 36 | + }), |
| 37 | + 'service-url': Flags.string({ |
| 38 | + description: 'Watsonx service URL (required for watsonx)', |
| 39 | + required: false, |
| 40 | + }), |
| 41 | + } |
| 42 | + |
| 43 | + async run(): Promise<void> { |
| 44 | + const {args, flags} = await this.parse(ProfilesSet) |
| 45 | + |
| 46 | + if (flags.provider === 'openai') { |
| 47 | + const config: OpenAIProfileConfig = { |
| 48 | + apiKey: flags['api-key'], |
| 49 | + model: flags.model, |
| 50 | + } |
| 51 | + |
| 52 | + saveProfile({ |
| 53 | + config, |
| 54 | + name: args.name, |
| 55 | + provider: 'openai', |
| 56 | + }) |
| 57 | + |
| 58 | + this.log(`Profile "${args.name}" saved successfully`) |
| 59 | + } else if (flags.provider === 'watsonx') { |
| 60 | + if (!flags['project-id']) { |
| 61 | + this.error('--project-id is required for watsonx provider') |
| 62 | + } |
| 63 | + |
| 64 | + if (!flags['service-url']) { |
| 65 | + this.error('--service-url is required for watsonx provider') |
| 66 | + } |
| 67 | + |
| 68 | + const config: WatsonxProfileConfig = { |
| 69 | + apiKey: flags['api-key'], |
| 70 | + model: flags.model, |
| 71 | + projectId: flags['project-id'], |
| 72 | + serviceUrl: flags['service-url'], |
| 73 | + } |
| 74 | + |
| 75 | + saveProfile({ |
| 76 | + config, |
| 77 | + name: args.name, |
| 78 | + provider: 'watsonx', |
| 79 | + }) |
| 80 | + |
| 81 | + this.log(`Profile "${args.name}" saved successfully`) |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments