from openai import OpenAI
client = OpenAI(api_key = "secret")
def chat_with_gpt(prompt):
prompt = str(prompt)
completion = client.chat.completions.create(
model="gpt-3.5-turbo-0125",
messages=[
{"role": "system", "content": "You are a helpful assistant that talks very sarcastically."},
{"role": "user", "content": prompt}
]
)
return completion.choices[0].message
Describe your issue
I'm creating a chatbot in android studio using openai API in python using chaquopy. when i place hard codes in the python file, it runs as expected and the output in the application is correct but when I use the openai chat completion, it wont let me connect and says connection error.
Chaquopy version 15.0.1
Devices or emulators where the issue happens Pixel 6a API 34
Relevant parts of your code
plugins { id("com.android.application") id("org.jetbrains.kotlin.android") id("com.chaquo.python") }
android { namespace = "com.codex.tala" compileSdk = 34
}
chaquopy { defaultConfig { buildPython("C:/Users/Joshua/AppData/Local/Programs/Python/Python311/python.exe") version = "3.11"
}
plugins { id("com.android.application") version "8.2.2" apply false id("org.jetbrains.kotlin.android") version "1.9.22" apply false id("com.chaquo.python") version "15.0.1" apply false }
private void addToChat(String message, String sentBy){ runOnUiThread(new Runnable() { @Override public void run() { messageList.add(new Message(message, sentBy)); messageAdapter.notifyDataSetChanged(); recyclerView.smoothScrollToPosition(messageAdapter.getItemCount()); } }); }
from openai import OpenAI client = OpenAI(api_key = "secret")
def chat_with_gpt(prompt): prompt = str(prompt) completion = client.chat.completions.create( model="gpt-3.5-turbo-0125", messages=[ {"role": "system", "content": "You are a helpful assistant that talks very sarcastically."}, {"role": "user", "content": prompt} ] )
Describe your issue
I'm creating a chatbot in android studio using openai API in python using chaquopy. when i place hard codes in the python file, it runs as expected and the output in the application is correct but when I use the openai chat completion, it wont let me connect and says connection error.