mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-24 03:24:21 +01:00
dave: reorganize ModelConfig
start to clean up the lib.rs a bit Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -444,7 +444,7 @@ fn add_deck_button() -> impl Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wallet_button() -> impl Widget {
|
fn _wallet_button() -> impl Widget {
|
||||||
|ui: &mut egui::Ui| -> egui::Response {
|
|ui: &mut egui::Ui| -> egui::Response {
|
||||||
let img_size = 24.0;
|
let img_size = 24.0;
|
||||||
|
|
||||||
|
|||||||
45
crates/notedeck_dave/src/config.rs
Normal file
45
crates/notedeck_dave/src/config.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
use async_openai::config::OpenAIConfig;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ModelConfig {
|
||||||
|
endpoint: Option<String>,
|
||||||
|
model: String,
|
||||||
|
api_key: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ModelConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
ModelConfig {
|
||||||
|
endpoint: None,
|
||||||
|
model: "gpt-4o".to_string(),
|
||||||
|
api_key: std::env::var("OPENAI_API_KEY").ok(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ModelConfig {
|
||||||
|
pub fn model(&self) -> &str {
|
||||||
|
&self.model
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ollama() -> Self {
|
||||||
|
ModelConfig {
|
||||||
|
endpoint: std::env::var("OLLAMA_HOST").ok().map(|h| h + "/v1"),
|
||||||
|
model: "hhao/qwen2.5-coder-tools:latest".to_string(),
|
||||||
|
api_key: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_api(&self) -> OpenAIConfig {
|
||||||
|
let mut cfg = OpenAIConfig::new();
|
||||||
|
if let Some(endpoint) = &self.endpoint {
|
||||||
|
cfg = cfg.with_api_base(endpoint.to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(api_key) = &self.api_key {
|
||||||
|
cfg = cfg.with_api_key(api_key.to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ use async_openai::{
|
|||||||
Client,
|
Client,
|
||||||
};
|
};
|
||||||
use chrono::{DateTime, Duration, Local};
|
use chrono::{DateTime, Duration, Local};
|
||||||
|
use egui_wgpu::RenderState;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use nostrdb::{Ndb, NoteKey, Transaction};
|
use nostrdb::{Ndb, NoteKey, Transaction};
|
||||||
use notedeck::AppContext;
|
use notedeck::AppContext;
|
||||||
@@ -23,12 +24,12 @@ use std::sync::mpsc::{self, Receiver};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub use avatar::DaveAvatar;
|
pub use avatar::DaveAvatar;
|
||||||
use egui_wgpu::RenderState;
|
pub use config::ModelConfig;
|
||||||
|
|
||||||
pub use quaternion::Quaternion;
|
pub use quaternion::Quaternion;
|
||||||
pub use vec3::Vec3;
|
pub use vec3::Vec3;
|
||||||
|
|
||||||
mod avatar;
|
mod avatar;
|
||||||
|
mod config;
|
||||||
mod quaternion;
|
mod quaternion;
|
||||||
mod vec3;
|
mod vec3;
|
||||||
|
|
||||||
@@ -336,46 +337,6 @@ pub struct Dave {
|
|||||||
model_config: ModelConfig,
|
model_config: ModelConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ModelConfig {
|
|
||||||
endpoint: Option<String>,
|
|
||||||
model: String,
|
|
||||||
api_key: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ModelConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
ModelConfig {
|
|
||||||
endpoint: None,
|
|
||||||
model: "gpt-4o".to_string(),
|
|
||||||
api_key: std::env::var("OPENAI_API_KEY").ok(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ModelConfig {
|
|
||||||
pub fn ollama() -> Self {
|
|
||||||
ModelConfig {
|
|
||||||
endpoint: std::env::var("OLLAMA_HOST").ok().map(|h| h + "/v1"),
|
|
||||||
model: "hhao/qwen2.5-coder-tools:latest".to_string(),
|
|
||||||
api_key: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_api(&self) -> OpenAIConfig {
|
|
||||||
let mut cfg = OpenAIConfig::new();
|
|
||||||
if let Some(endpoint) = &self.endpoint {
|
|
||||||
cfg = cfg.with_api_base(endpoint.to_owned());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(api_key) = &self.api_key {
|
|
||||||
cfg = cfg.with_api_key(api_key.to_owned());
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Dave {
|
impl Dave {
|
||||||
pub fn avatar_mut(&mut self) -> Option<&mut DaveAvatar> {
|
pub fn avatar_mut(&mut self) -> Option<&mut DaveAvatar> {
|
||||||
self.avatar.as_mut()
|
self.avatar.as_mut()
|
||||||
@@ -608,7 +569,7 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
|
|||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
let client = self.client.clone();
|
let client = self.client.clone();
|
||||||
let tools = self.tools.clone();
|
let tools = self.tools.clone();
|
||||||
let model_name = self.model_config.model.clone();
|
let model_name = self.model_config.model().to_owned();
|
||||||
|
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
self.incoming_tokens = Some(rx);
|
self.incoming_tokens = Some(rx);
|
||||||
|
|||||||
Reference in New Issue
Block a user