Skip to content

Instantly share code, notes, and snippets.

@morganmcg1
Created July 19, 2023 15:40
Show Gist options
  • Save morganmcg1/72c1699d60598ee0eceacbc9230fb1e7 to your computer and use it in GitHub Desktop.
Save morganmcg1/72c1699d60598ee0eceacbc9230fb1e7 to your computer and use it in GitHub Desktop.
import openai
import wandb
openai.api_key = "sk-..." # supply your API key however you choose
# https://platform.openai.com/docs/models
tbl = wandb.Table("my_table", columns=["input", "output", "temperature"])
query = "hello world"
systemp_prompts = "you are friendly"
completion = openai.ChatCompletion.create(
model="gpt-4",
temperature=0.7,
messages=[
{"role": "system", "content": system_prompts}
{"role": "user", "content": query}
# {"role": "assistant", "content": "hello"}
]
)
output = completion.choices[0].message.content # extract token counts from "completion"
tbl.add_data(query, output, temperature)
wandb.log({"tbl": tbl})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment