Spaces:
Runtime error
Runtime error
Download service/api.py from JR818/JarvisFastAPI: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/JR818/JarvisFastAPI/resolve/e9fffa81c981f9eddbbc7065d231ffc8ee7fb485/service/api.py
- Command line
-
hf download hf://spaces/JR818/JarvisFastAPI@e9fffa81c981f9eddbbc7065d231ffc8ee7fb485/service/api.py
-
curl -L -o api.py https://huggingface.co/spaces/JR818/JarvisFastAPI/resolve/e9fffa81c981f9eddbbc7065d231ffc8ee7fb485/service/api.py
1.43 kB
| import time | |
| import json | |
| from typing import Any | |
| from .llm import search_bot | |
| from .vector_store import vector_store | |
| class API(): | |
| HF_SPACE="JR818/Jarvis-Backend" | |
| PROJECT='filecoin' | |
| def __init__(self) -> None: | |
| pass | |
| def get_suggestion(self,query): | |
| if not query: | |
| return [] | |
| docs = vector_store.marginal_search(query) | |
| res = [] | |
| for doc in docs: | |
| name = doc.metadata.get('title_llm','') | |
| url = doc.metadata.get('source','') | |
| if name == '' or url == '': | |
| continue | |
| res.append({"name":name,"url":url}) | |
| return res | |
| def get_answer(self,query): | |
| docs = vector_store.search(query) | |
| source = [] | |
| context = [] | |
| for doc in docs: | |
| if doc.metadata['score']<0.2: | |
| continue | |
| if 'title_llm' in doc.metadata: | |
| source.append({ | |
| "name":doc.metadata.get('title_llm',''), | |
| "url":doc.metadata.get('source',''), | |
| "description":doc.metadata.get('description_llm','') | |
| }) | |
| context.append(doc.metadata.get('description','')) | |
| yield json.dumps(source) | |
| context = "\n".join(context) | |
| answer = search_bot(query,context,stream=True) | |
| text = "" | |
| for i in answer: | |
| text += i | |
| yield i | |
| api = API() |