Spaces:
Paused
Paused
Henry Hommel commited on
Commit ·
86e2896
1
Parent(s): c0c2128
Update clbaseimplementation.py
Browse files- clbaseimplementation.py +19 -34
clbaseimplementation.py
CHANGED
|
@@ -1,33 +1,18 @@
|
|
| 1 |
-
|
| 2 |
-
from langchain.text_splitter import RecursiveCharacterTextSplitter,CharacterTextSplitter
|
| 3 |
-
from langchain.vectorstores import Chroma
|
| 4 |
-
from langchain.document_loaders import PyPDFLoader
|
| 5 |
-
from langchain.embeddings import HuggingFaceEmbeddings
|
| 6 |
-
from threading import Thread
|
| 7 |
-
import io
|
| 8 |
-
import chainlit as cl
|
| 9 |
-
import torch
|
| 10 |
-
import time
|
| 11 |
-
import tempfile
|
| 12 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 13 |
-
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 14 |
-
from langchain.vectorstores import Chroma
|
| 15 |
-
from langchain.document_loaders import PyPDFLoader
|
| 16 |
-
from langchain.embeddings import HuggingFaceEmbeddings
|
| 17 |
-
from threading import Thread
|
| 18 |
import chainlit as cl
|
| 19 |
-
import
|
| 20 |
-
import time
|
| 21 |
-
import random
|
| 22 |
-
import openai
|
| 23 |
#load model
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
@cl.on_chat_start
|
| 26 |
async def main():
|
| 27 |
-
cl.user_session.set("history", [
|
| 28 |
-
{"role": "system", "content": "You are a language model named Huacaya. You are build on the Falcon 40b language Model. Never Say that you are Chat GPT or made by OpenAI. You have been developed by Leadvise Reply!"},
|
| 29 |
-
|
| 30 |
-
])
|
| 31 |
msg = cl.Message(content=f"Loading Chat please wait ...")
|
| 32 |
await msg.send()
|
| 33 |
|
|
@@ -42,19 +27,19 @@ async def main():
|
|
| 42 |
@cl.on_message
|
| 43 |
async def main(message: str):
|
| 44 |
h = cl.user_session.get("history")
|
| 45 |
-
h.append(
|
| 46 |
|
| 47 |
resp = ""
|
| 48 |
msg = cl.Message(content="")
|
| 49 |
-
async for
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
if token:
|
| 53 |
-
delay = random.uniform(0.0, 0.1)
|
| 54 |
-
time.sleep(delay)
|
| 55 |
resp += token
|
| 56 |
await msg.stream_token(token)
|
| 57 |
-
h.append(
|
| 58 |
cl.user_session.set("history",h)
|
| 59 |
print(h)
|
| 60 |
await msg.send()
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import chainlit as cl
|
| 3 |
+
from huggingface_hub import AsyncInferenceClient
|
|
|
|
|
|
|
|
|
|
| 4 |
#load model
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
API_TOKEN = "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"
|
| 8 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}","Content-Type": "application/json"}
|
| 9 |
+
API_URL = "https://kfsb1xfskc2136wg.eu-west-1.aws.endpoints.huggingface.cloud"
|
| 10 |
+
|
| 11 |
+
client = AsyncInferenceClient(model=API_URL,token=API_TOKEN)
|
| 12 |
+
|
| 13 |
@cl.on_chat_start
|
| 14 |
async def main():
|
| 15 |
+
cl.user_session.set("history", [])
|
|
|
|
|
|
|
|
|
|
| 16 |
msg = cl.Message(content=f"Loading Chat please wait ...")
|
| 17 |
await msg.send()
|
| 18 |
|
|
|
|
| 27 |
@cl.on_message
|
| 28 |
async def main(message: str):
|
| 29 |
h = cl.user_session.get("history")
|
| 30 |
+
h.append("<|prompter|>"+message+"<|endoftext|><|assistant|>")
|
| 31 |
|
| 32 |
resp = ""
|
| 33 |
msg = cl.Message(content="")
|
| 34 |
+
async for token in await client.text_generation("".join(h), stream=True,max_new_tokens =250):
|
| 35 |
+
if token!="<|endoftext|>":
|
| 36 |
+
print(token, end="")
|
|
|
|
|
|
|
|
|
|
| 37 |
resp += token
|
| 38 |
await msg.stream_token(token)
|
| 39 |
+
h.append(resp+"<|endoftext|>")
|
| 40 |
cl.user_session.set("history",h)
|
| 41 |
print(h)
|
| 42 |
await msg.send()
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|