Last active
September 21, 2023 12:47
-
-
Save mvsoom/e177bfad9e48e69079eefed0238cc94f 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
import openai | |
openai.api_base = "https://api.endpoints.anyscale.com/v1" | |
openai.api_key = ANYSCALE_API_KEY | |
COMPLETIONS = 3 | |
prompt = "Fine," # <---- NO space | |
print(prompt, end="") | |
def enhanced(text, i): | |
if i % 2 == 1: | |
return text | |
else: | |
return '\033[94m' + text + '\033[0m' | |
for i in range(COMPLETIONS): | |
for chunk in openai.Completion.create( | |
model="meta-llama/Llama-2-7b-chat-hf", | |
prompt=prompt, | |
temperature=0.7, | |
stream=True | |
): | |
word = chunk['choices'][0]['text'] | |
print(enhanced(word, i), end="", flush=True) | |
prompt += word |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment