Skip to content

Commit

Permalink
Fix types for openai>1
Browse files Browse the repository at this point in the history
  • Loading branch information
john-kurkowski committed Nov 9, 2023
1 parent c71c8b1 commit 44218d9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/music/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def main(example_audio_file: Path) -> None:
proc = subprocess.run(cmd, check=True, stderr=subprocess.PIPE, text=True)
proc_output = proc.stderr

messages = [
messages: list[openai.types.chat.ChatCompletionMessageParam] = [
{
"role": "system",
"content": (
Expand All @@ -45,9 +45,14 @@ def main(example_audio_file: Path) -> None:
),
},
]
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages, temperature=0) # type: ignore[no-untyped-call]
lines = response.choices[0].message["content"].splitlines()
response = openai.chat.completions.create(
model="gpt-3.5-turbo", messages=messages, temperature=0
)
message = response.choices[0].message
if message.content is None:
raise Exception(f"No content in message from GPT: {message}")

lines = message.content.splitlines()
if lines[0].startswith("```"):
lines = lines[1:]
if lines[-1].startswith("```"):
Expand Down

0 comments on commit 44218d9

Please sign in to comment.