Skip to content

Instantly share code, notes, and snippets.

@mvsoom
Last active September 21, 2023 12:47
Show Gist options
  • Save mvsoom/e177bfad9e48e69079eefed0238cc94f to your computer and use it in GitHub Desktop.
Save mvsoom/e177bfad9e48e69079eefed0238cc94f to your computer and use it in GitHub Desktop.
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