Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -61,9 +61,7 @@ def qwen_api(user_message, top_p=0.9,temperature=0.7, system_message='', max_tok
|
|
61 |
|
62 |
os.environ["OPENAI_API_BASE"] = "https://api-inference.huggingface.co/v1/"
|
63 |
os.environ["OPENAI_API_KEY"] = TOKEN
|
64 |
-
|
65 |
-
model="meta-llama/Meta-Llama-3-8B-Instruct",
|
66 |
-
temperature=0.8,)
|
67 |
|
68 |
|
69 |
|
@@ -79,13 +77,22 @@ PROMPT = PromptTemplate(
|
|
79 |
)
|
80 |
chain_type_kwargs = {"prompt": PROMPT}
|
81 |
retriever = db.as_retriever()
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
def chat(
|
91 |
message,
|
@@ -96,9 +103,9 @@ def chat(
|
|
96 |
top_p,
|
97 |
):
|
98 |
if len(history) == 0:
|
99 |
-
response =
|
100 |
else:
|
101 |
-
response = qwen_api(message, gradio_history=history)
|
102 |
print(response)
|
103 |
yield response
|
104 |
return response
|
|
|
61 |
|
62 |
os.environ["OPENAI_API_BASE"] = "https://api-inference.huggingface.co/v1/"
|
63 |
os.environ["OPENAI_API_KEY"] = TOKEN
|
64 |
+
|
|
|
|
|
65 |
|
66 |
|
67 |
|
|
|
77 |
)
|
78 |
chain_type_kwargs = {"prompt": PROMPT}
|
79 |
retriever = db.as_retriever()
|
80 |
+
|
81 |
+
def langchain_chat(message, temperature, top_p, max_tokens):
|
82 |
+
llm = ChatOpenAI(
|
83 |
+
model="meta-llama/Meta-Llama-3-8B-Instruct",
|
84 |
+
temperature=temperature,
|
85 |
+
top_p=top_p,
|
86 |
+
max_tokens=max_tokens)
|
87 |
+
qa = RetrievalQA.from_chain_type(
|
88 |
+
llm=llm,
|
89 |
+
chain_type="stuff",
|
90 |
+
retriever=retriever,
|
91 |
+
chain_type_kwargs=chain_type_kwargs,
|
92 |
+
return_source_documents=True
|
93 |
+
)
|
94 |
+
response = qa.invoke(message)['result']
|
95 |
+
return response
|
96 |
|
97 |
def chat(
|
98 |
message,
|
|
|
103 |
top_p,
|
104 |
):
|
105 |
if len(history) == 0:
|
106 |
+
response = langchain_chat(message, temperature, top_p, max_tokens)
|
107 |
else:
|
108 |
+
response = qwen_api(message, gradio_history=history, max_tokens=max_tokens, top_p=top_p, temperature=temperature)
|
109 |
print(response)
|
110 |
yield response
|
111 |
return response
|