Commit 8896d353 authored by Alp Deniz Ogut's avatar Alp Deniz Ogut
Browse files

Update demo

parent 1bce2f4e
Pipeline #14104 passed with stages
in 6 minutes and 20 seconds
Showing with 22 additions and 50 deletions
+22 -50
import json
from pathlib import Path
from typing import List
from pymemri.data.schema import Tweet
import requests
from pymemri.pod.client import PodClient
from rich import print
from rich.panel import Panel
from rich.prompt import Confirm, Prompt
from rich.rule import Rule
from semantic_search.plugin import SemanticSearchPlugin
def get_tweets() -> List[Tweet]:
with open(TWEET_FILE, "r") as f:
tweets_json = json.load(f)
return [Tweet.from_json(t) for t in tweets_json]
def print_tweet(tweet):
print(Panel(tweet.message))
ASSETS_DIR = Path(__file__).parent.parent / "tests" / "test_assets"
TWEET_FILE = ASSETS_DIR / "tweets.json"
def setup_plugin():
tweets = get_tweets()
client = PodClient()
client.add_to_schema(Tweet)
client.bulk_action(create_items=tweets)
plugin = SemanticSearchPlugin(client=client)
plugin.add_to_index(tweets)
return plugin
def main():
plugin = setup_plugin()
go_again = True
while go_again:
query = Prompt.ask("enter your search query")
results = plugin.search_top_k(query)
for result in results:
print_tweet(result)
print(Rule())
go_again = Confirm.ask("Go again?")
c = PodClient(url='https://dev.backend.memri.io')
pck = {"url":"https://dev.backend.memri.io", "owner_key":c.owner_key, "database_key":c.database_key}
payload = {
'pod_client_kwargs': pck,
'texts': ['hello this is a warm welcome', 'The world as we observe is just a collective illusion of our senses. Additionally, we have not yet looked beyond the electromagnetic domain'],
'ids': ['Simple greeting', 'Philosophical questioning']
}
response = requests.post("https://semantic-search.dev.backend.memri.io/index_texts?index_name=question", json=payload)
print(response.content)
query = 'philosophy'
print(f"Querying '{query}'...")
response = requests.post(f"https://semantic-search.dev.backend.memri.io/search_top_k?index_name=question&query={query}&top_k=1", json=payload)
print(response.content)
query = 'greeting'
print(f"Querying '{query}'...")
response = requests.post(f"https://semantic-search.dev.backend.memri.io/search_top_k?index_name=question&query={query}&top_k=1", json=payload)
print(response.content)
if __name__=="__main__":
main()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment