mirror of
https://github.com/coaidev/coai.git
synced 2025-05-20 05:20:15 +09:00
feat: tools_call
finish reason
This commit is contained in:
parent
efc76c3642
commit
082bd0695a
@ -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 = {
|
||||
@ -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");
|
||||
},
|
||||
};
|
||||
|
@ -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>
|
||||
)}
|
||||
|
@ -16,6 +16,11 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
ReasonStop = "stop"
|
||||
ReasonToolsCall = "tools_call"
|
||||
)
|
||||
|
||||
func supportRelayPlan() bool {
|
||||
return channel.SystemInstance.SupportRelayPlan()
|
||||
}
|
||||
@ -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",
|
||||
@ -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{
|
||||
@ -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),
|
||||
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user