Skip to content

Commit 17c0823

Browse files
committed
update readme
1 parent 0e107f1 commit 17c0823

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ schema = get_function_schema(get_weather, "claude")
8989

9090
Please refer to the [Claude tool use](https://docs.anthropic.com/claude/docs/tool-use) documentation for more information.
9191

92+
### Literal types can be used as Enum
93+
94+
```python
95+
def get_weather(
96+
city: Annotated[str, "The city to get the weather for"],
97+
unit: Annotated[
98+
Optional[Literal["celcius", "fahrenheit"]], # <- Literal type represents Enum
99+
"The unit to return the temperature in",
100+
] = "celcius",
101+
) -> str:
102+
"""Returns the weather for the given city."""
103+
return f"Weather for {city} is 20°C"
104+
```
105+
The schema will be generated as the same as the previous example.
106+
107+
### Usage with OpenAI API
108+
92109
You can use this schema to make a function call in OpenAI API:
93110
```python
94111
import openai
@@ -118,12 +135,15 @@ result = openai.chat.completion.create(
118135
messages=[
119136
{"role": "user", "content": "What's the weather like in Seoul?"}
120137
],
121-
tools=[get_function_schema(get_weather)],
138+
tools=[{
139+
"type": "function",
140+
"function": get_function_schema(get_weather)
141+
}],
122142
tool_call="auto",
123143
)
124144
```
125145

126-
In claude api,
146+
### Usage with Anthropic Claude
127147

128148
```python
129149
import anthropic

0 commit comments

Comments
 (0)