Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

反序列化ChatCompletionRequest对象失败 #33

Closed
egan-mw opened this issue May 28, 2024 · 3 comments
Closed

反序列化ChatCompletionRequest对象失败 #33

egan-mw opened this issue May 28, 2024 · 3 comments

Comments

@egan-mw
Copy link

egan-mw commented May 28, 2024

我在尝试将接收到的JSON请求体反序列化为ChatCompletionRequest对象时遇到了问题。尽管我发送的请求数据格式看起来是正确的,但是反序列化过程没有成功。

请求示例
{
"topP": 1,
"temperature": 1,
"maxTokens": 2500,
"messages": [
{
"role": "system",
"content": "你好"
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "识别这张图片"
},
{
"type": "image_url",
"imageUrl": {
"url": "https://img.baigonglian.com/open_platform/generate/1ad71539c74715cfceb1c6b2634e9bf1.png"
}
}
]
}
],
"model": "gpt-4o",
"frequencyPenalty": 0.6299999952316284
}

@Lambdua
Copy link
Owner

Lambdua commented May 28, 2024

openai-api返回的数据对象不是驼峰命名的. 因该返回类似下面的结构:

{
  "model": "gpt-4-turbo",
  "messages": [
    {
      "role": "system",
      "content": "Hello! I'm a weather bot. I can help you with the weather. Just ask me for the current weather in a specific location."
    },
    {
      "role": "assistant",
      "content": "这是一个assistant的回复模拟"
    },
    {
      "role": "user",
      "content": "文本内容测试"
    },
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "What's 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"
          }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "123",
      "content": "这是一个tool的回复模拟"
    },
    {
      "role": "function",
      "content": "这是一个system的回复模拟",
      "name": "get_current_weather"
    }
  ],
  "max_tokens": 300,
  "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",
  "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"
        ]
      }
    }
  ],
  "function_call": {
    "name": "get_current_weather"
  },
  "logprobs": true,
  "top_logprobs": 2,
  "stop": [
    "test",
    "other"
  ],
  "stream_options": {
    "include_usage": true
  }
}

@egan-mw
Copy link
Author

egan-mw commented May 28, 2024

openai-api返回的数据对象不是驼峰命名的. 因该返回类似下面的结构:

{
  "model": "gpt-4-turbo",
  "messages": [
    {
      "role": "system",
      "content": "Hello! I'm a weather bot. I can help you with the weather. Just ask me for the current weather in a specific location."
    },
    {
      "role": "assistant",
      "content": "这是一个assistant的回复模拟"
    },
    {
      "role": "user",
      "content": "文本内容测试"
    },
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "What's 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"
          }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "123",
      "content": "这是一个tool的回复模拟"
    },
    {
      "role": "function",
      "content": "这是一个system的回复模拟",
      "name": "get_current_weather"
    }
  ],
  "max_tokens": 300,
  "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",
  "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"
        ]
      }
    }
  ],
  "function_call": {
    "name": "get_current_weather"
  },
  "logprobs": true,
  "top_logprobs": 2,
  "stop": [
    "test",
    "other"
  ],
  "stream_options": {
    "include_usage": true
  }
}

我是在接口中反序列化ChatCompletionRequest类型的参数不成功
@PostMapping("/chat-dialog")
public ChatCompletionChoice chatCompletions(@requestbody ChatCompletionRequest chatCompletionRequest) {
return customerService.chat(chatCompletionRequest);
}

@egan-mw egan-mw closed this as completed May 28, 2024
@Lambdua
Copy link
Owner

Lambdua commented May 28, 2024

你应该按照snake_case的参数命名风格来设置你的参数

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants