-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix array "required" and "enum" in function calling
- Loading branch information
Showing
11 changed files
with
344 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package tests_grpc_test | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/joho/godotenv" | ||
"go.limit.dev/unollm/grpcServer" | ||
"go.limit.dev/unollm/model" | ||
"go.limit.dev/unollm/utils" | ||
) | ||
|
||
func TestMoonShot(t *testing.T) { | ||
godotenv.Load("../.env") | ||
|
||
messages := make([]*model.LLMChatCompletionMessage, 0) | ||
messages = append(messages, &model.LLMChatCompletionMessage{ | ||
Role: "user", | ||
Content: "假如今天下大雨,我是否需要带伞?", | ||
}) | ||
OPENAIApiKey := os.Getenv("TEST_MOONSHOT_API") | ||
req_info := model.LLMRequestInfo{ | ||
LlmApiType: grpcServer.MOONSHOT_LLM_API, | ||
Model: "moonshot-v1-8k", | ||
Temperature: 0.9, | ||
TopP: 0.9, | ||
TopK: 1, | ||
Url: "https://api.moonshot.cn/v1", | ||
Token: OPENAIApiKey, | ||
} | ||
req := model.LLMRequestSchema{ | ||
Messages: messages, | ||
LlmRequestInfo: &req_info, | ||
} | ||
mockServer := grpcServer.UnoForwardServer{} | ||
res, err := mockServer.BlockingRequestLLM(context.Background(), &req) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
log.Println("res: ", res) | ||
} | ||
|
||
func TestMoonShotStreaming(t *testing.T) { | ||
godotenv.Load("../.env") | ||
|
||
messages := make([]*model.LLMChatCompletionMessage, 0) | ||
messages = append(messages, &model.LLMChatCompletionMessage{ | ||
Role: "user", | ||
Content: "假如今天下大雨,我是否需要带伞?", | ||
}) | ||
OPENAIApiKey := os.Getenv("TEST_MOONSHOT_API") | ||
req_info := model.LLMRequestInfo{ | ||
LlmApiType: grpcServer.MOONSHOT_LLM_API, | ||
Model: "moonshot-v1-8k", | ||
Temperature: 0.9, | ||
TopP: 0.9, | ||
TopK: 1, | ||
Url: "https://api.moonshot.cn/v1", | ||
Token: OPENAIApiKey, | ||
} | ||
req := model.LLMRequestSchema{ | ||
Messages: messages, | ||
LlmRequestInfo: &req_info, | ||
} | ||
mockServer := grpcServer.UnoForwardServer{} | ||
mockServerPipe := utils.MockServerStream{ | ||
Stream: make(chan *model.PartialLLMResponse, 1000), | ||
} | ||
err := mockServer.StreamRequestLLM(&req, &mockServerPipe) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for { | ||
res := <-mockServerPipe.Stream | ||
log.Println(res) | ||
if res.LlmTokenCount != nil { | ||
log.Println(res.LlmTokenCount) | ||
return | ||
} | ||
} | ||
} | ||
|
||
func TestMoonShotFunctionCalling(t *testing.T) { | ||
godotenv.Load("../.env") | ||
|
||
messages := make([]*model.LLMChatCompletionMessage, 0) | ||
messages = append(messages, &model.LLMChatCompletionMessage{ | ||
Role: "user", | ||
Content: "whats the weather like in Poston?", | ||
}) | ||
OPENAIApiKey := os.Getenv("TEST_MOONSHOT_API") | ||
req_info := model.LLMRequestInfo{ | ||
LlmApiType: grpcServer.MOONSHOT_LLM_API, | ||
Model: "moonshot-v1-8k", | ||
Temperature: 0.9, | ||
TopP: 0.9, | ||
TopK: 1, | ||
Url: "https://api.moonshot.cn/v1", | ||
Token: OPENAIApiKey, | ||
Functions: []*model.Function{ | ||
{ | ||
Name: "get_weather", | ||
Description: "Get the weather of a location", | ||
Parameters: []*model.FunctionCallingParameter{ | ||
{ | ||
Name: "location", | ||
Type: "string", | ||
Description: "The city and state, e.g. San Francisco, CA", | ||
}, | ||
{ | ||
Name: "unit", | ||
Type: "string", | ||
Enums: []string{"celsius", "fahrenheit"}, | ||
}, | ||
}, | ||
Requireds: []string{"location", "unit"}, | ||
}, | ||
}, | ||
UseFunctionCalling: true, | ||
} | ||
req := model.LLMRequestSchema{ | ||
Messages: messages, | ||
LlmRequestInfo: &req_info, | ||
} | ||
mockServer := grpcServer.UnoForwardServer{} | ||
res, err := mockServer.BlockingRequestLLM(context.Background(), &req) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
log.Printf("res: %#v", res.ToolCalls[0]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.