-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct
embed
and using arbitrary models on function calling
- Loading branch information
Showing
8 changed files
with
607 additions
and
435 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
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,19 @@ | ||
from cursive.compat.pydantic import BaseModel | ||
from cursive.function import cursive_function | ||
|
||
def test_function_schema_allows_arbitrary_types(): | ||
|
||
class Character(BaseModel): | ||
name: str | ||
age: int | ||
|
||
@cursive_function() | ||
def gen_arbitrary_type(character: Character): | ||
""" | ||
A test function. | ||
character: A character. | ||
""" | ||
return f"{character.name} is {character.age} years old." | ||
|
||
assert 'description' in gen_arbitrary_type.function_schema |
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,13 @@ | ||
from cursive import Cursive | ||
import numpy as np | ||
|
||
cursive = Cursive() | ||
|
||
x1 = cursive.embed("""Pizza""") | ||
|
||
x2 = cursive.embed("""Cat""") | ||
|
||
def cosine_similarity(x, y): | ||
return np.dot(x, y) / (np.linalg.norm(x) * np.linalg.norm(y)) | ||
|
||
print(cosine_similarity(x1, x2)) |
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,28 @@ | ||
from typing import List | ||
from cursive.compat.pydantic import BaseModel | ||
from cursive.function import cursive_function | ||
from cursive import Cursive | ||
|
||
class Input(BaseModel): | ||
input: str | ||
idx: int | ||
|
||
@cursive_function(pause=True) | ||
def gen_character_list(inputs: List[Input]): | ||
""" | ||
Given a prompt (which is directives for a LLM), generate possible inputs that could be fed to it. | ||
Generate 10 inputs. | ||
inputs: A list of inputs. | ||
""" | ||
return inputs | ||
|
||
c = Cursive() | ||
|
||
res = c.ask( | ||
prompt="Generate a headline for a SaaS company.", | ||
model="gpt-4", | ||
function_call=gen_character_list | ||
) | ||
|
||
print(res.function_result) |
Oops, something went wrong.