Skip to content

Commit

Permalink
add claude
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhe4096 committed Nov 15, 2024
1 parent ed3cc77 commit bfc29af
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 93 deletions.
6 changes: 6 additions & 0 deletions web/package-lock.json

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

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@primevue/themes": "^4.2.1",
"dayjs": "^1.11.13",
"papaparse": "^5.4.1",
"pinia": "^2.2.6",
"postcss": "^8.4.47",
Expand Down
6 changes: 4 additions & 2 deletions web/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { ref } from "vue";
import { onMounted, ref } from "vue";
import ItemList from "./components/ItemList.vue";
import ItemDetail from "./components/ItemDetail.vue";
import AIHelper from "./components/AIHelper.vue";
Expand All @@ -12,7 +12,9 @@ import DecisionPanel from "./components/DecisionPanel.vue";
const store = useDataStore();
onMounted(() => {
store.loadSettingsFromLocalStorage();
});
</script>

<template>
Expand Down
73 changes: 62 additions & 11 deletions web/src/DataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ state: () => ({
api_server_url: "http://localhost:8123",
api_server_token: "",

keywords: [
{token: "cancer", bgcolor:"#ECDCAC"},
{token: "data", bgcolor:"#FFA704"},
],

// list of AI models
// each model has an id, name, enabled flag, and api_key
ai_models: {
Expand All @@ -33,6 +38,15 @@ state: () => ({
"enabled": true,
"api_key": ""
},
claude: {
"id": "claude",
"service_type": "claude",
"name": "Claude 3.5 Haiku",
"model_name": "claude-3-5-haiku-20241022",
"endpoint": "https://api.anthropic.com/v1/messages",
"enabled": true,
"api_key": ""
},
llama: {
"id": "llama",
"service_type": "ollama",
Expand All @@ -44,7 +58,6 @@ state: () => ({
},
},

keywords: [],
},
// global variables for all components
/*
Expand Down Expand Up @@ -149,7 +162,7 @@ getters: {
},

keywords_list(state) {
return state.keywords.join("\n");
return state.config.keywords.join("\n");
},

has_working_item_title(state) {
Expand Down Expand Up @@ -305,9 +318,28 @@ actions: {
// highlight keywords in text
// the given keywords are a list of strings
highlight: function(text, keywords) {
let re = new RegExp(keywords.join("|"), "gi");
return text.replace(re, function(matched){
return "<mark>" + matched + "</mark>";
// convert keywords to a dictionary
let kws = [];
let kwd = {};
for (let i in keywords) {
let kw = keywords[i];

// if kw is a string, convert it to an object
if (typeof kw === 'string') {
kws.push(kw);
kwd[kw] = 'yellow';
} else {
// put the token to lowercase
kws.push(kw.token);
kwd[kw.token.toLowerCase()] = kw.bgcolor;
}
}
let re = new RegExp(kws.join("|"), "gi");
return text.replace(re, (matched) => {
let kw = matched.toLowerCase();
let clr = kwd[kw];
return `<mark style="background: ${clr};">${matched}</mark>`;
// return "<mark>" + matched + "</mark>";
});
},

Expand Down Expand Up @@ -358,18 +390,37 @@ actions: {
this.llm_prompt_template = text;
},

updateSettingsByJSON: function(json) {
// copy the items from json to store.config
for (let key in this.config) {
if (json.hasOwnProperty(key)) {
this.config[key] = json[key];
}
}
},

loadSettingsFromLocalStorage: function() {
// get keywords from local storage
try {
let keywords = JSON.parse(localStorage.getItem("keywords"));
this.keywords = keywords;
} catch (e) {
console.log(e);
// just load the object from localstorage
let x = localStorage.getItem('config');

if (x == null) {
store.msg('No settings from local');
return;
}

// parse
let cfg = JSON.parse(x);
console.log('* local storage config:', cfg);

this.updateSettingsByJSON(cfg);

console.log('* loaded settings from local storage');
},

clearSettingsFromLocalStorage: function() {
localStorage.removeItem('config');
},

msg: function(text, type='info') {
this.toast.add({
severity: type,
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/ItemDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function highlightText(text) {
if (store.flag.enable_highlight) {
return store.highlight(
text,
store.keywords,
store.config.keywords,
)
}
return text;
Expand Down
Loading

0 comments on commit bfc29af

Please sign in to comment.