quocdat25 commited on
Commit
d109b16
1 Parent(s): fae0e8a

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. .ipynb_checkpoints/main-checkpoint.py +51 -0
  2. main.py +6 -3
.ipynb_checkpoints/main-checkpoint.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.llms import HuggingFaceEndpoint
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain.schema import AIMessage, HumanMessage
4
+ from langchain.chains import LLMChain
5
+ import gradio as gr
6
+ import os
7
+
8
+ from dotenv import load_dotenv
9
+
10
+ load_dotenv()
11
+
12
+ repo_id = "mistralai/Mistral-7B-Instruct-v0.2"
13
+ llm = HuggingFaceEndpoint(
14
+ repo_id = repo_id,
15
+ # huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
16
+ )
17
+
18
+ # template = """You're a good chatbot, you're thinking only about Eras Tour.
19
+ # You're playing with the user: they will guess what you're thinking. If their text doesn't have word like Taylor Swift or Eras Tour, response them funny and shortly like: Bitch! User: {question}
20
+ # Answer: """
21
+ template = """You're a clever chatbot, always pondering over a special theme related to music and tours, but it's a secret. When interacting with the user, play a guessing game: if they don't mention anything related to the secret theme (hint: it involves a famous musician and their concert series), respond in a playful yet cryptic manner, if they insist, repond like Bitch! Hell no!, etc ... Here's how you should structure your responses:
22
+ User: {question}
23
+ Answer: """
24
+ prompt = PromptTemplate.from_template(template=template)
25
+ llm_chain = LLMChain(llm=llm, prompt=prompt)
26
+
27
+
28
+ def predict(message, history):
29
+ history_langchain_format = []
30
+ # for human, ai in history:
31
+ # history_langchain_format.append(HumanMessage(content=human))
32
+ # history_langchain_format.append(AIMessage(content=ai))
33
+ # history_langchain_format.append(HumanMessage(content=message))
34
+ # gpt_response = llm(history_langchain_format)
35
+ response = llm_chain.invoke(message)['text']
36
+ return response
37
+
38
+ gr.ChatInterface(predict).launch()
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
main.py CHANGED
@@ -15,9 +15,12 @@ llm = HuggingFaceEndpoint(
15
  # huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
16
  )
17
 
18
- template = """You're a good chatbot, you're thinking only about Eras Tour.
19
- You're playing with the user: they will guess what you're thinking. If their text doesn't have word like Taylor Swift or Eras Tour, response them funny and shortly like: Bitch!. User: {question}
20
- Answer: ."""
 
 
 
21
  prompt = PromptTemplate.from_template(template=template)
22
  llm_chain = LLMChain(llm=llm, prompt=prompt)
23
 
 
15
  # huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
16
  )
17
 
18
+ # template = """You're a good chatbot, you're thinking only about Eras Tour.
19
+ # You're playing with the user: they will guess what you're thinking. If their text doesn't have word like Taylor Swift or Eras Tour, response them funny and shortly like: Bitch! User: {question}
20
+ # Answer: """
21
+ template = """You're a clever chatbot, always pondering over a special theme related to music and tours, but it's a secret. When interacting with the user, play a guessing game: if they don't mention anything related to the secret theme (hint: it involves a famous musician and their concert series), respond in a playful yet cryptic manner, if they insist, repond like Bitch! Hell no!, etc ... Here's how you should structure your responses:
22
+ User: {question}
23
+ Answer: """
24
  prompt = PromptTemplate.from_template(template=template)
25
  llm_chain = LLMChain(llm=llm, prompt=prompt)
26