Skip to content

Commit

Permalink
update 0.7.0 for model settings
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhe4096 committed Nov 25, 2024
1 parent 3a34dd0 commit a8468db
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ The translate, llama model, and other services can be started separately. Please

# Updates

## 0.7.0

- Add "temperature slider" for AI model
- Add "system role" prompt for AI model

## 0.6.8

- Add try-catch for importing JSON config
Expand Down
28 changes: 24 additions & 4 deletions web/src/DataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useToast } from "primevue/usetoast";

export const useDataStore = defineStore('jarvis', {
state: () => ({
version: '0.6.8',
version: '0.7.0',
config: {
api_server_url: "http://localhost:8123",
api_server_token: "",
Expand Down Expand Up @@ -34,7 +34,9 @@ state: () => ({
"model_name": "gpt-4o",
"endpoint": "https://api.openai.com/v1/chat/completions",
"enabled": true,
"api_key": ""
"api_key": "",
"temperature": 0,
"system_prompt": "You are a helpful assistant.",
},
claude: {
"id": "claude",
Expand All @@ -43,7 +45,9 @@ state: () => ({
"model_name": "claude-3-5-haiku-20241022",
"endpoint": "https://api.anthropic.com/v1/messages",
"enabled": true,
"api_key": ""
"api_key": "",
"temperature": 0,
"system_prompt": "You are a helpful assistant.",
},
// llama: {
// "id": "llama",
Expand Down Expand Up @@ -433,7 +437,23 @@ actions: {
// copy the items from json to store.config
for (let key in this.config) {
if (json.hasOwnProperty(key)) {
this.config[key] = json[key];
// special rule for ai models
if (key == 'ai_models') {
// for this case, search all settings from the json
for (let model_id in json[key]) {
if (this.config[key].hasOwnProperty(model_id)) {
for (let model_attribute in json[key][model_id]) {
this.config[key][model_id][model_attribute] = json[key][model_id][model_attribute];
}
} else {
// just copy the whole content if not found
// which means the localStorage has custmoized settings
this.config[key][model_id] = json[key][model_id];
}
}
} else {
this.config[key] = json[key];
}
}
}
},
Expand Down
2 changes: 0 additions & 2 deletions web/src/components/AIHelper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ async function onClickReview(model_id) {
// set flag
status.value[model_id] = 'reviewing';
console.log(`* AI Helper [${model_id}] is thinking ...`);
// first generate the prompot
let question = ai_helper.generateQuestionFromTemplate(
store.llm_prompt_template,
Expand Down
18 changes: 18 additions & 0 deletions web/src/components/SettingPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,24 @@ const toggle = (event) => {
<InputText v-model="model.api_key"
class="w-full"/>
</div>

<div class="label">
Temperature (0-1)
</div>
<div class="mb-2">
<InputNumber v-model.number="model.temperature"
:min="0" :max="1"
:minFractionDigits="2"
class="w-full"/>
</div>

<div class="label">
System Prompt
</div>
<div class="mb-2">
<InputText v-model="model.system_prompt"
class="w-full"/>
</div>
</div>
</template>

Expand Down
14 changes: 13 additions & 1 deletion web/src/utils/ai_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const ai_helper = {
},

_ask_openai: async function(question, config) {
console.log(`* asking openai ...`);
// e.g., "endpoint": "https://api.openai.com/v1/chat/completions",
let endpoint = config.endpoint;

Expand All @@ -95,13 +96,14 @@ export const ai_helper = {
body: JSON.stringify({
"model": model_name,
"format": "json",
"temperature": config.temperature,
"response_format": {
"type": "json_object",
},
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
"content": config.system_prompt
},
{
"role": "user",
Expand Down Expand Up @@ -131,9 +133,11 @@ export const ai_helper = {
},

_ask_gemini: async function(question, config) {
console.log(`* asking gemini ...`);
},

_ask_claude: async function(question, config) {
console.log(`* asking claude ...`);
let endpoint = config.endpoint;

// e.g., "model_name": "gpt-4o-mini",
Expand All @@ -153,6 +157,7 @@ export const ai_helper = {
body: JSON.stringify({
model: model_name,
max_tokens: 4096,
temperature: config.temperature,
messages: [
{
role: "user",
Expand All @@ -163,6 +168,13 @@ export const ai_helper = {
},
],
},
{
role: "assistant",
content: [{
type: "text",
text: config.system_prompt
}]
},
// {
// "role": "assistant",
// "content": [{
Expand Down

0 comments on commit a8468db

Please sign in to comment.