summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2025-08-08 09:24:47 +0300
committerGrail Finder <wohilas@gmail.com>2025-08-08 09:24:47 +0300
commit9cb4561c828426502b5a28797b932db6c06e22b1 (patch)
treeb82b102669b5bacfde1379fd9b4945ee3d1f58f3
parentd59b985534474ecd27c3c144e7dd770a2433d184 (diff)
Enha: openai tools [WIP]
-rw-r--r--models/models.go58
-rw-r--r--tools.go28
2 files changed, 58 insertions, 28 deletions
diff --git a/models/models.go b/models/models.go
index bb3fa1b..51a4b87 100644
--- a/models/models.go
+++ b/models/models.go
@@ -108,33 +108,6 @@ func (cb *ChatBody) MakeStopSlice() []string {
return ss
}
-type ChatToolsBody struct {
- Model string `json:"model"`
- Messages []RoleMsg `json:"messages"`
- Tools []struct {
- Type string `json:"type"`
- Function struct {
- Name string `json:"name"`
- Description string `json:"description"`
- Parameters struct {
- Type string `json:"type"`
- Properties struct {
- Location struct {
- Type string `json:"type"`
- Description string `json:"description"`
- } `json:"location"`
- Unit struct {
- Type string `json:"type"`
- Enum []string `json:"enum"`
- } `json:"unit"`
- } `json:"properties"`
- Required []string `json:"required"`
- } `json:"parameters"`
- } `json:"function"`
- } `json:"tools"`
- ToolChoice string `json:"tool_choice"`
-}
-
type DSChatReq struct {
Messages []RoleMsg `json:"messages"`
Model string `json:"model"`
@@ -287,6 +260,37 @@ type EmbeddingResp struct {
// } `json:"data"`
// }
+// === tools models
+
+type ToolArgProps struct {
+ Type string `json:"type"`
+ Description string `json:"description"`
+}
+
+type ToolFuncParams struct {
+ Type string `json:"type"`
+ Properties map[string]ToolArgProps `json:"properties"`
+ Required []string `json:"required"`
+}
+
+type ToolFunc struct {
+ Name string `json:"name"`
+ Description string `json:"description"`
+ Parameters ToolFuncParams `json:"parameters"`
+}
+
+type Tool struct {
+ Type string `json:"type"`
+ Function ToolFunc `json:"function"`
+}
+
+type OpenAIReq struct {
+ ChatBody
+ Tools []Tool `json:"tools"`
+}
+
+// ===
+
type LLMModels struct {
Object string `json:"object"`
Data []struct {
diff --git a/tools.go b/tools.go
index fe95ce5..01ab32b 100644
--- a/tools.go
+++ b/tools.go
@@ -1,8 +1,8 @@
package main
import (
- "gf-lt/models"
"fmt"
+ "gf-lt/models"
"regexp"
"strings"
"time"
@@ -141,3 +141,29 @@ var fnMap = map[string]fnSig{
"recall_topics": recallTopics,
"memorise": memorise,
}
+
+// openai style def
+var baseTools = []models.Tool{
+ // memorise
+ models.Tool{
+ Type: "function",
+ Function: models.ToolFunc{
+ Name: "memorise",
+ Description: "save topic-data in key-value cache",
+ Parameters: models.ToolFuncParams{
+ Type: "object",
+ Required: []string{"topic", "data"},
+ Properties: map[string]models.ToolArgProps{
+ "topic": models.ToolArgProps{
+ Type: "string",
+ Description: "topic is the key under which data is saved",
+ },
+ "data": models.ToolArgProps{
+ Type: "string",
+ Description: "data is the value that is saved under the topic-key",
+ },
+ },
+ },
+ },
+ },
+}