Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ralphe/telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
ralph-msft committed Mar 27, 2024
2 parents af1c514 + 39f484a commit 3190c30
Show file tree
Hide file tree
Showing 105 changed files with 1,661 additions and 1,769 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @robch
128 changes: 128 additions & 0 deletions ideas/azd-imposter/azd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>
#include <algorithm>
#include <istream>
#include <string>
#include <windows.h>

using namespace std;

constexpr char* pathSeparator = ";";
constexpr char* dirSeparator = "\\";
constexpr char* azdBinaryFileName = "azd.exe";
constexpr char* azdFullNameCacheFile = "azd.ini";
constexpr char* azdFullNameMustContains = "Azure Dev CLI";

constexpr char* aiCommandName = "ai";
constexpr char* aiBinaryFileName = "ai.exe";

string findMyself() {
char path[MAX_PATH];
GetModuleFileNameA(NULL, path, MAX_PATH);

auto whereThisBinaryLives = string(path);
auto lastSlash = whereThisBinaryLives.find_last_of(dirSeparator);
if (lastSlash != string::npos) {
whereThisBinaryLives = whereThisBinaryLives.substr(0, lastSlash);
}
else {
whereThisBinaryLives = ".";
}

return whereThisBinaryLives;
}

bool fileExists(const string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}

string findAzdBinaryInPath() {
vector<string> paths;
char* path = getenv("PATH");
char* token = strtok(path, pathSeparator);
while (token != NULL) {
paths.push_back(string(token));
token = strtok(NULL, pathSeparator);
}

for (auto& p : paths) {
string withPath = p + std::string(dirSeparator) + azdBinaryFileName;
if (fileExists(withPath) && withPath.find(azdFullNameMustContains) != string::npos) {
return withPath;
}
}

printf("ERROR: `%s` not found in PATH!!\n\n TRY: Update PATH to include location %s...\n OR: Update %s with full path to %s", azdBinaryFileName, azdBinaryFileName, azdFullNameCacheFile, azdBinaryFileName);
exit(1);
}

string findAndCacheAzdBinary()
{
auto whereThisBinaryLives = findMyself();

auto sideBySideCacheFile = whereThisBinaryLives + dirSeparator + azdFullNameCacheFile;
ifstream cacheStream(sideBySideCacheFile);

string cachedContent;
if (cacheStream.good()) {
getline(cacheStream, cachedContent);
cacheStream.close();
} else {
cachedContent = findAzdBinaryInPath();
std::ofstream outFile(sideBySideCacheFile);
outFile << cachedContent;
outFile.close();
}

return cachedContent;
}

string quoteArgIfNeeded(const char* arg) {

bool needsQuoted = false;
string argStr(arg);

if (argStr.find('\"') != string::npos) {
needsQuoted = true;
size_t pos = 0;
while ((pos = argStr.find("\"", pos)) != string::npos) {
argStr.replace(pos, 1, "\\\"");
pos += 2;
}
}

if (argStr.find(' ') != string::npos) {
needsQuoted = true;
}

return needsQuoted
? "\"" + argStr + "\""
: argStr;
}

int main(int argc, char* argv[]) {

auto actualBinaryFullFileName = findAndCacheAzdBinary();

if (argc > 1 && string(argv[1]) == aiCommandName) {
string commandLine(aiBinaryFileName);
for (int i = 2; i < argc; i++) {
commandLine += " ";
commandLine += quoteArgIfNeeded(argv[i]);
}
return system(commandLine.c_str());
} else {
string commandLine("\"" + actualBinaryFullFileName + "\"");
for (int i = 1; i < argc; i++) {
commandLine += " ";
commandLine += quoteArgIfNeeded(argv[i]);
}
return system(commandLine.c_str());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Azure.AI.Details.Common.CLI.Extensions.HelperFunctions;

public static class NutritionHelperFunctions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Azure.AI.Details.Common.CLI.Extensions.HelperFunctions;

public static class PokemonHelperFunctions
Expand Down
2 changes: 0 additions & 2 deletions ideas/planning-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion scripts/Azure-AI-CLI-Setup.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@
supported here. Thus need to check for each possible 8.x SDK folder and
if none is found then install the configured (highest) 8.x version.
-->
<util:DirectorySearch Id="DotNet80202" Path="[ProgramFiles64Folder]dotnet\sdk\8.0.202" Result="exists" Variable="NET_80202"/>
<util:DirectorySearch Id="DotNet80201" Path="[ProgramFiles64Folder]dotnet\sdk\8.0.201" Result="exists" Variable="NET_80201"/>
<util:DirectorySearch Id="DotNet80200" Path="[ProgramFiles64Folder]dotnet\sdk\8.0.200" Result="exists" Variable="NET_80200"/>
<util:DirectorySearch Id="DotNet80103" Path="[ProgramFiles64Folder]dotnet\sdk\8.0.103" Result="exists" Variable="NET_80103"/>
<util:DirectorySearch Id="DotNet80102" Path="[ProgramFiles64Folder]dotnet\sdk\8.0.102" Result="exists" Variable="NET_80102"/>
<util:DirectorySearch Id="DotNet80101" Path="[ProgramFiles64Folder]dotnet\sdk\8.0.101" Result="exists" Variable="NET_80101"/>
<util:DirectorySearch Id="DotNet80100" Path="[ProgramFiles64Folder]dotnet\sdk\8.0.100" Result="exists" Variable="NET_80100"/>

<PackageGroup Id="DotNetSdk">
<ExePackage Compressed="no"
DetectCondition="NET_80201 OR NET_80200 OR NET_80102 OR NET_80101 OR NET_80100"
DetectCondition="NET_80202 OR NET_80201 OR NET_80200 OR NET_80103 OR NET_80102 OR NET_80101 OR NET_80100"
DownloadUrl="$(var.dotNetUrl)"
InstallCommand="/quiet /norestart"
PerMachine="yes"
Expand Down
4 changes: 2 additions & 2 deletions scripts/WixBuildInstaller.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ set INSTALLER_FILE=Setup-%TARGET_PLATFORM%.exe
set PACKAGE_URL=https://csspeechstorage.blob.core.windows.net/drop/private/ai/Azure.AI.CLI.%PACKAGE_VERSION%.nupkg

REM Dependencies (note: do NOT use redirecting URLs like aka.ms)
set AZURE_CLI_VERSION=2.57.0
set AZURE_CLI_VERSION=2.58.0
set AZURE_CLI_INSTALLER=azure-cli-%AZURE_CLI_VERSION%-%TARGET_PLATFORM%.msi
set AZURE_CLI_URL=https://azcliprod.blob.core.windows.net/msi/%AZURE_CLI_INSTALLER%
set DOTNET_VERSION=8.0.201
set DOTNET_VERSION=8.0.202
set DOTNET_INSTALLER=dotnet-sdk-%DOTNET_VERSION%-win-%TARGET_PLATFORM%.exe
set DOTNET_URL=https://dotnetcli.azureedge.net/dotnet/Sdk/%DOTNET_VERSION%/%DOTNET_INSTALLER%
set VCRT_VERSION=14.38.33135
Expand Down
3 changes: 0 additions & 3 deletions src/ai/.x/config/flow.default.config

This file was deleted.

10 changes: 5 additions & 5 deletions src/ai/.x/help/dev
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
___ ____ ___ _____ ___ _____ __
/ _ /_ / / _ |/_ _/ / _ \/ __/ | / /
/ __ |/ /_/ __ |_/ /_ / // / _/ | |/ /
/_/ |_/___/_/ |_/____/ /____/___/ |___/

___ _____ ___ _____ __
/ _ |/_ _/ / _ \/ __/ | / /
/ __ |_/ /_ / // / _/ | |/ /
/_/ |_/____/ /____/___/ |___/
USAGE: ai dev <command> [...]

COMMANDS
Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/examples
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
___ ____ ___ _____
/ _ /_ / / _ |/_ _/
/ __ |/ /_/ __ |_/ /_
/_/ |_/___/_/ |_/____/
___ _____
/ _ |/_ _/
/ __ |_/ /_
/_/ |_/____/

USAGE: ai <command> [...]

Expand Down
23 changes: 0 additions & 23 deletions src/ai/.x/help/flow

This file was deleted.

22 changes: 0 additions & 22 deletions src/ai/.x/help/flow.invoke

This file was deleted.

23 changes: 0 additions & 23 deletions src/ai/.x/help/flow.new

This file was deleted.

20 changes: 0 additions & 20 deletions src/ai/.x/help/flow.package

This file was deleted.

21 changes: 0 additions & 21 deletions src/ai/.x/help/flow.serve

This file was deleted.

26 changes: 0 additions & 26 deletions src/ai/.x/help/flow.upload

This file was deleted.

9 changes: 4 additions & 5 deletions src/ai/.x/help/help
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

___ ____ ___ _____ __ __ ___ _ ___
/ _ /_ / / _ |/_ _/ / // / __/ / / _ \
/ __ |/ /_/ __ |_/ /_ / _ / _// /__/ ___/
/_/ |_/___/_/ |_/____/ /_//_/___/____/_/
___ _____ __ __ ___ _ ___
/ _ |/_ _/ / // / __/ / / _ \
/ __ |_/ /_ / _ / _// /__/ ___/
/_/ |_/____/ /_//_/___/____/_/


`AI HELP`
Expand Down Expand Up @@ -33,7 +33,6 @@ USAGE: ai <command> [...]
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)
Expand Down
8 changes: 4 additions & 4 deletions src/ai/.x/help/include.ai.ascii.logo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
___ ____ ___ _____
/ _ /_ / / _ |/_ _/
/ __ |/ /_/ __ |_/ /_
/_/ |_/___/_/ |_/____/
___ _____
/ _ |/_ _/
/ __ |_/ /_
/_/ |_/____/
Loading

0 comments on commit 3190c30

Please sign in to comment.