File size: 692 Bytes
9c1406a
523bf6e
9c1406a
 
7b6cc23
9c1406a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import gradio as gr
from friendli import Friendli

FRIENDLI_TOKEN = os.getenv("FRIENDLI_TOKEN")
client = Friendli(token=FRIENDLI_TOKEN)

def chat_function(message, history):
  new_messages = []
  for user, chatbot in history:
    new_messages.append({"role" : "user", "content": user})
    new_messages.append({"role" : "assistant", "content": chatbot})
  new_messages.append({"role": "user", "content": message})

  stream = client.chat.completions.create(
    model="meta-llama-3-70b-instruct",
    messages=new_messages,
    stream=True
  )
  res = ""
  for chunk in stream:
    res += chunk.choices[0].delta.content or ""
    yield res

gr.ChatInterface(chat_function).launch()