seungah commited on
Commit
9c1406a
1 Parent(s): c284472

Add application file & dependecy file

Browse files
Files changed (2) hide show
  1. app.py +23 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from friendli import Friendli
3
+
4
+ client = Friendli(token=FRIENDLI_TOKEN)
5
+
6
+ def chat_function(message, history):
7
+ new_messages = []
8
+ for user, chatbot in history:
9
+ new_messages.append({"role" : "user", "content": user})
10
+ new_messages.append({"role" : "assistant", "content": chatbot})
11
+ new_messages.append({"role": "user", "content": message})
12
+
13
+ stream = client.chat.completions.create(
14
+ model="meta-llama-3-70b-instruct",
15
+ messages=new_messages,
16
+ stream=True
17
+ )
18
+ res = ""
19
+ for chunk in stream:
20
+ res += chunk.choices[0].delta.content or ""
21
+ yield res
22
+
23
+ gr.ChatInterface(chat_function).launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio==4.31.4
2
+ friendli-client=1.3.4