Skip to content

Commit

Permalink
Merge branch 'release/v0.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
u1and0 committed Dec 30, 2024
2 parents a32264e + bf4e304 commit c8f3986
Show file tree
Hide file tree
Showing 12 changed files with 535 additions and 203 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
uses: denoland/setup-deno@v2
# uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 # v1.1.2
with:
deno-version: v1.x
deno-version: v2.x.x

# Uncomment this step to verify the use of 'deno fmt' on each commit.
- name: Verify formatting
Expand All @@ -63,25 +63,35 @@ jobs:
strategy:
matrix:
include:
- name: linux
- name: linux-x64
vm: ubuntu-latest
- name: macosx
target: x86_64-unknown-linux-gnu
- name: linux-arm64
vm: ubuntu-latest
target: aarch64-unknown-linux-gnu
- name: macosx-x64
vm: macos-latest
target: x86_64-apple-darwin
- name: macosx-arm64
vm: macos-latest
- name: windows
target: aarch64-apple-darwin
- name: windows-x64
vm: windows-latest
target: x86_64-pc-windows-msvc


steps:
- name: Setup repo
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
uses: denoland/setup-deno@v2
# uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 # v1.1.2
with:
deno-version: v1.x
deno-version: v2.x.x

- name: Build binary
run: deno compile --allow-net --allow-env --output gpt index.ts
run: deno compile --allow-net --allow-env --target ${{ matrix.target }} --output gpt index.ts

- name: Binary upload (Unix, MacOS)
# Artifact upload only occurs when tag matches
Expand Down
88 changes: 63 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="https://img.shields.io/badge/version-v0.7.0-FF7777.svg"></img>
<img src="https://img.shields.io/badge/version-v0.8.0-FF7777.svg"></img>
<img src="https://img.shields.io/badge/LICENSE-MIT-3388FF.svg"></img>
<img src="https://shield.deno.dev/deno/%5E1.39"></img>
<img src="https://github.com/u1and0/gpt-cli/actions/workflows/deno.yml/badge.svg"></img>
Expand All @@ -10,10 +10,16 @@ Command-line interface that enables interactive chat with LLMs.
# Quick start

```
$ curl -LO https://github.com/u1and0/gpt-cli/releases/download/v0.7.0/gpt-cli-linux.zip
# Install binary
$ curl -LO https://github.com/u1and0/gpt-cli/releases/download/v0.8.0/gpt-cli-linux.zip
$ unzip gpt-cli.zip
$ chmod 755 gpt
$ sudo ln -s ./gpt /usr/bin
# Setup API key
$ export OPENAI_API_KEY='sk-*****'
# Run
$ gpt
Ctrl-D to confirm input, q or exit to end chat
You: hi
Expand Down Expand Up @@ -46,7 +52,7 @@ You have 3 options.
The simplest way.

```
$ curl -LO https://github.com/u1and0/gpt-cli/releases/download/v0.7.0/gpt-cli-linux.zip
$ curl -LO https://github.com/u1and0/gpt-cli/releases/download/v0.8.0/gpt-cli-linux.zip
$ unzip gpt-cli-linux.zip
$ chmod 755 gpt
$ sudo ln -s ./gpt /usr/bin
Expand Down Expand Up @@ -104,14 +110,30 @@ export OPENAI_API_KEY='sk-*****'
export ANTHROPIC_API_KEY='sk-ant-*****'
```

### Goolgle API (for Gemini)
### Google API (for Gemini)

[Get Google API key](https://aistudio.google.com/app/apikey), then set environment argument.

```
export GOOGLE_API_KEY='*****'
```

### Groq API

[Get Groq API key](https://console.groq.com/keys), then set environment argument.

```
export GROQ_API_KEY='*****'
```

### Together AI API

[Get Together AI API key](https://api.together.xyz/settings/api-keys), then set environment argument.

```
export TOGETHER_AI_API_KEY='*****'
```

### Replicate API (for Open Models)

[Get Replicate API token](https://replicate.com/account/api-tokens), then set environment argument.
Expand All @@ -138,7 +160,7 @@ $ gpt -m gpt-4o-mini -x 1000 -t 1.0 [OPTIONS] PROMPT
|--------------|-------------|------|----|
| -v | --version | boolean | Show version |
| -h | --help | boolean | Show this message |
| -m | --model | string | OpenAI, Anthropic, Google, Replicate, Ollama model (default gpt-4o-mini) |
| -m | --model | string | LLM model (default gpt-4o-mini) |
| -x | --max\_tokens | number | Number of AI answer tokens (default 1000) |
| -t | --temperature | number | Higher number means more creative answers, lower number means more exact answers (default 1.0) |
| -u | --url | string | URL and port number for ollama server |
Expand All @@ -153,38 +175,54 @@ A Questions for Model
## Models
- [OpenAI](https://platform.openai.com/docs/models)
- gpt-4o-mini
- gpt-4o...
- gpt-4o
- o1
- o1-preview
- o1-mini...
- [Anthropic](https://docs.anthropic.com/claude/docs/models-overview)
- claude-3-opus-20240229
- claude-3-haiku-20240307
- claude-instant-1.2...
- claude-3-5-sonnet-latest
- claude-3-5-haiku-latest
- [Gemini](https://ai.google.dev/gemini-api/docs/models/gemini)
- gemini-1.5-pro-latest
- gemini-pro
- gemini-2.0-flash-exp...
- [Groq](https://console.groq.com/docs/models)
- groq/llama3-groq-70b-8192-tool-use-preview
- groq/llama-3.3-70b-specdec
- groq/llama3.1-70b-specdec
- groq/llama-3.2-1b-preview
- groq/llama-3.2-3b-preview...
- [TogetherAI](https://api.together.ai/models)
- togetherai/meta-llama/Llama-3.3-70B-Instruct-Turbo
- togetherai/Qwen/QwQ-32B-Preview
- togetherai/meta-llama/Llama-3.1-405B-Instruct-Turbo
- togetherai/google/gemma-2-27b-it
- togetherai/mistralai/Mistral-7B-Instruct-v0.3...
- [Replicate](https://replicate.com/models)
- meta/meta-llama-3-70b-instruct
- meta/llama-2-7b-chat
- mistralai/mistral-7b-instruct-v0.2
- mistralai/mixtral-8x7b-instruct-v0.1
- snowflake/snowflake-arctic-instruct
- replicate/flan-t5-xl...
- replicate/meta/meta-llama-3-70b-instruct
- replicate/meta/llama-2-7b-chat
- replicate/mistralai/mistral-7b-instruct-v0.2
- replicate/mistralai/mixtral-8x7b-instruct-v0.1
- replicate/snowflake/snowflake-arctic-instruct
- replicate/replicate/flan-t5-xl...
- [Ollama](https://ollama.com/library) ** Using before "$ ollama serve" locally **
- phi3
- llama3:70b
- mixtral:8x7b-text-v0.1-q5\_K\_M...
- ollama/phi3
- ollama/llama3:70b
- ollama/mixtral:8x7b-text-v0.1-q5\_K\_M...

## / command
Help (/commands):

- /?, /help Help for a command
- /clear Clear session context
- /bye Exit
- /?, /help Help for a command
- /clear Clear session context
- /modelStack Show model's history
- /bye,/exit,/quit Exit

## @ command
Help (@commands): Change model while asking.

- @{ModelName} Change LLM model
- ex) @gemini-1.5-pro any prompt...
- @ModelName Change LLM model
- ex) @gemini-1.5-pro your question...

## Test

Expand Down Expand Up @@ -215,12 +253,12 @@ hook_add = '''
" Create test code
command! -nargs=0 -range GPTGenerateTest <line1>,<line2>call gptcli#GPT('You are the best code tester. Please write test code that covers all cases to try the given code.', { "temperature": 0.5, "model": "claude-3-haiku-20240307" })
command! -nargs=0 -range GPTErrorBustor <line1>,<line2>call gptcli#GPT('Your task is to analyze the provided code snippet, identify any bugs or errors present, and provide a corrected version of the code that resolves these issues. Explain the problems you found in the original code and how your fixes address them. The corrected code should be functional, efficient, and adhere to best practices in programming.', {"temperature": 0.5, "model": "claude-3-sonnet-20240229"})
command! -nargs=0 -range GPTCodeOptimizer <line1>,<line2>call gptcli#GPT("Your task is to analyze the provided code snippet and suggest improvements to optimize its performance. Identify areas where the code can be made more efficient, faster, or less resource-intensive. Provide specific suggestions for optimization, along with explanations of how these changes can enhance the code performance. The optimized code should maintain the same functionality as the original code while demonstrating improved efficiency.", { "model": "meta/meta-llama-3-70b-instruct" })
command! -nargs=0 -range GPTCodeOptimizer <line1>,<line2>call gptcli#GPT("Your task is to analyze the provided code snippet and suggest improvements to optimize its performance. Identify areas where the code can be made more efficient, faster, or less resource-intensive. Provide specific suggestions for optimization, along with explanations of how these changes can enhance the code performance. The optimized code should maintain the same functionality as the original code while demonstrating improved efficiency.", { "model": "replicate/meta/meta-llama-3-70b-instruct" })
" Any system prompt
command! -nargs=? -range GPTComplete <line1>,<line2>call gptcli#GPT(<q-args>, { "model": "claude-3-haiku-20240307" })
" Chat with GPT
command! -nargs=? GPTChat call gptcli#GPTWindow(<q-args>, { "model": "phi3:instruct", "url": "http://localhost:11434"})
command! -nargs=? GPTChat call gptcli#GPTWindow(<q-args>, { "model": "ollama/phi3:instruct", "url": "http://localhost:11434"})
```
![Peek 2024-04-01 03-35.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/113494/f243f19b-ee47-9821-5899-7ed2acc17320.gif)
Expand Down
7 changes: 6 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
},
"test": {
"exclude": ["node_modules/"]
}
},
"dependencies": {
"@langchain/groq": "^0.1.2"
},
"nodeModulesDir": "auto"
}

79 changes: 44 additions & 35 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,21 @@ import { commandMessage, helpMessage } from "./lib/help.ts";
import { LLM, Message } from "./lib/llm.ts";
import { getUserInputInMessage, readStdin } from "./lib/input.ts";
import { Params, parseArgs } from "./lib/params.ts";
import { Command, extractAtModel, isCommand } from "./lib/command.ts";

const VERSION = "v0.7.0";
import {
Command,
extractAtModel,
handleSlashCommand,
isAtCommand,
isSlashCommand,
modelStack,
} from "./lib/command.ts";

const VERSION = "v0.8.0";

/** 灰色のテキストで表示 */
function consoleInfoWithGrayText(s: string): void {
console.info(`\x1b[90m${s}\x1b[0m`);
}

const llmAsk = async (params: Params) => {
params.debug && console.debug(params);
Expand All @@ -48,51 +60,46 @@ const llmAsk = async (params: Params) => {
}

// 対話的回答
consoleInfoWithGrayText(commandMessage);
while (true) {
// ユーザーからの入力待ち
let humanMessage = await getUserInputInMessage(messages);

/** /commandを実行する
* Help: ヘルプメッセージを出力する
* Clear: systemp promptを残してコンテキストを削除する
* Bye: コマンドを終了する
*/
if (isCommand(humanMessage)) {
switch (humanMessage) {
case Command.Help: {
console.log(commandMessage);
continue; // Slashコマンドを処理したら次のループへ
}
case Command.Clear: {
// system promptが設定されていれば、それを残してコンテキストクリア
console.log("Context clear successful");
messages = params.systemPrompt
? [new SystemMessage(params.systemPrompt)]
: [];
continue; // Slashコマンドを処理したら次のループへ
}
case Command.Bye: {
Deno.exit(0);
}
}
} else if (humanMessage?.content.toString().startsWith("@")) {
let humanMessage: HumanMessage | Command = await getUserInputInMessage(
messages,
);

// /commandを実行する
if (isSlashCommand(humanMessage)) {
messages = handleSlashCommand(humanMessage, messages);
continue;
} else if (isAtCommand(humanMessage)) {
// @Model名で始まるinput はllmモデルを再指定する
const { model, message } = extractAtModel(
humanMessage.content.toString(),
);
// モデル名指定以外のプロンプトがなければ前のプロンプトを引き継ぐ。
humanMessage = message ? message : messages.at(-2);
// 前のプロンプトもなければ空のHumanMessageを渡す
humanMessage = message || messages.at(-2) || new HumanMessage("");

// @コマンドで指定したモデルのパースに成功したら
// モデルスタックに追加して新しいモデルで会話を始める。
// パースに失敗したら、以前のモデルを復元してエラー表示して
// 前のモデルに戻して会話を継続。
if (model) {
const modelBackup = params.model;
params.model = model;
llm = new LLM(params);
try {
llm = new LLM(params);
} catch (error: unknown) {
console.error(error);
params.model = modelBackup;
continue;
}
modelStack.push(model);
}
}

// 最後のメッセージがHumanMessageではない場合
// ユーザーからの問いを追加
if (humanMessage) {
messages.push(humanMessage);
}
messages.push(humanMessage);
// console.debug(messages);
// AIからの回答を追加
const aiMessage = await llm.ask(messages);
Expand All @@ -119,6 +126,8 @@ const main = async () => {
Deno.exit(0);
}

// modelStackに使用した最初のモデルを追加
modelStack.push(params.model);
// 標準入力をチェック
const stdinContent: string | null = await readStdin();
if (stdinContent) {
Expand Down
Loading

0 comments on commit c8f3986

Please sign in to comment.