Skip to content

Instantly share code, notes, and snippets.

@ngxson
Last active February 20, 2024 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngxson/c477fd9fc8e0a25c52ff4aa6129dc7a1 to your computer and use it in GitHub Desktop.
Save ngxson/c477fd9fc8e0a25c52ff4aa6129dc7a1 to your computer and use it in GitHub Desktop.
Meetkai Llama.cpp
from functionary.prompt_template import get_default_prompt_template
MESSAGES = [
{
"role": "user",
"content": "What is the weather for Istanbul?"
},
{
"role": "assistant",
"content": "Yes I will try",
},
{
"role": "assistant",
"content": None,
"tool_calls": [
{"type": "function",
"function": {"name": "plan_trip", "arguments": '{\n "destination": "Paris",\n "duration": 7,\n "interests": ["art", "culture"]\n}'
}}
]
},
{
"role": "tool",
"tool_call_id": "get_current_weather",
"name": "get_current_weather",
"content": "Sunny day!!!"
},
]
TOOLS = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"format": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.",
},
},
"required": ["location", "format"],
},
}
},
{
"type": "function",
"function": {
"name": "get_n_day_weather_forecast",
"description": "Get an N-day weather forecast",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"format": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the users location.",
},
"num_days": {
"type": "integer",
"description": "The number of days to forecast",
}
},
"required": ["location", "format", "num_days"]
},
}
},
]
prompt_template = get_default_prompt_template()
prompt_str = prompt_template.get_prompt_from_messages(
MESSAGES + [{"role": "assistant"}], TOOLS
)
print(prompt_str)
'''
<|from|>system
<|recipient|>all
<|content|>// Supported function definitions that should be called when necessary.
namespace functions {
// Get the current weather
type get_current_weather = (_: {
// The city and state, e.g. San Francisco, CA.
location: string,
// The temperature unit to use. Infer this from the users location.
format: "celsius" | "fahrenheit",
}) => any;
// Get an N-day weather forecast
type get_n_day_weather_forecast = (_: {
// The city and state, e.g. San Francisco, CA.
location: string,
// The temperature unit to use. Infer this from the users location.
format: "celsius" | "fahrenheit",
// The number of days to forecast.
num_days: number,
}) => any;
} // namespace functions
<|from|>system
<|recipient|>all
<|content|>A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. The assistant calls functions with appropriate input when necessary
<|from|>user
<|recipient|>all
<|content|>What is the weather for Istanbul?
<|from|>assistant
<|recipient|>all
<|content|>Yes I will try<|stop|>
<|from|>assistant
<|recipient|>plan_trip
<|content|>{
"destination": "Paris",
"duration": 7,
"interests": ["art", "culture"]
}<|stop|>
<|from|>get_current_weather
<|recipient|>all
<|content|>Sunny day!!!
<|from|>assistant
<|recipient|>
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment