Skip to main content

Functions

FUNC add_tools_from_model_options

add_tools_from_model_options(tools_dict: dict[str, Callable], model_options: dict[str, Any])
If model_options has tools, add those tools to the tools_dict.

FUNC add_tools_from_context_actions

add_tools_from_context_actions(tools_dict: dict[str, Callable], ctx_actions: list[Component | CBlock] | None)
If any of the actions in ctx_actions have tools in their template_representation, add those to the tools_dict.

FUNC convert_tools_to_json

convert_tools_to_json(tools: dict[str, Callable]) -> list[dict]
Convert tools to json dict representation. Notes:
  • Huggingface transformers library lets you pass in an array of functions but doesn’t like methods.
  • WatsonxAI uses from langchain_ibm.chat_models import convert_to_openai_tool in their demos, but it gives the same values.
  • OpenAI uses the same format / schema.

FUNC json_extraction

json_extraction(text: str) -> Generator[dict, None, None]
Yields the next valid json object in a given string.

FUNC find_func

find_func(d) -> tuple[str | None, Mapping | None]
Find the first function in a json-like dictionary. Most llms output tool requests in the form ...{"name": string, "arguments": {}}...

FUNC parse_tools

parse_tools(llm_response: str) -> list[tuple[str, Mapping]]
A simple parser that will scan a string for tools and attempt to extract them; only works for json based outputs.

FUNC convert_function_to_tool

convert_function_to_tool(func: Callable) -> Tool
Imported from Ollama.

Classes

CLASS SubscriptableBaseModel

Class imported from Ollama.
Methods:

FUNC get

get(self, key: str, default: Any = None) -> Any
Get.
msg = Message(role=‘user’) msg.get(‘role’) ‘user’ msg = Message(role=‘user’) msg.get(‘nonexistent’) msg = Message(role=‘user’) msg.get(‘nonexistent’, ‘default’) ‘default’ msg = Message(role=‘user’, tool_calls=[ Message.ToolCall(function=Message.ToolCall.Function(name=‘foo’, arguments=))]) msg.get(‘tool_calls’)[0][‘function’][‘name’] ‘foo’

CLASS Tool

Class imported from Ollama.