diff --git a/ideas/planning-tasks.md b/ideas/planning-tasks.md index 24b4bb96..8dd086f6 100644 --- a/ideas/planning-tasks.md +++ b/ideas/planning-tasks.md @@ -10,8 +10,6 @@ 🚫 ⏹️ `ai chat evaluate`: wrap python SDK 🟩 ⏹️ `ai chat evaluate`: `@file`/`--save` can read/write yaml -🟩 ⏹️ `ai flow ...`: wrap `pf` CLI - 🟩 ⏹️ `ai dev shell`: populate environment, run bash/cmd ## installation/docker diff --git a/src/ai/.x/config/flow.default.config b/src/ai/.x/config/flow.default.config deleted file mode 100644 index 6671d381..00000000 --- a/src/ai/.x/config/flow.default.config +++ /dev/null @@ -1,3 +0,0 @@ -@default.log -@default.path -@my.defaults \ No newline at end of file diff --git a/src/ai/.x/help/flow b/src/ai/.x/help/flow deleted file mode 100644 index 5c8b7d77..00000000 --- a/src/ai/.x/help/flow +++ /dev/null @@ -1,23 +0,0 @@ -FLOW - -@include.the.flow.command - -USAGE: ai flow [...] - -COMMANDS - - ai flow new [...] (see: ai help flow new) - ai flow invoke [...] (see: ai help flow invoke) - - ai flow serve [...] (see: ai help flow serve) - ai flow upload [...] (see: ai help flow upload) - - ai flow package [...] (see: ai help flow package) -`#e_;*` ai flow deploy [...] (see: ai help flow deploy) - -`#e_;* - COMING SOON` - -ADDITIONAL TOPICS - - ai help flow examples - ai help find topics flow diff --git a/src/ai/.x/help/flow.invoke b/src/ai/.x/help/flow.invoke deleted file mode 100644 index b82d098a..00000000 --- a/src/ai/.x/help/flow.invoke +++ /dev/null @@ -1,22 +0,0 @@ -FLOW INVOKE - -@include.the.flow.invoke.command - -USAGE: ai flow invoke [...] - - FLOW - --name NAME - --node NODE - --input KEY=VALUE - -EXAMPLE - - ai flow invoke --name my_flow --input question=hello - -SEE ALSO - - ai help flow - ai help flow new - ai help flow upload - ai help flow examples - ai help find topics flow \ No newline at end of file diff --git a/src/ai/.x/help/flow.new b/src/ai/.x/help/flow.new deleted file mode 100644 index 82f7c578..00000000 --- a/src/ai/.x/help/flow.new +++ /dev/null @@ -1,23 +0,0 @@ -FLOW NEW - -@include.the.flow.new.command - -USAGE: ai flow new [...] - - FLOW - --name NAME - --function MODULE:FUNCTION - --prompt-template TEMPLATE - -EXAMPLES - - ai flow new --name my_flow - ai flow new --name my_flow --function MyModule:chat_function - -SEE ALSO - - ai help flow - ai help flow invoke - ai help flow upload - ai help flow examples - ai help find topics flow \ No newline at end of file diff --git a/src/ai/.x/help/flow.package b/src/ai/.x/help/flow.package deleted file mode 100644 index e1ca0a9a..00000000 --- a/src/ai/.x/help/flow.package +++ /dev/null @@ -1,20 +0,0 @@ -FLOW PACKAGE - -@include.the.flow.package.command - -USAGE: ai flow package [...] - - FLOW - --name NAME - --docker LOCATION - -EXAMPLE - - ai flow package --name my_flow --docker /tmp/my_flow - -SEE ALSO - - ai help flow - ai help flow new - ai help flow examples - ai help find topics flow \ No newline at end of file diff --git a/src/ai/.x/help/flow.serve b/src/ai/.x/help/flow.serve deleted file mode 100644 index 6fbd6885..00000000 --- a/src/ai/.x/help/flow.serve +++ /dev/null @@ -1,21 +0,0 @@ -FLOW SERVE - -@include.the.flow.serve.command - -USAGE: ai flow serve [...] - - FLOW - --name NAME - --port PORT - --host HOST - -EXAMPLE - - ai flow serve --name my_flow --port 8080 - -SEE ALSO - - ai help flow - ai help flow new - ai help flow examples - ai help find topics flow \ No newline at end of file diff --git a/src/ai/.x/help/flow.upload b/src/ai/.x/help/flow.upload deleted file mode 100644 index 02286630..00000000 --- a/src/ai/.x/help/flow.upload +++ /dev/null @@ -1,26 +0,0 @@ -FLOW PACKAGE - -@include.the.flow.upload.command - -USAGE: ai flow upload [...] - - AZURE - --subscription SUBSCRIPTION (see: ai help subscription) - --group GROUP (see: ai help resource group) - --project NAME (see: ai help project name) - - FLOW - --name NAME - -EXAMPLE - - ai flow new --name my_flow - ai flow upload --name my_flow - -SEE ALSO - - ai help flow - ai help flow new - ai help flow invoke - ai help flow examples - ai help find topics flow \ No newline at end of file diff --git a/src/ai/.x/help/help b/src/ai/.x/help/help index f4bad274..bf24839b 100644 --- a/src/ai/.x/help/help +++ b/src/ai/.x/help/help @@ -33,7 +33,6 @@ USAGE: ai [...] ai test [...] (see: ai help test) ai chat [...] (see: ai help chat) - ai flow [...] (see: ai help flow) ai search [...] (see: ai help search) ai speech [...] (see: ai help speech) diff --git a/src/ai/.x/help/include.the.flow.command b/src/ai/.x/help/include.the.flow.command deleted file mode 100644 index 3eb1d639..00000000 --- a/src/ai/.x/help/include.the.flow.command +++ /dev/null @@ -1 +0,0 @@ - The `ai flow` command manages AI flows, including prompt flows. diff --git a/src/ai/.x/help/include.the.flow.invoke.command b/src/ai/.x/help/include.the.flow.invoke.command deleted file mode 100644 index 52a65532..00000000 --- a/src/ai/.x/help/include.the.flow.invoke.command +++ /dev/null @@ -1,2 +0,0 @@ - The `ai flow invoke` command invokes a flow, likely created using - the `ai flow new` command. diff --git a/src/ai/.x/help/include.the.flow.new.command b/src/ai/.x/help/include.the.flow.new.command deleted file mode 100644 index 28cfc811..00000000 --- a/src/ai/.x/help/include.the.flow.new.command +++ /dev/null @@ -1,2 +0,0 @@ - The `ai flow new` command initializes a new flow directory; - By default that flow directory is a chat prompt flow. diff --git a/src/ai/.x/help/include.the.flow.package.command b/src/ai/.x/help/include.the.flow.package.command deleted file mode 100644 index f83f115d..00000000 --- a/src/ai/.x/help/include.the.flow.package.command +++ /dev/null @@ -1 +0,0 @@ - The `ai flow package` command packages a flow as a Dockerfile. diff --git a/src/ai/.x/help/include.the.flow.serve.command b/src/ai/.x/help/include.the.flow.serve.command deleted file mode 100644 index f38c30f6..00000000 --- a/src/ai/.x/help/include.the.flow.serve.command +++ /dev/null @@ -1 +0,0 @@ - The `ai flow serve` command serves a flow as an endpoint. diff --git a/src/ai/.x/help/include.the.flow.upload.command b/src/ai/.x/help/include.the.flow.upload.command deleted file mode 100644 index 6693cd81..00000000 --- a/src/ai/.x/help/include.the.flow.upload.command +++ /dev/null @@ -1 +0,0 @@ - The `ai flow upload` command uploads an existing flow to AI Studio. diff --git a/src/ai/.x/help/usage b/src/ai/.x/help/usage index c8a1baeb..e2374d9d 100644 --- a/src/ai/.x/help/usage +++ b/src/ai/.x/help/usage @@ -19,7 +19,6 @@ USAGE: ai [...] ai test [...] (see: ai help test) ai chat [...] (see: ai help chat) - ai flow [...] (see: ai help flow) ai search [...] (see: ai help search) ai speech [...] (see: ai help speech) diff --git a/src/ai/Program_AI.cs b/src/ai/Program_AI.cs index 9a553cba..677abc5c 100644 --- a/src/ai/Program_AI.cs +++ b/src/ai/Program_AI.cs @@ -113,11 +113,11 @@ public AiProgramData() #endregion #region help command data - public string HelpCommandTokens => "wizard;dev;test;init;config;chat;flow;speech;vision;language;search;service;tool;samples;eval;run"; + public string HelpCommandTokens => "wizard;dev;test;init;config;chat;speech;vision;language;search;service;tool;samples;eval;run"; #endregion #region config command data - public string ConfigScopeTokens => $"wizard;dev;test;init;chat;flow;speech;vision;language;search;service;tool;samples;eval;run;*"; + public string ConfigScopeTokens => $"wizard;dev;test;init;chat;speech;vision;language;search;service;tool;samples;eval;run;*"; #endregion #region zip option data @@ -170,7 +170,6 @@ public bool DispatchRunCommand(ICommandValues values) return root switch { "init" => (new InitCommand(values)).RunCommand(), "chat" => (new ChatCommand(values)).RunCommand(), - "flow" => (new FlowCommand(values)).RunCommand(), "speech" => (new SpeechCommand(values)).RunCommand(), "vision" => (new VisionCommand(values)).RunCommand(), "language" => (new LanguageCommand(values)).RunCommand(), @@ -199,7 +198,6 @@ public bool DispatchParseCommand(INamedValueTokens tokens, ICommandValues values "init" => InitCommandParser.ParseCommand(tokens, values), "config" => ConfigCommandParser.ParseCommand(tokens, values), "chat" => ChatCommandParser.ParseCommand(tokens, values), - "flow" => FlowCommandParser.ParseCommand(tokens, values), "eval" => EvalCommandParser.ParseCommand(tokens, values), "speech" => SpeechCommandParser.ParseCommand(tokens, values), "vision" => VisionCommandParser.ParseCommand(tokens, values), @@ -225,7 +223,6 @@ public bool DispatchParseCommandValues(INamedValueTokens tokens, ICommandValues "init" => InitCommandParser.ParseCommandValues(tokens, values), "config" => ConfigCommandParser.ParseCommandValues(tokens, values), "chat" => ChatCommandParser.ParseCommandValues(tokens, values), - "flow" => FlowCommandParser.ParseCommandValues(tokens, values), "eval" => EvalCommandParser.ParseCommandValues(tokens, values), "speech" => SpeechCommandParser.ParseCommandValues(tokens, values), "vision" => VisionCommandParser.ParseCommandValues(tokens, values), diff --git a/src/ai/commands/flow_command.cs b/src/ai/commands/flow_command.cs deleted file mode 100644 index 7218ea90..00000000 --- a/src/ai/commands/flow_command.cs +++ /dev/null @@ -1,221 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. -// - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; - -namespace Azure.AI.Details.Common.CLI -{ - public class FlowCommand : Command - { - internal FlowCommand(ICommandValues values) - { - _values = values.ReplaceValues(); - _quiet = _values.GetOrDefault("x.quiet", false); - _verbose = _values.GetOrDefault("x.verbose", true); - } - - internal bool RunCommand() - { - try - { - RunFlowCommand().Wait(); - } - catch (WebException ex) - { - ConsoleHelpers.WriteLineError($"\n ERROR: {ex.Message}"); - JsonHelpers.PrintJson(HttpHelpers.ReadWriteJson(ex.Response, _values, "flow")); - } - - return _values.GetOrDefault("passed", true); - } - - private async Task RunFlowCommand() - { - await DoCommand(_values.GetCommand()); - return _values.GetOrDefault("passed", true); - } - - private async Task DoCommand(string command) - { - StartCommand(); - - switch (command) - { - case "flow.new": await DoNewFlow(); break; - case "flow.invoke": await DoInvokeFlow(); break; - case "flow.serve": await DoServeFlow(); break; - case "flow.upload": await DoUploadFlow(); break; - case "flow.package": await DoPackageFlow(); break; - // case "flow.deploy": await DoDeployFlow(); break; - - default: - _values.AddThrowError("WARNING:", $"'{command.Replace('.', ' ')}' NOT YET IMPLEMENTED!!"); - break; - } - - StopCommand(); - DisposeAfterStop(); - DeleteTemporaryFiles(); - } - - private async Task DoNewFlow() - { - var action = "Creating flow"; - var command = "flow new"; - - var flow = FlowNameToken.Data().Demand(_values, action, command); - var prompt = SystemPromptTemplateToken.Data().GetOrDefault(_values); - var function = FunctionToken.Data().GetOrDefault(_values, ""); - SplitFunctionReference(function, out var module, out function); - - await DoFlowInitConsoleGui(flow, prompt, function, module); - } - - private async Task DoInvokeFlow() - { - var action = "Invoking flow"; - var command = "flow invoke"; - - var flowName = FlowNameToken.Data().Demand(_values, action, command); - var nodeName = FlowNodeToken.Data().GetOrDefault(_values); - var inputs = string.Join(" ", InputWildcardToken.GetNames(_values) - .Select(name => $"{name}={InputWildcardToken.Data(name).GetOrDefault(_values)}")); - - await DoFlowTestConsoleGui(flowName, inputs, nodeName); - } - - private async Task DoServeFlow() - { - var action = "Serving flow"; - var command = "flow serve"; - - var flowName = FlowNameToken.Data().Demand(_values, action, command); - var port = PortToken.Data().GetOrDefault(_values); - var host = HostToken.Data().GetOrDefault(_values); - var env = EnvironmentVariablesToken.Data().GetOrDefault(_values); - - await DoFlowServeConsoleGui(flowName, port, host, env); - } - - private async Task DoUploadFlow() - { - var action = "Uploading flow"; - var command = "flow upload"; - - var flowName = FlowNameToken.Data().Demand(_values, action, command); - var subscription = SubscriptionToken.Data().Demand(_values, action, command, "subscription"); - var resourceGroup = ResourceGroupNameToken.Data().Demand(_values, action, command, "group"); - var projectName = ProjectNameToken.Data().Demand(_values, action, command, "project"); - - await DoFlowUpload(subscription, resourceGroup, projectName, flowName); - } - - private async Task DoPackageFlow() - { - var action = "Packaging flow"; - var command = "flow package"; - - var flowName = FlowNameToken.Data().Demand(_values, action, command); - var dockerBuildContext = DockerBuildContextToken.Data().Demand(_values, action, command); - - await DoFlowBuild(flowName, dockerBuildContext, "docker"); - } - - private async Task DoFlowInitConsoleGui(string flow, string prompt, string function, string module) - { - var response = await PfCli.FlowInit(flow, module, function, prompt, "chat", true); - if (!string.IsNullOrEmpty(response.StdError)) - { - _values.AddThrowError("ERROR:", response.StdError); - } - } - - private async Task DoFlowTestConsoleGui(string flowName, string inputs, string nodeName) - { - var response = await PfCli.FlowTest(flowName, inputs, nodeName); - if (!string.IsNullOrEmpty(response.StdError)) - { - _values.AddThrowError("ERROR:", response.StdError); - } - } - - private async Task DoFlowServeConsoleGui(string flowName, string port, string host, string env) - { - var response = await PfCli.FlowServe(flowName, port, host, env); - if (!string.IsNullOrEmpty(response.StdError)) - { - _values.AddThrowError("ERROR:", response.StdError); - } - } - - private Task DoFlowUpload(string subscription, string resourceGroup, string projectName, string flowName) - { - return PfCli.FlowUpload(subscription, resourceGroup, projectName, flowName); - } - - private async Task DoFlowBuild(string flowName, string dockerBuildContext, string format) - { - var response = await PfCli.FlowBuild(flowName, dockerBuildContext, format); - if (!string.IsNullOrEmpty(response.StdError)) - { - _values.AddThrowError("ERROR:", response.StdError); - } - } - - private static void SplitFunctionReference(string functionData, out string entryFile, out string functionName) - { - var parts = functionData.Split(':'); - entryFile = parts != null && parts.Length > 0 ? parts[0] : ""; - functionName = parts != null && parts.Length > 1 ? parts[1] : ""; - } - - private void DisplayBanner(string which) - { - if (_quiet) return; - - var logo = FileHelpers.FindFileInHelpPath($"help/include.{Program.Name}.{which}.ascii.logo"); - if (!string.IsNullOrEmpty(logo)) - { - var text = FileHelpers.ReadAllHelpText(logo, Encoding.UTF8); - ConsoleHelpers.WriteLineWithHighlight(text); - } - } - - private void StartCommand() - { - CheckPath(); - LogHelpers.EnsureStartLogFile(_values); - - // _display = new DisplayHelper(_values); - - // _output = new OutputHelper(_values); - // _output.StartOutput(); - - _lock = new SpinLock(); - _lock.StartLock(); - } - - private void StopCommand() - { - _lock.StopLock(5000); - - // LogHelpers.EnsureStopLogFile(_values); - // _output.CheckOutput(); - // _output.StopOutput(); - - _stopEvent.Set(); - } - - private SpinLock _lock = null; - private readonly bool _quiet = false; - private readonly bool _verbose = false; - } -} diff --git a/src/ai/commands/parsers/flow_command_parser.cs b/src/ai/commands/parsers/flow_command_parser.cs deleted file mode 100644 index 0b19ed21..00000000 --- a/src/ai/commands/parsers/flow_command_parser.cs +++ /dev/null @@ -1,127 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. -// - -using System.Collections.Generic; - -namespace Azure.AI.Details.Common.CLI -{ - class FlowCommandParser : CommandParser - { - public static bool ParseCommand(INamedValueTokens tokens, ICommandValues values) - { - return ParseCommands(_commands, _partialCommands, tokens, values, x => GetCommandParsers(x)); - } - - public static bool ParseCommandValues(INamedValueTokens tokens, ICommandValues values) - { - return ParseCommandValues("flow", GetCommandParsers(values), tokens, values); - } - - private static readonly (string name, bool valuesRequired)[] _commands = { - ("flow.new", true), - ("flow.invoke", true), - ("flow.serve", true), - ("flow.upload", true), - ("flow.package", true), - ("flow.deploy", true), - }; - - private static readonly string[] _partialCommands = { - "flow" - }; - - private static IEnumerable GetCommandParsers(ICommandValues values) - { - var commandName = values.GetCommand(); - - switch (commandName) - { - case "flow.new": return _flowNewParsers; - case "flow.invoke": return _flowInvokeParsers; - case "flow.deploy": return _flowDeployParsers; - case "flow.upload": return _flowUploadParsers; - case "flow.package": return _flowPackageParsers; - case "flow.serve": return _flowServeParsers; - } - - foreach (var command in _commands) - { - if (commandName == command.name) - { - return _flowPlaceHolderParsers; - } - } - - return null; - } - - public class CommonFlowNamedValueTokenParsers : NamedValueTokenParserList - { - public CommonFlowNamedValueTokenParsers() : base( - - new NamedValueTokenParser(null, "x.command", "11", "1"), - - new ExpectOutputTokenParser(), - new DiagnosticLogTokenParser(), - new CommonNamedValueTokenParsers(), - - new NamedValueTokenParser("--ini", "ini.file", "10", "1", "@"), - - new NamedValueTokenParser(null, "x.command.expand.file.name", "11111", "1") - - ) - { - } - } - - private static INamedValueTokenParser[] _flowPlaceHolderParsers = { - new CommonFlowNamedValueTokenParsers() - }; - - private static INamedValueTokenParser[] _flowNewParsers = { - new CommonFlowNamedValueTokenParsers(), - FlowNameToken.Parser(), - FunctionToken.Parser(), - SystemPromptTemplateToken.Parser(), - // --type TYPE (can be chat/evaluate/standard) default is chat, and only chat is implemented at the moment - // --yes (we'll always pass --yes, as we don't want `pf flow init` to prompt for anything) - }; - - private static INamedValueTokenParser[] _flowInvokeParsers = { - new CommonFlowNamedValueTokenParsers(), - FlowNameToken.Parser(), - FlowNodeToken.Parser(), - InputWildcardToken.Parser(), - }; - - private static INamedValueTokenParser[] _flowDeployParsers = { - new CommonFlowNamedValueTokenParsers(), - FlowNameToken.Parser() - }; - - private static INamedValueTokenParser[] _flowUploadParsers = { - new CommonFlowNamedValueTokenParsers(), - SubscriptionToken.Parser(), - ResourceGroupNameToken.Parser(), - ProjectNameToken.Parser(), - FlowNameToken.Parser(), - }; - - - private static INamedValueTokenParser[] _flowPackageParsers = { - new CommonFlowNamedValueTokenParsers(), - FlowNameToken.Parser(), - DockerBuildContextToken.Parser() - }; - - private static INamedValueTokenParser[] _flowServeParsers = { - new CommonFlowNamedValueTokenParsers(), - FlowNameToken.Parser(), - HostToken.Parser(), - PortToken.Parser(), - EnvironmentVariablesToken.Parser(), - }; - } -} diff --git a/src/ai/commands/parsers/service_command_parser.cs b/src/ai/commands/parsers/service_command_parser.cs index de14c97a..5451627e 100644 --- a/src/ai/commands/parsers/service_command_parser.cs +++ b/src/ai/commands/parsers/service_command_parser.cs @@ -52,12 +52,6 @@ private static readonly (string name, bool valuesRequired)[] _commands = { ("service.search.update", true), ("service.search.delete", true), ("service.search", true), - ("service.flow.create", true), - ("service.flow.status", true), - ("service.flow.list", false), - ("service.flow.update", true), - ("service.flow.delete", true), - ("service.flow", true), ("service.evaluation.create", true), ("service.evaluation.status", true), ("service.evaluation.list", false), @@ -73,7 +67,6 @@ private static readonly (string name, bool valuesRequired)[] _commands = { "service.connection", "service.deployment", "service.search", - "service.flow", "service.evaluation", "service" }; diff --git a/src/common/details/named_values/tokens/flow_name_token.cs b/src/common/details/named_values/tokens/flow_name_token.cs deleted file mode 100644 index 2b0148f9..00000000 --- a/src/common/details/named_values/tokens/flow_name_token.cs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. -// - -namespace Azure.AI.Details.Common.CLI -{ - public class FlowNameToken - { - public static NamedValueTokenData Data() => new NamedValueTokenData(_optionName, _fullName, _optionExample, _requiredDisplayName); - public static INamedValueTokenParser Parser(bool requireFlowPart = false) => new NamedValueTokenParser(_optionName, _fullName, requireFlowPart ? "11" : "01;10", "1"); - - private const string _requiredDisplayName = "flow name"; - private const string _optionName = "--flow-name"; - private const string _optionExample = "NAME"; - private const string _fullName = "flow.name"; - } -} diff --git a/src/common/details/named_values/tokens/flow_node_token.cs b/src/common/details/named_values/tokens/flow_node_token.cs deleted file mode 100644 index b741c510..00000000 --- a/src/common/details/named_values/tokens/flow_node_token.cs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. -// - -namespace Azure.AI.Details.Common.CLI -{ - public class FlowNodeToken - { - public static NamedValueTokenData Data() => new NamedValueTokenData(_optionName, _fullName, _optionExample, _requiredDisplayName); - public static INamedValueTokenParser Parser(bool requireFlowPart = false) => new NamedValueTokenParser(_optionName, _fullName, requireFlowPart ? "11" : "01;10", "1"); - - private const string _requiredDisplayName = "flow node"; - private const string _optionName = "--flow-node"; - private const string _optionExample = "NODE"; - private const string _fullName = "flow.node"; - } -} diff --git a/src/common/details/pfcli/PfCli.cs b/src/common/details/pfcli/PfCli.cs deleted file mode 100644 index 164cf1fa..00000000 --- a/src/common/details/pfcli/PfCli.cs +++ /dev/null @@ -1,205 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. -// - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using Azure.AI.Details.Common.CLI; -using System.Collections.Generic; - -namespace Azure.AI.Details.Common.CLI -{ - public class PfCli - { - public static async Task FlowInit(string flowPath, string entryFile = null, string functionName = null, string promptTemplate = null, string type = null, bool yes = false) - { - var cmdPart = "flow init"; - var argsPart = CliHelpers.BuildCliArgs( - "--flow", flowPath, - "--entry", entryFile, - "--function", functionName, - "--prompt-template", promptTemplate, - "--type", type) + - (yes ? " --yes" : ""); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task FlowTest(string flowPath, string inputs, string node = null, string variant = null, bool debug = false, bool interactive = false, bool verbose = false) - { - var cmdPart = "flow test"; - var argsPart = CliHelpers.BuildCliArgs( - "--config", "connection.provider=azureml", - "--flow", flowPath, - "--inputs", inputs, - "--node", node, - "--variant", variant) + - (debug ? " --debug" : "") + - (interactive ? " --interactive" : "") + - (verbose ? " --verbose" : ""); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static Task FlowUpload(string subscription, string resourceGroup, string projectName, string flowName) - { - var cmdPart = "flow create"; - var argsPart = CliHelpers.BuildCliArgs( - "--subscription", subscription, - "--resource-group", resourceGroup, - "--workspace-name", projectName, - "--flow", flowName); - - return ProcessHelpers.RunShellCommandAsync("pfazure", $"{cmdPart} {argsPart} --set name={flowName} type=chat", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task FlowBuild(string flowPath, string output, string format, string variant = null, bool verbose = false, bool debug = false) - { - var cmdPart = "flow build"; - var argsPart = CliHelpers.BuildCliArgs( - "--source", flowPath, - "--output", output, - "--format", format, - "--variant", variant) + - (verbose ? " --verbose" : "") + - (debug ? " --debug" : ""); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task FlowServe(string flowPath, string port = null, string host = null, string environmentVariables = null, bool verbose = false, bool debug = false) - { - var cmdPart = "flow serve"; - var argsPart = CliHelpers.BuildCliArgs( - "--config", "connection.provider=azureml", - "--source", flowPath, - "--port", port, - "--host", host, - "--environment-variables", environmentVariables) + - (verbose ? " --verbose" : "") + - (debug ? " --debug" : ""); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task RunCreate(string flowPath, string file, string data, string columnMapping, string run, string variant, bool stream, string environmentVariables, string connections, string set) - { - var cmdPart = "run create"; - var argsPart = CliHelpers.BuildCliArgs( - "--flow", flowPath, - "--file", file, - "--data", data, - "--column-mapping", columnMapping, - "--run", run, - "--variant", variant, - "--environment-variables", environmentVariables, - "--connections", connections, - "--set", set) + - (stream ? " --stream" : ""); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task RunUpdate(string name, string set) - { - var cmdPart = "run update"; - var argsPart = CliHelpers.BuildCliArgs( - "--name", name, - "--set", set); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task RunStream(string name) - { - var cmdPart = "run stream"; - var argsPart = CliHelpers.BuildCliArgs("--name", name); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task RunList(bool allResults, bool archivedOnly, bool includeArchived, int maxResults) - { - var cmdPart = "run list"; - var argsPart = CliHelpers.BuildCliArgs( - "--max-results", maxResults.ToString()) + - (allResults ? " --all-results" : "") + - (archivedOnly ? " --archived-only" : "") + - (includeArchived ? " --include-archived" : ""); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task RunShow(string name) - { - var cmdPart = "run show"; - var argsPart = CliHelpers.BuildCliArgs("--name", name); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task RunShowDetails(string name) - { - var cmdPart = "run show-details"; - var argsPart = CliHelpers.BuildCliArgs("--name", name); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task RunShowMetrics(string name) - { - var cmdPart = "run show-metrics"; - var argsPart = CliHelpers.BuildCliArgs("--name", name); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task RunVisualize(string names) - { - var cmdPart = "run visualize"; - var argsPart = CliHelpers.BuildCliArgs("--names", names); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task RunArchive(string name) - { - var cmdPart = "run archive"; - var argsPart = CliHelpers.BuildCliArgs("--name", name); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - public static async Task RunRestore(string name) - { - var cmdPart = "run restore"; - var argsPart = CliHelpers.BuildCliArgs("--name", name); - - return await ProcessHelpers.RunShellCommandAsync("pf", $"{cmdPart} {argsPart}", null, StdOutputHandler(), StandardErrorHandler()); - } - - private static Action StandardErrorHandler() - { - return x => Console.Error.WriteLine(RemapStrings(x)); - } - - private static Action StdOutputHandler() - { - return x => Console.WriteLine(RemapStrings(x)); - } - - private static string RemapStrings(string x) - { - var check = "You can execute this command to test the flow, pf flow test"; - if (x.StartsWith(check)) - { - x = x.Replace(check, "You can execute this command to test the flow, ai flow invoke"); - x = x.Replace(" --interactive", ""); - } - return x; - } - } -} diff --git a/tests/test-speech.yaml b/tests/test-speech.yaml index 21fddefe..b7239457 100644 --- a/tests/test-speech.yaml +++ b/tests/test-speech.yaml @@ -32,6 +32,13 @@ - name: install requirements bash: | cd speech-to-text-py + if [ -f /etc/os-release ]; then + python3 -m venv env + source env/bin/activate + else + python -m venv env + source env/Scripts/activate + fi pip install -r requirements.txt # - name: run template # command: ai dev shell @@ -39,8 +46,10 @@ # bash: | # cd speech-to-text-py # if [ -f /etc/os-release ]; then + # source env/bin/activate # python3 main.py # else + # source env/Scripts/activate # python main.py # fi # tag: skip-run-requires-microphone @@ -67,6 +76,13 @@ - name: install requirements bash: | cd speech-to-text-continuous-reco-py + if [ -f /etc/os-release ]; then + python3 -m venv env + source env/bin/activate + else + python -m venv env + source env/Scripts/activate + fi pip install -r requirements.txt # - name: run template # command: ai dev shell @@ -74,8 +90,10 @@ # bash: | # cd speech-to-text-continuous-reco-py # if [ -f /etc/os-release ]; then + # source env/bin/activate # python3 main.py # else + # source env/Scripts/activate # python main.py # fi # tag: skip-run-requires-microphone @@ -105,6 +123,13 @@ - name: install requirements bash: | cd speech-to-text-with-file-py + if [ -f /etc/os-release ]; then + python3 -m venv env + source env/bin/activate + else + python -m venv env + source env/Scripts/activate + fi pip install -r requirements.txt - name: create audio file for input command: ai speech synthesize --text "Hello world" --audio-output "speech-to-text-with-file-py/hello.wav" @@ -114,8 +139,10 @@ bash: | cd speech-to-text-with-file-py if [ -f /etc/os-release ]; then + source env/bin/activate python3 main.py hello.wav else + source env/Scripts/activate python main.py hello.wav fi @@ -143,6 +170,13 @@ - name: install requirements bash: | cd speech-to-text-with-keyword-py + if [ -f /etc/os-release ]; then + python3 -m venv env + source env/bin/activate + else + python -m venv env + source env/Scripts/activate + fi pip install -r requirements.txt # - name: create audio file for input # command: ai speech synthesize --text "Computer tell me a joke. Computer tell me another joke." --audio-output "speech-to-text-with-keyword-py/jokes.wav" @@ -152,8 +186,10 @@ # bash: | # cd speech-to-text-with-keyword-py # if [ -f /etc/os-release ]; then + # source env/bin/activate # python3 main.py jokes.wav # else + # source env/Scripts/activate # python main.py jokes.wav # fi # tag: skip-run-requires-bugfix @@ -183,6 +219,13 @@ - name: install requirements bash: | cd speech-to-text-with-translation-py + if [ -f /etc/os-release ]; then + python3 -m venv env + source env/bin/activate + else + python -m venv env + source env/Scripts/activate + fi pip install -r requirements.txt - name: create audio file for input command: ai speech synthesize --text "Hello world" --audio-output "speech-to-text-with-translation-py/hello.wav" @@ -192,8 +235,10 @@ bash: | cd speech-to-text-with-translation-py if [ -f /etc/os-release ]; then + source env/bin/activate python3 main.py hello.wav else + source env/Scripts/activate python main.py hello.wav fi @@ -221,6 +266,13 @@ - name: install requirements bash: | cd text-to-speech-py + if [ -f /etc/os-release ]; then + python3 -m venv env + source env/bin/activate + else + python -m venv env + source env/Scripts/activate + fi pip install -r requirements.txt # - name: run template # command: ai dev shell @@ -228,8 +280,10 @@ # bash: | # cd text-to-speech-py # if [ -f /etc/os-release ]; then + # source env/bin/activate # python3 main.py # else + # source env/Scripts/activate # python main.py # fi # tag: skip-run-requires-speakers @@ -257,6 +311,13 @@ - name: install requirements bash: | cd text-to-speech-with-file-py + if [ -f /etc/os-release ]; then + python3 -m venv env + source env/bin/activate + else + python -m venv env + source env/Scripts/activate + fi pip install -r requirements.txt - name: run template command: ai dev shell @@ -264,8 +325,10 @@ bash: | cd text-to-speech-with-file-py if [ -f /etc/os-release ]; then + source env/bin/activate python3 main.py else + source env/Scripts/activate python main.py fi input: |- diff --git a/tests/test.yaml b/tests/test.yaml index c4a89ec8..f6b56a92 100644 --- a/tests/test.yaml +++ b/tests/test.yaml @@ -54,7 +54,6 @@ ^ ai test \[\.\.\.\] \(see: ai help test\)\r?$\n ^\r?$\n ^ ai chat \[\.\.\.\] \(see: ai help chat\)\r?$\n - ^ ai flow \[\.\.\.\] \(see: ai help flow\)\r?$\n ^\r?$\n ^ ai search \[\.\.\.\] \(see: ai help search\)\r?$\n ^ ai speech \[\.\.\.\] \(see: ai help speech\)\r?$\n diff --git a/tests/test3.yaml b/tests/test3.yaml index e42cb105..1fa8ad60 100644 --- a/tests/test3.yaml +++ b/tests/test3.yaml @@ -141,9 +141,16 @@ steps: - name: generate template command: ai dev new openai-chat --python - - name: build template + - name: install requirements bash: | cd openai-chat-py + if [ -f /etc/os-release ]; then + python3 -m venv env + source env/bin/activate + else + python -m venv env + source env/Scripts/activate + fi pip install -r requirements.txt - name: run template command: ai dev shell @@ -151,8 +158,10 @@ bash: | cd openai-chat-py if [ -f /etc/os-release ]; then + source env/bin/activate python3 openai_chat_completions.py else + source env/Scripts/activate python openai_chat_completions.py fi input: |- @@ -242,9 +251,16 @@ steps: - name: generate template command: ai dev new openai-chat-streaming --python - - name: build template + - name: install requirements bash: | cd openai-chat-streaming-py + if [ -f /etc/os-release ]; then + python3 -m venv env + source env/bin/activate + else + python -m venv env + source env/Scripts/activate + fi pip install -r requirements.txt - name: run template command: ai dev shell @@ -252,8 +268,10 @@ bash: | cd openai-chat-streaming-py if [ -f /etc/os-release ]; then + source env/bin/activate python3 main.py else + source env/Scripts/activate python main.py fi input: |- @@ -298,9 +316,16 @@ steps: - name: generate template command: ai dev new openai-chat-streaming-with-data --python - - name: build template + - name: install requirements bash: | cd openai-chat-streaming-with-data-py + if [ -f /etc/os-release ]; then + python3 -m venv env + source env/bin/activate + else + python -m venv env + source env/Scripts/activate + fi pip install -r requirements.txt - name: run template command: ai dev shell @@ -308,8 +333,10 @@ bash: | cd openai-chat-streaming-with-data-py if [ -f /etc/os-release ]; then + source env/bin/activate python3 main.py else + source env/Scripts/activate python main.py fi input: |- @@ -385,9 +412,16 @@ steps: - name: generate template command: ai dev new openai-chat-streaming-with-functions --python - - name: build template + - name: install requirements bash: | cd openai-chat-streaming-with-functions-py + if [ -f /etc/os-release ]; then + python3 -m venv env + source env/bin/activate + else + python -m venv env + source env/Scripts/activate + fi pip install -r requirements.txt - name: run template command: ai dev shell @@ -395,8 +429,10 @@ bash: | cd openai-chat-streaming-with-functions-py if [ -f /etc/os-release ]; then + source env/bin/activate python3 main.py else + source env/Scripts/activate python main.py fi input: |-