├── .gitignore ├── Readme.md ├── docs └── img │ ├── example.gif │ ├── logo.png │ └── wechat.jpg ├── install.ps1 └── install.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/go 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=go 3 | 4 | ### Go ### 5 | # If you prefer the allow list template instead of the deny list, see community template: 6 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore 7 | # 8 | # Binaries for programs and plugins 9 | *.exe 10 | *.exe~ 11 | *.dll 12 | *.so 13 | *.dylib 14 | 15 | # Test binary, built with `go test -c` 16 | *.test 17 | 18 | # Output of the go coverage tool, specifically when used with LiteIDE 19 | *.out 20 | 21 | # Dependency directories (remove the comment below to include it) 22 | # vendor/ 23 | 24 | # Go workspace file 25 | go.work 26 | 27 | # idea 28 | .idea* 29 | 30 | # 31 | aispark* 32 | 33 | 34 | # End of https://www.toptal.com/developers/gitignore/api/go 35 | 36 | # config 37 | *config.yaml -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 | 5 | 讯飞星火智能终端 (spark-ai-cli) 6 |

7 | 8 | ## 项目地址 9 | 10 | * Github: [https://github.com/iflytek/spark-ai-cli](https://github.com/iflytek/spark-ai-cli) 11 | 欢迎点赞,star 12 | 13 | ## 前言 14 | 15 | 感谢开源的力量,希望讯飞开源越做越好,星火大模型效果越来越好! 16 | 17 | ## 示例 18 | ![示例](./docs/img/example.gif) 19 | 20 | ## 近期规划新特性 21 | 22 | - [x] config模块接入 23 | - [x] 执行结果优化 24 | - [x] 获取终端环境,进行个性化 25 | - [ ] agents 26 | - [ ] plugins 27 | - [ ] 知识库 28 | 29 | ## 快速开始 30 | 31 | **安装** 32 | 33 | **linux和Mac shell脚本** 34 | 35 | ```shell 36 | sudo bash -c "$(curl -s -L https://521github.com/iflytek/spark-ai-cli/releases/download/latest/install.sh)" 37 | ``` 38 | 39 | **Mac brew安装** 40 | 41 | Mac已支持brew安装,如果您之前通过bash脚本安装过aispark,请先删除 42 | ```shell 43 | rm -rf /usr/local/bin/aispark 44 | ``` 45 | brew安装命令: 46 | ```shell 47 | brew tap iflytek/aispark 48 | brew install aispark 49 | ``` 50 | 51 | **windows** 52 | 53 | 使用Windows PowerShell管理员权限执行如下脚本 54 | 55 | ```shell 56 | Invoke-Expression (Invoke-RestMethod 'https://521github.com/iflytek/spark-ai-cli/releases/download/latest/install.ps1') 57 | ``` 58 | 59 | * 升级最新stable版本: 60 | 61 | ```aispark update``` 62 | 63 | 升级需要管理员权限,powershell请使用**管理员身份**运行,linux和mac平台请使用**sudo**执行 64 | 65 | * 查看当前版本: 66 | 67 | `aispark version` 68 | 69 | ```bash 70 | aispark cli version: v0.0.20 71 | Git Commit Hash: 69ad2242e775d58299c62bd57477ccd2eab43ae6 72 | Build TimeStamp: Wed, 24 Apr 2024 11:39:26 +0000 73 | GoLang Version: 1.21 74 | 75 | _ ___ ____ ____ _ ____ _ __ 76 | / \ |_ _|/ ___| | _ \ / \ | _ \ | |/ / 77 | / _ \ | | \___ \ | |_) |/ _ \ | |_) || ' / 78 | / ___ \ | | ___) || __// ___ \ | _ < | . \ 79 | /_/ \_\|___||____/ |_| /_/ \_\|_| \_\|_|\_\ 80 | 81 | 82 | 讯飞云提供计算服务 83 | https://xinghuo.xfyun.cn/sparkapi 84 | ``` 85 | ## 账号 86 | ### 账号申请 87 | 前往[讯飞开放平台](https://passport.xfyun.cn/register?ch=xfy-sparkcli)**免费注册**账号 88 | 89 | ### 账号登录 90 | 注册账号后,记住账户和密码,通过以下命令登录,登陆成功后即可使用 91 | ```shell 92 | aispark login 93 | ``` 94 | 95 | ### 退出登录 96 | ```shell 97 | aispark logout 98 | ``` 99 | 100 | ## 如何使用 101 | 102 | ### shell相关的问题 103 | ```shell 104 | aispark q nginx重启 105 | aispark q awk截取{{xxx}}中xxx的字符 106 | ``` 107 | 108 | ### 知识问答问题 109 | ```shell 110 | aispark c 今天天气怎么样 111 | ``` 112 | 113 | ### wow模式 114 | 支持平台: 115 | 116 | - [x] windows powershell 117 | - [x] macos bash 118 | - [x] linux bash 119 | 120 | 121 | 122 | #### 使用方式 123 | ```shell 124 | aispark wow 125 | aispark wow aptget 126 | ``` 127 | 128 | #### 配置 129 | 130 | **Windows** 131 | 132 | 在windows下配置 Powershell $PROFILE,加入以下内容: 133 | ```powershell 134 | iex "$(aispark wow --alias)" 135 | ``` 136 | 137 | 这个文件是一个脚本文件,当 PowerShell 启动时自动执行里面的内容。如果你想知道你的 $PROFILE 文件的具体位置,可以在 PowerShell 窗口中运行以下命令: 138 | 139 | ```powershell 140 | echo $PROFILE 141 | ``` 142 | 143 | 您的目录下可能没有这个文件,若没有该文件,新建此文件并配置上述命令即可 144 | 145 | **Linux** 146 | 147 | 将以下命令放在 .bash_profile,.bashrc,.zshrc 或其他启动脚本中: 148 | 149 | ```shell 150 | eval $(aispark wow --alias) 151 | ``` 152 | 例如: 153 | ```shell 154 | echo 'eval "$(aispark wow --alias)"' >> ~/.bashrc 155 | ``` 156 | 157 | 更改仅在新的 shell 会话中可用。若想立即生效,请运行 source ~/.bashrc (或 shell 配置文件,如 .zshrc )。 158 | 159 | 160 | 161 | 162 | ### mode切换 163 | ```shell 164 | aispark -l q nginx重启 #可交互模式 165 | aispark -v q nginx重启 #啰嗦模式,解释脚本内容 166 | ``` 167 | 168 | ### 配置 169 | 170 | aispark现已开箱即用,登录讯飞开放平台账户即可使用; 171 | 172 | 若您是开发者,登录[讯飞开放平台](https://www.xfyun.cn/?ch=xfy-sparkcli)免费注册开发者账户,进行如下配置,独享个人账户,高效稳定 173 | 174 | ```shell 175 | aispark config # 交互式设置 176 | # 177 | aispark config key xxxx 178 | aispark config secret xxxx 179 | aispark config appid xxxx 180 | ``` 181 | 182 | ## 欢迎贡献 183 | 184 | 扫码加入交流群 185 | 186 | ![用户交流群](./docs/img/wechat.jpg) 187 | 188 | ## 已知问题 189 | 190 | * 项目目前处于开发阶段,部分思想借鉴开源实现 191 | 192 | 193 | ## 🌟 Star History 194 | 195 | [![Star History Chart](https://api.star-history.com/svg?repos=iflytek/spark-ai-cli&type=Date)](https://star-history.com/#iflytek/spark-ai-cli&Date) 196 | 197 | -------------------------------------------------------------------------------- /docs/img/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iflytek/spark-ai-cli/95d198e43fd19e1971c9fb9e9cca39e2f7c6ebb8/docs/img/example.gif -------------------------------------------------------------------------------- /docs/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iflytek/spark-ai-cli/95d198e43fd19e1971c9fb9e9cca39e2f7c6ebb8/docs/img/logo.png -------------------------------------------------------------------------------- /docs/img/wechat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iflytek/spark-ai-cli/95d198e43fd19e1971c9fb9e9cca39e2f7c6ebb8/docs/img/wechat.jpg -------------------------------------------------------------------------------- /install.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | [string]$repoowner = "iflytek", 3 | [string]$reponame = "spark-ai-cli", 4 | [string]$toolname = "aispark", 5 | [string]$toolsymlink = "aispark", 6 | [string]$region = "cn", 7 | [switch]$help 8 | ) 9 | 10 | # Check if running as Administrator and restart with elevated permissions if not 11 | function Test-Admin { 12 | $user = [Security.Principal.WindowsIdentity]::GetCurrent() 13 | $principal = New-Object Security.Principal.WindowsPrincipal($user) 14 | return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) 15 | } 16 | 17 | if (-not (Test-Admin)) { 18 | # uac在云端执行下不适用 19 | <# Write-Host "Restarting script with administrator privileges..." 20 | $script = $MyInvocation.MyCommand.Definition 21 | $scriptPath = Split-Path -Parent $script 22 | Start-Process PowerShell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$script`"" -Verb RunAs -WorkingDirectory $scriptPath#> 23 | Write-Host "Please run as administrator" -ForegroundColor Red 24 | Write-Host "Please run as administrator" -ForegroundColor Red 25 | Write-Host "Please run as administrator" -ForegroundColor Red 26 | exit 1 27 | } 28 | 29 | if ($help) { 30 | Write-Host "aispark Installer Help!" 31 | Write-Host " Usage: " 32 | Write-Host " aispark -help " 33 | Write-Host " aispark -repoowner " 34 | Write-Host " aispark -reponame " 35 | Write-Host " aispark -toolname " 36 | Write-Host " aispark -toolsymlink " 37 | 38 | exit 0 39 | } 40 | 41 | # Define the temporary directory for all intermediate files 42 | $tempDir = Join-Path $env:TEMP "aispark" 43 | New-Item -ItemType Directory -Path $tempDir -Force | Out-Null 44 | 45 | 46 | function Expand-GZipFile { 47 | param( 48 | [string]$inputPath, # Input .gz file path 49 | [string]$outputPath # Output file path after decompression 50 | ) 51 | 52 | # Build the complete input and output paths 53 | $fullInputPath = Join-Path $tempDir $inputPath 54 | $fullOutputPath = Join-Path $tempDir $outputPath 55 | 56 | # Ensure the output directory exists, create it if it doesn't 57 | $outputDir = Split-Path -Path $fullOutputPath -Parent 58 | if (-Not (Test-Path -Path $outputDir)) { 59 | New-Item -ItemType Directory -Path $outputDir -Force | Out-Null 60 | Write-Host "Output directory created: $outputDir" 61 | } 62 | 63 | try { 64 | # Open the .gz file stream 65 | if (-Not (Test-Path $fullInputPath)) { 66 | Write-Error "Input file does not exist: $fullInputPath" 67 | return 68 | } 69 | 70 | $inputStream = [System.IO.File]::OpenRead($fullInputPath) 71 | $outputStream = [System.IO.File]::Create($fullOutputPath) 72 | $gzipStream = New-Object System.IO.Compression.GZipStream($inputStream, [System.IO.Compression.CompressionMode]::Decompress) 73 | 74 | # Copy the compressed data to the output file 75 | $gzipStream.CopyTo($outputStream) 76 | 77 | # Close all streams 78 | $gzipStream.Dispose() 79 | $outputStream.Dispose() 80 | $inputStream.Dispose() 81 | 82 | Write-Output "File has been decompressed to '$outputPath'." 83 | } 84 | catch { 85 | Write-Error "An error occurred: $_" 86 | } 87 | } 88 | 89 | # Detect the platform (architecture and OS) 90 | $ARCH = $null 91 | $OS = "windows" 92 | 93 | 94 | if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") { 95 | $ARCH = "amd64" 96 | } elseif ($env:PROCESSOR_ARCHITECTURE -eq "arm64") { 97 | $ARCH = "arm64" 98 | } else { 99 | $ARCH = "i386" 100 | } 101 | 102 | if ($env:OS -notmatch "Windows") { 103 | Write-Host "You are running the powershell script on a non-windows platform. Please use the install.sh script instead." 104 | } 105 | 106 | if ($env:OS -notmatch "Windows") { 107 | Write-Host "You are running the powershell script on a non-windows platform. Please use the install.sh script instead." 108 | } 109 | 110 | # Fetch the latest release tag from GitHub API 111 | $API_URL = "https://api.github.com/repos/$repoowner/$reponame/releases/latest" 112 | $LATEST_TAG = (Invoke-RestMethod -Uri $API_URL).tag_name 113 | 114 | # Set the download URL based on the platform and latest release tag 115 | if ($region -eq "cn"){ 116 | $DOWNLOAD_URL = "https://repo.model.xfyun.cn/api/packages/aispark/generic/aispark/$LATEST_TAG/${toolname}-${OS}-${ARCH}.exe.gz" 117 | }else{ 118 | $DOWNLOAD_URL = "https://github.com/$repoowner/$reponame/releases/download/$LATEST_TAG/${toolname}-${OS}-${ARCH}.exe.gz" 119 | } 120 | 121 | Write-Host $DOWNLOAD_URL 122 | 123 | 124 | # Download the file 125 | $downloadedFilePath = Join-Path $tempDir "${toolname}.exe.gz" 126 | Invoke-WebRequest -Uri $DOWNLOAD_URL -OutFile $downloadedFilePath 127 | 128 | # Extract the GZip file 129 | $extractedFilePath = "${toolname}.exe" 130 | Expand-GZipFile -inputPath "${toolname}.exe.gz" -outputPath $extractedFilePath 131 | 132 | # check if the file already exists 133 | $toolDir = "C:\Program Files\aispark" 134 | $toolPath = ${toolDir}+"\${toolsymlink}.exe" 135 | if (Test-Path $toolDir) { 136 | if (Test-Path $toolPath){ 137 | Write-Host "delete old file" 138 | Remove-Item $toolPath 139 | } 140 | } else { 141 | New-Item -ItemType Directory -Path "C:\Program Files\aispark\" 142 | } 143 | 144 | # Add the file to path 145 | $currentPath = [System.Environment]::GetEnvironmentVariable("PATH", "User") 146 | 147 | # Append the desired path to the current PATH value if it's not already present 148 | if (-not ($currentPath -split ";" | Select-String -SimpleMatch "C:\Program Files\aispark\")) { 149 | $updatedPath = $currentPath + ";" + "C:\Program Files\aispark\" 150 | 151 | # Set the updated PATH value 152 | [System.Environment]::SetEnvironmentVariable("PATH", $updatedPath, "User") # Use "User" instead of "Machine" for user-level PATH 153 | 154 | Write-Host "The path has been added to the PATH variable. You may need to restart applications to see the changes." -ForegroundColor Red 155 | } 156 | 157 | # Make the binary executable 158 | Move-Item "${tempDir}/${toolname}.exe" $toolPath 159 | 160 | # Clean up 161 | Remove-Item -Recurse -Force "${tempDir}" 162 | 163 | # Print success message 164 | Write-Host "The $toolname has been installed successfully (version: $LATEST_TAG)." -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | releases=$(curl -s https://api.github.com/repos/iflytek/spark-ai-cli/releases/latest) 4 | 5 | 6 | if which "sed" >/dev/null 2>&1; 7 | then 8 | tag_name=`echo "$releases" | grep '"tag_name": ' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/' ` 9 | elif which "cut">/dev/null 2>&1; 10 | then 11 | tag_name=`echo "$releases" | grep '"tag_name": '|cut -d':' -f2 |tr -d '",'` 12 | else 13 | tag_nam="development" 14 | fi 15 | 16 | ARCH=$(uname -m) 17 | architecture="" 18 | case $ARCH in 19 | i386) architecture="386" ;; 20 | i686) architecture="386" ;; 21 | x86_64) architecture="amd64" ;; 22 | arm64) architecture="arm64" ;; 23 | esac 24 | 25 | PLATFORM=$(uname -s | awk '{print tolower($0)}') 26 | BIN=aispark-$PLATFORM-$architecture 27 | 28 | echo "###### Start Downloading and Installing aispark cli tool ########" 29 | echo "Find latest release version: ${tag_name}" 30 | echo "Downloading >>>>" 31 | 32 | TAG=$tag_name 33 | URL=https://repo.model.xfyun.cn/api/packages/aispark/generic/aispark/$TAG/$BIN 34 | echo "Installing >>>>>>>> $URL" 35 | mkdir -p /usr/local/bin/ 36 | 37 | SUFFIX="" 38 | if which "gunzip" >/dev/null 2>&1; 39 | then 40 | if which "wget" >/dev/null 2>&1; 41 | then 42 | echo "using wget download..." 43 | wget --no-check-certificate --quiet $URL.gz -O - |gunzip > /usr/local/bin/aispark 44 | elif which "curl">/dev/null 2>&1; 45 | then 46 | echo "using curl download..." 47 | curl -s -k --location $URL.gz |gunzip > /usr/local/bin/aispark 48 | fi 49 | 50 | else 51 | if which "wget" >/dev/null 2>&1; 52 | then 53 | wget --no-check-certificate --quiet $URL -O /usr/local/bin/aispark 54 | elif which "curl">/dev/null 2>&1; 55 | then 56 | curl -k --location --output /usr/local/bin/aispark $URL 57 | fi 58 | 59 | fi 60 | 61 | chmod +x /usr/local/bin/aispark 62 | echo "<<<<<<<>>>" 65 | echo "Please enter aispark to start !!" --------------------------------------------------------------------------------