Skip to content

Commit

Permalink
fix_default_model_and_ollam_inst (#397)
Browse files Browse the repository at this point in the history
* fix

* update
  • Loading branch information
swuecho authored Dec 2, 2023
1 parent 8b4ea0b commit e722a64
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion api/chat_main_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ func (h *ChatHandler) chatOllamStram(w http.ResponseWriter, chatSession sqlc_que
// iterate through the messages and format them
// print the user's question
// convert assistant's response to json format
prompt := formatClaudePrompt(chat_compeletion_messages)
prompt := formatMinstralPrompt(chat_compeletion_messages)
// create the json data
jsonData := map[string]interface{}{
"prompt": prompt,
Expand Down
1 change: 0 additions & 1 deletion api/chat_session_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (h *ChatSessionHandler) createChatSessionByUUID(w http.ResponseWriter, r *h
return
}
// set active chat session when creating a new chat session
sessionParams.UserID = int32(userIDInt)
_, err = h.service.q.CreateOrUpdateUserActiveChatSession(r.Context(),
sqlc_queries.CreateOrUpdateUserActiveChatSessionParams{
UserID: session.UserID,
Expand Down
22 changes: 22 additions & 0 deletions api/ollama.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"fmt"
"strings"
)

func formatMinstralPrompt(chat_compeletion_messages []Message) string {
var sb strings.Builder

for _, message := range chat_compeletion_messages {

if message.Role != "assistant" {
sb.WriteString(fmt.Sprintf("<s>[INST] %s[/INST]\n", message.Content))
} else {
sb.WriteString(fmt.Sprintf("%s </s> \n", message.Content))
}
}
prompt := sb.String()
print(prompt)
return prompt
}
8 changes: 4 additions & 4 deletions api/sqlc/queries/chat_session.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ where active = true
ORDER BY id;

-- name: CreateChatSession :one
INSERT INTO chat_session (user_id, topic, max_length, uuid)
VALUES ($1, $2, $3, $4)
INSERT INTO chat_session (user_id, topic, max_length, uuid, model)
VALUES ($1, $2, $3, $4, $5)
RETURNING *;

-- name: UpdateChatSession :one
Expand All @@ -31,8 +31,8 @@ WHERE uuid = $1
order by updated_at;

-- name: CreateChatSessionByUUID :one
INSERT INTO chat_session (user_id, uuid, topic, created_at, active, max_length)
VALUES ($1, $2, $3, $4, $5, $6)
INSERT INTO chat_session (user_id, uuid, topic, created_at, active, max_length, model)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING *;

-- name: UpdateChatSessionByUUID :one
Expand Down
12 changes: 8 additions & 4 deletions api/sqlc_queries/chat_session.sql.go

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

3 changes: 2 additions & 1 deletion web/src/api/chat_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ export const deleteChatSession = async (uuid: string) => {
}
}

export const createChatSession = async (uuid: string, name: string) => {
export const createChatSession = async (uuid: string, name: string, model: string | undefined) => {
try {
const response = await request.post('/uuid/chat_sessions', {
uuid,
topic: name,
model
})
return response.data
}
Expand Down
8 changes: 5 additions & 3 deletions web/src/store/modules/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const useChatStore = defineStore('chat-store', {
},

addChatSession(history: Chat.Session, chatData: Chat.Message[] = []) {
createChatSession(history.uuid, history.title)
createChatSession(history.uuid, history.title, history.model)
this.history.unshift(history)
this.chat.unshift({ uuid: history.uuid, data: chatData })
this.active = history.uuid
Expand Down Expand Up @@ -157,12 +157,14 @@ export const useChatStore = defineStore('chat-store', {
return null
},

addChatByUuid(uuid: string, chat: Chat.Message) {
async addChatByUuid(uuid: string, chat: Chat.Message) {
const new_chat_text = t('chat.new')
if (!uuid) {
if (this.history.length === 0) {
const uuid = uuidv4()
createChatSession(uuid, chat.text)
const default_model_parameters = await getChatSessionDefault(new_chat_text)

createChatSession(uuid, chat.text, default_model_parameters.model)
this.history.push({ uuid, title: chat.text, isEdit: false })
// first chat message is prompt
this.chat.push({ uuid, data: [{ ...chat, isPrompt: true, isPin: false }] })
Expand Down

0 comments on commit e722a64

Please sign in to comment.