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

Fix tool use input handling #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zieen
Copy link

@zieen zieen commented Feb 21, 2025

Fixes #67

Address the issue of missing input field in tool_use structure by removing omitempty and handling empty input.

  • message.go

    • Remove omitempty from the Input field in the MessageContentToolUse struct.
    • Update the NewMessageContentToolUse function to handle empty Input by setting it to an empty JSON object if nil.
  • message_stream.go

    • Update the MessagesEventContentBlockStop case to handle empty Input by setting it to an empty JSON object if nil.
  • message_stream_test.go

    • Add test cases for tools with and without parameters to ensure proper handling of the input field.

For more details, open the Copilot Workspace session.

Fixes liushuangls#67

Address the issue of missing `input` field in `tool_use` structure by removing `omitempty` and handling empty `input`.

* **message.go**
  - Remove `omitempty` from the `Input` field in the `MessageContentToolUse` struct.
  - Update the `NewMessageContentToolUse` function to handle empty `Input` by setting it to an empty JSON object if nil.

* **message_stream.go**
  - Update the `MessagesEventContentBlockStop` case to handle empty `Input` by setting it to an empty JSON object if nil.

* **message_stream_test.go**
  - Add test cases for tools with and without parameters to ensure proper handling of the `input` field.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/liushuangls/go-anthropic/issues/67?shareId=XXXX-XXXX-XXXX-XXXX).
@liushuangls
Copy link
Owner

Thank you! Please fix the error in actions

Copy link
Collaborator

@WillMatthews WillMatthews left a comment

Choose a reason for hiding this comment

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

Looks good overall, thank you for making that change.

Please just follow through with the rename of handlerMessagesStreamEmptyMessages to handlerMessagesStreamToolUseWithoutParameters where appropriate to make tests pass 😸

I think I would like to see an integration test too, but that's something we should add to the backlog rather than fiddle more here - I am excited to get this feature in! 🎉

}

func NewMessageContentToolUse(
toolUseId, name string,
input json.RawMessage,
) *MessageContentToolUse {
if input == nil {
input = json.RawMessage("{}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: prefer backticks ` to a quotes " for strings in go.

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