Skip to content

Instantly share code, notes, and snippets.

@philschmid
Created February 22, 2024 17:37
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save philschmid/1c901096e91bf044be3525d74f3b7c34 to your computer and use it in GitHub Desktop.
Save philschmid/1c901096e91bf044be3525d74f3b7c34 to your computer and use it in GitHub Desktop.
from openai import OpenAI
# initialize the client but point it to TGI
client = OpenAI(
base_url="https://api-inference.huggingface.co/v1",
api_key="hf_xxx" # Replace with your token
)
chat_completion = client.chat.completions.create(
model="google/gemma-7b-it",
messages=[
{"role": "user", "content": "Why is open-source software important?"},
],
stream=True,
max_tokens=500
)
# iterate and print stream
for message in chat_completion:
print(message.choices[0].delta.content, end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment