-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (27 loc) · 841 Bytes
/
main.py
File metadata and controls
31 lines (27 loc) · 841 Bytes
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
30
31
import streamlit as st
import openai
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
client = openai.OpenAI(
api_key=os.getenv("AI71_API_KEY"),
base_url=os.getenv("AI71_BASE_URL"),
)
# Simple invocation:
print(client.chat.completions.create(
model="tiiuae/falcon-180B-chat",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
],
))
# Streaming invocation:
for chunk in client.chat.completions.create(
messages=[{"role": "user", "content": "Write a song about a ginger-colored fish on the moon."}],
model="tiiuae/falcon-180B-chat",
stream=True,
):
delta_content = chunk.choices[0].delta.content
if delta_content:
print(delta_content, sep="", end="", flush=True)