Skip to content

Commit

Permalink
feat: tools_call finish reason
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Feb 18, 2024
1 parent efc76c3 commit 082bd06
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
6 changes: 5 additions & 1 deletion app/src/components/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Button } from "./ui/button";
import { getMemory, setMemory } from "@/utils/memory.ts";
import { themeEvent } from "@/events/theme.ts";

const defaultTheme = "dark";

type Theme = "dark" | "light" | "system";

type ThemeProviderProps = {
Expand Down Expand Up @@ -37,7 +39,9 @@ const initialState: ThemeProviderState = {
activeTheme(theme);
},
toggleTheme: () => {
const theme = getMemory("theme") as Theme;
const key = getMemory("theme");
const theme = (key.length > 0 ? key : defaultTheme) as Theme;

activeTheme(theme === "dark" ? "light" : "dark");
},
};
Expand Down
4 changes: 2 additions & 2 deletions app/src/dialogs/SubscriptionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ function SubscriptionDialog() {
</p>
{!relayPlan && (
<div
className={`sub-tip flex flex-row items-center w-max mx-auto select-none`}
className={`sub-tip flex flex-row items-center px-4 mx-auto select-none break-all`}
>
<Info className={`h-4 w-4 mr-1.5`} />
<Info className={`shrink-0 h-4 w-4 mr-1.5`} />
{t("sub.plan-not-support-relay")}
</div>
)}
Expand Down
25 changes: 22 additions & 3 deletions manager/chat_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import (
"time"
)

const (
ReasonStop = "stop"
ReasonToolsCall = "tools_call"
)

func supportRelayPlan() bool {
return channel.SystemInstance.SupportRelayPlan()
}
Expand Down Expand Up @@ -111,6 +116,8 @@ func sendTranshipmentResponse(c *gin.Context, form RelayForm, messages []globals
CollectQuota(c, user, buffer, plan, err)
}

tools := buffer.GetToolCalls()

c.JSON(http.StatusOK, RelayResponse{
Id: fmt.Sprintf("chatcmpl-%s", id),
Object: "chat.completion",
Expand All @@ -122,10 +129,10 @@ func sendTranshipmentResponse(c *gin.Context, form RelayForm, messages []globals
Message: globals.Message{
Role: globals.Assistant,
Content: buffer.Read(),
ToolCalls: buffer.GetToolCalls(),
ToolCalls: tools,
FunctionCall: buffer.GetFunctionCall(),
},
FinishReason: "stop",
FinishReason: utils.Multi(tools != nil, ReasonToolsCall, ReasonStop),
},
},
Usage: Usage{
Expand All @@ -137,6 +144,18 @@ func sendTranshipmentResponse(c *gin.Context, form RelayForm, messages []globals
})
}

func getFinishReason(data *globals.Chunk, end bool) interface{} {
if end {
return nil
}

if data.ToolCall != nil {
return ReasonToolsCall
}

return ReasonStop
}

func getStreamTranshipmentForm(id string, created int64, form RelayForm, data *globals.Chunk, buffer *utils.Buffer, end bool, err error) RelayStreamResponse {
return RelayStreamResponse{
Id: fmt.Sprintf("chatcmpl-%s", id),
Expand All @@ -152,7 +171,7 @@ func getStreamTranshipmentForm(id string, created int64, form RelayForm, data *g
ToolCalls: data.ToolCall,
FunctionCall: data.FunctionCall,
},
FinishReason: utils.Multi[interface{}](end, "stop", nil),
FinishReason: getFinishReason(data, end),
},
},
Usage: Usage{
Expand Down

0 comments on commit 082bd06

Please sign in to comment.