Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Mar 7, 2024
2 parents 32e8c6c + 2404a61 commit 4f8d3eb
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 60 deletions.
79 changes: 32 additions & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "aichat"
version = "0.14.0"
edition = "2021"
authors = ["sigoden <[email protected]>"]
description = "All in one CLI tool for 10+ AI."
description = "All in one CLI tool for 10+ AI platforms"
license = "MIT OR Apache-2.0"
homepage = "https://github.com/sigoden/aichat"
repository = "https://github.com/sigoden/aichat"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![CI](https://github.com/sigoden/aichat/actions/workflows/ci.yaml/badge.svg)](https://github.com/sigoden/aichat/actions/workflows/ci.yaml)
[![Crates](https://img.shields.io/crates/v/aichat.svg)](https://crates.io/crates/aichat)

All in one CLI tool for 10+ AI, including OpenAI, Gemini, Claude, Mistral, LocalAI, Ollama, VertexAI, Ernie, Qianwen...
All in one CLI tool for 10+ AI platforms, including OpenAI, Gemini, Claude, Mistral, LocalAI, Ollama, VertexAI, Ernie, Qianwen...

Command Mode:

Expand Down Expand Up @@ -142,11 +142,11 @@ aichat -e install nvim # Execute
aichat -c fibonacci in js # Code

aichat -s # REPL + New session
aichat -s sess1 # REPL + New/Reuse test session
aichat -s session1 # REPL + New/Reuse 'session1'

aichat --info # System info
aichat -s sess1 --info # Session info
aichat -r role1 --info # Role info
aichat -s session1 --info # Session info

cat data.toml | aichat -c to json > data.json # Pipe IO

Expand Down
2 changes: 1 addition & 1 deletion config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ clients:

# See https://ai.google.dev/docs
- type: gemini
api_key: AIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# See https://docs.anthropic.com/claude/reference/getting-started-with-the-api
- type: claude
Expand Down
21 changes: 21 additions & 0 deletions scripts/shell-integration/integration.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def _aichat_nushell [] {
let _prev = (commandline)
if ($_prev != "") {
print ''
commandline edit -r (aichat -e $_prev)
}
}

$env.config.keybindings = ($env.config.keybindings | append {
name: aichat_integration
modifier: alt
keycode: char_e
mode: [emacs, vi_insert]
event:[
{
send: executehostcommand,
cmd: "_aichat_nushell"
}
]
}
)
2 changes: 1 addition & 1 deletion src/client/vertexai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl VertexAIClient {
let (token, expires_in) = fetch_access_token(&client, &self.config.adc_file)
.await
.with_context(|| "Failed to fetch access token")?;
let expires_at = Utc::now() + Duration::seconds(expires_in);
let expires_at = Utc::now() + Duration::try_seconds(expires_in).ok_or_else(|| anyhow!("Failed to parse expires_in of access_token"))?;
unsafe { ACCESS_TOKEN = (token, expires_at.timestamp()) };
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ impl State {
]
}

pub fn notin_session() -> Vec<Self> {
pub fn not_in_session() -> Vec<Self> {
let excludes: HashSet<_> = Self::in_session().into_iter().collect();
Self::all()
.into_iter()
Expand Down
17 changes: 12 additions & 5 deletions src/config/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,24 @@ impl Role {
pub fn for_execute() -> Self {
let os = detect_os();
let (shell, _, _) = detect_shell();
let combine = match shell.as_str() {
"nushell" | "powershell" => ";",
_ => "&&",
let (shell, use_semicolon) = match (shell.as_str(), os.as_str()) {
("nushell", "windows") => ("cmd", true),
("nushell", _) => ("bash", true),
("powershell", _) => ("powershell", true),
("pwsh", _) => ("powershell", false),
_ => (shell.as_str(), false),
};
let combine = if use_semicolon {
"\nIf multiple steps required try to combine them together using ';'.\nIf it already combined with '&&' try to replace it with ';'.".to_string()
} else {
"\nIf multiple steps required try to combine them together using &&.".to_string()
};
Self {
name: Self::EXECUTE.into(),
prompt: format!(
r#"Provide only {shell} commands for {os} without any description.
Ensure the output is a valid {shell} command. {combine}
If there is a lack of details, provide most logical solution.
Ensure the output is a valid {shell} command.
If multiple steps required try to combine them together using {combine}.
Provide only plain text without Markdown formatting.
Do not provide markdown formatting such as ```"#
),
Expand Down
2 changes: 1 addition & 1 deletion src/repl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ lazy_static! {
ReplCommand::new(
".session",
"Start a context-aware chat session",
State::notin_session(),
State::not_in_session(),
),
ReplCommand::new(".info session", "Show session info", State::in_session(),),
ReplCommand::new(
Expand Down

0 comments on commit 4f8d3eb

Please sign in to comment.