|
2009 | 2009 | "from fastcore.meta import delegates" |
2010 | 2010 | ] |
2011 | 2011 | }, |
| 2012 | + { |
| 2013 | + "cell_type": "code", |
| 2014 | + "execution_count": null, |
| 2015 | + "id": "162a5ba9", |
| 2016 | + "metadata": {}, |
| 2017 | + "outputs": [], |
| 2018 | + "source": [ |
| 2019 | + "#| export\n", |
| 2020 | + "from typing import Callable" |
| 2021 | + ] |
| 2022 | + }, |
2012 | 2023 | { |
2013 | 2024 | "cell_type": "code", |
2014 | 2025 | "execution_count": null, |
|
2019 | 2030 | "#| export\n", |
2020 | 2031 | "@delegates(completion)\n", |
2021 | 2032 | "def structured(\n", |
2022 | | - " m, # The LiteLLM model string\n", |
2023 | | - " msgs:list, # A list of messages \n", |
2024 | | - " tool, # The tool to be used for creating the structured output. Can also be a class, dataclass or Pydantic model \n", |
| 2033 | + " m:str, # The LiteLLM model string\n", |
| 2034 | + " msgs:list, # A list of messages \n", |
| 2035 | + " tool:Callable, # The tool to be used for creating the structured output. Can also be a class, dataclass or Pydantic model \n", |
2025 | 2036 | " **kwargs):\n", |
2026 | 2037 | " \"Return the value of the tool call (generally used for structured outputs)\"\n", |
| 2038 | + "\n", |
2027 | 2039 | " t = lite_mk_func(tool)\n", |
2028 | | - " \n", |
2029 | 2040 | " r = completion(m, msgs, tools=[t], tool_choice=t, **kwargs)\n", |
2030 | | - "\n", |
2031 | 2041 | " args = json.loads(r.choices[0].message.tool_calls[0].function.arguments)\n", |
2032 | | - "\n", |
2033 | 2042 | " return tool(**args)" |
2034 | 2043 | ] |
2035 | 2044 | }, |
|
2065 | 2074 | { |
2066 | 2075 | "data": { |
2067 | 2076 | "text/plain": [ |
2068 | | - "President(first='Thomas', last='Jefferson', spouse='Martha Jefferson Randolph', years_in_office='1801-1809', birthplace='Shadwell, Virginia', birth_year=1743)" |
| 2077 | + "President(first='Thomas', last='Jefferson', spouse='Martha Wayles Skelton', years_in_office='1801-1809', birthplace='Shadwell, Virginia, British America', birth_year=1743)" |
2069 | 2078 | ] |
2070 | 2079 | }, |
2071 | 2080 | "execution_count": null, |
|
0 commit comments