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

function calling fixes for together/llama-3.1 #446

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

Conversation

kwindla
Copy link
Contributor

@kwindla kwindla commented Sep 7, 2024

Fixes for these function call test cases:

test_strings = [
    '<function=hello>{world}</function>',
    '<function=goodbye>{cruel world}"</function>',
    '<function=spacey>{extra space} </function>',
    '<function=noclose>{this has no closing tag}',
    '<function=empty></function>',
]

And also extracts a function call from the middle of an output (not just the beginning).

Copy link

@filipi87 filipi87 left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this Kwin. 🙌

function_call_accumulator = "<function"
else:
await self.push_frame("<" + TextFrame(chunk.choices[0].delta.content))
elif text == '<':
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to make the assumption that < will arrive in its own chunk with nothing else included, as will the word function -- just checking if that assumption is valid?

Do the chunks here correspond to the SSE chunks from Together, and if so, is the above documented behaviour, or something we've observed empirically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not documented. But I did test really heavily and this seems to be the pattern empirically. It makes sense, given what I've seen in general and the Llama 3.1 tokenizer, I think.

My thinking is that we should implement this way, for now, and then revisit when we have a chance to regularize around @chadbailey59's ideas that there should be configurable "structured data" patterns that aren't streamed through the pipeline.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds reasonable!

# Function format regex. Llama 3.1 sometimes adds an extra " or space just before the
# </function> tag. This regexp just ignores the extra characters if they are there. (That's
# the [\s"]? part of the regex.) Occasionally the </function> close tag is also missing.
function_regex = r'<function=(\w+)>(.*?)<\/function>|<function=(\w+)>(.*)'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the question mark necessary in .*? ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah never mind, I assume this is to turn this into a lazy match.

@LewisWolfgang
Copy link
Contributor

This looks fine to me, but I will leave it to others to approve, as I have not tested function calling with Together.

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

Successfully merging this pull request may close these issues.

4 participants