Skip to content

Instantly share code, notes, and snippets.

@jlowin
Created July 17, 2023 22:43
Show Gist options
  • Save jlowin/82801b2914d810daf0fc59ce755f7fd6 to your computer and use it in GitHub Desktop.
Save jlowin/82801b2914d810daf0fc59ce755f7fd6 to your computer and use it in GitHub Desktop.
import marvin
from marvin import ai_fn
marvin.settings.llm_model = 'gpt-4'
@ai_fn
def semantic_deduplication(new_item: str, existing_items: list[str]) -> list[str]:
"""
Check if the `new_item` is semantically the same as any of the `existing_items`.
If it is, update the existing item's description with the new one.
Otherwise, add the `new_item` to the `existing_items` list.
"""
# --- Demo
existing_items = ["Go to the museum", "Go to the park", "Go to the zoo"]
# first try a semantically duplicated item
print(semantic_deduplication("Visit the museum", existing_items))
# ['Visit the museum', 'Go to the park', 'Go to the zoo']
# now add a new item
print(semantic_deduplication("Go to the beach", existing_items))
# ['Go to the museum', 'Go to the park', 'Go to the zoo', 'Go to the beach']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment