Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions api/chat_main_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ type BotRequest struct {

type ChatInstructionResponse struct {
ArtifactInstruction string `json:"artifactInstruction"`
ToolInstruction string `json:"toolInstruction"`
}

func (h *ChatHandler) GetChatInstructions(w http.ResponseWriter, r *http.Request) {
Expand All @@ -95,15 +94,8 @@ func (h *ChatHandler) GetChatInstructions(w http.ResponseWriter, r *http.Request
artifactInstruction = ""
}

toolInstruction, err := loadToolInstruction()
if err != nil {
log.Printf("Warning: Failed to load tool instruction: %v", err)
toolInstruction = ""
}

json.NewEncoder(w).Encode(ChatInstructionResponse{
ArtifactInstruction: artifactInstruction,
ToolInstruction: toolInstruction,
})
}

Expand Down
22 changes: 0 additions & 22 deletions api/chat_main_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ type ChatService struct {
//go:embed artifact_instruction.txt
var artifactInstructionText string

//go:embed tool_instruction.txt
var toolInstructionText string

// NewChatService creates a new ChatService with database queries.
func NewChatService(q *sqlc_queries.Queries) *ChatService {
return &ChatService{q: q}
Expand All @@ -44,15 +41,6 @@ func loadArtifactInstruction() (string, error) {
return artifactInstructionText, nil
}

// loadToolInstruction loads the tool-use instruction from file.
// Returns the instruction content or an error if the file cannot be read.
func loadToolInstruction() (string, error) {
if toolInstructionText == "" {
return "", eris.New("tool instruction text is empty")
}
return toolInstructionText, nil
}

func appendInstructionToSystemMessage(msgs []models.Message, instruction string) {
if instruction == "" || len(msgs) == 0 {
return
Expand Down Expand Up @@ -139,16 +127,6 @@ func (s *ChatService) getAskMessages(chatSession sqlc_queries.ChatSession, chatU
appendInstructionToSystemMessage(msgs, artifactInstruction)
}

if chatSession.CodeRunnerEnabled {
toolInstruction, err := loadToolInstruction()
if err != nil {
log.Printf("Warning: Failed to load tool instruction: %v", err)
toolInstruction = ""
}

appendInstructionToSystemMessage(msgs, toolInstruction)
}

return msgs, nil
}

Expand Down
68 changes: 32 additions & 36 deletions api/chat_session_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ func (h *ChatSessionHandler) getChatSessionByUUID(w http.ResponseWriter, r *http
}

session_resp := &ChatSessionResponse{
Uuid: session.Uuid,
Topic: session.Topic,
MaxLength: session.MaxLength,
CreatedAt: session.CreatedAt,
UpdatedAt: session.UpdatedAt,
CodeRunnerEnabled: session.CodeRunnerEnabled,
ArtifactEnabled: session.ArtifactEnabled,
Uuid: session.Uuid,
Topic: session.Topic,
MaxLength: session.MaxLength,
CreatedAt: session.CreatedAt,
UpdatedAt: session.UpdatedAt,
ArtifactEnabled: session.ArtifactEnabled,
}
json.NewEncoder(w).Encode(session_resp)
}
Expand Down Expand Up @@ -146,20 +145,19 @@ func (h *ChatSessionHandler) createChatSessionByUUID(w http.ResponseWriter, r *h
}

type UpdateChatSessionRequest struct {
Uuid string `json:"uuid"`
Topic string `json:"topic"`
MaxLength int32 `json:"maxLength"`
Temperature float64 `json:"temperature"`
Model string `json:"model"`
TopP float64 `json:"topP"`
N int32 `json:"n"`
MaxTokens int32 `json:"maxTokens"`
Debug bool `json:"debug"`
SummarizeMode bool `json:"summarizeMode"`
CodeRunnerEnabled bool `json:"codeRunnerEnabled"`
ArtifactEnabled bool `json:"artifactEnabled"`
ExploreMode bool `json:"exploreMode"`
WorkspaceUUID string `json:"workspaceUuid,omitempty"`
Uuid string `json:"uuid"`
Topic string `json:"topic"`
MaxLength int32 `json:"maxLength"`
Temperature float64 `json:"temperature"`
Model string `json:"model"`
TopP float64 `json:"topP"`
N int32 `json:"n"`
MaxTokens int32 `json:"maxTokens"`
Debug bool `json:"debug"`
SummarizeMode bool `json:"summarizeMode"`
ArtifactEnabled bool `json:"artifactEnabled"`
ExploreMode bool `json:"exploreMode"`
WorkspaceUUID string `json:"workspaceUuid,omitempty"`
}

// UpdateChatSessionByUUID updates a chat session by its UUID
Expand Down Expand Up @@ -197,7 +195,6 @@ func (h *ChatSessionHandler) createOrUpdateChatSessionByUUID(w http.ResponseWrit
sessionParams.MaxTokens = sessionReq.MaxTokens
sessionParams.Debug = sessionReq.Debug
sessionParams.SummarizeMode = sessionReq.SummarizeMode
sessionParams.CodeRunnerEnabled = sessionReq.CodeRunnerEnabled
sessionParams.ArtifactEnabled = sessionReq.ArtifactEnabled
sessionParams.ExploreMode = sessionReq.ExploreMode

Expand Down Expand Up @@ -377,20 +374,19 @@ func (h *ChatSessionHandler) createChatSessionFromSnapshot(w http.ResponseWriter
sessionUUID := uuid.New().String()

session, err := h.service.q.CreateOrUpdateChatSessionByUUID(r.Context(), sqlc_queries.CreateOrUpdateChatSessionByUUIDParams{
Uuid: sessionUUID,
UserID: userID,
Topic: sessionTitle,
MaxLength: originSession.MaxLength,
Temperature: originSession.Temperature,
Model: originSession.Model,
MaxTokens: originSession.MaxTokens,
TopP: originSession.TopP,
Debug: originSession.Debug,
SummarizeMode: originSession.SummarizeMode,
CodeRunnerEnabled: originSession.CodeRunnerEnabled,
ExploreMode: originSession.ExploreMode,
WorkspaceID: originSession.WorkspaceID,
N: 1,
Uuid: sessionUUID,
UserID: userID,
Topic: sessionTitle,
MaxLength: originSession.MaxLength,
Temperature: originSession.Temperature,
Model: originSession.Model,
MaxTokens: originSession.MaxTokens,
TopP: originSession.TopP,
Debug: originSession.Debug,
SummarizeMode: originSession.SummarizeMode,
ExploreMode: originSession.ExploreMode,
WorkspaceID: originSession.WorkspaceID,
N: 1,
})
if err != nil {
apiErr := ErrInternalUnexpected
Expand Down
27 changes: 13 additions & 14 deletions api/chat_session_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,19 @@ func (s *ChatSessionService) GetSimpleChatSessionsByUserID(ctx context.Context,
}

return SimpleChatSession{
Uuid: session.Uuid,
IsEdit: false,
Title: session.Topic,
MaxLength: int(session.MaxLength),
Temperature: float64(session.Temperature),
TopP: float64(session.TopP),
N: session.N,
MaxTokens: session.MaxTokens,
Debug: session.Debug,
Model: session.Model,
SummarizeMode: session.SummarizeMode,
CodeRunnerEnabled: session.CodeRunnerEnabled,
ArtifactEnabled: session.ArtifactEnabled,
WorkspaceUuid: workspaceUuid,
Uuid: session.Uuid,
IsEdit: false,
Title: session.Topic,
MaxLength: int(session.MaxLength),
Temperature: float64(session.Temperature),
TopP: float64(session.TopP),
N: session.N,
MaxTokens: session.MaxTokens,
Debug: session.Debug,
Model: session.Model,
SummarizeMode: session.SummarizeMode,
ArtifactEnabled: session.ArtifactEnabled,
WorkspaceUuid: workspaceUuid,
}
})
return simple_sessions, nil
Expand Down
2 changes: 0 additions & 2 deletions api/chat_workspace_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,6 @@ func (h *ChatWorkspaceHandler) createSessionInWorkspace(w http.ResponseWriter, r
"uuid": session.Uuid,
"topic": session.Topic,
"model": session.Model,
"codeRunnerEnabled": session.CodeRunnerEnabled,
"artifactEnabled": session.ArtifactEnabled,
"workspaceUuid": workspaceUUID,
"createdAt": session.CreatedAt.Format("2006-01-02T15:04:05Z"),
Expand Down Expand Up @@ -693,7 +692,6 @@ func (h *ChatWorkspaceHandler) getSessionsByWorkspace(w http.ResponseWriter, r *
"debug": session.Debug,
"summarizeMode": session.SummarizeMode,
"exploreMode": session.ExploreMode,
"codeRunnerEnabled": session.CodeRunnerEnabled,
"artifactEnabled": session.ArtifactEnabled,
"createdAt": session.CreatedAt.Format("2006-01-02T15:04:05Z"),
"updatedAt": session.UpdatedAt.Format("2006-01-02T15:04:05Z"),
Expand Down
3 changes: 0 additions & 3 deletions api/embed_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ func TestEmbedInstructions(t *testing.T) {
if artifactInstructionText == "" {
t.Fatalf("artifactInstructionText is empty")
}
if toolInstructionText == "" {
t.Fatalf("toolInstructionText is empty")
}
}
40 changes: 19 additions & 21 deletions api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,19 @@ func (msg SimpleChatMessage) GetRole() string {
}

type SimpleChatSession struct {
Uuid string `json:"uuid"`
IsEdit bool `json:"isEdit"`
Title string `json:"title"`
MaxLength int `json:"maxLength"`
Temperature float64 `json:"temperature"`
TopP float64 `json:"topP"`
N int32 `json:"n"`
MaxTokens int32 `json:"maxTokens"`
Debug bool `json:"debug"`
Model string `json:"model"`
SummarizeMode bool `json:"summarizeMode"`
CodeRunnerEnabled bool `json:"codeRunnerEnabled"`
ArtifactEnabled bool `json:"artifactEnabled"`
WorkspaceUuid string `json:"workspaceUuid"`
Uuid string `json:"uuid"`
IsEdit bool `json:"isEdit"`
Title string `json:"title"`
MaxLength int `json:"maxLength"`
Temperature float64 `json:"temperature"`
TopP float64 `json:"topP"`
N int32 `json:"n"`
MaxTokens int32 `json:"maxTokens"`
Debug bool `json:"debug"`
Model string `json:"model"`
SummarizeMode bool `json:"summarizeMode"`
ArtifactEnabled bool `json:"artifactEnabled"`
WorkspaceUuid string `json:"workspaceUuid"`
}

type ChatMessageResponse struct {
Expand All @@ -87,13 +86,12 @@ type ChatMessageResponse struct {
}

type ChatSessionResponse struct {
Uuid string `json:"uuid"`
Topic string `json:"topic"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
MaxLength int32 `json:"maxLength"`
CodeRunnerEnabled bool `json:"codeRunnerEnabled"`
ArtifactEnabled bool `json:"artifactEnabled"`
Uuid string `json:"uuid"`
Topic string `json:"topic"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
MaxLength int32 `json:"maxLength"`
ArtifactEnabled bool `json:"artifactEnabled"`
}

type Pagination struct {
Expand Down
5 changes: 2 additions & 3 deletions api/sqlc/queries/chat_session.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ WHERE uuid = $1
RETURNING *;

-- name: CreateOrUpdateChatSessionByUUID :one
INSERT INTO chat_session(uuid, user_id, topic, max_length, temperature, model, max_tokens, top_p, n, debug, summarize_mode, code_runner_enabled, workspace_id, explore_mode, artifact_enabled)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
INSERT INTO chat_session(uuid, user_id, topic, max_length, temperature, model, max_tokens, top_p, n, debug, summarize_mode, workspace_id, explore_mode, artifact_enabled)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
ON CONFLICT (uuid)
DO UPDATE SET
max_length = EXCLUDED.max_length,
Expand All @@ -53,7 +53,6 @@ top_p = EXCLUDED.top_p,
n= EXCLUDED.n,
model = EXCLUDED.model,
summarize_mode = EXCLUDED.summarize_mode,
code_runner_enabled = EXCLUDED.code_runner_enabled,
artifact_enabled = EXCLUDED.artifact_enabled,
workspace_id = CASE WHEN EXCLUDED.workspace_id IS NOT NULL THEN EXCLUDED.workspace_id ELSE chat_session.workspace_id END,
topic = CASE WHEN chat_session.topic IS NULL THEN EXCLUDED.topic ELSE chat_session.topic END,
Expand Down
3 changes: 1 addition & 2 deletions api/sqlc/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ CREATE TABLE IF NOT EXISTS chat_session (
max_tokens int DEFAULT 4096 NOT NULL,
n integer DEFAULT 1 NOT NULL,
summarize_mode boolean DEFAULT false NOT NULL,
code_runner_enabled boolean DEFAULT false NOT NULL,
workspace_id INTEGER REFERENCES chat_workspace(id) ON DELETE SET NULL,
artifact_enabled boolean DEFAULT false NOT NULL
);


-- chat_session
ALTER TABLE chat_session DROP COLUMN IF EXISTS code_runner_enabled;
ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS temperature float DEFAULT 1.0 NOT NULL;
ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS top_p float DEFAULT 1.0 NOT NULL;
ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS max_tokens int DEFAULT 4096 NOT NULL;
Expand All @@ -185,7 +185,6 @@ ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS explore_mode boolean DEFAULT f
ALTER TABlE chat_session ADD COLUMN IF NOT EXISTS model character varying(255) NOT NULL DEFAULT 'gpt-3.5-turbo';
ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS n INTEGER DEFAULT 1 NOT NULL;
ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS summarize_mode boolean DEFAULT false NOT NULL;
ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS code_runner_enabled boolean DEFAULT false NOT NULL;
ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS workspace_id INTEGER REFERENCES chat_workspace(id) ON DELETE SET NULL;
ALTER TABLE chat_session ADD COLUMN IF NOT EXISTS artifact_enabled boolean DEFAULT false NOT NULL;

Expand Down
Loading