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: add function call support for Spark #5039

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hezhijie0327
Copy link
Contributor

@hezhijie0327 hezhijie0327 commented Dec 16, 2024

💻 变更类型 | Change Type

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

🔀 变更说明 | Description of Change

补齐之前 Spark 缺少的 function call 的实现

  1. 通过改造实现了 Spark 的 Function Call 功能(整体工具调用效果不是特别好,存在限制)
  2. 支持流式及非流式对话
  3. 试了下工具调用支持流式,但是除了 max-32k 模型支持工具回调外,其余均不支持(curl 调用测试也为空;max-32k 存在相同 payload,上一秒还能出内容,再次执行直接返回空的问题)
Function Name 描述
transformSparkStream 处理流式
transformSparkResponseToStream 处理非流式

Spark 的工具调用流很怪,返回的是对象不是数组,通过魔改 OpenAI 流处理对非标准返回强制转换为数组


PS: 给讯飞开了工单,将近三个多月无进展
image

📝 补充信息 | Additional Information

模块 效果
对话 image
工具调用 image

非流式响应流

{
    "code": 0,
    "message": "Success",
    "sid": "cha000b95d2@dx193cef49db1b894532",
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "",
                "tool_calls": {
                    "type": "function",
                    "function": {
                        "arguments": "{\"city\":\"Shanghai\"}",
                        "name": "realtime-weather____fetchCurrentWeather"
                    }
                }
            },
            "index": 0
        }
    ],
    "usage": {
        "prompt_tokens": 8,
        "completion_tokens": 0,
        "total_tokens": 8
    }
}

流式输出响应流

{
    "code": 0,
    "message": "Success",
    "sid": "cha000b6cd0@dx193cef628319a4b532",
    "id": "cha000b6cd0@dx193cef628319a4b532",
    "created": 1734344060,
    "choices": [
        {
            "delta": {
                "role": "assistant",
                "content": "",
                "tool_calls": {
                    "type": "function",
                    "function": {
                        "arguments": "{\"city\":\"Shanghai\"}",
                        "name": "realtime-weather____fetchCurrentWeather"
                    }
                }
            },
            "index": 0
        }
    ],
    "usage": {
        "prompt_tokens": 8,
        "completion_tokens": 0,
        "total_tokens": 8
    }
}

Copy link

vercel bot commented Dec 16, 2024

@hezhijie0327 is attempting to deploy a commit to the LobeHub Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Dec 16, 2024
@lobehubbot
Copy link
Member

👍 @hezhijie0327

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 💄 Design Design an style | 样式问题 label Dec 16, 2024
Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 18.38565% with 182 lines in your changes missing coverage. Please review.

Project coverage is 91.58%. Comparing base (e63249b) to head (c7d22dc).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/libs/agent-runtime/utils/streams/spark.ts 13.43% 116 Missing ⚠️
src/libs/agent-runtime/spark/index.ts 22.35% 66 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5039      +/-   ##
==========================================
- Coverage   91.97%   91.58%   -0.40%     
==========================================
  Files         548      549       +1     
  Lines       41408    41612     +204     
  Branches     2355     2354       -1     
==========================================
+ Hits        38087    38110      +23     
- Misses       3321     3502     +181     
Flag Coverage Δ
app 91.58% <18.38%> (-0.40%) ⬇️
server 98.12% <ø> (ø)

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.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Dec 16, 2024
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块是不是最好看下哪里需要给工厂函数开槽的,给开个槽?单独实现一个感觉后续的维护成本比较高

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💄 Design Design an style | 样式问题 size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants