Anyone managed to use the Python openai module? #1656
Replies: 2 comments 1 reply
-
Mojo still doesn't support passing keyword arguments when calling Python functions, but it's on their roadmap. |
Beta Was this translation helpful? Give feedback.
1 reply
-
This might be a bit late, but I hope it helps someone. This code worked for me: from python import Python
fn main()-> None:
try:
var openai = Python.import_module("openai")
var client = openai.OpenAI(api_key=<"your api key">)
var dictionary = Python.dict()
dictionary["role"] = "user"
dictionary["content"] = "What is a context in OpenCL?"
var completion = client.chat.completions.create(model="gpt-3.5-turbo", messages=[dictionary])
print(completion.choices[0].message.content)
except e:
print("An error occurred:", e) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I heard about Mojo on the Lex Fridman Podcast and just decided to finally give it a try.
Came up with:
But with 'mojo main.mojo' I get:
main.mojo:12:52: error: invalid call to 'call': unexpected keyword arguments: 'messages', 'model'
let completion = client.chat.completions.create(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
main.mojo:1:1: note: function declared here
from python import Python
^
mojo: error: failed to parse the provided Mojo
Is this a bug? Does anyone know the cause of this?
I also tried to to use: messages=[{'content': 'What is a context in OpenCL??'}], but got the TODO error that dictionary literals are not supported.
ChatGPT told me that functions from Python modules have to comply to some criteria in order to work in Mojo, is this correct?
Thanks for any help.
Beta Was this translation helpful? Give feedback.
All reactions