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

💄 style: improve open router tools calling metadata #3835

Merged
merged 2 commits into from
Sep 18, 2024

Conversation

arvinxx
Copy link
Contributor

@arvinxx arvinxx commented Sep 8, 2024

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • 📝 docs
  • 🔨 chore

🔀 变更说明 | Description of Change

📝 补充信息 | Additional Information

OpenRouter 的 Claude Tools calling 和 OpenAI 的兼容实现非常有问题,tool_calls 的 index 直接从 1 开始了,导致无法正常使用,尝试做了兼容,但兼容不起来。

[
        {
          id: 'gen-Bx4R8TCbr4GElWZJtE30XGDQyoYW',
          model: 'anthropic/claude-3.5-sonnet',
          object: 'chat.completion.chunk',
          created: 1725817213,
          choices: [
            {
              index: 0,
              delta: {
                role: 'assistant',
                content:
                  '为了回答您关于杭州天气的问题,我需要使用实时天气查询工具来获取最新的天气信息。让我为您查询一下。',
              },
              finish_reason: null,
              logprobs: null,
            },
          ],
        },
        {
          id: 'gen-Bx4R8TCbr4GElWZJtE30XGDQyoYW',
          model: 'anthropic/claude-3.5-sonnet',
          object: 'chat.completion.chunk',
          created: 1725817213,
          choices: [
            {
              delta: {
                role: 'assistant',
                content: null,
                tool_calls: [
                  {
                    id: 'toolu_01M368ZnDFfJwaiVGL4evqhn',
                    index: 1,
                    type: 'function',
                    function: { name: 'realtime-weather____fetchCurrentWeather', arguments: '' },
                  },
                ],
              },
              index: 0,
            },
          ],
        },
        {
          id: 'gen-Bx4R8TCbr4GElWZJtE30XGDQyoYW',
          model: 'anthropic/claude-3.5-sonnet',
          object: 'chat.completion.chunk',
          created: 1725817213,
          choices: [
            {
              delta: {
                role: 'assistant',
                content: null,
                tool_calls: [{ index: 1, type: 'function', function: { arguments: '{"city"' } }],
              },
              index: 0,
            },
          ],
        },
        {
          id: 'gen-Bx4R8TCbr4GElWZJtE30XGDQyoYW',
          model: 'anthropic/claude-3.5-sonnet',
          object: 'chat.completion.chunk',
          created: 1725817213,
          choices: [
            {
              delta: {
                role: 'assistant',
                content: null,
                tool_calls: [{ index: 1, type: 'function', function: { arguments: ':"杭州"}' } }],
              },
              index: 0,
            },
          ],
        },
        {
          id: 'gen-Bx4R8TCbr4GElWZJtE30XGDQyoYW',
          model: 'anthropic/claude-3.5-sonnet',
          object: 'chat.completion.chunk',
          created: 1725817213,
          choices: [
            { index: 0, delta: { role: 'assistant', content: '' }, finish_reason: 'tool_calls' },
          ],
        },
        {
          id: 'gen-Bx4R8TCbr4GElWZJtE30XGDQyoYW',
          model: 'anthropic/claude-3.5-sonnet',
          object: 'chat.completion.chunk',
          created: 1725817213,
          choices: [
            {
              index: 0,
              delta: { role: 'assistant', content: '' },
              finish_reason: null,
              logprobs: null,
            },
          ],
          usage: { prompt_tokens: 474, completion_tokens: 114, total_tokens: 588 },
        },
      ]

Copy link

vercel bot commented Sep 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lobe-chat-database ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 18, 2024 2:00pm
lobe-chat-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 18, 2024 2:00pm

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Sep 8, 2024
@lobehubbot
Copy link
Member

👍 @arvinxx

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

@dosubot dosubot bot added the 🐛 Bug Something isn't working | 缺陷 label Sep 8, 2024
Copy link

codecov bot commented Sep 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.16%. Comparing base (d3fabdc) to head (d8af127).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3835      +/-   ##
==========================================
+ Coverage   92.08%   92.16%   +0.07%     
==========================================
  Files         460      466       +6     
  Lines       31709    32045     +336     
  Branches     2004     3229    +1225     
==========================================
+ Hits        29198    29533     +335     
- Misses       2511     2512       +1     
Flag Coverage Δ
app 92.16% <100.00%> (+0.07%) ⬆️
server 97.36% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@arvinxx arvinxx changed the title 🐛 fix: open router tools calling for claude 💄 style: improve open router tools calling metadata Sep 16, 2024
@arvinxx arvinxx marked this pull request as ready for review September 18, 2024 13:53
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. 💄 Design Design an style | 样式问题 and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Sep 18, 2024
@arvinxx arvinxx merged commit 5ccc41d into main Sep 18, 2024
11 checks passed
@arvinxx arvinxx deleted the fix/openrouter-apikey branch September 18, 2024 16:02
@lobehubbot
Copy link
Member

❤️ Great PR @arvinxx ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.
项目的成长离不开用户反馈和贡献,感谢您的贡献! 如果您对 LobeHub 开发者社区感兴趣,请加入我们的 discord,然后私信 @arvinxx@canisminor1990。他们会邀请您加入我们的私密开发者频道。我们将会讨论关于 Lobe Chat 的开发,分享和讨论全球范围内的 AI 消息。

@lobehubbot
Copy link
Member

🎉 This PR is included in version 1.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

cy948 pushed a commit to cy948/lobe-chat that referenced this pull request Sep 21, 2024
* 🐛 fix: open router function calling for claude

* 📸 test: fix snapshot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working | 缺陷 💄 Design Design an style | 样式问题 released size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] openrouter api的模型无法支持fc [Bug] Openrouter模型不支持函数
2 participants