Skip to content

Conversation

@willkurt
Copy link
Contributor

This is the basic implementation of a demo of the HF SMoL model being used as a NL interface for calling applications. The current supported functions are:

  • send a text message
  • order food
  • order a ride
  • get the weather

The user is prompted to ask a question and the model should translate this into a function call (which could presumable be mapped to a real application in the future).

@willkurt willkurt requested a review from rlouf October 16, 2024 20:22
@rlouf rlouf changed the title Smol world Smol world (ADV-163) Oct 21, 2024
def instruct_prompt(question, functions, tokenizer):
messages = [
{"role": "user", "content": SYSTEM_PROMPT_FOR_CHAT_MODEL.format(functions=format_functions(functions))},
{"role": "assistant", "content": ASSISTANT_PROMPT_FOR_CHAT_MODEL },
Copy link
Member

Choose a reason for hiding this comment

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

I like the idea of injecting a first assistant response. Does that improve the subsequent generations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like most prompt engineering things I feel like it does improve outcomes, but hard to say without proper evaluations. Right now it's definitely in the AI-superstition category.

"items": {"type": "float"}
})

def build_standard_fc_regex(function_data):
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind documenting these functions? I opened an issue on Outlines to provide an interface for multi-functions function calling and we will probably use this code as a first draft.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely!

@rlouf
Copy link
Member

rlouf commented Oct 21, 2024

Just a few minor comments, otherwise this is looking great!

@@ -0,0 +1,3 @@
outlines==0.1.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
outlines==0.1.0
outlines==0.1.1

Might be able to go up to 0.1.1

Comment on lines +18 to +27
def format_functions(functions):
formatted_functions = []
for func in functions:
function_info = f"{func['name']}: {func['description']}\n"
if 'parameters' in func and 'properties' in func['parameters']:
for arg, details in func['parameters']['properties'].items():
description = details.get('description', 'No description provided')
function_info += f"- {arg}: {description}\n"
formatted_functions.append(function_info)
return "\n".join(formatted_functions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def format_functions(functions):
formatted_functions = []
for func in functions:
function_info = f"{func['name']}: {func['description']}\n"
if 'parameters' in func and 'properties' in func['parameters']:
for arg, details in func['parameters']['properties'].items():
description = details.get('description', 'No description provided')
function_info += f"- {arg}: {description}\n"
formatted_functions.append(function_info)
return "\n".join(formatted_functions)
def format_functions(functions):
"""
Formats the functions in the given list of functions into a list
of human-readable strings.
Example output:
[
'send_text: Send a text message to a contact
- to: The name of the contact to send the text to.
- message: The message to send to the contact.',
'send_email: Send an email to a contact
- to: The name of the contact to send the email to.
- subject: The subject of the email.
- message: The message to send to the contact.'
]
"""
formatted_functions = []
for func in functions:
function_info = f"{func['name']}: {func['description']}\n"
if 'parameters' in func and 'properties' in func['parameters']:
for arg, details in func['parameters']['properties'].items():
description = details.get('description', 'No description provided')
function_info += f"- {arg}: {description}\n"
formatted_functions.append(function_info)
return "\n".join(formatted_functions)

Possible comment string

@rlouf rlouf self-requested a review October 25, 2024 19:52
@willkurt willkurt merged commit 8cb9dd6 into main Nov 4, 2024
@willkurt willkurt deleted the smol-world branch November 4, 2024 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants