Arafath10 commited on
Commit
81dbe97
·
verified ·
1 Parent(s): c4eb94d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +18 -0
main.py CHANGED
@@ -52,6 +52,24 @@ async def reply_whatsapp(request: Request):
52
  #msg.media(GOOD_BOY_URL)
53
  try:
54
  openai.api_key = os.environ["OPENAI_API_KEY"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  global index # Use the global index variable
56
  if index is None: # Check if the index is already loaded
57
  from llama_index import StorageContext, load_index_from_storage # Import necessary modules
 
52
  #msg.media(GOOD_BOY_URL)
53
  try:
54
  openai.api_key = os.environ["OPENAI_API_KEY"]
55
+
56
+ # Define the messages for the conversation
57
+ messages = [
58
+ {"role": "system", "content": "You are a helpful assistant."},
59
+ {"role": "user", "content": f"translate sinhala to english : '{user_query}' give only translated part only without any extra details" }
60
+ ]
61
+ # Make the API call
62
+ gptresponse = openai.chat.completions.create(
63
+ model="gpt-4o",
64
+ messages=messages
65
+ )
66
+
67
+ user_query = gptresponse.choices[0].message.content
68
+
69
+ print(f"translated text : {user_query}")
70
+
71
+
72
+
73
  global index # Use the global index variable
74
  if index is None: # Check if the index is already loaded
75
  from llama_index import StorageContext, load_index_from_storage # Import necessary modules