jonathanjordan21 commited on
Commit
20ceb06
·
verified ·
1 Parent(s): 262c871

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  from langchain_community.chat_models import ChatOllama
4
  from langchain_core.prompts import ChatPromptTemplate
 
5
  """
6
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
7
  """
@@ -40,19 +41,21 @@ def respond(
40
  # messages.append({"role": "user", "content": message})
41
  messages.append(("user", message))
42
 
43
- response = ""
 
 
44
 
45
- for message in client.chat_completion(
46
- messages,
47
- max_tokens=max_tokens,
48
- stream=True,
49
- temperature=temperature,
50
- top_p=top_p,
51
- ):
52
- token = message.choices[0].delta.content
53
 
54
- response += token
55
- yield response
56
 
57
  """
58
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
2
  from huggingface_hub import InferenceClient
3
  from langchain_community.chat_models import ChatOllama
4
  from langchain_core.prompts import ChatPromptTemplate
5
+ from langchain_core.output_parsers import StrOutputParser
6
  """
7
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
8
  """
 
41
  # messages.append({"role": "user", "content": message})
42
  messages.append(("user", message))
43
 
44
+ chain = ChatPromptTemplate.from_messages(messages) | ChatOllama | StrOutputParser()
45
+ return chain.invoke()
46
+ # response = ""
47
 
48
+ # for message in client.chat_completion(
49
+ # messages,
50
+ # max_tokens=max_tokens,
51
+ # stream=True,
52
+ # temperature=temperature,
53
+ # top_p=top_p,
54
+ # ):
55
+ # token = message.choices[0].delta.content
56
 
57
+ # response += token
58
+ # yield response
59
 
60
  """
61
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface