langchain[patch], experimental[minor]: Adds OllamaFunctions wrapper (#13330)

CC @baskaryan @hwchase17 @jmorganca 

Having a bit of trouble importing `langchain_experimental` from a
notebook, will figure it out tomorrow

~Ah and also is blocked by #13226~

---------

Co-authored-by: Lance Martin <lance@langchain.dev>
Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
Jacob Lee
2023-11-30 16:13:57 -08:00
committed by GitHub
parent 4063bf144a
commit 3328507f11
7 changed files with 529 additions and 6 deletions

View File

@@ -0,0 +1,49 @@
"""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")