-
-
Save donwany/f65c5a6c272e5bb70e1d63ea4189f0a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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