SimaFarazi commited on
Commit
feb1823
1 Parent(s): bdb23e1

add comments to simple app stream

Browse files
app_simple_stream/app/chains.py CHANGED
@@ -14,7 +14,7 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
14
  llm = HuggingFaceEndpoint(
15
  repo_id="meta-llama/Meta-Llama-3-8B-Instruct",
16
  huggingfacehub_api_token=os.environ['HF_TOKEN'],
17
- max_new_tokens=512,
18
  stop_sequences=[tokenizer.eos_token],
19
  streaming=True,
20
  )
 
14
  llm = HuggingFaceEndpoint(
15
  repo_id="meta-llama/Meta-Llama-3-8B-Instruct",
16
  huggingfacehub_api_token=os.environ['HF_TOKEN'],
17
+ max_new_tokens=512, # Response will not exceed 512 words/tokens
18
  stop_sequences=[tokenizer.eos_token],
19
  streaming=True,
20
  )
app_simple_stream/app/database.py DELETED
@@ -1,12 +0,0 @@
1
- from sqlalchemy import create_engine
2
- from sqlalchemy.ext.declarative import declarative_base
3
- from sqlalchemy.orm import sessionmaker
4
-
5
- SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"
6
-
7
- engine = create_engine(
8
- SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
9
- )
10
- SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
11
-
12
- Base = declarative_base()
 
 
 
 
 
 
 
 
 
 
 
 
 
app_simple_stream/test.py CHANGED
@@ -1,7 +1,11 @@
1
  from langserve import RemoteRunnable
2
  # Hit our enpoint with specified rout
3
  url = "https://simafarazi-backend-c.hf.space/simple/"
4
- chain = RemoteRunnable(url)
5
- stream = chain.stream(input={'question':'How are you?'})
6
- for chunk in stream:
7
- print(chunk, end="", flush=True)
 
 
 
 
 
1
  from langserve import RemoteRunnable
2
  # Hit our enpoint with specified rout
3
  url = "https://simafarazi-backend-c.hf.space/simple/"
4
+ chain = RemoteRunnable(url) #Client for iteracting with LangChain runnables that are hosted as LangServe endpoints
5
+ stream = chain.stream(input={'question':'How are you?'}) # .stream() and .invoke() are standard methods to interact with hosted runnables
6
+
7
+
8
+ for chunk in stream: # Each chunk corresponds to a token/word
9
+ #end="": prints worlds one after each other, an not in a separate lines
10
+ #flush=True: prints world to the screen immidiately without any buffer
11
+ print(chunk, end="", flush=True)