-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from aurelio-labs/james/ollama-signature
feat: add ollama signature builder
- Loading branch information
Showing
5 changed files
with
143 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "semantic-router" | ||
version = "0.0.58" | ||
version = "0.0.59" | ||
description = "Super fast semantic router for AI decision making" | ||
authors = [ | ||
"James Briggs <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import inspect | ||
from semantic_router.utils.function_call import FunctionSchema | ||
|
||
|
||
def scrape_webpage(url: str, name: str = "test") -> str: | ||
"""Provides access to web scraping. You can use this tool to scrape a webpage. | ||
Many webpages may return no information due to JS or adblock issues, if this | ||
happens, you must use a different URL. | ||
""" | ||
return "hello there" | ||
|
||
|
||
def test_function_schema(): | ||
schema = FunctionSchema(scrape_webpage) | ||
assert schema.name == scrape_webpage.__name__ | ||
assert schema.description == str(inspect.getdoc(scrape_webpage)) | ||
assert schema.signature == str(inspect.signature(scrape_webpage)) | ||
assert schema.output == str(inspect.signature(scrape_webpage).return_annotation) | ||
assert len(schema.parameters) == 2 | ||
|
||
|
||
def test_ollama_function_schema(): | ||
schema = FunctionSchema(scrape_webpage) | ||
ollama_schema = schema.to_ollama() | ||
assert ollama_schema["type"] == "function" | ||
assert ollama_schema["function"]["name"] == schema.name | ||
assert ollama_schema["function"]["description"] == schema.description | ||
assert ollama_schema["function"]["parameters"]["type"] == "object" | ||
assert ( | ||
ollama_schema["function"]["parameters"]["properties"]["url"]["type"] == "string" | ||
) | ||
assert ( | ||
ollama_schema["function"]["parameters"]["properties"]["name"]["type"] | ||
== "string" | ||
) | ||
assert ( | ||
ollama_schema["function"]["parameters"]["properties"]["url"]["description"] | ||
is None | ||
) | ||
assert ( | ||
ollama_schema["function"]["parameters"]["properties"]["name"]["description"] | ||
is None | ||
) | ||
assert ollama_schema["function"]["parameters"]["required"] == ["name"] |