Spaces:
Runtime error
Runtime error
File size: 847 Bytes
2d19a65 |
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 27 28 29 |
# This is a simple general-purpose chatbot built on top of SambaNova API.
# Before running this, make sure you have exported your SambaNova API key as an environment variable:
# export SAMBANOVA_API_KEY="your-sambanova-api-key"
import os
import gradio as gr
from openai import OpenAI
api_key = os.getenv("SAMBANOVA_API_KEY")
client = OpenAI(
base_url="https://api.sambanova.ai/v1/",
api_key=api_key,
)
def predict(message, history):
history.append({"role": "user", "content": message})
stream = client.chat.completions.create(messages=history, model="Meta-Llama-3.1-70B-Instruct-8k", stream=True)
chunks = []
for chunk in stream:
chunks.append(chunk.choices[0].delta.content or "")
yield "".join(chunks)
demo = gr.ChatInterface(predict, type="messages")
if __name__ == "__main__":
demo.launch()
|