You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
langchain/libs/experimental/tests/integration_tests/llms/test_ollama_functions.py

50 lines
1.6 KiB
Python

"""Test OllamaFunctions"""
import unittest
from langchain.chat_models.ollama import ChatOllama
from langchain_experimental.llms.ollama_functions import OllamaFunctions
class TestOllamaFunctions(unittest.TestCase):
"""
Test OllamaFunctions
"""
def test_default_ollama_functions(self) -> None:
base_model = OllamaFunctions(model="mistral")
self.assertIsInstance(base_model.model, ChatOllama)
# bind functions
model = base_model.bind(
functions=[
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, "
"e.g. San Francisco, CA",
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
},
},
"required": ["location"],
},
}
],
function_call={"name": "get_current_weather"},
)
res = model.invoke("What's the weather in San Francisco?")
function_call = res.additional_kwargs.get("function_call")
assert function_call
self.assertEqual(function_call.get("name"), "get_current_weather")