Skip to content

Commit

Permalink
chore: address clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
covercash2 committed Nov 21, 2024
1 parent 7e69d12 commit d11e100
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
- name: typos-action
uses: crate-ci/[email protected]
- uses: actions/checkout@v4
- name: lint
run: cargo clippy
- name: Build
run: cargo build --verbose
- name: Run tests
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ a Rust playground
for running language models
and some other machine learning models.

## `ollama-cli`

a CLI/TUI for interacting with an [Ollama] server.

## `djinn-cli`
the main entrypoint
for running either
Expand Down
7 changes: 7 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tui:
cargo run --bin ollama-cli -- tui

check:
typos
cargo clippy
cargo test --all
2 changes: 1 addition & 1 deletion ollama-cli/src/tui/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub impl<'a> Frame<'a> {
"e".bold(),
" to start editing.".bold(),
],
Style::default().add_modifier(Modifier::RAPID_BLINK),
style.add_modifier(Modifier::RAPID_BLINK),
),
InputMode::Edit => (
vec![
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
use crossterm::event::{Event, KeyCode, KeyEvent};

#[derive(Debug, Clone, PartialEq)]
pub struct ActionDefinition {
action: Action,
key: KeyEvent,
description: String,
}

#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum Action {
Left,
Expand Down Expand Up @@ -40,6 +47,8 @@ impl From<KeyEvent> for Action {
KeyCode::Char('h') => Action::Left,
KeyCode::Char('l') => Action::Right,
KeyCode::Char('r') => Action::Refresh,
KeyCode::Char('w') => Action::RightWord,
KeyCode::Char('b') => Action::LeftWord,
KeyCode::Enter => Action::Enter,
_ => Action::Unhandled,
}
Expand Down
4 changes: 0 additions & 4 deletions ollama-cli/src/tui/messages/state.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use ratatui::widgets::ListState;

use super::view::MessageContent;

#[derive(Debug, Clone, Default)]
pub struct MessagesState {
cursor: usize,
message_view: Vec<MessageContent>,
pub list_state: ListState,
}

Expand Down
5 changes: 3 additions & 2 deletions ollama-cli/src/tui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io::stdout, process::Command, time::Duration};
use std::{io::stdout, time::Duration};

use chat::ChatViewModel;
use crossterm::ExecutableCommand as _;
Expand Down Expand Up @@ -120,6 +120,7 @@ impl AppContext {
Ok(app_event)
}

// TODO: use this function with [`modelfile`]
fn edit_model_file(
&mut self,
terminal: &mut DefaultTerminal,
Expand All @@ -131,7 +132,7 @@ impl AppContext {
let mut edit_options = edit::Builder::default();
let edit_options = edit_options.suffix(".tmpl");

let edited_modelfile = edit::edit_with_builder(model_info.modelfile, edit_options)?;
let _edited_modelfile = edit::edit_with_builder(model_info.modelfile, edit_options)?;

stdout().execute(crossterm::terminal::EnterAlternateScreen)?;
crossterm::terminal::enable_raw_mode()?;
Expand Down
1 change: 0 additions & 1 deletion ollama-cli/src/tui/model_context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use futures::StreamExt;
use ollama_rs::models::{LocalModel, ModelInfo};
use tokio::{
sync::mpsc::{Receiver, Sender},
task::JoinHandle,
Expand Down
5 changes: 0 additions & 5 deletions ollama-cli/src/tui/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ impl ModelsViewModel {

if let Some(model_event) = model_event {
match model_event {
ModelEvent::Activate(pane) => {
self.active_pane = Some(pane);
Ok(None)
}
ModelEvent::Deactivate => {
self.active_pane = None;
Ok(None)
Expand Down Expand Up @@ -94,7 +90,6 @@ impl ModelsViewModel {

#[derive(Clone, Debug)]
pub enum ModelEvent {
Activate(Pane),
Deactivate,
EditInfo(ModelInfo),
GetInfo(ModelName),
Expand Down
2 changes: 1 addition & 1 deletion ollama-cli/src/tui/models/model_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ollama_rs::models::LocalModel;
use ratatui::{
layout::{Constraint, Layout, Rect},
style::{Color, Style},
text::{Line, Span},
text::Span,
widgets::{Block, Row, Table, TableState},
Frame,
};
Expand Down
16 changes: 10 additions & 6 deletions ollama-cli/src/tui/models/modelfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use modelfile::Modelfile;
use ratatui::{
layout::{Constraint, Layout, Offset, Rect},
layout::{Constraint, Layout, Rect},
style::{Color, Style},
widgets::{Block, List, ListState, Paragraph, Wrap},
Frame,
Expand All @@ -21,10 +21,7 @@ pub struct ModelfileViewModel {
instructions: Vec<String>,
details: Option<toml::Value>,
list_state: ListState,
/// x, y scroll offset
scroll_offset: Offset,
wrap: bool,
active_panel: Panel,
active_panel: Option<Panel>,
}

impl ModelfileViewModel {
Expand Down Expand Up @@ -61,7 +58,14 @@ impl ModelfileViewModel {
self.update_details()?;
Ok(None)
}
Action::Enter => todo!(),
Action::Enter => {
if let Some(_selected) = self.selected {
self.active_panel = Some(Panel::Details);
Ok(None)
} else {
Ok(None)
}
}
Action::Left => todo!(),
Action::Right => todo!(),
Action::LeftWord => todo!(),
Expand Down

0 comments on commit d11e100

Please sign in to comment.