Skip to content

Commit 3659486

Browse files
committed
fix
1 parent 26de144 commit 3659486

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

pages/models/code-llama.en.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ For all the prompt examples below, we will be using [Code Llama 70B Instruct](ht
2020
- [Unit Tests](#unit-tests)
2121
- [Text-to-SQL Generation](#text-to-sql-generation)
2222
- [Few-shot Prompting with Code Llama](#few-shot-prompting-with-code-llama)
23+
- [Function Calling](#function-calling)
2324
- [Safety Guardrails](#safety-guardrails)
2425
- [Notebook](#full-notebook)
2526
- [References](#additional-references)
@@ -372,6 +373,53 @@ result = students_df[(students_df['GPA'] >= 3.5) & (students_df['GPA'] <= 3.8)]
372373

373374
For the pandas dataframe prompts and examples, we got inspiration from the recent work of [Ye et al. 2024](https://arxiv.org/abs/2401.15463).
374375

376+
## Function Calling
377+
378+
You can also use the Code Llama models for function calling. However, the Code Llama 70B Instruct model provided via the together.ai APIs currently don't support this feature. So for now we went ahead and provided an example with the Code Llama 34B Instruct model instead.
379+
380+
```python
381+
tools = [
382+
{
383+
"type": "function",
384+
"function": {
385+
"name": "get_current_weather",
386+
"description": "Get the current weather in a given location",
387+
"parameters": {
388+
"type": "object",
389+
"properties": {
390+
"location": {
391+
"type": "string",
392+
"description": "The city and state, e.g. San Francisco, CA"
393+
},
394+
"unit": {
395+
"type": "string",
396+
"enum": [
397+
"celsius",
398+
"fahrenheit"
399+
]
400+
}
401+
}
402+
}
403+
}
404+
}
405+
]
406+
407+
messages = [
408+
{"role": "system", "content": "You are a helpful assistant that can access external functions. The responses from these function calls will be appended to this dialogue. Please provide responses based on the information from these function calls."},
409+
{"role": "user", "content": "What is the current temperature of New York, San Francisco and Chicago?"}
410+
]
411+
412+
response = client.chat.completions.create(
413+
model="togethercomputer/CodeLlama-34b-Instruct",
414+
messages=messages,
415+
tools=tools,
416+
tool_choice="auto",
417+
)
418+
419+
print(json.dumps(response.choices[0].message.model_dump()['tool_calls'], indent=2))
420+
```
421+
422+
375423
## Safety Guardrails
376424

377425
There are some scenarios where the model will refuse to respond because of the safety alignment it has undergone. As an example, the model sometimes refuses to answer the prompt request below. It can be fixed by rephrasing the prompt or removing the `system` prompt.

0 commit comments

Comments
 (0)