one-api/common/test/chat_config.go
Buer ef041e28a1
♻️ refactor: provider refactor (#41)
* ♻️ refactor: provider refactor
* 完善百度/讯飞的函数调用,现在可以在`lobe-chat`中正常调用函数了
2024-01-19 02:47:10 +08:00

133 lines
2.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package test
import (
"encoding/json"
"one-api/types"
"strings"
)
func GetChatCompletionRequest(chatType, modelName, stream string) *types.ChatCompletionRequest {
chatJSON := GetChatRequest(chatType, modelName, stream)
chatCompletionRequest := &types.ChatCompletionRequest{}
json.NewDecoder(chatJSON).Decode(chatCompletionRequest)
return chatCompletionRequest
}
func GetChatRequest(chatType, modelName, stream string) *strings.Reader {
var chatJSON string
switch chatType {
case "image":
chatJSON = `{
"model": "` + modelName + `",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Whats in this image?"
},
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
}
}
]
}
],
"max_tokens": 300,
"stream": ` + stream + `
}`
case "default":
chatJSON = `{
"model": "` + modelName + `",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
],
"stream": ` + stream + `
}`
case "function":
chatJSON = `{
"model": "` + modelName + `",
"stream": ` + stream + `,
"messages": [
{
"role": "user",
"content": "What is the weather like in Boston?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}`
case "tools":
chatJSON = `{
"model": "` + modelName + `",
"stream": ` + stream + `,
"messages": [
{
"role": "user",
"content": "What is the weather like in Boston?"
}
],
"functions": [
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
]
}
}
]
}`
}
return strings.NewReader(chatJSON)
}