File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,23 @@ schema = get_function_schema(get_weather, "claude")
8989
9090Please 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+
92109You can use this schema to make a function call in OpenAI API:
93110``` python
94111import 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
129149import anthropic
You can’t perform that action at this time.
0 commit comments