Skip to content

Instantly share code, notes, and snippets.

@alonsosilvaallende
Created July 12, 2023 07:54
Show Gist options
  • Save alonsosilvaallende/70705e77890a739e95b8bc6eccd4282c to your computer and use it in GitHub Desktop.
Save alonsosilvaallende/70705e77890a739e95b8bc6eccd4282c to your computer and use it in GitHub Desktop.
Impatient-OpenRouter
import os
import openai
openai.api_base = "https://openrouter.ai/api/v1"
openai.api_key = os.getenv("OPENAI_API_KEY")
OPENROUTER_REFERRER = "https://github.com/alonsosilvaallende/chatplotlib-openrouter"
def llm(text: str) -> str:
return openai.ChatCompletion.create(
model='openai/gpt-4-32K',
headers={
"HTTP-Referer": OPENROUTER_REFERRER
}, # Not needed if you already have access to gpt-4
messages=[{
'role': 'user',
'content': f'{text}'
}],
temperature=0.9).choices[0].message.content
print(llm("Tell me a joke"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment